2019-03-26 00:08:28 +03:00
/ *
* Copyright 2019 Michail Vourlakos < mvourlakos @ gmail . com >
*
* This file is part of Latte - Dock
*
* Latte - Dock is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation ; either version 2 of
* the License , or ( at your option ) any later version .
*
* Latte - Dock is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http: //www.gnu.org/licenses/>.
* /
import QtQuick 2.1
2019-03-26 22:47:17 +03:00
import QtQuick . Layouts 1.3
2019-03-26 00:08:28 +03:00
import org . kde . plasma . components 2.0 as PlasmaComponents
import org . kde . plasma . components 3.0 as PlasmaComponents3
import org . kde . latte 0.2 as Latte
import org . kde . latte . components 1.0 as LatteComponents
2019-03-26 22:47:17 +03:00
Rectangle {
2019-03-26 00:08:28 +03:00
id: root
2019-03-26 22:47:17 +03:00
color: "transparent"
implicitWidth: buttonMetrics . implicitWidth
implicitHeight: buttonMetrics . implicitHeight
2019-03-26 00:08:28 +03:00
readonly property Item comboBox: mainComboBox
readonly property Item button: mainButton
property bool buttonEnabled: true
property string buttonText: ""
property string buttonIconSource: ""
property string buttonToolTip: ""
2019-03-26 20:31:52 +03:00
property QtObject buttonExclusiveGroup: null
property bool checked: false
property bool checkable: false
2019-03-26 00:08:28 +03:00
property bool comboBoxEnabled: true
2019-03-26 20:51:30 +03:00
property bool comboBoxBlankSpaceForEmptyIcons: false
2019-03-26 21:46:57 +03:00
property bool comboBoxForcePressed: false
2019-03-28 20:32:02 +03:00
property bool comboBoxPopUpAlignRight: true
2019-03-26 21:15:22 +03:00
property int comboBoxMinimumPopUpWidth: 150
2019-03-27 21:14:20 +03:00
property string comboBoxEnabledRole: ""
2019-03-26 20:31:52 +03:00
property string comboBoxTextRole: ""
2019-03-26 20:51:30 +03:00
property string comboBoxIconRole: ""
2019-03-31 14:53:12 +03:00
property string comboBoxIconToolTipRole: ""
property string comboBoxIconOnlyWhenHoveredRole: ""
signal iconClicked ( int index ) ;
2019-03-26 00:08:28 +03:00
PlasmaComponents . Button {
id: mainButton
anchors.left: Qt . application . layoutDirection === Qt . RightToLeft ? undefined : parent . left
anchors.right: Qt . application . layoutDirection === Qt . RightToLeft ? parent.right : undefined
LayoutMirroring.enabled: false
enabled: buttonEnabled
2019-03-26 20:31:52 +03:00
checked: root . checked
checkable: root . checkable
exclusiveGroup: buttonExclusiveGroup
2019-03-26 00:08:28 +03:00
2019-03-26 22:47:17 +03:00
width: parent . width
2019-03-26 00:08:28 +03:00
height: mainComboBox . height
2019-03-26 22:47:17 +03:00
text: checkable ? " " : buttonText
2019-03-26 00:08:28 +03:00
iconSource: buttonIconSource
tooltip: buttonToolTip
}
2019-03-26 21:46:57 +03:00
2019-03-26 22:47:17 +03:00
//overlayed combobox
LatteComponents . ComboBox {
id: mainComboBox
anchors.right: mainButton . right
anchors.top: parent . top
width: units . iconSizes . medium - units . smallSpacing
height: parent . height
enabled: comboBoxEnabled
2019-03-27 21:14:20 +03:00
enabledRole: comboBoxEnabledRole
2019-03-26 22:47:17 +03:00
iconRole: comboBoxIconRole
textRole: comboBoxTextRole
2019-03-31 14:53:12 +03:00
iconToolTipRole: comboBoxIconToolTipRole
iconOnlyWhenHoveredRole: comboBoxIconOnlyWhenHoveredRole
2019-03-26 22:47:17 +03:00
blankSpaceForEmptyIcons: comboBoxBlankSpaceForEmptyIcons
forcePressed: comboBoxForcePressed
2019-03-28 20:32:02 +03:00
popUpAlignRight: comboBoxPopUpAlignRight
popUpRelativeX: Qt . application . layoutDirection === Qt . RightToLeft ?
( popUpAlignRight ? root . width - width : 0 ) :
( popUpAlignRight ? width : - ( root . width - width ) )
2019-03-26 22:47:17 +03:00
minimumPopUpWidth: Math . max ( comboBoxMinimumPopUpWidth , root . width )
2019-03-31 14:53:12 +03:00
onIconClicked: root . iconClicked ( index ) ;
2019-03-26 22:47:17 +03:00
}
2019-03-26 21:46:57 +03:00
Label {
2019-03-26 22:47:17 +03:00
width: labelMetrics . exceeds ? parent . width - mainComboBox.width : parent . width
height: parent . height
2019-03-26 21:46:57 +03:00
text: buttonText
font: mainButton . font
color: theme . buttonTextColor
2019-03-26 22:47:17 +03:00
visible: root . checkable
2019-03-26 21:46:57 +03:00
elide: Text . ElideRight
horizontalAlignment: Text . AlignHCenter
verticalAlignment: Text . AlignVCenter
}
Label {
id: labelMetrics
text: root . buttonText
opacity: 0
elide: Text . ElideNone
horizontalAlignment: Text . AlignHCenter
verticalAlignment: Text . AlignVCenter
2019-03-26 22:47:17 +03:00
readonly property bool exceeds: width > ( mainButton . width - mainComboBox . width )
2019-03-26 21:46:57 +03:00
}
2019-03-26 00:08:28 +03:00
}