improvements for ComboBoxButton

--centered aligned button text properly and
at the same time elide the text when needed in
order to not overlap with the combobox down
arrow
pull/5/head
Michail Vourlakos 6 years ago
parent 02c388d2bf
commit 9e9a8428b5

@ -43,6 +43,7 @@ T.ComboBox {
wheelEnabled: false wheelEnabled: false
property bool blankSpaceForEmptyIcons: false property bool blankSpaceForEmptyIcons: false
property bool forcePressed: false
property int minimumPopUpWidth: 150 property int minimumPopUpWidth: 150
property string iconRole property string iconRole
@ -206,7 +207,7 @@ T.ComboBox {
imagePath: editable ? "widgets/lineedit" : "widgets/button" imagePath: editable ? "widgets/lineedit" : "widgets/button"
prefix: editable prefix: editable
? "base" ? "base"
: (control.pressed ? "pressed" : "normal") : (control.pressed || control.forcePressed ? "pressed" : "normal")
Private.TextFieldFocus { Private.TextFieldFocus {
visible: parent.editable visible: parent.editable
z: -1 z: -1

@ -43,6 +43,7 @@ PlasmaComponents.Button {
property bool comboBoxEnabled: true property bool comboBoxEnabled: true
property bool comboBoxBlankSpaceForEmptyIcons: false property bool comboBoxBlankSpaceForEmptyIcons: false
property bool comboBoxForcePressed: false
property int comboBoxMinimumPopUpWidth: 150 property int comboBoxMinimumPopUpWidth: 150
property string comboBoxTextRole: "" property string comboBoxTextRole: ""
property string comboBoxIconRole: "" property string comboBoxIconRole: ""
@ -56,6 +57,7 @@ PlasmaComponents.Button {
textRole: comboBoxTextRole textRole: comboBoxTextRole
blankSpaceForEmptyIcons: comboBoxBlankSpaceForEmptyIcons blankSpaceForEmptyIcons: comboBoxBlankSpaceForEmptyIcons
forcePressed: comboBoxForcePressed
minimumPopUpWidth: comboBoxMinimumPopUpWidth minimumPopUpWidth: comboBoxMinimumPopUpWidth
} }
@ -74,8 +76,31 @@ PlasmaComponents.Button {
width: parent.width - units.iconSizes.medium + 2*units.smallSpacing width: parent.width - units.iconSizes.medium + 2*units.smallSpacing
height: mainComboBox.height height: mainComboBox.height
text: buttonText text: checkable && !labelMetrics.exceeds? "" : buttonText
iconSource: buttonIconSource iconSource: buttonIconSource
tooltip: buttonToolTip tooltip: buttonToolTip
} }
Label{
anchors.fill: parent
visible: mainButton.checkable && !labelMetrics.exceeds
text: buttonText
font: mainButton.font
color: theme.buttonTextColor
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
readonly property bool exceeds: width>mainButton.width
}
} }

@ -31,6 +31,7 @@ LatteComponents.ComboBoxButton{
comboBoxTextRole: "name" comboBoxTextRole: "name"
comboBoxIconRole: "icon" comboBoxIconRole: "icon"
comboBoxBlankSpaceForEmptyIcons: true comboBoxBlankSpaceForEmptyIcons: true
comboBoxForcePressed: latteView.indicator.type === type
property string type: "org.kde.latte.unity" property string type: "org.kde.latte.unity"

Loading…
Cancel
Save