Refactor HButton

This commit is contained in:
miruka 2019-08-20 17:41:24 -04:00
parent 7e7852b51e
commit ce128d5ab5
14 changed files with 101 additions and 187 deletions

View File

@ -6,8 +6,8 @@
- Make the icon blue in EditAccount when hovering and no avatar set - Make the icon blue in EditAccount when hovering and no avatar set
- HButton - HButton
- Control: hovered, visualFocus, enabled - visualFocus
- Border and pressed color in theme / checkbox theming - Checkbox theming
- `^property type name$` - `^property type name$`
- Use [Animators](https://doc.qt.io/qt-5/qml-qtquick-animator.html) - Use [Animators](https://doc.qt.io/qt-5/qml-qtquick-animator.html)

View File

@ -1,71 +0,0 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
Button {
property bool circle: false
property color backgroundColor: theme.controls.button.background
property alias overlayOpacity: buttonBackgroundOverlay.opacity
property bool checkedLightens: false
signal canceled
signal clicked
signal doubleClicked
signal entered
signal exited
signal pressAndHold
signal pressed
signal released
id: button
background: Rectangle {
id: buttonBackground
color:
enabled ?
(checked ?
theme.controls.button.checkedBackground : backgroundColor) :
theme.controls.button.disabledBackground
radius: circle ? height : 0
Behavior on color { HColorAnimation { factor: 0.5 } }
Rectangle {
id: buttonBackgroundOverlay
anchors.fill: parent
radius: parent.radius
color: theme.controls.button.hoveredOverlay
opacity: 0
Behavior on opacity { HNumberAnimation { factor: 0.5 } }
}
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onCanceled: button.canceled()
onClicked: button.clicked()
onDoubleClicked: button.doubleClicked()
onEntered: {
overlayOpacity = checked ? 0 : 0.15
button.entered()
}
onExited: {
overlayOpacity = 0
button.exited()
}
onPressAndHold: button.pressAndHold()
onPressed: {
overlayOpacity += 0.15
button.pressed()
}
onReleased: {
if (checkable) { checked = ! checked }
overlayOpacity = checked ? 0 : 0.15
button.released()
}
}
}

63
src/qml/Base/HButton.qml Normal file
View File

@ -0,0 +1,63 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
Button {
id: button
opacity: enabled ? 1 : theme.controls.button.disabledOpacity
onVisibleChanged: if (! visible) loading = false
readonly property alias ico: ico
readonly property alias label: label
property string iconName: ""
property color backgroundColor: theme.controls.button.background
property bool loading: false
property bool circle: false
background: HRectangle {
radius: circle ? height : 0
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 ?
theme.controls.button.hoveredOverlay :
"transparent"
Behavior on color { HColorAnimation { factor: 0.5 } }
}
}
contentItem: HRowLayout {
spacing: button.spacing
HIcon {
id: ico
x: button.leftPadding
y: button.topPadding + button.availableHeight / 2 - height / 2
svgName: loading ? "hourglass" : iconName
}
HLabel {
id: label
text: button.text
visible: Boolean(text)
color: theme.controls.button.text
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
Layout.fillWidth: true
}
}
}

View File

