25 import
QtQml.Models 2.12
28 import org.
kde.kitemmodels 1.0 as KItemModels
34 property bool supportsColors:
true 35 property int maxAllowedSensors: -1
36 property var selected: []
37 property var colors: {}
39 signal selectColor(
string sensorId)
40 signal colorForSensorGenerated(
string sensorId, color color)
43 if (!control.selected) {
46 for (let i = 0; i < Math.min(control.selected.length, selectedModel.count); ++i) {
47 selectedModel.set(i, {
"sensor": control.selected[i]});
49 if (selectedModel.count > control.selected.length) {
50 selectedModel.remove(control.selected.length, selectedModel.count - control.selected.length);
51 }
else if (selectedModel.count < control.selected.length) {
52 for (let i = selectedModel.count; i < control.selected.length; ++i) {
53 selectedModel.append({
"sensor": control.selected[i]});
58 background: TextField {
63 if (focus && (maxAllowedSensors <= 0 || repeater.count < maxAllowedSensors)) {
70 if (focus && (maxAllowedSensors <= 0 || repeater.count < maxAllowedSensors)) {
82 duration:
Kirigami.Units.shortDuration
83 easing.type: Easing.InOutQuad
90 function writeSelectedSensors() {
92 for (let i = 0; i < count; ++i) {
93 newSelected.push(
get(i).sensor);
95 control.selected = newSelected;
96 control.selectedChanged();
102 implicitHeight: layout.implicitHeight +
Kirigami.Units.smallSpacing * 2
103 implicitWidth: Math.min(layout.implicitWidth +
Kirigami.Units.smallSpacing * 2,
104 control.width - control.leftPadding - control.rightPadding)
105 readonly
property int position: index
115 border.color:
Kirigami.Theme.highlightColor
117 opacity: (control.maxAllowedSensors <= 0 || index < control.maxAllowedSensors) ? 1 : 0.4
118 parent: drag.active ? control : delegate
120 width: delegate.width
121 height: delegate.height
126 enabled: selectedModel.count > 1
129 let pos = delegateContents.mapFromItem(control.contentItem, 0, 0);
130 delegateContents.x = pos.x;
131 delegateContents.y = pos.y;
133 let pos = delegate.mapFromItem(delegateContents, 0, 0);
134 delegateContents.x = pos.x;
135 delegateContents.y = pos.y;
137 selectedModel.writeSelectedSensors();
142 maximum: control.width - delegateContents.width
146 maximum: control.height - delegateContents.height
149 if (!active || control.contentItem.move.running) {
152 let pos = control.contentItem.mapFromItem(null, drag.centroid.scenePosition.x, drag.centroid.scenePosition.y);
153 pos.x = Math.max(0, Math.min(control.contentItem.width - 1, pos.x));
154 pos.y = Math.max(0, Math.min(control.contentItem.height - 1, pos.y));
156 let child = control.contentItem.childAt(pos.x, pos.y);
157 if (child === delegate) {
161 if (pos.x > child.x + child.width/2) {
162 newIndex = Math.min(child.position + 1, selectedModel.count - 1);
164 newIndex = child.position;
166 selectedModel.move(index, newIndex, 1);
173 target: delegateContents
174 from: delegateContents.x
176 duration:
Kirigami.Units.shortDuration
177 easing.type: Easing.InOutQuad
180 target: delegateContents
181 from: delegateContents.y
183 duration:
Kirigami.Units.shortDuration
184 easing.type: Easing.InOutQuad
188 Sensors.Sensor {
id: sensor; sensorId: model.sensor }
190 Component.onCompleted: {
191 if (typeof control.colors ===
"undefined" ||
192 typeof control.colors[sensor.sensorId] ===
"undefined") {
193 let color =
Qt.hsva(Math.random(),
Kirigami.Theme.highlightColor.hsvSaturation,
Kirigami.Theme.highlightColor.hsvValue, 1);
194 control.colorForSensorGenerated(sensor.sensorId, color)
202 anchors.margins:
Kirigami.Units.smallSpacing
205 visible: control.supportsColors
206 Layout.preferredWidth:
Kirigami.Units.iconSizes.smallMedium
207 Layout.preferredHeight:
Kirigami.Units.iconSizes.smallMedium
209 padding:
Kirigami.Units.smallSpacing
211 contentItem: Rectangle {
212 color: typeof control.colors ===
"undefined" ?
"black" : control.colors[sensor.sensorId]
215 onClicked: control.selectColor(sensor.sensorId)
221 Layout.fillWidth:
true 224 Layout.maximumWidth: labelMetrics.boundingRect.width +
Kirigami.Units.gridUnit
232 elide:
Text.ElideRight
234 HoverHandler {
id: handler }
242 icon.name:
"edit-delete-remove" 243 icon.width:
Kirigami.Units.iconSizes.small
244 icon.height:
Kirigami.Units.iconSizes.small
245 Layout.preferredWidth:
Kirigami.Units.iconSizes.smallMedium
246 Layout.preferredHeight:
Kirigami.Units.iconSizes.smallMedium
249 if (control.selected === undefined || control.selected === null) {
250 control.selected = []
252 control.selected.splice(control.selected.indexOf(sensor.sensorId), 1)
253 control.selectedChanged()
262 width:
Kirigami.Units.iconSizes.smallMedium +
Kirigami.Units.smallSpacing * 2
264 visible: control.maxAllowedSensors <= 0 || control.selected.length < control.maxAllowedSensors
272 y: (control.Kirigami.ScenePosition.y + control.height + height > control.Window.height)
275 implicitHeight: Math.min(contentItem.implicitHeight + 2,
Kirigami.Units.gridUnit * 20)
276 width: control.width + 2
283 closePolicy:
Popup.CloseOnEscape |
Popup.CloseOnPressOutside
288 if (control.Kirigami.ScenePosition.y + control.height + height > control.Window.height) {
294 searchField.forceActiveFocus();
296 onClosed: delegateModel.rootIndex = delegateModel.parentModelIndex()
298 contentItem: ColumnLayout {
301 Layout.fillWidth:
true 302 Layout.minimumHeight: implicitHeight
303 Layout.maximumHeight: implicitHeight
304 Layout.leftMargin:
Kirigami.Units.smallSpacing
305 Layout.topMargin:
Kirigami.Units.smallSpacing
306 Layout.rightMargin:
Kirigami.Units.smallSpacing
307 Layout.bottomMargin:
Kirigami.Units.smallSpacing
310 Layout.fillHeight:
true 311 Layout.preferredWidth: height
312 icon.name:
"go-previous" 313 text:
i18nc(
"@action:button",
"Back")
314 display: Button.IconOnly
315 visible: delegateModel.rootIndex.valid
316 onClicked: delegateModel.rootIndex = delegateModel.parentModelIndex()
321 Layout.fillWidth:
true 322 Layout.fillHeight:
true 323 placeholderText:
i18n(
"Search...")
324 onTextEdited: listView.searchString = text
325 KeyNavigation.down: listView
329 Layout.fillWidth:
true 332 Layout.fillWidth:
true 333 Layout.fillHeight:
true 334 ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
343 property string searchString
345 implicitHeight: contentHeight
346 model: DelegateModel {
349 model: listView.searchString ? sensorsSearchableModel : treeModel
351 width: listView.width
353 reserveSpaceForIcon:
false 356 if (model.SensorId.length == 0) {
357 delegateModel.rootIndex = delegateModel.modelIndex(index);
359 if (control.selected === undefined || control.selected === null) {
360 control.selected = []
362 const length = control.selected.push(model.SensorId)
363 control.selectedChanged()
364 if (control.maxAllowedSensors == length) {
372 Sensors.SensorTreeModel {
id: treeModel }
374 KItemModels.KSortFilterProxyModel {
375 id: sensorsSearchableModel
376 filterCaseSensitivity:
Qt.CaseInsensitive
377 filterString: listView.searchString
378 sourceModel: KItemModels.KSortFilterProxyModel {
379 filterRowCallback:
function(row, parent) {
380 var sensorId = sourceModel.data(sourceModel.index(row, 0), Sensors.SensorTreeModel.SensorId)
381 return sensorId.length > 0
383 sourceModel: KItemModels.KDescendantsProxyModel {
384 model: listView.searchString ? treeModel : null
389 highlightRangeMode: ListView.ApplyRange
390 highlightMoveDuration: 0
391 boundsBehavior: Flickable.StopAtBounds
410 color:
Kirigami.Theme.backgroundColor
412 property color borderColor:
Kirigami.Theme.textColor
413 border.color:
Qt.rgba(borderColor.r, borderColor.g, borderColor.b, 0.3)
418 shadow.color:
Qt.rgba(0, 0, 0, 0.3)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString label(StandardShortcut id)
QString i18n(const char *text, const TYPE &arg...)
KIOCORE_EXPORT CopyJob * move(const QUrl &src, const QUrl &dest, JobFlags flags=DefaultFlags)