-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
273 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,103 @@ | ||
import QtQuick | ||
import QtQuick.Layouts | ||
import org.kde.kirigami as Kirigami | ||
import org.kde.plasma.core as PlasmaCore | ||
import org.kde.plasma.plasmoid | ||
import org.kde.plasma.workspace.components as WorkspaceComponents | ||
import "components" as Components | ||
|
||
MouseArea { | ||
id: compact | ||
anchors.fill: parent | ||
property bool isPanelVertical: plasmoid.formFactor === PlasmaCore.Types.Vertical | ||
property real itemSize: Math.min(compact.height, compact.width) | ||
Loader { | ||
id: compactRoot | ||
|
||
property var engineIcon | ||
property color badgeColor | ||
property var usageNow | ||
property var currentUsage | ||
|
||
readonly property bool vertical: (Plasmoid.formFactor == PlasmaCore.Types.Vertical) | ||
// 0: disable, 1: badge, 2: beside icon | ||
readonly property int showUsageMode: Plasmoid.configuration.showUsageMode | ||
// 0: percentage, 1: color | ||
readonly property int badgeStyle: Plasmoid.configuration.badgeStyle | ||
// 0: current engine, 1: total (rc6) | ||
readonly property int usageSource: Plasmoid.configuration.usageSource | ||
readonly property bool useBadge: showUsageMode === 1 || Plasmoid.configuration.needsToBeSquare | ||
|
||
hoverEnabled: true | ||
onClicked: { | ||
main.expanded = !main.expanded | ||
sourceComponent: (showUsageMode !== 0 && !useBadge) ? iconAndTextComponent : iconComponent | ||
// sourceComponent: iconComponent | ||
Layout.fillWidth: compactRoot.vertical | ||
Layout.fillHeight: !compactRoot.vertical | ||
Layout.minimumWidth: item.Layout.minimumWidth | ||
Layout.minimumHeight: item.Layout.minimumHeight | ||
|
||
MouseArea { | ||
id: compactMouseArea | ||
anchors.fill: parent | ||
|
||
hoverEnabled: true | ||
|
||
onClicked: { | ||
main.expanded = !main.expanded | ||
} | ||
} | ||
|
||
Item { | ||
id: container | ||
height: compact.itemSize | ||
width: compact.width | ||
anchors.centerIn: parent | ||
Component { | ||
id: iconComponent | ||
|
||
Components.PlasmoidIcon { | ||
Kirigami.Icon { | ||
id: plasmoidIcon | ||
height: Kirigami.Units.iconSizes.roundedIconSize(Math.min(parent.width, parent.height)) | ||
width: height | ||
source: engineIcon | ||
} | ||
readonly property int minIconSize: Math.max((compactRoot.vertical ? compactRoot.width : compactRoot.height), Kirigami.Units.iconSizes.small) | ||
|
||
Item { | ||
id: innerRectangle | ||
width: plasmoidIcon.width * 0.7 | ||
height: plasmoidIcon.height * 0.7 | ||
anchors.centerIn: parent | ||
} | ||
source: Plasmoid.icon | ||
active: compactMouseArea.containsMouse | ||
// reset implicit size, so layout in free dimension does not stop at the default one | ||
implicitWidth: Kirigami.Units.iconSizes.small | ||
implicitHeight: Kirigami.Units.iconSizes.small | ||
Layout.minimumWidth: compactRoot.vertical ? Kirigami.Units.iconSizes.small : minIconSize | ||
Layout.minimumHeight: compactRoot.vertical ? minIconSize : Kirigami.Units.iconSizes.small | ||
|
||
Rectangle { | ||
visible: true | ||
anchors { | ||
horizontalCenter: innerRectangle.right | ||
verticalCenter: innerRectangle.bottom | ||
WorkspaceComponents.BadgeOverlay { | ||
anchors.bottom: parent.bottom | ||
anchors.right: parent.right | ||
visible: showUsageMode === 1 && badgeStyle === 0 | ||
text: parseInt(currentUsage) + "%" | ||
icon: parent | ||
} | ||
|
||
Rectangle { | ||
anchors.centerIn: parent | ||
width: Math.min(plasmoidIcon.width, plasmoidIcon.height) * 0.7 | ||
height: width | ||
color: "transparent" | ||
Rectangle { | ||
anchors { | ||
horizontalCenter: parent.right | ||
verticalCenter: parent.bottom | ||
} | ||
visible: showUsageMode === 1 && badgeStyle === 1 | ||
|
||
property Item icon: plasmoidIcon | ||
property real scaling: 1 | ||
color: badgeColor | ||
width: Math.min(parseInt(icon.height / 2.5) , 10) | ||
height: width | ||
radius: width / 2 | ||
opacity: 1 | ||
border.width: 1 | ||
border.color: Kirigami.Theme.backgroundColor | ||
smooth: true | ||
} | ||
} | ||
// visible: !isPanelVertical | ||
|
||
property Item icon: plasmoidIcon | ||
property real scaling: 1 | ||
color: badgeColor | ||
width: Math.min(parseInt(icon.height / 2.5) , 10) | ||
height: width | ||
radius: width / 2 | ||
opacity: 1 | ||
border.width: 1 | ||
border.color: Kirigami.Theme.backgroundColor //PlasmaCore.ColorScope.backgroundColor | ||
smooth: true | ||
} | ||
} | ||
|
||
Component { | ||
id: iconAndTextComponent | ||
|
||
IconAndTextItem { | ||
vertical: compactRoot.vertical | ||
iconSource: Plasmoid.icon | ||
active: compactMouseArea.containsMouse | ||
text: parseInt(currentUsage) + "%" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2018 Friedrich W. H. Kossebau <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-or-later | ||
*/ | ||
|
||
import QtQuick | ||
|
||
import QtQuick.Layouts | ||
|
||
import org.kde.kirigami as Kirigami | ||
import org.kde.plasma.components as PlasmaComponents | ||
|
||
GridLayout { | ||
id: iconAndTextRoot | ||
|
||
property alias iconSource: icon.source | ||
property alias text: label.text | ||
property bool vertical: false // too bad we cannot make this an enum | ||
property alias active: icon.active | ||
|
||
readonly property int minimumIconSize: Kirigami.Units.iconSizes.small | ||
readonly property int iconSize: iconAndTextRoot.vertical ? width : height | ||
|
||
columns: iconAndTextRoot.vertical ? 1 : 2 | ||
rows: iconAndTextRoot.vertical ? 2 : 1 | ||
|
||
columnSpacing: 0 | ||
rowSpacing: 0 | ||
|
||
Kirigami.Icon { | ||
id: icon | ||
|
||
readonly property int implicitMinimumIconSize: Math.max(iconSize, minimumIconSize) | ||
// reset implicit size, so layout in free dimension does not stop at the default one | ||
implicitWidth: minimumIconSize | ||
implicitHeight: minimumIconSize | ||
|
||
Layout.fillWidth: iconAndTextRoot.vertical | ||
Layout.fillHeight: !iconAndTextRoot.vertical | ||
Layout.minimumWidth: iconAndTextRoot.vertical ? minimumIconSize : implicitMinimumIconSize | ||
Layout.minimumHeight: iconAndTextRoot.vertical ? implicitMinimumIconSize : minimumIconSize | ||
} | ||
|
||
Item { | ||
id: text | ||
|
||
// Otherwise it takes up too much space while loading | ||
visible: label.text.length > 0 | ||
|
||
Layout.fillWidth: iconAndTextRoot.vertical | ||
Layout.fillHeight: !iconAndTextRoot.vertical | ||
Layout.minimumWidth: iconAndTextRoot.vertical ? 0 : sizehelper.paintedWidth | ||
Layout.maximumWidth: iconAndTextRoot.vertical ? Infinity : Layout.minimumWidth | ||
|
||
Layout.minimumHeight: iconAndTextRoot.vertical ? sizehelper.paintedHeight : 0 | ||
Layout.maximumHeight: iconAndTextRoot.vertical ? Layout.minimumHeight : Infinity | ||
|
||
Text { | ||
id: sizehelper | ||
|
||
font { | ||
family: label.font.family | ||
weight: label.font.weight | ||
italic: label.font.italic | ||
pixelSize: iconAndTextRoot.vertical ? Kirigami.Units.gridUnit * 2 : 1024 // random "big enough" size - this is used as a max pixelSize by the fontSizeMode | ||
} | ||
minimumPixelSize: Math.round(Kirigami.Units.gridUnit / 2) | ||
fontSizeMode: iconAndTextRoot.vertical ? Text.HorizontalFit : Text.VerticalFit | ||
wrapMode: Text.NoWrap | ||
|
||
horizontalAlignment: Text.AlignHCenter | ||
verticalAlignment: Text.AlignVCenter | ||
anchors { | ||
leftMargin: Kirigami.Units.smallSpacing | ||
rightMargin: Kirigami.Units.smallSpacing | ||
} | ||
// These magic values are taken from the digital clock, so that the | ||
// text sizes here are identical with various clock text sizes | ||
height: { | ||
const textHeightScaleFactor = (parent.height > 26) ? 0.7 : 0.9; | ||
return Math.min (parent.height * textHeightScaleFactor, 3 * Kirigami.Theme.defaultFont.pixelSize); | ||
} | ||
visible: false | ||
|
||
// pattern to reserve some constant space TODO: improve and take formatting/i18n into account | ||
text: "888° X" | ||
textFormat: Text.PlainText | ||
} | ||
|
||
PlasmaComponents.Label { | ||
id: label | ||
|
||
font { | ||
weight: Font.Normal | ||
pixelSize: 1024 | ||
} | ||
minimumPixelSize: Math.round(Kirigami.Units.gridUnit / 2) | ||
fontSizeMode: Text.Fit | ||
textFormat: Text.PlainText | ||
wrapMode: Text.NoWrap | ||
|
||
height: 0 | ||
width: 0 | ||
verticalAlignment: Text.AlignVCenter | ||
horizontalAlignment: Text.AlignHCenter | ||
anchors { | ||
fill: parent | ||
leftMargin: Kirigami.Units.smallSpacing | ||
rightMargin: Kirigami.Units.smallSpacing | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters