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++

Initial implementation of new text tool options

Wolthera van Hövell tot Westerflier873d0833da2e
diff --git a/plugins/tools/svgtexttool/CMakeLists.txt b/plugins/tools/svgtexttool/CMakeLists.txt
index 6e127f8bc4..42c6a20778 100644
--- a/plugins/tools/svgtexttool/CMakeLists.txt
+++ b/plugins/tools/svgtexttool/CMakeLists.txt
@@ -24,6 +24,9 @@ set (SvgTextTool_SRCS
SvgTextShapeManagerBlocker.cpp
SvgConvertTextTypeCommand.cpp
SvgTextShortCuts.cpp
+ SvgTextToolOptionsData.cpp
+ SvgTextToolOptionsModel.cpp
+ SvgTextToolOptionsManager.cpp
glyphpalette/GlyphPaletteDialog.cpp
glyphpalette/GlyphPaletteProxyModel.cpp
diff --git a/plugins/tools/svgtexttool/Plugin.cpp b/plugins/tools/svgtexttool/Plugin.cpp
index 09c7ed8ddb..ebe31b3ebe 100644
--- a/plugins/tools/svgtexttool/Plugin.cpp
+++ b/plugins/tools/svgtexttool/Plugin.cpp
@@ -17,11 +17,16 @@
#include "SvgTextToolFactory.h"
#include "glyphpalette/GlyphPaletteProxyModel.h"
+#include "SvgTextToolOptionsModel.h"
+#include "SvgTextToolOptionsManager.h"
K_PLUGIN_FACTORY_WITH_JSON(PluginFactory, "krita_tool_svgtext.json", registerPlugin<Plugin>();)
KIS_DECLARE_STATIC_INITIALIZER {
qmlRegisterType<GlyphPaletteProxyModel>("org.krita.tools.text", 1, 0, "GlyphPaletteProxyModel");
+
+ qmlRegisterType<SvgTextToolOptionsModel>("org.krita.tools.text", 1, 0, "SvgTextToolOptionsModel");
+ qmlRegisterType<SvgTextToolOptionsManager>("org.krita.tools.text", 1, 0, "SvgTextToolOptionsManager");
}
Plugin::Plugin(QObject *parent, const QVariantList &)
: QObject(parent)
diff --git a/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp b/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp
index a0b3fbed41..189e3e69c0 100644
--- a/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp
+++ b/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp
@@ -7,8 +7,7 @@
#include "SvgCreateTextStrategy.h"
#include "SvgTextTool.h"
-#include <QFontDatabase>
-#include <QRectF>
+#include <KoFontRegistry.h>
#include "KisHandlePainterHelper.h"
#include "KoCanvasBase.h"
@@ -29,8 +28,11 @@ SvgCreateTextStrategy::SvgCreateTextStrategy(SvgTextTool *tool, const QPointF &c
, m_dragStart(clicked)
, m_dragEnd(clicked)
{
- const QFontMetrics fontMetrics = QFontMetrics(tool->defaultFont());
- double lineHeight = (fontMetrics.lineSpacing() / fontMetrics.fontDpi()) * 72.0;
+ KoSvgTextProperties properties = tool->propertiesForNewText();
+ properties.inheritFrom(KoSvgTextProperties::defaultProperties(), true);
+ const KoSvgText::FontMetrics fontMetrics = properties.metrics(true);
+ const qreal ftMultiplier = properties.fontSize().value / fontMetrics.fontSize;
+ const double lineHeight = (fontMetrics.lineGap+fontMetrics.ascender+fontMetrics.descender)*ftMultiplier;
m_minSizeInline = {lineHeight, lineHeight};
}
@@ -59,40 +61,54 @@ KUndo2Command *SvgCreateTextStrategy::createCommand()
QRectF rectangle = QRectF(m_dragStart, m_dragEnd).normalized();
- const QFontMetrics fontMetrics = QFontMetrics(tool->defaultFont());
- double ascender = fontMetrics.ascent();
- ascender += fontMetrics.leading()/2;
- ascender = (ascender / fontMetrics.fontDpi()) * 72.0; // 72 points in an inch.
- double lineHeight = (fontMetrics.lineSpacing() / fontMetrics.fontDpi()) * 72.0;
- const KoSvgText::WritingMode writingMode = KoSvgText::WritingMode(tool->writingMode());
+ KoSvgTextProperties properties = tool->propertiesForNewText();
+ KoSvgTextProperties resolvedProperties = properties;
+ resolvedProperties.inheritFrom(KoSvgTextProperties::defaultProperties(), true);
+
+ const KoSvgText::FontMetrics fontMetrics = properties.metrics(true);
+ const qreal ftMultiplier = resolvedProperties.fontSize().value / fontMetrics.fontSize;
+ double ascender = fontMetrics.ascender;
+ ascender += fontMetrics.lineGap/2;
+ ascender *= ftMultiplier;
+ const double lineHeight = m_minSizeInline.width();
+ const KoSvgText::WritingMode writingMode = KoSvgText::WritingMode(properties.propertyOrDefault(KoSvgTextProperties::WritingModeId).toInt());
bool unwrappedText = m_modifiers.testFlag(Qt::ControlModifier);
if (rectangle.width() < m_minSizeInline.width() && rectangle.height() < m_minSizeInline.height()) {
unwrappedText = true;
}
- QString extraProperties;
if (!unwrappedText) {
- if (writingMode == KoSvgText::HorizontalTB) {
- extraProperties = QLatin1String("inline-size:%1;").arg(QString::number(rectangle.width()));
- } else {
- extraProperties = QLatin1String("inline-size:%1;").arg(QString::number(rectangle.height()));
- }
+ KoSvgText::AutoValue val;
+ val.isAuto = false;
+ val.customValue = writingMode == KoSvgText::HorizontalTB? rectangle.width(): rectangle.height();
+ properties.setProperty(KoSvgTextProperties::InlineSizeId, QVariant::fromValue(val));
}
+ if (writingMode != KoSvgText::HorizontalTB) {
+ properties.setProperty(KoSvgTextProperties::TextOrientationId, KoSvgText::OrientationUpright);
+ }
+ // Ensure white space is set to pre-wrap if unspecified.
+ if (!properties.hasProperty(KoSvgTextProperties::TextCollapseId)) {
+ properties.setProperty(KoSvgTextProperties::TextCollapseId, KoSvgText::Preserve);
+ }
+ if (!properties.hasProperty(KoSvgTextProperties::TextWrapId)) {
+ properties.setProperty(KoSvgTextProperties::TextWrapId, KoSvgText::Wrap);
+ }
+
KoShapeFactoryBase *factory = KoShapeRegistry::instance()->value("KoSvgTextShapeID");
KoProperties *params = new KoProperties();//Fill these with "svgText", "defs" and "shapeRect"
- params->setProperty("defs", QVariant(tool->generateDefs(extraProperties)));
+ params->setProperty("defs", QVariant(tool->generateDefs(properties)));
QPointF origin = rectangle.topLeft();
{
- const Qt::Alignment halign = tool->horizontalAlign();
- const bool isRtl = tool->isRtl();
+ const KoSvgText::TextAnchor halign = KoSvgText::TextAnchor(properties.propertyOrDefault(KoSvgTextProperties::TextAnchorId).toInt());
+ const bool isRtl = KoSvgText::Direction(properties.propertyOrDefault(KoSvgTextProperties::DirectionId).toInt()) == KoSvgText::DirectionRightToLeft;
if (writingMode == KoSvgText::HorizontalTB) {
origin.setY(rectangle.top() + ascender);
- if (halign & Qt::AlignCenter) {
+ if (halign == KoSvgText::AnchorMiddle) {
origin.setX(rectangle.center().x());
- } else if ((halign & Qt::AlignRight && !isRtl) || (halign & Qt::AlignLeft && isRtl)) {
+ } else if ((halign == KoSvgText::AnchorEnd && !isRtl) || (halign == KoSvgText::AnchorStart && isRtl)) {
origin.setX(rectangle.right());
}
} else {
@@ -102,9 +118,9 @@ KUndo2Command *SvgCreateTextStrategy::createCommand()
origin.setX(rectangle.left() + (lineHeight*0.5));
}
- if (halign & Qt::AlignCenter) {
+ if (halign == KoSvgText::AnchorMiddle) {
origin.setY(rectangle.center().y());
- } else if (halign & Qt::AlignRight) {
+ } else if (halign == KoSvgText::AnchorEnd) {
origin.setY(rectangle.bottom());
}
}
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.cpp b/plugins/tools/svgtexttool/SvgTextCursor.cpp
index 80102832aa..7e0a63e37b 100644
--- a/plugins/tools/svgtexttool/SvgTextCursor.cpp
+++ b/plugins/tools/svgtexttool/SvgTextCursor.cpp
@@ -203,6 +203,11 @@ void SvgTextCursor::setVisualMode(bool visualMode)
d->visualNavigation = visualMode;
}
+void SvgTextCursor::setPasteRichTextByDefault(const bool pasteRichText)
+{
+ d->pasteRichText = pasteRichText;
+}
+
int SvgTextCursor::getPos()
{
return d->pos;
@@ -1516,5 +1521,8 @@ bool SvgTextCursorPropertyInterface::spanSelection()
void SvgTextCursorPropertyInterface::emitSelectionChange()
{
+ // Don't bother updating the selection when there's no shape
+ // this is so we can use the text properties last used to create new texts.
+ if (d->parent->shape()) return;
d->compressor.start();
}
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.h b/plugins/tools/svgtexttool/SvgTextCursor.h
index 57ae084143..7a64543dab 100644
--- a/plugins/tools/svgtexttool/SvgTextCursor.h
+++ b/plugins/tools/svgtexttool/SvgTextCursor.h
@@ -95,7 +95,13 @@ public:
* This right now primarily affects Bidirectional text.
* @param mode whether to turn off visual mode.
*/
- void setVisualMode(bool visualMode = true);
+ void setVisualMode(const bool visualMode = true);
+
+ /**
+ * @brief setPasteRichText
+ * @param pasteRichText -- whether to paste rich text when possible.
+ */
+ void setPasteRichTextByDefault(const bool pasteRichText = true);
/// Get the current position.
int getPos();
diff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cpp
index 9ac4551068..3725328f68 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.cpp
+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp
@@ -21,16 +21,14 @@
#include "SvgTextRemoveCommand.h"
#include "SvgConvertTextTypeCommand.h"
#include "SvgTextShortCuts.h"
+#include "SvgTextToolOptionsModel.h"
#include <QPainterPath>
-#include <QGridLayout>
-#include <QVBoxLayout>
#include <QDesktopServices>
#include <QApplication>
-#include <QGroupBox>
-#include <QFontDatabase>
-#include <QButtonGroup>
-#include <QMenuBar>
+#include <QStyle>
+#include <QDockWidget>
+#include <QQuickItem>
#include <klocalizedstring.h>
@@ -57,8 +55,17 @@
#include <KoPathShape.h>
#include <KoPathSegment.h>
-#include <KisViewManager.h>
+#include <KisResourceModelProvider.h>
+#include <KoCssStylePreset.h>
+#include <KoSvgTextPropertyData.h>
+#include <KoColorBackground.h>
+#include <KisResourceModel.h>
+
#include <KisTextPropertiesManager.h>
+#include <KisViewManager.h>
+#include <KisQQuickWidget.h>
+#include <QQmlError>
+#include <KisMainWindow.h>
#include "KisHandlePainterHelper.h"
#include "kis_tool_utils.h"
@@ -83,6 +90,7 @@ static bool debugEnabled()
SvgTextTool::SvgTextTool(KoCanvasBase *canvas)
: KoToolBase(canvas)
, m_textCursor(canvas)
+ , m_optionManager(new SvgTextToolOptionsManager(this))
{
// TODO: figure out whether we should use system config for this, Windows and GTK have values for it, but Qt and MacOS don't(?).
int cursorFlashLimit = 5000;
@@ -123,10 +131,6 @@ SvgTextTool::~SvgTextTool()
if(m_glyphPalette) {
m_glyphPalette->close();
}
- delete m_defAlignment;
- delete m_defWritingMode;
- delete m_defDirection;
- delete m_convertType;
}
void SvgTextTool::activate(const QSet<KoShape *> &shapes)
@@ -137,6 +141,10 @@ void SvgTextTool::activate(const QSet<KoShape *> &shapes)
const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());
if (canvas2) {
canvas2->viewManager()->textPropertyManager()->setTextPropertiesInterface(m_textCursor.textPropertyInterface());
+ QDockWidget *docker = canvas2->viewManager()->mainWindow()->dockWidget("TextProperties");
+ if (docker && m_optionManager) {
+ m_optionManager->setTextPropertiesOpen(docker->isVisible());
+ }
}
useCursor(m_base_cursor);
@@ -182,118 +190,36 @@ void SvgTextTool::inputMethodEvent(QInputMethodEvent *event)
QWidget *SvgTextTool::createOptionWidget()
{
- QWidget *optionWidget = new QWidget();
- optionUi.setupUi(optionWidget);
-
- if (!debugEnabled()) {
- optionUi.groupBoxDebug->hide();
- }
-
- m_configGroup = KSharedConfig::openConfig()->group(toolId());
-
- QString storedFont = m_configGroup.readEntry<QString>("defaultFont", QApplication::font().family());
- optionUi.defFont->setCurrentFont(QFont(storedFont));
- Q_FOREACH (int size, QFontDatabase::standardSizes()) {
- optionUi.defPointSize->addItem(QString::number(size)+" pt");
- }
- int storedSize = m_configGroup.readEntry<int>("defaultSize", QApplication::font().pointSize());
-#ifdef Q_OS_ANDROID
- // HACK: on some devices where android.R.styleable exists, Qt's platform
- // plugin sets the pixelSize of a font, which returns -1 when asked for pointSize.
- //
- // The way to fetch font in Qt from SDK is deprecated in newer Android versions.
- if (storedSize <= 0) {
- storedSize = 18; // being one of the standardSizes
- }
-#endif
- int sizeIndex = 0;
- if (QFontDatabase::standardSizes().contains(storedSize)) {
- sizeIndex = QFontDatabase::standardSizes().indexOf(storedSize);
- }
- optionUi.defPointSize->setCurrentIndex(sizeIndex);
-
- int checkedAlignment = m_configGroup.readEntry<int>("defaultAlignment", 0);
-
- m_defAlignment = new QButtonGroup();
- optionUi.alignLeft->setIcon(KisIconUtils::loadIcon("format-justify-left"));
- m_defAlignment->addButton(optionUi.alignLeft, 0);
-
- optionUi.alignCenter->setIcon(KisIconUtils::loadIcon("format-justify-center"));
- m_defAlignment->addButton(optionUi.alignCenter, 1);
+ KisQQuickWidget *optionWidget = new KisQQuickWidget();
+ optionWidget->setMinimumWidth(100);
+ optionWidget->setMinimumHeight(100);
- optionUi.alignRight->setIcon(KisIconUtils::loadIcon("format-justify-right"));
- m_defAlignment->addButton(optionUi.alignRight, 2);
+ optionWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
+ optionWidget->setSource(QUrl("qrc:/SvgTextToolOptions.qml"));
- m_defAlignment->setExclusive(true);
- if (checkedAlignment<1) {
- optionUi.alignLeft->setChecked(true);
- } else if (checkedAlignment==1) {
- optionUi.alignCenter->setChecked(true);
- } else if (checkedAlignment==2) {
- optionUi.alignRight->setChecked(true);
+ m_optionManager->setShowDebug(debugEnabled());
+ if (optionWidget->errors().isEmpty()) {
+ optionWidget->rootObject()->setProperty("manager", QVariant::fromValue(m_optionManager.data()));
+ optionWidget->connectMinimumHeightToRootObject();
} else {
- optionUi.alignLeft->setChecked(true);
+ qWarning() << optionWidget->errors();
}
- int checkedWritingMode = m_configGroup.readEntry<int>("defaultWritingMode", 0);
- m_defWritingMode = new QButtonGroup();
- optionUi.modeHorizontalTb->setIcon(KisIconUtils::loadIcon("format-text-direction-horizontal-tb"));
- m_defWritingMode->addButton(optionUi.modeHorizontalTb, 0);
+ connect(m_optionManager.data(), SIGNAL(openTextEditor()), SLOT(showEditor()));
+ connect(m_optionManager.data(), SIGNAL(openGlyphPalette()), SLOT(showGlyphPalette()));
- optionUi.modeVerticalRl->setIcon(KisIconUtils::loadIcon("format-text-direction-vertical-rl"));
- m_defWritingMode->addButton(optionUi.modeVerticalRl, 1);
-
- optionUi.modeVerticalLr->setIcon(KisIconUtils::loadIcon("format-text-direction-vertical-lr"));
- m_defWritingMode->addButton(optionUi.modeVerticalLr, 2);
-
- m_defWritingMode->setExclusive(true);
- if (checkedWritingMode<1) {
- optionUi.modeHorizontalTb->setChecked(true);
- } else if (checkedWritingMode==1) {
- optionUi.modeVerticalRl->setChecked(true);
- } else if (checkedWritingMode==2) {
- optionUi.modeVerticalLr->setChecked(true);
- } else {
- optionUi.modeHorizontalTb->setChecked(true);
+ connect(m_optionManager.data(), SIGNAL(convertTextType(int)), SLOT(slotConvertType(int)));
+ connect(m_optionManager->optionsModel(), SIGNAL(useVisualBidiCursorChanged(bool)), this, SLOT(slotUpdateVisualCursor()));
+ connect(m_optionManager->optionsModel(), SIGNAL(pasteRichtTextByDefaultChanged(bool)), this, SLOT(slotUpdateTextPasteBehaviour()));
+ const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());
+ if (canvas2 && canvas2->viewManager()->mainWindow()) {
+ QDockWidget *docker = canvas2->viewManager()->mainWindow()->dockWidget("TextProperties");
+ m_optionManager->setShowTextPropertyButton((docker));
+ connect(m_optionManager.data(), SIGNAL(openTextPropertiesDocker(bool)), docker, SLOT(setVisible(bool)));
}
-
- bool rtl = m_configGroup.readEntry<int>("defaultWritingDirection", false);
- m_defDirection = new QButtonGroup();
-
- optionUi.directionLtr->setIcon(KisIconUtils::loadIcon("format-text-direction-ltr"));
- m_defDirection->addButton(optionUi.directionLtr, 0);
-
- optionUi.directionRtl->setIcon(KisIconUtils::loadIcon("format-text-direction-rtl"));
- m_defDirection->addButton(optionUi.directionRtl, 1);
- m_defDirection->setExclusive(true);
- optionUi.directionLtr->setChecked(!rtl);
- optionUi.directionRtl->setChecked(rtl);
-
- bool directionEnabled = !bool(m_defWritingMode->checkedId());
- optionUi.directionLtr->setEnabled(directionEnabled);
- optionUi.directionRtl->setEnabled(directionEnabled);
-
- double storedLetterSpacing = m_configGroup.readEntry<double>("defaultLetterSpacing", 0.0);
- optionUi.defLetterSpacing->setValue(storedLetterSpacing);
-
- connect(m_defAlignment, SIGNAL(idClicked(int)), this, SLOT(storeDefaults()));
- connect(m_defWritingMode, SIGNAL(idClicked(int)), this, SLOT(storeDefaults()));
- connect(m_defDirection, SIGNAL(idClicked(int)), this, SLOT(storeDefaults()));
-
- connect(optionUi.defFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(storeDefaults()));
- connect(optionUi.defPointSize, SIGNAL(currentIndexChanged(int)), this, SLOT(storeDefaults()));
- connect(optionUi.defLetterSpacing, SIGNAL(valueChanged(double)), SLOT(storeDefaults()));
-
- connect(optionUi.btnEditSvg, SIGNAL(clicked(bool)), SLOT(showEditor()));
- connect(optionUi.btnGlyphPalette, SIGNAL(clicked(bool)), SLOT(showGlyphPalette()));
-
- m_convertType = new QButtonGroup();
- m_convertType->setExclusive(true);
- m_convertType->addButton(optionUi.convertPreFormatBtn, KoSvgTextShape::PreformattedText);
- m_convertType->addButton(optionUi.convertInlineBtn, KoSvgTextShape::InlineWrap);
- m_convertType->addButton(optionUi.convertToSvg1_1, KoSvgTextShape::PrePositionedText);
- connect(m_convertType, SIGNAL(idClicked(int)), this, SLOT(slotConvertType(int)));
+ slotUpdateVisualCursor();
+ slotUpdateTextPasteBehaviour();
slotTextTypeUpdated();
return optionWidget;
@@ -401,52 +327,49 @@ void SvgTextTool::slotTextEditorClosed()
KoToolManager::instance()->switchToolRequested("InteractionTool");
}
-QString SvgTextTool::generateDefs(const QString &extraProperties)
+QString SvgTextTool::generateDefs(const KoSvgTextProperties &properties)
{
- QString font = optionUi.defFont->currentFont().family();
- QString size = QString::number(QFontDatabase::standardSizes().at(optionUi.defPointSize->currentIndex() > -1 ? optionUi.defPointSize->currentIndex() : 0));
-
- QString textAnchor = "middle";
- if (m_defAlignment->button(0)->isChecked()) {
- textAnchor = "start";
+ QStringList propStrings;
+ QMap<QString, QString> paraProps = properties.convertParagraphProperties();
+ for (auto it = paraProps.constBegin(); it != paraProps.constEnd(); it++) {
+ propStrings.append(QString("%1: %2;").arg(it.key()).arg(it.value()));
}
- if (m_defAlignment->button(2)->isChecked()) {
- textAnchor = "end";
+ paraProps = properties.convertToSvgTextAttributes();
+ for (auto it = paraProps.constBegin(); it != paraProps.constEnd(); it++) {
+ propStrings.append(QString("%1: %2;").arg(it.key()).arg(it.value()));
}
- QString direction = "ltr";
- QString writingMode = "horizontal-tb";
- QString textOrientation = "text-orientation: upright";
- if (m_defWritingMode->button(1)->isChecked()) {
- writingMode = "vertical-rl;" + textOrientation;
- } else if (m_defWritingMode->button(2)->isChecked()) {
- writingMode = "vertical-lr;" + textOrientation;
+ return QString("<defs>\n <style>\n text {\n %1\n }\n </style>\n</defs>").arg(propStrings.join("\n "));
+}
+
+KoSvgTextProperties SvgTextTool::propertiesForNewText() const
+{
+ const bool useCurrent = m_optionManager->optionsModel()->useCurrentTextProperties();
+ const QString presetName = m_optionManager->optionsModel()->cssStylePresetName();
+
+ KoSvgTextProperties props;
+ if (useCurrent || presetName.isEmpty()) {
+ KoSvgTextPropertyData textData = canvas()->resourceManager()->resource(KoCanvasResource::SvgTextPropertyData).value<KoSvgTextPropertyData>();
+ props = textData.commonProperties;
} else {
- direction = m_defDirection->button(0)->isChecked()? "ltr" : "rtl";
+ KisAllResourcesModel *model = KisResourceModelProvider::resourceModel(ResourceType::CssStyles);
+ QVector<KoResourceSP> res = model->resourcesForName(presetName);
+ if (res.first()) {
+ KoCssStylePresetSP style = res.first().staticCast<KoCssStylePreset>();
+ if (style) {
+ props = style->properties();
+ }
+ }
}
- QString fontColor = (canvas()->resourceManager()->isUsingOtherColor()
+ QColor fontColor = (canvas()->resourceManager()->isUsingOtherColor()
? canvas()->resourceManager()->backgroundColor()
- : canvas()->resourceManager()->foregroundColor()).toQColor().name();
- QString letterSpacing = QString::number(optionUi.defLetterSpacing->value());
-
- return QString("<defs>\n <style>\n text {\n font-family:'%1';\n font-size:%2 ; fill:%3 ; text-anchor:%4; letter-spacing:%5; writing-mode:%6; direction: %7; %8\n white-space:pre-wrap;\n }\n </style>\n</defs>")
- .arg(font, size, fontColor, textAnchor, letterSpacing, writingMode, direction, extraProperties);
-}
-
-void SvgTextTool::storeDefaults()
-{
- m_configGroup = KSharedConfig::openConfig()->group(toolId());
- m_configGroup.writeEntry("defaultFont", optionUi.defFont->currentFont().family());
- m_configGroup.writeEntry("defaultSize", QFontDatabase::standardSizes().at(optionUi.defPointSize->currentIndex() > -1 ? optionUi.defPointSize->currentIndex() : 0));
- m_configGroup.writeEntry("defaultAlignment", m_defAlignment->checkedId());
- m_configGroup.writeEntry("defaultLetterSpacing", optionUi.defLetterSpacing->value());
- m_configGroup.writeEntry("defaultWritingMode", m_defWritingMode->checkedId());
- m_configGroup.writeEntry("defaultWritingDirection", m_defDirection->checkedId());
-
- bool directionEnabled = !bool(m_defWritingMode->checkedId());
- optionUi.directionLtr->setEnabled(directionEnabled);
- optionUi.directionRtl->setEnabled(directionEnabled);
+ : canvas()->resourceManager()->foregroundColor()).toQColor();
+ QSharedPointer<KoColorBackground> bg(new KoColorBackground());
+ bg->setColor(fontColor);
+ KoSvgText::BackgroundProperty bgProp(bg);
+ props.setProperty(KoSvgTextProperties::FillId, QVariant::fromValue(bgProp));
+ return props;
}
void SvgTextTool::slotShapeSelectionChanged()
@@ -555,21 +478,6 @@ void SvgTextTool::slotUpdateCursorDecoration(QRectF updateRect)
}
}
-void SvgTextTool::slotTextTypeUpdated()
-{
- if (!m_convertType) return;
- if (selectedShape()) {
- KoSvgTextShape::TextType type = selectedShape()->textType();
- if (m_convertType->button(type)) {
- m_convertType->button(type)->setChecked(true);
- } else {
- Q_FOREACH(QAbstractButton *button, m_convertType->buttons()) {
- button->setChecked(false);
- }
- }
- }
-}
-
void SvgTextTool::slotConvertType(int index) {
if (selectedShape()) {
if (index == selectedShape()->textType()) return;
@@ -589,33 +497,24 @@ void SvgTextTool::slotConvertType(int index) {
}
}
-QFont SvgTextTool::defaultFont() const
-{
- int size = QFontDatabase::standardSizes().at(optionUi.defPointSize->currentIndex() > -1 ? optionUi.defPointSize->currentIndex() : 0);
- QFont font = optionUi.defFont->currentFont();
- font.setPointSize(size);
- return font;
-}
-
-Qt::Alignment SvgTextTool::horizontalAlign() const
+void SvgTextTool::slotUpdateVisualCursor()
{
- if (m_defAlignment->button(1)->isChecked()) {
- return Qt::AlignHCenter;
- }
- if (m_defAlignment->button(2)->isChecked()) {
- return Qt::AlignRight;
- }
- return Qt::AlignLeft;
+ m_textCursor.setVisualMode(m_optionManager->optionsModel()->useVisualBidiCursor());
}
-int SvgTextTool::writingMode() const
+void SvgTextTool::slotUpdateTextPasteBehaviour()
{
- return m_defWritingMode->checkedId();
+ m_textCursor.setPasteRichTextByDefault(m_optionManager->optionsModel()->pasteRichtTextByDefault());
}
-bool SvgTextTool::isRtl() const
+void SvgTextTool::slotTextTypeUpdated()
{
- return m_defDirection->checkedId();
+ KoSvgTextShape *shape = selectedShape();
+ if (shape && m_optionManager) {
+ m_optionManager->convertToTextType(int(shape->textType()));
+ } else {
+ m_optionManager->convertToTextType(-1);
+ }
}
QRectF SvgTextTool::decorationsRect() const
@@ -721,10 +620,10 @@ void SvgTextTool::paint(QPainter &gc, const KoViewConverter &converter)
gc.save();
using Element = KoSvgTextShape::DebugElement;
KoSvgTextShape::DebugElements el{};
- if (optionUi.chkDbgCharBbox->isChecked()) {
+ if (m_optionManager->showCharacterDebug()) {
el |= Element::CharBbox;
}
- if (optionUi.chkDbgLineBox->isChecked()) {
+ if (m_optionManager->showLineDebug()) {
el |= Element::LineBox;
}
@@ -1036,3 +935,9 @@ qreal SvgTextTool::grabSensitivityInPt() const
return canvas()->viewConverter()->viewToDocumentX(sensitivity);
}
+KoSvgText::WritingMode SvgTextTool::writingMode() const
+{
+ KoSvgTextProperties props = propertiesForNewText();
+ return KoSvgText::WritingMode(props.propertyOrDefault(KoSvgTextProperties::WritingModeId).toInt());
+}
+
diff --git a/plugins/tools/svgtexttool/SvgTextTool.h b/plugins/tools/svgtexttool/SvgTextTool.h
index 7f41b4aceb..5299a31253 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.h
+++ b/plugins/tools/svgtexttool/SvgTextTool.h
@@ -8,17 +8,15 @@
#ifndef SVG_TEXT_TOOL
#define SVG_TEXT_TOOL
-#include "ui_WdgSvgTextOptionWidget.h"
#include <KConfigGroup>
#include <KoToolBase.h>
-#include <QFontComboBox>
#include <QPointer>
-#include <QDoubleSpinBox>
#include <kis_signal_auto_connection.h>
#include "SvgTextCursor.h"
+#include "SvgTextToolOptionsManager.h"
#include "glyphpalette/GlyphPaletteDialog.h"
#include <memory>
@@ -98,10 +96,7 @@ protected:
private:
qreal grabSensitivityInPt() const;
- QFont defaultFont() const;
- Qt::Alignment horizontalAlign() const;
- int writingMode() const;
- bool isRtl() const;
+ KoSvgText::WritingMode writingMode() const;
private Q_SLOTS:
@@ -130,17 +125,15 @@ private Q_SLOTS:
/**
* @brief generateDefs
* This generates a defs section with the appropriate
- * css and css strings assigned. This allows the artist
- * to select settings that new texts will be created with.
- * @return a string containing the defs.
+ * css and css strings assigned.
*/
- QString generateDefs(const QString &extraProperties = QString());
+ QString generateDefs(const KoSvgTextProperties &properties = KoSvgTextProperties());
/**
- * @brief storeDefaults
- * store default font and point size when they change.
+ * @brief propertiesForNewText
+ * get the text properties that should be used for new text.
*/
- void storeDefaults();
+ KoSvgTextProperties propertiesForNewText() const;
/**
* @brief selectionChanged
@@ -155,9 +148,29 @@ private Q_SLOTS:
*/
void slotUpdateCursorDecoration(QRectF updateRect);
- void slotTextTypeUpdated();
+ /**
+ * @brief slotConvertType
+ * @param index
+ */
void slotConvertType(int index);
+ /**
+ * @brief slotUpdateVisualCursor
+ * update the visual cursor mode on the text cursor.
+ */
+ void slotUpdateVisualCursor();
+
+ /**
+ * @brief slotUpdateTextPasteBehaviour
+ * update the default text paste behaviour.
+ */
+ void slotUpdateTextPasteBehaviour();
+
+ /**
+ * @brief slotTextTypeUpdated
+ * Update the text type in the tool options.
+ */
+ void slotTextTypeUpdated();
private:
enum class DragMode {
@@ -174,6 +187,7 @@ private:
MoveBorder,
};
+ QScopedPointer<SvgTextToolOptionsManager>m_optionManager;
QPointer<SvgTextEditor> m_editor;
QPointer<GlyphPaletteDialog> m_glyphPalette;
QPointF m_lastMousePos;
@@ -182,20 +196,12 @@ private:
HighlightItem m_highlightItem {HighlightItem::None};
bool m_strategyAddingCommand {false};
- QButtonGroup *m_defAlignment {nullptr};
- QButtonGroup *m_defWritingMode {nullptr};
- QButtonGroup *m_defDirection {nullptr};
- QButtonGroup *m_convertType {nullptr};
- KConfigGroup m_configGroup;
+
SvgTextCursor m_textCursor;
KisSignalAutoConnectionsStore m_canvasConnections;
-
QPainterPath m_hoveredShapeHighlightRect;
- Ui_WdgSvgTextOptionWidget optionUi;
- bool m_optionUiInitialized {false};
-
QCursor m_base_cursor;
QCursor m_text_inline_horizontal;
QCursor m_text_inline_vertical;
diff --git a/plugins/tools/svgtexttool/SvgTextToolOptions.qml b/plugins/tools/svgtexttool/SvgTextToolOptions.qml
new file mode 100644
index 0000000000..3020bf36db
--- /dev/null
+++ b/plugins/tools/svgtexttool/SvgTextToolOptions.qml
@@ -0,0 +1,304 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+import QtQuick.Layouts 1.15
+import org.krita.tools.text 1.0
+import org.krita.components 1.0 as Kis
+
+Control {
+ id: toolOptionsControl;
+ anchors.fill: parent;
+
+ property SvgTextToolOptionsManager manager: SvgTextToolOptionsManager{};
+
+ onManagerChanged: {
+ updateTextProperties()
+ textType.updateTextTypes();
+ }
+
+ Connections {
+ target: manager;
+ function onTextPropertiesOpenChanged() {
+ updateTextProperties();
+ }
+ function onTextTypeChanged() {
+ textType.updateTextTypes();
+ }
+ }
+
+ Connections {
+ target: manager.optionsModel;
+ function onUseVisualBidiCursorChanged() {
+ chkVisualBidiCursor.checked = manager.optionsModel.useVisualBidiCursor;
+ }
+ function onPasteRichtTextByDefaultChanged() {
+ chkPasteRichTextByDefault.checked = manager.optionsModel.pasteRichtTextByDefault;
+ }
+ function onCssStylePresetNameChanged() {
+ // todo;
+ }
+ function onUseCurrentTextPropertiesChanged() {
+ chkCurrentProperties.checked = manager.optionsModel.useCurrentTextProperties;
+ }
+ }
+
+ function updateTextProperties() {
+ btnTextProperties.checked = manager.textPropertiesOpen;
+ }
+
+ Kis.ThemedControl {
+ id: themedControl;
+ }
+ palette: themedControl.palette;
+ contentItem: ColumnLayout {
+ id: childColumn;
+ width: parent.width;
+
+ Label {
+ text: i18nc("@label:group", "Create New Texts with...");
+ Layout.fillWidth: true;
+ }
+
+ CheckBox {
+ id: chkCurrentProperties;
+ text: i18nc("@option:check", "Current Text Properties");
+ checked: manager.optionsModel.useCurrentTextProperties;
+ onCheckedChanged: {
+ manager.optionsModel.useCurrentTextProperties = checked;
+ }
+ Layout.fillWidth: true;
+ hoverEnabled: true;
+ Kis.ToolTipBase {
+ parent: chkCurrentProperties;
+ text: i18nc("@info:tooltip", "Use the current properties in the text properties docker to create new texts.");
+ visible: parent.hovered;
+ }
+ }
+
+ Button {
+ id: btnSelectCssStylePreset;
+ enabled: !chkCurrentProperties.checked;
+ text: "placeholder style presets";
+ Layout.fillWidth: true;
+ // TODO: write KoCssStylePreset thing here.
+ }
+
+ Kis.ToolSeparatorBase {
+ orientation: Qt.Horizontal;
+ Layout.fillWidth: true;
+ }
+
+ Button {
+ id: btnTextProperties;
+ text: i18nc("@label:button", "Open Text Properties");
+ checkable: true;
+ hoverEnabled: true;
+ onCheckedChanged: {
+ manager.textPropertiesOpen = checked;
+ }
+ visible: manager.showTextPropertyButton;
+ height: visible? implicitHeight: 0;
+ Layout.fillWidth: true;
+
+ Kis.ToolTipBase {
+ parent: btnTextProperties;
+ text: i18nc("@info:tooltip", "Open the Text Properties Docker to edit properties like font size and style.");
+ visible: parent.hovered;
+ }
+ }
+ Kis.ToolSeparatorBase {
+ orientation: Qt.Horizontal;
+ Layout.fillWidth: true;
+ }
+
+ Label {
+ text: i18nc("@label:group", "Options");
+ Layout.fillWidth: true;
+ }
+
+ CheckBox {
+ id: chkVisualBidiCursor;
+ text: i18nc("@option:check", "Use Visual Cursor");
+ checked: manager.optionsModel.useVisualBidiCursor;
+ onCheckedChanged: {
+ manager.optionsModel.useVisualBidiCursor = checked;
+ }
+ Kis.ToolTipBase {
+ parent: chkVisualBidiCursor;
+ text: i18nc("@info:tooltip", "Use the visual order for bidirectional text.");
+ visible: parent.hovered;
+ }
+ hoverEnabled: true;
+ Layout.fillWidth: true;
+ }
+
+ CheckBox {
+ id: chkPasteRichTextByDefault;
+ text: i18nc("@option:check", "Paste Rich Text by Default");
+ checked: manager.optionsModel.pasteRichtTextByDefault;
+ onCheckedChanged: {
+ manager.optionsModel.pasteRichtTextByDefault = checked;
+ }
+ Kis.ToolTipBase {
+ parent: chkPasteRichTextByDefault;
+ text: i18nc("@info:tooltip", "Always paste rich text when using paste action.");
+ visible: parent.hovered;
+ }
+ hoverEnabled: true;
+ Layout.fillWidth: true;
+ }
+
+ Kis.ToolSeparatorBase {
+ orientation: Qt.Horizontal;
+ Layout.fillWidth: true;
+ }
+
+ Label {
+ text: i18nc("@label:group", "Dialogs");
+ }
+
+ Button {
+ id: btnEditSource;
+ text: i18nc("@label:button", "Edit SVG Source");
+ onClicked: {
+ manager.emitOpenTextEditor();
+ }
+ Layout.fillWidth: true;
+ hoverEnabled: true;
+ Kis.ToolTipBase {
+ parent: btnEditSource;
+ text: i18nc("@info:tooltip", "Edit the currently selected text as SVG XML.");
+ visible: parent.hovered;
+ }
+ }
+ Button {
+ id: btnGlyphPalette;
+ text: i18nc("@label:button", "Glyph Palette");
+ onClicked: {
+ manager.emitGlyphPalette();
+ }
+ Layout.fillWidth: true;
+ hoverEnabled: true;
+ Kis.ToolTipBase {
+ parent: btnGlyphPalette;
+ text: i18nc("@info:tooltip", "Open the Glyph Palette, which provides access to alternative OpenType or Unicode Variations of glyphs, as well as a Character Map.");
+ visible: parent.hovered;
+ }
+ palette: themedControl.palette;
+ }
+
+ Kis.ToolSeparatorBase {
+ orientation: Qt.Horizontal;
+ Layout.fillWidth: true;
+ }
+ Label {
+ text: i18nc("@label:group", "Convert Type...");
+ }
+
+ ButtonGroup {
+ id: textType;
+
+ exclusive: true;
+ function updateTextTypes() {
+ btnPreFormatted.checked = (manager.textType === btnPreFormatted.type);
+ btnInlineWrapped.checked = (manager.textType === btnInlineWrapped.type);
+ btnPrepositioned.checked = (manager.textType === btnPrepositioned.type);
+
+ if (manager.textType < 0) {
+ btnPreFormatted.enabled = false;
+ btnInlineWrapped.enabled = false;
+ btnPrepositioned.enabled = false;
+ } else {
+ btnPreFormatted.enabled = true;
+ btnInlineWrapped.enabled = true;
+ btnPrepositioned.enabled = true;
+ }
+ }
+ }
+
+ Button {
+ id: btnPreFormatted;
+ property int type: SvgTextToolOptionsManager.PreformattedText;
+ text: i18nc("@label:button", "Preformatted");
+ Layout.fillWidth: true;
+ ButtonGroup.group: textType;
+ onClicked: manager.textType = type;
+ hoverEnabled: true;
+ Kis.ToolTipBase {
+ parent: btnPreFormatted;
+ text: i18nc("@info:tooltip", "The text will not wrap and preserves spaces and new lines. A line break is inserted so the lines from wrapping or positioning remain separated.");
+ visible: parent.hovered;
+ }
+ Kis.ThemedControl {
+ id: convertButtonPalette;
+ }
+ palette: convertButtonPalette.palette;
+ }
+ Button {
+ id: btnInlineWrapped;
+ text: i18nc("@label:button", "Inline Wrapped");
+ property int type: SvgTextToolOptionsManager.InlineWrap;
+ Layout.fillWidth: true;
+ ButtonGroup.group: textType;
+ onClicked: manager.textType = type;
+ hoverEnabled: true;
+ Kis.ToolTipBase {
+ parent: btnInlineWrapped;
+ text: i18nc("@info:tooltip", "Text wraps inside a fixed length, spaces and new lines are preserved. New lines are not removed.");
+ visible: parent.hovered;
+ }
+ palette: convertButtonPalette.palette;
+ }
+ Button {
+ id: btnPrepositioned;
+ text: i18nc("@label:button", "Prepositioned");
+ property int type: SvgTextToolOptionsManager.PrePositionedText;
+ Layout.fillWidth: true;
+ ButtonGroup.group: textType;
+ onClicked: manager.textType = type;
+ hoverEnabled: true;
+ Kis.ToolTipBase {
+ parent: btnPrepositioned;
+ text: i18nc("@info:tooltip", "Text uses SVG 1.1 character transforms to position each line. Spaces and new lines are collapsed. This is for backward compatibility with SVG 1.1.");
+ visible: parent.hovered;
+ }
+ palette: convertButtonPalette.palette;
+ }
+
+ Kis.ToolSeparatorBase {
+ orientation: Qt.Horizontal;
+ Layout.fillWidth: true;
+ visible: manager.showDebug;
+ }
+ Label {
+ text: i18nc("@label:group", "Debug");
+ visible: manager.showDebug;
+ }
+
+ CheckBox {
+ id: chkDebugCharacter;
+ text: i18nc("@option:check", "Show Char Bounding Boxes");
+ checked: manager.showCharacterDebug;
+ onCheckedChanged: {
+ manager.showCharacterDebug = checked;
+ }
+ Layout.fillWidth: true;
+ visible: manager.showDebug;
+ }
+ CheckBox {
+ id: chkDebugLine;
+ text: i18nc("@option:check", "Show Line Boxes");
+ checked: manager.showLineDebug;
+ onCheckedChanged: {
+ manager.showLineDebug = checked;
+ }
+ Layout.fillWidth: true;
+ visible: manager.showDebug;
+ }
+
+ }
+}
diff --git a/plugins/tools/svgtexttool/SvgTextToolOptionsData.cpp b/plugins/tools/svgtexttool/SvgTextToolOptionsData.cpp
new file mode 100644
index 0000000000..8dfcf6a643
--- /dev/null
+++ b/plugins/tools/svgtexttool/SvgTextToolOptionsData.cpp
@@ -0,0 +1,40 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+#include "SvgTextToolOptionsData.h"
+
+#include <KSharedConfig>
+#include <KConfigGroup>
+
+const QString USE_CURRENT_TEXT_PROPERTIES = "useCurrentTextProperties";
+const QString CSS_STYLE_PRESET_NAME = "cssStylePresetName";
+const QString USE_VISUAL_BIDI_CURSOR = "useVisualBidiCursor";
+const QString PASTE_RICH_TEXT_BY_DEFAULT = "pasteRichtTextByDefault";
+
+void SvgTextToolOptionsData::writeConfig(const QString &toolId)
+{
+ KConfigGroup configGroup = KSharedConfig::openConfig()->group(toolId);
+ configGroup.writeEntry(USE_CURRENT_TEXT_PROPERTIES, useCurrentTextProperties);
+ configGroup.writeEntry(CSS_STYLE_PRESET_NAME, cssStylePresetName);
+ configGroup.writeEntry(USE_VISUAL_BIDI_CURSOR, useVisualBidiCursor);
+ configGroup.writeEntry(PASTE_RICH_TEXT_BY_DEFAULT, pasteRichtTextByDefault);
+}
+
+void SvgTextToolOptionsData::loadConfig(const QString &toolId)
+{
+ KConfigGroup configGroup = KSharedConfig::openConfig()->group(toolId);
+ useCurrentTextProperties = configGroup.readEntry<bool>(USE_CURRENT_TEXT_PROPERTIES, true);
+ cssStylePresetName = configGroup.readEntry<QString>(CSS_STYLE_PRESET_NAME, QString());
+ useVisualBidiCursor = configGroup.readEntry<bool>(USE_VISUAL_BIDI_CURSOR, false);
+ pasteRichtTextByDefault = configGroup.readEntry<bool>(PASTE_RICH_TEXT_BY_DEFAULT, false);
+}
+
+void SvgTextToolOptionsData::resetConfig()
+{
+ useCurrentTextProperties = true;
+ cssStylePresetName = QString();
+ useVisualBidiCursor = false;
+ pasteRichtTextByDefault = false;
+}
diff --git a/plugins/tools/svgtexttool/SvgTextToolOptionsData.h b/plugins/tools/svgtexttool/SvgTextToolOptionsData.h
new file mode 100644
index 0000000000..5ab0bcb9b7
--- /dev/null
+++ b/plugins/tools/svgtexttool/SvgTextToolOptionsData.h
@@ -0,0 +1,25 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+#ifndef SVGTEXTTOOLOPTIONSDATA_H
+#define SVGTEXTTOOLOPTIONSDATA_H
+
+#include <QString>
+
+struct SvgTextToolOptionsData
+{
+ bool useCurrentTextProperties = true;
+ QString cssStylePresetName = QString();
+
+ bool useVisualBidiCursor = false;
+
+ bool pasteRichtTextByDefault = false;
+
+ void writeConfig(const QString &toolId);
+ void loadConfig(const QString &toolId);
+ void resetConfig();
+};
+
+#endif // SVGTEXTTOOLOPTIONSDATA_H
diff --git a/plugins/tools/svgtexttool/SvgTextToolOptionsManager.cpp b/plugins/tools/svgtexttool/SvgTextToolOptionsManager.cpp
new file mode 100644
index 0000000000..a45532ca41
--- /dev/null
+++ b/plugins/tools/svgtexttool/SvgTextToolOptionsManager.cpp
@@ -0,0 +1,125 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+#include "SvgTextToolOptionsManager.h"
+
+struct SvgTextToolOptionsManager::Private
+{
+ SvgTextToolOptionsModel *model{new SvgTextToolOptionsModel()};
+
+ bool showDebug = false;
+ bool showCharacterDebug = true;
+ bool showLineDebug = false;
+
+ int textType = 0;
+
+ bool textPropertiesDockerOpen = false;
+ bool showTextPropertyButton = false;
+};
+
+SvgTextToolOptionsManager::SvgTextToolOptionsManager(QObject *parent)
+ : QObject(parent)
+ , d(new Private)
+{
+
+}
+
+SvgTextToolOptionsManager::~SvgTextToolOptionsManager()
+{
+
+}
+
+SvgTextToolOptionsModel *SvgTextToolOptionsManager::optionsModel() const
+{
+ return d->model;
+}
+
+void SvgTextToolOptionsManager::setOptionsModel(SvgTextToolOptionsModel *model)
+{
+ if (d->model == model) return;
+ d->model = model;
+ Q_EMIT optionsModelChanged();
+}
+
+bool SvgTextToolOptionsManager::showDebug() const
+{
+ return d->showDebug;
+}
+
+void SvgTextToolOptionsManager::setShowDebug(const bool show)
+{
+ if (d->showDebug == show) return;
+ d->showDebug = show;
+ Q_EMIT showDebugChanged();
+}
+
+bool SvgTextToolOptionsManager::showCharacterDebug() const
+{
+ return d->showCharacterDebug;
+}
+
+void SvgTextToolOptionsManager::setShowCharacterDebug(const bool show)
+{
+ if (d->showCharacterDebug == show) return;
+ d->showCharacterDebug = show;
+ Q_EMIT showDebugCharacterChanged();
+}
+
+bool SvgTextToolOptionsManager::showLineDebug() const
+{
+ return d->showLineDebug;
+}
+
+void SvgTextToolOptionsManager::setShowLineDebug(const bool show)
+{
+ if (d->showLineDebug == show) return;
+ d->showLineDebug = show;
+ Q_EMIT showLineDebugChanged();
+}
+
+int SvgTextToolOptionsManager::textType() const
+{
+ return d->textType;
+}
+void SvgTextToolOptionsManager::convertToTextType(const int type)
+{
+ if (d->textType == type) return;
+ d->textType = type;
+ Q_EMIT convertTextType(type);
+}
+
+bool SvgTextToolOptionsManager::textPropertiesOpen() const
+{
+ return d->textPropertiesDockerOpen;
+}
+
+void SvgTextToolOptionsManager::setTextPropertiesOpen(const bool open)
+{
+ if (d->textPropertiesDockerOpen == open) return;
+ d->textPropertiesDockerOpen = open;
+ Q_EMIT openTextPropertiesDocker(open);
+}
+
+bool SvgTextToolOptionsManager::showTextPropertyButton() const
+{
+ return d->showTextPropertyButton;
+}
+
+void SvgTextToolOptionsManager::setShowTextPropertyButton(const bool show)
+{
+ if (d->showTextPropertyButton == show) return;
+ d->showTextPropertyButton = show;
+ Q_EMIT showTextPropertyButtonChanged();
+}
+
+void SvgTextToolOptionsManager::emitOpenTextEditor()
+{
+ Q_EMIT openTextEditor();
+}
+
+void SvgTextToolOptionsManager::emitGlyphPalette()
+{
+ Q_EMIT openGlyphPalette();
+}
diff --git a/plugins/tools/svgtexttool/SvgTextToolOptionsManager.h b/plugins/tools/svgtexttool/SvgTextToolOptionsManager.h
new file mode 100644
index 0000000000..395c585954
--- /dev/null
+++ b/plugins/tools/svgtexttool/SvgTextToolOptionsManager.h
@@ -0,0 +1,111 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+#ifndef SVGTEXTTOOLOPTIONSOBJECT_H
+#define SVGTEXTTOOLOPTIONSOBJECT_H
+
+#include <QObject>
+#include "SvgTextToolOptionsModel.h"
+/**
+ * @brief The SvgTextToolOptionsManager class
+ *
+ * Class that communicates state changes and signals between SvgTextTool.cpp
+ * and the SvgTextToolOptions.qml file.
+ */
+class SvgTextToolOptionsManager : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(SvgTextToolOptionsModel *optionsModel READ optionsModel WRITE setOptionsModel NOTIFY optionsModelChanged)
+
+ Q_PROPERTY(int textType READ textType WRITE convertToTextType NOTIFY convertTextType)
+ Q_PROPERTY(bool textPropertiesOpen READ textPropertiesOpen WRITE setTextPropertiesOpen NOTIFY openTextPropertiesDocker)
+ Q_PROPERTY(bool showTextPropertyButton READ showTextPropertyButton WRITE setShowTextPropertyButton NOTIFY showTextPropertyButtonChanged)
+
+ /* Debug options */
+ Q_PROPERTY(bool showDebug READ showDebug WRITE setShowDebug NOTIFY showDebugChanged)
+ Q_PROPERTY(bool showCharacterDebug READ showCharacterDebug WRITE setShowCharacterDebug NOTIFY showDebugCharacterChanged)
+ Q_PROPERTY(bool showLineDebug READ showLineDebug WRITE setShowLineDebug NOTIFY showLineDebugChanged)
+
+public:
+ explicit SvgTextToolOptionsManager(QObject *parent = nullptr);
+ ~SvgTextToolOptionsManager();
+
+ /// Sync with KoSvgTextShape::TextType
+ enum TextType {
+ PrePositionedText = 0,
+ PreformattedText,
+ InlineWrap,
+ TextInShape
+ };
+ Q_ENUM(TextType)
+
+ SvgTextToolOptionsModel* optionsModel() const;
+ void setOptionsModel(SvgTextToolOptionsModel *model);
+
+ /* Debug options */
+ bool showDebug() const;
+ void setShowDebug(const bool show);
+
+ bool showCharacterDebug() const;
+ void setShowCharacterDebug(const bool show);
+
+ bool showLineDebug() const;
+ void setShowLineDebug(const bool show);
+
+ /*
+ * typeType handles the conversion from textShapes
+ * to different types, like wrapped, preformatted
+ * and svg 1.1 style positioned text.
+ */
+ int textType() const;
+ void convertToTextType(const int type);
+
+ /**
+ * @brief textPropertiesOpen
+ * @return whether the text properties docker is open.
+ */
+ bool textPropertiesOpen() const;
+ void setTextPropertiesOpen(const bool open);
+
+ /**
+ * @brief showTextPropertyButton
+ * Whether to show the open text properties button.
+ * It is hidden when somehow that docker is missing.
+ */
+ bool showTextPropertyButton() const;
+ void setShowTextPropertyButton(const bool show);
+
+public Q_SLOTS:
+ /**
+ * @brief emitOpenTextEditor
+ * Emit the open text editor signal.
+ */
+ void emitOpenTextEditor();
+ /**
+ * @brief emitGlyphPalette
+ * Emit the open glyph palette signal.
+ */
+ void emitGlyphPalette();
+
+Q_SIGNALS:
+ void optionsModelChanged();
+ void convertTextType(int type);
+ void openTextEditor();
+ void openGlyphPalette();
+
+ void openTextPropertiesDocker(bool open);
+ void showTextPropertyButtonChanged();
+
+ /* Debug options */
+ void showDebugChanged();
+ void showDebugCharacterChanged();
+ void showLineDebugChanged();
+
+private:
+ struct Private;
+ QScopedPointer<Private> d;
+};
+
+#endif // SVGTEXTTOOLOPTIONSOBJECT_H
diff --git a/plugins/tools/svgtexttool/SvgTextToolOptionsModel.cpp b/plugins/tools/svgtexttool/SvgTextToolOptionsModel.cpp
new file mode 100644
index 0000000000..e0ec446cc9
--- /dev/null
+++ b/plugins/tools/svgtexttool/SvgTextToolOptionsModel.cpp
@@ -0,0 +1,41 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+#include "SvgTextToolOptionsModel.h"
+
+const QString SVG_TEXT_TOOL_ID = "SvgTextTool";
+
+SvgTextToolOptionsModel::SvgTextToolOptionsModel(lager::cursor<SvgTextToolOptionsData> _data, QObject *parent)
+ : QObject{parent}
+ , data(_data)
+ , LAGER_QT(useCurrentTextProperties) {data[&SvgTextToolOptionsData::useCurrentTextProperties]}
+ , LAGER_QT(cssStylePresetName) {data[&SvgTextToolOptionsData::cssStylePresetName]}
+ , LAGER_QT(useVisualBidiCursor) {data[&SvgTextToolOptionsData::useVisualBidiCursor]}
+ , LAGER_QT(pasteRichtTextByDefault) {data[&SvgTextToolOptionsData::pasteRichtTextByDefault]}
+{
+ lager::watch(data, std::bind(&SvgTextToolOptionsModel::optionsChanged, this));
+ connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()));
+ loadOptions();
+}
+
+void SvgTextToolOptionsModel::saveOptions()
+{
+ SvgTextToolOptionsData _d = data.get();
+ _d.writeConfig(SVG_TEXT_TOOL_ID);
+}
+
+void SvgTextToolOptionsModel::loadOptions()
+{
+ SvgTextToolOptionsData _d = data.get();
+ _d.loadConfig(SVG_TEXT_TOOL_ID);
+ data.set(_d);
+}
+
+void SvgTextToolOptionsModel::resetOptions()
+{
+ SvgTextToolOptionsData _d = data.get();
+ _d.resetConfig();
+ data.set(_d);
+}
diff --git a/plugins/tools/svgtexttool/SvgTextToolOptionsModel.h b/plugins/tools/svgtexttool/SvgTextToolOptionsModel.h
new file mode 100644
index 0000000000..e70da9b159
--- /dev/null
+++ b/plugins/tools/svgtexttool/SvgTextToolOptionsModel.h
@@ -0,0 +1,36 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+#ifndef SVGTEXTTOOLOPTIONSMODEL_H
+#define SVGTEXTTOOLOPTIONSMODEL_H
+
+#include <QObject>
+#include <lager/cursor.hpp>
+#include <lager/state.hpp>
+#include <lager/extra/qt.hpp>
+#include <SvgTextToolOptionsData.h>
+
+class SvgTextToolOptionsModel : public QObject
+{
+ Q_OBJECT
+public:
+ SvgTextToolOptionsModel(lager::cursor<SvgTextToolOptionsData> _data = lager::make_state(SvgTextToolOptionsData(), lager::automatic_tag{}), QObject *parent = nullptr);
+
+ lager::cursor<SvgTextToolOptionsData> data;
+ LAGER_QT_CURSOR(bool, useCurrentTextProperties);
+ LAGER_QT_CURSOR(QString, cssStylePresetName);
+ LAGER_QT_CURSOR(bool, useVisualBidiCursor);
+ LAGER_QT_CURSOR(bool, pasteRichtTextByDefault);
+
+public Q_SLOTS:
+ void saveOptions();
+ void loadOptions();
+ void resetOptions();
+
+Q_SIGNALS:
+ void optionsChanged();
+};
+
+#endif // SVGTEXTTOOLOPTIONSMODEL_H
diff --git a/plugins/tools/svgtexttool/svgtexttool.qrc b/plugins/tools/svgtexttool/svgtexttool.qrc
index 41fb925849..a6de57b4d1 100644
--- a/plugins/tools/svgtexttool/svgtexttool.qrc
+++ b/plugins/tools/svgtexttool/svgtexttool.qrc
@@ -14,5 +14,6 @@
<file alias="GlyphPalette.qml">glyphpalette/GlyphPalette.qml</file>
<file alias="GlyphDelegate.qml">glyphpalette/GlyphDelegate.qml</file>
<file alias="GlyphPaletteAlts.qml">glyphpalette/GlyphPaletteAlts.qml</file>
+ <file>SvgTextToolOptions.qml</file>
</qresource>
</RCC>
diff --git a/qmlmodules/widgets/KisQQuickWidget.cpp b/qmlmodules/widgets/KisQQuickWidget.cpp
index d799079adc..2d220fbd71 100644
--- a/qmlmodules/widgets/KisQQuickWidget.cpp
+++ b/qmlmodules/widgets/KisQQuickWidget.cpp
@@ -9,6 +9,7 @@
#include <QQmlEngine>
#include <QQmlContext>
#include <QQuickStyle>
+#include <QQuickItem>
#include <QQmlFileSelector>
#include <QFileSelector>
@@ -85,7 +86,37 @@ KisQQuickWidget::~KisQQuickWidget()
setParent(nullptr);
}
+void KisQQuickWidget::connectMinimumHeightToRootObject()
+{
+ if (rootObject()) {
+ connect(rootObject(), SIGNAL(implicitHeightChanged()), this, SLOT(setMinimumHeightFromRoot()));
+ setMinimumHeightFromRoot();
+ }
+}
+
+void KisQQuickWidget::connectMinimumWidthToRootObject()
+{
+ if (rootObject()) {
+ connect(rootObject(), SIGNAL(implicitWidthChanged()), this, SLOT(setMinimumWidthFromRoot()));
+ setMinimumWidthFromRoot();
+ }
+}
+
void KisQQuickWidget::updatePaletteFromConfig()
{
setClearColor(palette().window().color());
}
+
+void KisQQuickWidget::setMinimumHeightFromRoot()
+{
+ if (rootObject()) {
+ setMinimumHeight(rootObject()->implicitHeight());
+ }
+}
+
+void KisQQuickWidget::setMinimumWidthFromRoot()
+{
+ if (rootObject()) {
+ setMinimumWidth(rootObject()->implicitWidth());
+ }
+}
diff --git a/qmlmodules/widgets/KisQQuickWidget.h b/qmlmodules/widgets/KisQQuickWidget.h
index de00dc35e4..23273d7156 100644
--- a/qmlmodules/widgets/KisQQuickWidget.h
+++ b/qmlmodules/widgets/KisQQuickWidget.h
@@ -24,8 +24,26 @@ public:
KisQQuickWidget(QWidget *parent = nullptr);
~KisQQuickWidget();
+
+ /**
+ * @brief connectMinimumHeightToRootObject
+ * By default we scale rootObject to widget, but in some situations we need
+ * the widget to have the minimum required height of the root object. This
+ * sets up a connection that links the minimum height to the root object
+ * implicitHeight.
+ */
+ void connectMinimumHeightToRootObject();
+ /**
+ * @brief connectMinimumWidthToRootObject
+ * Same as for connectMinimumHeightToRootObject,
+ * but then for width.
+ */
+ void connectMinimumWidthToRootObject();
private Q_SLOTS:
void updatePaletteFromConfig();
+
+ void setMinimumHeightFromRoot();
+ void setMinimumWidthFromRoot();
};
#endif // KISQQUICKWIDGET_H