Commit e9983fc8 authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Add a way to make TextButton non-clickable

parent a92c7d11
Pipeline #995 passed with stage
in 7 seconds
import QtQuick 2.6;
import QtQmlTricks 3.0;
AutoRepeatableClicker {
id: clicker;
MouseArea {
id: self;
width: implicitWidth;
height: implicitHeight;
hoverEnabled: Style.useHovering;
......@@ -14,11 +14,11 @@ AutoRepeatableClicker {
when: (ico.visible && lbl.visible && !invertLayout);
PropertyChanges {
target: clicker;
contentWidth: Math.ceil (ico.width + lbl.contentWidth + clicker.padding * 3);
target: self;
contentWidth: Math.ceil (ico.width + lbl.contentWidth + self.padding * 3);
contentHeight: Math.ceil (ico.height > lbl.contentHeight
? ico.height + clicker.padding * 2
: lbl.contentHeight + clicker.padding * 2);
? ico.height + self.padding * 2
: lbl.contentHeight + self.padding * 2);
}
AnchorChanges {
target: ico;
......@@ -41,11 +41,11 @@ AutoRepeatableClicker {
when: (ico.visible && lbl.visible && invertLayout);
PropertyChanges {
target: clicker;
contentWidth: Math.ceil (ico.width + lbl.contentWidth + clicker.padding * 3);
target: self;
contentWidth: Math.ceil (ico.width + lbl.contentWidth + self.padding * 3);
contentHeight: Math.ceil (ico.height > lbl.contentHeight
? ico.height + clicker.padding * 2
: lbl.contentHeight + clicker.padding * 2);
? ico.height + self.padding * 2
: lbl.contentHeight + self.padding * 2);
}
AnchorChanges {
target: lbl;
......@@ -68,9 +68,9 @@ AutoRepeatableClicker {
when: (!ico.visible && lbl.visible);
PropertyChanges {
target: clicker;
contentWidth: Math.ceil (Math.max (lbl.contentWidth + clicker.padding * 2, contentHeight));
contentHeight: Math.ceil (lbl.contentHeight + clicker.padding * 2);
target: self;
contentWidth: Math.ceil (Math.max (lbl.contentWidth + self.padding * 2, contentHeight));
contentHeight: Math.ceil (lbl.contentHeight + self.padding * 2);
}
AnchorChanges {
target: lbl;
......@@ -85,9 +85,9 @@ AutoRepeatableClicker {
when: (ico.visible && !lbl.visible);
PropertyChanges {
target: clicker;
contentWidth: Math.ceil (ico.width + clicker.padding * 2);
contentHeight: Math.ceil (ico.height + clicker.padding * 2);
target: self;
contentWidth: Math.ceil (ico.width + self.padding * 2);
contentHeight: Math.ceil (ico.height + self.padding * 2);
}
AnchorChanges {
target: ico;
......@@ -102,29 +102,34 @@ AutoRepeatableClicker {
when: (!ico.visible && !lbl.visible);
PropertyChanges {
target: clicker;
target: self;
contentWidth: 0;
contentHeight: 0;
}
}
]
property int padding : Style.spacingNormal;
property bool flat : false;
property bool checked : false;
property bool autoColorIcon : true;
property bool invertLayout : false;
property alias text : lbl.text;
property alias textFont : lbl.font;
property alias rounding : rect.radius;
property alias icon : ico.sourceComponent;
property alias hovered : clicker.containsMouse;
property int contentWidth : 0;
property int contentHeight : 0;
property color backColor : Style.colorClickable;
property color textColor : (Style.useDarkTheme !== Style.isDark (backColor)
? Style.colorInverted
: Style.colorForeground);
property int padding : Style.spacingNormal;
property bool flat : false;
property bool checked : false;
property bool clickable : true;
property bool autoColorIcon : true;
property bool invertLayout : false;
property alias text : lbl.text;
property alias textFont : lbl.font;
property alias rounding : rect.radius;
property alias icon : ico.sourceComponent;
property alias hovered : clicker.containsMouse;
property alias autoRepeat : clicker.autoRepeat;
property alias repeatDelay : clicker.repeatDelay;
property alias repeatInterval : clicker.repeatInterval;
property alias sensitiveHalo : clicker.sensitiveHalo;
property int contentWidth : 0;
property int contentHeight : 0;
property color backColor : Style.colorClickable;
property color textColor : (Style.useDarkTheme !== Style.isDark (backColor)
? Style.colorInverted
: Style.colorForeground);
function click (isAutoRepeat) {
if (enabled) {
......@@ -132,6 +137,17 @@ AutoRepeatableClicker {
}
}
signal clicked (bool isRepeated);
AutoRepeatableClicker {
id: clicker;
visible: clickable;
enabled: self.enabled;
anchors.fill: parent;
onClicked: {
self.clicked (isRepeated);
}
}
Binding {
target: ico.item;
when: (autoColorIcon && ico.item && "color" in ico.item);
......@@ -142,8 +158,9 @@ AutoRepeatableClicker {
id: rect;
width: Math.round (parent.width);
height: Math.round (parent.height);
enabled: clicker.enabled;
enabled: self.enabled;
radius: Style.roundness;
visible: clickable;
antialiasing: radius;
gradient: (enabled
? (checked
......@@ -161,9 +178,9 @@ AutoRepeatableClicker {
Loader {
id: ico;
active: (sourceComponent !== null);
enabled: clicker.enabled;
enabled: self.enabled;
visible: (item !== null);
anchors.margins: clicker.padding;
anchors.margins: self.padding;
}
TextLabel {
id: lbl;
......@@ -174,13 +191,13 @@ AutoRepeatableClicker {
: Qt.darker (Style.colorSelection))
: textColor)
: Style.colorBorder);
enabled: clicker.enabled;
enabled: self.enabled;
visible: (text !== "");
horizontalAlignment: (ico.visible ? Text.AlignLeft : Text.AlignHCenter);
font {
family: Style.fontName;
pixelSize: Style.fontSizeNormal;
}
anchors.margins: clicker.padding;
anchors.margins: self.padding;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment