Split HButton components, add HMenu/HMenuItem

This commit is contained in:
miruka 2019-08-21 15:45:13 -04:00
parent 6067c8ec96
commit ed96409645
13 changed files with 129 additions and 65 deletions

View File

@ -9,65 +9,29 @@ Button {
rightPadding: spacing / 1.5 rightPadding: spacing / 1.5
topPadding: spacing / 2 topPadding: spacing / 2
bottomPadding: spacing / 2 bottomPadding: spacing / 2
opacity: enabled ? 1 : theme.disabledElementsOpacity iconItem.svgName: loading ? "hourglass" : icon.name
onVisibleChanged: if (! visible) loading = false onVisibleChanged: if (! visible) loading = false
readonly property alias ico: ico readonly property alias iconItem: contentItem.icon
readonly property alias label: label readonly property alias label: contentItem.label
property string iconName: ""
property color backgroundColor: theme.controls.button.background property color backgroundColor: theme.controls.button.background
property bool loading: false property bool loading: false
property bool circle: false property bool circle: false
Behavior on opacity { HNumberAnimation {} } background: HButtonBackground {
button: button
buttonTheme: theme.controls.button
background: HRectangle {
radius: circle ? height : 0 radius: circle ? height : 0
color: backgroundColor color: backgroundColor
HRectangle {
anchors.fill: parent
radius: parent.radius
color: button.checked ?
theme.controls.button.checkedOverlay :
button.enabled && button.pressed ?
theme.controls.button.pressedOverlay :
(button.enabled && button.hovered) || button.visualFocus ?
theme.controls.button.hoveredOverlay :
"transparent"
Behavior on color { HColorAnimation { factor: 0.5 } }
}
} }
contentItem: HRowLayout { contentItem: HButtonContent {
spacing: button.spacing id: contentItem
button: button
HIcon { buttonTheme: theme.controls.button
id: ico
svgName: loading ? "hourglass" : iconName
Layout.fillHeight: true
Layout.alignment: Qt.AlignCenter
}
HLabel {
id: label
text: button.text
visible: Boolean(text)
color: theme.controls.button.text
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
Layout.fillWidth: true
Layout.fillHeight: true
}
} }
} }

View File

@ -0,0 +1,29 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
HRectangle {
opacity: enabled ? 1 : theme.disabledElementsOpacity
property AbstractButton button
property QtObject buttonTheme
Behavior on opacity { HNumberAnimation {} }
HRectangle {
anchors.fill: parent
radius: parent.radius
color: button.checked ? buttonTheme.checkedOverlay :
button.enabled && button.pressed ? buttonTheme.pressedOverlay :
(button.enabled && button.hovered) || button.visualFocus ?
buttonTheme.hoveredOverlay :
"transparent"
Behavior on color { HColorAnimation { factor: 0.5 } }
}
}

View File

@ -0,0 +1,41 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
HRowLayout {
spacing: button.spacing
opacity: enabled ? 1 : theme.disabledElementsOpacity
property AbstractButton button
property QtObject buttonTheme
readonly property alias icon: icon
readonly property alias label: label
Behavior on opacity { HNumberAnimation {} }
HIcon {
id: icon
svgName: button.icon.name
colorize: button.icon.color
cache: button.icon.cache
Layout.fillHeight: true
Layout.alignment: Qt.AlignCenter
}
HLabel {
id: label
text: button.text
visible: Boolean(text)
color: buttonTheme.text
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
Layout.fillWidth: true
Layout.fillHeight: true
}
}

View File

