split ToolbarButton.qml into a stateful image part

This commit is contained in:
howard-stearns 2016-11-15 14:59:27 -08:00
parent 182050c4b9
commit b0518feee4
2 changed files with 35 additions and 29 deletions

View file

@ -0,0 +1,34 @@
import QtQuick 2.5
import QtQuick.Controls 1.4
Item {
property alias imageURL: image.source
property alias alpha: image.opacity
property var subImage;
property int yOffset: 0
property int buttonState: 0
property real size: 50
width: size; height: size
property bool pinned: false
clip: true
function updateYOffset() { yOffset = size * buttonState; }
onButtonStateChanged: updateYOffset();
Component.onCompleted: {
if (subImage) {
if (subImage.y) {
yOffset = subImage.y;
return;
}
}
updateYOffset();
}
Image {
id: image
y: -parent.yOffset;
width: parent.width
}
}

View file

@ -1,41 +1,13 @@
import QtQuick 2.5
import QtQuick.Controls 1.4
Item {
StateImage {
id: button
property alias imageURL: image.source
property alias alpha: image.opacity
property var subImage;
property int yOffset: 0
property int buttonState: 0
property int hoverState: -1
property int defaultState: -1
property var toolbar;
property real size: 50 // toolbar ? toolbar.buttonSize : 50
width: size; height: size
property bool pinned: false
clip: true
onButtonStateChanged: {
yOffset = size * buttonState;
}
Component.onCompleted: {
if (subImage) {
if (subImage.y) {
yOffset = subImage.y;
}
}
}
signal clicked()
Image {
id: image
y: -button.yOffset;
width: parent.width
}
Timer {
id: asyncClickSender
interval: 10