33 import org.kde.plasma.core 0.1 as PlasmaCore
34 import "private" as Private
50 property bool checked:
false
58 property bool checkable:
false
65 property alias pressed: mouse.pressed
71 property alias text: label.text
82 property alias iconSource: icon.source
91 property alias font: label.font
97 property real minimumWidth: icon.width + label.paintedWidth + surfaceNormal.margins.left + surfaceNormal.margins.right + ((icon.valid) ? surfaceNormal.margins.left : 0)
102 property real minimumHeight: Math.max(theme.smallIconSize, label.paintedHeight) + surfaceNormal.margins.top + surfaceNormal.margins.bottom
110 if (label.text.length == 0) {
113 Math.max(theme.defaultFont.mSize.width*12, minimumWidth);
117 implicitHeight: Math.max(theme.defaultFont.mSize.height*1.6, minimumHeight)
121 opacity: enabled ? 1.0 : 0.5
125 property bool userPressed:
false
127 function belongsToButtonGroup()
130 && button.parent.hasOwnProperty(
"checkedButton")
131 && button.parent.exclusive
134 function clickButton()
137 if (!button.enabled) {
141 if ((!belongsToButtonGroup() || !button.checked) && button.checkable) {
142 button.checked = !button.checked
145 button.forceActiveFocus()
150 Keys.onSpacePressed:
internal.userPressed =
true
151 Keys.onReturnPressed:
internal.userPressed =
true
153 internal.userPressed =
false
154 if (event.key == Qt.Key_Space ||
155 event.key == Qt.Key_Return)
156 internal.clickButton();
159 Private.ButtonShadow {
163 if (
internal.userPressed || checked) {
165 }
else if (mouse.containsMouse) {
167 }
else if (button.activeFocus) {
176 PlasmaCore.FrameSvgItem {
180 imagePath:
"widgets/button"
185 PlasmaCore.FrameSvgItem {
189 imagePath:
"widgets/button"
196 state: (
internal.userPressed || checked) ?
"pressed" :
"normal"
197 spacing: icon.valid ? surfaceNormal.margins.left : 0
200 State { name:
"normal" },
201 State { name:
"pressed"
203 target: surfaceNormal
207 target: surfacePressed
217 NumberAnimation { target: surfaceNormal;
property:
"opacity"; to: 1; duration: 100 }
218 NumberAnimation { target: surfacePressed;
property:
"opacity"; to: 0; duration: 100 }
225 leftMargin: surfaceNormal.margins.left
226 topMargin: surfaceNormal.margins.top
227 rightMargin: surfaceNormal.margins.right
228 bottomMargin: surfaceNormal.margins.bottom
231 PlasmaCore.IconItem {
233 anchors.verticalCenter: parent.verticalCenter
234 width: valid? parent.height: 0
236 active: shadow.hasOverState && mouse.containsMouse
242 width: parent.width - icon.width - parent.spacing
243 height: parent.height
245 font.capitalization: theme.defaultFont.capitalization
246 font.family: theme.defaultFont.family
247 font.italic: theme.defaultFont.italic
248 font.letterSpacing: theme.defaultFont.letterSpacing
249 font.pointSize: theme.defaultFont.pointSize
250 font.strikeout: theme.defaultFont.strikeout
251 font.underline: theme.defaultFont.underline
252 font.weight: theme.defaultFont.weight
253 font.wordSpacing: theme.defaultFont.wordSpacing
254 color: theme.buttonTextColor
255 horizontalAlignment: icon.valid ? Text.AlignLeft : Text.AlignHCenter
256 verticalAlignment: Text.AlignVCenter
257 elide: button.width < button.implicitWidth ? Text.ElideRight : Text.ElideNone
266 onPressed:
internal.userPressed =
true
267 onReleased:
internal.userPressed =
false
268 onCanceled:
internal.userPressed =
false
269 onClicked:
internal.clickButton()