Changeset View
Changeset View
Standalone View
Standalone View
applets/systemtray/package/contents/ui/items/AbstractItem.qml
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright 2016 Marco Martin <mart@kde.org> | 2 | * Copyright 2016 Marco Martin <mart@kde.org> | ||
3 | * Copyright 2019 ivan tkachenko <ratijastk@kde.org> | ||||
3 | * | 4 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU Library General Public License as | 6 | * it under the terms of the GNU Library General Public License as | ||
6 | * published by the Free Software Foundation; either version 2, or | 7 | * published by the Free Software Foundation; either version 2, or | ||
7 | * (at your option) any later version. | 8 | * (at your option) any later version. | ||
8 | * | 9 | * | ||
9 | * This program is distributed in the hope that it will be useful, | 10 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU Library General Public License for more details | 13 | * GNU Library General Public License for more details | ||
13 | * | 14 | * | ||
14 | * You should have received a copy of the GNU Library General Public | 15 | * You should have received a copy of the GNU Library General Public | ||
15 | * License along with this program; if not, write to the | 16 | * License along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | 17 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
18 | */ | 19 | */ | ||
19 | 20 | | |||
20 | import QtQuick 2.1 | 21 | import QtQuick 2.1 | ||
22 | import QtQuick.Layouts 1.12 | ||||
broulik: You sure this high version number is neccessary? | |||||
Not exactly. But old layouts used to have a load of restrictions, for sure. ratijas: Not exactly. But old layouts used to have a load of restrictions, for sure. | |||||
broulik: "Old layouts"? You only use `Layouts 1.2` features as far as I can tell | |||||
21 | import org.kde.plasma.core 2.0 as PlasmaCore | 23 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
22 | import org.kde.plasma.components 2.0 as PlasmaComponents | 24 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||
23 | 25 | | |||
24 | PlasmaCore.ToolTipArea { | 26 | PlasmaCore.ToolTipArea { | ||
25 | id: abstractItem | 27 | id: abstractItem | ||
28 | objectName: "abstractItem" | ||||
26 | 29 | | |||
27 | height: effectiveItemSize + marginHints.top + marginHints.bottom | 30 | Layout.fillHeight: !(labelVisible || vertical) | ||
broulik: Avoid doing negated disjunctions for clarity: `!labelVisible && !vertical` | |||||
Oh, give it a rest. These two lines looking good together, this way it is clear that they are an opposite of each other. ratijas: Oh, give it a rest. These two lines looking good together, this way it is clear that they are… | |||||
You first have to evaluate the inner statement in your head and then negate it vs. just seeing at a glance what it is supposed to do broulik: You first have to evaluate the inner statement in your head and then negate it vs. just seeing… | |||||
28 | width: labelVisible ? parent.width : effectiveItemSize + marginHints.left + marginHints.right | 31 | Layout.fillWidth: labelVisible || vertical | ||
32 | Layout.preferredHeight: effectiveItemSize + marginHints.top + marginHints.bottom | ||||
33 | Layout.preferredWidth: labelVisible ? -1 : effectiveItemSize + marginHints.left + marginHints.right | ||||
29 | 34 | | |||
30 | property real effectiveItemSize: hidden ? root.hiddenItemSize : root.itemSize | 35 | property real effectiveItemSize: hidden ? root.hiddenItemSize : root.itemSize | ||
31 | property string itemId | 36 | property string itemId | ||
32 | property string category | 37 | property string category | ||
33 | property alias text: label.text | 38 | property alias text: label.text | ||
34 | property bool hidden: parent.objectName == "hiddenTasksColumn" | 39 | property bool hidden: parent.objectName === "hiddenTasksColumn" | ||
35 | property QtObject marginHints: parent.marginHints | 40 | property QtObject marginHints: parent.marginHints | ||
36 | property bool labelVisible: abstractItem.hidden && !root.activeApplet | 41 | property alias labelVisible: label.visible | ||
42 | property Item iconItemContainer: iconItemContainer | ||||
37 | property Item iconItem | 43 | property Item iconItem | ||
38 | //PlasmaCore.Types.ItemStatus | 44 | property int /* PlasmaCore.Types.ItemStatus */ status | ||
39 | property int status | | |||
40 | property QtObject model | 45 | property QtObject model | ||
41 | 46 | | |||
42 | signal clicked(var mouse) | 47 | signal clicked(var mouse) | ||
43 | signal wheel(var wheel) | 48 | signal wheel(var wheel) | ||
44 | signal contextMenu(var mouse) | 49 | signal contextMenu(var mouse) | ||
45 | 50 | | |||
46 | property bool forcedHidden: plasmoid.configuration.hiddenItems.indexOf(itemId) !== -1 | 51 | property bool forcedHidden: plasmoid.configuration.hiddenItems.indexOf(itemId) !== -1 | ||
47 | property bool forcedShown: plasmoid.configuration.showAllItems || plasmoid.configuration.shownItems.indexOf(itemId) !== -1 | 52 | property bool forcedShown: plasmoid.configuration.showAllItems || plasmoid.configuration.shownItems.indexOf(itemId) !== -1 | ||
48 | property bool categoryShown: shownCategories.indexOf(category) !== -1; | 53 | property bool categoryShown: shownCategories.indexOf(category) !== -1; | ||
49 | 54 | | |||
50 | readonly property int effectiveStatus: { | 55 | readonly property int effectiveStatus: { | ||
51 | if (!categoryShown || status === PlasmaCore.Types.HiddenStatus) { | 56 | if (!categoryShown || status === PlasmaCore.Types.HiddenStatus) { | ||
52 | return PlasmaCore.Types.HiddenStatus | 57 | return PlasmaCore.Types.HiddenStatus | ||
53 | } else if (forcedShown || (!forcedHidden && status !== PlasmaCore.Types.PassiveStatus)) { | 58 | } else if (forcedShown || (!forcedHidden && status !== PlasmaCore.Types.PassiveStatus)) { | ||
54 | return PlasmaCore.Types.ActiveStatus | 59 | return PlasmaCore.Types.ActiveStatus | ||
55 | } else { | 60 | } else { | ||
56 | return PlasmaCore.Types.PassiveStatus | 61 | return PlasmaCore.Types.PassiveStatus | ||
57 | } | 62 | } | ||
58 | } | 63 | } | ||
59 | 64 | | |||
60 | /* subclasses need to assign to this tiiltip properties | 65 | RowLayout { | ||
66 | anchors.fill: parent | ||||
67 | spacing: 0 | ||||
68 | | ||||
69 | Item { | ||||
70 | id: iconItemContainer | ||||
71 | property real size: Math.min(parent.width - marginHints.left - marginHints.right, | ||||
72 | parent.height - marginHints.top - marginHints.bottom) | ||||
73 | Layout.preferredWidth: abstractItem.effectiveItemSize | ||||
74 | Layout.preferredHeight: abstractItem.effectiveItemSize | ||||
broulik: For some reason the icons are now smaller than they were before, observed on two separate… | |||||
Not even sure, is it directly my mistake, or rebase on that later master branch. Could you provide more specific numbers, please? ratijas: Not even sure, is it directly my mistake, or rebase on that later master branch. Could you… | |||||
When I revert this patch in master the icons return to normal, so this isn't a rebase issue. broulik: When I revert this patch in master the icons return to normal, so this isn't a rebase issue. | |||||
75 | Layout.leftMargin: labelVisible ? marginHints.left : 0 | ||||
76 | Layout.rightMargin: labelVisible ? marginHints.right : 0 | ||||
broulik: This margin stuff doesn't work with right to left layout.
Run `plasmashell -reverse` and… | |||||
77 | Layout.alignment: Qt.AlignVCenter | (labelVisible ? Qt.AlignLeft : Qt.AlignHCenter) | ||||
78 | } | ||||
79 | PlasmaComponents.Label { | ||||
80 | id: label | ||||
81 | Layout.fillWidth: true | ||||
82 | | ||||
83 | opacity: visible ? 1 : 0 | ||||
84 | visible: abstractItem.hidden && !root.activeApplet | ||||
85 | Behavior on opacity { | ||||
86 | NumberAnimation { | ||||
87 | duration: units.longDuration | ||||
88 | easing.type: Easing.InOutQuad | ||||
89 | } | ||||
90 | } | ||||
91 | } | ||||
92 | } | ||||
93 | | ||||
94 | /* subclasses need to assign to this tooltip properties | ||||
61 | mainText: | 95 | mainText: | ||
62 | subText: | 96 | subText: | ||
63 | icon: | 97 | icon: | ||
64 | */ | 98 | */ | ||
65 | 99 | | |||
66 | location: { | 100 | location: { | ||
67 | if (abstractItem.parent && abstractItem.parent.objectName === "hiddenTasksColumn") { | 101 | if (hidden) { | ||
68 | if (LayoutMirroring.enabled && plasmoid.location !== PlasmaCore.Types.RightEdge) { | 102 | if (LayoutMirroring.enabled && plasmoid.location !== PlasmaCore.Types.RightEdge) { | ||
69 | return PlasmaCore.Types.LeftEdge; | 103 | return PlasmaCore.Types.LeftEdge; | ||
70 | } else if (plasmoid.location !== PlasmaCore.Types.LeftEdge) { | 104 | } else if (plasmoid.location !== PlasmaCore.Types.LeftEdge) { | ||
71 | return PlasmaCore.Types.RightEdge; | 105 | return PlasmaCore.Types.RightEdge; | ||
72 | } | 106 | } | ||
73 | } | 107 | } | ||
74 | 108 | | |||
75 | return plasmoid.location; | 109 | return plasmoid.location; | ||
Show All 9 Lines | 116 | onContainsMouseChanged: { | |||
85 | } | 119 | } | ||
86 | } | 120 | } | ||
87 | 121 | | |||
88 | Component.onCompleted: updateItemVisibility(abstractItem); | 122 | Component.onCompleted: updateItemVisibility(abstractItem); | ||
89 | 123 | | |||
90 | //dangerous but needed due how repeater reparents | 124 | //dangerous but needed due how repeater reparents | ||
91 | onParentChanged: updateItemVisibility(abstractItem); | 125 | onParentChanged: updateItemVisibility(abstractItem); | ||
92 | 126 | | |||
127 | onIconItemChanged: { | ||||
128 | if (iconItem) { | ||||
129 | iconItem.parent = iconItemContainer; | ||||
130 | iconItem.anchors.fill = iconItemContainer; | ||||
broulik: Can you just make the `iconItem` have a `anchors.fill: parent`? | |||||
ratijas: maaayyybe... | |||||
131 | } | ||||
132 | } | ||||
133 | | ||||
93 | //END CONNECTIONS | 134 | //END CONNECTIONS | ||
94 | 135 | | |||
95 | PulseAnimation { | 136 | PulseAnimation { | ||
96 | targetItem: iconItem | 137 | targetItem: iconItem | ||
97 | running: (abstractItem.status === PlasmaCore.Types.NeedsAttentionStatus || | 138 | running: (abstractItem.status === PlasmaCore.Types.NeedsAttentionStatus || | ||
98 | abstractItem.status === PlasmaCore.Types.RequiresAttentionStatus ) && | 139 | abstractItem.status === PlasmaCore.Types.RequiresAttentionStatus ) && | ||
99 | units.longDuration > 0 | 140 | units.longDuration > 0 | ||
100 | } | 141 | } | ||
101 | 142 | | |||
102 | MouseArea { | 143 | MouseArea { | ||
103 | id: mouseArea | 144 | id: mouseArea | ||
104 | anchors.fill: abstractItem | 145 | anchors.fill: parent | ||
105 | hoverEnabled: true | 146 | hoverEnabled: true | ||
106 | drag.filterChildren: true | 147 | drag.filterChildren: true | ||
107 | acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton | 148 | acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton | ||
108 | onClicked: abstractItem.clicked(mouse) | 149 | onClicked: abstractItem.clicked(mouse) | ||
109 | onPressed: { | 150 | onPressed: { | ||
110 | abstractItem.hideToolTip() | 151 | abstractItem.hideToolTip() | ||
111 | if (mouse.button === Qt.RightButton) { | 152 | if (mouse.button === Qt.RightButton) { | ||
112 | abstractItem.contextMenu(mouse) | 153 | abstractItem.contextMenu(mouse) | ||
113 | } | 154 | } | ||
114 | } | 155 | } | ||
115 | onPressAndHold: { | 156 | onPressAndHold: { | ||
116 | abstractItem.contextMenu(mouse) | 157 | abstractItem.contextMenu(mouse) | ||
117 | } | 158 | } | ||
118 | onWheel: { | 159 | onWheel: { | ||
119 | abstractItem.wheel(wheel); | 160 | abstractItem.wheel(wheel); | ||
120 | //Don't accept the event in order to make the scrolling by mouse wheel working | 161 | //Don't accept the event in order to make the scrolling by mouse wheel working | ||
121 | //for the parent scrollview this icon is in. | 162 | //for the parent scrollview this icon is in. | ||
122 | wheel.accepted = false; | 163 | wheel.accepted = false; | ||
123 | } | 164 | } | ||
124 | } | 165 | } | ||
125 | | ||||
126 | PlasmaComponents.Label { | | |||
127 | id: label | | |||
128 | anchors { | | |||
129 | left: parent.left | | |||
130 | leftMargin: iconItem ? iconItem.width + units.smallSpacing : 0 | | |||
131 | verticalCenter: parent.verticalCenter | | |||
132 | } | | |||
133 | opacity: labelVisible ? 1 : 0 | | |||
134 | visible: abstractItem.hidden | | |||
135 | Behavior on opacity { | | |||
136 | NumberAnimation { | | |||
137 | duration: units.longDuration | | |||
138 | easing.type: Easing.InOutQuad | | |||
139 | } | | |||
140 | } | | |||
141 | } | | |||
142 | } | 166 | } | ||
143 | 167 | |
You sure this high version number is neccessary?