diff --git a/applets/binary-clock/package/contents/ui/main.qml b/applets/binary-clock/package/contents/ui/main.qml index 816d7b369..4f511258a 100644 --- a/applets/binary-clock/package/contents/ui/main.qml +++ b/applets/binary-clock/package/contents/ui/main.qml @@ -1,73 +1,73 @@ /* * Copyright 2014 Joseph Wenninger * Copyright 2018 Piotr Kąkol * * Based on fuzzy-clock main.qml: * Copyright 2013 Heena Mahour * Copyright 2013 Sebastian Kügler * Copyright 2014 Kai Uwe Broulik * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import QtQuick 2.0 import QtQuick.Layouts 1.1 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.calendar 2.0 as PlasmaCalendar Item { id: root property bool showSeconds: plasmoid.configuration.showSeconds property int hours property int minutes property int seconds width: units.gridUnit * 10 height: units.gridUnit * 4 Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation Plasmoid.toolTipMainText: Qt.formatDate(dataSource.data["Local"]["DateTime"], "dddd") Plasmoid.toolTipSubText: Qt.formatDate(dataSource.data["Local"]["DateTime"], Qt.locale().dateFormat(Locale.LongFormat).replace(/(^dddd.?\s)|(,?\sdddd$)/, "")) PlasmaCore.DataSource { id: dataSource engine: "time" connectedSources: ["Local"] intervalAlignment: plasmoid.configuration.showSeconds ? PlasmaCore.Types.NoAlignment : PlasmaCore.Types.AlignToMinute interval: showSeconds ? 1000 : 60000 onDataChanged: { var date = new Date(data["Local"]["DateTime"]); hours = date.getHours(); minutes = date.getMinutes(); seconds = date.getSeconds(); } Component.onCompleted: { onDataChanged(); } } Plasmoid.compactRepresentation: BinaryClock { } Plasmoid.fullRepresentation: PlasmaCalendar.MonthView { Layout.minimumWidth: units.gridUnit * 20 Layout.minimumHeight: units.gridUnit * 20 today: dataSource.data["Local"]["DateTime"] } -} \ No newline at end of file +} diff --git a/applets/comic/package/contents/ui/main.qml b/applets/comic/package/contents/ui/main.qml index 24b4c7cec..536ade66b 100644 --- a/applets/comic/package/contents/ui/main.qml +++ b/applets/comic/package/contents/ui/main.qml @@ -1,232 +1,233 @@ /* * Copyright 2012 Reza Fatahilah Shah * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import QtQuick 2.1 import QtQuick.Layouts 1.1 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.kquickcontrolsaddons 2.0 Item { id: mainWindow readonly property int implicitWidth: units.gridUnit * 40 readonly property int implicitHeight: units.gridUnit * 15 + Plasmoid.backgroundHints: PlasmaCore.Types.DefaultBackground | PlasmaCore.Types.ConfigurableBackground Plasmoid.switchWidth: { if (centerLayout.comicData.image) { return Math.max(minimumWidth, Math.min(centerLayout.comicData.image.nativeWidth * 0.6, implicitWidth)); } else { return units.gridUnit * 8; } } Plasmoid.switchHeight: { if (centerLayout.comicData.image) { return Math.max(minimumHeight, Math.min(centerLayout.comicData.image.nativeHeight * 0.6, implicitHeight)); } else { return units.gridUnit * 8; } } Plasmoid.icon: "face-laughing" width: implicitWidth height: implicitHeight readonly property int minimumWidth: units.gridUnit * 8 readonly property int minimumHeight: units.gridUnit * 8 readonly property bool showComicAuthor: plasmoid.nativeInterface.showComicAuthor readonly property bool showComicTitle: plasmoid.nativeInterface.showComicTitle readonly property bool showErrorPicture: plasmoid.nativeInterface.showErrorPicture readonly property bool middleClick: plasmoid.nativeInterface.middleClick Connections { target: plasmoid.nativeInterface onComicsModelChanged: { comicTabbar.currentTab = comicTabbar.layout.children[1]; } onTabHighlightRequest: { for (var i = 0; i < comicTabbar.layout.children.length; ++i) { var button = comicTabbar.layout.children[i]; if (button.key !== undefined && button.key == id) { button.highlighted = highlight; } } } onShowNextNewStrip: { var firstButton = undefined; for (var i = 0; i < comicTabbar.layout.children.length; ++i) { var button = comicTabbar.layout.children[i]; if (button.key !== undefined && button.highlighted == true) { //key is ordered if (button.key > comicTabbar.currentTab.key) { comicTabbar.currentTab = button; return; } else if (firstButton === undefined){ firstButton = button; } } } if (firstButton !== undefined) { comicTabbar.currentTab = firstButton; } } } PlasmaCore.Svg { id: arrowsSvg imagePath: "widgets/arrows" } PlasmaComponents.TabBar{ id: comicTabbar anchors { left: parent.left right: parent.right } visible: plasmoid.nativeInterface.tabIdentifiers.length > 1 onCurrentTabChanged: { console.log("onCurrentTabChanged:" + comicTabbar.currentTab.key); plasmoid.nativeInterface.tabChanged(comicTabbar.currentTab.key); } Repeater { model: plasmoid.nativeInterface.comicsModel delegate: PlasmaComponents.TabButton { id: tabButton readonly property string key: model.key property bool highlighted: model.highlight text: model.title iconSource: model.icon } } } PlasmaComponents.Label { id: topInfo anchors { top: comicTabbar.visible ? comicTabbar.bottom : mainWindow.top left: mainWindow.left right: mainWindow.right } visible: (topInfo.text.length > 0) horizontalAlignment: Text.AlignHCenter text: (showComicAuthor || showComicTitle) ? getTopInfo() : "" function getTopInfo() { var tempTop = ""; if ( showComicTitle ) { tempTop = plasmoid.nativeInterface.comicData.title; tempTop += ( ( (plasmoid.nativeInterface.comicData.stripTitle.length > 0) && (plasmoid.nativeInterface.comicData.title.length > 0) ) ? " - " : "" ) + plasmoid.nativeInterface.comicData.stripTitle; } if ( showComicAuthor && (plasmoid.nativeInterface.comicData.author != undefined || plasmoid.nativeInterface.comicData.author.length > 0) ) { tempTop = ( tempTop.length > 0 ? plasmoid.nativeInterface.comicData.author + ": " + tempTop : plasmoid.nativeInterface.comicData.author ); } return tempTop; } } ComicCentralView { id: centerLayout anchors { left: mainWindow.left right: mainWindow.right bottom: (bottomInfo.visible) ? bottomInfo.top : mainWindow.bottom top: (topInfo.visible) ? topInfo.bottom : (comicTabbar.visible ? comicTabbar.bottom : mainWindow.top) topMargin: (comicTabbar.visible) ? 3 : 0 } visible: plasmoid.nativeInterface.tabIdentifiers.length > 0 comicData: plasmoid.nativeInterface.comicData } ComicBottomInfo { id:bottomInfo anchors { left: mainWindow.left right: mainWindow.right bottom: mainWindow.bottom } comicData: plasmoid.nativeInterface.comicData showUrl: plasmoid.nativeInterface.showComicUrl showIdentifier: plasmoid.nativeInterface.showComicIdentifier } PlasmaComponents.Button { anchors.centerIn: parent iconSource: "configure" text: i18nc("@action:button", "Configure...") visible: plasmoid.nativeInterface.tabIdentifiers.length == 0 onClicked: plasmoid.action("configure").trigger(); } states: [ State { name: "topInfoVisible" when: topInfo.visible && !bottomInfo.visible AnchorChanges { target: centerLayout anchors.top: topInfo.bottom } }, State { name: "bottomInfoVisible" when: bottomInfo.visible && !topInfo.visible AnchorChanges { target: centerLayout anchors.bottom: bottomInfo.top } }, State { name: "topBottomInfoVisible" when: bottomInfo.visible && topInfo.visible AnchorChanges { target: centerLayout anchors.top: topInfo.bottom anchors.bottom: bottomInfo.top } } ] transitions: Transition { AnchorAnimation { duration: 500 easing.type: Easing.InOutQuad } } } diff --git a/applets/fuzzy-clock/package/contents/ui/main.qml b/applets/fuzzy-clock/package/contents/ui/main.qml index ae151bd23..a830e8364 100644 --- a/applets/fuzzy-clock/package/contents/ui/main.qml +++ b/applets/fuzzy-clock/package/contents/ui/main.qml @@ -1,57 +1,59 @@ /* * Copyright 2013 Heena Mahour * Copyright 2013 Sebastian Kügler * Copyright 2014 Kai Uwe Broulik * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import QtQuick 2.0 import QtQuick.Layouts 1.1 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.calendar 2.0 as PlasmaCalendar Item { id: root readonly property date currentDateTime: dataSource.data.Local ? dataSource.data.Local.DateTime : new Date() width: units.gridUnit * 10 height: units.gridUnit * 4 Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation Plasmoid.toolTipMainText: Qt.formatTime(currentDateTime) Plasmoid.toolTipSubText: Qt.formatDate(currentDateTime, Qt.locale().dateFormat(Locale.LongFormat)) + Plasmoid.backgroundHints: PlasmaCore.Types.ShadowBackground | PlasmaCore.Types.ConfigurableBackground + PlasmaCore.DataSource { id: dataSource engine: "time" connectedSources: ["Local"] interval: 60000 intervalAlignment: PlasmaCore.Types.AlignToMinute } Plasmoid.compactRepresentation: FuzzyClock { } Plasmoid.fullRepresentation: PlasmaCalendar.MonthView { Layout.minimumWidth: units.gridUnit * 20 Layout.minimumHeight: units.gridUnit * 20 today: currentDateTime } } diff --git a/applets/quicklaunch/package/contents/ui/main.qml b/applets/quicklaunch/package/contents/ui/main.qml index 651f8365f..0777306cb 100644 --- a/applets/quicklaunch/package/contents/ui/main.qml +++ b/applets/quicklaunch/package/contents/ui/main.qml @@ -1,292 +1,293 @@ /* * Copyright 2015 David Rosca * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see */ import QtQuick 2.2 import QtQuick.Layouts 1.0 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.draganddrop 2.0 as DragAndDrop import org.kde.plasma.private.quicklaunch 1.0 import "layout.js" as LayoutManager Item { id: root readonly property int maxSectionCount: plasmoid.configuration.maxSectionCount readonly property bool showLauncherNames : plasmoid.configuration.showLauncherNames readonly property bool enablePopup : plasmoid.configuration.enablePopup readonly property string title : plasmoid.formFactor == PlasmaCore.Types.Planar ? plasmoid.configuration.title : "" readonly property bool vertical : plasmoid.formFactor == PlasmaCore.Types.Vertical || (plasmoid.formFactor == PlasmaCore.Types.Planar && height > width) readonly property bool horizontal : plasmoid.formFactor == PlasmaCore.Types.Horizontal property bool dragging : false Layout.minimumWidth: LayoutManager.minimumWidth() Layout.minimumHeight: LayoutManager.minimumHeight() Layout.preferredWidth: LayoutManager.preferredWidth() Layout.preferredHeight: LayoutManager.preferredHeight() Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation + Plasmoid.backgroundHints: PlasmaCore.Types.DefaultBackground | PlasmaCore.Types.ConfigurableBackground DragAndDrop.DropArea { anchors.fill: parent preventStealing: true enabled: !plasmoid.immutable onDragEnter: { if (event.mimeData.hasUrls) { dragging = true; } else { event.ignore(); } } onDragMove: { var index = grid.indexAt(event.x, event.y); if (isInternalDrop(event)) { launcherModel.moveUrl(event.mimeData.source.itemIndex, index); } else { launcherModel.showDropMarker(index); } popup.visible = root.childAt(event.x, event.y) == popupArrow; } onDragLeave: { dragging = false; launcherModel.clearDropMarker(); } onDrop: { dragging = false; launcherModel.clearDropMarker(); if (isInternalDrop(event)) { event.accept(Qt.IgnoreAction); saveConfiguration(); } else { var index = grid.indexAt(event.x, event.y); launcherModel.insertUrls(index == -1 ? launcherModel.count : index, event.mimeData.urls); event.accept(event.proposedAction); } } } PlasmaComponents.Label { id: titleLabel anchors { top: parent.top left: parent.left right: parent.right } height: theme.mSize(theme.defaultFont).height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignTop elide: Text.ElideMiddle text: title } Item { id: launcher anchors { top: title.length ? titleLabel.bottom : parent.top left: parent.left right: !vertical && popupArrow.visible ? popupArrow.left : parent.right bottom: vertical && popupArrow.visible ? popupArrow.top : parent.bottom } GridView { id: grid anchors.fill: parent interactive: false flow: horizontal ? GridView.FlowTopToBottom : GridView.FlowLeftToRight cellWidth: LayoutManager.preferredCellWidth() cellHeight: LayoutManager.preferredCellHeight() visible: count model: UrlModel { id: launcherModel } delegate: IconItem { } } PlasmaCore.IconItem { id: defaultIcon anchors.fill: parent source: "fork" visible: !grid.visible PlasmaCore.ToolTipArea { anchors.fill: parent icon: "fork" mainText: i18n("Quicklaunch") subText: i18nc("@info", "Add launchers by Drag and Drop or by using the context menu.") } } } PlasmaCore.Dialog { id: popup type: PlasmaCore.Dialog.PopupMenu flags: Qt.WindowStaysOnTopHint hideOnWindowDeactivate: true location: plasmoid.location visualParent: vertical ? popupArrow : root mainItem: Popup { } } PlasmaCore.ToolTipArea { id: popupArrow visible: enablePopup anchors { top: vertical ? undefined : parent.top right: parent.right bottom: parent.bottom } subText: popup.visible ? i18n("Hide icons") : i18n("Show hidden icons") MouseArea { id: arrowMouseArea anchors.fill: parent onClicked: { popup.visible = !popup.visible } PlasmaCore.Svg { id: arrowSvg imagePath: "widgets/arrows" } PlasmaCore.SvgItem { id: arrow anchors.centerIn: parent width: Math.min(parent.width, parent.height) height: width rotation: popup.visible ? 180 : 0 Behavior on rotation { RotationAnimation { duration: units.shortDuration * 3 } } svg: arrowSvg elementId: { if (plasmoid.location == PlasmaCore.Types.TopEdge) { return "down-arrow"; } else if (plasmoid.location == PlasmaCore.Types.LeftEdge) { return "right-arrow"; } else if (plasmoid.location == PlasmaCore.Types.RightEdge) { return "left-arrow"; } else if (vertical) { return "right-arrow"; } else { return "up-arrow"; } } } } } Logic { id: logic onLauncherAdded: { var m = isPopup ? popup.mainItem.popupModel : launcherModel; m.appendUrl(url); } onLauncherEdited: { var m = isPopup ? popup.mainItem.popupModel : launcherModel; m.changeUrl(index, url); } } // States to fix binding loop with enabled popup states: [ State { name: "normal" when: !vertical PropertyChanges { target: popupArrow width: units.iconSizes.smallMedium height: root.height } }, State { name: "vertical" when: vertical PropertyChanges { target: popupArrow width: root.width height: units.iconSizes.smallMedium } } ] Connections { target: plasmoid.configuration onLauncherUrlsChanged: { launcherModel.urlsChanged.disconnect(saveConfiguration); launcherModel.setUrls(plasmoid.configuration.launcherUrls); launcherModel.urlsChanged.connect(saveConfiguration); } } Component.onCompleted: { launcherModel.setUrls(plasmoid.configuration.launcherUrls); launcherModel.urlsChanged.connect(saveConfiguration); plasmoid.setAction("addLauncher", i18nc("@action", "Add Launcher..."), "list-add"); } function action_addLauncher() { logic.addLauncher(); } function saveConfiguration() { if (!dragging) { plasmoid.configuration.launcherUrls = launcherModel.urls(); } } function isInternalDrop(event) { return event.mimeData.source && event.mimeData.source.GridView && event.mimeData.source.GridView.view == grid; } } diff --git a/applets/systemloadviewer/package/contents/ui/BarMonitor.qml b/applets/systemloadviewer/package/contents/ui/BarMonitor.qml index 56e89280d..39de64022 100644 --- a/applets/systemloadviewer/package/contents/ui/BarMonitor.qml +++ b/applets/systemloadviewer/package/contents/ui/BarMonitor.qml @@ -1,60 +1,62 @@ /* * Copyright (C) 2014 Martin Yrjölä * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see */ import QtQuick 2.2 import QtQuick.Layouts 1.1 +import org.kde.plasma.core 2.0 as PlasmaCore + Item { id: barMonitor property var colors property var proportions Layout.fillHeight: true Layout.fillWidth: true Rectangle { id: barBorder anchors.fill: parent color: "transparent" radius: 3 opacity: .4 border { - color: theme.textColor + color: PlasmaCore.ColorScope.textColor width: 1 } } Repeater { id: barRepeater model: proportions.length ConditionallyRoundedRectangle { color: barMonitor.colors[index] height: (barBorder.height - barBorder.border.width) * barMonitor.proportions[index] borderRectangle: barBorder // Bars should always be below border z: -1 anchors { bottom: index == 0 ? barBorder.bottom : barRepeater.itemAt(index-1).top bottomMargin: index == 0 ? barBorder.border.width : 0 } } } } diff --git a/applets/systemloadviewer/package/contents/ui/CircularMonitor.qml b/applets/systemloadviewer/package/contents/ui/CircularMonitor.qml index bf2c821f8..735bbe99f 100644 --- a/applets/systemloadviewer/package/contents/ui/CircularMonitor.qml +++ b/applets/systemloadviewer/package/contents/ui/CircularMonitor.qml @@ -1,90 +1,92 @@ /* * Copyright (C) 2014 Martin Yrjölä * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see */ import QtQuick 2.0 import QtQuick.Layouts 1.1 +import org.kde.plasma.core 2.0 as PlasmaCore + Item { property alias colors: canvas.colors property alias proportions: canvas.proportions Layout.fillHeight: true Layout.fillWidth: true onProportionsChanged: { canvas.requestPaint() } Canvas { id: canvas readonly property int lineWidth: 1 readonly property bool fill: true readonly property bool stroke: true readonly property real alpha: 1.0 property var proportions property var colors // This fixes edge bleeding readonly property double filler: 0.01 width: parent.width height: Math.min(parent.height, parent.width) antialiasing: true onPaint: { var ctx = getContext("2d"); ctx.save(); ctx.clearRect(0,0,canvas.width, canvas.height); ctx.strokeStyle = canvas.strokeStyle; ctx.globalAlpha = canvas.alpha // Start from 6 o'clock var currentRadian = Math.PI/2 // Draw the sectors for (var i = 0; i < proportions.length; i++) { var radians = proportions[i] * 2 * Math.PI ctx.fillStyle = colors[i] ctx.beginPath(); ctx.arc(width/2, height/2, height/2.1, currentRadian, currentRadian + radians + filler, false) ctx.arc(width/2, height/2, height/4, currentRadian + radians + filler, currentRadian, true) currentRadian += radians - filler ctx.closePath(); ctx.fill(); } // Draw border ctx.fillStyle = "transparent" - ctx.strokeStyle = theme.textColor + ctx.strokeStyle = PlasmaCore.ColorScope.textColor ctx.lineWidth = canvas.lineWidth ctx.globalAlpha = .4 ctx.beginPath(); ctx.arc(width/2, height/2, height/2.1, Math.PI/2, 5*Math.PI/2, false) ctx.moveTo(width/2,height/2+height/4); ctx.arc(width/2, height/2, height/4, Math.PI/2, 5*Math.PI/2, false) ctx.fillRule = Qt.OddEvenFill ctx.fill(); ctx.stroke(); ctx.restore(); } } } diff --git a/applets/systemloadviewer/package/contents/ui/SystemLoadViewer.qml b/applets/systemloadviewer/package/contents/ui/SystemLoadViewer.qml index 279dba02e..196ad4c15 100644 --- a/applets/systemloadviewer/package/contents/ui/SystemLoadViewer.qml +++ b/applets/systemloadviewer/package/contents/ui/SystemLoadViewer.qml @@ -1,556 +1,558 @@ /* * Copyright (C) 2014 Martin Yrjölä * Copyright (C) 2015 Joshua Worth * Copyright (C) 2015 Kåre Särs * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see */ import QtQuick 2.2 import QtQuick.Layouts 1.1 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.kio 1.0 as Kio import org.kde.plasma.plasmoid 2.0 Item { id: main + Plasmoid.backgroundHints: PlasmaCore.Types.DefaultBackground | PlasmaCore.Types.ConfigurableBackground + readonly property double maxCpuLoad: 100.0 readonly property int borderWidth: 1 readonly property int borderRounding: 3 readonly property int headingLevel: 2 readonly property bool setColorsManually: plasmoid.configuration.setColorsManually readonly property var cpuColors: setColorsManually ? [plasmoid.configuration.cpuSysColor, plasmoid.configuration.cpuUserColor, plasmoid.configuration.cpuNiceColor, plasmoid.configuration.cpuIOWaitColor] : [theme.buttonFocusColor, theme.highlightColor, theme.visitedLinkColor, theme.linkColor] readonly property var memoryColors: setColorsManually ? [plasmoid.configuration.memApplicationColor, plasmoid.configuration.memBuffersColor] : [theme.buttonFocusColor, theme.visitedLinkColor] readonly property var swapColors: setColorsManually ? [plasmoid.configuration.swapUsedColor] : [theme.highlightColor] readonly property var cacheColors: setColorsManually ? [plasmoid.configuration.cacheDirtyColor, plasmoid.configuration.cacheWritebackColor] : [theme.buttonFocusColor, theme.visitedLinkColor] // Make labels visible first time so that the // user knows which monitor is which. implicitWidth: widestLabelWidth()*1.3 * columnCount() implicitHeight: implicitWidth / 2 readonly property bool circularMonitorsInUse: plasmoid.configuration.monitorType == 1 readonly property bool compactBarMonitorsInUse: plasmoid.configuration.monitorType == 2 readonly property bool allCPUsShown: plasmoid.configuration.cpuAllActivated readonly property double barsWidth: compactBarMonitorsInUse ? main.height * 0.35 * columnCount() : main.height * 0.5 * columnCount() // Don't show icon in panel. Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation // Correct the size when in panel Layout.preferredWidth: { if (circularMonitorsInUse) { return parent.height * 1.2 * columnCount() } else if (!plasmoid.configuration.cpuAllActivated) { return barsWidth + rowLayout.spacing * (columnCount() - 1) // 0 * x == 0 (compact) } // else plasmoid.configuration.cpuAllActivated var wantedWidth = cpusRow.minWidth if (plasmoid.configuration.swapActivated) { wantedWidth += memColumn.minWidth } if (plasmoid.configuration.memoryActivated) { wantedWidth += swapColumn.minWidth } if (plasmoid.configuration.cacheActivated) { wantedWidth += cacheColumn.minWidth } return wantedWidth } Layout.minimumWidth: { if (circularMonitorsInUse) { return units.gridUnit * columnCount() * 2 } else if (!plasmoid.configuration.cpuAllActivated) { return memColumn.minWidth * columnCount() + rowLayout.spacing * (columnCount() - 1) } var wantedWidth = cpusRow.minWidth if (plasmoid.configuration.swapActivated) { wantedWidth += memColumn.minWidth } if (plasmoid.configuration.memoryActivated) { wantedWidth += swapColumn.minWidth } if (plasmoid.configuration.cacheActivated) { wantedWidth += cacheColumn.minWidth } return wantedWidth } property bool labelsVisible Kio.KRun { id: kRun } PlasmaCore.DataSource { id: dataSource engine: "systemmonitor" readonly property string cpuSystem: "cpu/system/" readonly property string niceLoad: cpuSystem + "nice" readonly property string userLoad: cpuSystem + "user" readonly property string sysLoad: cpuSystem + "sys" readonly property string ioWait: cpuSystem + "wait" readonly property string averageClock: cpuSystem + "AverageClock" readonly property string totalLoad: cpuSystem + "TotalLoad" readonly property string memPhysical: "mem/physical/" readonly property string memFree: memPhysical + "free" readonly property string memApplication: memPhysical + "application" readonly property string memBuffers: memPhysical + "buf" readonly property string memUsed: memPhysical + "used" readonly property string swap: "mem/swap/" readonly property string swapUsed: swap + "used" readonly property string swapFree: swap + "free" readonly property string cache: "mem/cache/" readonly property string cacheDirty: cache + "dirty" readonly property string cacheWriteback: cache + "writeback" readonly property string cores: "system/cores" property var totalCpuLoadProportions: [.0, .0, .0, .0] property int maxCpuIndex: 0 property var memoryUsageProportions: [.0, .0] property double swapUsageProportion: .0 property var cacheUsageProportions: [.0, .0] property double maxCache: 0.0 connectedSources: [ cores ] function sources() { var array = [niceLoad, userLoad, sysLoad, ioWait, memFree, memApplication, memBuffers, memUsed, swapUsed, swapFree, averageClock, totalLoad, cores, cacheDirty, cacheWriteback] if (plasmoid.configuration.cpuAllActivated) { for (var i = 0; i <= maxCpuIndex; i++) { array.push("cpu/cpu" + i + "/TotalLoad"); array.push("cpu/cpu" + i + "/clock"); array.push("cpu/cpu" + i + "/nice"); array.push("cpu/cpu" + i + "/user"); array.push("cpu/cpu" + i + "/sys"); array.push("cpu/cpu" + i + "/wait"); } } return array; } onNewData: { if (sourceName == sysLoad) { totalCpuLoadProportions[0] = fitCpuLoad(data.value) } else if (sourceName == userLoad) { totalCpuLoadProportions[1] = fitCpuLoad(data.value) } else if (sourceName == niceLoad) { totalCpuLoadProportions[2] = fitCpuLoad(data.value) } else if (sourceName == ioWait) { totalCpuLoadProportions[3] = fitCpuLoad(data.value) totalCpuLoadProportionsChanged() } else if (sourceName == memApplication) { memoryUsageProportions[0] = fitMemoryUsage(data.value) } else if (sourceName == memBuffers) { memoryUsageProportions[1] = fitMemoryUsage(data.value) memoryUsageProportionsChanged() } else if (sourceName == swapUsed) { swapUsageProportion = fitSwapUsage(data.value) swapUsageProportionChanged() } else if (sourceName == cacheWriteback) { cacheUsageProportions = fitCacheUsage() cacheUsageProportionsChanged() } else if (sourceName == cores) { maxCpuIndex = data.value - 1 connectedSources = sources() } } interval: 1000 * plasmoid.configuration.updateInterval } onWidthChanged: labelsVisible = shouldLabelsBeVisible() onAllCPUsShownChanged: labelsVisible = shouldLabelsBeVisible() function toolTipSubText() { var cpuLoadPart = ""; var cpuClockPart = ""; if (plasmoid.configuration.cpuAllActivated) { for (var i=0; i<=dataSource.maxCpuIndex; i++) { if (i>0) { cpuLoadPart += "\n" } var totalName = "cpu/cpu" + i + "/TotalLoad" var clockName = "cpu/cpu" + i + "/clock" var totValue = dataSource.data[totalName] ? dataSource.data[totalName].value : 0 var clockValue = dataSource.data[clockName] ? dataSource.data[clockName].value : 0 cpuLoadPart += i18n("CPU%1: %2% @ %3 Mhz", i, Math.round(totValue), Math.round(clockValue)) } } else { var cpuLoad = dataSource.data[dataSource.totalLoad] ? dataSource.data[dataSource.totalLoad].value : 0 var averageClock = dataSource.data[dataSource.averageClock] ? dataSource.data[dataSource.averageClock].value : 0 cpuLoadPart = i18n("CPU: %1%", Math.round(cpuLoad)) cpuClockPart = i18n("Average clock: %1 MHz", Math.round(averageClock)) } var memFree = parseFloat(dataSource.data[dataSource.memFree] ? dataSource.data[dataSource.memFree].value : 0) / 1024 var memUsed = parseFloat(dataSource.data[dataSource.memUsed] ? dataSource.data[dataSource.memUsed].value : 0) / 1024 var memApplication = parseFloat(dataSource.data[dataSource.memApplication] ? dataSource.data[dataSource.memApplication].value : 0) / 1024 var memTotal = memFree + memUsed var memoryPart = i18n("Memory: %1/%2 MiB", Math.round(memApplication), Math.round(memTotal)) var swapFree = parseFloat(dataSource.data[dataSource.swapFree] ? dataSource.data[dataSource.swapFree].value : 0) / 1024 var swapUsed = parseFloat(dataSource.data[dataSource.swapUsed] ? dataSource.data[dataSource.swapUsed].value : 0) / 1024 var swapTotal = swapFree + swapUsed var swapPart = i18n("Swap: %1/%2 MiB", Math.round(swapUsed), Math.round(swapTotal)) var cacheDirty = parseFloat(dataSource.data[dataSource.cacheDirty].value) / 1024 var cacheWriteback = parseFloat(dataSource.data[dataSource.cacheWriteback].value) / 1024 var cachePart = i18n("Cache Dirty, Writeback: %1 MiB, %2 MiB", Math.round(cacheDirty), Math.round(cacheWriteback)) if (cpuClockPart === "") { return [cpuLoadPart, memoryPart, swapPart, cachePart].join("\n") } return [cpuLoadPart, cpuClockPart, memoryPart, swapPart, cachePart].join("\n") } function fitCpuLoad(load) { var x = load / maxCpuLoad; if (isNaN(x)) {return 0;} return Math.min(x, 1); // Ensure that we do not get values that might cause problems } function fitMemoryUsage(usage) { if (!dataSource.data[dataSource.memFree] || !dataSource.data[dataSource.memUsed]) return 0; var x = (usage / (parseFloat(dataSource.data[dataSource.memFree].value) + parseFloat(dataSource.data[dataSource.memUsed].value))) if (isNaN(x)) {return 0;} return Math.min(x, 1); } function fitSwapUsage(usage) { if (!dataSource.data[dataSource.swapFree]) return 0; var x = (usage / (parseFloat(usage) + parseFloat(dataSource.data[dataSource.swapFree].value))) if (isNaN(x)) {return 0;} return Math.min(x, 1); } function fitCacheUsage() { var values = [ parseFloat(dataSource.data[dataSource.cacheDirty].value), parseFloat(dataSource.data[dataSource.cacheWriteback].value) ]; var total = values[0] + values[1]; var props = [.0, .0]; // hide the persistent small amount of dirty cache (10M seems a good threshold) if ( total < 10000 ) { dataSource.maxCache = 0; return props; } if (total > dataSource.maxCache) { dataSource.maxCache = total; } for (var i = 0; i < values.length; i++) { props[i] = values[i] / dataSource.maxCache; if (isNaN(props[i])) { props[i] = 0; } else { props[i] = Math.min(props[i], 0.99); } } return props; } function columnCount() { var columns = 0; var activeMonitors = [plasmoid.configuration.cpuActivated, plasmoid.configuration.memoryActivated, plasmoid.configuration.swapActivated, plasmoid.configuration.cacheActivated] for (var i = 0; i < activeMonitors.length; i++) { if (activeMonitors[i]) { columns++; } } return columns } function columnWidth(compact) { var columns = columnCount(); var width = rowLayout.width / columns; if (!compact) { width -= rowLayout.spacing * (columns - 1); } return width; } function widestLabelWidth() { var widest = 0; if (plasmoid.configuration.cpuActivated) { widest = cpuLabel.paintedWidth } if (plasmoid.configuration.memoryActivated) { widest = Math.max(widest, memoryLabel.paintedWidth) } if (plasmoid.configuration.swapActivated) { widest = Math.max(widest, swapLabel.paintedWidth) } if (plasmoid.configuration.cacheActivated) { widest = Math.max(widest, cacheLabel.paintedWidth) } return widest } // Hide all labels when one of them is wider than the column width function shouldLabelsBeVisible() { if (plasmoid.configuration.cpuAllActivated) { return false; } return widestLabelWidth() <= columnWidth() } PlasmaCore.ToolTipArea { id: stdToolTip anchors.fill: parent active: true mainText: i18n("System load") subText: toolTipSubText() visible: !plasmoid.configuration.cpuAllActivated || dataSource.maxCpuIndex < 5 MouseArea { anchors.fill: parent hoverEnabled: true onClicked: { kRun.openService("org.kde.ksysguard") } } } PlasmaCore.ToolTipArea { anchors.fill: parent active: true visible: !stdToolTip.visible mainItem: Item { height: childrenRect.height + units.gridUnit * 2 width: childrenRect.width + units.gridUnit * 2 ColumnLayout { anchors { top: parent.top left:parent.left margins: units.gridUnit } PlasmaExtras.Heading { id: tooltipMaintext level: 3 text: stdToolTip.mainText } PlasmaComponents.Label { id: tooltipSubtext text: toolTipSubText() opacity: 0.7 } } } MouseArea { anchors.fill: parent hoverEnabled: true onClicked: { kRun.openService("org.kde.ksysguard") } } } RowLayout { id: rowLayout anchors { fill: main } spacing: main.compactBarMonitorsInUse ? 0 : 5 RowLayout { id: cpusRow readonly property int minCpuWidth: memColumn.minWidth * 0.33 readonly property int minWidth : Math.max(memColumn.minWidth * 2, cpuRepeater.count * minCpuWidth) visible: plasmoid.configuration.cpuActivated && plasmoid.configuration.cpuAllActivated Layout.minimumWidth: minWidth Layout.preferredWidth: height * 2 spacing: 0 Repeater { id: cpuRepeater model: (dataSource.maxCpuIndex+1) delegate: ColumnLayout { Layout.minimumWidth: cpusRow.minCpuWidth readonly property int cpuIndex: index PlasmaExtras.Heading { id: cpuLabel level: main.headingLevel text: i18n("CPU %1", cpuIndex) visible: main.labelsVisible horizontalAlignment: Text.AlignHCenter Layout.fillWidth: true } ConditionallyLoadedMonitors { colors: cpuColors readonly property string niceLoad: "cpu/cpu" + cpuIndex + "/nice" readonly property string userLoad: "cpu/cpu" + cpuIndex + "/user" readonly property string sysLoad: "cpu/cpu" + cpuIndex + "/sys" readonly property string ioWait: "cpu/cpu" + cpuIndex + "/wait" readonly property var cpuLoadProportions: dataSource.data[ioWait] ? [ fitCpuLoad(dataSource.data[sysLoad].value), fitCpuLoad(dataSource.data[userLoad].value), fitCpuLoad(dataSource.data[niceLoad].value), fitCpuLoad(dataSource.data[ioWait].value) ] : [.0, .0, .0, .0] proportions: cpuLoadProportions } } } } ColumnLayout { id: cpuColumn readonly property double minWidth: memColumn.minWidth visible: plasmoid.configuration.cpuActivated && !plasmoid.configuration.cpuAllActivated Layout.minimumWidth: minWidth Layout.preferredWidth: height PlasmaExtras.Heading { id: cpuLabel level: main.headingLevel text: i18n("CPU") visible: main.labelsVisible horizontalAlignment: Text.AlignHCenter Layout.fillWidth: true } ConditionallyLoadedMonitors { colors: cpuColors proportions: dataSource.totalCpuLoadProportions } } ColumnLayout { id: memColumn readonly property double minWidth: units.gridUnit * 0.7 visible: plasmoid.configuration.memoryActivated Layout.minimumWidth: minWidth Layout.preferredWidth: height PlasmaExtras.Heading { id: memoryLabel level: main.headingLevel text: i18n("Memory") visible: main.labelsVisible horizontalAlignment: Text.AlignHCenter Layout.fillWidth: true } ConditionallyLoadedMonitors { colors: memoryColors proportions: dataSource.memoryUsageProportions } } ColumnLayout { id: swapColumn readonly property double minWidth: memColumn.minWidth visible: plasmoid.configuration.swapActivated Layout.minimumWidth: minWidth Layout.preferredWidth: height PlasmaExtras.Heading { id: swapLabel level: main.headingLevel text: i18n("Swap") visible: main.labelsVisible horizontalAlignment: Text.AlignHCenter Layout.fillWidth: true } ConditionallyLoadedMonitors { colors: swapColors proportions: [dataSource.swapUsageProportion] } } ColumnLayout { id: cacheColumn readonly property double minWidth: memColumn.minWidth visible: plasmoid.configuration.cacheActivated Layout.minimumWidth: minWidth Layout.preferredWidth: height PlasmaExtras.Heading { id: cacheLabel level: main.headingLevel text: i18n("Cache") visible: main.labelsVisible horizontalAlignment: Text.AlignHCenter Layout.fillWidth: true } ConditionallyLoadedMonitors { colors: cacheColors proportions: dataSource.cacheUsageProportions } } } // rowLayout } // main diff --git a/applets/timer/package/contents/ui/main.qml b/applets/timer/package/contents/ui/main.qml index 02de4f52a..8e893211e 100644 --- a/applets/timer/package/contents/ui/main.qml +++ b/applets/timer/package/contents/ui/main.qml @@ -1,207 +1,209 @@ /*************************************************************************** * Copyright 2016 Michael Abrahams * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ import QtQuick 2.2 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.kquickcontrolsaddons 2.0 as QtExtra import org.kde.plasma.private.timer 0.1 as TimerPlasmoid Item { id: root; readonly property variant predefinedTimers: plasmoid.configuration.predefinedTimers; + Plasmoid.backgroundHints: PlasmaCore.Types.ShadowBackground | PlasmaCore.Types.ConfigurableBackground + property int seconds : restoreToSeconds(plasmoid.configuration.running, plasmoid.configuration.savedAt, plasmoid.configuration.seconds); // show notification on timer completion (default: enabled) property bool showNotification: plasmoid.configuration.showNotification; // run custom command on timer completion (default: disabled) property bool runCommand: plasmoid.configuration.runCommand; property string command: plasmoid.configuration.command; // show title (can be customized in the settings dialog, default: disabled) readonly property bool showTitle: plasmoid.configuration.showTitle; readonly property string title: plasmoid.configuration.title; property bool running: (plasmoid.configuration.running > 0) ? true : false; property bool suspended: false; readonly property string notificationText: plasmoid.configuration.notificationText; Plasmoid.toolTipMainText: { var timerName = ""; if (showTitle && title != "") { timerName = title; } else { timerName = i18n("Timer"); } var toolTipText = ""; if (running) { toolTipText = i18n("%1 is running", timerName); } else { toolTipText = i18n("%1 not running", timerName); } return toolTipText; } Plasmoid.toolTipSubText: i18np("Remaining time left: %1 second", "Remaining time left: %1 seconds", seconds); Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation Plasmoid.compactRepresentation: TimerView { } Plasmoid.fullRepresentation: TimerView { } PlasmaCore.DataSource { id: notificationSource engine: "notifications" connectedSources: "org.freedesktop.Notifications" } Timer { id: t; interval: 1000; onTriggered: { if (root.seconds != 0) { root.seconds--; } if (root.seconds == 0) { root.running = false; if (showNotification) { root.createNotification(); } if (runCommand) { TimerPlasmoid.Timer.runCommand(command); } saveTimer(); } } repeat: true; running: root.running; } Timer { id: delayedSaveTimer; interval: 3000; onTriggered: saveTimer(); } function onDigitHasChanged() { delayedSaveTimer.stop(); delayedSaveTimer.start(); } function createNotification() { var service = notificationSource.serviceForSource("notification"); var operation = service.operationDescription("createNotification"); operation.appName = root.title || i18n("Timer"); operation["appIcon"] = "chronometer"; operation.summary = notificationText || i18n("Timer finished") operation["body"] = ""; operation["timeout"] = 2000; service.startOperationCall(operation); } Component.onCompleted: { plasmoid.setAction("timerStart", i18nc("@action", "&Start")); plasmoid.setAction("timerStop", i18nc("@action", "S&top")); plasmoid.setAction("timerReset", i18nc("@action", "&Reset")); plasmoid.setActionSeparator("separator0"); for (var predefinedTimer in plasmoid.configuration.predefinedTimers) { plasmoid.setAction("predefined_timer_" + plasmoid.configuration.predefinedTimers[predefinedTimer], secondsToDisplayableString(plasmoid.configuration.predefinedTimers[predefinedTimer])); } plasmoid.setActionSeparator("separator1"); } function secondsToDisplayableString(sec) { return ~~((sec / (60*60)) / 10) + "" + (~~(~~(sec / (60*60))) % 10) + ":" + ~~(~~((sec % (60*60)) / 60) / 10) + "" + ~~((sec % (60*60)) / 60) % 10 + ":" + ~~((sec % 60) / 10) + "" + (sec % 60) % 10; } function startTimer() { running = true; suspended = false; opacityNeedsReset(); saveTimer(); } function stopTimer() { running = false; suspended = true; saveTimer(); } function resetTimer() { running = false; suspended = false; seconds = 0; opacityNeedsReset(); saveTimer(); } signal opacityNeedsReset() signal digitHasChanged() function saveTimer() { plasmoid.configuration.running = running ? seconds : 0; plasmoid.configuration.savedAt = new Date(); plasmoid.configuration.seconds = seconds } function actionTriggered(actionName) { if (actionName.indexOf("predefined_timer_") == 0) { seconds = actionName.replace("predefined_timer_", ""); startTimer(); } } function restoreToSeconds(cRunning, cSavedAt, cSeconds) { if (cRunning > 0) { var elapsedSeconds = cRunning - ~~(~~(((new Date()).getTime() - cSavedAt.getTime()) / 1000)); if (elapsedSeconds >= 0) { return elapsedSeconds; } else { return 0; } } else { return cSeconds; } } function action_timerStart() { startTimer(); } function action_timerStop() { stopTimer(); } function action_timerReset() { resetTimer(); } }