Changeset View
Changeset View
Standalone View
Standalone View
kcms/notifications/package/contents/ui/ScreenPositionSelector.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2015 (C) Martin Klapetek <mklapetek@kde.org> | ||||
3 | * Copyright 2019 (C) Kai Uwe Broulik <kde@privat.broulik.de> | ||||
4 | * | ||||
5 | * This program is free software; you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU General Public License as | ||||
7 | * published by the Free Software Foundation; either version 2 of | ||||
8 | * the License or (at your option) version 3 or any later version | ||||
9 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
10 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
11 | * defined in 14 of version 3 of the license. | ||||
12 | * | ||||
13 | * This program is distributed in the hope that it will be useful, | ||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
16 | * GNU General Public License for more details. | ||||
17 | * | ||||
18 | * You should have received a copy of the GNU General Public License | ||||
19 | * along with this program. If not, see <http://www.gnu.org/licenses/> | ||||
20 | */ | ||||
21 | | ||||
22 | import QtQuick 2.0 | ||||
23 | import QtQuick.Window 2.1 | ||||
24 | import QtQuick.Controls 2.2 as QtControls | ||||
25 | import org.kde.kirigami 2.4 as Kirigami | ||||
26 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
27 | | ||||
28 | import org.kde.notificationmanager 1.0 as NotificationManager | ||||
29 | | ||||
30 | Item { | ||||
31 | id: monitorPanel | ||||
32 | | ||||
33 | property int baseUnit: Kirigami.Units.gridUnit | ||||
34 | | ||||
35 | implicitWidth: baseUnit * 13 + baseUnit * 2 | ||||
36 | implicitHeight: (screenRatio * baseUnit * 13) + (baseUnit * 2) + basePart.height | ||||
37 | | ||||
38 | property int selectedPosition | ||||
39 | property var disabledPositions: [] | ||||
40 | property real screenRatio: Screen.height / Screen.width | ||||
41 | | ||||
42 | onSelectedPositionChanged: { | ||||
43 | var buttons = positionRadios.buttons.length; | ||||
44 | for (var i = 0; i < buttons.length; ++i) { | ||||
45 | var button = buttons[i]; | ||||
46 | if (button.position === selectedPosition) { | ||||
47 | button.checked = true; | ||||
48 | break; | ||||
49 | } | ||||
50 | } | ||||
51 | } | ||||
52 | | ||||
53 | PlasmaCore.Svg { | ||||
54 | id: monitorSvg | ||||
55 | imagePath: "widgets/monitor" | ||||
56 | } | ||||
57 | | ||||
58 | PlasmaCore.SvgItem { | ||||
59 | id: topleftPart | ||||
60 | anchors { | ||||
61 | left: parent.left | ||||
62 | top: parent.top | ||||
63 | } | ||||
64 | svg: monitorSvg | ||||
65 | elementId: "topleft" | ||||
66 | width: baseUnit | ||||
67 | height: baseUnit | ||||
68 | } | ||||
69 | | ||||
70 | PlasmaCore.SvgItem { | ||||
71 | id: topPart | ||||
72 | anchors { | ||||
73 | top: parent.top | ||||
74 | left: topleftPart.right | ||||
75 | right: toprightPart.left | ||||
76 | } | ||||
77 | svg: monitorSvg | ||||
78 | elementId: "top" | ||||
79 | height: baseUnit | ||||
80 | } | ||||
81 | | ||||
82 | PlasmaCore.SvgItem { | ||||
83 | id: toprightPart | ||||
84 | anchors { | ||||
85 | right: parent.right | ||||
86 | top: parent.top | ||||
87 | } | ||||
88 | svg: monitorSvg | ||||
89 | elementId: "topright" | ||||
90 | width: baseUnit | ||||
91 | height: baseUnit | ||||
92 | } | ||||
93 | | ||||
94 | PlasmaCore.SvgItem { | ||||
95 | id: leftPart | ||||
96 | anchors { | ||||
97 | left: parent.left | ||||
98 | top: topleftPart.bottom | ||||
99 | bottom: bottomleftPart.top | ||||
100 | } | ||||
101 | svg: monitorSvg | ||||
102 | elementId: "left" | ||||
103 | width: baseUnit | ||||
104 | } | ||||
105 | | ||||
106 | PlasmaCore.SvgItem { | ||||
107 | id: rightPart | ||||
108 | anchors { | ||||
109 | right: parent.right | ||||
110 | top: toprightPart.bottom | ||||
111 | bottom: bottomrightPart.top | ||||
112 | } | ||||
113 | svg: monitorSvg | ||||
114 | elementId: "right" | ||||
115 | width: baseUnit | ||||
116 | } | ||||
117 | | ||||
118 | PlasmaCore.SvgItem { | ||||
119 | id: bottomleftPart | ||||
120 | anchors { | ||||
121 | left: parent.left | ||||
122 | bottom: basePart.top | ||||
123 | } | ||||
124 | svg: monitorSvg | ||||
125 | elementId: "bottomleft" | ||||
126 | width: baseUnit | ||||
127 | height: baseUnit | ||||
128 | } | ||||
129 | | ||||
130 | PlasmaCore.SvgItem { | ||||
131 | id: bottomPart | ||||
132 | anchors { | ||||
133 | bottom: basePart.top | ||||
134 | left: bottomleftPart.right | ||||
135 | right: bottomrightPart.left | ||||
136 | } | ||||
137 | svg: monitorSvg | ||||
138 | elementId: "bottom" | ||||
139 | height: baseUnit | ||||
140 | } | ||||
141 | | ||||
142 | PlasmaCore.SvgItem { | ||||
143 | id: bottomrightPart | ||||
144 | anchors { | ||||
145 | right: parent.right | ||||
146 | bottom: basePart.top | ||||
147 | } | ||||
148 | svg: monitorSvg | ||||
149 | elementId: "bottomright" | ||||
150 | width: baseUnit | ||||
151 | height: baseUnit | ||||
152 | } | ||||
153 | | ||||
154 | PlasmaCore.SvgItem { | ||||
155 | id: basePart | ||||
156 | anchors { | ||||
157 | bottom: parent.bottom | ||||
158 | horizontalCenter: parent.horizontalCenter | ||||
159 | } | ||||
160 | width: 120 | ||||
161 | height: 60 | ||||
162 | svg: monitorSvg | ||||
163 | elementId: "base" | ||||
164 | } | ||||
165 | | ||||
166 | QtControls.ButtonGroup { | ||||
167 | id: positionRadios | ||||
168 | onCheckedButtonChanged: monitorPanel.selectedPosition = checkedButton.position | ||||
169 | } | ||||
170 | | ||||
171 | // TODO increase hit area for radio buttons | ||||
172 | | ||||
173 | QtControls.RadioButton { | ||||
174 | anchors { | ||||
175 | top: topPart.bottom | ||||
176 | left: leftPart.right | ||||
177 | margins: Kirigami.Units.smallSpacing | ||||
178 | } | ||||
179 | readonly property int position: NotificationManager.Settings.TopLeft | ||||
180 | checked: monitorPanel.selectedPosition == position | ||||
181 | visible: monitorPanel.disabledPositions.indexOf(position) == -1 | ||||
182 | QtControls.ButtonGroup.group: positionRadios | ||||
183 | } | ||||
184 | QtControls.RadioButton { | ||||
185 | anchors { | ||||
186 | top: topPart.bottom | ||||
187 | horizontalCenter: topPart.horizontalCenter | ||||
188 | margins: Kirigami.Units.smallSpacing | ||||
189 | } | ||||
190 | readonly property int position: NotificationManager.Settings.TopCenter | ||||
191 | checked: monitorPanel.selectedPosition == position | ||||
192 | visible: monitorPanel.disabledPositions.indexOf(position) == -1 | ||||
193 | QtControls.ButtonGroup.group: positionRadios | ||||
194 | } | ||||
195 | QtControls.RadioButton { | ||||
196 | anchors { | ||||
197 | top: topPart.bottom | ||||
198 | right: rightPart.left | ||||
199 | margins: Kirigami.Units.smallSpacing | ||||
200 | } | ||||
201 | readonly property int position: NotificationManager.Settings.TopRight | ||||
202 | checked: monitorPanel.selectedPosition == position | ||||
203 | visible: monitorPanel.disabledPositions.indexOf(position) == -1 | ||||
204 | QtControls.ButtonGroup.group: positionRadios | ||||
205 | } | ||||
206 | QtControls.RadioButton { | ||||
207 | anchors { | ||||
208 | bottom: bottomPart.top | ||||
209 | left: leftPart.right | ||||
210 | margins: Kirigami.Units.smallSpacing | ||||
211 | } | ||||
212 | readonly property int position: NotificationManager.Settings.BottomLeft | ||||
213 | checked: monitorPanel.selectedPosition == position | ||||
214 | visible: monitorPanel.disabledPositions.indexOf(position) == -1 | ||||
215 | QtControls.ButtonGroup.group: positionRadios | ||||
216 | } | ||||
217 | QtControls.RadioButton { | ||||
218 | anchors { | ||||
219 | bottom: bottomPart.top | ||||
220 | horizontalCenter: bottomPart.horizontalCenter | ||||
221 | margins: Kirigami.Units.smallSpacing | ||||
222 | } | ||||
223 | readonly property int position: NotificationManager.Settings.BottomCenter | ||||
224 | checked: monitorPanel.selectedPosition == position | ||||
225 | visible: monitorPanel.disabledPositions.indexOf(position) == -1 | ||||
226 | QtControls.ButtonGroup.group: positionRadios | ||||
227 | } | ||||
228 | QtControls.RadioButton { | ||||
229 | anchors { | ||||
230 | bottom: bottomPart.top | ||||
231 | right: rightPart.left | ||||
232 | margins: Kirigami.Units.smallSpacing | ||||
233 | } | ||||
234 | readonly property int position: NotificationManager.Settings.BottomRight | ||||
235 | checked: monitorPanel.selectedPosition == position | ||||
236 | visible: monitorPanel.disabledPositions.indexOf(position) == -1 | ||||
237 | QtControls.ButtonGroup.group: positionRadios | ||||
238 | } | ||||
239 | } |