Warning, /graphics/krita/libs/libqml/plugins/components/Button.qml is written in an unsupported language. File is not indexed.
0001 /* This file is part of the KDE project
0002 * SPDX-FileCopyrightText: 2012 Arjen Hiemstra <ahiemstra@heimr.nl>
0003 *
0004 * SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006
0007 import QtQuick 2.3
0008 import org.krita.sketch 1.0
0009
0010 Item {
0011 id: base;
0012
0013 signal clicked();
0014
0015 property alias image: icon.source;
0016 //property color color: Settings.theme.color("components/button/base");
0017 // define background and highlight color transparent by default,
0018 // so they can be defined depending on the context; also make the icon half transparent on click
0019 // if the color is transparent #00000000
0020 property color color: "#00000000"
0021 property alias border: fill.border;
0022 property alias radius: fill.radius;
0023 property alias text: label.text;
0024 property color textColor: Settings.theme.color("components/button/text");
0025 property alias textSize: label.font.pixelSize;
0026 property alias bold: label.font.bold;
0027 property bool shadow: false;
0028 property bool enabled: true; // XXX: visualize disabledness
0029 property alias asynchronous: icon.asynchronous;
0030
0031 property bool highlight: false;
0032 //property color highlightColor: Settings.theme.color("components/button/highlight");
0033 property color highlightColor: "#00000000"
0034
0035 property bool checkable: false;
0036 property bool checked: false;
0037 property color checkedColor: Settings.theme.color("components/button/checked");
0038
0039 property bool hasFocus: false;
0040
0041 property string tooltip: "";
0042
0043 width: Constants.GridWidth;
0044 height: Constants.GridHeight;
0045
0046 Rectangle {
0047 id: fill;
0048 anchors.fill: parent;
0049 anchors.margins: 0;
0050 color: base.highlight && mouse.pressed && base.enabled ? base.highlightColor : base.color;
0051 visible: true
0052
0053 Rectangle {
0054 anchors {
0055 left: parent.left;
0056 right: parent.right;
0057 bottom: parent.bottom;
0058 margins: fill.radius / 2;
0059 }
0060 height: fill.radius / 2;
0061 radius: fill.radius / 4;
0062 color: base.textColor;
0063 visible: base.hasFocus;
0064 opacity: 0.3
0065 }
0066
0067 Rectangle {
0068 id: checkedVisualiser;
0069 opacity: base.checked ? 1 : 0;
0070 Behavior on opacity { NumberAnimation { duration: Constants.AnimationDuration; } }
0071 anchors.fill: parent;
0072 anchors.margins: 2;
0073 color: base.checkedColor;
0074 radius: base.height === base.width ? base.height / 2 - 1 : base.radius;
0075 }
0076
0077 Image {
0078 id: icon;
0079 anchors.centerIn: parent
0080 width: parent.width > parent.height ? parent.height * 0.9 : parent.width * 0.9;
0081 height: width
0082 fillMode: Image.PreserveAspectFit;
0083 smooth: true;
0084 asynchronous: true;
0085 opacity: base.enabled ? (mouse.pressed && base.highlightColor == "#00000000" ? 0.5 : 1) : 0.7;
0086 Behavior on opacity { NumberAnimation { duration: Constants.AnimationDuration * 0.5; } }
0087
0088 sourceSize.width: width;
0089 sourceSize.height: width;
0090 }
0091
0092 Label {
0093 id: label;
0094 anchors.verticalCenter: parent.verticalCenter;
0095 height: font.pixelSize;
0096 width: parent.width;
0097 horizontalAlignment: Text.AlignHCenter;
0098 elide: Text.ElideRight;
0099 opacity: base.enabled ? 1 : 0.7;
0100 color: base.textColor;
0101 }
0102 // Rectangle {
0103 // id: enabledVisualiser;
0104 // opacity: base.enabled ? 0 : 0.7;
0105 // anchors.fill: parent;
0106 // color: "black";
0107 // }
0108 }
0109
0110 SimpleTouchArea {
0111 anchors.fill: parent;
0112 onTouched: {
0113 if (base.enabled) {
0114 base.clicked();
0115 if (base.checkable) {
0116 base.checked = !base.checked;
0117 }
0118 }
0119 }
0120 }
0121 MouseArea {
0122 id: mouse;
0123 anchors.fill: parent;
0124 hoverEnabled: true;
0125 acceptedButtons: Qt.LeftButton | Qt.RightButton;
0126
0127 onClicked: {
0128 if(mouse.button == Qt.LeftButton && base.enabled) {
0129 base.clicked();
0130 if(base.checkable) {
0131 base.checked = !base.checked;
0132 }
0133 } else if(mouse.button == Qt.RightButton && base.tooltip != "") {
0134 tooltip.show(base.width / 2, 0);
0135 }
0136 }
0137 onEntered: {
0138 hoverDelayTimer.start();
0139 }
0140 onPositionChanged: {
0141 if(hoverDelayTimer.running) {
0142 hoverDelayTimer.restart();
0143 }
0144 }
0145 onExited: {
0146 hoverDelayTimer.stop();
0147 tooltip.hide();
0148 }
0149 }
0150
0151 Timer {
0152 id: hoverDelayTimer;
0153 interval: 1000;
0154 onTriggered: { if(base.tooltip != "") tooltip.show(base.width / 2, 0) }
0155 }
0156
0157 Tooltip {
0158 id: tooltip;
0159 text: base.tooltip;
0160 }
0161
0162 states: State {
0163 name: "pressed";
0164 when: (mouse.pressed || base.checked) && enabled;
0165
0166 PropertyChanges {
0167 target: fill
0168 color: base.highlightColor
0169 anchors.topMargin: 0
0170 }
0171 }
0172
0173 transitions: Transition {
0174 from: "";
0175 to: "down";
0176 reversible: true;
0177 ParallelAnimation {
0178 NumberAnimation { properties: "size"; duration: 150; }
0179 ColorAnimation { duration: 150; }
0180 }
0181 }
0182 }