Commit 6eec434c authored by Denys Madureira's avatar Denys Madureira 🐕 Committed by Nate Graham
Browse files

applets/kickoff: add option to display only label instead of icon

This commit allows the user of Kickoff on a horizontal panel to
optionally add text to the panel button and/or remove the icon from it.
These options are disabled when Kickoff is located on a vertical panel
because there is not enough room there.

This allows the user to mimic the UI used to open XFCE and Mate's menus,
or GNOME's Activities Overview.
parent b8e9000c
Pipeline #217617 passed with stage
in 2 minutes and 43 seconds
......@@ -9,6 +9,10 @@
<label>The name of the icon used in the compact representation (e.g. on a small panel).</label>
<default>start-here-kde</default>
</entry>
<entry name="menuLabel" type="string">
<label>Text label for the Panel button</label>
<default></default>
</entry>
<entry name="favorites" type="StringList">
<label>List of general favorites. Supported values are menu id's (usually .desktop file names), special URLs that expand into default applications (e.g. preferred://browser), document URLs and KPeople contact URIs.</label>
<default>preferred://browser,org.kde.kontact.desktop,systemsettings.desktop,org.kde.dolphin.desktop,ktp-contactlist.desktop,org.kde.discover.desktop</default>
......
......@@ -13,9 +13,11 @@ import QtQuick.Controls 2.5
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.kquickcontrolsaddons 2.0 as KQuickAddons
import org.kde.kirigami 2.5 as Kirigami
import org.kde.plasma.extras 2.0 as PlasmaExtras
ColumnLayout {
property string cfg_menuLabel: menuLabel.text
property string cfg_icon: plasmoid.configuration.icon
property int cfg_favoritesDisplay: plasmoid.configuration.favoritesDisplay
property int cfg_applicationsDisplay: plasmoid.configuration.applicationsDisplay
......@@ -53,7 +55,7 @@ ColumnLayout {
anchors.centerIn: parent
width: PlasmaCore.Units.iconSizes.large
height: width
source: cfg_icon
source: plasmoid.formFactor !== PlasmaCore.Types.Vertical ? cfg_icon : cfg_icon ? cfg_icon : "start-here-kde"
}
}
......@@ -69,13 +71,57 @@ ColumnLayout {
onClicked: iconDialog.open()
}
MenuItem {
text: i18nc("@item:inmenu Reset icon to default", "Clear Icon")
text: i18nc("@item:inmenu Reset icon to default", "Reset to default icon")
icon.name: "edit-clear"
onClicked: cfg_icon = "start-here-kde"
}
MenuItem {
text: i18nc("@action:inmenu", "Remove icon")
icon.name: "delete"
enabled: !!cfg_icon && menuLabel.text && plasmoid.formFactor !== PlasmaCore.Types.Vertical
onClicked: cfg_icon = ""
}
}
}
PlasmaExtras.ActionTextField {
id: menuLabel
enabled: plasmoid.formFactor !== PlasmaCore.Types.Vertical
Kirigami.FormData.label: i18nc("@label:textbox", "Text label:")
text: plasmoid.configuration.menuLabel
placeholderText: i18nc("@info:placeholder", "Type here to add a text label")
onTextEdited: {
cfg_menuLabel = menuLabel.text
// This is to make sure that we always have a icon if there is no text.
// If the user remove the icon and remove the text, without this, we'll have no icon and no text.
// This is to force the icon to be there.
if (!menuLabel.text) {
cfg_icon = cfg_icon || "start-here-kde"
}
}
rightActions: [
Action {
icon.name: "edit-clear"
enabled: menuLabel.text !== ""
onTriggered: {
menuLabel.clear()
cfg_menuLabel = ''
cfg_icon = cfg_icon || "start-here-kde"
}
}
]
}
Label {
Layout.fillWidth: true
Layout.maximumWidth: Kirigami.Units.gridUnit * 25
visible: plasmoid.formFactor === PlasmaCore.Types.Vertical
text: i18nc("@info", "A text label cannot be set when the Panel is vertical.")
wrapMode: Text.Wrap
font: Kirigami.Theme.smallFont
}
Item {
Kirigami.FormData.isSection: true
}
......
......@@ -17,18 +17,25 @@ import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PC3
import org.kde.plasma.private.kicker 0.1 as Kicker
import "code/tools.js" as Tools
Item {
id: kickoff
// The properties are defined here instead of the singleton because each
// instance of Kickoff requires different instances of these properties
// Used to display the menu label on the only text mode
property string menuLabel: plasmoid.configuration.menuLabel
property bool inPanel: plasmoid.location === PlasmaCore.Types.TopEdge
|| plasmoid.location === PlasmaCore.Types.RightEdge
|| plasmoid.location === PlasmaCore.Types.BottomEdge
|| plasmoid.location === PlasmaCore.Types.LeftEdge
property bool vertical: plasmoid.formFactor === PlasmaCore.Types.Vertical
property string defaultIcon: "start-here-kde"
// Used to prevent the width from changing frequently when the scrollbar appears or disappears
property bool mayHaveGridWithScrollBar: plasmoid.configuration.applicationsDisplay === 0
|| (plasmoid.configuration.favoritesDisplay === 0 && plasmoid.rootItem.rootModel.favoritesModel.count > 16)
......@@ -130,18 +137,21 @@ Item {
Plasmoid.compactRepresentation: MouseArea {
id: compactRoot
// Taken from DigitalClock to ensure uniform sizing when next to each other
readonly property bool tooSmall: plasmoid.formFactor === PlasmaCore.Types.Horizontal && Math.round(2 * (compactRoot.height / 5)) <= PlasmaCore.Theme.smallestFont.pixelSize
implicitWidth: PlasmaCore.Units.iconSizeHints.panel
implicitHeight: PlasmaCore.Units.iconSizeHints.panel
Layout.minimumWidth: {
if (!kickoff.inPanel) {
return PlasmaCore.Units.iconSizes.small
return Tools.dynamicSetWidgetWidth(plasmoid.icon, buttonIcon.width, kickoff.menuLabel, labelTextField.width, PlasmaCore.Units.smallSpacing * 2);
}
if (kickoff.vertical) {
return -1;
} else {
return Math.min(PlasmaCore.Units.iconSizeHints.panel, parent.height) * buttonIcon.aspectRatio;
return Tools.dynamicSetWidgetWidth(plasmoid.icon, buttonIcon.width, kickoff.menuLabel, labelTextField.width, PlasmaCore.Units.smallSpacing * 2);
}
}
......@@ -165,7 +175,7 @@ Item {
if (kickoff.vertical) {
return PlasmaCore.Units.iconSizeHints.panel;
} else {
return Math.min(PlasmaCore.Units.iconSizeHints.panel, parent.height) * buttonIcon.aspectRatio;
return Tools.dynamicSetWidgetWidth(plasmoid.icon, buttonIcon.width, kickoff.menuLabel, labelTextField.width, PlasmaCore.Units.smallSpacing * 2);
}
}
......@@ -200,17 +210,36 @@ Item {
onTriggered: plasmoid.expanded = true
}
PlasmaCore.IconItem {
id: buttonIcon
readonly property double aspectRatio: (kickoff.vertical ? implicitHeight / implicitWidth
: implicitWidth / implicitHeight)
RowLayout {
anchors.fill: parent
source: plasmoid.icon
active: parent.containsMouse || compactDragArea.containsDrag
smooth: true
roundToIconSize: aspectRatio === 1
spacing: PlasmaCore.Units.smallSpacing
PlasmaCore.IconItem {
id: buttonIcon
readonly property double aspectRatio: (kickoff.vertical ? implicitHeight / implicitWidth
: implicitWidth / implicitHeight)
readonly property int iconSize: Tools.returnValueIfExists(plasmoid.icon, compactRoot.height)
Layout.preferredWidth: iconSize
Layout.preferredHeight: iconSize
source: !kickoff.vertical ? plasmoid.icon : plasmoid.icon ? plasmoid.icon : kickoff.defaultIcon
active: parent.containsMouse || compactDragArea.containsDrag
smooth: true
roundToIconSize: aspectRatio === 1
}
PC3.Label {
id: labelTextField
text: !kickoff.vertical ? kickoff.menuLabel : ''
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
wrapMode: Text.NoWrap
fontSizeMode: Text.VerticalFit
font.pixelSize: compactRoot.tooSmall ? PlasmaCore.Theme.defaultFont.pixelSize : PlasmaCore.Units.roundToIconSize(PlasmaCore.Units.gridUnit * 2)
minimumPointSize: PlasmaCore.Theme.smallestFont.pointSize
visible: !kickoff.vertical
}
}
}
......
......@@ -174,3 +174,18 @@ function handleFavoriteAction(actionId, actionArgument) {
favoriteModel.setFavoriteOn(favoriteId, actionArgument.favoriteActivity);
}
}
function returnValueIfExists(checker, value, optional = 0) {
var condition = Array.isArray(checker) ? checker.some(el => el) : checker;
return condition ? value : optional;
}
function dynamicSetWidgetWidth(icon, buttonIconWidth, kickoffMenuLabel, menuLabelWidth, spacing) {
return [
returnValueIfExists(icon, buttonIconWidth),
returnValueIfExists(kickoffMenuLabel, menuLabelWidth),
returnValueIfExists(kickoffMenuLabel, spacing),
returnValueIfExists(kickoffMenuLabel && icon, spacing)
].reduce((sum, n) => sum + n, 0);
}
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