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 | import QtGraphicalEffects 1.0 | ||||
26 | 27 | | |||
27 | PlasmaComponents.ToolButton { | 28 | 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 | 29 | id: sessionButton | ||
29 | property int currentIndex: -1 | 30 | 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 | 31 | | |||
31 | implicitWidth: minimumWidth | 32 | visible: sessionMenu.count > 1 | ||
32 | 33 | | |||
33 | visible: menu.items.length > 1 | 34 | 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 | 35 | | |||
37 | font.pointSize: config.fontSize | 36 | font.pointSize: config.fontSize | ||
38 | 37 | | |||
39 | Component.onCompleted: { | 38 | Component.onCompleted: { | ||
40 | currentIndex = sessionModel.lastIndex | 39 | currentIndex = sessionModel.lastIndex | ||
41 | } | 40 | } | ||
42 | 41 | | |||
43 | menu: QQC.Menu { | 42 | onClicked: { | ||
44 | id: menu | 43 | sessionMenu.popup(x, y) | ||
45 | style: BreezeMenuStyle {} | 44 | } | ||
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. | |||||
45 | | ||||
46 | QQC2.Menu { | ||||
47 | id: sessionMenu | ||||
48 | | ||||
49 | property int largestWidth: 9999 | ||||
50 | | ||||
51 | Component.onCompleted: { | ||||
52 | var trueWidth = 0; | ||||
53 | for (var i = 0; i < sessionMenu.count; i++) { | ||||
54 | trueWidth = Math.max(trueWidth, sessionMenu.itemAt(i).textWidth) | ||||
55 | } | ||||
56 | sessionMenu.largestWidth = trueWidth | ||||
57 | } | ||||
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… | |||||
58 | | ||||
59 | background: Rectangle { | ||||
60 | implicitHeight: 40 | ||||
61 | implicitWidth: sessionMenu.largestWidth > sessionButton.implicitWidth ? sessionMenu.largestWidth : sessionButton.implicitWidth | ||||
62 | color: PlasmaCore.ColorScope.backgroundColor | ||||
63 | property color borderColor: PlasmaCore.Colorscope.textColor | ||||
64 | border.color: Qt.rgba(borderColor.r, borderColor.g, borderColor.b, 0.3) | ||||
65 | border.width: 1 | ||||
66 | layer.enabled: true | ||||
67 | layer.effect: DropShadow { | ||||
68 | transparentBorder: true | ||||
69 | radius: 8 | ||||
70 | samples: 8 | ||||
71 | horizontalOffset: 0 | ||||
72 | verticalOffset: 2 | ||||
73 | color: Qt.rgba(0, 0, 0, 0.3) | ||||
74 | } | ||||
75 | } | ||||
76 | | ||||
46 | Instantiator { | 77 | Instantiator { | ||
47 | id: instantiator | 78 | id: instantiator | ||
48 | model: sessionModel | 79 | model: sessionModel | ||
49 | onObjectAdded: menu.insertItem(index, object) | 80 | onObjectAdded: sessionMenu.addItem( object ) | ||
50 | onObjectRemoved: menu.removeItem( object ) | 81 | onObjectRemoved: sessionMenu.removeItem( object ) | ||
51 | delegate: QQC.MenuItem { | 82 | delegate: QQC2.MenuItem { | ||
83 | id: menuItem | ||||
84 | property string name: model.name | ||||
85 | | ||||
86 | property real textWidth: text.contentWidth + 20 | ||||
87 | implicitWidth: text.contentWidth + 20 | ||||
88 | implicitHeight: Math.round(text.contentHeight * 1.6) | ||||
89 | | ||||
90 | contentItem: QQC2.Label { | ||||
91 | id: text | ||||
92 | font.pointSize: config.fontSize | ||||
52 | text: model.name | 93 | text: model.name | ||
filipf: Why do we need to set this? | |||||
53 | onTriggered: { | 94 | color: menuItem.highlighted ? PlasmaCore.ColorScope.highlightedTextColor : PlasmaCore.ColorScope.textColor | ||
54 | root.currentIndex = model.index | 95 | horizontalAlignment: Text.AlignLeft | ||
96 | verticalAlignment: Text.AlignVCenter | ||||
97 | elide: Text.ElideRight | ||||
98 | } | ||||
99 | | ||||
100 | background: Rectangle { | ||||
101 | color: PlasmaCore.ColorScope.highlightColor | ||||
102 | opacity: menuItem.highlighted ? 1 : 0 | ||||
103 | MouseArea { | ||||
104 | anchors.fill: parent | ||||
105 | hoverEnabled: true | ||||
106 | onContainsMouseChanged: menuItem.highlighted = containsMouse | ||||
107 | onClicked: { | ||||
108 | sessionMenu.dismiss() | ||||
109 | sessionButton.currentIndex = model.index | ||||
110 | } | ||||
111 | } | ||||
112 | } | ||||
113 | } | ||||
114 | } | ||||
115 | | ||||
116 | enter: Transition { | ||||
117 | NumberAnimation { | ||||
118 | property: "opacity" | ||||
119 | from: 0 | ||||
120 | to: 1 | ||||
121 | duration: 150 | ||||
122 | } | ||||
55 | } | 123 | } | ||
124 | exit: Transition { | ||||
125 | NumberAnimation { | ||||
126 | property: "opacity" | ||||
127 | from: 1 | ||||
128 | to: 0 | ||||
129 | duration: 150 | ||||
56 | } | 130 | } | ||
57 | } | 131 | } | ||
58 | } | 132 | } | ||
59 | } | 133 | } |
Note that (confusingly) Plasma components 2 is QQC1
Plasma components3 is QQC2
It might fix the menu issue