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: inVisibleLayout ? visibleLayout.iconSize : hiddenLayout.iconItemHeight | 28 | height: inVisibleLayout ? visibleLayout.cellHeight : hiddenLayout.iconItemHeight | ||
28 | width: inVisibleLayout ? visibleLayout.iconSize : hiddenLayout.width | 29 | width: inVisibleLayout ? visibleLayout.cellWidth : hiddenLayout.width | ||
29 | 30 | | |||
30 | property string itemId | 31 | property string itemId | ||
31 | property string category | | |||
32 | property alias text: label.text | 32 | property alias text: label.text | ||
33 | property Item iconItem | 33 | property Item iconItem | ||
34 | property int /*PlasmaCore.Types.ItemStatus*/ status | 34 | property int /*PlasmaCore.Types.ItemStatus*/ status | ||
35 | property int /*PlasmaCore.Types.ItemStatus*/ effectiveStatus | ||||
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 | |||||
35 | readonly property bool inHiddenLayout: effectiveStatus === PlasmaCore.Types.PassiveStatus | 36 | readonly property bool inHiddenLayout: effectiveStatus === PlasmaCore.Types.PassiveStatus | ||
36 | readonly property bool inVisibleLayout: effectiveStatus === PlasmaCore.Types.ActiveStatus | 37 | readonly property bool inVisibleLayout: effectiveStatus === PlasmaCore.Types.ActiveStatus | ||
37 | property QtObject model | | |||
38 | 38 | | |||
39 | signal clicked(var mouse) | 39 | signal clicked(var mouse) | ||
40 | signal pressed(var mouse) | 40 | signal pressed(var mouse) | ||
41 | signal wheel(var wheel) | 41 | signal wheel(var wheel) | ||
42 | signal contextMenu(var mouse) | 42 | signal contextMenu(var mouse) | ||
43 | 43 | | |||
44 | property bool forcedHidden: plasmoid.configuration.hiddenItems.indexOf(itemId) !== -1 | | |||
45 | property bool forcedShown: plasmoid.configuration.showAllItems || plasmoid.configuration.shownItems.indexOf(itemId) !== -1 | | |||
46 | | ||||
47 | readonly property int effectiveStatus: { | | |||
48 | if (status === PlasmaCore.Types.HiddenStatus) { | | |||
49 | return PlasmaCore.Types.HiddenStatus | | |||
50 | } else if (forcedShown || (!forcedHidden && status !== PlasmaCore.Types.PassiveStatus)) { | | |||
51 | return PlasmaCore.Types.ActiveStatus | | |||
52 | } else { | | |||
53 | return PlasmaCore.Types.PassiveStatus | | |||
54 | } | | |||
55 | } | | |||
56 | | ||||
57 | /* subclasses need to assign to this tooltip properties | 44 | /* subclasses need to assign to this tooltip properties | ||
58 | mainText: | 45 | mainText: | ||
59 | subText: | 46 | subText: | ||
60 | icon: | 47 | icon: | ||
61 | */ | 48 | */ | ||
62 | 49 | | |||
63 | location: { | 50 | location: { | ||
64 | if (inHiddenLayout) { | 51 | if (inHiddenLayout) { | ||
65 | if (LayoutMirroring.enabled && plasmoid.location !== PlasmaCore.Types.RightEdge) { | 52 | if (LayoutMirroring.enabled && plasmoid.location !== PlasmaCore.Types.RightEdge) { | ||
66 | return PlasmaCore.Types.LeftEdge; | 53 | return PlasmaCore.Types.LeftEdge; | ||
67 | } else if (plasmoid.location !== PlasmaCore.Types.LeftEdge) { | 54 | } else if (plasmoid.location !== PlasmaCore.Types.LeftEdge) { | ||
68 | return PlasmaCore.Types.RightEdge; | 55 | return PlasmaCore.Types.RightEdge; | ||
69 | } | 56 | } | ||
70 | } | 57 | } | ||
71 | 58 | | |||
72 | return plasmoid.location; | 59 | return plasmoid.location; | ||
73 | } | 60 | } | ||
74 | 61 | | |||
75 | //BEGIN CONNECTIONS | 62 | //BEGIN CONNECTIONS | ||
76 | 63 | | |||
77 | property int creationId // used for item order tie breaking | | |||
78 | onEffectiveStatusChanged: updateItemVisibility(abstractItem) | | |||
79 | onCategoryChanged: updateItemVisibility(abstractItem) | | |||
80 | onTextChanged: updateItemVisibility(abstractItem) | | |||
81 | Component.onCompleted: { | | |||
82 | creationId = root.creationIdCounter++ | | |||
83 | updateItemVisibility(abstractItem) | | |||
84 | } | | |||
85 | | ||||
86 | onContainsMouseChanged: { | 64 | onContainsMouseChanged: { | ||
87 | if (inHiddenLayout && containsMouse) { | 65 | if (inHiddenLayout && containsMouse) { | ||
88 | root.hiddenLayout.hoveredItem = abstractItem | 66 | root.hiddenLayout.currentIndex = index | ||
89 | } | 67 | } | ||
90 | } | 68 | } | ||
91 | 69 | | |||
92 | //END CONNECTIONS | 70 | //END CONNECTIONS | ||
93 | 71 | | |||
94 | PulseAnimation { | 72 | PulseAnimation { | ||
95 | targetItem: iconItem | 73 | targetItem: iconItem | ||
96 | running: (abstractItem.status === PlasmaCore.Types.NeedsAttentionStatus || | 74 | running: (abstractItem.status === PlasmaCore.Types.NeedsAttentionStatus || | ||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |
Lets look at fixing in a follow up patch
QML can do enums now