paysages3d/src/interface/modeler/quickapp/qml/ToolbarButton.qml

113 lines
2.7 KiB
QML
Raw Normal View History

2014-08-19 15:37:24 +00:00
import QtQuick 2.0
2014-08-28 08:29:12 +00:00
import QtGraphicalEffects 1.0
2015-08-28 09:40:35 +00:00
import QtQuick.Controls 1.2
2014-08-19 15:37:24 +00:00
Item {
2015-08-20 22:25:34 +00:00
id: button
2015-08-28 09:40:35 +00:00
property var toolbar: null
property string picture
2015-08-28 09:40:35 +00:00
property bool checked: false
2014-08-19 15:37:24 +00:00
property bool hovered: false
2015-08-20 22:25:34 +00:00
property bool toggle: false
2015-08-28 09:40:35 +00:00
property ExclusiveGroup exclusiveGroup: null
2014-08-27 15:23:59 +00:00
property string helptext
property string hovertext
2015-08-20 22:46:42 +00:00
property string shortcut
property alias image_width: image.width
property alias image_height: image.height
signal clicked
2015-08-28 09:40:35 +00:00
signal toggled(bool value)
2014-08-19 15:37:24 +00:00
width: image.width + 10
height: image.height + 10
2015-08-20 22:41:14 +00:00
opacity: enabled ? 1.0 : 0.1
2014-08-19 15:37:24 +00:00
2015-08-28 09:40:35 +00:00
onExclusiveGroupChanged: {
if (exclusiveGroup)
exclusiveGroup.bindCheckable(button)
}
onCheckedChanged: {
toggled(checked);
if (toolbar && !toggle && checked) {
toolbar.current = button;
}
}
2015-08-20 22:25:34 +00:00
2015-08-20 22:41:14 +00:00
Behavior on opacity {
PropertyAnimation {
duration: 200
}
}
2014-08-19 15:37:24 +00:00
Rectangle {
id: glow
anchors.fill: parent
2015-08-20 22:25:34 +00:00
color: parent.toggle ? "#bbccbb" : "#cccccc"
2014-08-19 15:37:24 +00:00
radius: 8
2015-08-28 09:40:35 +00:00
opacity: button.checked ? 1.0 : (button.hovered ? 0.5 : 0.0)
2014-08-19 15:37:24 +00:00
Behavior on opacity {
PropertyAnimation {
duration: 200
}
}
2014-08-28 08:29:12 +00:00
RectangularGlow {
anchors.fill: glow
glowRadius: 8
spread: 0.2
2015-08-20 22:25:34 +00:00
color: button.toggle ? "#99aa99" : "#ffffff"
2014-08-28 08:29:12 +00:00
cornerRadius: glow.radius + glowRadius
}
2014-08-19 15:37:24 +00:00
}
Image {
id: image
2015-08-20 22:25:34 +00:00
source: button.picture
2014-08-19 15:37:24 +00:00
anchors.centerIn: parent
2014-08-27 15:23:59 +00:00
width: 32
height: 32
2014-08-28 08:29:12 +00:00
antialiasing: true
}
DropShadow {
anchors.fill: image
horizontalOffset: 2
verticalOffset: 2
radius: 4.0
samples: 16
color: "#80000000"
source: image
2014-08-19 15:37:24 +00:00
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
2014-08-27 15:23:59 +00:00
cursorShape: Qt.PointingHandCursor
2014-08-19 15:37:24 +00:00
2014-08-27 15:23:59 +00:00
onEntered: {
2015-08-20 22:25:34 +00:00
button.hovered = true;
2015-08-20 22:46:42 +00:00
tooltip_widget.hovertext = button.hovertext + (button.shortcut ? (" (" + button.shortcut + ")") : "");
2015-08-19 23:15:08 +00:00
tooltip_widget.hovered = this;
2014-08-27 15:23:59 +00:00
}
onExited: {
2015-08-20 22:25:34 +00:00
button.hovered = false;
2014-08-27 15:23:59 +00:00
tooltip_widget.hovertext = "";
}
onClicked: {
2015-08-28 09:40:35 +00:00
button.checked = !button.checked;
2015-08-20 22:25:34 +00:00
if (!button.toggle)
2014-08-27 15:23:59 +00:00
{
2015-08-28 09:40:35 +00:00
if (button.checked)
2014-08-27 15:23:59 +00:00
{
2015-08-20 22:25:34 +00:00
tooltip_widget.helptext = helptext;
}
else
{
tooltip_widget.helptext = "";
2014-08-27 15:23:59 +00:00
}
}
2015-08-20 22:25:34 +00:00
button.clicked();
2014-08-27 15:23:59 +00:00
}
2014-08-19 15:37:24 +00:00
}
}