@ -1,6 +1,8 @@
import QtQuick 2.12 import QtQuick 2.12
HImage { HImage {
visible: Boolean(svgName)
property string svgName: "" property string svgName: ""
property int dimension: 20 property int dimension: 20

View File

@ -68,13 +68,13 @@ HRectangle {
id: interfaceButtonsRepeater id: interfaceButtonsRepeater
model: [] model: []
HUIButton { HButton {
property string name: modelData.name property string name: modelData.name
id: button id: button
text: modelData.text text: modelData.text
iconName: modelData.iconName || "" iconName: modelData.iconName || ""
enabled: modelData.enabled === false ? false : true enabled: modelData.enabled
onClicked: buttonCallbacks[modelData.name](button) onClicked: buttonCallbacks[modelData.name](button)
Layout.fillWidth: true Layout.fillWidth: true

View File

@ -1,74 +0,0 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtGraphicalEffects 1.12
HBaseButton {
property int contentWidth: 0
property int horizontalMargin: 0
property int verticalMargin: 0
property int fontSize: theme.fontSize.normal
property string iconName: ""
property var iconDimension: null
property var iconTransform: null
property bool loading: false
readonly property alias visibility: button.visible
onVisibilityChanged: if (! visibility) { loading = false }
id: button
Component {
id: buttonContent
HRowLayout {
id: contentLayout
spacing: button.text && iconName ? theme.spacing : 0
Component.onCompleted: contentWidth = implicitWidth
HIcon {
svgName: loading ? "hourglass" : iconName
dimension: iconDimension || contentLayout.height
transform: iconTransform
opacity: button.enabled ? 1 : 0.7
Behavior on opacity { HNumberAnimation {} }
Layout.topMargin: verticalMargin
Layout.bottomMargin: verticalMargin
Layout.leftMargin: horizontalMargin
Layout.rightMargin: horizontalMargin
}
HLabel {
visible: Boolean(text)
text: button.text
font.pixelSize: fontSize
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
color: button.enabled ?
theme.controls.button.text :
theme.controls.button.disabledText
Layout.fillWidth: true
}
}
}
Component {
id: loadingOverlay
HRowLayout {
HIcon {
svgName: "hourglass"
Layout.preferredWidth: contentWidth || -1
Layout.alignment: Qt.AlignCenter
}
}
}
contentItem: HLoader {
sourceComponent:
loading && ! iconName ? loadingOverlay : buttonContent
}
}

View File

@ -68,7 +68,7 @@ HRectangle {
id: bannerRepeater id: bannerRepeater
model: [] model: []
HUIButton { HButton {
id: button id: button
text: modelData.text text: modelData.text
iconName: modelData.iconName iconName: modelData.iconName

View File

@ -73,14 +73,15 @@ HRectangle {
model: [ model: [
"members", "files", "notifications", "history", "settings" "members", "files", "notifications", "history", "settings"
] ]
HUIButton { HButton {
backgroundColor: theme.chat.selectViewBar.background backgroundColor: "transparent"
iconName: "room-view-" + modelData iconName: "room-view-" + modelData
iconDimension: 22 ico.dimension: 22
height: parent.height
autoExclusive: true autoExclusive: true
checked: activeButton == modelData checked: activeButton == modelData
onClicked: activeButton = activeButton == modelData ? onClicked: activeButton =
null : modelData activeButton == modelData ? null : modelData
} }
} }
@ -90,16 +91,16 @@ HRectangle {
} }
} }
HUIButton { HButton {
id: expandButton id: expandButton
z: 1 z: 1
width: theme.controls.avatar.size width: height
height: width height: parent.height
anchors.right: parent.right anchors.right: parent.right
opacity: collapseButtons ? 1 : 0 opacity: collapseButtons ? 1 : 0
visible: opacity > 0 visible: opacity > 0
backgroundColor: theme.chat.selectViewBar.background backgroundColor: "transparent"
iconName: "reduced-room-buttons" iconName: "reduced-room-buttons"
Behavior on opacity { Behavior on opacity {

View File

@ -31,7 +31,7 @@ HColumnLayout {
} }
HRowLayout { HRowLayout {
HUIButton { HButton {
id: exportButton id: exportButton
iconName: "export-keys" iconName: "export-keys"
text: qsTr("Export") text: qsTr("Export")
@ -41,7 +41,7 @@ HColumnLayout {
Layout.alignment: Qt.AlignBottom Layout.alignment: Qt.AlignBottom
} }
HUIButton { HButton {
id: importButton id: importButton
iconName: "import-keys" iconName: "import-keys"
text: qsTr("Import") text: qsTr("Import")

View File

@ -173,7 +173,7 @@ HGridLayout {
HRowLayout { HRowLayout {
Layout.alignment: Qt.AlignBottom Layout.alignment: Qt.AlignBottom
HUIButton { HButton {
property bool nameChangeRunning: false property bool nameChangeRunning: false
property bool avatarChangeRunning: false property bool avatarChangeRunning: false
@ -183,22 +183,20 @@ HGridLayout {
loading: nameChangeRunning || avatarChangeRunning loading: nameChangeRunning || avatarChangeRunning
enabled: enabled:
nameField.changed || aliasField.changed || avatar.changed nameField.changed || aliasField.changed || avatar.changed
onClicked: applyChanges()
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignBottom Layout.alignment: Qt.AlignBottom
onClicked: applyChanges()
} }
HUIButton { HButton {
iconName: "cancel" iconName: "cancel"
text: qsTr("Cancel") text: qsTr("Cancel")
enabled: saveButton.enabled && ! saveButton.loading enabled: saveButton.enabled && ! saveButton.loading
onClicked: cancelChanges()
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignBottom Layout.alignment: Qt.AlignBottom
onClicked: cancelChanges()
} }
} }
} }

View File

@ -62,13 +62,12 @@ HPage {
Repeater { Repeater {
model: ["username", "email", "phone"] model: ["username", "email", "phone"]
HUIButton { HButton {
iconName: modelData iconName: modelData
circle: true circle: true
checked: loginWith == modelData checked: loginWith == modelData
enabled: modelData == "username" enabled: modelData == "username"
autoExclusive: true autoExclusive: true
checkedLightens: true
onClicked: loginWith = modelData onClicked: loginWith = modelData
} }
} }

View File

@ -102,10 +102,10 @@ HInteractiveRectangle {
Layout.fillHeight: true Layout.fillHeight: true
} }
HUIButton { HButton {
id: expandButton id: expandButton
iconName: "expand" iconName: "expand"
iconDimension: 16 ico.dimension: 16
backgroundColor: "transparent" backgroundColor: "transparent"
leftPadding: sidePane.currentSpacing leftPadding: sidePane.currentSpacing
rightPadding: leftPadding rightPadding: leftPadding
@ -118,9 +118,9 @@ HInteractiveRectangle {
1 1
Behavior on opacity { HNumberAnimation {} } Behavior on opacity { HNumberAnimation {} }
iconTransform: Rotation { ico.transform: Rotation {
origin.x: expandButton.iconDimension / 2 origin.x: expandButton.ico.dimension / 2
origin.y: expandButton.iconDimension / 2 origin.y: expandButton.ico.dimension / 2
angle: collapsed ? 180 : 90 angle: collapsed ? 180 : 90
Behavior on angle { HNumberAnimation {} } Behavior on angle { HNumberAnimation {} }

View File

@ -11,12 +11,12 @@ HRowLayout {
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: theme.baseElementsHeight Layout.preferredHeight: theme.baseElementsHeight
HUIButton { HButton {
iconName: "add-account" iconName: "add-account"
backgroundColor: theme.sidePane.settingsButton.background backgroundColor: theme.sidePane.settingsButton.background
Layout.preferredHeight: parent.height
onClicked: pageLoader.showPage("SignIn") onClicked: pageLoader.showPage("SignIn")
Layout.preferredHeight: parent.height
} }
HTextField { HTextField {

View File

@ -88,14 +88,13 @@ controls:
color background: colors.strongBackground color background: colors.strongBackground
button: button:
color background: colors.inputBackground color background: colors.inputBackground
color checkedBackground: colors.accentBackground
color disabledBackground:
hsluv(0, 0, colors.intensity * 2, Math.min(0.6, opacity))
color hoveredOverlay: hsluv(0, 0, 100)
color text: colors.text color text: colors.text
color disabledText: colors.dimmerText real disabledOpacity: 0.3
color hoveredOverlay: hsluv(0, 0, 50, 0.3)
color pressedOverlay: hsluv(0, 0, 50, 0.6)
color checkedOverlay: colors.accentBackground
interactiveRectangle: interactiveRectangle:
color background: "transparent" color background: "transparent"
@ -191,9 +190,6 @@ chat:
roomSidePane: roomSidePane:
color background: colors.mediumBackground color background: colors.mediumBackground
selectViewBar:
color background: chat.roomHeader.background
eventList: eventList:
int ownEventsOnRightUnderWidth: 768 int ownEventsOnRightUnderWidth: 768
color background: "transparent" color background: "transparent"