22 import org.kde.plasma.core 0.1 as PlasmaCore
23 import "private" as Private
35 property bool flat:
true
40 property bool checked: defaultAction ? defaultAction.checked :
false
45 property bool checkable: defaultAction ? defaultAction.checkable :
false
51 property alias pressed: mouse.pressed
57 property alias text: label.text
65 property alias iconSource: icon.source
71 property alias font: label.font
79 property QtObject defaultAction
82 enabled: defaultAction == undefined || defaultAction.enabled
90 property real minimumWidth: Math.max(theme.smallIconSize, height) + label.paintedWidth + delegate.margins.left + delegate.margins.left + ((icon.valid) ? delegate.margins.left : 0)
95 property real minimumHeight: Math.max(theme.smallIconSize, label.paintedHeight) + delegate.margins.top + delegate.margins.top
98 if (label.text.length == 0) {
101 Math.max(theme.defaultFont.mSize.width*12, minimumWidth);
105 implicitHeight: Math.max(theme.defaultFont.mSize.height*1.6, minimumHeight)
109 opacity: enabled ? 1.0 : 0.5
111 Keys.onSpacePressed:
internal.userPressed =
true
112 Keys.onReturnPressed:
internal.userPressed =
true
114 internal.userPressed =
false
115 if (event.key == Qt.Key_Space ||
116 event.key == Qt.Key_Return)
117 internal.clickButton()
120 onActiveFocusChanged: {
122 shadow.state =
"focus"
123 }
else if (checked) {
124 shadow.state =
"hidden"
126 shadow.state =
"shadow"
132 property bool userPressed:
false
134 function clickButton()
136 if (!button.enabled) {
140 if (defaultAction && defaultAction.checkable) {
141 defaultAction.checked = !defaultAction.checked
142 }
else if (button.checkable) {
143 button.checked = !button.checked
146 if (button.KeyNavigation.tab || button.KeyNavigation.backtab) {
151 button.forceActiveFocus();
156 defaultAction.trigger()
164 property QtObject margins: item.margins
165 property string shadowState:
"shadow"
167 if (label.text.length == 0 && button.width == button.height && (button.parent && button.parent.checkedButton === undefined) && !flat) {
168 return roundButtonComponent
170 return buttonComponent
180 property alias margins: surface.margins
181 property alias hasOverState: shadow.hasOverState
182 Private.ButtonShadow {
185 visible: !flat && (surface.enabledBorders ==
"AllBorders" || state ==
"hover" || state ==
"focus")
186 state: delegate.shadowState
189 PlasmaCore.FrameSvgItem {
194 button.parent.width < button.parent.implicitWidth ||
195 button.parent.checkedButton === undefined ||
196 !bordersSvg.hasElement(
"pressed-hint-compose-over-border")) {
197 if (shadows !== null) {
203 var borders =
new Array()
205 borders.push(
"LeftBorder")
208 borders.push(
"TopBorder")
210 if (button.x + button.width >= button.parent.width) {
211 borders.push(
"RightBorder")
213 if (button.y + button.height >= button.parent.height) {
214 borders.push(
"BottomBorder")
217 if (shadows === null) {
218 shadows = shadowsComponent.createObject(surface)
221 return borders.join(
"|")
225 imagePath:
"widgets/button"
226 prefix: (
internal.userPressed || checked) ?
"pressed" :
"normal"
228 opacity: (
internal.userPressed || checked || !flat || (shadow.hasOverState && mouse.containsMouse && button.enabled)) ? 1 : 0
229 Behavior on opacity {
230 PropertyAnimation { duration: 250 }
235 imagePath:
"widgets/button"
238 property Item shadows
246 width: naturalSize.width
247 elementId: surface.prefix+
"-left"
248 visible: button.x > 0
252 bottom: parent.bottom
259 width: naturalSize.width
260 elementId: surface.prefix+
"-right"
261 visible: button.x + button.width < button.parent.width
265 bottom: parent.bottom
272 height: naturalSize.height
273 elementId: surface.prefix+
"-top"
274 visible: button.y > 0
285 width: naturalSize.width
286 elementId: surface.prefix+
"-bottom"
287 visible: button.y + button.height < button.parent.height
291 bottom: parent.bottom
303 id: roundButtonComponent
305 id: roundButtonDelegate
308 property QtObject margins: QtObject {
309 property int left: delegate.width/8
310 property int top: delegate.width/8
311 property int right: delegate.width/8
312 property int bottom: delegate.width/8
314 property alias hasOverState: roundShadow.hasOverState
315 Private.RoundShadow {
319 state: delegate.shadowState
324 imagePath:
"widgets/actionbutton"
330 elementId: (
internal.userPressed || checked) ?
"pressed" :
"normal"
334 opacity: (
internal.userPressed || checked || !flat || (roundShadow.hasOverState && mouse.containsMouse)) ? 1 : 0
335 Behavior on opacity {
336 PropertyAnimation { duration: 250 }
345 leftMargin: delegate.margins.left
346 topMargin: delegate.margins.top
347 rightMargin: delegate.margins.right
348 bottomMargin: delegate.margins.bottom
351 spacing: icon.valid ? delegate.margins.left : 0
353 PlasmaCore.IconItem {
355 anchors.verticalCenter: parent.verticalCenter
356 width: valid ? Math.min(parent.width, parent.height): 0
358 active: delegate.item.hasOverState && mouse.containsMouse
364 width: parent.width - icon.width - parent.spacing
365 height: parent.height
367 font.capitalization: theme.defaultFont.capitalization
368 font.family: theme.defaultFont.family
369 font.italic: theme.defaultFont.italic
370 font.letterSpacing: theme.defaultFont.letterSpacing
371 font.pointSize: theme.defaultFont.pointSize
372 font.strikeout: theme.defaultFont.strikeout
373 font.underline: theme.defaultFont.underline
374 font.weight: theme.defaultFont.weight
375 font.wordSpacing: theme.defaultFont.wordSpacing
377 color: mouse.containsMouse ? theme.buttonTextColor : theme.textColor
378 Behavior on color { ColorAnimation { duration: 100 } }
380 horizontalAlignment: icon.valid ?
Text.AlignLeft :
Text.AlignHCenter
381 verticalAlignment:
Text.AlignVCenter
389 hoverEnabled: delegate.item.hasOverState
391 onPressed:
internal.userPressed =
true
392 onReleased:
internal.userPressed =
false
394 internal.userPressed =
false
395 delegate.shadowState =
"shadow"
397 onClicked:
internal.clickButton()
400 if (delegate.item.hasOverState && !flat && !
internal.userPressed && !checked) {
401 delegate.shadowState =
"hover"
407 if (button.activeFocus) {
408 delegate.shadowState =
"focus"
409 }
else if (checked) {
410 delegate.shadowState =
"hidden"
412 delegate.shadowState =
"shadow"