Skip to content

armgit / krita

Public Imported from GitHub
0

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 issues with implicit size and the shape painter in SVGTextLabel.

Wolthera van Hövell tot Westerflier7b1cbcd66277
diff --git a/plugins/dockers/textproperties/qml/OpenTypeFeatureDelegate.qml b/plugins/dockers/textproperties/qml/OpenTypeFeatureDelegate.qml
index 861d88db7d..56bcf2abce 100644
--- a/plugins/dockers/textproperties/qml/OpenTypeFeatureDelegate.qml
+++ b/plugins/dockers/textproperties/qml/OpenTypeFeatureDelegate.qml
@@ -77,6 +77,8 @@ Control {
SvgTextLabel {
text: root.sample;
id: svgTextLabel;
+ implicitWidth: minimumRect.width;
+ implicitHeight: minimumRect.height;
Layout.preferredHeight: displayLabel.height * 2;
Layout.preferredWidth: (displayLabel.height * 2) * (implicitWidth/implicitHeight);
Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter;
diff --git a/qmlmodules/components/SvgTextLabel.cpp b/qmlmodules/components/SvgTextLabel.cpp
index c674ffccfd..962d7e2e6a 100644
--- a/qmlmodules/components/SvgTextLabel.cpp
+++ b/qmlmodules/components/SvgTextLabel.cpp
@@ -37,6 +37,8 @@ struct Q_DECL_HIDDEN SvgTextLabel::Private {
int bottomPadding = 2;
int leftPadding = 2;
int rightPadding = 2;
+
+ bool addedShapeToPainter = false; //Tests if the shape has been added to the painter yet.
};
SvgTextLabel::SvgTextLabel(QQuickItem *parent)
@@ -276,9 +278,8 @@ void SvgTextLabel::setPadding(int padding)
d->rightPadding = padding;
d->topPadding = padding;
d->bottomPadding = padding;
- setImplicitSize(d->shape->boundingRect().width() + d->leftPadding + d->rightPadding,
- d->shape->boundingRect().height() + d->topPadding + d->bottomPadding);
emit paddingChanged(padding);
+ emit minimumRectChanged();
}
void SvgTextLabel::setLanguage(QString language)
@@ -305,15 +306,27 @@ void SvgTextLabel::componentComplete()
d->shapePainter.reset(new KoShapePainter());
if (!d->shape->boundingRect().isEmpty()) {
d->shapePainter->setShapes({d->shape.data()});
+ d->addedShapeToPainter = true;
}
}
}
+QRectF SvgTextLabel::minimumRect() const
+{
+ if (d->shape) {
+ const QRectF bbox = d->shape->selectionBoxes(0, d->shape->posForIndex(d->shape->plainText().size())).boundingRect();
+ return bbox.adjusted(-d->leftPadding, -d->topPadding, d->rightPadding, d->bottomPadding);
+ }
+ return QRectF();
+}
+
void SvgTextLabel::updateShape()
{
d->shape->setPropertiesAtPos(-1, d->props);
d->shape->relayout();
- const QRectF bbox = d->shape->selectionBoxes(0, d->shape->posForIndex(d->shape->plainText().size())).boundingRect();
- setImplicitSize(bbox.width() + d->leftPadding + d->rightPadding,
- bbox.height() + d->topPadding + d->bottomPadding);
+ if (!d->addedShapeToPainter && d->shapePainter && !d->shape->boundingRect().isEmpty()) {
+ d->shapePainter->setShapes({d->shape.data()});
+ d->addedShapeToPainter = true;
+ }
+ emit minimumRectChanged();
}
diff --git a/qmlmodules/components/SvgTextLabel.h b/qmlmodules/components/SvgTextLabel.h
index 9db3948394..11ceb3ffdb 100644
--- a/qmlmodules/components/SvgTextLabel.h
+++ b/qmlmodules/components/SvgTextLabel.h
@@ -34,6 +34,7 @@ class SvgTextLabel : public QQuickPaintedItem
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(int padding READ padding WRITE setPadding NOTIFY paddingChanged)
Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged)
+ Q_PROPERTY(QRectF minimumRect READ minimumRect NOTIFY minimumRectChanged)
public:
SvgTextLabel(QQuickItem *parent = nullptr);
@@ -65,6 +66,8 @@ public:
QString language() const;
+ QRectF minimumRect() const;
+
public Q_SLOTS:
void setFontFamilies(QStringList fontFamilies);
@@ -114,6 +117,8 @@ Q_SIGNALS:
void paddingChanged(int padding);
void languageChanged(QString language);
+
+ void minimumRectChanged();
protected:
/**
* @brief componentComplete