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++
Rework font family to allow fallback family selection.
Wolthera van Hövell tot Westerflierc3416e6cf2e5
diff --git a/plugins/dockers/textproperties/qml/FontFamily.qml b/plugins/dockers/textproperties/qml/FontFamily.qmlindex 89601f524f..2999d84989 100644--- a/plugins/dockers/textproperties/qml/FontFamily.qml+++ b/plugins/dockers/textproperties/qml/FontFamily.qml@@ -50,123 +50,19 @@ CollapsibleGroupProperty {Layout.maximumWidth: contentWidth;}- ComboBox {- id: mainFamilyCmb;- model: fontFamilyModel;- Layout.fillWidth: true;- onActivated: {if (fontFamilies.length >0) {- fontFamilies[0] = currentText;- }- }- textRole: "name";-- delegate: ItemDelegate {- id: fontDelegate- required property var model;-- highlighted: mainFamilyCmb.highlightedIndex === model.index;- contentItem: KoShapeQtQuickLabel{- id: fontFamilyDelegate;- property bool colorBitmap : model.metadata.color_bitmap;- property bool colorCLRV0 : model.metadata.color_clrv0;- property bool colorCLRV1 : model.metadata.color_clrv1;- property bool colorSVG : model.metadata.color_svg;- property bool isVariable : model.metadata.is_variable;- property int type : model.metadata.font_type;- property string fontName: model.name;-- Layout.fillWidth: true;- svgData: model.metadata.sample_svg;- imageScale: 3;- imagePadding: nameLabel.height;- foregroundColor: sysPalette.text;- fullColor: colorBitmap || colorCLRV0 || colorCLRV1 || colorSVG;-- Component.onCompleted: {- var localizedDict = model.metadata.localized_font_family;- for (var i in locales) {- var key = locales[i];- if (key in localizedDict) {- fontName = localizedDict[key];- break;- }- }- }-- Label {- id: nameLabel;- text: fontFamilyDelegate.fontName;- anchors.top: parent.top;- anchors.left: parent.left;- }-- Row {- id: featureRow;- spacing: columnSpacing;- anchors.bottom: parent.bottom;- anchors.left: parent.left;- property int imgHeight: 12;- Image {- property int type: fontFamilyDelegate.type;- width: parent.imgHeight;- height: parent.imgHeight;- source: type === KoSvgText.BDFFontType? "qrc:///light_select-pixel.svg"- : type === KoSvgText.Type1FontType? "qrc:///light_transparency-enabled.svg"- : type === KoSvgText.OpenTypeFontType? "qrc:///light_select-shape.svg":"qrc:///light_system-help.svg";- }- Image {- width: parent.imgHeight;- height: parent.imgHeight;- visible: fontFamilyDelegate.isVariable;- source: "qrc:///light_zoom-horizontal.svg"- }-- Image {- width: parent.imgHeight;- height: parent.imgHeight;- visible: fontFamilyDelegate.colorBitmap;- source: "qrc:///light_palette-library.svg"- }- Image {- width: parent.imgHeight;- height: parent.imgHeight;- visible: fontFamilyDelegate.colorCLRV0;- source: "qrc:///light_color-adjustment-mode-channels.svg"- }- Image {- width: parent.imgHeight;- height: parent.imgHeight;- visible: fontFamilyDelegate.colorCLRV1;- source: "qrc:///light_config-color-manage.svg"- }- Image {- width: parent.imgHeight;- height: parent.imgHeight;- visible: fontFamilyDelegate.colorSVG;- source: "qrc:///light_sort-by-hue.svg"- }+ FontResourceDropdown {+ id: mainFamilyCmb;+ model: fontFamilyModel;+ Layout.fillWidth: true;+ onActivated: {+ if (fontFamilies.length >0) {+ fontFamilies[0] = currentText;+ } else {+ fontFamilies = [ currentText ];}}- width: fontResourceView.listWidth;- background: Rectangle { color: highlighted? parent.palette.highlight:"transparent"; }- }- popup: Popup {- y: mainFamilyCmb.height - 1;- x: mainFamilyCmb.width - width;- width: contentWidth;- height: contentHeight;- padding: 2;-- contentItem: FontResourceView {- id: fontResourceView;- fontModel: mainFamilyCmb.delegateModel;- tagModel: fontTagModel;- currentIndex: mainFamilyCmb.highlightedIndex;- }- palette: mainFamilyCmb.palette;}- wheelEnabled: true;- }+}onEnableProperty: properties.fontFamiliesState = KoSvgTextPropertiesModel.PropertySet;@@ -185,22 +81,38 @@ CollapsibleGroupProperty {ScrollView {id: fullFamilyList;Layout.fillWidth: true;- Layout.preferredHeight: ItemDelegate.implicitHeight * 3;- background: Rectangle {- color: sysPalette.alternateBase;- border.color: sysPalette.text;- border.width: 1;- }+ Layout.preferredHeight: contentHeight;ListView {id: familyListView;anchors.fill: parent;model: []- delegate: ItemDelegate {- text: modelData;++ delegate: RowLayout {+ id: fontListDelegate;+ spacing: 5;width: parent.width;+ property int dIndex: index;+ FontResourceDropdown {+ model: fontFamilyModel;+ Layout.fillWidth: true;+ onActivated: {+ fontFamilies[fontListDelegate.dIndex] = currentText;+ }+ Component.onCompleted: currentIndex = find(fontFamilies[fontListDelegate.dIndex]);+ }+ ToolButton {+ id: removeFont;+ icon.width: 22;+ icon.height: 22;+ icon.source: "qrc:///22_light_list-remove.svg"+ onClicked: fontFamilies.splice(fontListDelegate.dIndex, 1);+ ToolTip.text: i18n("Remove family");+ ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval;+ ToolTip.visible: hovered;+ }}Label {- text: i18n("Family list is empty");+ text: i18n("Family list is empty.");wrapMode: Text.WordWrap;anchors.fill: parent;anchors.horizontalCenter: parent.horizontalCenter;@@ -209,6 +121,17 @@ CollapsibleGroupProperty {}}+ Item {+ width: 1;+ height: 1;+ }+ Button {+ id: addFamilyButtons;+ Layout.fillWidth: true;+ text: i18n("Add Fallback Family");+ onClicked: fontFamilies.push("sans-serif");+ }+}}diff --git a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml b/plugins/dockers/textproperties/qml/FontResourceDropdown.qmlnew file mode 100644index 0000000000..08f6278104--- /dev/null+++ b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml@@ -0,0 +1,176 @@+/*+ * 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 org.krita.flake.text 1.0++ComboBox {+ id: familyCmb;++ Component {+ id: fontDelegate+ ItemDelegate {+ required property var model;++ highlighted: familyCmb.highlightedIndex === model.index;+ contentItem: KoShapeQtQuickLabel{+ id: fontFamilyDelegate;+ property bool colorBitmap : model.metadata.color_bitmap;+ property bool colorCLRV0 : model.metadata.color_clrv0;+ property bool colorCLRV1 : model.metadata.color_clrv1;+ property bool colorSVG : model.metadata.color_svg;+ property bool isVariable : model.metadata.is_variable;+ property int type : model.metadata.font_type;+ property string fontName: model.name;++ Layout.fillWidth: true;+ svgData: model.metadata.sample_svg;+ imageScale: 3;+ imagePadding: nameLabel.height;+ foregroundColor: sysPalette.text;+ fullColor: colorBitmap || colorCLRV0 || colorCLRV1 || colorSVG;++ Component.onCompleted: {+ var localizedDict = model.metadata.localized_font_family;+ for (var i in locales) {+ var key = locales[i];+ if (key in localizedDict) {+ fontName = localizedDict[key];+ break;+ }+ }+ }++ Label {+ id: nameLabel;+ text: fontFamilyDelegate.fontName;+ anchors.top: parent.top;+ anchors.left: parent.left;+ }++ Row {+ id: featureRow;+ spacing: columnSpacing;+ anchors.bottom: parent.bottom;+ anchors.left: parent.left;+ property int imgHeight: 12;+ Image {+ property int type: fontFamilyDelegate.type;+ width: parent.imgHeight;+ height: parent.imgHeight;+ source: type === KoSvgText.BDFFontType? "qrc:///light_select-pixel.svg"+ : type === KoSvgText.Type1FontType? "qrc:///light_transparency-enabled.svg"+ : type === KoSvgText.OpenTypeFontType? "qrc:///light_select-shape.svg":"qrc:///light_system-help.svg";+ }+ Image {+ width: parent.imgHeight;+ height: parent.imgHeight;+ visible: fontFamilyDelegate.isVariable;+ source: "qrc:///light_zoom-horizontal.svg"+ }++ Image {+ width: parent.imgHeight;+ height: parent.imgHeight;+ visible: fontFamilyDelegate.colorBitmap;+ source: "qrc:///light_palette-library.svg"+ }+ Image {+ width: parent.imgHeight;+ height: parent.imgHeight;+ visible: fontFamilyDelegate.colorCLRV0;+ source: "qrc:///light_color-adjustment-mode-channels.svg"+ }+ Image {+ width: parent.imgHeight;+ height: parent.imgHeight;+ visible: fontFamilyDelegate.colorCLRV1;+ source: "qrc:///light_config-color-manage.svg"+ }+ Image {+ width: parent.imgHeight;+ height: parent.imgHeight;+ visible: fontFamilyDelegate.colorSVG;+ source: "qrc:///light_sort-by-hue.svg"+ }+ }+ }+ width: fontResourceView.listWidth;+ background: Rectangle { color: highlighted? parent.palette.highlight:"transparent"; }+ }+ }+++ textRole: "name";++ delegate: fontDelegate;+ popup: Popup {+ y: familyCmb.height - 1;+ x: familyCmb.width - width;+ width: contentWidth;+ height: contentHeight;+ padding: 2;++ contentItem:+ ColumnLayout {+ id: fontResourceView;+ fontModel: familyCmb.delegateModel;+ tagModel: fontTagModel;+ currentIndex: familyCmb.highlightedIndex;+ clip:true;+ property var fontModel;+ property var tagModel;+ property alias currentIndex : view.currentIndex;+ property alias listWidth : view.width;++ RowLayout {+ id: tagAndConfig;++ ComboBox {+ id: tagFilter;+ model: fontResourceView.tagModel;+ textRole: "display";+ Layout.fillWidth: true;+ onActivated: {+ mainWindow.slotFontTagActivated(currentIndex);+ }+ }++ }+ Frame {+ Layout.minimumHeight: font.pixelSize*3;+ Layout.preferredHeight: 300;+ Layout.maximumHeight: 500;+ Layout.fillWidth: true;+ clip: true;+ ListView {+ anchors.fill: parent;+ id: view;+ model: fontResourceView.fontModel;+ ScrollBar.vertical: ScrollBar {+ }+ }+ }+ RowLayout {+ Layout.preferredHeight: childrenRect.height;+ TextField {+ id: search;+ placeholderText: i18nc("@info:placeholder", "Search...");+ Layout.fillWidth: true;+ onTextEdited: mainWindow.slotFontSearchTextChanged(text);+ }+ CheckBox {+ id: opticalSizeCbx+ text: i18nc("@option:check", "Search in tag")+ onCheckedChanged: mainWindow.slotFontSearchInTag(checked);+ }+ }+ }+ palette: familyCmb.palette;+ }+ wheelEnabled: true;+}diff --git a/plugins/dockers/textproperties/qml/FontResourceView.qml b/plugins/dockers/textproperties/qml/FontResourceView.qmldeleted file mode 100644index 337f9ab242..0000000000--- a/plugins/dockers/textproperties/qml/FontResourceView.qml+++ /dev/null@@ -1,62 +0,0 @@-/*- * 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 org.krita.flake.text 1.0---ColumnLayout {- id: root;- clip:true;- property var fontModel;- property var tagModel;- property alias currentIndex : view.currentIndex;- property alias listWidth : view.width;-- RowLayout {- id: tagAndConfig;-- ComboBox {- id: tagFilter;- model: tagModel;- textRole: "display";- Layout.fillWidth: true;- onActivated: {- mainWindow.slotFontTagActivated(currentIndex);- }- }-- }- Frame {- Layout.minimumHeight: font.pixelSize*3;- Layout.preferredHeight: 300;- Layout.maximumHeight: 500;- Layout.fillWidth: true;- clip: true;- ListView {- anchors.fill: parent;- id: view;- model: fontModel;- ScrollBar.vertical: ScrollBar {- }- }- }- RowLayout {- Layout.preferredHeight: childrenRect.height;- TextField {- id: search;- placeholderText: i18nc("@info:placeholder", "Search...");- Layout.fillWidth: true;- onTextEdited: mainWindow.slotFontSearchTextChanged(text);- }- CheckBox {- id: opticalSizeCbx- text: i18nc("@option:check", "Search in tag")- onCheckedChanged: mainWindow.slotFontSearchInTag(checked);- }- }-}diff --git a/plugins/dockers/textproperties/textproperties.qrc b/plugins/dockers/textproperties/textproperties.qrcindex 4190ddca17..97a4bc61a8 100644--- a/plugins/dockers/textproperties/textproperties.qrc+++ b/plugins/dockers/textproperties/textproperties.qrc@@ -34,6 +34,6 @@<file alias="UnitComboBox.qml">qml/UnitComboBox.qml</file><file alias="DoubleSpinBox.qml">qml/DoubleSpinBox.qml</file><file alias="light_edit-undo-tristate.svg">icons/light_edit-undo-tristate.svg</file>- <file alias="FontResourceView.qml">qml/FontResourceView.qml</file>+ <file alias="FontResourceDropdown.qml">qml/FontResourceDropdown.qml</file></qresource></RCC>