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

Replace "add property" with a filter bar when default text property visibility is alwaysVisible.

Wolthera van Hövell tot Westerfliereca65cc42b31
diff --git a/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml b/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml
index 7e99183e16..e4329b102c 100644
--- a/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml
+++ b/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml
@@ -28,10 +28,19 @@ ColumnLayout {
showParagraphProperties: propertyBaseList.propertyType === TextPropertyConfigModel.Paragraph;
onShowParagraphPropertiesChanged: fillPropertyList();
filterCaseSensitivity: Qt.CaseInsensitive;
+
+ property bool isFiltering: configModel.defaultVisibilityState === TextPropertyConfigModel.AlwaysVisible;
+
+ onFilteredNamesChanged: {
+ if (isFiltering) {
+ updatePropertyVisibilityState();
+ }
+ }
}
onConfigModelChanged: {if (configModel != null) fillPropertyList();}
+ /// Initialize the property list and add each property to the TextPropertyConfigModel.
function fillPropertyList() {
for (var i = 0; i < propertyWidgetModel.count; i++) {
let prop = propertyWidgetModel.get(i);
@@ -43,16 +52,18 @@ ColumnLayout {
prop.visibilityState
);
- if (testShowProperty(prop.propertyType)) {
+ if (testShowProperty(prop.propertyType) && !shouldFilter(prop.propertyName)) {
prop.setVisibleFromProperty();
} else {
prop.visible = false;
}
}
- textPropertyConfigModel.loadFromConfiguration();
+ configModel.loadFromConfiguration();
updatePropertyVisibilityState();
}
+ /// Test if the current propertyType is the same as the one for this list.
+ /// Used to filter out paragraph-properties from character property list and vice-versa.
function testShowProperty(propertyType) {
if (filteredConfigModel.showParagraphProperties && propertyType === TextPropertyConfigModel.Character) {
return false;
@@ -62,29 +73,52 @@ ColumnLayout {
return true;
}
+ /// Update properties on the list or hide them.
function updateProperties() {
for (var i = 0; i < propertyWidgetModel.count; i++) {
- if (testShowProperty(propertyWidgetModel.get(i).propertyType)) {
- propertyWidgetModel.get(i).propertiesUpdated();
+ let prop = propertyWidgetModel.get(i);
+ if (testShowProperty(prop.propertyType)) {
+ prop.propertiesUpdated();
+ if (shouldFilter(prop.propertyName)) {
+ prop.visible = false;
+ }
} else {
- propertyWidgetModel.get(i).visible = false;
+ prop.visible = false;
}
}
}
+ /// Check if we're filtering at all...
+ function shouldFilter(name) {
+ if (!filteredConfigModel.isFiltering) return false;
+ if (filteredConfigModel.filteredNames.length === 0) return false;
+ if (filteredConfigModel.filteredNames.indexOf(name) < 0) {
+ return true;
+ }
+ return false;
+ }
+
+ /// Update the visibility state from the config.
function updatePropertyVisibilityState() {
for (var i = 0; i < propertyWidgetModel.count; i++) {
- let name = propertyWidgetModel.get(i).propertyName;
- propertyWidgetModel.get(i).defaultVisibilityState = configModel.defaultVisibilityState;
- propertyWidgetModel.get(i).visibilityState = configModel.visibilityStateForName(name);
- if (testShowProperty(propertyWidgetModel.get(i).propertyType)) {
- propertyWidgetModel.get(i).setVisibleFromProperty();
+ let prop = propertyWidgetModel.get(i);
+ let name = prop.propertyName;
+ prop.defaultVisibilityState = configModel.defaultVisibilityState;
+ prop.visibilityState = configModel.visibilityStateForName(name);
+
+ if (testShowProperty(prop.propertyType)) {
+ if (shouldFilter(name)) {
+ prop.visible = false;
+ } else {
+ prop.setVisibleFromProperty();
+ }
} else {
- propertyWidgetModel.get(i).visible = false;
+ prop.visible = false;
}
}
}
+ /// when the text property with the current propertyName is visible
function isVisible(name) {
for (var i = 0; i < propertyWidgetModel.count; i++) {
let prop = propertyWidgetModel.get(i);
@@ -94,6 +128,7 @@ ColumnLayout {
}
}
+ /// Enable the property with the current property name.
function enableProperty(name) {
for (var i = 0; i < propertyWidgetModel.count; i++) {
if (name === propertyWidgetModel.get(i).propertyName) {
@@ -191,95 +226,125 @@ ColumnLayout {
}
}
- ComboBox {
- id: addPropertyCmb;
+ RowLayout {
Layout.fillWidth: true;
- Layout.minimumHeight: implicitHeight;
- model: filteredConfigModel;
- textRole: "display";
- displayText: i18nc("@label:listbox", "Add Property");
- onPopupChanged: if (!addPropertyCmb.popup.visible) { propertySearch.text = ""; }
-
- PaletteControl {
- id: cmbPalette;
- colorGroup: addPropertyCmb.enabled? SystemPalette.Active: SystemPalette.Disabled;
- }
- palette: cmbPalette.palette;
-
- function enableProperty(name) {
- propertySearch.blockSignals = true;
- propertySearch.text = "";
- propertyBaseList.enableProperty(name);
- popup.close();
- propertySearch.blockSignals = false;
- }
-
- contentItem: TextField {
- id: propertySearch;
- placeholderText: i18nc("@info:placeholder", "Add Property...");
+ TextField {
+ id: filterPropertyLn;
+ Layout.fillWidth: true;
+ Layout.minimumHeight: implicitHeight;
+ placeholderText: i18nc("@info:placeholder", "Filter...");
- verticalAlignment: Text.AlignVCenter
- font: addPropertyCmb.font
- color: addPropertyCmb.palette.text
- selectionColor: addPropertyCmb.palette.highlight
- selectedTextColor: addPropertyCmb.palette.highlightedText;
-
- property bool blockSignals: false;
-
- selectByMouse: true;
+ visible: filteredConfigModel.isFiltering;
+ onVisibleChanged: {
+ if (visible) {
+ text = "";
+ }
+ }
onTextChanged: {
- if (text !== "") {
- filteredConfigModel.setFilterRegularExpression(text);
- addPropertyCmb.popup.open();
- } else {
- addPropertyCmb.popup.close();
+ if (visible) {
filteredConfigModel.setFilterRegularExpression(text);
}
}
+ }
- onAccepted: {
- blockSignals = true;
- let name = filteredConfigModel.filteredNames[addPropertyCmb.highlightedIndex]
- if (typeof name != 'undefined') {
- addPropertyCmb.enableProperty(name);
+ ComboBox {
+ id: addPropertyCmb;
+ visible: !filteredConfigModel.isFiltering;
+ onVisibleChanged: {
+ if (visible) {
+ filteredConfigModel.setFilterRegularExpression("");
}
- text = "";
- blockSignals = false;
}
- }
- delegate: ItemDelegate {
- id: addPropertyDelegate;
- width: addPropertyCmb.width;
- required property var model;
- required property string title;
- required property string name;
- required property int index;
- required property string toolTip;
- contentItem: Label {
- enabled: addPropertyDelegate.enabled;
- PaletteControl {
- id: addPropertyPalette;
- colorGroup: parent.enabled? SystemPalette.Active: SystemPalette.Disabled;
- }
- palette: addPropertyPalette.palette;
- color: addPropertyDelegate.highlighted? palette.highlightedText: palette.text;
- text: addPropertyDelegate.title;
- elide: Text.ElideRight;
+ Layout.fillWidth: true;
+ Layout.minimumHeight: implicitHeight;
+ model: filteredConfigModel;
+ textRole: "display";
+ displayText: i18nc("@label:listbox", "Add Property");
+ onPopupChanged: if (!addPropertyCmb.popup.visible) { propertySearch.text = ""; }
+
+ PaletteControl {
+ id: cmbPalette;
+ colorGroup: addPropertyCmb.enabled? SystemPalette.Active: SystemPalette.Disabled;
+ }
+ palette: cmbPalette.palette;
+
+ function enableProperty(name) {
+ propertySearch.blockSignals = true;
+ propertySearch.text = "";
+ propertyBaseList.enableProperty(name);
+ popup.close();
+ propertySearch.blockSignals = false;
+ }
+
+ contentItem: TextField {
+ id: propertySearch;
+ placeholderText: i18nc("@info:placeholder", "Add Property...");
+
verticalAlignment: Text.AlignVCenter
+ font: addPropertyCmb.font
+ color: addPropertyCmb.palette.text
+ selectionColor: addPropertyCmb.palette.highlight
+ selectedTextColor: addPropertyCmb.palette.highlightedText;
+
+ property bool blockSignals: false;
+
+ selectByMouse: true;
+
+ onTextChanged: {
+ if (text !== "") {
+ filteredConfigModel.setFilterRegularExpression(text);
+ addPropertyCmb.popup.open();
+ } else {
+ addPropertyCmb.popup.close();
+ filteredConfigModel.setFilterRegularExpression(text);
+ }
+ }
+
+ onAccepted: {
+ blockSignals = true;
+ let name = filteredConfigModel.filteredNames[addPropertyCmb.highlightedIndex]
+ if (typeof name != 'undefined') {
+ addPropertyCmb.enableProperty(name);
+ }
+ text = "";
+ blockSignals = false;
+ }
}
- enabled: !isVisible(name);
- highlighted: addPropertyCmb.highlightedIndex === index;
- background: Rectangle { color: highlighted? parent.palette.highlight:"transparent"; }
- ToolTip.text: toolTip;
- ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
- ToolTip.visible: highlighted;
+ delegate: ItemDelegate {
+ id: addPropertyDelegate;
+ width: addPropertyCmb.width;
+ required property var model;
+ required property string title;
+ required property string name;
+ required property int index;
+ required property string toolTip;
+ contentItem: Label {
+ enabled: addPropertyDelegate.enabled;
+ PaletteControl {
+ id: addPropertyPalette;
+ colorGroup: parent.enabled? SystemPalette.Active: SystemPalette.Disabled;
+ }
+ palette: addPropertyPalette.palette;
+ color: addPropertyDelegate.highlighted? palette.highlightedText: palette.text;
+ text: addPropertyDelegate.title;
+ elide: Text.ElideRight;
+ verticalAlignment: Text.AlignVCenter
+ }
+ enabled: !isVisible(name);
+ highlighted: addPropertyCmb.highlightedIndex === index;
+ background: Rectangle { color: highlighted? parent.palette.highlight:"transparent"; }
- onClicked: addPropertyCmb.enableProperty(name);
+ ToolTip.text: toolTip;
+ ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
+ ToolTip.visible: highlighted;
+
+ onClicked: addPropertyCmb.enableProperty(name);
+ }
+ popup.y: addPropertyCmb.height - 1;
+ popup.palette: cmbPalette.palette;
}
- popup.y: addPropertyCmb.height - 1;
- popup.palette: cmbPalette.palette;
}
}