kill the ToolButton duplication for touch
This commit is contained in:
parent
b794f94286
commit
05936e77d8
@ -60,6 +60,7 @@ install(FILES qml/TabGroup.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports
|
||||
#install(FILES qml/TextField.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components)
|
||||
install(FILES qml/ToolBarLayout.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components)
|
||||
install(FILES qml/ToolBar.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components)
|
||||
install(FILES qml/ToolButton.qml DESTINATION ${PLUGIN_INSTALL_DIR}/platformimports/touch/org/kde/plasma/components)
|
||||
|
||||
|
||||
#Now install the private stuff!
|
||||
|
@ -1,334 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 by Daker Fernandes Pinheiro <dakerfp@gmail.com>
|
||||
* Copyright (C) 2011 by Marco Martin <mart@kde.org>
|
||||
*
|
||||
* 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 Library 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.1
|
||||
import org.kde.plasma.core 0.1 as PlasmaCore
|
||||
import "private" as Private
|
||||
|
||||
Item {
|
||||
id: button
|
||||
|
||||
// Commmon API
|
||||
property bool flat: true
|
||||
property bool checked: defaultAction ? defaultAction.checked : false
|
||||
property bool checkable: defaultAction ? defaultAction.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 extensiuons
|
||||
property QtObject defaultAction
|
||||
|
||||
onFlatChanged: {
|
||||
if (!flat) {
|
||||
delegate.opacity = 1
|
||||
}
|
||||
}
|
||||
|
||||
enabled: defaultAction==undefined||defaultAction.enabled
|
||||
|
||||
implicitWidth: {
|
||||
if (label.paintedWidth == 0) {
|
||||
return implicitHeight
|
||||
} else {
|
||||
return Math.max(theme.defaultFont.mSize.width*12, icon.width + label.paintedWidth + delegate.margins.left + delegate.margins.right) + ((icon.valid) ? delegate.margins.left : 0)
|
||||
}
|
||||
}
|
||||
implicitHeight: Math.max(theme.defaultFont.mSize.height*1.6, Math.max(icon.height, label.paintedHeight) + delegate.margins.top/2 + delegate.margins.bottom/2)
|
||||
|
||||
// TODO: needs to define if there will be specific graphics for
|
||||
// disabled buttons
|
||||
opacity: enabled ? 1.0 : 0.5
|
||||
|
||||
Keys.onSpacePressed: internal.userPressed = true
|
||||
Keys.onReturnPressed: internal.userPressed = true
|
||||
Keys.onReleased: {
|
||||
internal.userPressed = false
|
||||
if (event.key == Qt.Key_Space ||
|
||||
event.key == Qt.Key_Return)
|
||||
internal.clickButton()
|
||||
}
|
||||
|
||||
QtObject {
|
||||
id: internal
|
||||
property bool userPressed: false
|
||||
|
||||
function clickButton()
|
||||
{
|
||||
if (!button.enabled) {
|
||||
return
|
||||
}
|
||||
|
||||
if (defaultAction && defaultAction.checkable) {
|
||||
defaultAction.checked = !defaultAction.checked
|
||||
} else if (button.checkable) {
|
||||
button.checked = !button.checked
|
||||
}
|
||||
|
||||
button.clicked()
|
||||
button.forceActiveFocus()
|
||||
|
||||
if (defaultAction) {
|
||||
defaultAction.trigger()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: delegate
|
||||
anchors.fill:parent
|
||||
property QtObject margins: item.margins
|
||||
sourceComponent: {
|
||||
if (label.text.length == 0 && button.width == button.height) {
|
||||
return roundButtonComponent
|
||||
} else {
|
||||
return buttonComponent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: buttonComponent
|
||||
Item {
|
||||
anchors.fill: parent
|
||||
property alias margins: surface.margins
|
||||
property alias surfaceOpacity: surface.opacity
|
||||
Private.ButtonShadow {
|
||||
id: shadow
|
||||
anchors.fill: parent
|
||||
visible: !flat && (surface.enabledBorders == "AllBorders" || state == "hover" || state == "focus")
|
||||
state: (internal.userPressed || checked) ? "hidden" : "shadow"
|
||||
}
|
||||
|
||||
PlasmaCore.FrameSvgItem {
|
||||
id: surface
|
||||
|
||||
enabledBorders: {
|
||||
if (flat || button.parent.width < button.parent.implicitWidth ||
|
||||
button.parent.checkedButton === undefined) {
|
||||
if (shadows !== null) {
|
||||
shadows.destroy()
|
||||
}
|
||||
return "AllBorders"
|
||||
}
|
||||
|
||||
var borders = new Array()
|
||||
if (button.x == 0) {
|
||||
borders.push("LeftBorder")
|
||||
}
|
||||
if (button.y == 0) {
|
||||
borders.push("TopBorder")
|
||||
}
|
||||
if (button.x + button.width >= button.parent.width) {
|
||||
borders.push("RightBorder")
|
||||
}
|
||||
if (button.y + button.height >= button.parent.height) {
|
||||
borders.push("BottomBorder")
|
||||
}
|
||||
|
||||
if (shadows === null) {
|
||||
shadows = shadowsComponent.createObject(surface)
|
||||
}
|
||||
|
||||
return borders.join("|")
|
||||
}
|
||||
|
||||
anchors.fill: parent
|
||||
imagePath: "widgets/button"
|
||||
prefix: (internal.userPressed || checked) ? "pressed" : "normal"
|
||||
//internal: if there is no hover status, don't paint on mouse over in touchscreens
|
||||
opacity: (internal.userPressed || checked || !flat || (shadow.hasOverState && mouse.containsMouse)) ? 1 : 0
|
||||
Behavior on opacity {
|
||||
PropertyAnimation { duration: 250 }
|
||||
}
|
||||
property Item shadows
|
||||
Component {
|
||||
id: shadowsComponent
|
||||
Item {
|
||||
anchors.fill: parent
|
||||
PlasmaCore.Svg {
|
||||
id: bordersSvg
|
||||
imagePath: "widgets/button"
|
||||
}
|
||||
PlasmaCore.SvgItem {
|
||||
svg: bordersSvg
|
||||
width: naturalSize.width
|
||||
elementId: surface.prefix+"-left"
|
||||
visible: button.x > 0
|
||||
anchors {
|
||||
left: parent.left
|
||||
top: parent.top
|
||||
bottom: parent.bottom
|
||||
margins: 2
|
||||
leftMargin: -2
|
||||
}
|
||||
}
|
||||
PlasmaCore.SvgItem {
|
||||
svg: bordersSvg
|
||||
width: naturalSize.width
|
||||
elementId: surface.prefix+"-right"
|
||||
visible: button.x + button.width < button.parent.width
|
||||
anchors {
|
||||
right: parent.right
|
||||
top: parent.top
|
||||
bottom: parent.bottom
|
||||
margins: 2
|
||||
rightMargin: -2
|
||||
}
|
||||
}
|
||||
PlasmaCore.SvgItem {
|
||||
svg: bordersSvg
|
||||
height: naturalSize.height
|
||||
elementId: surface.prefix+"-top"
|
||||
visible: button.y > 0
|
||||
anchors {
|
||||
left: parent.left
|
||||
top: parent.top
|
||||
right: parent.right
|
||||
margins: 2
|
||||
topMargin: -2
|
||||
}
|
||||
}
|
||||
PlasmaCore.SvgItem {
|
||||
svg: bordersSvg
|
||||
width: naturalSize.width
|
||||
elementId: surface.prefix+"-bottom"
|
||||
visible: button.y + button.height < button.parent.height
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
bottom: parent.bottom
|
||||
margins: 2
|
||||
bottomMargin: -2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: roundButtonComponent
|
||||
Item {
|
||||
id: roundButtonDelegate
|
||||
parent: delegate
|
||||
anchors.fill: parent
|
||||
property alias surfaceOpacity: buttonItem.opacity
|
||||
property QtObject margins: QtObject {
|
||||
property int left: delegate.width/8
|
||||
property int top: delegate.width/8
|
||||
property int right: delegate.width/8
|
||||
property int bottom: delegate.width/8
|
||||
}
|
||||
Private.RoundShadow {
|
||||
id: roundShadow
|
||||
anchors.fill: parent
|
||||
visible: !flat
|
||||
state: (internal.userPressed || checked) ? "hidden" : "shadow"
|
||||
}
|
||||
|
||||
PlasmaCore.Svg {
|
||||
id: buttonSvg
|
||||
imagePath: "widgets/actionbutton"
|
||||
}
|
||||
|
||||
PlasmaCore.SvgItem {
|
||||
id: buttonItem
|
||||
svg: buttonSvg
|
||||
elementId: (internal.userPressed || checked) ? "pressed" : "normal"
|
||||
width: parent.height
|
||||
height: width
|
||||
opacity: (internal.userPressed || checked || !flat || (roundShadow.hasOverState && mouse.containsMouse && button.enabled)) ? 1 : 0
|
||||
|
||||
Behavior on opacity {
|
||||
PropertyAnimation { duration: 250 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
anchors {
|
||||
fill: parent
|
||||
leftMargin: delegate.margins.left
|
||||
topMargin: delegate.margins.top
|
||||
rightMargin: delegate.margins.right
|
||||
bottomMargin: delegate.margins.bottom
|
||||
}
|
||||
|
||||
Private.IconLoader {
|
||||
id: icon
|
||||
|
||||
anchors {
|
||||
verticalCenter: parent.verticalCenter
|
||||
left: label.text ? parent.left : undefined
|
||||
horizontalCenter: label.text ? undefined : parent.horizontalCenter
|
||||
}
|
||||
width: label.text ? implicitWidth : roundToStandardSize(parent.width)
|
||||
height: width
|
||||
}
|
||||
|
||||
Text {
|
||||
id: label
|
||||
|
||||
//FIXME: why this is needed?
|
||||
onPaintedWidthChanged: {
|
||||
icon.anchors.horizontalCenter = label.paintedWidth > 0 ? undefined : icon.parent.horizontalCenter
|
||||
icon.anchors.left = label.paintedWidth > 0 ? icon.parent.left : undefined
|
||||
}
|
||||
|
||||
anchors {
|
||||
top: parent.top
|
||||
bottom: parent.bottom
|
||||
left: icon.valid ? icon.right : parent.left
|
||||
right: parent.right
|
||||
}
|
||||
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
|
||||
color: delegate.item.surfaceOpacity > 0.5 ? theme.buttonTextColor : theme.textColor
|
||||
horizontalAlignment: icon.valid ? Text.AlignLeft : Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: mouse
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
|
||||
onPressed: internal.userPressed = true
|
||||
onReleased: internal.userPressed = false
|
||||
onCanceled: internal.userPressed = false
|
||||
onClicked: internal.clickButton()
|
||||
}
|
||||
}
|
||||
|
@ -179,6 +179,7 @@ Item {
|
||||
parent: delegate
|
||||
anchors.fill: parent
|
||||
property alias margins: surface.margins
|
||||
property alias hasOverState: shadow.hasOverState
|
||||
Private.ButtonShadow {
|
||||
id: shadow
|
||||
anchors.fill: parent
|
||||
@ -311,6 +312,7 @@ Item {
|
||||
property int right: delegate.width/8
|
||||
property int bottom: delegate.width/8
|
||||
}
|
||||
property alias hasOverState: roundShadow.hasOverState
|
||||
Private.RoundShadow {
|
||||
id: roundShadow
|
||||
visible: !flat
|
||||
@ -397,7 +399,7 @@ Item {
|
||||
id: mouse
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
hoverEnabled: delegate.item.hasOverState
|
||||
|
||||
onPressed: internal.userPressed = true
|
||||
onReleased: internal.userPressed = false
|
||||
@ -408,7 +410,7 @@ Item {
|
||||
onClicked: internal.clickButton()
|
||||
|
||||
onEntered: {
|
||||
if (!flat && !internal.userPressed && !checked) {
|
||||
if (delegate.item.hasOverState && !flat && !internal.userPressed && !checked) {
|
||||
delegate.shadowState = "hover"
|
||||
}
|
||||
button.z += 2
|
||||
|
Loading…
x
Reference in New Issue
Block a user