2011-07-08 20:11:55 +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-10 13:04:22 +02:00
|
|
|
* GNU Library General Public License for more details
|
2011-07-08 20:11:55 +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: dualButton
|
|
|
|
|
|
|
|
// Common API
|
|
|
|
property bool checked
|
|
|
|
property alias pressed: mouseArea.pressed
|
|
|
|
|
|
|
|
signal clicked()
|
|
|
|
|
|
|
|
// Plasma API
|
|
|
|
property alias text: label.text // TODO: Not yet part of the common API
|
2011-10-10 13:04:22 +02:00
|
|
|
property alias view: surfaceLoader.sourceComponent
|
|
|
|
property alias shadow: shadowLoader.sourceComponent
|
2011-07-08 20:11:55 +02:00
|
|
|
|
2011-10-10 13:04:22 +02:00
|
|
|
width: surfaceLoader.width + label.paintedWidth
|
2011-11-09 22:31:39 +01:00
|
|
|
height: theme.defaultFont.mSize.height*1.8
|
2011-07-18 23:49:45 +02:00
|
|
|
// TODO: needs to define if there will be specific graphics for
|
|
|
|
// disabled buttons
|
|
|
|
opacity: dualButton.enabled ? 1.0 : 0.5
|
2011-07-08 20:11:55 +02:00
|
|
|
|
|
|
|
function entered() {
|
2011-07-18 23:41:07 +02:00
|
|
|
if (dualButton.enabled) {
|
2011-10-10 13:04:22 +02:00
|
|
|
shadowLoader.state = "hover"
|
2011-07-18 23:41:07 +02:00
|
|
|
}
|
2011-07-08 20:11:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function released() {
|
2011-07-18 23:41:07 +02:00
|
|
|
if (dualButton.enabled) {
|
|
|
|
dualButton.checked = !dualButton.checked;
|
|
|
|
dualButton.clicked();
|
|
|
|
}
|
2011-07-08 20:11:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Keys.onSpacePressed: entered();
|
|
|
|
Keys.onReturnPressed: entered();
|
|
|
|
Keys.onReleased: {
|
|
|
|
if(event.key == Qt.Key_Space ||
|
|
|
|
event.key == Qt.Key_Return)
|
|
|
|
released();
|
|
|
|
}
|
|
|
|
|
2011-10-10 13:04:22 +02:00
|
|
|
Loader {
|
|
|
|
id: shadowLoader
|
|
|
|
anchors.fill: surfaceLoader
|
2011-07-08 20:11:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
2011-10-10 13:04:22 +02:00
|
|
|
id: surfaceLoader
|
2011-07-08 20:11:55 +02:00
|
|
|
|
|
|
|
anchors {
|
|
|
|
verticalCenter: parent.verticalCenter
|
|
|
|
left: text ? parent.left : undefined
|
|
|
|
horizontalCenter: text ? undefined : parent.horizontalCenter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: label
|
|
|
|
|
|
|
|
text: dualButton.text
|
|
|
|
anchors {
|
|
|
|
top: parent.top
|
|
|
|
bottom: parent.bottom
|
2011-10-10 13:04:22 +02:00
|
|
|
left: surfaceLoader.right
|
2011-07-08 20:11:55 +02:00
|
|
|
right: parent.right
|
2011-10-10 13:39:16 +02:00
|
|
|
//FIXME: see how this margin will be set
|
|
|
|
leftMargin: height/4
|
2011-07-08 20:11:55 +02:00
|
|
|
}
|
|
|
|
color: theme.textColor
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: mouseArea
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
|
|
|
|
|
|
|
onReleased: dualButton.released();
|
|
|
|
onEntered: dualButton.entered();
|
|
|
|
onPressed: dualButton.forceActiveFocus();
|
|
|
|
onExited: {
|
2011-10-10 13:04:22 +02:00
|
|
|
shadowLoader.state = "shadow"
|
2011-07-08 20:11:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|