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

Split character and paragraph properties into two separate textData.

Wolthera van Hövell tot Westerflier12b3e8fa694f
diff --git a/libs/flake/text/KoSvgTextPropertiesInterface.h b/libs/flake/text/KoSvgTextPropertiesInterface.h
index c804f82993..1b0b5d3e1d 100644
--- a/libs/flake/text/KoSvgTextPropertiesInterface.h
+++ b/libs/flake/text/KoSvgTextPropertiesInterface.h
@@ -28,6 +28,12 @@ public:
*/
virtual QList<KoSvgTextProperties> getSelectedProperties() = 0;
+ /**
+ * @brief getSelectedProperties
+ * @return all KoSvgTextProperties for the given character selection.
+ */
+ virtual QList<KoSvgTextProperties> getCharacterProperties() = 0;
+
/**
* @brief getInheritedProperties
* The properties that should be visible when a given property
@@ -36,18 +42,37 @@ public:
* @return what counts as the inherited properties for the given selection.
*/
virtual KoSvgTextProperties getInheritedProperties() = 0;
+
/**
* @brief setPropertiesOnSelected
* This sets the properties on the selection. The implementation is responsible
* for handling the undo states.
* @param properties -- the properties to set.
+ * @param removeProperties -- properties to remove.
*/
virtual void setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) = 0;
+ /**
+ * @brief setCharacterPropertiesOnSelected
+ * This sets the properties for a character selection instead of the full
+ * text shape. Typically the selection of characters.
+ * The implementation is responsible for handling the undo states.
+ * @param properties -- the properties to set.
+ * @param removeProperties -- properties to remove.
+ */
+ virtual void setCharacterPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) = 0;
+
/// Whether the tool is currently selecting a set of characters instead of whole paragraphs.
virtual bool spanSelection() = 0;
+
+ /// Whether character selections are possible at all.
+ virtual bool characterPropertiesEnabled() = 0;
Q_SIGNALS:
+ /// Emit to signal to KisTextPropertiesManager to call getSelectedProperties
void textSelectionChanged();
+ /// Emit to signal to KisTextPropertiesManager to call getCharacterProperties
+ /// and getInheritedProperties.
+ void textCharacterSelectionChanged();
};
diff --git a/libs/flake/text/KoSvgTextPropertyData.cpp b/libs/flake/text/KoSvgTextPropertyData.cpp
index 96078be072..1226d14998 100644
--- a/libs/flake/text/KoSvgTextPropertyData.cpp
+++ b/libs/flake/text/KoSvgTextPropertyData.cpp
@@ -22,6 +22,8 @@ QDebug operator<<(QDebug dbg, const KoSvgTextPropertyData &prop)
dbg.nospace() << "TextPropertyData(";
dbg.nospace() << " Common properties:" << prop.commonProperties.convertParagraphProperties() << prop.commonProperties.convertToSvgTextAttributes();
dbg.nospace() << " Tristate:" << prop.tristate;
+ dbg.nospace() << " SpanSelection:" << prop.spanSelection;
+ dbg.nospace() << " Enabled:" << prop.enabled;
dbg.nospace() << " )";
return dbg.space();
}
diff --git a/libs/flake/text/KoSvgTextPropertyData.h b/libs/flake/text/KoSvgTextPropertyData.h
index a9abd33fea..99440f19f7 100644
--- a/libs/flake/text/KoSvgTextPropertyData.h
+++ b/libs/flake/text/KoSvgTextPropertyData.h
@@ -36,8 +36,14 @@ struct KRITAFLAKE_EXPORT KoSvgTextPropertyData : public boost::equality_comparab
/// Whether we're currently selecting a span of text as opposed to editing the whole paragraph.
bool spanSelection {false};
+ bool enabled{false};
+
bool operator==(const KoSvgTextPropertyData &rhs) const {
- return commonProperties == rhs.commonProperties && inheritedProperties == rhs.inheritedProperties && tristate == rhs.tristate && spanSelection == rhs.spanSelection;
+ return commonProperties == rhs.commonProperties
+ && inheritedProperties == rhs.inheritedProperties
+ && tristate == rhs.tristate
+ && spanSelection == rhs.spanSelection
+ && enabled == rhs.enabled;
}
};
diff --git a/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp b/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp
index 12dddeb7e3..e2edd81c74 100644
--- a/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp
+++ b/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp
@@ -304,6 +304,7 @@ KoSvgTextPropertiesModel::KoSvgTextPropertiesModel(lager::cursor<KoSvgTextProper
, LAGER_QT(shapePaddingState) {textData.zoom(propertyModifyState(KoSvgTextProperties::ShapePaddingId))}
, LAGER_QT(shapeMarginState) {textData.zoom(propertyModifyState(KoSvgTextProperties::ShapeMarginId))}
, LAGER_QT(spanSelection) {textData[&KoSvgTextPropertyData::spanSelection]}
+ , LAGER_QT(enabled) {textData[&KoSvgTextPropertyData::enabled]}
{
lager::watch(textData, std::bind(&KoSvgTextPropertiesModel::textPropertyChanged, this));
lager::watch(fontSizeData, std::bind(&KoSvgTextPropertiesModel::fontSizeChanged, this));
diff --git a/libs/flake/text/lager/KoSvgTextPropertiesModel.h b/libs/flake/text/lager/KoSvgTextPropertiesModel.h
index 0ee6ce7c01..c82f3d613a 100644
--- a/libs/flake/text/lager/KoSvgTextPropertiesModel.h
+++ b/libs/flake/text/lager/KoSvgTextPropertiesModel.h
@@ -232,6 +232,9 @@ public:
/// We're selecting a span of text instead of the whole paragraph.
LAGER_QT_CURSOR(bool, spanSelection);
+ // Check if this model is abled at all.
+ LAGER_QT_CURSOR(bool, enabled);
+
/**
* @brief resolvedFontSize
* this returns the resolved font (em) size, needed for unit conversion for em.
diff --git a/libs/resources/KoCanvasResourcesIds.h b/libs/resources/KoCanvasResourcesIds.h
index 93b7bba1d0..3dae10fd05 100644
--- a/libs/resources/KoCanvasResourcesIds.h
+++ b/libs/resources/KoCanvasResourcesIds.h
@@ -65,6 +65,7 @@ enum CanvasResourceId {
UsingOtherColor, ///<- a boolean that is controlled by the tool invocation action
ColorHistory, ///< Color history if not per document
SvgTextPropertyData, ///< KoSvgTextPropertyDataStruct
+ SvgCharacterTextPropertyData, ///< KoSvgTextPropertyDataStruct
};
}
diff --git a/libs/ui/KisTextPropertiesManager.cpp b/libs/ui/KisTextPropertiesManager.cpp
index 42b37fdf96..3ac1f55573 100644
--- a/libs/ui/KisTextPropertiesManager.cpp
+++ b/libs/ui/KisTextPropertiesManager.cpp
@@ -21,6 +21,7 @@ struct KisTextPropertiesManager::Private {
KoSvgTextPropertiesInterface *interface {nullptr};
KoSvgTextPropertyData lastSetTextData;
+ KoSvgTextPropertyData lastSetCharacterData;
KisSignalAutoConnectionsStore interfaceConnectionStore;
KisSignalAutoConnectionsStore providerConnectionStore;
@@ -42,6 +43,7 @@ void KisTextPropertiesManager::setCanvasResourceProvider(KisCanvasResourceProvid
d->provider = provider;
if (d->provider) {
d->providerConnectionStore.addUniqueConnection(d->provider, SIGNAL(sigTextPropertiesChanged()), this, SLOT(slotTextPropertiesChanged()));
+ d->providerConnectionStore.addUniqueConnection(d->provider, SIGNAL(sigCharacterPropertiesChanged()), this, SLOT(slotCharacterPropertiesChanged()));
}
}
@@ -51,7 +53,9 @@ void KisTextPropertiesManager::setTextPropertiesInterface(KoSvgTextPropertiesInt
d->interface = interface;
if (d->interface) {
d->interfaceConnectionStore.addUniqueConnection(d->interface, SIGNAL(textSelectionChanged()), this, SLOT(slotInterfaceSelectionChanged()));
+ d->interfaceConnectionStore.addUniqueConnection(d->interface, SIGNAL(textCharacterSelectionChanged()), this, SLOT(slotCharacterInterfaceSelectionChanged()));
slotInterfaceSelectionChanged();
+ slotCharacterInterfaceSelectionChanged();
}
}
@@ -76,12 +80,7 @@ KoSvgTextPropertyData textDataProperties(QList<KoSvgTextProperties> props, QSet<
return textData;
}
-void KisTextPropertiesManager::slotInterfaceSelectionChanged() {
- if (!d->interface || !d->provider) return;
-
- QList<KoSvgTextProperties> props = d->interface->getSelectedProperties();
- if (props.isEmpty()) return;
-
+QSet<KoSvgTextProperties::PropertyId> getTristate(QList<KoSvgTextProperties> props) {
QSet<KoSvgTextProperties::PropertyId> propIds;
for (auto it = props.begin(); it != props.end(); it++) {
@@ -90,35 +89,81 @@ void KisTextPropertiesManager::slotInterfaceSelectionChanged() {
propIds.insert(p.properties().at(i));
}
}
+ return propIds;
+}
+
+void KisTextPropertiesManager::slotInterfaceSelectionChanged() {
+ if (!d->interface || !d->provider) return;
+
+ QList<KoSvgTextProperties> props = d->interface->getSelectedProperties();
+ if (props.isEmpty()) return;
+
+ QSet<KoSvgTextProperties::PropertyId> propIds = getTristate(props);
KoSvgTextPropertyData textData = textDataProperties(props, propIds);
- textData.inheritedProperties = d->interface->getInheritedProperties();
- textData.spanSelection = d->interface->spanSelection();
+ textData.inheritedProperties = KoSvgTextProperties();
+ textData.enabled = true;
d->lastSetTextData = textData;
d->provider->setTextPropertyData(textData);
}
-void KisTextPropertiesManager::slotTextPropertiesChanged()
+void KisTextPropertiesManager::slotCharacterInterfaceSelectionChanged()
{
if (!d->interface || !d->provider) return;
- if (d->lastSetTextData == d->provider->textPropertyData()) return;
-
- KoSvgTextPropertyData textData = d->provider->textPropertyData();
+ KoSvgTextPropertyData charData;
+ if (d->interface->characterPropertiesEnabled()) {
+ QList<KoSvgTextProperties> charProps = d->interface->getCharacterProperties();
+ if (!charProps.isEmpty()) {
+ QSet<KoSvgTextProperties::PropertyId> charPropIds = getTristate(charProps);
+ charData = textDataProperties(charProps, charPropIds);
+ }
+ charData.inheritedProperties = d->interface->getInheritedProperties();
+ charData.spanSelection = d->interface->spanSelection();
+ charData.enabled = true;
+ }
+ d->lastSetCharacterData = charData;
+ d->provider->setCharacterPropertyData(charData);
+}
- KoSvgTextProperties newProps = textData.commonProperties.ownProperties(d->lastSetTextData.commonProperties);
+QSet<KoSvgTextProperties::PropertyId> removedProps(KoSvgTextPropertyData textData, KoSvgTextPropertyData oldProps) {
QSet<KoSvgTextProperties::PropertyId> removeProperties;
-
- QList<KoSvgTextProperties::PropertyId> oldPropIds = d->lastSetTextData.commonProperties.properties();
- oldPropIds.append(d->lastSetTextData.tristate.values());
+ QList<KoSvgTextProperties::PropertyId> oldPropIds = oldProps.commonProperties.properties();
+ oldPropIds.append(oldProps.tristate.values());
for (auto it = oldPropIds.begin(); it != oldPropIds.end(); it++) {
KoSvgTextProperties::PropertyId p = *it;
if (!textData.commonProperties.hasProperty(p) && !textData.tristate.contains(p)) {
removeProperties.insert(p);
}
}
+ return removeProperties;
+}
+
+void KisTextPropertiesManager::slotTextPropertiesChanged()
+{
+ if (!d->interface || !d->provider) return;
+ if (d->lastSetTextData == d->provider->textPropertyData()) return;
+
+ KoSvgTextPropertyData textData = d->provider->textPropertyData();
+
+ KoSvgTextProperties newProps = textData.commonProperties.ownProperties(d->lastSetTextData.commonProperties);
+ QSet<KoSvgTextProperties::PropertyId> removeProperties = removedProps(textData, d->lastSetTextData);
if (newProps.isEmpty() && removeProperties.isEmpty()) return;
d->interface->setPropertiesOnSelected(newProps, removeProperties);
}
+
+void KisTextPropertiesManager::slotCharacterPropertiesChanged()
+{
+ if (!d->interface || !d->provider) return;
+ if (!d->interface->characterPropertiesEnabled()) return;
+ KoSvgTextPropertyData textData = d->provider->characterTextPropertyData();
+ if (textData == d->lastSetCharacterData) return;
+
+ KoSvgTextProperties newProps = textData.commonProperties.ownProperties(d->lastSetCharacterData.commonProperties);
+ QSet<KoSvgTextProperties::PropertyId> removeProperties = removedProps(textData, d->lastSetCharacterData);
+
+ if (newProps.isEmpty() && removeProperties.isEmpty()) return;
+ d->interface->setCharacterPropertiesOnSelected(newProps, removeProperties);
+}
diff --git a/libs/ui/KisTextPropertiesManager.h b/libs/ui/KisTextPropertiesManager.h
index 59f39ca654..d51b744280 100644
--- a/libs/ui/KisTextPropertiesManager.h
+++ b/libs/ui/KisTextPropertiesManager.h
@@ -44,7 +44,9 @@ public:
private Q_SLOTS:
void slotInterfaceSelectionChanged();
+ void slotCharacterInterfaceSelectionChanged();
void slotTextPropertiesChanged();
+ void slotCharacterPropertiesChanged();
private:
struct Private;
diff --git a/libs/ui/kis_canvas_resource_provider.cpp b/libs/ui/kis_canvas_resource_provider.cpp
index 6202a4cd26..8f762c770f 100644
--- a/libs/ui/kis_canvas_resource_provider.cpp
+++ b/libs/ui/kis_canvas_resource_provider.cpp
@@ -558,6 +558,17 @@ KoSvgTextPropertyData KisCanvasResourceProvider::textPropertyData() const
return m_resourceManager->resource(KoCanvasResource::SvgTextPropertyData).value<KoSvgTextPropertyData>();
}
+void KisCanvasResourceProvider::setCharacterPropertyData(KoSvgTextPropertyData data)
+{
+ m_resourceManager->setResource(KoCanvasResource::SvgCharacterTextPropertyData, QVariant::fromValue(data));
+ Q_EMIT sigCharacterPropertiesChanged();
+}
+
+KoSvgTextPropertyData KisCanvasResourceProvider::characterTextPropertyData() const
+{
+ return m_resourceManager->resource(KoCanvasResource::SvgCharacterTextPropertyData).value<KoSvgTextPropertyData>();
+}
+
void KisCanvasResourceProvider::notifyLoadingWorkspace(KisWorkspaceResourceSP workspace)
{
Q_EMIT sigLoadingWorkspace(workspace);
diff --git a/libs/ui/kis_canvas_resource_provider.h b/libs/ui/kis_canvas_resource_provider.h
index 3009e0b4e8..0ead73a751 100644
--- a/libs/ui/kis_canvas_resource_provider.h
+++ b/libs/ui/kis_canvas_resource_provider.h
@@ -134,6 +134,9 @@ public:
void setTextPropertyData(KoSvgTextPropertyData data);
KoSvgTextPropertyData textPropertyData() const;
+ void setCharacterPropertyData(KoSvgTextPropertyData data);
+ KoSvgTextPropertyData characterTextPropertyData() const;
+
///Notify that the workspace is saved and settings should be saved to it
void notifySavingWorkspace(KisWorkspaceResourceSP workspace);
@@ -191,6 +194,7 @@ Q_SIGNALS:
void sigGamutMaskDeactivated();
void sigTextPropertiesChanged();
+ void sigCharacterPropertiesChanged();
private:
diff --git a/plugins/dockers/textproperties/TextPropertiesCanvasObserver.cpp b/plugins/dockers/textproperties/TextPropertiesCanvasObserver.cpp
index f63c967e09..8edfb878e9 100644
--- a/plugins/dockers/textproperties/TextPropertiesCanvasObserver.cpp
+++ b/plugins/dockers/textproperties/TextPropertiesCanvasObserver.cpp
@@ -23,13 +23,16 @@
struct TextPropertiesCanvasObserver::Private {
Private(QObject *parent = nullptr)
- : modelToProviderCompressor(KisSignalCompressor(100, KisSignalCompressor::FIRST_ACTIVE, parent)) {
+ : textToProviderCompressor(KisSignalCompressor(100, KisSignalCompressor::FIRST_ACTIVE, parent))
+ , characterToProviderCompressor(KisSignalCompressor(100, KisSignalCompressor::FIRST_ACTIVE, parent)){
}
- KisSignalCompressor modelToProviderCompressor;
+ KisSignalCompressor textToProviderCompressor;
+ KisSignalCompressor characterToProviderCompressor;
KoSvgTextPropertiesModel *textModel {new KoSvgTextPropertiesModel()};
+ KoSvgTextPropertiesModel *characterModel {new KoSvgTextPropertiesModel()};
KisCanvasResourceProvider *provider{nullptr};
TextPropertyConfigModel *textPropertyConfigModel {nullptr};
qreal currentDpi{72.0};
@@ -51,10 +54,15 @@ TextPropertiesCanvasObserver::TextPropertiesCanvasObserver(QObject *parent)
d->locales = wellFormedBCPNames;
connect(d->textModel, SIGNAL(textPropertyChanged()),
- &d->modelToProviderCompressor, SLOT(start()));
- connect(&d->modelToProviderCompressor, SIGNAL(timeout()), this, SLOT(slotTextPropertiesChanged()));
+ &d->textToProviderCompressor, SLOT(start()));
+ connect(d->characterModel, SIGNAL(textPropertyChanged()),
+ &d->characterToProviderCompressor, SLOT(start()));
+ connect(&d->textToProviderCompressor, SIGNAL(timeout()), this, SLOT(slotTextPropertiesChanged()));
+ connect(&d->characterToProviderCompressor, SIGNAL(timeout()), this, SLOT(slotCharacterPropertiesChanged()));
connect(d->textModel, SIGNAL(textPropertyChanged()),
this, SIGNAL(textPropertiesChanged()));
+ connect(d->characterModel, SIGNAL(textPropertyChanged()),
+ this, SIGNAL(characterPropertiesChanged()));
}
TextPropertiesCanvasObserver::~TextPropertiesCanvasObserver()
@@ -68,11 +76,16 @@ void TextPropertiesCanvasObserver::setViewManager(KisViewManager *kisview)
if (d->provider) {
connect(d->provider, SIGNAL(sigTextPropertiesChanged()),
this, SLOT(slotCanvasTextPropertiesChanged()));
+ connect(d->provider, SIGNAL(sigCharacterPropertiesChanged()),
+ this, SLOT(slotCanvasCharacterPropertiesChanged()));
// This initializes the docker to an empty entry;
KoSvgTextPropertyData textData;
textData.inheritedProperties = KoSvgTextProperties();
+ textData.enabled = true;
d->provider->setTextPropertyData(textData);
+ textData.enabled = false;
+ d->provider->setCharacterPropertyData(textData);
}
}
@@ -117,6 +130,11 @@ KoSvgTextPropertiesModel *TextPropertiesCanvasObserver::textProperties() const
return d->textModel;
}
+KoSvgTextPropertiesModel *TextPropertiesCanvasObserver::characterProperties() const
+{
+ return d->characterModel;
+}
+
TextPropertyConfigModel *TextPropertiesCanvasObserver::textPropertyConfig() const
{
return d->textPropertyConfigModel;
@@ -137,13 +155,23 @@ void TextPropertiesCanvasObserver::setHasFocus(const bool focus)
void TextPropertiesCanvasObserver::slotCanvasTextPropertiesChanged()
{
KoSvgTextPropertyData data = d->provider->textPropertyData();
- const bool shouldSet = d->hasFocus? !d->modelToProviderCompressor.isActive(): true;
+ const bool shouldSet = d->hasFocus? !d->textToProviderCompressor.isActive(): true;
if (d->textModel->textData.get() != data && shouldSet) {
d->textModel->textData.set(data);
Q_EMIT textPropertiesChanged();
}
}
+void TextPropertiesCanvasObserver::slotCanvasCharacterPropertiesChanged()
+{
+ KoSvgTextPropertyData data = d->provider->characterTextPropertyData();
+ const bool shouldSet = d->hasFocus? !d->characterToProviderCompressor.isActive(): true;
+ if (d->characterModel->textData.get() != data && shouldSet) {
+ d->characterModel->textData.set(data);
+ Q_EMIT characterPropertiesChanged();
+ }
+}
+
void TextPropertiesCanvasObserver::slotTextPropertiesChanged()
{
KoSvgTextPropertyData textData = d->textModel->textData.get();
@@ -153,6 +181,15 @@ void TextPropertiesCanvasObserver::slotTextPropertiesChanged()
}
}
+void TextPropertiesCanvasObserver::slotCharacterPropertiesChanged()
+{
+ KoSvgTextPropertyData characterData = d->characterModel->textData.get();
+ debugFlake << Q_FUNC_INFO << characterData;
+ if (d->provider && d->provider->characterTextPropertyData() != characterData) {
+ d->provider->setCharacterPropertyData(characterData);
+ }
+}
+
void TextPropertiesCanvasObserver::callModalTextPropertyConfigDialog()
{
TextPropertyConfigDialog dialog(qApp->activeWindow());
@@ -167,18 +204,20 @@ void TextPropertiesCanvasObserver::applyPreset(KoResourceSP resource)
{
KoCssStylePresetSP preset = resource.staticCast<KoCssStylePreset>();
if (!preset) return;
- KoSvgTextPropertyData textData = d->textModel->textData.get();
+ KoSvgTextPropertiesModel *model = d->characterModel->enabled() && d->characterModel->spanSelection()? d->characterModel: d->textModel;
+ KoSvgTextPropertyData textData = model->textData.get();
KoSvgTextProperties properties = preset->properties(d->currentDpi, true);
Q_FOREACH(KoSvgTextProperties::PropertyId p, properties.properties()) {
textData.commonProperties.setProperty(p, properties.property(p));
}
- d->textModel->textData.set(textData);
+ model->textData.set(textData);
}
bool TextPropertiesCanvasObserver::createNewPresetFromSettings()
{
KoCssStylePresetSP preset(new KoCssStylePreset(QString()));
- KoSvgTextPropertyData textData = d->textModel->textData.get();
+ KoSvgTextPropertiesModel *model = d->characterModel->enabled() && d->characterModel->spanSelection()? d->characterModel: d->textModel;
+ KoSvgTextPropertyData textData = model->textData.get();
preset->setProperties(textData.commonProperties);
preset->setName(i18nc("@info:placeholder", "New Style Preset"));
preset->setStyleType("character");
diff --git a/plugins/dockers/textproperties/TextPropertiesCanvasObserver.h b/plugins/dockers/textproperties/TextPropertiesCanvasObserver.h
index 56a3e8a3fa..7a3c4be6df 100644
--- a/plugins/dockers/textproperties/TextPropertiesCanvasObserver.h
+++ b/plugins/dockers/textproperties/TextPropertiesCanvasObserver.h
@@ -31,6 +31,7 @@ class TextPropertiesCanvasObserver : public QObject, public KisMainwindowObserve
Q_PROPERTY(qreal dpi READ dpi() NOTIFY dpiChanged)
Q_PROPERTY(QStringList locales READ locales() NOTIFY localesChanged)
Q_PROPERTY(KoSvgTextPropertiesModel *textProperties READ textProperties NOTIFY textPropertiesChanged)
+ Q_PROPERTY(KoSvgTextPropertiesModel *characterProperties READ characterProperties NOTIFY characterPropertiesChanged)
Q_PROPERTY(TextPropertyConfigModel *textPropertyConfig READ textPropertyConfig NOTIFY textPropertyConfigChanged)
/*
* \qmlproperty hasFocus
@@ -52,6 +53,7 @@ public:
qreal dpi() const;
QStringList locales() const;
KoSvgTextPropertiesModel *textProperties() const;
+ KoSvgTextPropertiesModel *characterProperties() const;
TextPropertyConfigModel *textPropertyConfig() const;
bool hasFocus() const;
@@ -59,7 +61,9 @@ public:
public Q_SLOTS:
void slotCanvasTextPropertiesChanged();
+ void slotCanvasCharacterPropertiesChanged();
void slotTextPropertiesChanged();
+ void slotCharacterPropertiesChanged();
void callModalTextPropertyConfigDialog();
@@ -72,6 +76,7 @@ Q_SIGNALS:
void localesChanged();
void textPropertiesChanged();
void textPropertyConfigChanged();
+ void characterPropertiesChanged();
void hasFocusChanged();
private:
struct Private;
diff --git a/plugins/dockers/textproperties/TextPropertyConfigModel.cpp b/plugins/dockers/textproperties/TextPropertyConfigModel.cpp
index 4da3c4127c..0f44a6f0ca 100644
--- a/plugins/dockers/textproperties/TextPropertyConfigModel.cpp
+++ b/plugins/dockers/textproperties/TextPropertyConfigModel.cpp
@@ -226,8 +226,6 @@ bool TextPropertyConfigFilterModel::filterAcceptsRow(int source_row, const QMode
const TextPropertyConfigModel::PropertyType type = TextPropertyConfigModel::PropertyType(sourceModel()->data(idx, TextPropertyConfigModel::Type).toInt());
if (type == TextPropertyConfigModel::Paragraph && !m_showParagraphProperties) {
return false;
- } else if (type == TextPropertyConfigModel::Character && m_showParagraphProperties) {
- return false;
}
const QString name = sourceModel()->data(idx, Qt::DisplayRole).toString();
diff --git a/plugins/dockers/textproperties/qml/TextProperties.qml b/plugins/dockers/textproperties/qml/TextProperties.qml
index 957b94ac1f..b4e8651016 100644
--- a/plugins/dockers/textproperties/qml/TextProperties.qml
+++ b/plugins/dockers/textproperties/qml/TextProperties.qml
@@ -84,7 +84,8 @@ Control {
configModel: root.configModel;
canvasDPI: root.canvasDPI;
locales: canvasObserver.locales;
- propertiesModel: canvasObserver.textProperties;
+ enabled: canvasObserver.characterProperties.enabled;
+ propertiesModel: canvasObserver.characterProperties;
onCallPropertyVisibilityConfig: canvasObserver.callModalTextPropertyConfigDialog();
}
diff --git a/plugins/dockers/textproperties/qml/TextPropertyBase.qml b/plugins/dockers/textproperties/qml/TextPropertyBase.qml
index 6934231390..fb9d0859f6 100644
--- a/plugins/dockers/textproperties/qml/TextPropertyBase.qml
+++ b/plugins/dockers/textproperties/qml/TextPropertyBase.qml
@@ -33,7 +33,7 @@ Column {
property var propertyState: []; /// All property states related to the current property.
function setVisibleFromProperty() {
- if (propertyType !== parentPropertyType && propertyType !== TextPropertyConfigModel.Mixed) {
+ if (propertyType !== parentPropertyType && propertyType === TextPropertyConfigModel.Paragraph) {
visible = false;
return;
}
diff --git a/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml b/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml
index f9f524fb49..f99515b27e 100644
--- a/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml
+++ b/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml
@@ -20,6 +20,11 @@ ColumnLayout {
property alias textConfigButtonVisible: configButton.visible;
+ enabled: propertiesModel.enabled;
+ onEnabledChanged: {
+ updatePropertyVisibilityState();
+ }
+
ListModel {
id: propertyList;
}
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
index bdeec4fcdb..e5d98a3e3c 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
@@ -2367,6 +2367,11 @@ QList<KoSvgTextProperties> DefaultToolTextPropertiesInterface::getSelectedProper
return props;
}
+QList<KoSvgTextProperties> DefaultToolTextPropertiesInterface::getCharacterProperties()
+{
+ return QList<KoSvgTextProperties>();
+}
+
KoSvgTextProperties DefaultToolTextPropertiesInterface::getInheritedProperties()
{
return KoSvgTextProperties();
@@ -2381,11 +2386,23 @@ void DefaultToolTextPropertiesInterface::setPropertiesOnSelected(KoSvgTextProper
}
}
+void DefaultToolTextPropertiesInterface::setCharacterPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties)
+{
+ Q_UNUSED(properties)
+ Q_UNUSED(removeProperties)
+ return;
+}
+
bool DefaultToolTextPropertiesInterface::spanSelection()
{
return false;
}
+bool DefaultToolTextPropertiesInterface::characterPropertiesEnabled()
+{
+ return false;
+}
+
void DefaultToolTextPropertiesInterface::notifyCursorPosChanged(int pos, int anchor)
{
Q_UNUSED(pos)
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.h b/plugins/tools/defaulttool/defaulttool/DefaultTool.h
index 1ca9010ae1..709a83d193 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.h
+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.h
@@ -230,9 +230,12 @@ public:
DefaultToolTextPropertiesInterface(DefaultTool *parent);
~DefaultToolTextPropertiesInterface();
virtual QList<KoSvgTextProperties> getSelectedProperties() override;
+ virtual QList<KoSvgTextProperties> getCharacterProperties() override;
virtual KoSvgTextProperties getInheritedProperties() override;
virtual void setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) override;
+ virtual void setCharacterPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) override;
virtual bool spanSelection() override;
+ virtual bool characterPropertiesEnabled() override;
virtual void notifyCursorPosChanged(int pos, int anchor) override;
virtual void notifyMarkupChanged() override;
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.cpp b/plugins/tools/svgtexttool/SvgTextCursor.cpp
index 6fac31a52a..d94b0cd2be 100644
--- a/plugins/tools/svgtexttool/SvgTextCursor.cpp
+++ b/plugins/tools/svgtexttool/SvgTextCursor.cpp
@@ -230,6 +230,7 @@ void SvgTextCursor::setShape(KoSvgTextShape *textShape)
d->anchor = 0;
updateCursor(true);
updateSelection();
+ d->interface->emitSelectionChange();
}
void SvgTextCursor::setCaretSetting(int cursorWidth, int cursorFlash, int cursorFlashLimit, bool drawCursorInAdditionToSelection)
@@ -597,19 +598,25 @@ QList<KoSvgTextProperties> SvgTextCursor::propertiesForRange() const
if (!d->shape) return QList<KoSvgTextProperties>();
int start = -1;
int end = -1;
- if (d->pos != d->anchor) {
+ //if (d->pos != d->anchor) {
start = qMin(d->pos, d->anchor);
end = qMax(d->pos, d->anchor);
- }
+ //}
return d->shape->propertiesForRange(start, end);
}
-void SvgTextCursor::mergePropertiesIntoSelection(const KoSvgTextProperties props, const QSet<KoSvgTextProperties::PropertyId> removeProperties)
+QList<KoSvgTextProperties> SvgTextCursor::propertiesForShape() const
+{
+ if (!d->shape) return QList<KoSvgTextProperties>();
+ return {d->shape->propertiesForRange(-1, -1)};
+}
+
+void SvgTextCursor::mergePropertiesIntoSelection(const KoSvgTextProperties props, const QSet<KoSvgTextProperties::PropertyId> removeProperties, bool paragraphOnly)
{
if (d->shape) {
int start = -1;
int end = -1;
- if (hasSelection()) {
+ if (!paragraphOnly) {
start = d->pos;
end = d->anchor;
}
@@ -1218,7 +1225,7 @@ void SvgTextCursor::canvasResourceChanged(int key, const QVariant &value)
}
}
if (!props.isEmpty()) {
- mergePropertiesIntoSelection(props);
+ mergePropertiesIntoSelection(props, QSet<KoSvgTextProperties::PropertyId>(), false);
}
}
@@ -1316,6 +1323,7 @@ void SvgTextCursor::notifyCursorPosChanged(int pos, int anchor)
void SvgTextCursor::notifyMarkupChanged()
{
d->interface->emitSelectionChange();
+ d->interface->emitCharacterSelectionChange();
updateTypeSettingDecoration();
}
@@ -1633,7 +1641,7 @@ void SvgTextCursor::updateCursor(bool firstUpdate)
qApp->inputMethod()->update(Qt::ImQueryInput);
}
updateCanvasResources();
- d->interface->emitSelectionChange();
+ d->interface->emitCharacterSelectionChange();
if (!(d->canvas->canvasWidget() && d->canvas->canvasController())) {
// Mockcanvas in the tests has neither.
return;
@@ -1939,15 +1947,18 @@ void SvgTextCursor::updateCanvasResources()
struct SvgTextCursorPropertyInterface::Private {
Private(SvgTextCursor *parent)
: parent(parent)
- , compressor(10, KisSignalCompressor::POSTPONE){}
+ , compressor(10, KisSignalCompressor::POSTPONE)
+ , characterCompressor(10, KisSignalCompressor::POSTPONE){}
SvgTextCursor *parent{nullptr};
KisSignalCompressor compressor;
+ KisSignalCompressor characterCompressor;
};
SvgTextCursorPropertyInterface::SvgTextCursorPropertyInterface(SvgTextCursor *parent)
: KoSvgTextPropertiesInterface(parent), d(new Private(parent))
{
connect(&d->compressor, SIGNAL(timeout()), this, SIGNAL(textSelectionChanged()));
+ connect(&d->characterCompressor, SIGNAL(timeout()), this, SIGNAL(textCharacterSelectionChanged()));
}
SvgTextCursorPropertyInterface::~SvgTextCursorPropertyInterface()
@@ -1955,6 +1966,11 @@ SvgTextCursorPropertyInterface::~SvgTextCursorPropertyInterface()
}
QList<KoSvgTextProperties> SvgTextCursorPropertyInterface::getSelectedProperties()
+{
+ return d->parent->propertiesForShape();
+}
+
+QList<KoSvgTextProperties> SvgTextCursorPropertyInterface::getCharacterProperties()
{
return d->parent->propertiesForRange();
}
@@ -1963,12 +1979,17 @@ KoSvgTextProperties SvgTextCursorPropertyInterface::getInheritedProperties()
{
// 9 times out of 10 this is correct, though we could do better by actually
// getting inherited properties for the range and not just defaulting to the paragraph.
- return (d->parent->shape() && spanSelection())? d->parent->shape()->textProperties(): KoSvgTextProperties();
+ return (d->parent->shape())? d->parent->shape()->textProperties(): KoSvgTextProperties();
}
void SvgTextCursorPropertyInterface::setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties)
{
- d->parent->mergePropertiesIntoSelection(properties, removeProperties);
+ d->parent->mergePropertiesIntoSelection(properties, removeProperties, true);
+}
+
+void SvgTextCursorPropertyInterface::setCharacterPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties)
+{
+ d->parent->mergePropertiesIntoSelection(properties, removeProperties, false);
}
bool SvgTextCursorPropertyInterface::spanSelection()
@@ -1976,6 +1997,11 @@ bool SvgTextCursorPropertyInterface::spanSelection()
return d->parent->hasSelection();
}
+bool SvgTextCursorPropertyInterface::characterPropertiesEnabled()
+{
+ return true;
+}
+
void SvgTextCursorPropertyInterface::emitSelectionChange()
{
// Don't bother updating the selection when there's no shape
@@ -1983,3 +2009,8 @@ void SvgTextCursorPropertyInterface::emitSelectionChange()
if (!d->parent->shape()) return;
d->compressor.start();
}
+
+void SvgTextCursorPropertyInterface::emitCharacterSelectionChange()
+{
+ d->characterCompressor.start();
+}
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.h b/plugins/tools/svgtexttool/SvgTextCursor.h
index 38775af266..bc1ff7c701 100644
--- a/plugins/tools/svgtexttool/SvgTextCursor.h
+++ b/plugins/tools/svgtexttool/SvgTextCursor.h
@@ -200,8 +200,9 @@ public:
QPair<KoSvgTextProperties, KoSvgTextProperties> currentTextProperties() const;
QList<KoSvgTextProperties> propertiesForRange() const;
+ QList<KoSvgTextProperties> propertiesForShape() const;
- void mergePropertiesIntoSelection(const KoSvgTextProperties props, const QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>());
+ void mergePropertiesIntoSelection(const KoSvgTextProperties props, const QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>(), bool paragraphOnly = false);
/**
* @brief removeSelection
@@ -332,10 +333,14 @@ public:
SvgTextCursorPropertyInterface(SvgTextCursor *parent);
~SvgTextCursorPropertyInterface();
virtual QList<KoSvgTextProperties> getSelectedProperties() override;
+ virtual QList<KoSvgTextProperties> getCharacterProperties() override;
virtual KoSvgTextProperties getInheritedProperties() override;
virtual void setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) override;
+ virtual void setCharacterPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) override;
virtual bool spanSelection() override;
+ virtual bool characterPropertiesEnabled() override;
void emitSelectionChange();
+ void emitCharacterSelectionChange();
private:
struct Private;
const QScopedPointer<Private> d;