2011-04-26 23:35:42 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 by Daker Fernandes Pinheiro <dakerfp@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, 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
|
2011-10-13 11:19:39 +02:00
|
|
|
* GNU Library General Public License for more details
|
2011-04-26 23:35:42 +02:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQuick 1.0
|
|
|
|
import org.kde.plasma.core 0.1 as PlasmaCore
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: button
|
|
|
|
|
|
|
|
// Commmon API
|
|
|
|
property bool checked: false
|
|
|
|
property bool checkable: false
|
|
|
|
property alias pressed: mouse.pressed
|
|
|
|
property alias text: label.text
|
|
|
|
property alias iconSource: icon.source
|
|
|
|
property alias font: label.font
|
|
|
|
|
|
|
|
signal clicked()
|
|
|
|
|
2011-10-13 11:19:39 +02:00
|
|
|
PlasmaCore.Theme {
|
|
|
|
id: theme
|
|
|
|
}
|
2011-04-26 23:35:42 +02:00
|
|
|
|
2011-07-16 02:21:06 +02:00
|
|
|
function pressButton() {
|
2011-07-18 23:20:49 +02:00
|
|
|
if (button.enabled)
|
|
|
|
surface.prefix = "pressed";
|
2011-07-16 02:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function releaseButton() {
|
2011-07-18 23:20:49 +02:00
|
|
|
if (!button.enabled)
|
|
|
|
return;
|
|
|
|
|
2011-07-16 02:21:06 +02:00
|
|
|
if (button.checkable)
|
|
|
|
button.checked = !button.checked;
|
|
|
|
|
|
|
|
// TODO: "checked" state must have special graphics?
|
|
|
|
if (button.checked)
|
|
|
|
surface.prefix = "pressed";
|
|
|
|
else
|
|
|
|
surface.prefix = "normal";
|
|
|
|
|
|
|
|
button.clicked();
|
|
|
|
button.forceActiveFocus();
|
|
|
|
}
|
|
|
|
|
2011-10-12 00:04:37 +02:00
|
|
|
width: Math.max(50, icon.width + label.paintedWidth + surface.margins.left + surface.margins.right)
|
|
|
|
height: Math.max(20, Math.max(icon.height, label.paintedHeight) + surface.margins.top + surface.margins.bottom)
|
2011-07-18 23:49:45 +02:00
|
|
|
// TODO: needs to define if there will be specific graphics for
|
|
|
|
// disabled buttons
|
|
|
|
opacity: enabled ? 1.0 : 0.5
|
2011-04-26 23:35:42 +02:00
|
|
|
|
2011-07-16 02:21:06 +02:00
|
|
|
Keys.onSpacePressed: pressButton();
|
|
|
|
Keys.onReturnPressed: pressButton();
|
|
|
|
Keys.onReleased: {
|
|
|
|
if (event.key == Qt.Key_Space ||
|
|
|
|
event.key == Qt.Key_Return)
|
|
|
|
releaseButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
onActiveFocusChanged: {
|
|
|
|
if (activeFocus) {
|
2011-10-10 15:26:46 +02:00
|
|
|
shadow.state = "focus"
|
2011-10-10 15:33:28 +02:00
|
|
|
} else if (checked) {
|
|
|
|
shadow.state = "hidden"
|
|
|
|
} else {
|
2011-10-10 15:26:46 +02:00
|
|
|
shadow.state = "shadow"
|
2011-07-16 02:21:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-10 15:26:46 +02:00
|
|
|
ButtonShadow {
|
2011-04-26 23:35:42 +02:00
|
|
|
id: shadow
|
2011-10-10 15:26:46 +02:00
|
|
|
anchors.fill: parent
|
2011-04-26 23:35:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PlasmaCore.FrameSvgItem {
|
|
|
|
id: surface
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
imagePath: "widgets/button"
|
|
|
|
prefix: "normal"
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
anchors {
|
|
|
|
fill: parent
|
|
|
|
leftMargin: surface.margins.left
|
|
|
|
topMargin: surface.margins.top
|
|
|
|
rightMargin: surface.margins.right
|
|
|
|
bottomMargin: surface.margins.bottom
|
|
|
|
}
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: icon
|
|
|
|
|
|
|
|
anchors {
|
|
|
|
fill: label.text ? undefined : parent
|
|
|
|
top: label.text ? parent.top : undefined
|
|
|
|
left: label.text ? parent.left : undefined
|
|
|
|
bottom: label.text ? parent.bottom : undefined
|
|
|
|
}
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: label
|
|
|
|
|
|
|
|
anchors {
|
|
|
|
top: parent.top
|
|
|
|
bottom: parent.bottom
|
|
|
|
left: icon.right
|
|
|
|
right: parent.right
|
|
|
|
}
|
2011-10-13 18:23:40 +02:00
|
|
|
font.capitalization: theme.defaultFont.capitalization
|
|
|
|
font.family: theme.defaultFont.family
|
|
|
|
font.italic: theme.defaultFont.italic
|
|
|
|
font.letterSpacing: theme.defaultFont.letterSpacing
|
|
|
|
font.pointSize: theme.defaultFont.pointSize
|
|
|
|
font.strikeout: theme.defaultFont.strikeout
|
|
|
|
font.underline: theme.defaultFont.underline
|
|
|
|
font.weight: theme.defaultFont.weight
|
|
|
|
font.wordSpacing: theme.defaultFont.wordSpacing
|
2011-04-26 23:35:42 +02:00
|
|
|
color: theme.buttonTextColor
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: mouse
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
|
|
|
|
|
|
|
onPressed: {
|
2011-07-16 02:21:06 +02:00
|
|
|
pressButton();
|
2011-04-26 23:35:42 +02:00
|
|
|
}
|
|
|
|
onReleased: {
|
2011-07-16 02:21:06 +02:00
|
|
|
releaseButton();
|
2011-04-26 23:35:42 +02:00
|
|
|
}
|
|
|
|
onEntered: {
|
2011-10-10 15:26:46 +02:00
|
|
|
shadow.state = "hover"
|
2011-04-26 23:35:42 +02:00
|
|
|
}
|
|
|
|
onExited: {
|
2011-07-16 02:21:06 +02:00
|
|
|
if (button.activeFocus) {
|
2011-10-10 15:26:46 +02:00
|
|
|
shadow.state = "focus"
|
2011-10-10 15:33:28 +02:00
|
|
|
} else if (checked) {
|
|
|
|
shadow.state = "hidden"
|
2011-07-16 02:21:06 +02:00
|
|
|
} else {
|
2011-10-10 15:26:46 +02:00
|
|
|
shadow.state = "shadow"
|
2011-07-16 02:21:06 +02:00
|
|
|
}
|
2011-04-26 23:35:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|