Warning, /maui/mauikit-calendar/src/controls.6/CollectionComboBox.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu> 0002 // SPDX-License-Identifier: LGPL-2.0-or-later 0003 0004 import QtQuick 0005 import QtQuick.Controls 0006 import org.mauikit.calendar 1.0 as Cal 0007 import org.mauikit.controls 1.3 as Maui 0008 0009 /** 0010 * Special combobox control that allows to choose a collection. 0011 * The collection displayed can be filtered using the \p mimeTypeFilter 0012 * and @p accessRightsFilter properties. 0013 */ 0014 ComboBox 0015 { 0016 id: comboBox 0017 0018 /** 0019 * This property holds the id of the default collection, that is the 0020 * collection that will be selected by default. 0021 * @property int defaultCollectionId 0022 */ 0023 property alias defaultCollectionId: collectionComboBoxModel.defaultCollectionId 0024 0025 /** 0026 * This property holds the mime types of the collection that should be 0027 * displayed. 0028 * 0029 * @property list<string> mimeTypeFilter 0030 * @code{.qml} 0031 * import org.mauikit.calendar 1.0 as Cal 0032 * 0033 * Cal.CollectionComboBoxModel { 0034 * mimeTypeFilter: [Cal.MimeTypes.address, Cal.MimeTypes.contactGroup] 0035 * } 0036 * @endcode 0037 */ 0038 property alias mimeTypeFilter: collectionComboBoxModel.mimeTypeFilter 0039 0040 /** 0041 * This property holds the access right of the collection that should be 0042 * displayed. 0043 * 0044 * @property Cal::Collection::Rights rights 0045 * @code{.qml} 0046 * import org.mauikit.calendar 1.0 as Cal 0047 * 0048 * Cal.CollectionComboBoxModel { 0049 * accessRightsFilter: Cal.Collection.CanCreateItem 0050 * } 0051 * @endcode 0052 */ 0053 property alias accessRightsFilter: collectionComboBoxModel.accessRightsFilter 0054 0055 signal userSelectedCollection(var collection) 0056 0057 currentIndex: 0 0058 onActivated: if (index > -1) { 0059 const selectedModelIndex = collectionComboBoxModel.index(currentIndex, 0); 0060 const selectedCollection = collectionComboBoxModel.data(selectedModelIndex, Cal.Collection.CollectionRole); 0061 userSelectedCollection(selectedCollection); 0062 } 0063 0064 textRole: "display" 0065 valueRole: "collectionId" 0066 0067 indicator: Rectangle { 0068 id: indicatorDot 0069 0070 // Make sure to check the currentValue property directly or risk listening to something that won't necessarily emit a changed() signal' 0071 readonly property var selectedModelIndex: comboBox.currentValue > -1 ? comboBox.model.index(comboBox.currentIndex, 0) : null 0072 readonly property var selectedCollectionColor: comboBox.currentValue > -1 ? comboBox.model.data(selectedModelIndex, Cal.Collection.CollectionColorRole) : null 0073 0074 implicitHeight: comboBox.implicitHeight * 0.4 0075 implicitWidth: implicitHeight 0076 0077 x: comboBox.mirrored ? comboBox.leftPadding : comboBox.width - (comboBox.leftPadding * 3) - Maui.Style.iconSizes.medium 0078 y: comboBox.topPadding + (comboBox.availableHeight - height) / 2 0079 0080 radius: width * 0.5 0081 color: selectedCollectionColor 0082 } 0083 0084 model: Cal.CollectionComboBoxModel { 0085 id: collectionComboBoxModel 0086 onCurrentIndexChanged: comboBox.currentIndex = currentIndex 0087 } 0088 0089 delegate: MenuItem 0090 { 0091 text: display 0092 icon.name: decoration 0093 indicator: Rectangle { 0094 anchors.margins: Maui.Style.space.medium 0095 width: height 0096 radius: width * 0.5 0097 color: model.collectionColor 0098 } 0099 } 0100 0101 popup.z: 1000 0102 }