Warning, /plasma/latte-dock/declarativeimports/components/ComboBoxButton.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 import QtQuick.Controls 1.4 0007 import QtQuick 2.2 0008 import QtQuick.Layouts 1.3 0009 0010 import org.kde.plasma.components 2.0 as PlasmaComponents 0011 import org.kde.plasma.components 3.0 as PlasmaComponents3 0012 0013 import org.kde.latte.components 1.0 as LatteComponents 0014 0015 Rectangle { 0016 id: root 0017 color: "transparent" 0018 0019 implicitWidth: buttonMetrics.implicitWidth 0020 implicitHeight: buttonMetrics.implicitHeight 0021 0022 property ExclusiveGroup exclusiveGroup: null 0023 property bool checked: false 0024 property bool checkable: false 0025 0026 readonly property alias comboBox: mainComboBox 0027 readonly property alias button: mainButton 0028 0029 property bool buttonEnabled: true 0030 property bool buttonIsTransparent: false 0031 property bool buttonIsTriggeringMenu: false 0032 property string buttonText:"" 0033 property string buttonIconSource:"" 0034 property string buttonToolTip: "" 0035 0036 property bool comboBoxEnabled: true 0037 property bool comboBoxBlankSpaceForEmptyIcons: false 0038 property bool comboBoxForcePressed: false 0039 property bool comboBoxPopUpAlignRight: true 0040 property bool comboBoxButtonIsTransparent: false 0041 property bool comboBoxButtonIsVisible: true 0042 property int comboBoxMinimumPopUpWidth: 150 0043 property int comboBoxPopupTextHorizontalAlignment: Text.AlignLeft 0044 property string comboBoxEnabledRole: "" 0045 property string comboBoxTextRole: "" 0046 property string comboBoxIconRole: "" 0047 property string comboBoxIconToolTipRole: "" 0048 property string comboBoxIconOnlyWhenHoveredRole: "" 0049 property string comboBoxIsSeparatorRole: "" 0050 0051 readonly property bool isButtonIndicatingMenuPopup: buttonIsTriggeringMenu && !comboBoxButtonIsVisible && mainComboBox.popup.visible 0052 0053 signal iconClicked(int index); 0054 0055 onExclusiveGroupChanged: { 0056 if (exclusiveGroup) { 0057 exclusiveGroup.bindCheckable(root); 0058 } 0059 } 0060 0061 ExclusiveGroup { 0062 id: hiddenExclusiveGroup 0063 } 0064 0065 PlasmaComponents.Button { 0066 id: mainButton 0067 anchors.left: Qt.application.layoutDirection === Qt.RightToLeft ? undefined : parent.left 0068 anchors.right: Qt.application.layoutDirection === Qt.RightToLeft ? parent.right : undefined 0069 LayoutMirroring.enabled: false 0070 enabled: buttonEnabled 0071 checked: root.checked || (buttonIsTriggeringMenu && mainComboBox.popup.visible) 0072 opacity: buttonIsTransparent && !isButtonIndicatingMenuPopup ? 0 : 1 0073 0074 /*workaround in order to replicate the proper Buttons Exclusive Group Behavior*/ 0075 checkable: root.checkable && !parent.exclusiveGroup 0076 /*workaround in order to replicate the proper Buttons Exclusive Group Behavior*/ 0077 exclusiveGroup: parent.exclusiveGroup ? hiddenExclusiveGroup : null 0078 0079 width: parent.width 0080 height: mainComboBox.height 0081 0082 text: root.checkable ? " " : buttonText 0083 iconSource: buttonIconSource 0084 tooltip: buttonToolTip 0085 0086 onClicked: { 0087 if (buttonIsTriggeringMenu) { 0088 //! hiding combobox is triggered by default behavior 0089 mainComboBox.popup.visible = !mainComboBox.popup.visible; 0090 mainComboBox.down = mainComboBox.popup.visible; 0091 mainComboBox.pressed = mainComboBox.popup.visible; 0092 } 0093 } 0094 0095 //! WORKAROUND in order to miss one Clicked event from parent button, 0096 //! when combobox menu is shown and the user clicks the button in order to hide 0097 //! menu, this is enough in order to be dismissed. Without the workaround 0098 //! the menu is reshown because the Clicked event is triggered after 0099 //! the menu became hidden 0100 MouseArea { 0101 anchors.fill: parent 0102 visible: parent.enabled && buttonIsTriggeringMenu && mainComboBox.popup.visible 0103 } 0104 } 0105 0106 //overlayed combobox 0107 LatteComponents.ComboBox { 0108 id: mainComboBox 0109 anchors.right: mainButton.right 0110 anchors.top: parent.top 0111 0112 width: units.iconSizes.medium - 2 * units.smallSpacing 0113 height: parent.height 0114 0115 enabled: comboBoxEnabled 0116 visible: comboBoxButtonIsVisible 0117 0118 enabledRole: comboBoxEnabledRole 0119 iconRole: comboBoxIconRole 0120 textRole: comboBoxTextRole 0121 iconToolTipRole: comboBoxIconToolTipRole 0122 iconOnlyWhenHoveredRole: comboBoxIconOnlyWhenHoveredRole 0123 isSeparatorRole: comboBoxIsSeparatorRole 0124 buttonIsTransparent: comboBoxButtonIsTransparent 0125 0126 blankSpaceForEmptyIcons: comboBoxBlankSpaceForEmptyIcons 0127 forcePressed: comboBoxForcePressed 0128 popUpAlignRight: comboBoxPopUpAlignRight 0129 popUpRelativeX: Qt.application.layoutDirection === Qt.RightToLeft ? 0130 (popUpAlignRight ? root.width - width : 0) : 0131 (popUpAlignRight ? width : -(root.width - width)) 0132 popUpTextHorizontalAlignment: comboBoxPopupTextHorizontalAlignment 0133 0134 hideDisplayText: true 0135 hideSelectedItemIcon: true 0136 0137 minimumPopUpWidth: Math.max(comboBoxMinimumPopUpWidth, root.width) 0138 0139 onIconClicked: root.iconClicked(index); 0140 } 0141 0142 Label{ 0143 width: labelMetrics.exceeds ? parent.width-mainComboBox.width : parent.width 0144 height: parent.height 0145 text: buttonText 0146 font: mainButton.font 0147 color: buttonIsTransparent ? theme.textColor : theme.buttonTextColor 0148 visible: root.checkable || (mainButton.opacity === 0) 0149 0150 elide: Text.ElideRight 0151 horizontalAlignment: Text.AlignHCenter 0152 verticalAlignment: Text.AlignVCenter 0153 } 0154 0155 Label{ 0156 id: labelMetrics 0157 text: root.buttonText 0158 opacity: 0 0159 elide: Text.ElideNone 0160 horizontalAlignment: Text.AlignHCenter 0161 verticalAlignment: Text.AlignVCenter 0162 0163 readonly property bool exceeds: width>(mainButton.width-2*mainComboBox.width) 0164 } 0165 }