MauiKit Calendar

CollectionComboBox.qml
1// SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
2// SPDX-License-Identifier: LGPL-2.0-or-later
3
4import QtQuick
5import QtQuick.Controls
6import org.mauikit.calendar as Cal
7import org.mauikit.controls as Maui
8
9/**
10 * Special combobox control that allows to choose a collection.
11 * The collection displayed can be filtered using the \p mimeTypeFilter
12 * and @p accessRightsFilter properties.
13 */
14ComboBox
15{
16 id: comboBox
17
18 /**
19 * This property holds the id of the default collection, that is the
20 * collection that will be selected by default.
21 * @property int defaultCollectionId
22 */
23 property alias defaultCollectionId: collectionComboBoxModel.defaultCollectionId
24
25 /**
26 * This property holds the mime types of the collection that should be
27 * displayed.
28 *
29 * @property list<string> mimeTypeFilter
30 * @code{.qml}
31 * import org.mauikit.calendar 1.0 as Cal
32 *
33 * Cal.CollectionComboBoxModel {
34 * mimeTypeFilter: [Cal.MimeTypes.address, Cal.MimeTypes.contactGroup]
35 * }
36 * @endcode
37 */
38 property alias mimeTypeFilter: collectionComboBoxModel.mimeTypeFilter
39
40 /**
41 * This property holds the access right of the collection that should be
42 * displayed.
43 *
44 * @property Cal::Collection::Rights rights
45 * @code{.qml}
46 * import org.mauikit.calendar 1.0 as Cal
47 *
48 * Cal.CollectionComboBoxModel {
49 * accessRightsFilter: Cal.Collection.CanCreateItem
50 * }
51 * @endcode
52 */
53 property alias accessRightsFilter: collectionComboBoxModel.accessRightsFilter
54
55 signal userSelectedCollection(var collection)
56
57 currentIndex: 0
58 onActivated: if (index > -1) {
59 const selectedModelIndex = collectionComboBoxModel.index(currentIndex, 0);
60 const selectedCollection = collectionComboBoxModel.data(selectedModelIndex, Cal.Collection.CollectionRole);
61 userSelectedCollection(selectedCollection);
62 }
63
64 textRole: "display"
65 valueRole: "collectionId"
66
67 indicator: Rectangle {
68 id: indicatorDot
69
70 // Make sure to check the currentValue property directly or risk listening to something that won't necessarily emit a changed() signal'
71 readonly property var selectedModelIndex: comboBox.currentValue > -1 ? comboBox.model.index(comboBox.currentIndex, 0) : null
72 readonly property var selectedCollectionColor: comboBox.currentValue > -1 ? comboBox.model.data(selectedModelIndex, Cal.Collection.CollectionColorRole) : null
73
74 implicitHeight: comboBox.implicitHeight * 0.4
75 implicitWidth: implicitHeight
76
77 x: comboBox.mirrored ? comboBox.leftPadding : comboBox.width - (comboBox.leftPadding * 3) - Maui.Style.iconSizes.medium
78 y: comboBox.topPadding + (comboBox.availableHeight - height) / 2
79
80 radius: width * 0.5
81 color: selectedCollectionColor
82 }
83
84 model: Cal.CollectionComboBoxModel {
85 id: collectionComboBoxModel
86 onCurrentIndexChanged: comboBox.currentIndex = currentIndex
87 }
88
89 delegate: MenuItem
90 {
91 text: display
92 icon.name: decoration
93 indicator: Rectangle {
94 anchors.margins: Maui.Style.space.medium
95 width: height
96 radius: width * 0.5
97 color: model.collectionColor
98 }
99 }
100
101 popup.z: 1000
102}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:56:05 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.