mirror of
https://github.com/monero-project/monero-gui.git
synced 2025-02-24 02:30:33 +02:00
Merge pull request #1791
e0796b2
standard-button: fix layout (xiphon)f8a920d
standard-button: add hover color animation (xiphon)831dc59
standard-button: remove redundant 'icon' property (xiphon)
This commit is contained in:
commit
bd451e1402
@ -35,7 +35,6 @@ Item {
|
|||||||
id: button
|
id: button
|
||||||
property string rightIcon: ""
|
property string rightIcon: ""
|
||||||
property string rightIconInactive: ""
|
property string rightIconInactive: ""
|
||||||
property string icon: ""
|
|
||||||
property string textColor: button.enabled? MoneroComponents.Style.buttonTextColor: MoneroComponents.Style.buttonTextColorDisabled
|
property string textColor: button.enabled? MoneroComponents.Style.buttonTextColor: MoneroComponents.Style.buttonTextColorDisabled
|
||||||
property string textAlign: rightIcon !== "" ? "left" : "center"
|
property string textAlign: rightIcon !== "" ? "left" : "center"
|
||||||
property bool small: false
|
property bool small: false
|
||||||
@ -46,22 +45,9 @@ Item {
|
|||||||
}
|
}
|
||||||
signal clicked()
|
signal clicked()
|
||||||
|
|
||||||
// Dynamic height/width
|
|
||||||
Layout.minimumWidth: {
|
|
||||||
var _padding = 22;
|
|
||||||
if(button.rightIcon !== ""){
|
|
||||||
_padding += 60;
|
|
||||||
}
|
|
||||||
|
|
||||||
var _width = label.contentWidth + _padding;
|
|
||||||
if(_width <= 50) {
|
|
||||||
return 60;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _width;
|
|
||||||
}
|
|
||||||
|
|
||||||
height: small ? 30 * scaleRatio : 36 * scaleRatio
|
height: small ? 30 * scaleRatio : 36 * scaleRatio
|
||||||
|
width: buttonLayout.width + 22 * scaleRatio
|
||||||
|
Component.onCompleted: width = width
|
||||||
|
|
||||||
function doClick() {
|
function doClick() {
|
||||||
// Android workaround
|
// Android workaround
|
||||||
@ -70,70 +56,79 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors.left: parent.left
|
id: buttonRect
|
||||||
anchors.right: parent.right
|
anchors.fill: parent
|
||||||
height: parent.height - 1
|
|
||||||
radius: 3
|
radius: 3
|
||||||
color: parent.enabled ? MoneroComponents.Style.buttonBackgroundColor : MoneroComponents.Style.buttonBackgroundColorDisabled
|
|
||||||
border.width: parent.focus ? 1 : 0
|
border.width: parent.focus ? 1 : 0
|
||||||
|
|
||||||
MouseArea {
|
state: button.enabled ? "active" : "disabled"
|
||||||
anchors.fill: parent
|
Component.onCompleted: state = state
|
||||||
cursorShape: Qt.PointingHandCursor
|
states: [
|
||||||
hoverEnabled: true
|
State {
|
||||||
|
name: "hover"
|
||||||
propagateComposedEvents: true
|
when: buttonArea.containsMouse || button.focus
|
||||||
|
PropertyChanges {
|
||||||
// possibly do some hover effects here
|
target: buttonRect
|
||||||
onEntered: {
|
color: MoneroComponents.Style.buttonBackgroundColorHover
|
||||||
// if(button.enabled) parent.color = Style.buttonBackgroundColorHover;
|
}
|
||||||
// else parent.color = Style.buttonBackgroundColorDisabledHover;
|
},
|
||||||
}
|
State {
|
||||||
onExited: {
|
name: "active"
|
||||||
// if(button.enabled) parent.color = Style.buttonBackgroundColor;
|
when: button.enabled
|
||||||
// else parent.color = Style.buttonBackgroundColorDisabled;
|
PropertyChanges {
|
||||||
|
target: buttonRect
|
||||||
|
color: MoneroComponents.Style.buttonBackgroundColor
|
||||||
|
}
|
||||||
|
},
|
||||||
|
State {
|
||||||
|
name: "disabled"
|
||||||
|
when: !button.enabled
|
||||||
|
PropertyChanges {
|
||||||
|
target: buttonRect
|
||||||
|
color: MoneroComponents.Style.buttonBackgroundColorDisabled
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
]
|
||||||
|
transitions: Transition {
|
||||||
|
ColorAnimation { duration: 100 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
RowLayout {
|
||||||
id: label
|
id: buttonLayout
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
height: button.height
|
||||||
anchors.left: parent.left
|
spacing: 11 * scaleRatio
|
||||||
anchors.right: parent.right
|
|
||||||
horizontalAlignment: textAlign === "center" ? Text.AlignHCenter : Text.AlignLeft
|
|
||||||
anchors.leftMargin: textAlign === "center" ? 0 : 11
|
|
||||||
font.family: MoneroComponents.Style.fontBold.name
|
|
||||||
font.bold: true
|
|
||||||
font.pixelSize: buttonArea.pressed ? button.fontSize - 1 : button.fontSize
|
|
||||||
color: parent.textColor
|
|
||||||
visible: parent.icon === ""
|
|
||||||
}
|
|
||||||
|
|
||||||
Image {
|
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
visible: parent.icon !== ""
|
|
||||||
source: parent.icon
|
|
||||||
}
|
|
||||||
|
|
||||||
Image {
|
Text {
|
||||||
visible: parent.rightIcon !== ""
|
id: label
|
||||||
anchors.right: parent.right
|
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
|
||||||
anchors.rightMargin: 11 * scaleRatio
|
horizontalAlignment: textAlign === "center" ? Text.AlignHCenter : Text.AlignLeft
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
font.family: MoneroComponents.Style.fontBold.name
|
||||||
width: parent.small ? 16 * scaleRatio : 20 * scaleRatio
|
font.bold: true
|
||||||
height: parent.small ? 16 * scaleRatio : 20 * scaleRatio
|
font.pixelSize: buttonArea.pressed ? button.fontSize - 1 : button.fontSize
|
||||||
source: {
|
color: button.textColor
|
||||||
if(parent.rightIconInactive !== "" && !parent.enabled){
|
visible: text !== ""
|
||||||
return parent.rightIconInactive;
|
}
|
||||||
|
|
||||||
|
Image {
|
||||||
|
visible: button.rightIcon !== ""
|
||||||
|
Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
|
||||||
|
width: button.small ? 16 * scaleRatio : 20 * scaleRatio
|
||||||
|
height: button.small ? 16 * scaleRatio : 20 * scaleRatio
|
||||||
|
source: {
|
||||||
|
if(button.rightIconInactive !== "" && !button.enabled) {
|
||||||
|
return button.rightIconInactive;
|
||||||
|
}
|
||||||
|
return button.rightIcon;
|
||||||
}
|
}
|
||||||
return parent.rightIcon;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: buttonArea
|
id: buttonArea
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
hoverEnabled: true
|
||||||
onClicked: doClick()
|
onClicked: doClick()
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user