-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathButton.qml
98 lines (78 loc) · 2.94 KB
/
Button.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* QML Air - A lightweight and mostly flat UI widget collection for QML
* Copyright (C) 2014 Michael Spencer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import QtGraphicalEffects 1.0
Widget {
id: button
//----- STYLE PROPERTIES -----//
property color iconColor: textColor
property color textColor: style === "default" ? theme.textColor : "white"
property color background: style === "default" ? "white" : theme.getStyleColor(style)
property color background_mouseOver: hidden ? "white" : style == "default" ? Qt.darker(background, 1.1) : Qt.darker(background, 1.15)
property color background_selected: style == "default" ? Qt.darker(background, 1.2) : Qt.darker(background, 1.25)
property color borderColor: Qt.darker(background, 1.4)
radius: units.gu(0.5)
property int horizPadding: units.gu(2)
property int minWidth: units.gu(10)
height: units.gu(4)
property var fontSize: "medium"
//----- STATE PROPERTIES -----//
property bool primary
property bool selected
property bool hidden
style: primary ? "primary" : "default"
width: text === "" ? height : Math.max(minWidth, row.width + 2 * horizPadding)
property alias text: label.text
property alias iconName: icon.name
border.color: mouseOver || !hidden ? borderColor : "transparent"
color: selected ? background_selected : mouseOver ? background_mouseOver : hidden ? Qt.rgba(1,1,1,0) : background
Behavior on border.color {
ColorAnimation { duration: 200 }
}
Behavior on color {
ColorAnimation { duration: 200 }
}
border.width: units.gu(0.1)
opacity: enabled ? 1 : 0.5
Behavior on opacity {
NumberAnimation { duration: 200 }
}
Row {
id: row
anchors {
centerIn: parent
verticalCenterOffset: pressed ? 1 : 0
horizontalCenterOffset: pressed ? 1 : 0
}
spacing: units.gu(1)
Icon {
id: icon
color: button.iconColor
anchors.verticalCenter: parent.verticalCenter
}
Label {
id: label
color: button.textColor
fontSize: button.fontSize
anchors.verticalCenter: parent.verticalCenter
Behavior on color {
ColorAnimation { duration: 200 }
}
}
}
}