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 basic charmap search.

Wolthera van Hövell tot Westerflier29639a09e2ac
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml b/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml
index 8f5edca549..3de474b727 100644
--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml
@@ -33,12 +33,11 @@ Rectangle {
anchors.left: parent.left;
anchors.right: parent.right;
- /// How are we going to translate this?
TabButton {
- text: "Glyph Alternates"
+ text: i18nc("@title:tab", "Glyph Alternates")
}
TabButton {
- text: "Character Map"
+ text: i18nc("@title:tab", "Character Map")
}
}
@@ -114,90 +113,107 @@ Rectangle {
}
}
- GridView {
- id: charMap;
- model: root.charMapModel;
- focus: true;
- clip: true;
+ ColumnLayout {
Layout.minimumWidth: 180;
Layout.fillHeight: true;
Layout.fillWidth: true;
- cellWidth: (width - charMapScroll.implicitBackgroundWidth)/8;
- cellHeight: cellWidth;
- delegate: GlyphDelegate {
- textColor: sysPalette.text;
- fillColor: sysPalette.base;
- fontFamilies: root.fontFamilies;
- fontSize: root.fontSize;
- fontStyle: root.fontStyle;
- fontWeight: root.fontWeight;
- onGlyphDoubleClicked: (index)=> {mainWindow.slotInsertRichText(index)};
- onGlyphClicked: (index)=> {
- if (model.childCount > 1){
- charMapAltGlyphs.open()
- }
- }
- }
- ScrollBar.vertical: ScrollBar {
- id: charMapScroll;
+ TextField {
+ id: searchInput;
+ onTextEdited: {
+ mainWindow.slotChangeSearchText(text);
+ }
+ placeholderText: i18nc("@info:placeholder", "Search...");
+ Layout.fillWidth: true;
+ Layout.preferredHeight: implicitHeight;
+ padding: 5;
}
- Popup {
- id: charMapAltGlyphs
- x: 0
- y: 0
- width: charMap.width
- height: charMap.cellHeight*3;
- modal: true
- focus: true
- padding: 2;
- closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
-
- palette: TabBar.palette;
- GridView {
- anchors.fill: parent;
- clip: true;
-
- cellWidth: (width - charMapAltGlyphsScroll.implicitBackgroundWidth)/8;
- cellHeight: cellWidth;
-
- ScrollBar.vertical: ScrollBar {
- id: charMapAltGlyphsScroll;
- }
+ GridView {
+ id: charMap;
+ model: root.charMapModel;
+ focus: true;
+ clip: true;
+ Layout.fillHeight: true;
+ Layout.fillWidth: true;
+
+ cellWidth: (width - charMapScroll.implicitBackgroundWidth)/8;
+ cellHeight: cellWidth;
+
+ delegate: GlyphDelegate {
+ textColor: sysPalette.text;
+ fillColor: sysPalette.base;
+ fontFamilies: root.fontFamilies;
+ fontSize: root.fontSize;
+ fontStyle: root.fontStyle;
+ fontWeight: root.fontWeight;
+ onGlyphDoubleClicked: (index)=> {mainWindow.slotInsertRichText(index)};
+ onGlyphClicked: (index)=> {
+ if (model.childCount > 1){
+ charMapAltGlyphs.open()
+ }
+ }
+ }
- model: DelegateModel {
- model: charMap.model
- property alias rIndex: charMap.currentIndex;
- property var defaultIndex: modelIndex(-1);
- onRIndexChanged: {
- rootIndex = defaultIndex;
- rootIndex = modelIndex(rIndex);
- }
+ ScrollBar.vertical: ScrollBar {
+ id: charMapScroll;
+ }
- delegate: GlyphDelegate {
- textColor: sysPalette.text;
- fillColor: sysPalette.base;
- fontFamilies: root.fontFamilies;
- fontSize: root.fontSize;
- fontStyle: root.fontStyle;
- fontWeight: root.fontWeight;
- onGlyphDoubleClicked: (index)=> {
- mainWindow.slotInsertRichText(charMap.currentIndex, index);
- charMapAltGlyphs.close()
- };
- onGlyphClicked: (index)=> {
- mainWindow.slotInsertRichText(charMap.currentIndex, index);
- charMapAltGlyphs.close()
- };
+ Popup {
+ id: charMapAltGlyphs
+ x: 0
+ y: 0
+ width: charMap.width
+ height: charMap.cellHeight*3;
+ modal: true
+ focus: true
+ padding: 2;
+ closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
+
+ palette: TabBar.palette;
+ GridView {
+ anchors.fill: parent;
+ clip: true;
+
+ cellWidth: (width - charMapAltGlyphsScroll.implicitBackgroundWidth)/8;
+ cellHeight: cellWidth;
+
+ ScrollBar.vertical: ScrollBar {
+ id: charMapAltGlyphsScroll;
}
+ model: DelegateModel {
+ model: charMap.model
+ property alias rIndex: charMap.currentIndex;
+ property var defaultIndex: modelIndex(-1);
+ onRIndexChanged: {
+ rootIndex = defaultIndex;
+ rootIndex = modelIndex(rIndex);
+ }
+
+ delegate: GlyphDelegate {
+ textColor: sysPalette.text;
+ fillColor: sysPalette.base;
+ fontFamilies: root.fontFamilies;
+ fontSize: root.fontSize;
+ fontStyle: root.fontStyle;
+ fontWeight: root.fontWeight;
+ onGlyphDoubleClicked: (index)=> {
+ mainWindow.slotInsertRichText(charMap.currentIndex, index);
+ charMapAltGlyphs.close()
+ };
+ onGlyphClicked: (index)=> {
+ mainWindow.slotInsertRichText(charMap.currentIndex, index);
+ charMapAltGlyphs.close()
+ };
+ }
+
+ }
}
}
}
-
}
}
}
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp
index 581ecfb188..338aaa29ac 100644
--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp
@@ -36,6 +36,7 @@ GlyphPaletteDialog::GlyphPaletteDialog(QWidget *parent)
this->setMainWidget(m_quickWidget);
m_quickWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_quickWidget->engine()->rootContext()->setContextProperty("mainWindow", this);
+ m_quickWidget->engine()->rootContext()->setContextObject(new KLocalizedContext(this));
m_quickWidget->engine()->addImportPath(KoResourcePaths::getApplicationRoot() + "/lib/qml/");
m_quickWidget->engine()->addImportPath(KoResourcePaths::getApplicationRoot() + "/lib64/qml/");
@@ -153,15 +154,19 @@ 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);
+ m_charMapModel->setBlockFilter(filter);
}
}
+void GlyphPaletteDialog::slotChangeSearchText(QString searchText)
+{
+ m_charMapModel->setSearchText(searchText);
+}
+
void GlyphPaletteDialog::slotUpdateFilterList()
{
m_filters->clear();
- m_charMapModel->setFilter(0);
+ m_charMapModel->setBlockFilter(0);
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);
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h
index ed37aa2172..6fc733daf1 100644
--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h
@@ -31,6 +31,7 @@ public Q_SLOTS:
void slotInsertRichText(int charRow, int glyphRow = -1, bool replace = false);
void slotChangeFilter(int filterRow);
+ void slotChangeSearchText(QString searchText);
void slotUpdateFilterList();
private:
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteProxyModel.cpp b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteProxyModel.cpp
index 47a96bd1c0..c3788ff94d 100644
--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteProxyModel.cpp
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteProxyModel.cpp
@@ -8,8 +8,15 @@
#include <QDebug>
#include <data/KoUnicodeBlockData.h>
+struct GlyphPaletteProxyModel::Private {
+ KoUnicodeBlockData block{KoUnicodeBlockDataFactory::noBlock()};
+ int filterIndex{0};
+ QString searchText;
+};
+
GlyphPaletteProxyModel::GlyphPaletteProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
+ , d(new Private)
{
}
@@ -18,9 +25,14 @@ GlyphPaletteProxyModel::~GlyphPaletteProxyModel()
{
}
-int GlyphPaletteProxyModel::filter() const
+int GlyphPaletteProxyModel::blockFilter() const
+{
+ return d->filterIndex;
+}
+
+QString GlyphPaletteProxyModel::searchText() const
{
- return m_filter;
+ return d->searchText;
}
QMap<int, QString> GlyphPaletteProxyModel::filterLabels()
@@ -36,27 +48,56 @@ QMap<int, QString> GlyphPaletteProxyModel::filterLabels()
return labels;
}
-void GlyphPaletteProxyModel::setFilter(int filter)
+void GlyphPaletteProxyModel::setSearchText(const QString &text)
{
- m_filter = filter;
- invalidateFilter();
+ if (!d->searchText.isEmpty() && !text.isEmpty() && d->searchText.toUcs4().first() == text.toUcs4().first()) {
+ return;
+ } else {
+ d->searchText = text.isEmpty()? text: QString::fromUcs4(&text.toUcs4().first(), 1);
+ emit searchTextChanged();
+ invalidateFilter();
+ }
}
-bool GlyphPaletteProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
+void GlyphPaletteProxyModel::setBlockFilter(int filter)
{
- if (sourceParent.isValid()) return true;
- KoFontGlyphModel *model = qobject_cast<KoFontGlyphModel*>(sourceModel());
- if (!model) {
- return true;
+ if (d->filterIndex == filter) {
+ return;
}
- if (m_filter == 0) {
- return true;
+ if (filter == 0) {
+ d->filterIndex = 0;
+ d->block = KoUnicodeBlockDataFactory::noBlock();
+ emit blockFilterChanged();
+ invalidateFilter();
+ } else {
+ KoFontGlyphModel *model = qobject_cast<KoFontGlyphModel*>(sourceModel());
+ if (model) {
+ int actualFilter = filter - 1;
+ if (actualFilter < model->blocks().size()) {
+ d->filterIndex = filter;
+ d->block = model->blocks().at(actualFilter);
+ emit blockFilterChanged();
+ invalidateFilter();
+ }
+ }
}
- const KoUnicodeBlockData block = model->blocks().value(m_filter-1, KoUnicodeBlockDataFactory::noBlock());
+}
+
+bool GlyphPaletteProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
+{
+ if (sourceParent.isValid()) return true;
const QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent);
const QString main = sourceModel()->data(idx).toString();
if (main.isEmpty()) return false;
+ const uint firstChar = main.toUcs4().first();
+
+ if (!d->searchText.isEmpty()) {
+ const QString decomposition = QChar::decomposition(firstChar);
+ const uint searchFirst = d->searchText.toUcs4().first();
+ return searchFirst == firstChar
+ || (!decomposition.isEmpty() && searchFirst == decomposition.toUcs4().first());
+ }
+ if (d->filterIndex == 0) return true;
- bool scriptMatch = block.match(main.toUcs4().first());
- return scriptMatch;
+ return d->block.match(firstChar);
}
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteProxyModel.h b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteProxyModel.h
index 269688b3ca..aa3034ec12 100644
--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteProxyModel.h
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteProxyModel.h
@@ -14,21 +14,31 @@
class GlyphPaletteProxyModel: public QSortFilterProxyModel
{
Q_OBJECT
+
+ Q_PROPERTY(int blockFilter READ blockFilter WRITE setBlockFilter NOTIFY blockFilterChanged)
+ Q_PROPERTY(QString searchText READ searchText() WRITE setSearchText NOTIFY searchTextChanged)
public:
GlyphPaletteProxyModel(QObject *parent = nullptr);
~GlyphPaletteProxyModel() override;
- int filter() const;
+ int blockFilter() const;
+ QString searchText() const;
QMap<int, QString> filterLabels();
public Q_SLOTS:
- void setFilter(int filter);
+ void setSearchText(const QString &text);
+ void setBlockFilter(int filter);
+
+Q_SIGNALS:
+ void blockFilterChanged();
+ void searchTextChanged();
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
private:
- int m_filter{0};
+ struct Private;
+ QScopedPointer<Private> d;
};