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

Speed up the font family dropdown in the text properties docker.

Wolthera van Hövell tot Westerflierd6b1531c2377
diff --git a/HACKING b/HACKING
index 64438cc470..824f5dd944 100644
--- a/HACKING
+++ b/HACKING
@@ -300,3 +300,21 @@ pep8.py --ignore=E501
You can read more about the error codes and what they mean here:
http://pep8.readthedocs.io/en/release-1.7.x/intro.html#error-codes
+
+QML Notes:
+
+ While the hacking file is not a good place to discuss human interface design, there are some technical
+ oddities with QML to take into account:
+
+ - Height, Implicit Height and Content Height can get very confusing. In theory, implicit height is only used
+ when height isn't set, but this is complicated by delegates never using the height property, and only using
+ implicit height. Furthermore, contentHeight, and contentItem.implicitHeight are only relevant when the item
+ has a contentItem, like with AbstractButtons and PopUps, but commonly, the implicit height of these
+ is already set to the contentHeight, so doesn't need to be set (and can in fact lead to slowdowns).
+ Conversely, if no implicit height is set on the content item, the content item will take the height
+ and width from the parent button or popup.
+ - Similarly, ListViews are not supossed to instatiate delegates outside of their views, but if a ListViews
+ is instatiated with their height set to contentHeight, then, even as the ListView resizes itself later, it
+ will instantiate a delegate for every single item it could lay out upon the ListView itself be instantiated.
+ It's better to set the default height of the ListView to something bounded, like the fontSize * 3, and then
+ ensure it is resized later.
diff --git a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
index 00b0396a7f..be10fbeb53 100644
--- a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
+++ b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
@@ -46,43 +46,135 @@ Button {
id: fontDelegateItem;
required property var model;
property string fontName: model.name;
- property var meta: familyCmb.modelWrapper.metadataForIndex(model.index);
+ property var meta: model.metadata;
// TODO: change this to use the text locale, if possible.
- property string sample: familyCmb.modelWrapper.localizedSampleFromMetadata(meta, locales, "");
+ property string sample: "";
+ onMetaChanged: {
+ sample = familyCmb.modelWrapper.localizedSampleFromMetadata(meta, locales, "");
+ fontName = familyCmb.modelWrapper.localizedNameFromMetadata(meta, locales, model.name);
+ }
+
/// 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: familyCmb.highlightedIndex === model.index;
- Component.onCompleted: {
- fontName = familyCmb.modelWrapper.localizedNameFromMetadata(meta, locales, model.name);
- }
-
palette: familyCmb.palette;
- contentItem: KoShapeQtQuickLabel {
- id: fontFamilyDelegate;
- property alias meta: fontDelegateItem.meta;
+ contentItem: Control {
+ id: delegateControl;
+
property alias highlighted: fontDelegateItem.highlighted;
- property alias palette: fontDelegateItem.palette;
- 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;
+ palette: fontDelegateItem.palette;
+
property string fontName: fontDelegateItem.fontName;
- padding: nameLabel.height;
- scalingType: KoShapeQtQuickLabel.FitHeight;
- svgData: fontDelegateItem.sample;
- foregroundColor: highlighted? palette.highlightedText: palette.text;
- fullColor: colorBitmap || colorCLRV0 || colorCLRV1 || colorSVG;
- implicitHeight: padding*4;
+
+ implicitHeight: nameLabel.height*4;
+
+ Loader {
+ anchors.fill: parent;
+ asynchronous: true;
+ sourceComponent: Component {
+ KoShapeQtQuickLabel {
+ id: fontFamilyDelegate;
+
+ property var meta: fontDelegateItem.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: fontFamilyDelegate.fontName;
+ text: delegateControl.fontName;
anchors.top: parent.top;
anchors.left: parent.left;
elide: Text.ElideRight;
@@ -90,83 +182,10 @@ Button {
color: parent.highlighted? palette.highlightedText: palette.text;
}
- 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"
- }
- }
}
background: Rectangle {
- color: highlighted? familyCmb.palette.highlight: "transparent";
+ id: fontDelegateBackground
+ color: highlighted? familyCmb.palette.highlight: familyCmb.palette.window;
}
MouseArea {
diff --git a/plugins/dockers/textproperties/qml/OpenTypeFeatureSettings.qml b/plugins/dockers/textproperties/qml/OpenTypeFeatureSettings.qml
index 245c722553..e89546b022 100644
--- a/plugins/dockers/textproperties/qml/OpenTypeFeatureSettings.qml
+++ b/plugins/dockers/textproperties/qml/OpenTypeFeatureSettings.qml
@@ -65,6 +65,7 @@ TextPropertyBase {
Layout.preferredHeight: contentHeight;
Layout.minimumHeight: noContentLabel.contentHeight;
spacing: columnSpacing;
+ reuseItems: true;
Label {
id: noContentLabel;
@@ -241,13 +242,14 @@ TextPropertyBase {
x: 0;
padding: 0;
width: featureTxtEdit.width;
- height: Math.min(contentItem.implicitHeight, 300);
+ height: contentItem.implicitHeight;
property string highlightedTag;
contentItem: ListView {
model: featureTxtEdit.filterModel;
clip: true;
- implicitHeight: contentHeight;
+ implicitHeight: Math.min(contentHeight, 300);
width: completerPopup.width;
+ reuseItems: true;
ScrollBar.vertical: ScrollBar {
}
diff --git a/plugins/dockers/textproperties/qml/ResourceView.qml b/plugins/dockers/textproperties/qml/ResourceView.qml
index bd7be72290..251b5ffa9f 100644
--- a/plugins/dockers/textproperties/qml/ResourceView.qml
+++ b/plugins/dockers/textproperties/qml/ResourceView.qml
@@ -34,7 +34,7 @@ Control {
anchors.fill: parent;
property alias resourceModel : view.model;
property alias tagModel: tagFilter.model;
- resourceModel: modelWrapper.model;
+ resourceModel: visible? modelWrapper.model: null;
tagModel: modelWrapper.tagModel;
RowLayout {
@@ -179,14 +179,14 @@ Control {
Layout.minimumHeight: font.pixelSize*3;
Layout.fillWidth: true;
Layout.fillHeight: true;
- Layout.preferredHeight: contentHeight;
+ Layout.preferredHeight: font.pixelSize*15;
palette: control.palette;
clip: true;
ListView {
anchors.fill: parent;
id: view;
- implicitHeight: contentHeight;
currentIndex: modelWrapper.currentIndex;
+ reuseItems: true;
ScrollBar.vertical: ScrollBar {
}
}
diff --git a/plugins/dockers/textproperties/qml/TextProperties.qml b/plugins/dockers/textproperties/qml/TextProperties.qml
index 03a7817f22..3e9882f78c 100644
--- a/plugins/dockers/textproperties/qml/TextProperties.qml
+++ b/plugins/dockers/textproperties/qml/TextProperties.qml
@@ -171,6 +171,12 @@ Rectangle {
icon.height: 16;
onClicked: mainWindow.editPreset(presetView.currentResource);
hoverEnabled: true;
+ PaletteControl {
+ id: editPalette;
+ }
+ palette: editPalette.palette;
+
+ enabled: presetView.currentIndex >= 0;
ToolTip.visible: hovered;
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval;
ToolTip.text: text;