Add Button component with QtComponents compatible api

Signed-off-by: Daker Fernandes Pinheiro <dakerfp@gmail.com>
This commit is contained in:
Daker Fernandes Pinheiro 2011-04-26 18:35:42 -03:00
parent 24f673a014
commit c0bb0bb955
2 changed files with 153 additions and 0 deletions

View File

@ -0,0 +1,152 @@
/*
* 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
* GNU General Public License for more details
*
* 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()
// Plasma API
property QtObject theme: PlasmaCore.Theme { }
width: 50
height: 20
PlasmaCore.FrameSvgItem {
id: hover
anchors.fill: parent
opacity: 0
anchors.leftMargin: -margins.left
anchors.topMargin: -margins.top
anchors.rightMargin: -margins.right
anchors.bottomMargin: -margins.bottom
imagePath: "widgets/button"
prefix: "hover"
Behavior on opacity {
PropertyAnimation { duration: 250 }
}
}
PlasmaCore.FrameSvgItem {
id: shadow
anchors {
fill: parent
leftMargin: -margins.left
topMargin: -margins.top
rightMargin: -margins.right
bottomMargin: -margins.bottom
}
imagePath: "widgets/button"
prefix: "shadow"
Behavior on opacity {
PropertyAnimation { duration: 250 }
}
}
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
}
color: theme.buttonTextColor
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
}
MouseArea {
id: mouse
anchors.fill: parent
hoverEnabled: true
onPressed: {
surface.prefix = "pressed";
}
onReleased: {
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();
}
onEntered: {
shadow.opacity = 0;
hover.opacity = 1;
}
onExited: {
shadow.opacity = 1;
hover.opacity = 0;
}
}
}

View File

@ -1,4 +1,5 @@
BusyWidget 0.1 BusyWidget.qml
Button 0.1 Button.qml
FlashingLabel 0.1 FlashingLabel.qml
Frame 0.1 Frame.qml
IconWidget 0.1 IconWidget.qml