Commit c8080e5c authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[Kickoff] Support non-square icons

You can load custom icons through icon dialog, so support non-square icons just like Kicker does. Code mostly from Kicker.

Differential Revision: https://phabricator.kde.org/D12161
parent 5a1e4395
......@@ -37,6 +37,7 @@ Item {
|| plasmoid.location == PlasmaCore.Types.RightEdge
|| plasmoid.location == PlasmaCore.Types.BottomEdge
|| plasmoid.location == PlasmaCore.Types.LeftEdge)
readonly property bool vertical: (plasmoid.formFactor == PlasmaCore.Types.Vertical)
Plasmoid.switchWidth: units.gridUnit * 20
Plasmoid.switchHeight: units.gridUnit * 30
......@@ -46,14 +47,38 @@ Item {
Plasmoid.icon: plasmoid.configuration.icon
Plasmoid.compactRepresentation: MouseArea {
//AppletQuickItem expects a layout to exist
//setting even a default property forces it to be created
Layout.fillWidth: false
id: compactRoot
Layout.maximumWidth: inPanel ? units.iconSizeHints.panel : -1
Layout.maximumHeight: inPanel ? units.iconSizeHints.panel : -1
hoverEnabled: true
onClicked: plasmoid.expanded = !plasmoid.expanded
onWidthChanged: updateSizeHints()
onHeightChanged: updateSizeHints()
function updateSizeHints() {
if (kickoff.vertical) {
var scaledHeight = Math.floor(parent.width * (buttonIcon.implicitHeight / buttonIcon.implicitWidth));
compactRoot.Layout.minimumHeight = scaledHeight;
compactRoot.Layout.maximumHeight = scaledHeight;
compactRoot.Layout.minimumWidth = units.iconSizes.small;
compactRoot.Layout.maximumWidth = inPanel ? units.iconSizeHints.panel : -1;
} else {
var scaledWidth = Math.floor(parent.height * (buttonIcon.implicitWidth / buttonIcon.implicitHeight));
compactRoot.Layout.minimumWidth = scaledWidth;
compactRoot.Layout.maximumWidth = scaledWidth;
compactRoot.Layout.minimumHeight = units.iconSizes.small;
compactRoot.Layout.maximumHeight = inPanel ? units.iconSizeHints.panel : -1;
}
}
Connections {
target: units.iconSizeHints
onPanelChanged: compactRoot.updateSizeHints()
}
DropArea {
id: compactDragArea
anchors.fill: parent
......@@ -67,10 +92,18 @@ Item {
}
PlasmaCore.IconItem {
id: buttonIcon
readonly property double aspectRatio: (vertical ? implicitHeight / implicitWidth
: implicitWidth / implicitHeight)
anchors.fill: parent
source: plasmoid.icon
active: parent.containsMouse || compactDragArea.containsDrag
smooth: true
roundToIconSize: aspectRatio === 1
onSourceChanged: updateSizeHints()
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment