plasma-framework/src/declarativeimports/plasmastyle/ComboBoxStyle.qml
Nate Graham 5447cef2d8 Port to singleton Units
The context property version is slower to access and won't be supported
in Qt6. Let's port away from it and use the singleton version instead.

Here was my full process for making this change:

1. Made the change with `find . -name '*.qml' | xargs perl -pi -e 's/units\./PlasmaCore\.Units\./g'`
2. Verified no more occurrences with `grep -r " units."`
3. Made sure this didn't change any comments in a silly way by inspecting the output of `git diff | grep "+   " | grep "//"`
4. Manually inspected the full git diff to make sure there were no other unintentional or silly changes (there were none)
5. verified that all changed files have the PlasmaCore import with the correct name with `for FILE in `git status | grep modified | cut -d ":" -f 3`; do grep -q "as PlasmaCore" $FILE || echo "$FILE needs the PlasmaCore import"; done` (one needed the import)
2021-03-07 13:34:47 +00:00

125 lines
3.9 KiB
QML

/*
SPDX-FileCopyrightText: 2014 David Edmundson <davidedmundson@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.0
import QtQuick.Window 2.2
import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import "private" as Private
QtQuickControlStyle.ComboBoxStyle {
drowDownButtonWidth: PlasmaCore.Units.iconSizes.small
label: PlasmaComponents.Label {
text: control.currentText
elide: Text.ElideRight
color: theme.buttonTextColor
verticalAlignment: Text.AlignTop
horizontalAlignment: Text.AlignLeft
}
background: Item {
//size copied from Plasma Button
//for some reason the logic there is:
// maximum of
// the calculated height + frame margins
// Or 1.6 letters tall no matter how big the margins are
//QtQuickControls tries to be helpful and adds on the margin sizes for us
//to compensate, we have to subtract our margins here in order to do the max 1.6 lines high tall feature
implicitHeight: Math.max(theme.mSize(theme.defaultFont).height*1.6 - surfaceNormal.margins.top - surfaceNormal.margins.bottom,
theme.mSize(theme.defaultFont).height)
implicitWidth: theme.mSize(theme.defaultFont).width*12
Private.ButtonShadow {
anchors.fill: parent
state: {
if (control.pressed) {
return "hidden"
} else if (control.hovered) {
return "hover"
} else if (control.activeFocus) {
return "focus"
} else {
return "shadow"
}
}
}
//This code is duplicated here and Button and ToolButton
//maybe we can make an AbstractButton class?
PlasmaCore.FrameSvgItem {
id: surfaceNormal
anchors.fill: parent
imagePath: "widgets/button"
prefix: "normal"
}
PlasmaCore.FrameSvgItem {
id: surfacePressed
anchors.fill: parent
imagePath: "widgets/button"
prefix: "pressed"
opacity: 0
}
state: control.pressed ? "pressed" : "normal"
states: [
State { name: "normal" },
State { name: "pressed"
PropertyChanges {
target: surfaceNormal
opacity: 0
}
PropertyChanges {
target: surfacePressed
opacity: 1
}
}
]
transitions: [
Transition {
to: "normal"
//Cross fade from pressed to normal
ParallelAnimation {
NumberAnimation { target: surfaceNormal; property: "opacity"; to: 1; duration: PlasmaCore.Units.shortDuration }
NumberAnimation { target: surfacePressed; property: "opacity"; to: 0; duration: PlasmaCore.Units.shortDuration }
}
}
]
PlasmaCore.SvgItem {
width: drowDownButtonWidth
height: drowDownButtonWidth
anchors {
right: parent.right
rightMargin: surfaceNormal.margins.right
verticalCenter: parent.verticalCenter
}
svg: PlasmaCore.Svg {
imagePath: "widgets/arrows"
colorGroup: PlasmaCore.Theme.ButtonColorGroup
}
elementId: "down-arrow"
}
Component.onCompleted: {
padding.top = surfaceNormal.margins.top
padding.left = surfaceNormal.margins.left
padding.right = surfaceNormal.margins.right
padding.bottom = surfaceNormal.margins.bottom
}
}
}