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

Implement creating texts from preset.

Wolthera van Hövell tot Westerflierbff9bfefd2a8
diff --git a/plugins/dockers/textproperties/CMakeLists.txt b/plugins/dockers/textproperties/CMakeLists.txt
index 537132a735..a55a2e7476 100644
--- a/plugins/dockers/textproperties/CMakeLists.txt
+++ b/plugins/dockers/textproperties/CMakeLists.txt
@@ -3,8 +3,6 @@ set(KRITA_TEXTPROPERTIES_SOURCES
TextPropertiesDock.cpp
FontStyleModel.cpp
FontAxesModel.cpp
- KoShapeQtQuickLabel.cpp
- TagFilterProxyModelQmlWrapper.cpp
OpenTypeFeatureModel.cpp
LocaleHandler.cpp
CssQmlUnitConverter.cpp
diff --git a/plugins/dockers/textproperties/TextPropertiesPlugin.cpp b/plugins/dockers/textproperties/TextPropertiesPlugin.cpp
index 8693d46681..b579ed3650 100644
--- a/plugins/dockers/textproperties/TextPropertiesPlugin.cpp
+++ b/plugins/dockers/textproperties/TextPropertiesPlugin.cpp
@@ -17,6 +17,7 @@
#include "TextPropertiesDock.h"
#include <KoDockRegistry.h>
+#include <QQmlEngine>
#include <text/lager/KoSvgTextPropertiesModel.h>
#include <text/lager/CssLengthPercentageModel.h>
@@ -31,9 +32,7 @@
#include "FontStyleModel.h"
#include "FontAxesModel.h"
-#include "KoShapeQtQuickLabel.h"
#include "OpenTypeFeatureModel.h"
-#include "TagFilterProxyModelQmlWrapper.h"
#include "LocaleHandler.h"
#include "CssQmlUnitConverter.h"
#include "TextPropertyConfigModel.h"
@@ -59,9 +58,7 @@ KIS_DECLARE_STATIC_INITIALIZER {
qmlRegisterType<FontAxesModel>("org.krita.flake.text", 1, 0, "FontAxesModel");
qmlRegisterType<OpenTypeFeatureFilterModel>("org.krita.flake.text", 1, 0, "OpenTypeFeatureFilterModel");
qmlRegisterType<OpenTypeFeatureModel>("org.krita.flake.text", 1, 0, "OpenTypeFeatureModel");
- qmlRegisterType<KoShapeQtQuickLabel>("org.krita.flake.text", 1, 0, "KoShapeQtQuickLabel");
qmlRegisterType<CssQmlUnitConverter>("org.krita.flake.text", 1, 0, "CssQmlUnitConverter");
- qmlRegisterType<TagFilterProxyModelQmlWrapper>("org.krita.flake.text", 1, 0, "TagFilterProxyModelQmlWrapper");
qmlRegisterType<LocaleHandler>("org.krita.flake.text", 1, 0, "LocaleHandler");
qmlRegisterType<TextPropertyConfigModel>("org.krita.flake.text", 1, 0, "TextPropertyConfigModel");
qmlRegisterType<TextPropertyConfigFilterModel>("org.krita.flake.text", 1, 0, "TextPropertyConfigFilterModel");
diff --git a/plugins/dockers/textproperties/qml/FontFamily.qml b/plugins/dockers/textproperties/qml/FontFamily.qml
index 576b05c0b0..a69c132500 100644
--- a/plugins/dockers/textproperties/qml/FontFamily.qml
+++ b/plugins/dockers/textproperties/qml/FontFamily.qml
@@ -82,9 +82,9 @@ CollapsibleGroupProperty {
locales: root.locales;
onActivated: {
if (fontFamilies.length >0) {
- fontFamilies[0] = fontFileName;
+ fontFamilies[0] = resourceName;
} else {
- fontFamilies = [ fontFileName ];
+ fontFamilies = [ resourceName ];
}
}
function updateCurrentIndex() {
@@ -93,7 +93,7 @@ CollapsibleGroupProperty {
modelWrapper.currentTag = 0;
modelWrapper.currentIndex = -1;
}
- fontFileName = name;
+ resourceName = name;
}
}
}
@@ -130,15 +130,15 @@ CollapsibleGroupProperty {
Layout.fillWidth: true;
locales: root.locales;
onActivated: {
- fontFamilies[fontListDelegate.dIndex] = fontFileName;
+ fontFamilies[fontListDelegate.dIndex] = resourceName;
}
Component.onCompleted: {
if (fontListDelegate.dIndex === 0) {
modelWrapper = mainFamilyCmb.modelWrapper;
- fontFileName = fontFunctions.wwsFontFamilyName(fontFamilies[fontListDelegate.dIndex]);
+ resourceName = fontFunctions.wwsFontFamilyName(fontFamilies[fontListDelegate.dIndex]);
}
}
- fontFileName: fontFunctions.wwsFontFamilyName(fontFamilies[fontListDelegate.dIndex]);
+ resourceName: fontFunctions.wwsFontFamilyName(fontFamilies[fontListDelegate.dIndex]);
}
ToolButton {
id: removeFont;
diff --git a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
index 416512e898..dbdcb77258 100644
--- a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
+++ b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
@@ -5,376 +5,20 @@
*/
import QtQuick 2.0
import QtQuick.Controls 2.15
-import QtQuick.Layouts 1.12
-import QtQuick.Window 2.15
-import org.krita.flake.text 1.0
import org.krita.components 1.0 as Kis
-Button {
- id: familyCmb;
- wheelEnabled: true;
+Kis.ResourcePopup {
+ id: resourceCmb;
- //--- Model setup. ---//
-
- property alias modelWrapper : resourceView.modelWrapper;
-
- Connections {
- target: modelWrapper;
- function onResourceFilenameChanged() {
- familyCmb.fontFileName = modelWrapper.resourceFilename;
- }
- }
-
- property var locales: [];
- property alias fontFileName: textInput.text;
- topPadding: 0;
- bottomPadding: 0;
- spacing: padding;
- leftPadding: (familyCmb.mirrored ? padding + indicator.width + spacing : 0);
- rightPadding: (!familyCmb.mirrored ? padding + indicator.width + spacing : 0);
-
- Kis.ThemedControl {
- id: palControl;
- }
- palette: palControl.palette;
- Kis.FontFunctions {
- id: fontFunctions;
- }
-
- /// Ideally we'd have the max popup height be Window-height - y-pos-of-item-to-window.
- /// But that's pretty hard to calculate (map to global is screen relative, but there's
- /// no way to get window.y relative to screen), so we'll just use 300 as the maximum.
- property int maxPopupHeight: Math.min(Window.height, 500) - height*3;
-
- contentItem: Kis.InformingTextInput {
- id: textInput;
-
- warnColor: palControl.theme.window.neutralBackgroundColor;
- warnColorBorder: palControl.theme.window.neutralTextColor;
- readOnly: !familyCmb.enabled;
-
- onEditingFinished: {
- if (familyCmbPopup.visible) {
- resourceView.applyHighlightedIndex();
- }
-
- testInput();
- familyCmb.activated();
- }
- onTextChanged: {
- testInput();
- }
-
- onTextEdited: {
- stopWarning();
- modelWrapper.searchText = text;
- resourceView.showTagging = false;
- resourceView.showSearch = false;
- familyCmbPopup.open();
- }
-
- onActiveFocusChanged: {
- if (activeFocus) {
- selectAll();
- }
- }
-
- warningTimeOut: activeFocus? 1000: 0;
-
- function testInput() {
- let test = fontFunctions.wwsFontFamilyNameVariant(text);
-
- if (typeof test === 'undefined') {
- if (!activeFocus) {
- startWarning();
- }
- } else {
- stopWarning();
- text = test;
- modelWrapper.resourceFilename = text;
- }
- }
-
- Keys.onDownPressed: {
- resourceView.downPress();
- }
- Keys.onUpPressed: {
- resourceView.upPress();
- }
- }
-
- indicator: Image {
- id: imgIndicator
- x: Math.round(familyCmb.mirrored ? familyCmb.padding : familyCmb.width - width - familyCmb.padding);
- y: Math.round(familyCmb.topPadding + (familyCmb.availableHeight - height) / 2);
- source: familyCmb.palette.button.hslLightness < 0.5? "qrc:///light_groupOpened.svg": "qrc:///dark_groupOpened.svg";
- width: 12;
- height: 12;
- clip: true;
- }
-
- onClicked: {
- if (familyCmbPopup.visible) {
- familyCmbPopup.close();
- } else {
- resourceView.showTagging = true;
- resourceView.showSearch = true;
- familyCmbPopup.open();
- }
- }
- signal activated();
- onActivated: {
- familyCmbPopup.close();
- modelWrapper.searchText = "";
- }
-
- //--- Delegate setup. ---//
- Component {
- id: fontDelegate
- ItemDelegate {
- /**
- Ideally we'd just use required properties for the metadata etc.
- However, when changing the modelwrapper in the font list,
- there's a short moment where the model data is unavailable, so
- instead we ensure we're not accessing undefined objects.
-
- Not great, would like a better solution...
- */
- id: fontDelegateItem;
- required property var model;
- property string name: typeof model.name !== "undefined"? model.name: "";
- property int index: model.index;
- property string fontName: name;
- property var metadata: model.metadata;
- // TODO: change this to use the text locale, if possible.
- property string sample: "";
-
- onMetadataChanged: {
- updateSample();
- }
-
- Component.onCompleted: {
- updateSample();
- }
-
- function updateSample() {
- if (typeof metadata === "undefined") return;
- let samples = fontFunctions.getMapFromQVariant(metadata.sample_svg);
- let sampleKeys = Object.keys(samples);
- sample = "";
- const latn = samples["s_Latn"];
- if (sampleKeys.length > 0) {
- if (latn) {
- sample = latn;
- } else {
- let tag = sampleKeys[0];
- sample = samples[tag];
- }
- }
- if (familyCmb.locales.length > 0) {
- for (const locale of familyCmb.locales) {
- let tag = fontFunctions.sampleTagForQLocale(Qt.locale(locale));
- let svg = samples[tag];
- if (svg) {
- sample = svg;
- break;
- }
-
-
- }
- }
- }
-
- /// When updating the model wrapper, the "model" doesn't always update on the delegate, so we need to manually load
- /// the metadata from the modelwrapper.
- width: ListView.view.width;
- highlighted: resourceView.highlightedIndex === model.index;
- property bool selected: resourceView.modelWrapper.currentIndex === model.index;
-
- palette: familyCmb.palette;
-
- contentItem: Control {
- id: delegateControl;
-
- property alias highlighted: fontDelegateItem.highlighted;
- palette: fontDelegateItem.palette;
-
- property alias fontName: fontDelegateItem.fontName;
-
- implicitHeight: nameLabel.height*4;
-
- Loader {
- anchors.fill: parent;
- asynchronous: true;
-
- sourceComponent: Component {
- KoShapeQtQuickLabel {
- id: fontFamilyDelegate;
-
- Binding {
- target: fontFamilyDelegate
- property: "meta"
- when: fontDelegateItem && typeof fontDelegateItem !== 'undefined' && typeof fontDelegateItem.metadata !== 'undefined';
- value: fontDelegateItem.metadata;
- }
-
- property var meta: ({});
- property bool colorBitmap : typeof meta.color_bitmap === 'boolean'? meta.color_bitmap: false;
- property bool colorCLRV0 : typeof meta.color_clrv0 === 'boolean'? meta.color_clrv0: false;
- property bool colorCLRV1 : typeof meta.color_clrv1 === 'boolean'? meta.color_clrv1: false;
- property bool colorSVG : typeof meta.color_svg === 'boolean'? meta.color_svg: false;
- property bool isVariable : typeof meta.is_variable === 'boolean'? meta.is_variable: false;
- property int type : typeof meta.font_type === 'number'? meta.font_type: 0;
-
- scalingType: KoShapeQtQuickLabel.FitHeight;
- svgData: fontDelegateItem.sample;
- foregroundColor: delegateControl.highlighted? palette.highlightedText: palette.text;
- fillColor: delegateControl.highlighted? familyCmb.palette.highlight: familyCmb.palette.window;
- fullColor: colorBitmap || colorCLRV0 || colorCLRV1 || colorSVG;
- padding: nameLabel.height;
-
-
- Row {
- id: featureRow;
- spacing: columnSpacing;
- anchors.bottom: parent.bottom;
- anchors.left: parent.left;
- property int imgHeight: 12;
- ToolButton {
- enabled: false;
- padding:0;
- width: parent.imgHeight;
- height: parent.imgHeight;
- property int type: fontFamilyDelegate.type;
- icon.width: parent.imgHeight;
- icon.height: parent.imgHeight;
- palette: fontDelegateItem.palette;
- icon.color: nameLabel.color;
- icon.source: type === KoSvgText.BDFFontType? "qrc:///font-type-bitmap.svg"
- : type === KoSvgText.Type1FontType? "qrc:///font-type-postscript.svg"
- : type === KoSvgText.OpenTypeFontType? "qrc:///font-type-opentype.svg":"qrc:///light_system-help.svg";
- }
- ToolButton {
- enabled: false;
- padding: 0;
- width: parent.imgHeight;
- height: parent.imgHeight;
- icon.width: parent.imgHeight;
- icon.height: parent.imgHeight;
- palette: fontDelegateItem.palette;
- icon.color: nameLabel.color;
- visible: fontFamilyDelegate.isVariable;
- icon.source: "qrc:///font-type-opentype-variable.svg"
- }
-
- ToolButton {
- enabled: false;
- padding: 0;
- width: parent.imgHeight;
- height: parent.imgHeight;
- icon.width: parent.imgHeight;
- icon.height: parent.imgHeight;
- visible: fontFamilyDelegate.colorBitmap;
- icon.source: "qrc:///font-color-type-clr-bitmap.svg"
- }
- ToolButton {
- enabled: false
- padding: 0;
- width: parent.imgHeight;
- height: parent.imgHeight;
- icon.width: parent.imgHeight;
- icon.height: parent.imgHeight;
- visible: fontFamilyDelegate.colorCLRV0;
- icon.source: "qrc:///font-color-type-clr-v0.svg"
- }
- ToolButton {
- padding: 0;
- enabled: false;
- width: parent.imgHeight;
- height: parent.imgHeight;
- icon.width: parent.imgHeight;
- icon.height: parent.imgHeight;
- visible: fontFamilyDelegate.colorCLRV1;
- icon.source: "qrc:///font-color-type-clr-v1.svg"
- }
- ToolButton {
- enabled: false;
- padding: 0;
- width: parent.imgHeight;
- height: parent.imgHeight;
- icon.width: parent.imgHeight;
- icon.height: parent.imgHeight;
- visible: fontFamilyDelegate.colorSVG;
- icon.source: "qrc:///font-color-type-svg.svg"
- }
- }
- }
- }
- }
-
- Label {
- id: nameLabel;
- palette: fontDelegateItem.palette;
- text: delegateControl.fontName;
- anchors.top: parent.top;
- anchors.left: parent.left;
- elide: Text.ElideRight;
- width: parent.width;
- color: parent.highlighted? palette.highlightedText: palette.text;
- }
-
- }
- background: Rectangle {
- id: fontDelegateBackground
- color: highlighted? familyCmb.palette.highlight: familyCmb.palette.window;
- }
-
- MouseArea {
- id: delegateMouseArea;
- acceptedButtons: Qt.RightButton | Qt.LeftButton;
- anchors.fill: parent;
- hoverEnabled: true;
- // Itemdelegate can also handle hovers, but we don't use those.
- preventStealing: true;
- onClicked: {
- if (mouse.button === Qt.RightButton) {
- resourceView.openContextMenu(mouse.x, mouse.y, parent.model.name, parent.index);
- } else {
- resourceView.applyHighlightedIndex();
- familyCmb.activated();
- }
- }
- onContainsMouseChanged: {
- if(containsMouse) {
- resourceView.highlightedIndex = parent.index;
- }
- }
-
- Kis.ToolTipBase {
- text: fontDelegateItem.fontName;
- visible: delegateMouseArea.containsMouse;
- }
- }
- }
- }
-
- //--- Pop up setup ---//
- Popup {
- id: familyCmbPopup;
- y: familyCmb.height - 1;
- x: familyCmb.width - width;
- width: Math.max(contentWidth, Math.max(familyCmb.width, 200));
- height: Math.min(contentItem.implicitHeight, familyCmb.maxPopupHeight - topMargin - bottomMargin)
- padding: 2;
-
- palette: familyCmb.palette;
-
- contentItem: ResourceView {
- id: resourceView;
- resourceType: "fontfamilies";
- resourceDelegate: fontDelegate;
- palette: familyCmbPopup.palette;
- addResourceRow.visible: false;
+ resourceType: "fontfamilies";
+ addResourceRowVisible: false;
+ resourceDelegate: Kis.FontFamilyDelegate {
+ id: fontDelegate;
+ resourceView: resourceCmb.view;
+ locales: resourceCmb.locales;
+ onResourceLeftClicked: {
+ resourceCmb.activated();
}
}
+ view.preferredHeight: 300; // roughly 3.5 times the font delegate size;
}
diff --git a/plugins/dockers/textproperties/qml/TextProperties.qml b/plugins/dockers/textproperties/qml/TextProperties.qml
index fcf878cad4..957b94ac1f 100644
--- a/plugins/dockers/textproperties/qml/TextProperties.qml
+++ b/plugins/dockers/textproperties/qml/TextProperties.qml
@@ -27,9 +27,6 @@ Control {
id: focusChecker;
onInFocusChanged: canvasObserver.hasFocus = inFocus;
}
- Kis.FontFunctions {
- id: fontFunctions;
- }
property TextPropertyConfigModel configModel : canvasObserver.textPropertyConfig;
property double canvasDPI: canvasObserver.dpi;
@@ -112,95 +109,16 @@ Control {
Layout.fillWidth: true;
}
- ResourceView {
+ Kis.ResourceView {
id: presetView;
resourceType: "css_styles";
Layout.fillHeight: true;
Layout.fillWidth: true;
- signal applyPreset;
- onApplyPreset: {
- canvasObserver.applyPreset(modelWrapper.currentResource);
- }
-
- resourceDelegate: ItemDelegate {
- id: presetDelegate;
- required property var model;
- property var meta: model.metadata;
- width: ListView.view.width;
- highlighted: presetView.highlightedIndex === model.index;
- property bool selected: presetView.modelWrapper.currentIndex === model.index;
- palette: presetView.palette;
- contentItem: KoShapeQtQuickLabel {
- implicitHeight: nameLabel.height * 4;
- padding: nameLabel.height;
- alignment: presetDelegate.meta.sample_align;
- scalingType: presetDelegate.meta.style_type === "paragraph"?
- KoShapeQtQuickLabel.FitWidth: KoShapeQtQuickLabel.Fit;
- svgData: presetDelegate.meta.sample_svg;
- foregroundColor: presetDelegate.highlighted? palette.highlightedText: palette.text;
-
- Label {
- id: nameLabel;
- palette: presetDelegate.palette;
- text: presetDelegate.model.name;
- anchors.top: parent.top;
- anchors.left: parent.left;
- anchors.right: parent.right;
- elide: Text.ElideRight;
- color: presetDelegate.highlighted? palette.highlightedText: palette.text;
- }
-
- Row {
- anchors.bottom: parent.bottom;
- anchors.left: parent.left;
- anchors.right: parent.right;
- ToolButton {
- id: missingFamily;
- visible: typeof presetDelegate.meta.primary_font_family !== 'undefined'?
- presetDelegate.meta.primary_font_family !== ""
- && typeof fontFunctions.wwsFontFamilyNameVariant(presetDelegate.meta.primary_font_family) === 'undefined': false;
- icon.source: palette.window.hslLightness < 0.5? "qrc:///16_light_warning.svg": "qrc:///16_dark_warning.svg";
- icon.height: 8;
- icon.width: 8;
- }
- }
- }
- background: Rectangle {
- color: presetDelegate.highlighted? presetDelegate.palette.highlight: "transparent";
- border.color: presetDelegate.selected? presetDelegate.palette.highlight: presetDelegate.palette.mid;
- border.width: presetDelegate.selected? 2: 1;
- }
-
- MouseArea {
- id: delegateMouseArea;
- acceptedButtons: Qt.RightButton | Qt.LeftButton;
- anchors.fill: parent;
- hoverEnabled: true;
- preventStealing: true;
- onClicked: {
- if (mouse.button === Qt.RightButton) {
- presetView.openContextMenu(mouse.x, mouse.y, parent.model.name, parent.model.index);
- } else {
- presetView.applyHighlightedIndex();
- }
- }
- onDoubleClicked: {
- presetView.applyHighlightedIndex();
- presetView.applyPreset();
- }
- onContainsMouseChanged: {
- if (containsMouse) {
- presetView.highlightedIndex = parent.model.index;
- }
- }
-
- readonly property string missingFontName : i18nc("%1 is name of a font family", "Font Family \"%1\" is missing on this machine. This style preset may not work correctly.", presetDelegate.meta.primary_font_family);
- Kis.ToolTipBase {
- text: (typeof presetDelegate.meta.description !== 'undefined'? presetDelegate.model.name + "\n" + presetDelegate.meta.description: presetDelegate.model.name) + (missingFamily.visible? "\n"+ delegateMouseArea.missingFontName: "");
- visible: delegateMouseArea.containsMouse;
- }
-
+ resourceDelegate: Kis.CssStylePresetDelegate {
+ resourceView: presetView;
+ onResourceDoubleClicked: {
+ canvasObserver.applyPreset(presetView.modelWrapper.currentResource);
}
}
additionalAddResourceRow: RowLayout {
diff --git a/plugins/dockers/textproperties/textproperties.qrc b/plugins/dockers/textproperties/textproperties.qrc
index c8a760c865..9428d2f90a 100644
--- a/plugins/dockers/textproperties/textproperties.qrc
+++ b/plugins/dockers/textproperties/textproperties.qrc
@@ -59,7 +59,6 @@
<file alias="FontSizeAdjust.qml">qml/FontSizeAdjust.qml</file>
<file alias="TextRendering.qml">qml/TextRendering.qml</file>
<file alias="TextPropertyConfigDialog.qml">qml/TextPropertyConfigDialog.qml</file>
- <file alias="ResourceView.qml">qml/ResourceView.qml</file>
<file alias="CssStylePresetEdit.qml">qml/CssStylePresetEdit.qml</file>
</qresource>
</RCC>
diff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cpp
index 3725328f68..6440096857 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.cpp
+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp
@@ -216,12 +216,16 @@ QWidget *SvgTextTool::createOptionWidget()
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)));
+ if (docker) {
+ optionWidget->setPalette(docker->palette());
+ connect(m_optionManager.data(), SIGNAL(openTextPropertiesDocker(bool)), docker, SLOT(setVisible(bool)));
+ }
}
slotUpdateVisualCursor();
slotUpdateTextPasteBehaviour();
slotTextTypeUpdated();
+
return optionWidget;
}
diff --git a/plugins/tools/svgtexttool/SvgTextToolOptions.qml b/plugins/tools/svgtexttool/SvgTextToolOptions.qml
index 3020bf36db..4c855e0518 100644
--- a/plugins/tools/svgtexttool/SvgTextToolOptions.qml
+++ b/plugins/tools/svgtexttool/SvgTextToolOptions.qml
@@ -18,6 +18,7 @@ Control {
onManagerChanged: {
updateTextProperties()
textType.updateTextTypes();
+ updatePresetName()
}
Connections {
@@ -39,7 +40,7 @@ Control {
chkPasteRichTextByDefault.checked = manager.optionsModel.pasteRichtTextByDefault;
}
function onCssStylePresetNameChanged() {
- // todo;
+ updatePresetName();
}
function onUseCurrentTextPropertiesChanged() {
chkCurrentProperties.checked = manager.optionsModel.useCurrentTextProperties;
@@ -50,6 +51,10 @@ Control {
btnTextProperties.checked = manager.textPropertiesOpen;
}
+ function updatePresetName() {
+ btnSelectCssStylePreset.resourceName = manager.optionsModel.cssStylePresetName;
+ }
+
Kis.ThemedControl {
id: themedControl;
}
@@ -78,13 +83,26 @@ Control {
visible: parent.hovered;
}
}
-
- Button {
+ Kis.ResourcePopup {
id: btnSelectCssStylePreset;
- enabled: !chkCurrentProperties.checked;
- text: "placeholder style presets";
Layout.fillWidth: true;
- // TODO: write KoCssStylePreset thing here.
+ enabled: !chkCurrentProperties.checked;
+ useFileName: false;
+
+ resourceType: "css_styles";
+ resourceDelegate: Kis.CssStylePresetDelegate {
+ id: presetDelegate;
+ resourceView: btnSelectCssStylePreset.view;
+ onResourceLeftClicked: {
+ btnSelectCssStylePreset.activated();
+ }
+
+ }
+ view.preferredHeight: 256; /// roughly 3x preset delegate size;
+
+ onResourceNameChanged: {
+ manager.optionsModel.cssStylePresetName = btnSelectCssStylePreset.resourceName;
+ }
}
Kis.ToolSeparatorBase {
diff --git a/qmlmodules/components/CMakeLists.txt b/qmlmodules/components/CMakeLists.txt
index fb844f101e..060775975e 100644
--- a/qmlmodules/components/CMakeLists.txt
+++ b/qmlmodules/components/CMakeLists.txt
@@ -21,6 +21,10 @@ if (QT_MAJOR_VERSION STREQUAL "6")
KisTheme.h
KisFontFunctions.cpp
KisFontFunctions.h
+ KoShapeQtQuickLabel.cpp
+ KoShapeQtQuickLabel.h
+ TagFilterProxyModelQmlWrapper.cpp
+ TagFilterProxyModelQmlWrapper.h
)
else ()
@@ -44,6 +48,10 @@ else ()
KisTheme.h
KisFontFunctions.cpp
KisFontFunctions.h
+ KoShapeQtQuickLabel.cpp
+ KoShapeQtQuickLabel.h
+ TagFilterProxyModelQmlWrapper.cpp
+ TagFilterProxyModelQmlWrapper.h
)
endif ()
@@ -105,6 +113,12 @@ ecm_target_qml_sources(kritaqmlcomponents SOURCES
qml/WindowFocusChecker.qml
+ qml/ResourceView.qml
+ qml/ResourcePopup.qml
+ qml/resourceDelegates/ResourceDelegateBase.qml
+ qml/resourceDelegates/FontFamilyDelegate.qml
+ qml/resourceDelegates/CssStylePresetDelegate.qml
+
)
if (QT_MAJOR_VERSION STREQUAL "6")
target_link_libraries(kritaqmlcomponents
diff --git a/qmlmodules/components/KisFontFunctions.cpp b/qmlmodules/components/KisFontFunctions.cpp
index a7f0efb119..5c8b3bceee 100644
--- a/qmlmodules/components/KisFontFunctions.cpp
+++ b/qmlmodules/components/KisFontFunctions.cpp
@@ -34,3 +34,18 @@ QVariantMap KisFontFunctions::getMapFromQVariant(QVariant var)
{
return var.toMap();
}
+
+bool KisFontFunctions::isBitmapType(int type)
+{
+ return KoSvgText::FontFormatType(type) == KoSvgText::BDFFontType;
+}
+
+bool KisFontFunctions::isPostScriptType(int type)
+{
+ return KoSvgText::FontFormatType(type) == KoSvgText::Type1FontType;
+}
+
+bool KisFontFunctions::isOpenType(int type)
+{
+ return KoSvgText::FontFormatType(type) == KoSvgText::OpenTypeFontType;
+}
diff --git a/qmlmodules/components/KisFontFunctions.h b/qmlmodules/components/KisFontFunctions.h
index 59053d1e7e..eb855cd7ec 100644
--- a/qmlmodules/components/KisFontFunctions.h
+++ b/qmlmodules/components/KisFontFunctions.h
@@ -35,6 +35,11 @@ public:
/// QVariantHash, you can use this function to convert it to a QVariantMap.
Q_INVOKABLE static QVariantMap getMapFromQVariant(QVariant var);
+ /// Because we can't register KoSvgText for qt 6 in this plugin, we'll test if the enum is valid here.
+ Q_INVOKABLE static bool isBitmapType(int type);
+ Q_INVOKABLE static bool isPostScriptType(int type);
+ Q_INVOKABLE static bool isOpenType(int type);
+
};
#endif // KISFONTFUNCTIONS_H
diff --git a/plugins/dockers/textproperties/KoShapeQtQuickLabel.cpp b/qmlmodules/components/KoShapeQtQuickLabel.cpp
similarity index 100%
rename from plugins/dockers/textproperties/KoShapeQtQuickLabel.cpp
rename to qmlmodules/components/KoShapeQtQuickLabel.cpp
diff --git a/plugins/dockers/textproperties/KoShapeQtQuickLabel.h b/qmlmodules/components/KoShapeQtQuickLabel.h
similarity index 98%
rename from plugins/dockers/textproperties/KoShapeQtQuickLabel.h
rename to qmlmodules/components/KoShapeQtQuickLabel.h
index c120bc2b0e..f2803b01de 100644
--- a/plugins/dockers/textproperties/KoShapeQtQuickLabel.h
+++ b/qmlmodules/components/KoShapeQtQuickLabel.h
@@ -26,6 +26,7 @@ class KoShapeQtQuickLabel: public QQuickPaintedItem
Q_PROPERTY(QRectF documentRect READ documentRect WRITE setDocumentRect NOTIFY documentRectChanged)
Q_PROPERTY(QRectF minimumRect READ minimumRect NOTIFY minimumRectChanged)
+ QML_NAMED_ELEMENT(KoShapeQtQuickLabel)
public:
KoShapeQtQuickLabel(QQuickItem *parent = nullptr);
~KoShapeQtQuickLabel();
diff --git a/qmlmodules/components/KritaQmlComponentsPlugin.cpp b/qmlmodules/components/KritaQmlComponentsPlugin.cpp
index 3d62b4367f..55cd97d06e 100644
--- a/qmlmodules/components/KritaQmlComponentsPlugin.cpp
+++ b/qmlmodules/components/KritaQmlComponentsPlugin.cpp
@@ -14,6 +14,8 @@
#include <KisCubicCurveQMLWrapper.h>
#include <KisTheme.h>
#include <KisFontFunctions.h>
+#include <KoShapeQtQuickLabel.h>
+#include <TagFilterProxyModelQmlWrapper.h>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#error "This plugin implementation is to be used with Qt5 only!\n"
@@ -43,6 +45,9 @@ void KritaQmlComponentsPlugin::registerTypes(const char *uri)
qmlRegisterType<KisTheme>(uri, 1, 0, "Theme");
qmlRegisterUncreatableType<KisThemeColorGroup>(uri, 1, 0, "ThemeColorGroup", "Use Theme instead");
qmlRegisterType<KisFontFunctions>(uri, 1, 0, "FontFunctions");
+ qmlRegisterType<KoShapeQtQuickLabel>(uri, 1, 0, "KoShapeQtQuickLabel");
+ qmlRegisterType<TagFilterProxyModelQmlWrapper>(uri, 1, 0, "TagFilterProxyModelQmlWrapper");
+
}
#include "moc_KritaQmlComponentsPlugin.cpp"
diff --git a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp b/qmlmodules/components/TagFilterProxyModelQmlWrapper.cpp
similarity index 90%
rename from plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp
rename to qmlmodules/components/TagFilterProxyModelQmlWrapper.cpp
index 11c20e183d..5a48381aca 100644
--- a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp
+++ b/qmlmodules/components/TagFilterProxyModelQmlWrapper.cpp
@@ -21,6 +21,7 @@
#include <QApplication>
#include <resources/KoFontFamily.h>
+#include "KisFontFunctions.h"
struct TagFilterProxyModelQmlWrapper::Private {
Private(QObject *parent = nullptr)
@@ -281,11 +282,61 @@ QString TagFilterProxyModelQmlWrapper::resourceFilename()
return d->currentResource? d->currentResource->filename(): "";
}
+QString TagFilterProxyModelQmlWrapper::resourceName() const
+{
+ return d->currentResource? d->currentResource->name(): "";
+}
+
+void TagFilterProxyModelQmlWrapper::setResourceToName(const QString &name)
+{
+ if (!d->allResourceModel) return;
+ if (d->currentResource && d->currentResource->name() == name) return;
+ KoResourceSP resource = d->currentResource;
+ QVector<KoResourceSP> resources = d->allResourceModel->resourcesForName(name);
+ if (!resources.isEmpty()) {
+ resource = resources.first();
+ }
+ if (resource != d->currentResource) {
+ d->currentResource = resource;
+ emit currentResourceChanged();
+ }
+}
+
KoResourceSP TagFilterProxyModelQmlWrapper::currentResource() const
{
return d->currentResource;
}
+QVariant TagFilterProxyModelQmlWrapper::testFileName(const QString &name)
+{
+ if (resourceType() == ResourceType::FontFamilies) {
+ KisFontFunctions func;
+ return func.wwsFontFamilyNameVariant(name);
+ }
+ QVector<KoResourceSP> resources = d->allResourceModel->resourcesForFilename(name);
+ KoResourceSP resource;
+ if (!resources.isEmpty()) {
+ resource = resources.first();
+ }
+ if (resource) {
+ return resource->filename();
+ }
+ return QVariant();
+}
+
+QVariant TagFilterProxyModelQmlWrapper::testName(const QString &name)
+{
+ QVector<KoResourceSP> resources = d->allResourceModel->resourcesForName(name);
+ KoResourceSP resource;
+ if (!resources.isEmpty()) {
+ resource = resources.first();
+ }
+ if (resource) {
+ return resource->name();
+ }
+ return QVariant();
+}
+
void TagFilterProxyModelQmlWrapper::importResource()
{
// Below copied from KisResourceItemChooser::slotButtonClicked
diff --git a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h b/qmlmodules/components/TagFilterProxyModelQmlWrapper.h
similarity index 90%
rename from plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h
rename to qmlmodules/components/TagFilterProxyModelQmlWrapper.h
index 1ab0d8a834..14b5710ce6 100644
--- a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h
+++ b/qmlmodules/components/TagFilterProxyModelQmlWrapper.h
@@ -7,6 +7,7 @@
#define TAGFILTERPROXYMODELQMLWRAPPER_H
#include <QObject>
+#include <QQmlEngine>
#include <QAbstractItemModel>
#include <KisTagFilterResourceProxyModel.h>
@@ -30,8 +31,12 @@ class TagFilterProxyModelQmlWrapper : public QObject
Q_PROPERTY(int currentTag READ currentTag WRITE tagActivated NOTIFY activeTagChanged)
Q_PROPERTY(bool searchInTag READ searchInTag WRITE setSearchInTag NOTIFY searchInTagChanged)
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentResourceChanged)
+
+ Q_PROPERTY(QString resourceName READ resourceName WRITE setResourceToName NOTIFY currentResourceChanged)
Q_PROPERTY(QString resourceFilename READ resourceFilename WRITE setResourceToFileName NOTIFY currentResourceChanged)
Q_PROPERTY(KoResourceSP currentResource READ currentResource NOTIFY currentResourceChanged)
+
+ QML_NAMED_ELEMENT(TagFilterProxyModelQmlWrapper)
public:
TagFilterProxyModelQmlWrapper(QObject *parent = nullptr);
~TagFilterProxyModelQmlWrapper();
@@ -103,9 +108,19 @@ public:
/// File name of the current resource.
QString resourceFilename();
+ /// Name of current resource
+ QString resourceName() const;
+ void setResourceToName(const QString &name);
+
/// current resource.
KoResourceSP currentResource() const;
+ /// Test if the given filename is in the resources.
+ Q_INVOKABLE QVariant testFileName(const QString &name);
+
+ /// Test if the given name is in the resources.
+ Q_INVOKABLE QVariant testName(const QString &name);
+
/// Import a resource with file picker.
Q_INVOKABLE void importResource();
diff --git a/qmlmodules/components/qml/ResourcePopup.qml b/qmlmodules/components/qml/ResourcePopup.qml
new file mode 100644
index 0000000000..8ad279601d
--- /dev/null
+++ b/qmlmodules/components/qml/ResourcePopup.qml
@@ -0,0 +1,162 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+import QtQuick 2.0
+import QtQuick.Controls 2.15
+import QtQuick.Layouts 1.12
+import QtQuick.Window 2.15
+import org.krita.flake.text 1.0
+import org.krita.components 1.0 as Kis
+
+/**
+ \qmltype ResourcePopup
+ This is a button with an editable text that has a resource view attached inside
+ a popup. Users can type in text and have the popup show the closest names.
+ */
+Button {
+ id: resourceCmb;
+ wheelEnabled: true;
+
+ //--- Model setup. ---//
+
+ property alias modelWrapper : resourceView.modelWrapper;
+ property bool useFileName : true;
+
+ property alias view: resourceView;
+ property alias resourceType: resourceView.resourceType;
+ property alias resourceDelegate: resourceView.resourceDelegate;
+ property alias addResourceRowVisible: resourceView.addResourceRowVisible;
+
+ Connections {
+ target: modelWrapper;
+ function onResourceFilenameChanged() {
+ resourceCmb.resourceName = useFileName? modelWrapper.resourceFilename: modelWrapper.resourceName;
+ }
+ function onResourceNameChanged() {
+ resourceCmb.resourceName = useFileName? modelWrapper.resourceFilename: modelWrapper.resourceName;
+ }
+ }
+
+ property var locales: [];
+ property alias resourceName: textInput.text;
+ topPadding: 0;
+ bottomPadding: 0;
+ spacing: padding;
+ leftPadding: (resourceCmb.mirrored ? padding + indicator.width + spacing : 0);
+ rightPadding: (!resourceCmb.mirrored ? padding + indicator.width + spacing : 0);
+
+ Kis.ThemedControl {
+ id: palControl;
+ }
+ palette: palControl.palette;
+
+ /// Ideally we'd have the max popup height be Window-height - y-pos-of-item-to-window.
+ /// But that's pretty hard to calculate (map to global is screen relative, but there's
+ /// no way to get window.y relative to screen), so we'll just use 300 as the maximum.
+ property int maxPopupHeight: Math.min(Window.height, 500) - height*3;
+
+ contentItem: Kis.InformingTextInput {
+ id: textInput;
+
+ warnColor: palControl.theme.window.neutralBackgroundColor;
+ warnColorBorder: palControl.theme.window.neutralTextColor;
+ readOnly: !resourceCmb.enabled;
+
+ onEditingFinished: {
+ if (resourceCmbPopup.visible) {
+ resourceView.applyHighlightedIndex();
+ }
+
+ testInput();
+ resourceCmb.activated();
+ }
+ onTextChanged: {
+ testInput();
+ }
+
+ onTextEdited: {
+ stopWarning();
+ modelWrapper.searchText = text;
+ resourceView.showTagging = false;
+ resourceView.showSearch = false;
+ resourceCmbPopup.open();
+ }
+
+ onActiveFocusChanged: {
+ if (activeFocus) {
+ selectAll();
+ }
+ }
+
+ warningTimeOut: activeFocus? 1000: 0;
+
+ function testInput() {
+ let test = resourceCmb.useFileName? modelWrapper.testFileName(text): modelWrapper.testName(text);
+
+ if (typeof test === 'undefined') {
+ if (!activeFocus) {
+ startWarning();
+ }
+ } else {
+ stopWarning();
+ text = test;
+ if (resourceCmb.useFileName) {
+ modelWrapper.resourceFilename = text;
+ } else {
+ modelWrapper.resourceName = text;
+ }
+ }
+ }
+
+ Keys.onDownPressed: {
+ resourceView.downPress();
+ }
+ Keys.onUpPressed: {
+ resourceView.upPress();
+ }
+ }
+
+ indicator: Image {
+ id: imgIndicator
+ x: Math.round(resourceCmb.mirrored ? resourceCmb.padding : resourceCmb.width - width - resourceCmb.padding);
+ y: Math.round(resourceCmb.topPadding + (resourceCmb.availableHeight - height) / 2);
+ source: resourceCmb.palette.button.hslLightness < 0.5? "qrc:///light_groupOpened.svg": "qrc:///dark_groupOpened.svg";
+ width: 12;
+ height: 12;
+ clip: true;
+ }
+
+ onClicked: {
+ if (resourceCmbPopup.visible) {
+ resourceCmbPopup.close();
+ } else {
+ resourceView.showTagging = true;
+ resourceView.showSearch = true;
+ resourceCmbPopup.open();
+ }
+ }
+ signal activated();
+ onActivated: {
+ resourceCmbPopup.close();
+ modelWrapper.searchText = "";
+ }
+
+ //--- Pop up setup ---//
+ Popup {
+ id: resourceCmbPopup;
+ y: resourceCmb.height - 1;
+ x: resourceCmb.width - width;
+ width: Math.max(contentWidth, Math.max(resourceCmb.width, 200));
+ height: Math.min(contentItem.implicitHeight, resourceCmb.maxPopupHeight - topMargin - bottomMargin)
+ padding: 2;
+
+ palette: resourceCmb.palette;
+
+ contentItem: Kis.ResourceView {
+ id: resourceView;
+ palette: resourceCmbPopup.palette;
+ }
+ }
+}
diff --git a/plugins/dockers/textproperties/qml/ResourceView.qml b/qmlmodules/components/qml/ResourceView.qml
similarity index 86%
rename from plugins/dockers/textproperties/qml/ResourceView.qml
rename to qmlmodules/components/qml/ResourceView.qml
index a99aa37a65..204b70b6fd 100644
--- a/plugins/dockers/textproperties/qml/ResourceView.qml
+++ b/qmlmodules/components/qml/ResourceView.qml
@@ -9,9 +9,13 @@ import QtQuick.Layouts 1.15
import org.krita.flake.text 1.0
import org.krita.components 1.0 as Kis
+/**
+ \qmltype ResourceView
+ This provides a resource selector complete with filters, tagging and more.
+ */
Control {
id: control;
- property TagFilterProxyModelQmlWrapper modelWrapper: TagFilterProxyModelQmlWrapper {
+ property Kis.TagFilterProxyModelQmlWrapper modelWrapper: Kis.TagFilterProxyModelQmlWrapper {
resourceType: control.resourceType;
};
@@ -37,18 +41,51 @@ Control {
/*
-
+ \qmlProperty highlightedIndex
+ The currently hovered index on the resource selector.
*/
property alias highlightedIndex : view.currentIndex;
+ /*
+ \qmlProperty resourceDelegate
+ Resource Delegate. This is used to draw the delegates.
+ */
property alias resourceDelegate : view.delegate;
+ property alias addResourceRowVisible: addResourceRow.visible;
+ /*
+ \qmlProperty resourceDelegate
+ The add resource row, this contains by default import and remove resource.
+ */
property alias addResourceRow: addResourceRow;
+ /*
+ \qmlProperty additionalAddResourceRow
+ The additional resource row can be used to add extra toolbuttons.
+ */
property alias additionalAddResourceRow: addResourceRow.data;
+ /*
+ \qmlProperty showTagging
+ Show tagging functionality, bool.
+ */
property alias showTagging: tagAndConfig.visible;
+ /*
+ \qmlProperty showSearch
+ Show the search bar, bool.
+ */
property alias showSearch: searchBar.visible;
+ /*
+ \qmlProperty viewPreferredHeight
+ Preferred height of the resource list view.
+ */
+ property int preferredHeight: font.pixelSize * 15;
+ /*
+ \qmlProperty viewMinimumHeight
+ Minimum height of the resource list view.
+ */
+ property int minimumHeight: font.pixelSize * 3;
+
function downPress() {
highlightedIndex += 1;
}
@@ -217,13 +254,25 @@ Control {
}
}
Frame {
- Layout.minimumHeight: font.pixelSize*3;
+ id:viewFrame;
+ Layout.minimumHeight: control.minimumHeight + bottomPadding + topPadding;
Layout.fillWidth: true;
Layout.fillHeight: true;
- Layout.preferredHeight: font.pixelSize*15;
+ Layout.preferredHeight: control.preferredHeight + bottomPadding + topPadding;
+ Layout.maximumHeight: control.maximumHeight - (bottomPadding + topPadding);
palette: control.palette;
- clip: true;
+ padding: 1;
+ bottomPadding: padding;
+ topPadding: padding;
+
+ background: Rectangle {
+ border.color: palette.mid;
+ border.width: viewFrame.padding;
+ color: "transparent";
+ }
+
ListView {
+ clip: true;
anchors.fill: parent;
id: view;
currentIndex: 0;
diff --git a/qmlmodules/components/qml/resourceDelegates/CssStylePresetDelegate.qml b/qmlmodules/components/qml/resourceDelegates/CssStylePresetDelegate.qml
new file mode 100644
index 0000000000..bcee141c58
--- /dev/null
+++ b/qmlmodules/components/qml/resourceDelegates/CssStylePresetDelegate.qml
@@ -0,0 +1,95 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+import org.krita.components 1.0 as Kis
+
+/**
+ Item Delegate to handle CssStylePresets;
+ */
+ResourceDelegateBase {
+ id: presetDelegate;
+
+ property var meta: model.metadata;
+ width: ListView.view.width;
+
+ Kis.FontFunctions {
+ id: fontFunctions;
+ }
+
+ contentItem: Kis.KoShapeQtQuickLabel {
+ implicitHeight: nameLabel.height * 4;
+ padding: nameLabel.height;
+ alignment: presetDelegate.meta.sample_align;
+ scalingType: presetDelegate.meta.style_type === "paragraph"?
+ Kis.KoShapeQtQuickLabel.FitWidth: Kis.KoShapeQtQuickLabel.Fit;
+ svgData: presetDelegate.meta.sample_svg;
+ foregroundColor: presetDelegate.highlighted? palette.highlightedText: palette.text;
+
+ Label {
+ id: nameLabel;
+ palette: presetDelegate.palette;
+ text: presetDelegate.model.name;
+ anchors.top: parent.top;
+ anchors.left: parent.left;
+ anchors.right: parent.right;
+ elide: Text.ElideRight;
+ color: presetDelegate.highlighted? palette.highlightedText: palette.text;
+ }
+
+ Row {
+ anchors.bottom: parent.bottom;
+ anchors.left: parent.left;
+ anchors.right: parent.right;
+ ToolButton {
+ id: missingFamily;
+ visible: typeof presetDelegate.meta.primary_font_family !== 'undefined'?
+ presetDelegate.meta.primary_font_family !== ""
+ && typeof fontFunctions.wwsFontFamilyNameVariant(presetDelegate.meta.primary_font_family) === 'undefined': false;
+ icon.source: palette.window.hslLightness < 0.5? "qrc:///16_light_warning.svg": "qrc:///16_dark_warning.svg";
+ icon.height: 8;
+ icon.width: 8;
+ }
+ }
+ }
+ background: Rectangle {
+ color: presetDelegate.highlighted? presetDelegate.palette.highlight: "transparent";
+ border.color: presetDelegate.selected? presetDelegate.palette.highlight: presetDelegate.palette.mid;
+ border.width: presetDelegate.selected? 2: 1;
+ }
+
+ MouseArea {
+ id: delegateMouseArea;
+ acceptedButtons: Qt.RightButton | Qt.LeftButton;
+ anchors.fill: parent;
+ hoverEnabled: true;
+ preventStealing: true;
+ onClicked: {
+ if (mouse.button === Qt.RightButton) {
+ resourceView.openContextMenu(mouse.x, mouse.y, parent.model.name, parent.model.index);
+ } else {
+ resourceView.applyHighlightedIndex();
+ presetDelegate.resourceLeftClicked();
+ }
+ }
+ onDoubleClicked: {
+ resourceView.applyHighlightedIndex();
+ presetDelegate.resourceDoubleClicked();
+ }
+ onContainsMouseChanged: {
+ if (containsMouse) {
+ resourceView.highlightedIndex = parent.model.index;
+ }
+ }
+
+ readonly property string missingFontName : i18nc("%1 is name of a font family", "Font Family \"%1\" is missing on this machine. This style preset may not work correctly.", presetDelegate.meta.primary_font_family);
+ Kis.ToolTipBase {
+ text: (typeof presetDelegate.meta.description !== 'undefined'? presetDelegate.model.name + "\n" + presetDelegate.meta.description: presetDelegate.model.name) + (missingFamily.visible? "\n"+ delegateMouseArea.missingFontName: "");
+ visible: delegateMouseArea.containsMouse;
+ }
+
+ }
+}
diff --git a/qmlmodules/components/qml/resourceDelegates/FontFamilyDelegate.qml b/qmlmodules/components/qml/resourceDelegates/FontFamilyDelegate.qml
new file mode 100644
index 0000000000..31babf0d1a
--- /dev/null
+++ b/qmlmodules/components/qml/resourceDelegates/FontFamilyDelegate.qml
@@ -0,0 +1,242 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+import QtQuick.Layouts 1.15
+import org.krita.components 1.0 as Kis
+
+/**
+ Item Delegate to handle FontFamilies;
+ */
+ResourceDelegateBase {
+ /**
+ Ideally we'd just use required properties for the metadata etc.
+ However, when changing the modelwrapper in the font list,
+ there's a short moment where the model data is unavailable, so
+ instead we ensure we're not accessing undefined objects.
+
+ Not great, would like a better solution...
+ */
+ id: fontDelegateItem;
+ property var locales: [];
+ property string name: typeof model.name !== "undefined"? model.name: "";
+ property int index: model.index;
+ property string fontName: name;
+ property var metadata: model.metadata;
+ // TODO: change this to use the text locale, if possible.
+ property string sample: "";
+
+ onMetadataChanged: {
+ updateSample();
+ }
+
+ Component.onCompleted: {
+ updateSample();
+ }
+
+ signal activated();
+
+ Kis.FontFunctions {
+ id: fontFunctions;
+ }
+
+ function updateSample() {
+ if (typeof metadata === "undefined") return;
+ let samples = fontFunctions.getMapFromQVariant(metadata.sample_svg);
+ let sampleKeys = Object.keys(samples);
+ sample = "";
+ const latn = samples["s_Latn"];
+ if (sampleKeys.length > 0) {
+ if (latn) {
+ sample = latn;
+ } else {
+ let tag = sampleKeys[0];
+ sample = samples[tag];
+ }
+ }
+ if (fontDelegateItem.locales.length > 0) {
+ for (const locale of fontDelegateItem.locales) {
+ let tag = fontFunctions.sampleTagForQLocale(Qt.locale(locale));
+ let svg = samples[tag];
+ if (svg) {
+ sample = svg;
+ break;
+ }
+
+
+ }
+ }
+ }
+
+ width: ListView.view.width;
+
+ contentItem: Control {
+ id: delegateControl;
+
+ property alias highlighted: fontDelegateItem.highlighted;
+ palette: fontDelegateItem.palette;
+
+ property alias fontName: fontDelegateItem.fontName;
+
+ implicitHeight: nameLabel.height*4;
+
+ Loader {
+ anchors.fill: parent;
+ asynchronous: true;
+
+ sourceComponent: Component {
+ Kis.KoShapeQtQuickLabel {
+ id: fontFamilyDelegate;
+
+ Binding {
+ target: fontFamilyDelegate
+ property: "meta"
+ when: fontDelegateItem && typeof fontDelegateItem !== 'undefined' && typeof fontDelegateItem.metadata !== 'undefined';
+ value: fontDelegateItem.metadata;
+ }
+
+ property var meta: ({});
+ property bool colorBitmap : typeof meta.color_bitmap === 'boolean'? meta.color_bitmap: false;
+ property bool colorCLRV0 : typeof meta.color_clrv0 === 'boolean'? meta.color_clrv0: false;
+ property bool colorCLRV1 : typeof meta.color_clrv1 === 'boolean'? meta.color_clrv1: false;
+ property bool colorSVG : typeof meta.color_svg === 'boolean'? meta.color_svg: false;
+ property bool isVariable : typeof meta.is_variable === 'boolean'? meta.is_variable: false;
+ property int type : typeof meta.font_type === 'number'? meta.font_type: 0;
+
+ scalingType: Kis.KoShapeQtQuickLabel.FitHeight;
+ svgData: fontDelegateItem.sample;
+ foregroundColor: delegateControl.highlighted? palette.highlightedText: palette.text;
+ fillColor: delegateControl.highlighted? fontDelegateItem.palette.highlight: fontDelegateItem.palette.window;
+ fullColor: colorBitmap || colorCLRV0 || colorCLRV1 || colorSVG;
+ padding: nameLabel.height;
+
+
+ Row {
+ id: featureRow;
+ spacing: fontDelegateItem.spacing;
+ anchors.bottom: parent.bottom;
+ anchors.left: parent.left;
+ property int imgHeight: 12;
+ ToolButton {
+ enabled: false;
+ padding:0;
+ width: parent.imgHeight;
+ height: parent.imgHeight;
+ property int type: fontFamilyDelegate.type;
+ icon.width: parent.imgHeight;
+ icon.height: parent.imgHeight;
+ palette: fontDelegateItem.palette;
+ icon.color: nameLabel.color;
+ icon.source: fontFunctions.isBitmapType(type)? "qrc:///font-type-bitmap.svg"
+ : fontFunctions.isPostScriptType(type)? "qrc:///font-type-postscript.svg"
+ : fontFunctions.isOpenType(type)? "qrc:///font-type-opentype.svg":"qrc:///light_system-help.svg";
+ }
+ ToolButton {
+ enabled: false;
+ padding: 0;
+ width: parent.imgHeight;
+ height: parent.imgHeight;
+ icon.width: parent.imgHeight;
+ icon.height: parent.imgHeight;
+ palette: fontDelegateItem.palette;
+ icon.color: nameLabel.color;
+ visible: fontFamilyDelegate.isVariable;
+ icon.source: "qrc:///font-type-opentype-variable.svg"
+ }
+
+ ToolButton {
+ enabled: false;
+ padding: 0;
+ width: parent.imgHeight;
+ height: parent.imgHeight;
+ icon.width: parent.imgHeight;
+ icon.height: parent.imgHeight;
+ visible: fontFamilyDelegate.colorBitmap;
+ icon.source: "qrc:///font-color-type-clr-bitmap.svg"
+ }
+ ToolButton {
+ enabled: false
+ padding: 0;
+ width: parent.imgHeight;
+ height: parent.imgHeight;
+ icon.width: parent.imgHeight;
+ icon.height: parent.imgHeight;
+ visible: fontFamilyDelegate.colorCLRV0;
+ icon.source: "qrc:///font-color-type-clr-v0.svg"
+ }
+ ToolButton {
+ padding: 0;
+ enabled: false;
+ width: parent.imgHeight;
+ height: parent.imgHeight;
+ icon.width: parent.imgHeight;
+ icon.height: parent.imgHeight;
+ visible: fontFamilyDelegate.colorCLRV1;
+ icon.source: "qrc:///font-color-type-clr-v1.svg"
+ }
+ ToolButton {
+ enabled: false;
+ padding: 0;
+ width: parent.imgHeight;
+ height: parent.imgHeight;
+ icon.width: parent.imgHeight;
+ icon.height: parent.imgHeight;
+ visible: fontFamilyDelegate.colorSVG;
+ icon.source: "qrc:///font-color-type-svg.svg"
+ }
+ }
+ }
+ }
+ }
+
+ Label {
+ id: nameLabel;
+ palette: fontDelegateItem.palette;
+ text: delegateControl.fontName;
+ anchors.top: parent.top;
+ anchors.left: parent.left;
+ elide: Text.ElideRight;
+ width: parent.width;
+ color: parent.highlighted? palette.highlightedText: palette.text;
+ }
+
+ }
+ background: Rectangle {
+ id: fontDelegateBackground
+ color: highlighted? fontDelegateItem.palette.highlight: fontDelegateItem.palette.window;
+ }
+
+ MouseArea {
+ id: delegateMouseArea;
+ acceptedButtons: Qt.RightButton | Qt.LeftButton;
+ anchors.fill: parent;
+ hoverEnabled: true;
+ // Itemdelegate can also handle hovers, but we don't use those.
+ preventStealing: true;
+ onClicked: {
+ if (mouse.button === Qt.RightButton) {
+ resourceView.openContextMenu(mouse.x, mouse.y, parent.model.name, parent.index);
+ } else {
+ resourceView.applyHighlightedIndex();
+ fontDelegateItem.resourceLeftClicked();
+ }
+ }
+ onDoubleClicked: {
+ fontDelegateItem.resourceDoubleClicked();
+ }
+
+ onContainsMouseChanged: {
+ if(containsMouse) {
+ resourceView.highlightedIndex = parent.index;
+ }
+ }
+
+ Kis.ToolTipBase {
+ text: fontDelegateItem.fontName;
+ visible: delegateMouseArea.containsMouse;
+ }
+ }
+}
diff --git a/qmlmodules/components/qml/resourceDelegates/ResourceDelegateBase.qml b/qmlmodules/components/qml/resourceDelegates/ResourceDelegateBase.qml
new file mode 100644
index 0000000000..e9b4cf74f0
--- /dev/null
+++ b/qmlmodules/components/qml/resourceDelegates/ResourceDelegateBase.qml
@@ -0,0 +1,22 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+import QtQuick.Layouts 1.15
+import org.krita.components 1.0 as Kis
+
+ItemDelegate {
+ required property var model;
+ property Kis.ResourceView resourceView;
+
+ signal resourceLeftClicked();
+ signal resourceDoubleClicked();
+
+ highlighted: resourceView.highlightedIndex === model.index;
+ property bool selected: resourceView.modelWrapper.currentIndex === model.index;
+
+ palette: resourceView.palette;
+}