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

Add a basic sort-filter proxy to filter the character map.

Wolthera van Hövell tot Westerflierb055b2a166dd
diff --git a/plugins/tools/svgtexttool/CMakeLists.txt b/plugins/tools/svgtexttool/CMakeLists.txt
index e9d23c6463..b03307e216 100644
--- a/plugins/tools/svgtexttool/CMakeLists.txt
+++ b/plugins/tools/svgtexttool/CMakeLists.txt
@@ -25,6 +25,7 @@ set (SvgTextTool_SRCS
SvgTextShapeManagerBlocker.cpp
glyphpalette/GlyphPaletteDialog.cpp
+ glyphpalette/GlyphPaletteProxyModel.cpp
glyphpalette/SvgTextLabel.cpp
)
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml b/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml
index c807a71e34..ba13281dd0 100644
--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.15
-import QtQml.Models 2.12
+import QtQml.Models 2.15
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.15
import org.krita.tools.text 1.0
@@ -14,7 +14,10 @@ Rectangle {
anchors.fill: parent;
property string titleText;
property QtObject model;
- property alias currentIndex: charMap.currentIndex;
+ property QtObject charMapModel;
+ property QtObject charMapFilterModel;
+
+ property int currentIndex: 0;
property var fontFamilies: [];
property double fontSize :10.0;
property int fontWeight : 400;
@@ -65,8 +68,8 @@ Rectangle {
padding: height/8;
clip: true;
- width: charMap.cellWidth;
- height: charMap.cellHeight;
+ width: GridView.view.cellWidth;
+ height: GridView.view.cellHeight;
property bool currentItem: GridView.isCurrentItem;
@@ -108,7 +111,6 @@ Rectangle {
id: glyphMouseArea
onClicked: {
parent.GridView.view.currentIndex = index;
- console.log(model.toolTip)
}
onDoubleClicked: {model.childCount === 0? mainWindow.slotInsertRichText(root.currentIndex, index): mainWindow.slotInsertRichText(index)}
hoverEnabled: true;
@@ -156,21 +158,52 @@ Rectangle {
}
// Charmap.
- GridView {
- id: charMap;
- model: root.model;
- focus: true;
- clip: true;
-
- cellWidth: (parent.width - charMapScroll.implicitBackgroundWidth)/8;
- cellHeight: cellWidth;
+ Item {
+ ListView {
+ id: charMapFilter
+ model: root.charMapFilterModel;
+ anchors.top: parent.top;
+ anchors.bottom: parent.bottom;
+ anchors.left: parent.left;
+ width: 100;
- delegate: glyphDelegate;
+ onCurrentIndexChanged: {
+ mainWindow.slotChangeFilter(currentIndex);
+ console.log(currentIndex)
+ }
- ScrollBar.vertical: ScrollBar {
- id: charMapScroll;
+ clip: true;
+ delegate: ItemDelegate {
+ width: parent.width;
+ text: model.display;
+ highlighted: ListView.isCurrentItem;
+ onClicked: {
+ charMapFilter.currentIndex = index;
+ }
+ }
}
+ GridView {
+ id: charMap;
+ model: root.charMapModel;
+ focus: true;
+ clip: true;
+
+ anchors.top: parent.top;
+ anchors.bottom: parent.bottom;
+ anchors.left: charMapFilter.right;
+ anchors.right: parent.right;
+
+ cellWidth: (width - charMapScroll.implicitBackgroundWidth)/8;
+ cellHeight: cellWidth;
+
+ delegate: glyphDelegate;
+
+ ScrollBar.vertical: ScrollBar {
+ id: charMapScroll;
+ }
+
+ }
}
}
}
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp
index 684d988d31..9d5531b20d 100644
--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp
@@ -4,10 +4,12 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "GlyphPaletteDialog.h"
+
#include <QQmlEngine>
#include <QQmlContext>
#include <QQuickItem>
#include <QHBoxLayout>
+
#include <KoResourcePaths.h>
#include <KoFontGlyphModel.h>
#include <KoFontRegistry.h>
@@ -23,6 +25,8 @@ KIS_DECLARE_STATIC_INITIALIZER {
GlyphPaletteDialog::GlyphPaletteDialog(QWidget *parent)
: KoDialog(parent)
, m_model(new KoFontGlyphModel)
+ , m_charMapModel(new GlyphPaletteProxyModel)
+ , m_filters(new QStandardItemModel)
{
setMinimumSize(500, 300);
@@ -39,9 +43,20 @@ GlyphPaletteDialog::GlyphPaletteDialog(QWidget *parent)
m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
m_quickWidget->setSource(QUrl("qrc:/GlyphPalette.qml"));
+ m_charMapModel->setSourceModel(m_model);
+ for (int i = 0; i< m_charMapModel->filterLabels().size(); i++) {
+ int key = m_charMapModel->filterLabels().keys().at(i);
+ QString label = m_charMapModel->filterLabels().value(key);
+ QStandardItem *item = new QStandardItem(label);
+ item->setData(key, Qt::UserRole+1);
+ m_filters->appendRow(item);
+ }
+
if (m_quickWidget->rootObject()) {
m_quickWidget->rootObject()->setProperty("titleText", "Glyph palette");
m_quickWidget->rootObject()->setProperty("model", QVariant::fromValue(m_model));
+ m_quickWidget->rootObject()->setProperty("charMapModel", QVariant::fromValue(m_charMapModel));
+ m_quickWidget->rootObject()->setProperty("charMapFilterModel", QVariant::fromValue(m_filters));
}
if (!m_quickWidget->errors().empty()) {
qWarning() << "Errors in " << windowTitle() << ":" << m_quickWidget->errors();
@@ -103,19 +118,33 @@ void GlyphPaletteDialog::setGlyphModelFromProperties(KoSvgTextProperties propert
void GlyphPaletteDialog::slotInsertRichText(int charRow, int glyphRow)
{
if (m_quickWidget->rootObject()) {
- QModelIndex idx = m_model->index(charRow, 0);
+ QModelIndex idx = glyphRow > -1? m_model->index(charRow, 0): m_charMapModel->index(charRow, 0);
+ QString text;
+ KoSvgTextProperties props = m_lastUsedProperties;
+ QStringList otf = props.property(KoSvgTextProperties::FontFeatureSettingsId).value<QStringList>();
if (glyphRow > -1) {
idx = m_model->index(glyphRow, 0, idx);
+ text = m_model->data(idx, Qt::DisplayRole).toString();
+ otf.append(m_model->data(idx, KoFontGlyphModel::OpenTypeFeatures).value<QStringList>());
+ } else {
+ text = m_charMapModel->data(idx, Qt::DisplayRole).toString();
}
KoSvgTextShape *richText = new KoSvgTextShape();
- KoSvgTextProperties props = m_lastUsedProperties;
- QStringList otf = props.property(KoSvgTextProperties::FontFeatureSettingsId).value<QStringList>();
- otf.append(m_model->data(idx, KoFontGlyphModel::OpenTypeFeatures).value<QStringList>());
props.setProperty(KoSvgTextProperties::FontFeatureSettingsId, otf);
richText->setPropertiesAtPos(-1, props);
- richText->insertText(0, m_model->data(idx, Qt::DisplayRole).toString());
+ richText->insertText(0, text);
emit signalInsertRichText(richText);
}
}
+
+void GlyphPaletteDialog::slotChangeFilter(int filterRow)
+{
+ QModelIndex idx = m_filters->index(filterRow, 0);
+ if (idx.isValid()) {
+ const int filter = idx.data(Qt::UserRole+1).toInt();
+ qDebug() << Q_FUNC_INFO << filter;
+ m_charMapModel->setFilter(filter);
+ }
+}
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h
index 3558f348d8..810967c623 100644
--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h
@@ -8,9 +8,13 @@
#include <KoDialog.h>
#include <QtQuickWidgets/QQuickWidget>
+
#include <KoSvgTextProperties.h>
#include <KoFontGlyphModel.h>
#include <KoSvgTextShape.h>
+#include <QStandardItemModel>
+
+#include "GlyphPaletteProxyModel.h"
class GlyphPaletteDialog: public KoDialog
{
@@ -25,10 +29,14 @@ Q_SIGNALS:
public Q_SLOTS:
void slotInsertRichText(int charRow, int glyphRow = -1);
+
+ void slotChangeFilter(int filterRow);
private:
QQuickWidget *m_quickWidget {0};
KoSvgTextProperties m_lastUsedProperties;
KoFontGlyphModel *m_model;
+ GlyphPaletteProxyModel *m_charMapModel;
+ QStandardItemModel *m_filters;
};
#endif // GLYPHPALETTEDIALOG_H
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteProxyModel.cpp b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteProxyModel.cpp
new file mode 100644
index 0000000000..76882d0595
--- /dev/null
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteProxyModel.cpp
@@ -0,0 +1,53 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "GlyphPaletteProxyModel.h"
+#include <KLocalizedString>
+#include <QDebug>
+
+GlyphPaletteProxyModel::GlyphPaletteProxyModel(QObject *parent)
+ : QSortFilterProxyModel(parent)
+{
+
+}
+
+GlyphPaletteProxyModel::~GlyphPaletteProxyModel()
+{
+}
+
+int GlyphPaletteProxyModel::filter() const
+{
+ return m_filter;
+}
+
+QMap<int, QString> GlyphPaletteProxyModel::filterLabels()
+{
+ QMap<int, QString> labels;
+ labels.insert(QChar::Script_Unknown, i18n("Any Script"));
+ labels.insert(QChar::Script_Latin, i18n("Latin"));
+ labels.insert(QChar::Script_Greek, i18n("Greek"));
+ labels.insert(QChar::Script_Cyrillic, i18n("Cyrillic"));
+ labels.insert(QChar::Script_Armenian, i18n("Armenian"));
+ labels.insert(QChar::Script_Hebrew, i18n("Hebrew"));
+ labels.insert(QChar::Script_Arabic, i18n("Arabic"));
+ labels.insert(QChar::Script_Syriac, i18n("Syriac"));
+ return labels;
+}
+
+void GlyphPaletteProxyModel::setFilter(int filter)
+{
+ m_filter = QChar::Script(filter);
+ invalidateFilter();
+}
+
+bool GlyphPaletteProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
+{
+ QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent);
+ QString main = sourceModel()->data(idx).toString();
+ QChar::Script script = main.isEmpty()? QChar::Script_Unknown :main.front().script();
+
+ bool scriptMatch = m_filter == 0 || m_filter == 1? true: script == m_filter;
+ return scriptMatch;
+}
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteProxyModel.h b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteProxyModel.h
new file mode 100644
index 0000000000..a65b53cfa6
--- /dev/null
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteProxyModel.h
@@ -0,0 +1,34 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef GLYPHPALETTEPROXYMODEL_H
+#define GLYPHPALETTEPROXYMODEL_H
+
+#include <QSortFilterProxyModel>
+#include <KoFontGlyphModel.h>
+#include <QChar>
+
+class GlyphPaletteProxyModel: public QSortFilterProxyModel
+{
+ Q_OBJECT
+public:
+ GlyphPaletteProxyModel(QObject *parent = nullptr);
+ ~GlyphPaletteProxyModel() override;
+
+ int filter() const;
+
+ static QMap<int, QString> filterLabels();
+
+public Q_SLOTS:
+ void setFilter(int filter);
+
+protected:
+ bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
+private:
+ QChar::Script m_filter{QChar::Script_Unknown};
+};
+
+#endif // GLYPHPALETTEPROXYMODEL_H