Changeset View
Changeset View
Standalone View
Standalone View
toolboxes/desktoptoolbox/contents/ui/ToolBoxRoot.qml
Show All 33 Lines | 31 | Item { | |||
---|---|---|---|---|---|
34 | 34 | | |||
35 | z: 999 | 35 | z: 999 | ||
36 | anchors.fill: parent | 36 | anchors.fill: parent | ||
37 | 37 | | |||
38 | Connections { | 38 | Connections { | ||
39 | target: plasmoid | 39 | target: plasmoid | ||
40 | onAvailableScreenRegionChanged: placeToolBoxTimer.restart(); | 40 | onAvailableScreenRegionChanged: placeToolBoxTimer.restart(); | ||
41 | } | 41 | } | ||
42 | 42 | | |||
43 | //FIXME: this timer shouldn't exist, but unfortunately when the focus passes | | |||
44 | //from the desktop to the dialog or vice versa, the event is not atomic | | |||
45 | //and ends up with neither of those having focus, hiding the dialog when | | |||
46 | //it shouldn't | | |||
47 | Timer { | | |||
48 | id: hideDialogTimer | | |||
49 | interval: 0 | | |||
50 | //NOTE: it's checking activeFocusItem instead of active as active doesn't correctly signal its change | | |||
51 | property bool desktopOrDialogFocus: main.Window.activeFocusItem !== null || (toolBoxLoader.item && toolBoxLoader.item.activeFocusItem !== null) | | |||
52 | onDesktopOrDialogFocusChanged: { | | |||
53 | if (!desktopOrDialogFocus) { | | |||
54 | hideDialogTimer.restart(); | | |||
55 | } | | |||
56 | | ||||
57 | } | | |||
58 | onTriggered: { | | |||
59 | if (!desktopOrDialogFocus) { | | |||
60 | open = false; | | |||
61 | } | | |||
62 | } | | |||
63 | } | | |||
64 | | ||||
65 | signal minimumWidthChanged | | |||
66 | signal minimumHeightChanged | | |||
67 | signal maximumWidthChanged | | |||
68 | signal maximumHeightChanged | | |||
69 | signal preferredWidthChanged | | |||
70 | signal preferredHeightChanged | | |||
71 | | ||||
72 | property int iconSize: units.iconSizes.small | 43 | property int iconSize: units.iconSizes.small | ||
davidedmundson: fix | |||||
73 | property int iconWidth: units.iconSizes.smallMedium | 44 | property int iconWidth: units.iconSizes.smallMedium | ||
74 | property int iconHeight: iconWidth | 45 | property int iconHeight: iconWidth | ||
75 | property bool dialogWasVisible: false | 46 | property bool dialogWasVisible: false | ||
76 | property bool open: false | 47 | property bool open: false | ||
77 | onOpenChanged: { | | |||
78 | plasmoid.editMode = open | | |||
79 | if (open) { | | |||
80 | plasmoid.contextualActionsAboutToShow(); | | |||
81 | | ||||
82 | toolBoxLoader.active = true; | | |||
83 | toolBoxLoader.item.visible = true; | | |||
84 | } else { | | |||
85 | toolBoxLoader.item.visible = false; | | |||
86 | } | | |||
87 | } | | |||
88 | 48 | | |||
89 | onWidthChanged: placeToolBoxTimer.restart(); | 49 | onWidthChanged: placeToolBoxTimer.restart(); | ||
90 | onHeightChanged: placeToolBoxTimer.restart(); | 50 | onHeightChanged: placeToolBoxTimer.restart(); | ||
91 | 51 | | |||
92 | LayoutMirroring.enabled: (Qt.application.layoutDirection === Qt.RightToLeft) | 52 | LayoutMirroring.enabled: (Qt.application.layoutDirection === Qt.RightToLeft) | ||
93 | LayoutMirroring.childrenInherit: true | 53 | LayoutMirroring.childrenInherit: true | ||
94 | 54 | | |||
95 | onVisibleChanged: { | | |||
96 | if (!visible && toolBoxLoader.item) { | | |||
97 | toolBoxLoader.item.visible = false | | |||
98 | } | | |||
99 | } | | |||
100 | | ||||
101 | ToolBoxButton { | 55 | ToolBoxButton { | ||
102 | id: toolBoxButton | 56 | id: toolBoxButton | ||
103 | visible: false | 57 | visible: false | ||
104 | Component.onCompleted: { | 58 | Component.onCompleted: { | ||
105 | placeToolBox(plasmoid.configuration.ToolBoxButtonState); | 59 | placeToolBox(plasmoid.configuration.ToolBoxButtonState); | ||
106 | toolBoxButton.visible = true | 60 | toolBoxButton.visible = true | ||
107 | } | 61 | } | ||
108 | } | 62 | } | ||
109 | 63 | | |||
110 | Timer { | 64 | Timer { | ||
111 | id: placeToolBoxTimer | 65 | id: placeToolBoxTimer | ||
112 | interval: 100 | 66 | interval: 100 | ||
113 | repeat: false | 67 | repeat: false | ||
114 | running: false | 68 | running: false | ||
115 | onTriggered: { | 69 | onTriggered: { | ||
116 | placeToolBox(plasmoid.configuration.ToolBoxButtonState); | 70 | placeToolBox(plasmoid.configuration.ToolBoxButtonState); | ||
117 | } | 71 | } | ||
118 | } | 72 | } | ||
119 | 73 | | |||
120 | Loader { | | |||
121 | id: toolBoxLoader | | |||
122 | active: false | | |||
123 | sourceComponent: PlasmaCore.Dialog { | | |||
124 | id: dialog | | |||
125 | flags: Qt.WindowStaysOnTopHint | | |||
126 | location: PlasmaCore.Types.Floating | | |||
127 | visualParent: toolBoxButton | | |||
128 | // hideOnWindowDeactivate: true | | |||
129 | mainItem: ToolBoxItem { | | |||
130 | LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft | | |||
131 | LayoutMirroring.childrenInherit: true | | |||
132 | | ||||
133 | Timer { | | |||
134 | id: visibleTimer | | |||
135 | interval: 300 | | |||
136 | onTriggered: main.dialogWasVisible = dialog.visible | | |||
137 | } | | |||
138 | } | | |||
139 | onVisibleChanged: visibleTimer.restart(); | | |||
140 | } | | |||
141 | } | | |||
142 | | ||||
143 | function placeToolBox(ts) { | 74 | function placeToolBox(ts) { | ||
144 | // if nothing has been setup yet, determine default position based on layout direction | 75 | // if nothing has been setup yet, determine default position based on layout direction | ||
145 | if (!ts) { | 76 | if (!ts) { | ||
146 | if (Qt.application.layoutDirection === Qt.RightToLeft) { | 77 | placeToolBox("topcenter"); | ||
147 | placeToolBox("topleft"); | | |||
148 | } else { | | |||
149 | placeToolBox("topright"); | | |||
150 | } | | |||
151 | return; | 78 | return; | ||
152 | } | 79 | } | ||
153 | 80 | | |||
154 | var tx = Plasmoid.configuration.ToolBoxButtonX | 81 | var tx = Plasmoid.configuration.ToolBoxButtonX | ||
155 | var ty = Plasmoid.configuration.ToolBoxButtonY | 82 | var ty = Plasmoid.configuration.ToolBoxButtonY | ||
156 | var pos; | 83 | var pos; | ||
157 | 84 | | |||
158 | switch (ts) { | 85 | switch (ts) { | ||
159 | case "top": | 86 | case "top": | ||
160 | ty = main.y; | 87 | ty = main.y; | ||
161 | pos = plasmoid.adjustToAvailableScreenRegion(tx, ty, toolBoxButton.width, toolBoxButton.height); | 88 | pos = plasmoid.adjustToAvailableScreenRegion(tx, ty, toolBoxButton.width, toolBoxButton.height); | ||
162 | break; | 89 | break; | ||
163 | case "left": | | |||
164 | tx = main.x; | | |||
165 | pos = plasmoid.adjustToAvailableScreenRegion(tx, ty, toolBoxButton.width, toolBoxButton.height); | | |||
166 | break; | | |||
167 | case "right": | | |||
168 | tx = main.width + main.x - toolBoxButton.width; | | |||
169 | pos = plasmoid.adjustToAvailableScreenRegion(tx, ty, toolBoxButton.width, toolBoxButton.height); | | |||
170 | break; | | |||
171 | case "bottom": | 90 | case "bottom": | ||
172 | ty = main.height + main.y - toolBoxButton.height; | 91 | ty = main.height + main.y - toolBoxButton.height; | ||
173 | pos = plasmoid.adjustToAvailableScreenRegion(tx, ty, toolBoxButton.width, toolBoxButton.height); | 92 | pos = plasmoid.adjustToAvailableScreenRegion(tx, ty, toolBoxButton.width, toolBoxButton.height); | ||
174 | break; | 93 | break; | ||
175 | case "topleft": | 94 | case "bottomcenter": | ||
176 | tx = main.x; | 95 | tx = main.width / 2 - toolBoxButton.width / 2; | ||
177 | ty = main.y; | | |||
178 | pos = plasmoid.adjustToAvailableScreenRegion(tx, ty, toolBoxButton.height, toolBoxButton.height); | | |||
179 | break; | | |||
180 | case "topright": | | |||
181 | tx = main.width + main.x - toolBoxButton.height; | | |||
182 | ty = main.y; | | |||
183 | pos = plasmoid.adjustToAvailableScreenRegion(tx, ty, toolBoxButton.height, toolBoxButton.height); | | |||
184 | break; | | |||
185 | case "bottomleft": | | |||
186 | tx = main.x; | | |||
187 | ty = main.height + main.y - toolBoxButton.height; | 96 | ty = main.height + main.y - toolBoxButton.height; | ||
188 | pos = plasmoid.adjustToAvailableScreenRegion(tx, ty, toolBoxButton.height, toolBoxButton.height); | 97 | pos = plasmoid.adjustToAvailableScreenRegion(tx, ty, toolBoxButton.width, toolBoxButton.height); | ||
189 | break; | 98 | break; | ||
190 | case "bottomright": | 99 | case "topcenter": | ||
191 | default: | 100 | default: | ||
192 | tx = main.width + main.x - toolBoxButton.height; | 101 | tx = main.width / 2 - toolBoxButton.width / 2; | ||
193 | ty = main.height + main.y - toolBoxButton.height; | 102 | ty = main.y; | ||
194 | pos = plasmoid.adjustToAvailableScreenRegion(tx, ty, toolBoxButton.height, toolBoxButton.height); | 103 | pos = plasmoid.adjustToAvailableScreenRegion(tx, ty, toolBoxButton.width, toolBoxButton.height); | ||
195 | break; | 104 | break; | ||
196 | } | 105 | } | ||
197 | //print("XXXY Setting toolbox to: " + ts + " " + tx + "x" + ty + " screen: " + main.width+ "x" + main.height+""); | 106 | //print("XXXY Setting toolbox to: " + ts + " " + tx + "x" + ty + " screen: " + main.width+ "x" + main.height+""); | ||
198 | 107 | | |||
199 | toolBoxButton.x = pos.x; | 108 | toolBoxButton.x = pos.x; | ||
200 | toolBoxButton.y = pos.y; | 109 | toolBoxButton.y = pos.y; | ||
201 | } | 110 | } | ||
202 | } | 111 | } |
fix