Warning, /plasma/latte-dock/declarativeimports/components/ComboBoxButton.qml is written in an unsupported language. File is not indexed.

0001 /*
0002 *  Copyright 2019  Michail Vourlakos <mvourlakos@gmail.com>
0003 *
0004 *  This file is part of Latte-Dock
0005 *
0006 *  Latte-Dock is free software; you can redistribute it and/or
0007 *  modify it under the terms of the GNU General Public License as
0008 *  published by the Free Software Foundation; either version 2 of
0009 *  the License, or (at your option) any later version.
0010 *
0011 *  Latte-Dock is distributed in the hope that it will be useful,
0012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 *  GNU General Public License for more details.
0015 *
0016 *  You should have received a copy of the GNU General Public License
0017 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 
0020 import QtQuick 2.1
0021 import QtQuick.Layouts 1.3
0022 
0023 import org.kde.plasma.components 2.0 as PlasmaComponents
0024 import org.kde.plasma.components 3.0 as PlasmaComponents3
0025 
0026 import org.kde.latte 0.2 as Latte
0027 import org.kde.latte.components 1.0 as LatteComponents
0028 
0029 Rectangle {
0030     id: root
0031     color: "transparent"
0032 
0033     implicitWidth: buttonMetrics.implicitWidth
0034     implicitHeight: buttonMetrics.implicitHeight
0035 
0036     readonly property Item comboBox: mainComboBox
0037     readonly property Item button: mainButton
0038 
0039     property bool buttonEnabled: true
0040     property string buttonText:""
0041     property string buttonIconSource:""
0042     property string buttonToolTip: ""
0043     property QtObject buttonExclusiveGroup: null
0044 
0045     property bool checked: false
0046     property bool checkable: false
0047 
0048     property bool comboBoxEnabled: true
0049     property bool comboBoxBlankSpaceForEmptyIcons: false
0050     property bool comboBoxForcePressed: false
0051     property bool comboBoxPopUpAlignRight: true
0052     property int comboBoxMinimumPopUpWidth: 150
0053     property string comboBoxEnabledRole: ""
0054     property string comboBoxTextRole: ""
0055     property string comboBoxIconRole: ""
0056     property string comboBoxIconToolTipRole: ""
0057     property string comboBoxIconOnlyWhenHoveredRole: ""
0058 
0059     signal iconClicked(int index);
0060 
0061     PlasmaComponents.Button {
0062         id: mainButton
0063         anchors.left: Qt.application.layoutDirection === Qt.RightToLeft ? undefined : parent.left
0064         anchors.right: Qt.application.layoutDirection === Qt.RightToLeft ? parent.right : undefined
0065         LayoutMirroring.enabled: false
0066         enabled: buttonEnabled
0067         checked: root.checked
0068         checkable: root.checkable
0069         exclusiveGroup: buttonExclusiveGroup
0070 
0071         width: parent.width
0072         height: mainComboBox.height
0073 
0074         text: checkable ?  " " : buttonText
0075         iconSource: buttonIconSource
0076         tooltip: buttonToolTip
0077     }
0078 
0079     //overlayed combobox
0080     LatteComponents.ComboBox {
0081         id: mainComboBox
0082         anchors.right: mainButton.right
0083         anchors.top: parent.top
0084 
0085         width:  units.iconSizes.medium - units.smallSpacing
0086         height: parent.height
0087 
0088         enabled: comboBoxEnabled
0089 
0090         enabledRole: comboBoxEnabledRole
0091         iconRole: comboBoxIconRole
0092         textRole: comboBoxTextRole
0093         iconToolTipRole: comboBoxIconToolTipRole
0094         iconOnlyWhenHoveredRole: comboBoxIconOnlyWhenHoveredRole
0095 
0096         blankSpaceForEmptyIcons: comboBoxBlankSpaceForEmptyIcons
0097         forcePressed: comboBoxForcePressed
0098         popUpAlignRight: comboBoxPopUpAlignRight
0099         popUpRelativeX: Qt.application.layoutDirection === Qt.RightToLeft ?
0100                             (popUpAlignRight ? root.width - width : 0) :
0101                             (popUpAlignRight ? width : -(root.width - width))
0102 
0103         hideDisplayText: true
0104         hideSelectedItemIcon: true
0105 
0106         minimumPopUpWidth: Math.max(comboBoxMinimumPopUpWidth, root.width)
0107 
0108         onIconClicked: root.iconClicked(index);
0109     }
0110 
0111     Label{
0112         width: labelMetrics.exceeds ? parent.width-mainComboBox.width :  parent.width
0113         height: parent.height
0114         text: buttonText
0115         font: mainButton.font
0116         color: theme.buttonTextColor
0117         visible: root.checkable
0118 
0119         elide: Text.ElideRight
0120         horizontalAlignment: Text.AlignHCenter
0121         verticalAlignment: Text.AlignVCenter
0122     }
0123 
0124     Label{
0125         id: labelMetrics
0126         text: root.buttonText
0127         opacity: 0
0128         elide: Text.ElideNone
0129         horizontalAlignment: Text.AlignHCenter
0130         verticalAlignment: Text.AlignVCenter
0131 
0132         readonly property bool exceeds: width>(mainButton.width-2*mainComboBox.width)
0133     }
0134 }