@ -73,7 +73,7 @@ HRectangle {
id: button id: button
text: modelData.text text: modelData.text
iconName: modelData.iconName || "" icon.name: modelData.iconName || ""
enabled: modelData.enabled enabled: modelData.enabled
onClicked: buttonCallbacks[modelData.name](button) onClicked: buttonCallbacks[modelData.name](button)

View File

@ -2,4 +2,26 @@ import QtQuick 2.12
import QtQuick.Controls 2.12 import QtQuick.Controls 2.12
MenuItem { MenuItem {
id: menuItem
spacing: theme.spacing
leftPadding: spacing / 1.5
rightPadding: spacing / 1.5
topPadding: spacing / 2
bottomPadding: spacing / 2
readonly property alias iconItem: contentItem.icon
readonly property alias label: contentItem.label
background: HButtonBackground {
button: menuItem
buttonTheme: theme.controls.menuItem
}
contentItem: HButtonContent {
id: contentItem
button: menuItem
buttonTheme: theme.controls.menuItem
}
} }

View File

@ -71,7 +71,7 @@ HRectangle {
HButton { HButton {
id: button id: button
text: modelData.text text: modelData.text
iconName: modelData.iconName icon.name: modelData.iconName
onClicked: buttonCallbacks[modelData.name](button) onClicked: buttonCallbacks[modelData.name](button)
Layout.preferredHeight: theme.baseElementsHeight Layout.preferredHeight: theme.baseElementsHeight

View File

@ -75,8 +75,8 @@ HRectangle {
] ]
HButton { HButton {
backgroundColor: "transparent" backgroundColor: "transparent"
iconName: "room-view-" + modelData icon.name: "room-view-" + modelData
ico.dimension: 22 iconItem.dimension: 22
height: parent.height height: parent.height
autoExclusive: true autoExclusive: true
checked: activeButton == modelData checked: activeButton == modelData
@ -101,7 +101,7 @@ HRectangle {
visible: opacity > 0 visible: opacity > 0
backgroundColor: "transparent" backgroundColor: "transparent"
iconName: "reduced-room-buttons" icon.name: "reduced-room-buttons"
Behavior on opacity { Behavior on opacity {
HNumberAnimation { duration: buttonsAnimation.duration * 2 } HNumberAnimation { duration: buttonsAnimation.duration * 2 }

View File

@ -33,7 +33,7 @@ HColumnLayout {
HRowLayout { HRowLayout {
HButton { HButton {
id: exportButton id: exportButton
iconName: "export-keys" icon.name: "export-keys"
text: qsTr("Export") text: qsTr("Export")
enabled: false enabled: false
@ -43,7 +43,7 @@ HColumnLayout {
HButton { HButton {
id: importButton id: importButton
iconName: "import-keys" icon.name: "import-keys"
text: qsTr("Import") text: qsTr("Import")
Layout.fillWidth: true Layout.fillWidth: true

View File

@ -178,7 +178,7 @@ HGridLayout {
property bool avatarChangeRunning: false property bool avatarChangeRunning: false
id: saveButton id: saveButton
iconName: "apply" icon.name: "apply"
text: qsTr("Apply") text: qsTr("Apply")
loading: nameChangeRunning || avatarChangeRunning loading: nameChangeRunning || avatarChangeRunning
enabled: enabled:
@ -190,7 +190,7 @@ HGridLayout {
} }
HButton { HButton {
iconName: "cancel" icon.name: "cancel"
text: qsTr("Cancel") text: qsTr("Cancel")
enabled: saveButton.enabled && ! saveButton.loading enabled: saveButton.enabled && ! saveButton.loading
onClicked: cancelChanges() onClicked: cancelChanges()

View File

@ -63,8 +63,8 @@ HPage {
model: ["username", "email", "phone"] model: ["username", "email", "phone"]
HButton { HButton {
iconName: modelData icon.name: modelData
ico.dimension: 24 iconItem.dimension: 24
circle: true circle: true
checked: loginWith == modelData checked: loginWith == modelData
enabled: modelData == "username" enabled: modelData == "username"

View File

@ -51,7 +51,7 @@ HTileDelegate {
HButton { HButton {
id: expand id: expand
iconName: "expand" icon.name: "expand"
backgroundColor: "transparent" backgroundColor: "transparent"
padding: sidePane.currentSpacing / 1.5 padding: sidePane.currentSpacing / 1.5
rightPadding: leftPadding rightPadding: leftPadding
@ -60,9 +60,9 @@ HTileDelegate {
visible: opacity > 0 visible: opacity > 0
opacity: accountDelegate.forceExpand ? 0 : 1 opacity: accountDelegate.forceExpand ? 0 : 1
ico.transform: Rotation { iconItem.transform: Rotation {
origin.x: expand.ico.dimension / 2 origin.x: expand.iconItem.dimension / 2
origin.y: expand.ico.dimension / 2 origin.y: expand.iconItem.dimension / 2
angle: collapsed ? 180 : 90 angle: collapsed ? 180 : 90
Behavior on angle { HNumberAnimation {} } Behavior on angle { HNumberAnimation {} }

View File

@ -12,7 +12,7 @@ HRowLayout {
Layout.preferredHeight: theme.baseElementsHeight Layout.preferredHeight: theme.baseElementsHeight
HButton { HButton {
iconName: "add-account" icon.name: "add-account"
backgroundColor: theme.sidePane.settingsButton.background backgroundColor: theme.sidePane.settingsButton.background
onClicked: pageLoader.showPage("SignIn") onClicked: pageLoader.showPage("SignIn")

View File

@ -96,15 +96,23 @@ controls:
color pressedOverlay: hsluv(0, 0, 50, 0.6) color pressedOverlay: hsluv(0, 0, 50, 0.6)
color checkedOverlay: colors.accentBackground color checkedOverlay: colors.accentBackground
menuItem:
color background: controls.button.background
color text: controls.button.text
color hoveredOverlay: controls.button.hoveredOverlay
color pressedOverlay: controls.button.hoveredOverlay
color checkedOverlay: controls.button.hoveredOverlay
checkBox: checkBox:
color checkIconColor: colors.strongAccentBackground color checkIconColor: colors.strongAccentBackground
color boxBackground: colors.inputBackground color boxBackground: controls.button.background
color boxBorder: hsluv(0, 0, 50, 0.3) color boxBorder: hsluv(0, 0, 50, 0.3)
color boxHoveredBorder: colors.accentBackground color boxHoveredBorder: colors.accentBackground
color boxPressedBorder: colors.strongAccentBackground color boxPressedBorder: colors.strongAccentBackground
color text: colors.text color text: controls.button.text
listView: listView:
color highlight: hsluv(0, 0, 50, 0.3) color highlight: hsluv(0, 0, 50, 0.3)