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++
Fix up QML AngleSelector, KisCurveWidget and KisGroupButton
Wolthera van Hövell tot Westerflier052c9f3039d8
diff --git a/plugins/dockers/textproperties/qml/TextAlign.qml b/plugins/dockers/textproperties/qml/TextAlign.qmlindex 020c219152..d91457b783 100644--- a/plugins/dockers/textproperties/qml/TextAlign.qml+++ b/plugins/dockers/textproperties/qml/TextAlign.qml@@ -7,6 +7,7 @@ import QtQuick 2.0import QtQuick.Controls 2.0import QtQuick.Layouts 1.12import org.krita.flake.text 1.0+import org.krita.components 1.0CollapsibleGroupProperty {propertyTitle: i18nc("@title:group", "Text Align");@@ -156,7 +157,6 @@ CollapsibleGroupProperty {id: propertyTitleLabel;text: propertyTitle;verticalAlignment: Text.AlignVCenter- color: sysPalette.text;elide: Text.ElideRight;Layout.maximumWidth: contentWidth;}@@ -165,58 +165,65 @@ CollapsibleGroupProperty {id: alignGroup;}- Button {- id: alignStartBtn;- checkable: true;- icon.source: properties.direction === KoSvgText.DirectionLeftToRight? "qrc:///16_light_format-justify-left.svg"- : "qrc:///16_light_format-justify-right.svg";- icon.height: 16;- icon.width: 16;- icon.color: palette.text;- ButtonGroup.group: alignGroup;- Layout.preferredWidth: height;- onToggled: setAlignmentFromButtons();- }- Button {- id: alignMiddleBtn;- checkable: true;- icon.source: "qrc:///16_light_format-justify-center.svg";- icon.height: 16;- icon.width: 16;- icon.color: palette.text;- ButtonGroup.group: alignGroup;- Layout.preferredWidth: height;- onToggled: {- setAlignmentFromButtons();+ RowLayout {+ spacing: 0;++ KisGroupButton {+ groupPosition: KisGroupButton.GroupLeft;+ id: alignStartBtn;+ checkable: true;+ icon.source: properties.direction === KoSvgText.DirectionLeftToRight? "qrc:///16_light_format-justify-left.svg"+ : "qrc:///16_light_format-justify-right.svg";+ icon.height: 16;+ icon.width: 16;+ icon.color: palette.buttonText;+ ButtonGroup.group: alignGroup;+ Layout.preferredWidth: height;+ onToggled: setAlignmentFromButtons();+ }+ KisGroupButton {+ id: alignMiddleBtn;+ groupPosition: KisGroupButton.GroupCenter;+ checkable: true;+ icon.source: "qrc:///16_light_format-justify-center.svg";+ icon.height: 16;+ icon.width: 16;+ icon.color: palette.buttonText;+ ButtonGroup.group: alignGroup;+ Layout.preferredWidth: height;+ onToggled: {+ setAlignmentFromButtons();+ }+ }+ KisGroupButton {+ groupPosition: KisGroupButton.GroupRight;+ id: alignEndBtn;+ checkable: true;+ icon.source: properties.direction === KoSvgText.DirectionLeftToRight? "qrc:///16_light_format-justify-right.svg"+ : "qrc:///16_light_format-justify-left.svg";+ icon.height: 16;+ icon.width: 16;+ icon.color: palette.buttonText;+ ButtonGroup.group: alignGroup;+ Layout.preferredWidth: height;+ onToggled: setAlignmentFromButtons();}- }- Button {- id: alignEndBtn;- checkable: true;- icon.source: properties.direction === KoSvgText.DirectionLeftToRight? "qrc:///16_light_format-justify-right.svg"- : "qrc:///16_light_format-justify-left.svg";- icon.height: 16;- icon.width: 16;- icon.color: palette.text;- ButtonGroup.group: alignGroup;- Layout.preferredWidth: height;- onToggled: setAlignmentFromButtons();- }Item {Layout.fillWidth: true;}- Button {+ KisGroupButton {id: alignJustifyBtn;checkable: true;checked: textAlignAll === KoSvgText.AlignJustify;icon.height: 16;icon.width: 16;- icon.color: palette.text;+ icon.color: palette.buttonText;icon.source: "qrc:///16_light_format-justify-fill.svg";Layout.preferredWidth: height;onToggled: setAlignmentFromButtons();}+ }}onEnableProperty: properties.textAnchorState = KoSvgTextPropertiesModel.PropertySet;diff --git a/qmlmodules/components/KisCubicCurveQMLWrapper.cpp b/qmlmodules/components/KisCubicCurveQMLWrapper.cppindex e4d118a67d..e19b1007a7 100644--- a/qmlmodules/components/KisCubicCurveQMLWrapper.cpp+++ b/qmlmodules/components/KisCubicCurveQMLWrapper.cpp@@ -9,7 +9,7 @@ KisCubicCurveQml::KisCubicCurveQml(QObject *parent): QObject(parent){}-const QList<QPointF>& KisCubicCurveQml::points() const+const QList<QPointF> KisCubicCurveQml::points() const{return m_curve.points();}@@ -55,7 +55,7 @@ void KisCubicCurveQml::fromString(const QString &str)}-void KisCubicCurveQml::setPoints(const QList<QPointF> &points)+void KisCubicCurveQml::setPoints(const QList<QPointF> points){m_curve.setPoints(points);emit pointsChanged(m_curve.points());diff --git a/qmlmodules/components/KisCubicCurveQMLWrapper.h b/qmlmodules/components/KisCubicCurveQMLWrapper.hindex a52b996842..7a0a3509f8 100644--- a/qmlmodules/components/KisCubicCurveQMLWrapper.h+++ b/qmlmodules/components/KisCubicCurveQMLWrapper.h@@ -22,7 +22,7 @@ class KisCubicCurveQml : public QObjectpublic:KisCubicCurveQml(QObject *parent = nullptr);- const QList<QPointF>& points() const;+ const QList<QPointF> points() const;const QString& name() const;Q_INVOKABLE qreal value(qreal x) const;@@ -34,7 +34,7 @@ public:Q_INVOKABLE void fromString(const QString&);public Q_SLOTS:- void setPoints(const QList<QPointF> &points);+ void setPoints(const QList<QPointF> points);void setPoint(int idx, const QPointF &point);int addPoint(const QPointF &point);void removePoint(int idx);diff --git a/qmlmodules/components/qml/angleselector/KisAngleGauge.qml b/qmlmodules/components/qml/angleselector/KisAngleGauge.qmlindex 4ca67b492b..93fe8f0510 100644--- a/qmlmodules/components/qml/angleselector/KisAngleGauge.qml+++ b/qmlmodules/components/qml/angleselector/KisAngleGauge.qml@@ -6,7 +6,7 @@import QtQml 2.15import QtQuick 2.15import QtQuick.Controls 2.15-import QtQuick.Shapes 2.15+import QtQuick.Shapes 1.15Control {id: root@@ -38,6 +38,11 @@ Control {}}+ function adjustOpacity(color, alpha) {+ // In Qt6 we can use Qt.Alpha for this, but not in qt5+ return Qt.rgba(color.r, color.g, color.b, alpha);+ }+implicitWidth: 40implicitHeight: implicitWidthfocusPolicy: Qt.WheelFocus@@ -45,6 +50,7 @@ Control {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@@ -54,8 +60,10 @@ Control {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 color circleColor: darkMode ? root.palette.light : root.palette.dark;+ property color axesColor: root.adjustOpacity(circleColor, 0.75);+ property color bgColor: darkMode ? root.palette.dark: root.palette.light;+ property color angleLineColor: darkMode ? Qt.rgba(1, 1, 1, 255): Qt.rgba(0, 0, 0, 255);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))@@ -72,7 +80,7 @@ Control {property real radius: (gaugeShape.bottomPoint.y - gaugeShape.topPoint.y) / 2strokeColor: "transparent"fillColor: root.enabled- ? gaugeShape.darkMode ? root.palette.dark : root.palette.light+ ? gaugeShape.bgColor: root.palette.windowstartX: gaugeShape.topPoint.xstartY: gaugeShape.topPoint.y@@ -136,9 +144,7 @@ Control {// Angle lineShapePath {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)+ strokeColor: root.adjustOpacity(gaugeShape.angleLineColor, 0.75);fillColor: "transparent"startX: gaugeShape.center.xstartY: gaugeShape.center.ydiff --git a/qmlmodules/components/qml/angleselector/KisAngleSelector.qml b/qmlmodules/components/qml/angleselector/KisAngleSelector.qmlindex 8ee606f55e..85949b2d7d 100644--- a/qmlmodules/components/qml/angleselector/KisAngleSelector.qml+++ b/qmlmodules/components/qml/angleselector/KisAngleSelector.qml@@ -163,9 +163,10 @@ FocusScope {visible: root.flipOptionsMode === KisAngleSelector.FlipOptionsMode.MenuButtonpadding: 4display: AbstractButton.IconOnly- icon.source: "qrc:/krita/qml/Krita/Resources/images/view-choose.svg"+ icon.source: "qrc:///light_view-choose.svg"icon.width: 16icon.height: 16+ icon.color: palette.buttonText;onClicked: {menu.popup(buttonMenu, 0, buttonMenu.height);menu.forceActiveFocus();@@ -178,6 +179,7 @@ FocusScope {padding: 4display: AbstractButton.IconOnlyaction: actionFlipHorizontally+ icon.color: palette.buttonText;KisToolTip {parentControl: buttonFlipHorizontallytext: actionFlipHorizontally.text@@ -190,6 +192,7 @@ FocusScope {padding: 4display: AbstractButton.IconOnlyaction: actionFlipVertically+ icon.color: palette.buttonText;KisToolTip {parentControl: buttonFlipVerticallytext: actionFlipVertically.text@@ -202,6 +205,7 @@ FocusScope {padding: 4display: AbstractButton.IconOnlyaction: actionFlipHorizontallyAndVertically+ icon.color: palette.buttonText;KisToolTip {parentControl: buttonFlipHorizontallyAndVerticallytext: actionFlipHorizontallyAndVertically.textdiff --git a/qmlmodules/components/qml/button/KisGroupButton.qml b/qmlmodules/components/qml/button/KisGroupButton.qmlindex 2750e31b3c..e46af48605 100644--- a/qmlmodules/components/qml/button/KisGroupButton.qml+++ b/qmlmodules/components/qml/button/KisGroupButton.qml@@ -16,35 +16,19 @@ Button {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);+ SystemPalette {+ id: sysPalette;+ colorGroup: root.enabled?+ root.activeFocus? SystemPalette.Active:+ SystemPalette.Inactive: SystemPalette.Disabled;}- function updatePalette()- {- root.normalButtonColor = root.palette.active.button- root.normalButtonTextColor = root.palette.active.buttonText- fixPalette();- }+ property int groupPosition: KisGroupButton.GroupPosition.NoGroup+ palette.button: checked? sysPalette.highlight: sysPalette.button;+ palette.buttonText: checked? sysPalette.highlightedText: sysPalette.buttonTexttext: "Button"clip: true- padding: 8implicitWidth: implicitContentWidth + (root.leftPadding ?? root.padding)+ (root.rightPadding ?? root.padding)leftInset: (groupPosition === KisGroupButton.GroupPosition.GroupRight ||@@ -52,17 +36,12 @@ Button {rightInset: (groupPosition === KisGroupButton.GroupPosition.GroupLeft ||groupPosition === KisGroupButton.GroupPosition.GroupCenter) * -50- Component.onCompleted: {- updatePalette();- root.checkedChanged.connect(() => { root.fixPalette(); });- KisUI.paletteChanged.connect(updatePalette);- }-Rectangle {width: 1height: root.background.heightanchors.right: parent.right- color: Qt.alpha(root.palette.buttonText, 0.1)+ color: root.palette.buttonText;+ opacity: 0.1;visible: root.groupPosition === KisGroupButton.GroupPosition.GroupLeft ||root.groupPosition === KisGroupButton.GroupPosition.GroupCenter}diff --git a/qmlmodules/components/qml/curvewidget/KisCurveWidget.qml b/qmlmodules/components/qml/curvewidget/KisCurveWidget.qmlindex 441d77099a..9042ff25c1 100644--- a/qmlmodules/components/qml/curvewidget/KisCurveWidget.qml+++ b/qmlmodules/components/qml/curvewidget/KisCurveWidget.qml@@ -5,7 +5,7 @@*/import QtQuick 2.15import QtQuick.Controls 2.15-import QtQuick.Shapes 2.15+import QtQuick.Shapes 1.15import org.krita.components 1.0Control {@@ -20,6 +20,8 @@ Control {onPaletteChanged: contentItem.requestPaint()onActiveFocusChanged: contentItem.requestPaint()+ onWidthChanged: contentItem.requestPaint();+ onHeightChanged: contentItem.requestPaint();background: Rectangle {id: backgroundItem@@ -69,9 +71,10 @@ Control {contentItem: Canvas {id: contentItem- property list<point> points+ // Qt6: switch this to list<point>, qt5 doesn't support that.+ property var points: []- function updatePoints(pts) {+ function updatePoints() {const width = contentItem.width;const height = contentItem.height;const pointYs = root.curve.floatTransfer(width);@@ -101,8 +104,16 @@ Control {implicitWidth: 256implicitHeight: 256+ onWidthChanged: updatePoints();+ onHeightChanged: updatePoints();+onPointsChanged: contentItem.requestPaint()+ function adjustOpacity(color, alpha) {+ // In Qt6 we can use Qt.Alpha for this, but not in qt5+ return Qt.rgba(color.r, color.g, color.b, alpha);+ }+onPaint: {if (!contentItem.points || contentItem.points.length === 0) {return;@@ -111,7 +122,7 @@ Control {ctx.clearRect(0, 0, contentItem.width, contentItem.height);// Paint the curve- ctx.fillStyle = Qt.alpha(root.palette.text, 0.2);+ ctx.fillStyle = adjustOpacity(root.palette.text, 0.2);ctx.strokeStyle = root.palette.text;ctx.lineWidth = 2;ctx.beginPath();@@ -128,7 +139,7 @@ Control {ctx.stroke();// Paint non selected knotsctx.beginPath();- ctx.fillStyle = Qt.alpha(root.palette.base, 0.3);+ ctx.fillStyle = adjustOpacity(root.palette.base, 0.3);for (let i = 0; i < root.curve.points.length; ++i) {if (i === root.selectedKnotIndex && root.activeFocus) {continue;@@ -141,8 +152,8 @@ Control {// Paint the selected knotif (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));+ ctx.fillStyle = adjustOpacity(root.palette.highlight, 0.8);+ ctx.strokeStyle = Qt.tint(root.palette.text, adjustOpacity(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();@@ -211,7 +222,7 @@ Control {mouseArea.isDragging = true;}- onReleased: mouseArea.isDragging = false+ onReleased: mouseArea.isDragging = false;onPositionChanged: (me) => {if (root.readOnly) {@@ -220,11 +231,7 @@ Control {if (!mouseArea.isDragging) {const closestKnot = mouseArea.closestKnotIndex(me.x, me.y);- if (closestKnot < 0) {- mouseArea.cursorShape = Qt.ArrowCursor;- } else {- mouseArea.cursorShape = Qt.CrossCursor;- }+ mouseArea.cursorShape = closestKnot< 0? Qt.ArrowCursor: Qt.CrossCursor;} else {const crossedHoriz = me.x - mouseArea.width > 15 || me.x < -15;const crossedVert = me.y - mouseArea.height > 15 || me.y < -15;@@ -279,7 +286,7 @@ Control {}Keys.onPressed: (ke) => {- if (ke.key == Qt.Key_Right) {+ if (ke.key === Qt.Key_Right) {if (ke.modifiers & Qt.ControlModifier) {if (root.selectedKnotIndex < root.curve.points.length - 1) {root.selectedKnotIndex++;@@ -297,7 +304,7 @@ Control {}ke.accepted = true;- } else if (ke.key == Qt.Key_Left) {+ } else if (ke.key === Qt.Key_Left) {if (ke.modifiers & Qt.ControlModifier) {if (root.selectedKnotIndex > 0) {root.selectedKnotIndex--;@@ -314,8 +321,7 @@ Control {}}ke.accepted = true;-- } else if (ke.key == Qt.Key_Up) {+ } 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;@@ -324,7 +330,7 @@ Control {}ke.accepted = true;- } else if (ke.key == Qt.Key_Down) {+ } 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;@@ -333,7 +339,7 @@ Control {}ke.accepted = true;- } else if (ke.key == Qt.Key_Delete || ke.key == Qt.Key_Backspace) {+ } 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;@@ -347,7 +353,7 @@ Control {}ke.accepted = true;- } else if (ke.key == Qt.Key_Escape && mouseArea.isDragging) {+ } else if (ke.key === Qt.Key_Escape && mouseArea.isDragging) {if (mouseArea.draggedAwayKnotIndex !== -1) {root.curve.addPoint(mouseArea.draggedAwayKnot);root.selectedKnotIndex = mouseArea.draggedAwayKnotIndex;@@ -358,7 +364,7 @@ Control {mouseArea.isDragging = false;ke.accepted = true;- } else if ((ke.key == Qt.Key_A || ke.key == Qt.Key_Insert) && !mouseArea.isDragging) {+ } 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@@ -375,7 +381,7 @@ Control {Connections {target: root.curve- function onPointsChanged(pts) {+ function onPointsChanged() {contentItem.updatePoints();}}