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 2020 Konrad Materka <materka@gmail.com> | ||||
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.2 | 21 | import QtQuick 2.2 | ||
21 | import org.kde.plasma.core 2.0 as PlasmaCore | 22 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
22 | import org.kde.plasma.components 2.0 as PlasmaComponents | 23 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||
23 | 24 | | |||
24 | PlasmaCore.ToolTipArea { | 25 | PlasmaCore.ToolTipArea { | ||
25 | id: abstractItem | 26 | id: abstractItem | ||
26 | 27 | | |||
27 | height: effectiveItemSize + marginHints.top + marginHints.bottom | 28 | height: inVisibleLayout ? visibleLayout.cellHeight : hiddenLayout.iconItemHeight | ||
28 | width: labelVisible ? parent.width : effectiveItemSize + marginHints.left + marginHints.right | 29 | width: inVisibleLayout ? visibleLayout.cellWidth : hiddenLayout.width | ||
29 | 30 | | |||
30 | property real effectiveItemSize: hidden ? root.hiddenItemSize : root.itemSize | | |||
31 | property string itemId | 31 | property string itemId | ||
32 | property string category | | |||
33 | property alias text: label.text | 32 | property alias text: label.text | ||
34 | property bool hidden: parent.objectName == "hiddenTasksColumn" | | |||
35 | property QtObject marginHints: parent.marginHints | | |||
36 | property bool labelVisible: abstractItem.hidden && !root.activeApplet | | |||
37 | property Item iconItem | 33 | property Item iconItem | ||
38 | //PlasmaCore.Types.ItemStatus | 34 | property int /*PlasmaCore.Types.ItemStatus*/ status | ||
davidedmundson: Lets look at fixing in a follow up patch
QML can do enums now | |||||
kmaterka: OK, I will change that in a separate patch | |||||
39 | property int status | 35 | property int /*PlasmaCore.Types.ItemStatus*/ effectiveStatus | ||
40 | property QtObject model | 36 | readonly property bool inHiddenLayout: effectiveStatus === PlasmaCore.Types.PassiveStatus | ||
37 | readonly property bool inVisibleLayout: effectiveStatus === PlasmaCore.Types.ActiveStatus | ||||
41 | 38 | | |||
42 | signal clicked(var mouse) | 39 | signal clicked(var mouse) | ||
43 | signal pressed(var mouse) | 40 | signal pressed(var mouse) | ||
44 | signal wheel(var wheel) | 41 | signal wheel(var wheel) | ||
45 | signal contextMenu(var mouse) | 42 | signal contextMenu(var mouse) | ||
46 | 43 | | |||
47 | property bool forcedHidden: plasmoid.configuration.hiddenItems.indexOf(itemId) !== -1 | 44 | /* subclasses need to assign to this tooltip properties | ||
48 | property bool forcedShown: plasmoid.configuration.showAllItems || plasmoid.configuration.shownItems.indexOf(itemId) !== -1 | | |||
49 | | ||||
50 | readonly property int effectiveStatus: { | | |||
51 | if (status === PlasmaCore.Types.HiddenStatus) { | | |||
52 | return PlasmaCore.Types.HiddenStatus | | |||
53 | } else if (forcedShown || (!forcedHidden && status !== PlasmaCore.Types.PassiveStatus)) { | | |||
54 | return PlasmaCore.Types.ActiveStatus | | |||
55 | } else { | | |||
56 | return PlasmaCore.Types.PassiveStatus | | |||
57 | } | | |||
58 | } | | |||
59 | | ||||
60 | /* subclasses need to assign to this tiiltip properties | | |||
61 | mainText: | 45 | mainText: | ||
62 | subText: | 46 | subText: | ||
63 | icon: | 47 | icon: | ||
64 | */ | 48 | */ | ||
65 | 49 | | |||
66 | location: { | 50 | location: { | ||
67 | if (abstractItem.parent && abstractItem.parent.objectName === "hiddenTasksColumn") { | 51 | if (inHiddenLayout) { | ||
68 | if (LayoutMirroring.enabled && plasmoid.location !== PlasmaCore.Types.RightEdge) { | 52 | if (LayoutMirroring.enabled && plasmoid.location !== PlasmaCore.Types.RightEdge) { | ||
69 | return PlasmaCore.Types.LeftEdge; | 53 | return PlasmaCore.Types.LeftEdge; | ||
70 | } else if (plasmoid.location !== PlasmaCore.Types.LeftEdge) { | 54 | } else if (plasmoid.location !== PlasmaCore.Types.LeftEdge) { | ||
71 | return PlasmaCore.Types.RightEdge; | 55 | return PlasmaCore.Types.RightEdge; | ||
72 | } | 56 | } | ||
73 | } | 57 | } | ||
74 | 58 | | |||
75 | return plasmoid.location; | 59 | return plasmoid.location; | ||
76 | } | 60 | } | ||
77 | 61 | | |||
78 | //BEGIN CONNECTIONS | 62 | //BEGIN CONNECTIONS | ||
79 | 63 | | |||
80 | property int creationId // used for item order tie breaking | | |||
81 | onEffectiveStatusChanged: updateItemVisibility(abstractItem) | | |||
82 | onCategoryChanged: updateItemVisibility(abstractItem) | | |||
83 | onTextChanged: updateItemVisibility(abstractItem) | | |||
84 | Component.onCompleted: { | | |||
85 | creationId = root.creationIdCounter++ | | |||
86 | updateItemVisibility(abstractItem) | | |||
87 | } | | |||
88 | | ||||
89 | onContainsMouseChanged: { | 64 | onContainsMouseChanged: { | ||
90 | if (hidden && containsMouse) { | 65 | if (inHiddenLayout && containsMouse) { | ||
91 | root.hiddenLayout.hoveredItem = abstractItem | 66 | root.hiddenLayout.currentIndex = index | ||
92 | } | 67 | } | ||
93 | } | 68 | } | ||
94 | 69 | | |||
95 | //END CONNECTIONS | 70 | //END CONNECTIONS | ||
96 | 71 | | |||
97 | PulseAnimation { | 72 | PulseAnimation { | ||
98 | targetItem: iconItem | 73 | targetItem: iconItem | ||
99 | running: (abstractItem.status === PlasmaCore.Types.NeedsAttentionStatus || | 74 | running: (abstractItem.status === PlasmaCore.Types.NeedsAttentionStatus || | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
149 | 124 | | |||
150 | PlasmaComponents.Label { | 125 | PlasmaComponents.Label { | ||
151 | id: label | 126 | id: label | ||
152 | anchors { | 127 | anchors { | ||
153 | left: parent.left | 128 | left: parent.left | ||
154 | leftMargin: iconItem ? iconItem.width + units.smallSpacing : 0 | 129 | leftMargin: iconItem ? iconItem.width + units.smallSpacing : 0 | ||
155 | verticalCenter: parent.verticalCenter | 130 | verticalCenter: parent.verticalCenter | ||
156 | } | 131 | } | ||
157 | opacity: labelVisible ? 1 : 0 | 132 | opacity: visible ? 1 : 0 | ||
158 | visible: abstractItem.hidden | 133 | visible: abstractItem.inHiddenLayout && !root.activeApplet | ||
159 | Behavior on opacity { | 134 | Behavior on opacity { | ||
160 | NumberAnimation { | 135 | NumberAnimation { | ||
161 | duration: units.longDuration | 136 | duration: units.longDuration | ||
162 | easing.type: Easing.InOutQuad | 137 | easing.type: Easing.InOutQuad | ||
163 | } | 138 | } | ||
164 | } | 139 | } | ||
165 | } | 140 | } | ||
166 | } | 141 | } | ||
167 | 142 | |
Lets look at fixing in a follow up patch
QML can do enums now