Index: sources/gui/qml/components/TouchRect.qml =================================================================== diff -u -rcd769413344091cea88a30861b49188c8c147cba -r73091a6f5717c0fc88e236c06c618ad361f30a3c --- sources/gui/qml/components/TouchRect.qml (.../TouchRect.qml) (revision cd769413344091cea88a30861b49188c8c147cba) +++ sources/gui/qml/components/TouchRect.qml (.../TouchRect.qml) (revision 73091a6f5717c0fc88e236c06c618ad361f30a3c) @@ -26,103 +26,78 @@ */ Rectangle { id : _root property alias text : _text - property alias button : _mouseArea - property bool animated : false - property alias loops : _clickAnimation.loops - property int duration : 200 - - property bool disabled : false + property bool animated : true + property bool isDefault : false property bool selectable : false property bool selected : false property color textColor : Colors.textButton property color borderColor : Colors.borderButton property color backgroundColor : Colors.backgroundButtonNormal + property color defaultColor : // Colors.backgroundButtonSelect + backgroundColor == Colors.transparent ? + Colors.backgroundButtonSelect : + Qt.lighter(_root.backgroundColor, 1.15) - property int touchExpanding : 0 + property color selectColor : // Colors.backgroundButtonSelectDark + backgroundColor == Colors.transparent ? + Colors.backgroundButtonSelectDark : + Qt.darker (_root.backgroundColor, 1.15) - signal clicked - - onDurationChanged: { - _colorAnimationOn .duration = duration - _colorAnimationOff.duration = duration - } - - function animate(vAnimate) { - if (vAnimate) { - if ( disabled ) { return } - if ( animated ) { - _clickAnimation.restart() - } - } else { - _clickAnimation.stop() - _root.color = backgroundColor + QtObject { id: _private + function color() { + var mBackgroundColor = _root.backgroundColor + if ( isDefault ) mBackgroundColor = _root.defaultColor + if (! enabled ) return Colors.transparent + if ( selectable ) + if ( selected ) return Colors.backgroundButtonSelectDark + else return mBackgroundColor + if (! animated ) return mBackgroundColor + if ( _mouseArea.pressed ) return _root.selectColor + return mBackgroundColor } - } - onDisabledChanged: { - if (disabled) { - text.color = Colors.textDisableButton - border.color = Colors.borderDisableButton - color = "Transparent" - } else { - text.color = textColor - border.color = borderColor - color = backgroundColor + function borderColor() { + if ( ! enabled ) return Colors.borderDisableButton + if ( selectable ) + if ( selected ) { + return _root.borderColor + } else { + return Colors.borderButtonUnselected + } + return _root.borderColor } } + color : _private.color() + border.color: _private.borderColor() + + property int touchExpanding : 0 + + signal pressed + signal released + signal clicked + width : Variables.touchRectWidth height : Variables.touchRectHeight radius : Variables.touchRectRadius - color : backgroundColor - border { - color: borderColor - width: Variables.borderWidth - } + border.width: Variables.borderWidth + + + Text { id: _text anchors.centerIn: parent - color: textColor + color: enabled ? _root.textColor : Colors.textDisableButton font.pixelSize: Fonts.fontPixelButton } - function setSelected(isSelected) { - _root.selected = isSelected - if (_root.selected) { - _root.color = Colors.backgroundButtonSelectDark - _root.borderColor = Colors.borderButton - } - else { - _root.color = backgroundColor - _root.borderColor = Colors.borderButtonUnselected - } - } - MouseArea { id: _mouseArea anchors.fill : parent anchors.margins : touchExpanding * -1 - onClicked : { - if ( disabled ) { return } - if (selectable) { - setSelected(!selected) - _root.clicked() - return - } - animate(true) - _root.clicked() - } - } + onClicked : _root.clicked() + onPressed : _root.pressed() + onReleased : _root.released() - SequentialAnimation { id: _clickAnimation - running: false - onStopped: { - _root.color = backgroundColor - } - onFinished: { - _root.color = backgroundColor - } - PropertyAnimation { id: _colorAnimationOn ; target: _root; property: "color"; to: _root.border.color; duration: duration; } - PropertyAnimation { id: _colorAnimationOff; target: _root; property: "color"; to: _root.color ; duration: duration; } } }