Changeset View
Standalone View
sddm-theme/SessionButton.qml
Show All 11 Lines | |||||
12 | * GNU General Public License for more details | 12 | * GNU General Public License for more details | ||
13 | * | 13 | * | ||
14 | * You should have received a copy of the GNU Library General Public | 14 | * You should have received a copy of the GNU Library General Public | ||
15 | * License along with this program; if not, write to the | 15 | * License along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | 16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | import QtQuick 2.2 | 20 | import QtQuick 2.6 | ||
21 | 21 | | |||
22 | import org.kde.plasma.core 2.0 as PlasmaCore | 22 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
23 | import org.kde.plasma.components 2.0 as PlasmaComponents | 23 | import org.kde.plasma.components 3.0 as PlasmaComponents | ||
davidedmundson: Note that (confusingly) Plasma components 2 is QQC1
Plasma components3 is QQC2
It might fix… | |||||
cblack: The `menu` property seems to be removed in PC3 | |||||
Additionally, ToolButton still seems to use QQC1 even in PC3. cblack: Additionally, [[ https://api.kde.org/frameworks/plasma… | |||||
24 | 24 | | |||
25 | import QtQuick.Controls 1.3 as QQC | 25 | import QtQuick.Controls 2.5 as QQC2 | ||
26 | 26 | | |||
27 | PlasmaComponents.ToolButton { | 27 | PlasmaComponents.ToolButton { | ||
davidedmundson: Why the wrapper? | |||||
QML files can only have one root, and the ToolButton's menu property doesn't accept QQC2 menus, meaning they have to be separated. cblack: QML files can only have one root, and the ToolButton's `menu` property doesn't accept QQC2… | |||||
It seems to be running fine without the Item wrapper for me. What I did though was but the QQC2 menu inside the button, I didn't split them up. filipf: It seems to be running fine without the Item wrapper for me. What I did though was but the QQC2… | |||||
28 | id: root | 28 | id: toolBtn | ||
29 | property int currentIndex: -1 | 29 | property int currentIndex: -1 | ||
davidedmundson: Implicit height should be propagated upwards, not height. | |||||
I meant implicitWidth: toolBtn.implicitWidth width by default is bound to the implicitWidth so you don't need to set it davidedmundson: I meant
implicitWidth: toolBtn.implicitWidth
width by default is bound to the implicitWidth… | |||||
30 | 30 | | |||
31 | implicitWidth: minimumWidth | 31 | visible: sessionMenu.count > 1 | ||
32 | 32 | | |||
33 | visible: menu.items.length > 1 | 33 | text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Desktop Session: %1", instantiator.objectAt(currentIndex).name || "Error") | ||
34 | | ||||
35 | text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Desktop Session: %1", instantiator.objectAt(currentIndex).text || "") | | |||
36 | 34 | | |||
37 | font.pointSize: config.fontSize | 35 | font.pointSize: config.fontSize | ||
38 | 36 | | |||
39 | Component.onCompleted: { | 37 | Component.onCompleted: { | ||
40 | currentIndex = sessionModel.lastIndex | 38 | currentIndex = sessionModel.lastIndex | ||
41 | } | 39 | } | ||
42 | 40 | | |||
43 | menu: QQC.Menu { | 41 | onClicked: { | ||
44 | id: menu | 42 | sessionMenu.popup(x, y) | ||
45 | style: BreezeMenuStyle {} | 43 | } | ||
While we're doing this, can you perhaps make the menu pop up *above* the button? filipf: While we're doing this, can you perhaps make the menu pop up *above* the button? | |||||
It seems that changing the y value doesn't affect its y position for whatever reason. cblack: It seems that changing the `y` value doesn't affect its y position for whatever reason. | |||||
44 | | ||||
45 | QQC2.Menu { | ||||
46 | id: sessionMenu | ||||
47 | property int largestWidth: 9999 | ||||
48 | | ||||
49 | Component.onCompleted: { | ||||
50 | var trueWidth = 0; | ||||
51 | for (var i = 0; i < sessionMenu.count; i++) { | ||||
52 | trueWidth = Math.max(trueWidth, sessionMenu.itemAt(i).textWidth) | ||||
53 | } | ||||
54 | sessionMenu.largestWidth = trueWidth | ||||
55 | } | ||||
56 | | ||||
This can be up for debate, but I sort of liked the older behavior more when the menu's width would be determined by the size of the ToolButton at a particular point. filipf: This can be up for debate, but I sort of liked the older behavior more when the menu's width… | |||||
57 | background: Rectangle { | ||||
58 | implicitHeight: 40 | ||||
59 | implicitWidth: sessionMenu.largestWidth > toolBtn.implicitWidth ? sessionMenu.largestWidth : toolBtn.implicitWidth | ||||
60 | color: PlasmaCore.ColorScope.backgroundColor | ||||
61 | border.color: Qt.tint(PlasmaCore.ColorScope.textColor, Qt.rgba(color.r, color.g, color.b, 0.7)) | ||||
62 | border.width: 1 | ||||
63 | } | ||||
64 | | ||||
46 | Instantiator { | 65 | Instantiator { | ||
47 | id: instantiator | 66 | id: instantiator | ||
48 | model: sessionModel | 67 | model: sessionModel | ||
49 | onObjectAdded: menu.insertItem(index, object) | 68 | onObjectAdded: sessionMenu.addItem( object ) | ||
50 | onObjectRemoved: menu.removeItem( object ) | 69 | onObjectRemoved: sessionMenu.removeItem( object ) | ||
51 | delegate: QQC.MenuItem { | 70 | delegate: QQC2.MenuItem { | ||
71 | id: menuItem | ||||
72 | property string name: model.name | ||||
73 | | ||||
74 | property real textWidth: text.contentWidth + 20 | ||||
75 | implicitWidth: text.contentWidth + 20 | ||||
76 | implicitHeight: text.contentHeight * 1.6 | ||||
77 | | ||||
78 | contentItem: QQC2.Label { | ||||
79 | id: text | ||||
52 | text: model.name | 80 | text: model.name | ||
53 | onTriggered: { | 81 | color: PlasmaCore.ColorScope.textColor | ||
filipf: Why do we need to set this? | |||||
54 | root.currentIndex = model.index | 82 | horizontalAlignment: Text.AlignLeft | ||
83 | verticalAlignment: Text.AlignVCenter | ||||
84 | elide: Text.ElideRight | ||||
85 | } | ||||
86 | | ||||
87 | background: Rectangle { | ||||
88 | color: menuItem.highlighted ? PlasmaCore.ColorScope.highlightColor : "transparent" | ||||
89 | MouseArea { | ||||
90 | anchors.fill: parent | ||||
91 | hoverEnabled: true | ||||
92 | onContainsMouseChanged: menuItem.highlighted = containsMouse | ||||
93 | onClicked: { | ||||
94 | sessionMenu.dismiss() | ||||
95 | toolBtn.currentIndex = model.index | ||||
96 | } | ||||
97 | } | ||||
98 | } | ||||
99 | } | ||||
100 | } | ||||
101 | | ||||
102 | enter: Transition { | ||||
103 | NumberAnimation { | ||||
104 | property: "opacity" | ||||
105 | from: 0 | ||||
106 | to: 1 | ||||
107 | duration: 150 | ||||
108 | } | ||||
55 | } | 109 | } | ||
110 | exit: Transition { | ||||
111 | NumberAnimation { | ||||
112 | property: "opacity" | ||||
113 | from: 1 | ||||
114 | to: 0 | ||||
115 | duration: 150 | ||||
56 | } | 116 | } | ||
57 | } | 117 | } | ||
58 | } | 118 | } | ||
59 | } | 119 | } |
Note that (confusingly) Plasma components 2 is QQC1
Plasma components3 is QQC2
It might fix the menu issue