Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Initial commit qml version of Krita's slider, curve, angle and groupbox widgets.
Deif Loub3a1f4ed456c
diff --git a/qmlmodules/components/CMakeLists.txt b/qmlmodules/components/CMakeLists.txtindex f883c6d0a8..6715f796b1 100644--- a/qmlmodules/components/CMakeLists.txt+++ b/qmlmodules/components/CMakeLists.txt@@ -28,12 +28,43 @@ else ()KritaQmlComponentsPlugin.hSvgTextLabel.cppSvgTextLabel.h+ KisNumParser.cpp+ KisNumParser.h+ KisCubicCurveQMLWrapper.cpp+ KisCubicCurveQMLWrapper.h)endif ()ecm_target_qml_sources(kritaqmlcomponents SOURCESqml/DoubleSpinBox.qml++ qml/button/KisGroupButton.qml+ qml/button/KisOptionButtonStrip.qml++ qml/overlays/KisWarningOverlay.qml+ qml/overlays/KisSliderOverlay.qml+ qml/tooltip/KisToolTip.qml++ qml/textinput/KisTextInputWithSelectionRange.qml+ qml/textinput/KisTextInputWithPrefixAndSuffix.qml++ qml/spinbox/KisParseSpinBoxContentItem.qml+ qml/spinbox/KisIntParseSpinBox.qml+ qml/spinbox/KisDoubleSpinBox.qml+ qml/spinbox/KisDoubleParseSpinBox.qml+ qml/spinbox/KisParseSpinBoxUtil.js++ qml/sliderspinbox/KisSliderSpinBoxManipulator.qml+ qml/sliderspinbox/KisSliderSpinBoxRangeSwitch.qml+ qml/sliderspinbox/KisSliderSpinBoxContentItem.qml+ qml/sliderspinbox/KisIntSliderSpinBox.qml+ qml/sliderspinbox/KisDoubleSliderSpinBox.qml++ qml/curvewidget/KisCurveWidget.qml+ qml/angleselector/KisAngleGauge.qml+ qml/angleselector/KisAngleSelector.qml+ qml/angleselector/KisAngleSelectorUtil.js)target_link_libraries(kritaqmlcomponentsdiff --git a/qmlmodules/components/KisCubicCurveQMLWrapper.cpp b/qmlmodules/components/KisCubicCurveQMLWrapper.cppnew file mode 100644index 0000000000..e4d118a67d--- /dev/null+++ b/qmlmodules/components/KisCubicCurveQMLWrapper.cpp@@ -0,0 +1,87 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#include "KisCubicCurveQMLWrapper.h"++KisCubicCurveQml::KisCubicCurveQml(QObject *parent)+ : QObject(parent)+{}++const QList<QPointF>& KisCubicCurveQml::points() const+{+ return m_curve.points();+}++const QString& KisCubicCurveQml::name() const+{+ return m_curve.name();+}++qreal KisCubicCurveQml::value(qreal x) const+{+ return m_curve.value(x);+}++bool KisCubicCurveQml::isIdentity() const+{+ return m_curve.isIdentity();+}++bool KisCubicCurveQml::isConstant(qreal c) const+{+ return m_curve.isConstant(c);+}++qreal KisCubicCurveQml::interpolateLinear(qreal normalizedValue, const QList<qreal> &transfer) const+{+ return m_curve.interpolateLinear(normalizedValue, transfer.toVector());+}++QList<qreal> KisCubicCurveQml::floatTransfer(int size) const+{+ return m_curve.floatTransfer(size).toList();+}++QString KisCubicCurveQml::toString() const+{+ return m_curve.toString();+}++void KisCubicCurveQml::fromString(const QString &str)+{+ m_curve.fromString(str);+}+++void KisCubicCurveQml::setPoints(const QList<QPointF> &points)+{+ m_curve.setPoints(points);+ emit pointsChanged(m_curve.points());+}++void KisCubicCurveQml::setPoint(int idx, const QPointF &point)+{+ m_curve.setPoint(idx, point);+ emit pointsChanged(m_curve.points());+}++int KisCubicCurveQml::addPoint(const QPointF &point)+{+ const int idx = m_curve.addPoint(point);+ emit pointsChanged(m_curve.points());+ return idx;+}++void KisCubicCurveQml::removePoint(int idx)+{+ m_curve.removePoint(idx);+ emit pointsChanged(m_curve.points());+}++void KisCubicCurveQml::setName(const QString& name)+{+ m_curve.setName(name);+ emit nameChanged(name);+}diff --git a/qmlmodules/components/KisCubicCurveQMLWrapper.h b/qmlmodules/components/KisCubicCurveQMLWrapper.hnew file mode 100644index 0000000000..a52b996842--- /dev/null+++ b/qmlmodules/components/KisCubicCurveQMLWrapper.h@@ -0,0 +1,51 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#ifndef KISCUBICCURVEQML_H+#define KISCUBICCURVEQML_H++#include <QQmlEngine>+#include <QPointF>++#include <kis_cubic_curve.h>++class KisCubicCurveQml : public QObject+{+ Q_OBJECT+ QML_NAMED_ELEMENT(KisCubicCurve)++ Q_PROPERTY(QList<QPointF> points READ points WRITE setPoints NOTIFY pointsChanged)+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)++public:+ KisCubicCurveQml(QObject *parent = nullptr);++ const QList<QPointF>& points() const;+ const QString& name() const;++ Q_INVOKABLE qreal value(qreal x) const;+ Q_INVOKABLE bool isIdentity() const;+ Q_INVOKABLE bool isConstant(qreal c) const;+ Q_INVOKABLE qreal interpolateLinear(qreal normalizedValue, const QList<qreal> &transfer) const;+ Q_INVOKABLE QList<qreal> floatTransfer(int size) const;+ Q_INVOKABLE QString toString() const;+ Q_INVOKABLE void fromString(const QString&);++public Q_SLOTS:+ void setPoints(const QList<QPointF> &points);+ void setPoint(int idx, const QPointF &point);+ int addPoint(const QPointF &point);+ void removePoint(int idx);+ void setName(const QString& name);++Q_SIGNALS:+ void pointsChanged(const QList<QPointF>&);+ void nameChanged(const QString&);++private:+ KisCubicCurve m_curve;+};++#endifdiff --git a/qmlmodules/components/KisNumParser.cpp b/qmlmodules/components/KisNumParser.cppnew file mode 100644index 0000000000..7bdc26fd85--- /dev/null+++ b/qmlmodules/components/KisNumParser.cpp@@ -0,0 +1,16 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#include "KisNumParser.h"++double KisNumParser::parseSimpleMathExpr(QString const &expr)+{+ bool ok = false;+ const double ret = KisNumericParser::parseSimpleMathExpr(expr, &ok);+ if (!ok) {+ return qQNaN();+ }+ return ret;+}diff --git a/qmlmodules/components/KisNumParser.h b/qmlmodules/components/KisNumParser.hnew file mode 100644index 0000000000..28e938e0ed--- /dev/null+++ b/qmlmodules/components/KisNumParser.h@@ -0,0 +1,27 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#ifndef KISNUMPARSER_H+#define KISNUMPARSER_H++#include <QObject>+#include <QString>+#include <QQmlEngine>++#include <limits>++#include <kis_num_parser.h>++class KisNumParser : public QObject+{+ Q_OBJECT+ QML_ELEMENT++public:+ //! \brief parse an expression to a double.+ Q_INVOKABLE static double parseSimpleMathExpr(QString const &expr);+};++#endifdiff --git a/qmlmodules/components/KritaQmlComponentsPlugin.cpp b/qmlmodules/components/KritaQmlComponentsPlugin.cppindex 4de53c30c1..a4384dcdbd 100644--- a/qmlmodules/components/KritaQmlComponentsPlugin.cpp+++ b/qmlmodules/components/KritaQmlComponentsPlugin.cpp@@ -8,7 +8,10 @@#include <QObject>#include <KisStaticInitializer.h>+#include <SvgTextLabel.h>+#include <KisNumParser.h>+#include <KisCubicCurveQMLWrapper.h>#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)#error "This plugin implementation is to be used with Qt5 only!\n"@@ -33,6 +36,8 @@ void KritaQmlComponentsPlugin::initializeEngine(QQmlEngine *engine, const char *void KritaQmlComponentsPlugin::registerTypes(const char *uri){qmlRegisterType<SvgTextLabel>(uri, 1, 0, "SvgTextLabel");+ qmlRegisterType<KisNumParser>(uri, 1, 0, "KisNumParser");+ qmlRegisterType<KisCubicCurveQml>(uri, 1, 0, "KisCubicCurve");}#include "KritaQmlComponentsPlugin.moc"diff --git a/qmlmodules/components/qml/angleselector/KisAngleGauge.qml b/qmlmodules/components/qml/angleselector/KisAngleGauge.qmlnew file mode 100644index 0000000000..4ca67b492b--- /dev/null+++ b/qmlmodules/components/qml/angleselector/KisAngleGauge.qml@@ -0,0 +1,283 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQml 2.15+import QtQuick 2.15+import QtQuick.Controls 2.15+import QtQuick.Shapes 2.15++Control {+ id: root++ property real angle: 0.0+ property real snapAngle: 15.0+ property real defaultAngle: 0.0+ property bool increaseClockwise: false++ function reset()+ {+ angle = defaultAngle+ }++ function increment(up: bool, snap: bool)+ {+ if (up) {+ if (snap) {+ root.angle = Math.floor((root.angle + root.snapAngle) / root.snapAngle) * root.snapAngle;+ } else {+ root.angle += 1;+ }+ } else {+ if (snap) {+ root.angle = Math.ceil((root.angle - root.snapAngle) / root.snapAngle) * root.snapAngle;+ } else {+ root.angle -= 1;+ }+ }+ }++ implicitWidth: 40+ implicitHeight: implicitWidth+ focusPolicy: Qt.WheelFocus++ contentItem: Shape {+ id: gaugeShape++ property point center: Qt.point(width / 2.0, height / 2.0)+ property real minSide: Math.min(center.x, center.y)+ property real radius: minSide * 0.9+ property real lineMarkerRadius: minSide - radius+ property real angleInRadians: root.angle * Math.PI / 180.0+ property point anglePoint: Qt.point(center.x + Math.cos(angleInRadians) * radius,+ root.increaseClockwise ? center.y + Math.sin(angleInRadians) * radius+ : center.y - Math.sin(angleInRadians) * radius)+ property bool darkMode: root.palette.window.hslLightness < 0.5+ property color circleColor: darkMode ? root.palette.light : root.palette.dark+ property color axesColor: Qt.alpha(circleColor, 0.75);++ property point topPoint: Qt.point(Math.round(center.x), Math.ceil(center.y - radius))+ property point bottomPoint: Qt.point(Math.round(center.x), Math.floor(center.y + radius))+ property point leftPoint: Qt.point(Math.ceil(center.x - radius), Math.round(center.y))+ property point rightPoint: Qt.point(Math.floor(center.x + radius), Math.round(center.y))++ layer.enabled: true+ layer.smooth: true+ layer.textureSize: Qt.size(width * 2, height * 2)++ // Background+ ShapePath {+ id: backgroundShape+ property real radius: (gaugeShape.bottomPoint.y - gaugeShape.topPoint.y) / 2+ strokeColor: "transparent"+ fillColor: root.enabled+ ? gaugeShape.darkMode ? root.palette.dark : root.palette.light+ : root.palette.window+ startX: gaugeShape.topPoint.x+ startY: gaugeShape.topPoint.y+ PathArc {+ x: gaugeShape.bottomPoint.x+ y: gaugeShape.bottomPoint.y+ radiusX: backgroundShape.radius+ radiusY: backgroundShape.radius+ }+ PathArc {+ x: gaugeShape.topPoint.x+ y: gaugeShape.topPoint.y+ radiusX: backgroundShape.radius+ radiusY: backgroundShape.radius+ }+ }+ // Axes lines+ ShapePath {+ id: axesLinesShape+ strokeColor: gaugeShape.axesColor+ strokeStyle: ShapePath.DashLine+ capStyle: ShapePath.FlatCap+ dashPattern: [1, 1]+ fillColor: "transparent"+ startX: gaugeShape.topPoint.x+ startY: gaugeShape.topPoint.y + 2+ PathLine {+ x: gaugeShape.bottomPoint.x+ y: gaugeShape.bottomPoint.y - 2+ }+ PathMove {+ x: gaugeShape.leftPoint.x + 2+ y: gaugeShape.leftPoint.y+ }+ PathLine {+ x: gaugeShape.rightPoint.x - 2+ y: gaugeShape.rightPoint.y+ }+ }+ // Outer circle+ ShapePath {+ id: outerCircleShape+ strokeColor: root.activeFocus ? root.palette.highlight : gaugeShape.circleColor+ strokeWidth: root.activeFocus || (root.enabled && gaugeMouseArea.gaugeHovered) ? 2 : 1+ fillColor: "transparent"+ startX: gaugeShape.topPoint.x+ startY: gaugeShape.topPoint.y+ PathArc {+ x: gaugeShape.bottomPoint.x+ y: gaugeShape.bottomPoint.y+ radiusX: backgroundShape.radius+ radiusY: backgroundShape.radius+ }+ PathArc {+ x: gaugeShape.topPoint.x+ y: gaugeShape.topPoint.y+ radiusX: backgroundShape.radius+ radiusY: backgroundShape.radius+ }+ }+ // Angle line+ ShapePath {+ id: angleLineShape+ strokeColor: root.enabled+ ? (gaugeShape.darkMode ? Qt.rgba(1, 1, 1, 0.75) : Qt.rgba(0, 0, 0, 0.75))+ : (gaugeShape.darkMode ? root.palette.light : root.palette.dark)+ fillColor: "transparent"+ startX: gaugeShape.center.x+ startY: gaugeShape.center.y+ PathLine {+ x: gaugeShape.anglePoint.x+ y: gaugeShape.anglePoint.y+ }+ }+ // Angle line markers+ ShapePath {+ id: angleLineMarkersShape+ strokeColor: "transparent"+ fillColor: angleLineShape.strokeColor+ startX: gaugeShape.center.x+ startY: gaugeShape.center.y - gaugeShape.lineMarkerRadius+ PathArc {+ x: gaugeShape.center.x+ y: gaugeShape.center.y + gaugeShape.lineMarkerRadius+ radiusX: gaugeShape.lineMarkerRadius+ radiusY: gaugeShape.lineMarkerRadius+ }+ PathArc {+ x: angleLineMarkersShape.startX+ y: angleLineMarkersShape.startY+ radiusX: gaugeShape.lineMarkerRadius+ radiusY: gaugeShape.lineMarkerRadius+ }+ PathMove {+ x: gaugeShape.anglePoint.x+ y: gaugeShape.anglePoint.y - gaugeShape.lineMarkerRadius+ }+ PathArc {+ x: gaugeShape.anglePoint.x+ y: gaugeShape.anglePoint.y + gaugeShape.lineMarkerRadius+ radiusX: gaugeShape.lineMarkerRadius+ radiusY: gaugeShape.lineMarkerRadius+ }+ PathArc {+ x: gaugeShape.anglePoint.x+ y: gaugeShape.anglePoint.y - gaugeShape.lineMarkerRadius+ radiusX: gaugeShape.lineMarkerRadius+ radiusY: gaugeShape.lineMarkerRadius+ }+ }+ }++ MouseArea {+ id: gaugeMouseArea++ property bool gaugeHovered: false+ property real cumulatedTrackpadLength: 0.0++ function setAngleFromPoint(me, pressEvent: bool)+ {+ const radiusSquared = gaugeShape.minSide * gaugeShape.minSide;+ const deltaX = me.x - gaugeShape.center.x;+ const deltaY = me.y - gaugeShape.center.y;+ const distanceSquared = deltaX * deltaX + deltaY * deltaY;++ gaugeMouseArea.gaugeHovered = distanceSquared <= radiusSquared;+ if (pressEvent) {+ if (!gaugeMouseArea.gaugeHovered) {+ return;+ }+ if (root.focusPolicy & Qt.ClickFocus) {+ root.forceActiveFocus(Qt.MouseFocusReason);+ }+ } else {+ if (!gaugeMouseArea.pressed) {+ return;+ }+ }++ let a = Math.atan2(root.increaseClockwise ? deltaY : -deltaY, deltaX) * 180 / Math.PI;++ const minimumSnapDistance = 40;+ const snapDistance = Math.max(minimumSnapDistance * minimumSnapDistance, radiusSquared * 4);+ const controlPressed = me.modifiers & Qt.ControlModifier;+ const shiftPressed = me.modifiers & Qt.ShiftModifier;++ if (controlPressed && shiftPressed) {+ a = Math.round(a);+ } else if (!shiftPressed && (controlPressed || distanceSquared < snapDistance)) {+ a = Math.round(a / root.snapAngle) * root.snapAngle;+ }++ root.angle = a;+ }++ anchors.fill: parent+ hoverEnabled: true+ preventStealing: true++ onExited: gaugeMouseArea.gaugeHovered = false++ onPressed: (me) => {+ setAngleFromPoint(me, true);+ if (!gaugeMouseArea.gaugeHovered) {+ me.accepted = false;+ }+ }++ onPositionChanged: (me) => {+ setAngleFromPoint(me, false);+ }++ onDoubleClicked: root.reset()++ onWheel: (we) => {+ if (root.focusPolicy & Qt.WheelFocus) {+ root.forceActiveFocus(Qt.MouseFocusReason);+ }++ let inc = 0.0;+ if (we.pixelDelta && we.pixelDelta.y !== 0) {+ cumulatedTrackpadLength += we.pixelDelta.y;+ if (Math.abs(cumulatedTrackpadLength) > 30) {+ inc = cumulatedTrackpadLength;+ cumulatedTrackpadLength = 0.0;+ }+ } else {+ inc = we.angleDelta.y;+ }++ if (inc === 0) {+ return;+ }++ inc *= we.inverted ? -1 : 1;+ increment(inc > 0, we.modifiers & Qt.ControlModifier);+ }+ }++ Keys.onPressed: (ke) => {+ if (ke.key !== Qt.Key_Up && ke.key !== Qt.Key_Right &&+ ke.key !== Qt.Key_Down && ke.key !== Qt.Key_Left) {+ return;+ }+ increment(ke.key === Qt.Key_Up || ke.key === Qt.Key_Right,+ ke.modifiers & Qt.ControlModifier);+ }+}diff --git a/qmlmodules/components/qml/angleselector/KisAngleSelector.qml b/qmlmodules/components/qml/angleselector/KisAngleSelector.qmlnew file mode 100644index 0000000000..8ee606f55e--- /dev/null+++ b/qmlmodules/components/qml/angleselector/KisAngleSelector.qml@@ -0,0 +1,212 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15+import QtQuick.Controls 2.15+import org.krita.components 1.0+import "KisAngleSelectorUtil.js" as KisAngleSelectorUtil++FocusScope {+ id: root++ enum FlipOptionsMode+ {+ NoFlipOptions,+ MenuButton,+ Buttons,+ ContextMenu+ }++ property alias angle: spinBox.dValue+ property alias decimals: spinBox.decimals+ property alias from: spinBox.dFrom+ property alias to: spinBox.dTo+ property alias prefix: spinBox.prefix+ property alias suffix: spinBox.suffix+ property alias wrap: spinBox.wrap+ property alias snapAngle: angleGauge.snapAngle+ property alias defaultAngle: angleGauge.defaultAngle+ property alias increaseClockwise: angleGauge.increaseClockwise++ property int flipOptionsMode: KisAngleSelector.FlipOptionsMode.Buttons+ property int gaugeSize: 0+ property bool flatSpinBox: false++ function reset()+ {+ angleGauge.reset();+ }++ function closestCoterminalAngleInRange(angle: real) : real+ {+ return KisAngleSelectorUtil.closestCoterminalAngleInRange(angle, root.from, root.to);+ }++ function flip(horizontal: bool, vertical: bool)+ {+ let ok = true;+ let flippedAngle = KisAngleSelectorUtil.flipAngleInRange(root.angle, root.from, root.to, horizontal, vertical,+ () => { ok = false; });+ if (ok) {+ root.angle = flippedAngle;+ }+ }++ implicitWidth: row.implicitWidth+ implicitHeight: row.implicitHeight++ Action {+ id: actionFlipHorizontally+ //: Flips the angle horizontally, around the vertical axis+ text: qsTr("Flip the angle horizontally")+ icon.source: "qrc:///light_flip_angle_h.svg"+ icon.width: 20+ icon.height: 20+ onTriggered: root.flip(true, false)+ }++ Action {+ id: actionFlipVertically+ //: Flips the angle vertically, around the horizontal axis+ text: qsTr("Flip the angle vertically")+ icon.source: "qrc:///light_flip_angle_v.svg"+ icon.width: 20+ icon.height: 20+ onTriggered: root.flip(false, true)+ }++ Action {+ id: actionFlipHorizontallyAndVertically+ //: Flips the angle horizontally and vertically+ text: qsTr("Flip the angle horizontally and vertically")+ icon.source: "qrc:///light_flip_angle_hv.svg"+ icon.width: 20+ icon.height: 20+ onTriggered: root.flip(true, true)+ }++ Action {+ id: actionResetAngle+ //: Resets the angle+ text: qsTr("Reset Angle")+ onTriggered: root.reset()+ }++ Menu {+ id: menu+ property Item separator: MenuSeparator {}+ contentData: [+ actionFlipHorizontally,+ actionFlipVertically,+ actionFlipHorizontallyAndVertically,+ separator,+ actionResetAngle+ ]+ }++ Row {+ id: row++ spacing: 5+ anchors.fill: parent++ KisAngleGauge {+ id: angleGauge++ anchors.verticalCenter: parent.verticalCenter+ implicitWidth: root.gaugeSize > 0 ? root.gaugeSize : spinBox.implicitHeight+ implicitHeight: implicitWidth++ onAngleChanged: spinBox.dValue = root.closestCoterminalAngleInRange(angle)++ MouseArea {+ anchors.fill: parent+ acceptedButtons: Qt.RightButton+ onClicked: {+ if (root.flipOptionsMode === KisAngleSelector.FlipOptionsMode.ContextMenu) {+ menu.popup();+ }+ }+ }+ }++ KisDoubleParseSpinBox {+ id: spinBox++ anchors.verticalCenter: parent.verticalCenter+ wrap: true+ dFrom: 0+ dTo: 360+ hoverEnabled: true+ suffix: "º"+++ onValueChanged: angleGauge.angle = dValue++ Component.onCompleted: {+ spinBox.background.visible = Qt.binding(() => { return !root.flatSpinBox || spinBox.hovered; });+ spinBox.up.indicator.visible = Qt.binding(() => { return spinBox.background.visible });+ spinBox.down.indicator.visible = Qt.binding(() => { return spinBox.background.visible });+ }+ }++ Row {+ id: buttonsContainer++ anchors.verticalCenter: parent.verticalCenter+ spacing: 0++ ToolButton {+ id: buttonMenu+ visible: root.flipOptionsMode === KisAngleSelector.FlipOptionsMode.MenuButton+ padding: 4+ display: AbstractButton.IconOnly+ icon.source: "qrc:/krita/qml/Krita/Resources/images/view-choose.svg"+ icon.width: 16+ icon.height: 16+ onClicked: {+ menu.popup(buttonMenu, 0, buttonMenu.height);+ menu.forceActiveFocus();+ }+ }++ ToolButton {+ id: buttonFlipHorizontally+ visible: root.flipOptionsMode === KisAngleSelector.FlipOptionsMode.Buttons+ padding: 4+ display: AbstractButton.IconOnly+ action: actionFlipHorizontally+ KisToolTip {+ parentControl: buttonFlipHorizontally+ text: actionFlipHorizontally.text+ }+ }++ ToolButton {+ id: buttonFlipVertically+ visible: root.flipOptionsMode === KisAngleSelector.FlipOptionsMode.Buttons+ padding: 4+ display: AbstractButton.IconOnly+ action: actionFlipVertically+ KisToolTip {+ parentControl: buttonFlipVertically+ text: actionFlipVertically.text+ }+ }++ ToolButton {+ id: buttonFlipHorizontallyAndVertically+ visible: root.flipOptionsMode === KisAngleSelector.FlipOptionsMode.Buttons+ padding: 4+ display: AbstractButton.IconOnly+ action: actionFlipHorizontallyAndVertically+ KisToolTip {+ parentControl: buttonFlipHorizontallyAndVertically+ text: actionFlipHorizontallyAndVertically.text+ }+ }+ }+ }+}diff --git a/qmlmodules/components/qml/angleselector/KisAngleSelectorUtil.js b/qmlmodules/components/qml/angleselector/KisAngleSelectorUtil.jsnew file mode 100644index 0000000000..c07b7e2b52--- /dev/null+++ b/qmlmodules/components/qml/angleselector/KisAngleSelectorUtil.js@@ -0,0 +1,74 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+function closestCoterminalAngleInRange(angle, from, to, errorCallback)+{+ let hasCoterminalAngleInRange = true;++ if (angle < from) {+ const d = from - angle;+ const cycles = Math.floor(d / 360) + 1;+ angle += cycles * 360;+ if (angle > to) {+ hasCoterminalAngleInRange = false;+ angle = from;+ }+ } else if (angle > to) {+ const d = angle - to;+ const cycles = Math.floor(d / 360) + 1;+ angle -= cycles * 360;+ if (angle < from) {+ hasCoterminalAngleInRange = false;+ angle = to;+ }+ }++ if (!hasCoterminalAngleInRange && errorCallback) {+ errorCallback();+ }+ return angle;+}++function flipAngle(angle, horizontal, vertical)+{+ if (horizontal && vertical) {+ angle += 180;+ } else if (horizontal) {+ let a = angle % 360;+ if (a < 0) {+ a += 360;+ }+ if (a > 270) {+ angle -= 2 * (a - 270);+ } else if (a > 180) {+ angle += 2 * (270 - a);+ } else if (a > 90) {+ angle -= 2 * (a - 90);+ } else {+ angle += 2 * (90 - a);+ }+ } else if (vertical) {+ let a = angle % 360;+ if (a < 0) {+ a += 360;+ }+ if (a > 270) {+ angle += 2 * (360 - a);+ } else if (a > 180) {+ angle -= 2 * (a - 180);+ } else if (a > 90) {+ angle += 2 * (180 - a);+ } else {+ angle -= 2 * a;+ }+ }++ return angle;+}++function flipAngleInRange(angle, from, to, horizontal, vertical, errorCallback)+{+ return closestCoterminalAngleInRange(flipAngle(angle, horizontal, vertical), from, to, errorCallback);+}diff --git a/qmlmodules/components/qml/button/KisGroupButton.qml b/qmlmodules/components/qml/button/KisGroupButton.qmlnew file mode 100644index 0000000000..2750e31b3c--- /dev/null+++ b/qmlmodules/components/qml/button/KisGroupButton.qml@@ -0,0 +1,69 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15+import QtQuick.Controls 2.15++Button {+ id: root++ enum GroupPosition {+ NoGroup,+ GroupLeft,+ GroupRight,+ GroupCenter+ }++ property int groupPosition: KisGroupButton.GroupPosition.NoGroup+ property color normalButtonColor+ property color normalButtonTextColor++ function fixPalette()+ {+ if (root.checked) {+ root.palette.active.button = root.palette.active.highlight;+ root.palette.active.buttonText = root.palette.active.highlightedText;+ } else {+ root.palette.active.button = normalButtonColor;+ root.palette.active.buttonText = normalButtonTextColor;+ }+ root.palette.inactive.button = Qt.darker(root.palette.active.button, 1.1);+ root.palette.inactive.buttonText = Qt.darker(root.palette.active.buttonText, 1.1);+ root.palette.disabled.button = Qt.alpha(root.palette.active.button, 0.5);+ root.palette.disabled.buttonText = Qt.alpha(root.palette.active.buttonText, 0.5);+ }++ function updatePalette()+ {+ root.normalButtonColor = root.palette.active.button+ root.normalButtonTextColor = root.palette.active.buttonText+ fixPalette();+ }++ text: "Button"+ clip: true+ padding: 8+ implicitWidth: implicitContentWidth + (root.leftPadding ?? root.padding)+ + (root.rightPadding ?? root.padding)+ leftInset: (groupPosition === KisGroupButton.GroupPosition.GroupRight ||+ groupPosition === KisGroupButton.GroupPosition.GroupCenter) * -50+ rightInset: (groupPosition === KisGroupButton.GroupPosition.GroupLeft ||+ groupPosition === KisGroupButton.GroupPosition.GroupCenter) * -50++ Component.onCompleted: {+ updatePalette();+ root.checkedChanged.connect(() => { root.fixPalette(); });+ KisUI.paletteChanged.connect(updatePalette);+ }++ Rectangle {+ width: 1+ height: root.background.height+ anchors.right: parent.right+ color: Qt.alpha(root.palette.buttonText, 0.1)+ visible: root.groupPosition === KisGroupButton.GroupPosition.GroupLeft ||+ root.groupPosition === KisGroupButton.GroupPosition.GroupCenter+ }+}diff --git a/qmlmodules/components/qml/button/KisOptionButtonStrip.qml b/qmlmodules/components/qml/button/KisOptionButtonStrip.qmlnew file mode 100644index 0000000000..4213d75f6d--- /dev/null+++ b/qmlmodules/components/qml/button/KisOptionButtonStrip.qml@@ -0,0 +1,71 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15+import QtQuick.Controls 2.15++Row {+ id: root++ property alias exclusive: buttonGroup.exclusive+ readonly property KisGroupButton checkedButton: buttonGroup.checkedButton as KisGroupButton+ property int checkedButtonIndex: -1++ function updateCheckedStatusFromIndex()+ {+ if (!root.exclusive) {+ return;+ }++ if (root.checkedButtonIndex === -1) {+ for (let i = 0; i < root.children.length; ++i) {+ if (root.children[i] instanceof KisGroupButton) {+ (root.children[i] as KisGroupButton).checked = false;+ }+ }+ return;+ }++ let buttonIndex = -1;+ for (let i = 0; i < root.children.length; ++i) {+ if (root.children[i] instanceof KisGroupButton) {+ ++buttonIndex;+ if (buttonIndex === root.checkedButtonIndex) {+ (root.children[i] as KisGroupButton).checked = true;+ }+ }+ }+ }++ function buttonIndexFromCheckedButton() : int+ {+ if (!root.exclusive) {+ return -1;+ }+ let buttonIndex = -1;+ for (let i = 0; i < root.children.length; ++i) {+ if (root.children[i] instanceof KisGroupButton) {+ ++buttonIndex;+ if (root.children[i].checked) {+ return buttonIndex;+ }+ }+ }+ return -1;+ }++ Component.onCompleted: {+ updateCheckedStatusFromIndex();+ root.exclusiveChanged.connect(() => { root.checkedButtonIndex = root.buttonIndexFromCheckedButton(); });+ root.checkedButtonChanged.connect(() => { root.checkedButtonIndex = buttonIndexFromCheckedButton(); });+ root.checkedButtonIndexChanged.connect(() => { root.updateCheckedStatusFromIndex(); });+ }++ ButtonGroup {+ id: buttonGroup+ buttons: root.children+ exclusive: true+ }+}diff --git a/qmlmodules/components/qml/curvewidget/KisCurveWidget.qml b/qmlmodules/components/qml/curvewidget/KisCurveWidget.qmlnew file mode 100644index 0000000000..441d77099a--- /dev/null+++ b/qmlmodules/components/qml/curvewidget/KisCurveWidget.qml@@ -0,0 +1,382 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15+import QtQuick.Controls 2.15+import QtQuick.Shapes 2.15+import org.krita.components 1.0++Control {+ id: root++ property KisCubicCurve curve: KisCubicCurve {}+ property int selectedKnotIndex: 0+ property bool readOnly: false++ padding: 1+ focusPolicy: Qt.StrongFocus++ onPaletteChanged: contentItem.requestPaint()+ onActiveFocusChanged: contentItem.requestPaint()++ background: Rectangle {+ id: backgroundItem++ readonly property real topPadding: root.topPadding ? root.topPadding : root.padding+ readonly property real bottomPadding: root.bottomPadding ? root.bottomPadding : root.padding+ readonly property real leftPadding: root.leftPadding ? root.leftPadding : root.padding+ readonly property real rightPadding: root.rightPadding ? root.rightPadding : root.padding+ readonly property real lineWidth: root.width - leftPadding - rightPadding+ readonly property real lineHeight: root.height - topPadding - bottomPadding++ color: root.palette.window+ border.color: root.activeFocus ? root.palette.highlight : root.palette.text++ Rectangle {+ anchors.fill: parent+ anchors.topMargin: backgroundItem.topPadding+ anchors.leftMargin: backgroundItem.leftPadding+ anchors.bottomMargin: backgroundItem.bottomPadding+ anchors.rightMargin: backgroundItem.rightPadding+ color: root.palette.base+ }++ Repeater {+ model: 3+ delegate: Rectangle {+ color: root.palette.window;+ width: 1+ height: backgroundItem.lineHeight+ x: backgroundItem.lineWidth * (index + 1) / 4 + backgroundItem.leftPadding+ y: backgroundItem.topPadding+ }+ }++ Repeater {+ model: 3+ delegate: Rectangle {+ color: root.palette.window;+ width: backgroundItem.lineWidth+ height: 1+ x: backgroundItem.leftPadding+ y: backgroundItem.lineHeight * (index + 1) / 4 + backgroundItem.topPadding+ }+ }+ }++ contentItem: Canvas {+ id: contentItem++ property list<point> points++ function updatePoints(pts) {+ const width = contentItem.width;+ const height = contentItem.height;+ const pointYs = root.curve.floatTransfer(width);+ if (pointYs.length === 0) {+ return [];+ }+ let points = [Qt.point(0.5, (height - 1) - pointYs[0] * (height - 1) + 0.5)];+ let lastAngle = 0;+ for (let i = 1; i < pointYs.length; i++) {+ let x = i + 0.5;+ let y = (height - 1) - pointYs[i] * (height - 1) + 0.5;+ if (i === 1) {+ points.push(Qt.point(x, y));+ } else {+ const angle = Math.atan(y - points[points.length - 1].y);+ if (Math.abs(angle - lastAngle) > 0.01) {+ points.push(Qt.point(x, y));+ } else {+ points[points.length - 1] = Qt.point(x, y);+ }+ }+ lastAngle = Math.atan2(y - points[points.length - 2].y, x - points[points.length - 2].x);+ }+ contentItem.points = points;+ }++ implicitWidth: 256+ implicitHeight: 256++ onPointsChanged: contentItem.requestPaint()++ onPaint: {+ if (!contentItem.points || contentItem.points.length === 0) {+ return;+ }+ var ctx = getContext("2d");++ ctx.clearRect(0, 0, contentItem.width, contentItem.height);+ // Paint the curve+ ctx.fillStyle = Qt.alpha(root.palette.text, 0.2);+ ctx.strokeStyle = root.palette.text;+ ctx.lineWidth = 2;+ ctx.beginPath();+ ctx.moveTo(0, 0);+ ctx.moveTo(contentItem.width + 10, contentItem.height + 10);+ ctx.lineTo(-10, contentItem.height + 10);+ ctx.lineTo(-10, contentItem.points[0].y);+ for (let i = 0; i < contentItem.points.length; ++i) {+ ctx.lineTo(contentItem.points[i].x, contentItem.points[i].y);+ }+ ctx.lineTo(contentItem.width + 10, contentItem.points[contentItem.points.length - 1].y);+ ctx.closePath();+ ctx.fill();+ ctx.stroke();+ // Paint non selected knots+ ctx.beginPath();+ ctx.fillStyle = Qt.alpha(root.palette.base, 0.3);+ for (let i = 0; i < root.curve.points.length; ++i) {+ if (i === root.selectedKnotIndex && root.activeFocus) {+ continue;+ }+ const p = root.curve.points[i];+ ctx.ellipse(p.x * contentItem.width - 6, contentItem.height - p.y * contentItem.height - 6, 12, 12);+ }+ ctx.fill();+ ctx.stroke();+ // Paint the selected knot+ if (root.activeFocus) {+ ctx.beginPath();+ ctx.fillStyle = Qt.alpha(root.palette.highlight, 0.8);+ ctx.strokeStyle = Qt.tint(root.palette.text, Qt.alpha(root.palette.highlight, 0.2));+ const p = root.curve.points[root.selectedKnotIndex];+ ctx.ellipse(p.x * contentItem.width - 6, contentItem.height - p.y * contentItem.height - 6, 12, 12);+ ctx.fill();+ ctx.stroke();+ }+ }++ Component.onCompleted: contentItem.updatePoints()++ MouseArea {+ id: mouseArea++ property bool isDragging: false+ property int draggedAwayKnotIndex: -1+ property point draggedAwayKnot+ property point grabbedKnotOriginalPosition+ property point grabbedKnotOffset++ anchors.fill: parent+ hoverEnabled: true+ preventStealing: true++ function closestKnotIndex(x: real, y: real) : int+ {+ let closestKnot = -1;+ let nearestDistanceSquared = 144;++ for (let i = 0; i < root.curve.points.length; ++i) {+ const delta = Qt.point(x - root.curve.points[i].x * (mouseArea.width - 1),+ (mouseArea.height - 1 - y) - root.curve.points[i].y * (mouseArea.height - 1));+ const distanceSquared = delta.x * delta.x + delta.y * delta.y;+ if (distanceSquared < nearestDistanceSquared) {+ closestKnot = i;+ nearestDistanceSquared = distanceSquared;+ }+ }++ return closestKnot;+ }++ onPressed: (me) => {+ if (root.readOnly) {+ return;+ }++ root.forceActiveFocus();++ const closestKnot = mouseArea.closestKnotIndex(me.x, me.y);++ if (closestKnot === -1) {+ root.selectedKnotIndex = root.curve.addPoint(Qt.point(me.x / (mouseArea.width - 1),+ 1 - me.y / (mouseArea.height - 1)));+ } else {+ root.selectedKnotIndex = closestKnot;+ }++ mouseArea.grabbedKnotOriginalPosition = root.curve.points[root.selectedKnotIndex];+ mouseArea.grabbedKnotOffset = Qt.point(me.x - mouseArea.grabbedKnotOriginalPosition.x+ * (mouseArea.width - 1),+ me.y - ((mouseArea.height - 1)+ - mouseArea.grabbedKnotOriginalPosition.y+ * (mouseArea.height - 1)));++ mouseArea.draggedAwayKnotIndex = -1;+ mouseArea.cursorShape = Qt.CrossCursor;+ mouseArea.isDragging = true;+ }++ onReleased: mouseArea.isDragging = false++ onPositionChanged: (me) => {+ if (root.readOnly) {+ return;+ }++ if (!mouseArea.isDragging) {+ const closestKnot = mouseArea.closestKnotIndex(me.x, me.y);+ if (closestKnot < 0) {+ mouseArea.cursorShape = Qt.ArrowCursor;+ } else {+ mouseArea.cursorShape = Qt.CrossCursor;+ }+ } else {+ const crossedHoriz = me.x - mouseArea.width > 15 || me.x < -15;+ const crossedVert = me.y - mouseArea.height > 15 || me.y < -15;++ const removePoint = (crossedHoriz || crossedVert);++ if (removePoint) {+ if (mouseArea.draggedAwayKnotIndex === -1 && root.curve.points.length > 2) {+ mouseArea.draggedAwayKnot = root.curve.points[root.selectedKnotIndex];+ mouseArea.draggedAwayKnotIndex = root.selectedKnotIndex;+ root.curve.removePoint(root.selectedKnotIndex);+ if (root.selectedKnotIndex === root.curve.points.length) {+ root.selectedKnotIndex = root.curve.points.length - 1;+ }+ }+ return;+ } else {+ if (mouseArea.draggedAwayKnotIndex !== -1) {+ root.curve.addPoint(mouseArea.draggedAwayKnot);+ root.selectedKnotIndex = mouseArea.draggedAwayKnotIndex;+ mouseArea.draggedAwayKnotIndex = -1;+ }+ }++ let x = (me.x - mouseArea.grabbedKnotOffset.x) / (mouseArea.width - 1);+ let y = 1.0 - (me.y - mouseArea.grabbedKnotOffset.y) / (mouseArea.height - 1);++ let leftX;+ let rightX;+ if (root.selectedKnotIndex === 0) {+ leftX = 0.0;+ if (root.curve.points.length > 1) {+ rightX = root.curve.points[root.selectedKnotIndex + 1].x - 0.0001;+ } else {+ rightX = 1.0;+ }+ } else if (root.selectedKnotIndex === root.curve.points.length - 1) {+ leftX = root.curve.points[root.selectedKnotIndex - 1].x + 0.0001;+ rightX = 1.0;+ } else {+ leftX = root.curve.points[root.selectedKnotIndex - 1].x + 0.0001;+ rightX = root.curve.points[root.selectedKnotIndex + 1].x - 0.0001;+ }++ x = Math.max(leftX, Math.min(x, rightX));+ y = Math.max(0, Math.min(y, 1));++ root.curve.setPoint(root.selectedKnotIndex, Qt.point(x, y));+ }+ }+ }+ }++ Keys.onPressed: (ke) => {+ if (ke.key == Qt.Key_Right) {+ if (ke.modifiers & Qt.ControlModifier) {+ if (root.selectedKnotIndex < root.curve.points.length - 1) {+ root.selectedKnotIndex++;+ }+ } else {+ let newPoint = root.curve.points[root.selectedKnotIndex];+ const maxX = root.selectedKnotIndex < root.curve.points.length - 1+ ? root.curve.points[root.selectedKnotIndex + 1].x - 0.0001+ : 1.0;+ if (maxX > newPoint.x) {+ const inc = ke.modifiers & Qt.ShiftModifier ? 0.001 : 0.01;+ newPoint.x = Math.min(newPoint.x + inc, maxX);+ root.curve.setPoint(root.selectedKnotIndex, newPoint);+ }+ }+ ke.accepted = true;++ } else if (ke.key == Qt.Key_Left) {+ if (ke.modifiers & Qt.ControlModifier) {+ if (root.selectedKnotIndex > 0) {+ root.selectedKnotIndex--;+ }+ } else {+ let newPoint = root.curve.points[root.selectedKnotIndex];+ const minX = root.selectedKnotIndex > 0+ ? root.curve.points[root.selectedKnotIndex - 1].x + 0.0001+ : 0.0;+ if (minX < newPoint.x) {+ const inc = ke.modifiers & Qt.ShiftModifier ? 0.001 : 0.01;+ newPoint.x = Math.max(newPoint.x - inc, minX);+ root.curve.setPoint(root.selectedKnotIndex, newPoint);+ }+ }+ ke.accepted = true;++ } else if (ke.key == Qt.Key_Up) {+ let newPoint = root.curve.points[root.selectedKnotIndex];+ if (newPoint.y < 1.0) {+ const inc = ke.modifiers & Qt.ShiftModifier ? 0.001 : 0.01;+ newPoint.y = Math.min(newPoint.y + inc, 1.0);+ root.curve.setPoint(root.selectedKnotIndex, newPoint);+ }+ ke.accepted = true;++ } else if (ke.key == Qt.Key_Down) {+ let newPoint = root.curve.points[root.selectedKnotIndex];+ if (newPoint.y > 0.0) {+ const inc = ke.modifiers & Qt.ShiftModifier ? 0.001 : 0.01;+ newPoint.y = Math.max(newPoint.y - inc, 0.0);+ root.curve.setPoint(root.selectedKnotIndex, newPoint);+ }+ ke.accepted = true;++ } else if (ke.key == Qt.Key_Delete || ke.key == Qt.Key_Backspace) {+ if (root.selectedKnotIndex > 0 && root.selectedKnotIndex < root.curve.points.length - 1) {+ const previouslySelectedKnotX = root.curve.points[root.selectedKnotIndex].x;++ root.curve.removePoint(root.selectedKnotIndex);+ if (Math.abs(root.curve.points[root.selectedKnotIndex].x - previouslySelectedKnotX) >+ Math.abs(root.curve.points[root.selectedKnotIndex - 1].x - previouslySelectedKnotX)) {+ root.selectedKnotIndex--;+ }+ mouseArea.cursorShape = Qt.ArrowCursor;+ mouseArea.isDragging = false;+ }+ ke.accepted = true;++ } else if (ke.key == Qt.Key_Escape && mouseArea.isDragging) {+ if (mouseArea.draggedAwayKnotIndex !== -1) {+ root.curve.addPoint(mouseArea.draggedAwayKnot);+ root.selectedKnotIndex = mouseArea.draggedAwayKnotIndex;+ mouseArea.draggedAwayKnotIndex = -1;+ }+ root.curve.setPoint(root.selectedKnotIndex, mouseArea.grabbedKnotOriginalPosition);+ mouseArea.cursorShape = Qt.ArrowCursor;+ mouseArea.isDragging = false;+ ke.accepted = true;++ } else if ((ke.key == Qt.Key_A || ke.key == Qt.Key_Insert) && !mouseArea.isDragging) {+ const selectedKnotX = root.curve.points[root.selectedKnotIndex].x;+ const neighborKnotX = root.selectedKnotIndex === root.curve.points.length - 1+ ? root.curve.points[root.selectedKnotIndex - 1].x+ : root.curve.points[root.selectedKnotIndex + 1].x;+ if (Math.abs(selectedKnotX - neighborKnotX) <= 0.0002) {+ return;+ }+ const centerPointX = (selectedKnotX + neighborKnotX) / 2;+ const centerPointY = root.curve.value(centerPointX);+ root.selectedKnotIndex = root.curve.addPoint(Qt.point(centerPointX, centerPointY));+ ke.accepted = true;+ }+ }++ Connections {+ target: root.curve+ function onPointsChanged(pts) {+ contentItem.updatePoints();+ }+ }+}diff --git a/qmlmodules/components/qml/overlays/KisSliderOverlay.qml b/qmlmodules/components/qml/overlays/KisSliderOverlay.qmlnew file mode 100644index 0000000000..d97f30a277--- /dev/null+++ b/qmlmodules/components/qml/overlays/KisSliderOverlay.qml@@ -0,0 +1,118 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15++Item {+ id: root++ property bool showTopBar: false+ property bool topBarActive: false+ property real radius: 0.0+ property color color: "blue"+ property real topBarWidth: 0.0+ property real bottomBarWidth: 0.0+ property bool faded: false+ property real exponentRatio: 1.0++ states: [+ State {+ name: "faded"+ when: root.faded++ PropertyChanges {+ target: root;+ opacity: 0.5+ }+ }+ ]++ transitions: [+ Transition {+ from: "*"+ to: "*"++ PropertyAnimation {+ target: root+ property: "opacity"+ duration: 200+ }+ }+ ]++ Item {+ anchors.fill: parent++ states: [+ State {+ name: "topBarShown"+ when: root.showTopBar && !root.topBarActive++ PropertyChanges {+ target: bottomBarContainer;+ height: root.height - 3+ }+ },+ State {+ name: "topBarShownAndActive"+ when: root.showTopBar && root.topBarActive++ PropertyChanges {+ target: bottomBarContainer;+ height: 3+ }+ }+ ]++ transitions: [+ Transition {+ from: "*"+ to: "*"+ PropertyAnimation {+ target: bottomBarContainer+ property: "height"+ duration: 150+ }+ }+ ]++ Item {+ id: topBarContainer+ anchors.top: parent.top+ anchors.left: parent.left+ anchors.bottom: bottomBarContainer.top+ width: Math.max(0, Math.min(1, Math.pow(root.topBarWidth, 1 / root.exponentRatio))) * root.width+ clip: true++ Rectangle {+ id: topBar+ width: topBarContainer.width + root.radius+ height: Math.max(root.radius * 2, topBarContainer.height + root.radius)+ opacity: 0.75+ color: root.color+ radius: root.radius+ }+ }++ Item {+ id: bottomBarContainer+ anchors.left: parent.left+ anchors.bottom: parent.bottom+ width: Math.max(0, Math.min(1, Math.pow(root.bottomBarWidth, 1 / root.exponentRatio))) * root.width+ height: root.height+ clip: true++ Rectangle {+ id: bottomBar+ anchors.left: parent.left+ anchors.bottom: parent.bottom+ width: bottomBarContainer.width + root.radius+ height: root.showTopBar ? Math.max(root.radius * 2, bottomBarContainer.height + root.radius) : bottomBarContainer.height+ color: root.color+ radius: root.radius+ }+ }+ }+}diff --git a/qmlmodules/components/qml/overlays/KisWarningOverlay.qml b/qmlmodules/components/qml/overlays/KisWarningOverlay.qmlnew file mode 100644index 0000000000..58c58825d0--- /dev/null+++ b/qmlmodules/components/qml/overlays/KisWarningOverlay.qml@@ -0,0 +1,138 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15++Item {+ id: root++ property bool warn: false+ property int warningSignAlignment: Qt.AlignLeft+ property bool showWarningSign: true+ property alias radius: background.radius++ states: [+ State {+ name: "warning"+ when: root.warn && !root.showWarningSign++ PropertyChanges {+ target: background;+ opacity: 0.6+ }+ PropertyChanges {+ target:warningSign+ opacity: 0+ x: root.warningSignAlignment == Qt.AlignLeft ? -24 : root.width+ }+ },+ State {+ name: "warningWithSign"+ when: root.warn && root.showWarningSign++ PropertyChanges {+ target: background;+ opacity: 0.6+ }++ PropertyChanges {+ target:warningSign+ opacity: 1+ x: root.warningSignAlignment == Qt.AlignLeft ? 0 : root.width - 24+ }+ }+ ]++ transitions: [+ Transition {+ from: ""+ to: "warning"+ PropertyAnimation {+ target: background+ property: "opacity"+ duration: 250+ }+ },+ Transition {+ from: ""+ to: "warningWithSign"+ ParallelAnimation {+ PropertyAnimation {+ target: background+ property: "opacity"+ duration: 250+ }+ PropertyAnimation {+ target: warningSign+ properties: "opacity, x"+ duration: 250+ }+ }+ },+ Transition {+ from: "warning"+ to: ""+ PropertyAnimation {+ target: background+ property: "opacity"+ duration: 250+ }+ },+ Transition {+ from: "warning"+ to: "warningWithSign"+ PropertyAnimation {+ target: warningSign+ properties: "opacity, x"+ duration: 250+ }+ },+ Transition {+ from: "warningWithSign"+ to: ""+ PropertyAnimation {+ target: background+ property: "opacity"+ duration: 250+ }+ PropertyAnimation {+ target: warningSign+ properties: "opacity, x"+ duration: 250+ }+ },+ Transition {+ from: "warningWithSign"+ to: "warning"+ PropertyAnimation {+ target: warningSign+ properties: "opacity, x"+ duration: 250+ }+ }+ ]++ Rectangle {+ id: background+ anchors.fill: parent+ color: Qt.rgba(1, 0.2, 0, 1)+ opacity: 0+ }++ Item {+ id: warningSign+ x: root.warningSignAlignment == Qt.AlignLeft ? -24 : root.width+ anchors.verticalCenter: parent.verticalCenter+ width: 24+ height: 24+ opacity: 0++ Image {+ anchors.fill: parent+ anchors.margins: 4+ source: "qrc:///16_light_warning.svg"+ }+ }+}diff --git a/qmlmodules/components/qml/sliderspinbox/KisDoubleSliderSpinBox.qml b/qmlmodules/components/qml/sliderspinbox/KisDoubleSliderSpinBox.qmlnew file mode 100644index 0000000000..d3742adf23--- /dev/null+++ b/qmlmodules/components/qml/sliderspinbox/KisDoubleSliderSpinBox.qml@@ -0,0 +1,71 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15+import org.krita.components 1.0++KisDoubleSpinBox {+ id: root++ property alias prefix: contentId.prefix+ property alias suffix: contentId.suffix+ property real softDFrom: from+ property real softDTo: from+ property bool softRangeActive: false+ property alias blockUpdateSignalOnDrag: contentId.blockUpdateSignalOnDrag+ property alias exponentRatio: contentId.exponentRatio+ property alias fastSliderStep: contentId.fastSliderStep+ readonly property alias dragging : contentId.dragging++ function fixSoftRange() {+ if (root.softDFrom < root.dFrom) {+ root.softDFrom = root.dFrom;+ } else if (root.softDFrom > root.softDTo) {+ root.softDFrom = root.softDTo;+ }+ if (root.softDTo < root.softDFrom) {+ root.softDTo = root.softDFrom;+ } else if (root.softDTo > root.dTo) {+ root.softDTo = root.dTo;+ }+ contentId.showSoftRange = root.softDFrom !== root.softDTo;+ }++ editable: false+ padding: 0+ focusPolicy: Qt.WheelFocus+ implicitWidth: contentId.implicitWidth + 1 + 2 + leftPadding + rightPadding++ contentItem: FocusScope {+ focus: true++ KisSliderSpinBoxContentItem {+ id: contentId++ anchors.fill: parent+ anchors.margins: 1+ anchors.rightMargin: 2+ focus: true++ decimals: root.decimals+ from: root.dFrom+ to: root.dTo+ softFrom: root.softDFrom+ softTo: root.softDTo+ showSoftRange: false+ softRangeActive: root.softRangeActive+ focusPolicy: root.focusPolicy+ parentSpinBox: root++ onValueChanged: root.dValue = value+ }+ }++ onDValueChanged: contentId.value = root.dValue+ onDFromChanged: fixSoftRange()+ onDToChanged: fixSoftRange()+ onSoftDFromChanged: fixSoftRange()+ onSoftDToChanged: fixSoftRange()+}diff --git a/qmlmodules/components/qml/sliderspinbox/KisIntSliderSpinBox.qml b/qmlmodules/components/qml/sliderspinbox/KisIntSliderSpinBox.qmlnew file mode 100644index 0000000000..461b3bbf69--- /dev/null+++ b/qmlmodules/components/qml/sliderspinbox/KisIntSliderSpinBox.qml@@ -0,0 +1,81 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15+import QtQuick.Controls 2.15++SpinBox {+ id: root++ property alias prefix: contentId.prefix+ property alias suffix: contentId.suffix+ property int softFrom: from+ property int softTo: from+ property bool softRangeActive: false+ property alias blockUpdateSignalOnDrag: contentId.blockUpdateSignalOnDrag+ property alias exponentRatio: contentId.exponentRatio+ property int fastSliderStep: 5+ readonly property alias dragging : contentId.dragging++ function fixSoftRange() {+ if (root.softFrom < root.from) {+ root.softFrom = root.from;+ } else if (root.softFrom > root.softTo) {+ root.softFrom = root.softTo;+ }+ if (root.softTo < root.softFrom) {+ root.softTo = root.softFrom;+ } else if (root.softTo > root.to) {+ root.softTo = root.to;+ }+ contentId.showSoftRange = root.softFrom !== root.softTo;+ }++ editable: false+ padding: 0+ focusPolicy: Qt.WheelFocus+ implicitWidth: contentId.implicitWidth + 1 + 2 + leftPadding + rightPadding++ contentItem: FocusScope {+ focus: true++ KisSliderSpinBoxContentItem {+ id: contentId++ anchors.fill: parent+ anchors.margins: 1+ anchors.rightMargin: 2+ focus: true++ from: root.from+ to: root.to+ softFrom: root.softFrom+ softTo: root.softTo+ showSoftRange: false+ softRangeActive: root.softRangeActive+ parentSpinBox: root+ focusPolicy: root.focusPolicy+ fastSliderStep: root.fastSliderStep++ onValueChanged: root.value = Math.round(value)+ }+ }++ onValueChanged: contentId.value = root.value+ onFromChanged: fixSoftRange()+ onToChanged: fixSoftRange()+ onSoftFromChanged: fixSoftRange()+ onSoftToChanged: fixSoftRange()++ Component.onCompleted: {+ // The following is to avoid an oddity inside Fusion+ // Where padding is added to ensure a centered text.+ if (root.mirrored) {+ root.rightPadding = 0;+ } else {+ root.leftPadding = 0;+ }+ }+}diff --git a/qmlmodules/components/qml/sliderspinbox/KisSliderSpinBoxContentItem.qml b/qmlmodules/components/qml/sliderspinbox/KisSliderSpinBoxContentItem.qmlnew file mode 100644index 0000000000..fba8e42aed--- /dev/null+++ b/qmlmodules/components/qml/sliderspinbox/KisSliderSpinBoxContentItem.qml@@ -0,0 +1,210 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15+import QtQuick.Controls 2.15+import org.krita.components 1.0++FocusScope {+ id: root++ property alias value: parseSpinBoxContentItem.value+ property alias decimals: parseSpinBoxContentItem.decimals+ property alias from: parseSpinBoxContentItem.from+ property alias to: parseSpinBoxContentItem.to+ property real softFrom: 0+ property real softTo: 0+ property alias showSoftRange: sliderOverlay.showTopBar+ property alias softRangeActive: sliderOverlay.topBarActive+ property real valueBeforeEditing: 0.0+ required property SpinBox parentSpinBox+ property alias prefix: parseSpinBoxContentItem.prefix+ property alias suffix: parseSpinBoxContentItem.suffix+ property alias focusPolicy: sliderManipulator.focusPolicy+ readonly property bool editing: parentSpinBox ? parentSpinBox.editable : false+ property alias blockUpdateSignalOnDrag: sliderManipulator.blockUpdateSignalOnDrag+ property alias exponentRatio: sliderManipulator.exponentRatio+ property alias fastSliderStep: sliderManipulator.fastSliderStep+ readonly property alias dragging : sliderManipulator.dragging++ implicitHeight: parseSpinBoxContentItem.implicitHeight+ implicitWidth: parseSpinBoxContentItem.implicitWidth + rangeSwitch.implicitWidth++ onSoftRangeActiveChanged: rangeSwitch.softRangeActive = root.softRangeActive++ KisSliderSpinBoxRangeSwitch {+ id: rangeSwitch++ anchors.top: parent.top+ anchors.bottom: parent.bottom+ anchors.right: parent.right+ implicitWidth: root.showSoftRange ? 16 : 0+ visible: root.showSoftRange;+ color: root.parentSpinBox.palette.text+ //: @info:tooltip toggle between soft and hard range in the slider spin box+ toolTip: qsTr("Toggle between full range and subrange.\nFull range: [%1, %2]\nSubrange: [%3, %4]")+ .arg(root.from.toFixed(root.decimals))+ .arg(root.to.toFixed(root.decimals))+ .arg(root.softFrom.toFixed(root.decimals))+ .arg(root.softTo.toFixed(root.decimals))++ onSoftRangeActiveChanged: root.softRangeActive = softRangeActive+ }++ KisSliderOverlay {+ id: sliderOverlay++ property real value: parseSpinBoxContentItem.value++ anchors.fill: parseSpinBoxContentItem+ color: root.parentSpinBox.palette.highlight+ radius: 1+ topBarWidth: {+ const x = value - root.softFrom;+ const w = root.softTo - root.softFrom;+ return Math.max(Math.min(x, w), 0) / w;+ }+ bottomBarWidth: value / (root.to - root.from)+ faded: root.editing+ exponentRatio: root.exponentRatio+ }++ KisParseSpinBoxContentItem {+ id: parseSpinBoxContentItem++ anchors.top: parent.top+ anchors.left: parent.left+ anchors.bottom: parent.bottom+ anchors.right: rangeSwitch.left+ parentSpinBox: root.parentSpinBox++ onEditingFinished: {+ if (root.parentSpinBox) {+ root.parentSpinBox.editable = false;+ }+ if (textInput.activeFocus) {+ sliderManipulator.forceActiveFocus(Qt.OtherFocusReason);+ }+ }++ onEditingCanceled: {+ if (root.parentSpinBox) {+ root.parentSpinBox.editable = false;+ }+ if (textInput.activeFocus) {+ sliderManipulator.forceActiveFocus(Qt.OtherFocusReason);+ }+ root.value = root.valueBeforeEditing;+ }++ onValueParsed: (v) => {+ if (!isNaN(v)) {+ sliderOverlay.value = v.toFixed(root.decimals);+ }+ }++ onValueChanged: {+ sliderOverlay.value = root.value;+ sliderManipulator.value = root.value;+ }++ Component.onCompleted: {+ textInput.horizontalAlignment = Text.AlignHCenter;+ textInput.focus = false;+ textInput.visible = Qt.binding(() => { return root.editing; });+ }+ }++ KisSliderSpinBoxManipulator {+ id: sliderManipulator+ anchors.fill: parseSpinBoxContentItem+ focus: true+ visible: !root.editing++ min: root.showSoftRange && root.softRangeActive ? root.softFrom : root.from+ max: root.showSoftRange && root.softRangeActive ? root.softTo : root.to+ stepSize: root.parentSpinBox ? root.parentSpinBox.stepSize : 1.0++ onValueChanged: root.value = value++ onEditingStarted: {+ if (root.parentSpinBox) {+ root.parentSpinBox.editable = true;+ }+ parseSpinBoxContentItem.textInput.selectAll();+ parseSpinBoxContentItem.textInput.forceActiveFocus(Qt.OtherFocusReason);+ root.valueBeforeEditing = root.value;+ }++ onEditingStartedWithValue: (v) => {+ if (root.parentSpinBox) {+ root.parentSpinBox.editable = true;+ }+ parseSpinBoxContentItem.textInput.selectAll();+ parseSpinBoxContentItem.textInput.forceActiveFocus(Qt.OtherFocusReason);+ root.valueBeforeEditing = root.value;+ parseSpinBoxContentItem.textInput.contentsText = v;+ }++ onIncrease: (wheel) => {+ if (!root.parentSpinBox) {+ return;+ }+ root.parentSpinBox.up.pressed = !wheel;+ root.parentSpinBox.increase();+ }++ onDecrease: (wheel) => {+ if (!root.parentSpinBox) {+ return;+ }+ root.parentSpinBox.up.pressed = !wheel;+ root.parentSpinBox.decrease();+ }++ Item {+ id: highlightedTextContainer+ anchors.top: parent.top+ anchors.left: parent.left+ anchors.bottom: parent.bottom+ width: (root.showSoftRange && root.softRangeActive ? sliderOverlay.topBarWidth : sliderOverlay.bottomBarWidth) * sliderManipulator.width+ clip: true++ Text {+ id: highlightedText+ anchors.top: parent.top+ anchors.left: parent.left+ anchors.bottom: parent.bottom+ width: sliderManipulator.width+ text: parseSpinBoxContentItem.textInput.text+ horizontalAlignment: Text.AlignHCenter;+ verticalAlignment: Text.AlignVCenter;+ font: root.parentSpinBox.font+ color: root.parentSpinBox.palette.highlightedText+ }+ }++ Item {+ id: nonHighlightedTextContainer+ anchors.top: parent.top+ anchors.left: highlightedTextContainer.right+ anchors.right: parent.right+ anchors.bottom: parent.bottom+ clip: true++ Text {+ id: nonHighlightedText+ anchors.top: parent.top+ anchors.right: parent.right+ anchors.bottom: parent.bottom+ width: sliderManipulator.width+ text: parseSpinBoxContentItem.textInput.text+ horizontalAlignment: Text.AlignHCenter;+ verticalAlignment: Text.AlignVCenter;+ color: root.parentSpinBox.palette.text+ }+ }+ }+}diff --git a/qmlmodules/components/qml/sliderspinbox/KisSliderSpinBoxManipulator.qml b/qmlmodules/components/qml/sliderspinbox/KisSliderSpinBoxManipulator.qmlnew file mode 100644index 0000000000..acd848fdb1--- /dev/null+++ b/qmlmodules/components/qml/sliderspinbox/KisSliderSpinBoxManipulator.qml@@ -0,0 +1,175 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15++FocusScope {+ id: root++ property real min: 0.0+ property real max: 0.0+ property real value: 0.0+ property real stepSize: 1.0+ property bool blockUpdateSignalOnDrag: false+ property real exponentRatio: 1.0+ property real fastSliderStep: 5.0+ readonly property alias dragging : mouseArea.isDragging+ property int focusPolicy: Qt.WheelFocus++ signal editingStarted()+ signal editingStartedWithValue(v: real)+ signal increase(wheel: bool)+ signal decrease(wheel: bool)++ MouseArea {+ id: mouseArea++ property bool isDragging: false+ property bool useRelativeDragging: false+ property real relativeDraggingOffset: 0.0+ property point lastMousePressPosition: Qt.point(0.0, 0.0)+ property real cumulatedTrackpadLength: 0.0++ function pointForValue() : real+ {+ const rangeSize = root.max - root.min;+ if (rangeSize <= 0.0) {+ return 0.0;+ }+ const localPosition = root.value - root.min;+ const normalizedValue = Math.pow(localPosition / rangeSize, 1.0 / root.exponentRatio);+ return Math.max(0.0, Math.min(width, Math.round(normalizedValue * width)));+ }++ function valueForPoint(x: real, y: real, modifiers: int) : real+ {+ const center = Qt.point(+ mouseArea.lastMousePressPosition.x + (mouseArea.useRelativeDragging ? mouseArea.relativeDraggingOffset : 0),+ mouseArea.height / 2.0+ );+ const rangeSize = root.max - root.min;+ const distanceY =+ Math.max(+ 0.0,+ Math.abs(y - center.y) - center.y - 32.0+ );+ const scale =+ modifiers & Qt.ShiftModifier+ ? (mouseArea.width + 2.0 * distanceY * 10.0) / mouseArea.width + 4.0+ : (mouseArea.width + 2.0 * distanceY * 2.0) / mouseArea.width;+ const scaledRectLeft = (0.0 - center.x) * scale + center.x;+ const scaledRectRight = (mouseArea.width - center.x) * scale + center.x;+ const scaledRectWidth = scaledRectRight - scaledRectLeft;+ const posX = x - scaledRectLeft;+ const normalizedPosX = Math.max(0.0, Math.min(1.0, posX / scaledRectWidth));+ const normalizedValue = Math.pow(normalizedPosX, root.exponentRatio);+ let v = normalizedValue * rangeSize + root.min;+ if (modifiers & Qt.ControlModifier) {+ v = Math.round(v / root.fastSliderStep) * root.fastSliderStep;+ }+ return v;+ }++ anchors.fill: parent+ cursorShape: Qt.SplitHCursor+ acceptedButtons: Qt.LeftButton | Qt.RightButton+ focus: true+ activeFocusOnTab: true+ preventStealing: true++ onPressAndHold: {+ if (isDragging) {+ return;+ }+ root.editingStarted()+ }++ onPressed: (me) => {+ if (root.focusPolicy & Qt.ClickFocus) {+ mouseArea.forceActiveFocus(Qt.MouseFocusReason);+ }++ if (me.button !== Qt.LeftButton) {+ return;+ }++ mouseArea.lastMousePressPosition = Qt.point(me.x, me.y);+ mouseArea.relativeDraggingOffset = mouseArea.pointForValue() - me.x;+ mouseArea.useRelativeDragging = (me.modifiers & Qt.ShiftModifier);+ }++ onReleased: (me) => {+ if (me.button === Qt.RightButton) {+ root.editingStarted();++ } else if (me.button === Qt.LeftButton) {+ if (root.blockUpdateSignalOnDrag) {+ let x = mouseArea.useRelativeDragging ? me.x + mouseArea.relativeDraggingOffset : me.x;+ value = mouseArea.valueForPoint(x, me.y, me.modifiers);+ } else {+ if (!mouseArea.isDragging) {+ root.value = mouseArea.valueForPoint(me.x, me.y, me.modifiers);+ }+ }+ mouseArea.isDragging = false;+ }+ }++ onPositionChanged: (me) => {+ if (!(me.buttons & Qt.LeftButton)) {+ return;+ }+ if (!mouseArea.isDragging) {+ const dx = me.x - mouseArea.lastMousePressPosition.x;+ const dy = me.y - mouseArea.lastMousePressPosition.y;+ if (dx * dx + dy * dy <= 2 * 2) {+ return;+ } else {+ mouseArea.isDragging = true;+ }+ }+ const x = mouseArea.useRelativeDragging ? me.x + mouseArea.relativeDraggingOffset : me.x;+ root.value = mouseArea.valueForPoint(x, me.y, me.modifiers);+ }++ onWheel: (we) => {+ if (root.focusPolicy & Qt.WheelFocus) {+ mouseArea.forceActiveFocus(Qt.MouseFocusReason);+ }++ let inc = 0.0;+ if (we.pixelDelta && we.pixelDelta.y !== 0) {+ mouseArea.cumulatedTrackpadLength += we.pixelDelta.y;+ if (Math.abs(mouseArea.cumulatedTrackpadLength) > 30) {+ inc = mouseArea.cumulatedTrackpadLength;+ mouseArea.cumulatedTrackpadLength = 0.0;+ }+ } else {+ inc = we.angleDelta.y;+ }++ inc *= we.inverted ? -1 : 1;+ if (inc > 0) {+ root.increase(true);+ } else if (inc < 0) {+ root.decrease(true);+ }+ }++ Keys.onPressed: (ke) => {+ if (ke.key === Qt.Key_Right) {+ root.increase(false);+ } else if (ke.key === Qt.Key_Left) {+ root.decrease(false);+ } else if (ke.key === Qt.Key_Return || ke.key === Qt.Key_Enter) {+ root.editingStarted();+ } else if (ke.key === Qt.Key_Up || ke.key === Qt.Key_Down || ke.key === Qt.Key_Escape) {+ return;+ } else if (ke.key >= Qt.Key_0 && ke.key <= Qt.Key_9) {+ root.editingStartedWithValue(ke.key - Qt.Key_0);+ }+ }+ }+}diff --git a/qmlmodules/components/qml/sliderspinbox/KisSliderSpinBoxRangeSwitch.qml b/qmlmodules/components/qml/sliderspinbox/KisSliderSpinBoxRangeSwitch.qmlnew file mode 100644index 0000000000..c0cc0e1f20--- /dev/null+++ b/qmlmodules/components/qml/sliderspinbox/KisSliderSpinBoxRangeSwitch.qml@@ -0,0 +1,120 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15+import org.krita.components 1.0++Item {+ id: root++ property bool softRangeActive: false+ property color color: "black"+ property alias toolTip: toolTipPopup.text++ opacity: 0.4++ states: [+ State {+ name: "hovered"+ when: root.enabled && !root.softRangeActive && mouseArea.containsMouse++ PropertyChanges {+ target: root;+ opacity: 1+ }+ },+ State {+ name: "softRangeActive"+ when: root.softRangeActive && (!root.enabled || !mouseArea.containsMouse)++ PropertyChanges {+ target: rangeSwitchOuterCircle;+ opacity: 1+ }+ PropertyChanges {+ target: rangeSwitchInnerCircle;+ width: rangeSwitchOuterCircle.width * 0.5 - 1;+ }+ },+ State {+ name: "softRangeActiveAndHovered"+ when: root.enabled && root.softRangeActive && mouseArea.containsMouse++ PropertyChanges {+ target: rangeSwitchOuterCircle;+ opacity: 1+ }+ PropertyChanges {+ target: rangeSwitchInnerCircle;+ width: rangeSwitchOuterCircle.width * 0.5 - 1;+ }+ PropertyChanges {+ target: root;+ opacity: 1+ }+ }+ ]++ transitions: [+ Transition {+ from: "*"+ to: "*"+ PropertyAnimation {+ target: root+ property: "opacity"+ duration: 150+ }+ PropertyAnimation {+ target: rangeSwitchOuterCircle+ property: "opacity"+ duration: 150+ }+ PropertyAnimation {+ target: rangeSwitchInnerCircle+ property: "width"+ duration: 150+ }+ }+ ]++ Rectangle {+ id: rangeSwitchOuterCircle++ width: 10+ height: width+ x: (parent.width - width) * 0.5+ y: (parent.height - height) * 0.5+ radius: width * 0.5+ border.width: 1+ border.color: root.color+ color: "transparent"+ opacity: 0+ }++ Rectangle {+ id: rangeSwitchInnerCircle++ width: rangeSwitchOuterCircle.width+ height: width+ x: (parent.width - width) * 0.5+ y: (parent.height - height) * 0.5+ radius: width * 0.5+ color: root.color+ }++ MouseArea {+ id: mouseArea+ anchors.fill: parent+ hoverEnabled: true++ onClicked: root.softRangeActive = !root.softRangeActive+ }++ KisToolTip {+ id: toolTipPopup+ parent: root+ visible: root.enabled && mouseArea.containsMouse+ }+}diff --git a/qmlmodules/components/qml/spinbox/KisDoubleParseSpinBox.qml b/qmlmodules/components/qml/spinbox/KisDoubleParseSpinBox.qmlnew file mode 100644index 0000000000..4e7c2ee5c3--- /dev/null+++ b/qmlmodules/components/qml/spinbox/KisDoubleParseSpinBox.qml@@ -0,0 +1,40 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15++KisDoubleSpinBox {+ id: root++ property alias prefix: contentId.prefix+ property alias suffix: contentId.suffix++ editable: true+ padding: 0+ focusPolicy: Qt.WheelFocus++ implicitWidth: contentId.implicitWidth + 1 + 2 + leftPadding + rightPadding++ contentItem: FocusScope {+ KisParseSpinBoxContentItem {+ id: contentId++ anchors.fill: parent+ anchors.margins: 1+ anchors.rightMargin: 2+ focus: true++ value: root.dValue+ decimals: root.decimals+ from: root.dFrom+ to: root.dTo+ parentSpinBox: root++ onValueChanged: root.dValue = value+ }+ }++ onDValueChanged: contentId.value = root.dValue+}diff --git a/qmlmodules/components/qml/spinbox/KisDoubleSpinBox.qml b/qmlmodules/components/qml/spinbox/KisDoubleSpinBox.qmlnew file mode 100644index 0000000000..a5a83add4c--- /dev/null+++ b/qmlmodules/components/qml/spinbox/KisDoubleSpinBox.qml@@ -0,0 +1,72 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15+import QtQuick.Controls 2.15+import "KisParseSpinBoxUtil.js" as KisParseSpinBoxUtil++SpinBox {+ id: root++ property int decimals: 2+ property real dValue: 0.0+ property real dFrom: 0.0+ property real dTo: 100.0+ property real dStepSize: 1.0++ property real factor: Math.pow(10, decimals)++ stepSize: Math.round(dStepSize * factor)+ from: Math.round(dFrom * factor)+ to: Math.round(dTo * factor)++ onValueChanged: root.dValue = root.value / root.factor;++ onDecimalsChanged: root.dValue = KisParseSpinBoxUtil.truncateValue(root.dValue, root.decimals)++ onDValueChanged: {+ let v = root.dValue;+ if (v > root.dTo) {+ v = root.dTo;+ } else if (v < root.dFrom) {+ v = root.dFrom;+ }+ v = parseFloat(KisParseSpinBoxUtil.truncateValue(v, root.decimals));+ if (v !== root.dValue) {+ root.dValue = v;+ }+ root.value = Math.round(root.dValue * root.factor);+ }++ onDFromChanged: {+ if (root.dFrom > root.dTo) {+ root.dFrom = root.dTo;+ }+ if (root.dFrom > root.dValue) {+ root.dValue = KisParseSpinBoxUtil.truncateValue(root.dFrom, root.decimals);+ }+ }++ onDToChanged: {+ if (root.dTo < root.dFrom) {+ root.dTo = root.dFrom;+ }+ if (root.dTo < root.dValue) {+ root.dValue = KisParseSpinBoxUtil.truncateValue(root.dTo, root.decimals);+ }+ }++ Component.onCompleted: {+ root.value = Math.round(root.dValue * root.factor)++ // The following is to avoid an oddity inside Fusion+ // Where padding is added to ensure a centered text.+ if (root.mirrored) {+ root.rightPadding = 0;+ } else {+ root.leftPadding = 0;+ }+ }+}diff --git a/qmlmodules/components/qml/spinbox/KisIntParseSpinBox.qml b/qmlmodules/components/qml/spinbox/KisIntParseSpinBox.qmlnew file mode 100644index 0000000000..0ca92a8c39--- /dev/null+++ b/qmlmodules/components/qml/spinbox/KisIntParseSpinBox.qml@@ -0,0 +1,50 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15+import QtQuick.Controls 2.15++SpinBox {+ id: root++ property alias prefix: contentId.prefix+ property alias suffix: contentId.suffix++ editable: true+ padding: 0+ focusPolicy: Qt.WheelFocus+ implicitWidth: contentId.implicitWidth + 1 + 2 + leftPadding + rightPadding++ contentItem: FocusScope {+ KisParseSpinBoxContentItem {+ id: contentId++ anchors.fill: parent+ anchors.margins: 1+ anchors.rightMargin: 2+ focus: true++ value: root.value+ from: root.from+ to: root.to+ parentSpinBox: root++ onValueChanged: root.value = Math.round(value)+ }+ }++ onValueChanged: contentId.value = root.value;++ Component.onCompleted: {++ // The following is to avoid an oddity inside Fusion+ // Where padding is added to ensure a centered text.+ if (root.mirrored) {+ root.rightPadding = 0;+ } else {+ root.leftPadding = 0;+ }+ }+}diff --git a/qmlmodules/components/qml/spinbox/KisParseSpinBoxContentItem.qml b/qmlmodules/components/qml/spinbox/KisParseSpinBoxContentItem.qmlnew file mode 100644index 0000000000..bf506aaa88--- /dev/null+++ b/qmlmodules/components/qml/spinbox/KisParseSpinBoxContentItem.qml@@ -0,0 +1,151 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQml 2.15+import QtQuick 2.15+import QtQuick.Controls 2.15+import org.krita.components 1.0+import "KisParseSpinBoxUtil.js" as KisParseSpinBoxUtil++FocusScope {+ id: root++ property real value: 0.0+ property int decimals: 0+ property real from: 0+ property real to: 0+ property alias prefix: textInput.prefix+ property alias suffix: textInput.suffix+ property alias warningOverlay: warningOverlay+ property alias textInput: textInput+ required property SpinBox parentSpinBox++ signal editingFinished()+ signal editingCanceled()+ signal valueParsed(real parsedValue)++ implicitHeight: textInput.implicitHeight+ implicitWidth: textMetrics.boundingRect.width + textInput.padding * 2++ onValueChanged: textInput.contentsText = parseFloat(KisParseSpinBoxUtil.truncateValue(root.value, root.decimals));++ onDecimalsChanged: textInput.contentsText = KisParseSpinBoxUtil.truncateValue(root.value, root.decimals)++ KisWarningOverlay {+ id: warningOverlay+ anchors.fill: parent+ clip: true++ radius: 1+ showWarningSign: width - textInput.displayTextWidth > 24 * (textInput.horizontalAlignment === Qt.AlignHCenter ? 2 : 1)+ warningSignAlignment: Qt.AlignRight+ }++ KisTextInputWithPrefixAndSuffix {+ id: textInput++ // This is a double, but QML 5.15 doesn't like it+ // when assigning a NaN to a double.+ property var parsedValue: 0.0++ anchors.fill: parent+ verticalAlignment: Text.AlignVCenter+ padding: 4+ contentsText: KisParseSpinBoxUtil.truncateValue(root.value, root.decimals)+ focus: true+ font: root.parentSpinBox.font+ color: root.parentSpinBox.palette.text+ selectionColor: root.parentSpinBox.palette.highlight+ selectedTextColor: root.parentSpinBox.palette.highlightedText+ inputMethodHints: root.parentSpinBox.inputMethodHints+ readOnly: !root.parentSpinBox.editable++ onEditingFinished: {+ warningTimer.stop();+ if (isNaN(parsedValue)) {+ warningOverlay.warn = true;+ } else {+ warningOverlay.warn = false;+ root.value = KisParseSpinBoxUtil.truncateValue(parsedValue, root.decimals);+ root.editingFinished();+ }+ }++ KisNumParser { id: numParser;}++ onContentsTextChanged: {+ parsedValue = numParser.parseSimpleMathExpr(contentsText);+ warningOverlay.warn = false;+ if (isNaN(parsedValue)) {+ warningTimer.restart();+ } else {+ warningTimer.stop();+ }+ root.valueParsed(parsedValue)+ }++ Keys.onEscapePressed: {+ warningTimer.stop();+ warningOverlay.warn = false;+ textInput.contentsText = KisParseSpinBoxUtil.truncateValue(root.value, root.decimals);+ root.editingCanceled();+ }++ Timer {+ id: warningTimer+ interval: 2000;+ onTriggered: warningOverlay.warn = true+ }++ MouseArea {+ property real cumulatedTrackpadLength: 0.0++ anchors.fill: parent+ acceptedButtons: Qt.NoButton+ cursorShape: textInput.readOnly ? Qt.ArrowCursor : Qt.IBeamCursor++ onWheel: (we) => {+ if (root.parentSpinBox.focusPolicy & Qt.WheelFocus) {+ if (!textInput.activeFocus) {+ textInput.forceActiveFocus(Qt.MouseFocusReason);+ textInput.selectAll();+ }+ }++ let inc = 0.0+ if (we.pixelDelta && we.pixelDelta.y !== 0) {+ cumulatedTrackpadLength += we.pixelDelta.y;+ if (Math.abs(cumulatedTrackpadLength) > 30) {+ inc = cumulatedTrackpadLength;+ cumulatedTrackpadLength = 0.0;+ }+ } else {+ inc = we.angleDelta.y;+ }++ inc *= we.inverted ? -1 : 1;+ if (inc > 0) {+ root.parentSpinBox.increase();+ textInput.selectAll();+ } else if (inc < 0) {+ root.parentSpinBox.decrease();+ textInput.selectAll();+ }+ }+ }+ }++ TextMetrics {+ id: textMetrics+ font: textInput.font+ text: {+ const fromText = KisParseSpinBoxUtil.truncateValue(root.from, root.decimals);+ const toText = KisParseSpinBoxUtil.truncateValue(root.to, root.decimals);+ return root.prefix+ + (fromText.length > toText.length ? fromText : toText)+ + root.suffix+ }+ }+}diff --git a/qmlmodules/components/qml/spinbox/KisParseSpinBoxUtil.js b/qmlmodules/components/qml/spinbox/KisParseSpinBoxUtil.jsnew file mode 100644index 0000000000..a73d19cb88--- /dev/null+++ b/qmlmodules/components/qml/spinbox/KisParseSpinBoxUtil.js@@ -0,0 +1,30 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+/**+ This function tries to truncate a float value, so that+ it will always show the minimum amount of decimals behind+ the dot.++ TODO: This isn't locale friendly.+ */+function truncateValue(value, decimals)+{+ if (isNaN(parseFloat(value))) return 0;+ const reg = new RegExp("^-?\\d+(?:\\.\\d{0," + decimals + "})?", "g");+ const a = value.toString().match(reg)[0];+ const dot = a.indexOf(".");+ if (dot === -1) {+ if (decimals < 1) {+ return a;+ }+ return a + "." + "0".repeat(decimals);+ }+ if (decimals < 1) {+ return a.slice(0, dot);+ }+ const b = decimals - (a.length - dot) + 1;+ return b > 0 ? (a + "0".repeat(b)) : a;+}diff --git a/qmlmodules/components/qml/textinput/KisTextInputWithPrefixAndSuffix.qml b/qmlmodules/components/qml/textinput/KisTextInputWithPrefixAndSuffix.qmlnew file mode 100644index 0000000000..af7210c83a--- /dev/null+++ b/qmlmodules/components/qml/textinput/KisTextInputWithPrefixAndSuffix.qml@@ -0,0 +1,21 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+KisTextInputWithSelectionRange {+ property string prefix: ""+ property string suffix: ""+ property string contentsText: ""++ selectionRangeStart: prefix.length+ selectionRangeEnd: text.length - suffix.length++ text: prefix + contentsText + suffix++ onTextChanged: {+ const startPos = text.startsWith(prefix) ? prefix.length : 0;+ const endPos = text.endsWith(suffix) ? text.length - suffix.length : text.length;+ contentsText = text.slice(startPos, endPos);+ }+}diff --git a/qmlmodules/components/qml/textinput/KisTextInputWithSelectionRange.qml b/qmlmodules/components/qml/textinput/KisTextInputWithSelectionRange.qmlnew file mode 100644index 0000000000..49b2102465--- /dev/null+++ b/qmlmodules/components/qml/textinput/KisTextInputWithSelectionRange.qml@@ -0,0 +1,52 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15++TextInput {+ id: root++ property int selectionRangeStart: 0+ property int selectionRangeEnd: 0+ property int selectionRangeLength: selectionRangeEnd - selectionRangeStart+ property int displayTextWidth: textMetrics.boundingRect.width++ clip: displayTextWidth > width++ function clampSelection(selectionPosition: int)+ {+ return Math.min(Math.max(selectionPosition, selectionRangeStart), selectionRangeEnd);+ }++ onCursorPositionChanged: {+ if (cursorPosition != selectionStart && cursorPosition != selectionEnd) {+ cursorPosition = clampSelection(cursorPosition);+ } else if (cursorPosition != selectionEnd) {+ select(clampSelection(selectionEnd), clampSelection(selectionStart))+ } else {+ select(clampSelection(selectionStart), clampSelection(selectionEnd))+ }+ }++ Keys.onPressed: (event) => {+ if (event.key === Qt.Key_Backspace) {+ if (root.selectionRangeLength === 0 || root.cursorPosition === root.selectionRangeStart) {+ event.accepted = true+ }+ } else if (event.key === Qt.Key_Delete) {+ if (root.selectionRangeLength === 0 || root.cursorPosition === root.selectionRangeEnd) {+ event.accepted = true+ }+ }+ }++ Component.onCompleted: select(clampSelection(selectionStart), clampSelection(selectionEnd))++ TextMetrics {+ id: textMetrics+ font: root.font+ text: root.text+ }+}diff --git a/qmlmodules/components/qml/tooltip/KisToolTip.qml b/qmlmodules/components/qml/tooltip/KisToolTip.qmlnew file mode 100644index 0000000000..7dcdb886a2--- /dev/null+++ b/qmlmodules/components/qml/tooltip/KisToolTip.qml@@ -0,0 +1,40 @@+/*+ * SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15+import QtQuick.Controls 2.15++ToolTip {+ id: root++ delay: Qt.styleHints.mousePressAndHoldInterval;+ timeout: Qt.styleHints.mousePressAndHoldInterval;++ property Item parentControl+ property bool changingParentControl: false++ onParentChanged: {+ if (changingParentControl) {+ return;+ }+ if (parentControl) {+ parentControl = undefined;+ root.visible = false;+ }+ }++ onParentControlChanged: {+ changingParentControl = true;+ if (root.parentControl) {+ root.parent = root.parentControl;+ root.parentControl.hoverEnabled = true;+ root.visible = Qt.binding(() => { return root.parentControl.hovered });+ } else {+ root.parent = undefined;+ root.visible = false;+ }+ changingParentControl = false;+ }+}