/
ButtonWithUnreadCount.qml
89 lines (87 loc) · 2.47 KB
/
ButtonWithUnreadCount.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
// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import com.nokia.meego 1.0
Button {
id: button
property string label: ""
property string icon: ""
property string errorIcon: "emblem-web.png"
property int unreads: 0
property bool busy: false
property bool moreAvailable: false
width: mainPage.width
height: buttonText.height + 30
BusyIndicator {
id: busyindicator
running: button.busy
visible: running
anchors.fill: iconImage
z: 100
}
Image {
id: iconImage
source: icon
anchors.left: button.left
anchors.verticalCenter: button.verticalCenter
width: 32
height: 32
anchors.leftMargin: 5
onStatusChanged: {
if(status == Image.Error)
source = errorIcon
}
}
Label {
font.pointSize: button.font.pointSize
anchors.verticalCenter: button.verticalCenter
anchors.left: busyindicator.right
id: buttonText
wrapMode: Text.Wrap
anchors.leftMargin: 5
text: button.label
// text: iconImage.source
width: button.width - busyindicator.width - separator.width - unreadText.width
verticalAlignment: Text.AlignVCenter
font.bold: unreads > 0
}
Rectangle {
id: separator
visible: unreadText.visible
width: 2
height: button.height * 0.9
anchors.right: unreadText.left
anchors.rightMargin: 2
anchors.verticalCenter: button.verticalCenter
gradient: Gradient {
GradientStop {
position: 0.0
color: "#FFFFFF"
}
GradientStop {
position: 0.2
color: "#888888"
}
GradientStop {
position: 0.8
color: "#666666"
}
GradientStop {
position: 1.0
color: "#FFFFFF"
}
}
}
Label {
id: unreadText
font.pointSize: button.font.pointSize/2
text: button.unreads.toString() + (moreAvailable ? "+" : "")
visible: button.unreads > 0 || moreAvailable
anchors.right: button.right
anchors.top: buttonText.top
width: button.width / 10
height: buttonText.height
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font.bold: unreads > 0
}
}