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 2.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 | Item { | ||
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: root | ||
29 | height: toolBtn.height | ||||
30 | width: toolBtn.width | ||||
31 | | ||||
32 | PlasmaComponents.ToolButton { | ||||
33 | id: toolBtn | ||||
29 | property int currentIndex: -1 | 34 | 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 | 35 | | |||
31 | implicitWidth: minimumWidth | 36 | implicitWidth: minimumWidth | ||
32 | 37 | | |||
33 | visible: menu.items.length > 1 | 38 | visible: sessionMenu.count > 1 | ||
34 | 39 | | |||
35 | text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Desktop Session: %1", instantiator.objectAt(currentIndex).text || "") | 40 | text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Desktop Session: %1", instantiator.objectAt(currentIndex).name || "Error") | ||
36 | 41 | | |||
37 | font.pointSize: config.fontSize | 42 | font.pointSize: config.fontSize | ||
38 | 43 | | |||
39 | Component.onCompleted: { | 44 | Component.onCompleted: { | ||
40 | currentIndex = sessionModel.lastIndex | 45 | currentIndex = sessionModel.lastIndex | ||
41 | } | 46 | } | ||
42 | 47 | | |||
43 | menu: QQC.Menu { | 48 | onClicked: { | ||
44 | id: menu | 49 | sessionMenu.popup(x, y) | ||
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 | style: BreezeMenuStyle {} | 50 | } | ||
51 | } | ||||
52 | | ||||
53 | QQC2.Menu { | ||||
54 | id: sessionMenu | ||||
55 | property int largestWidth: 9999 | ||||
56 | | ||||
57 | Component.onCompleted: { | ||||
58 | var trueWidth = 0; | ||||
59 | for (var i = 0; i < sessionMenu.count; i++) { | ||||
60 | trueWidth = Math.max(trueWidth, sessionMenu.itemAt(i).textWidth) | ||||
61 | } | ||||
62 | sessionMenu.largestWidth = trueWidth | ||||
63 | } | ||||
64 | | ||||
65 | background: Rectangle { | ||||
66 | implicitHeight: 40 | ||||
67 | implicitWidth: sessionMenu.largestWidth | ||||
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… | |||||
68 | color: PlasmaCore.ColorScope.backgroundColor | ||||
69 | border.color: Qt.tint(PlasmaCore.ColorScope.textColor, Qt.rgba(color.r, color.g, color.b, 0.7)) | ||||
70 | border.width: 1 | ||||
71 | } | ||||
72 | | ||||
46 | Instantiator { | 73 | Instantiator { | ||
47 | id: instantiator | 74 | id: instantiator | ||
48 | model: sessionModel | 75 | model: sessionModel | ||
49 | onObjectAdded: menu.insertItem(index, object) | 76 | onObjectAdded: sessionMenu.addItem( object ) | ||
50 | onObjectRemoved: menu.removeItem( object ) | 77 | onObjectRemoved: sessionMenu.removeItem( object ) | ||
51 | delegate: QQC.MenuItem { | 78 | delegate: QQC2.MenuItem { | ||
79 | id: menuItem | ||||
80 | property string name: model.name | ||||
81 | | ||||
82 | property real textWidth: text.contentWidth + 20 | ||||
83 | implicitWidth: text.contentWidth + 20 | ||||
84 | implicitHeight: text.contentHeight * 1.6 | ||||
85 | | ||||
86 | contentItem: QQC2.Label { | ||||
87 | id: text | ||||
52 | text: model.name | 88 | text: model.name | ||
53 | onTriggered: { | 89 | font: menuItem.font | ||
filipf: Why do we need to set this? | |||||
54 | root.currentIndex = model.index | 90 | color: PlasmaCore.ColorScope.textColor | ||
91 | horizontalAlignment: Text.AlignLeft | ||||
92 | verticalAlignment: Text.AlignVCenter | ||||
93 | elide: Text.ElideRight | ||||
94 | } | ||||
95 | | ||||
96 | background: Rectangle { | ||||
97 | color: menuItem.highlighted ? PlasmaCore.ColorScope.highlightColor : "transparent" | ||||
98 | MouseArea { | ||||
99 | anchors.fill: parent | ||||
100 | hoverEnabled: true | ||||
101 | onContainsMouseChanged: menuItem.highlighted = containsMouse | ||||
102 | onClicked: { | ||||
103 | sessionMenu.dismiss() | ||||
104 | toolBtn.currentIndex = model.index | ||||
105 | } | ||||
106 | } | ||||
55 | } | 107 | } | ||
56 | } | 108 | } | ||
57 | } | 109 | } | ||
58 | } | 110 | } | ||
59 | } | 111 | } |
Note that (confusingly) Plasma components 2 is QQC1
Plasma components3 is QQC2
It might fix the menu issue