Krita Source Code Documentation
Loading...
Searching...
No Matches
KisTextPropertiesManager.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
10#include <KoSelection.h>
11#include <KoSvgTextShape.h>
13
14#include <KisView.h>
15#include <kis_canvas2.h>
17
18
28
30 : QObject(parent)
31 , d(new Private)
32{
33}
34
38
40{
41 d->providerConnectionStore.clear();
42 d->provider = provider;
43 if (d->provider) {
44 d->providerConnectionStore.addUniqueConnection(d->provider, SIGNAL(sigTextPropertiesChanged()), this, SLOT(slotTextPropertiesChanged()));
45 }
46}
47
49{
50 d->interfaceConnectionStore.clear();
51 d->interface = interface;
52 if (d->interface) {
53 d->interfaceConnectionStore.addUniqueConnection(d->interface, SIGNAL(textSelectionChanged()), this, SLOT(slotInterfaceSelectionChanged()));
55 }
56}
57
58KoSvgTextPropertyData textDataProperties(QList<KoSvgTextProperties> props, QSet<KoSvgTextProperties::PropertyId> propIds) {
59 KoSvgTextPropertyData textData;
60 textData.commonProperties = props.first();
61
62 for (auto it = props.begin(); it != props.end(); it++) {
63 for (int i = 0; i < propIds.size(); i++) {
64 KoSvgTextProperties::PropertyId p = propIds.values().at(i);
65 if (it->hasProperty(p)) {
66 if (textData.commonProperties.property(p) != it->property(p)) {
68 textData.tristate.insert(p);
69 }
70 } else {
72 textData.tristate.insert(p);
73 }
74 }
75 }
76 return textData;
77}
78
80 if (!d->interface || !d->provider) return;
81
82 QList<KoSvgTextProperties> props = d->interface->getSelectedProperties();
83 if (props.isEmpty()) return;
84
85 QSet<KoSvgTextProperties::PropertyId> propIds;
86
87 for (auto it = props.begin(); it != props.end(); it++) {
89 for (int i = 0; i < p.properties().size(); i++) {
90 propIds.insert(p.properties().at(i));
91 }
92 }
93
94 KoSvgTextPropertyData textData = textDataProperties(props, propIds);
95 textData.inheritedProperties = d->interface->getInheritedProperties();
96 textData.spanSelection = d->interface->spanSelection();
97
98 d->lastSetTextData = textData;
99 d->provider->setTextPropertyData(textData);
100
101}
102
104{
105 if (!d->interface || !d->provider) return;
106 if (d->lastSetTextData == d->provider->textPropertyData()) return;
107
108 KoSvgTextPropertyData textData = d->provider->textPropertyData();
109
110 KoSvgTextProperties newProps = textData.commonProperties.ownProperties(d->lastSetTextData.commonProperties);
111 QSet<KoSvgTextProperties::PropertyId> removeProperties;
112
113 QList<KoSvgTextProperties::PropertyId> oldPropIds = d->lastSetTextData.commonProperties.properties();
114 oldPropIds.append(d->lastSetTextData.tristate.values());
115 for (auto it = oldPropIds.begin(); it != oldPropIds.end(); it++) {
117 if (!textData.commonProperties.hasProperty(p) && !textData.tristate.contains(p)) {
118 removeProperties.insert(p);
119 }
120 }
121
122 if (newProps.isEmpty() && removeProperties.isEmpty()) return;
123 d->interface->setPropertiesOnSelected(newProps, removeProperties);
124}
const Params2D p
KoSvgTextPropertyData textDataProperties(QList< KoSvgTextProperties > props, QSet< KoSvgTextProperties::PropertyId > propIds)
KisTextPropertiesManager(QObject *parent=nullptr)
void setTextPropertiesInterface(KoSvgTextPropertiesInterface *interface)
setTextPropertiesInterface set the text properties interface. This should be done on tool activation....
QScopedPointer< Private > d
void setCanvasResourceProvider(KisCanvasResourceProvider *provider)
setCanvasResourceProvider set the canvas resource provider.
The KoSvgTextPropertiesInterface class.
void removeProperty(PropertyId id)
QVariant property(PropertyId id, const QVariant &defaultValue=QVariant()) const
bool hasProperty(PropertyId id) const
KoSvgTextProperties ownProperties(const KoSvgTextProperties &parentProperties, bool keepFontSize=false) const
KisSignalAutoConnectionsStore interfaceConnectionStore
KisSignalAutoConnectionsStore providerConnectionStore
The KoSvgTextPropertyData struct.
KoSvgTextProperties commonProperties
The properties common between all the selected text.
QSet< KoSvgTextProperties::PropertyId > tristate
The properties that are not common (tri-state) between the selected text.
bool spanSelection
Whether we're currently selecting a span of text as opposed to editing the whole paragraph.
KoSvgTextProperties inheritedProperties
The properties that are inherited, so that widgets may be set correctly.