[fondue-commits] [SCM] Fondue Font Editor branch, master, updated. e667253ed5deaa2c87975c8a61012e430bad3d45
Eugeniy Meshcheryakov
eugen at debian.org
Wed Aug 22 13:52:49 UTC 2007
The branch, master has been updated
via e667253ed5deaa2c87975c8a61012e430bad3d45 (commit)
via 7e6a2d7cfcaf52db693e99a69dfd2850aa6dd5d2 (commit)
via 9c2316444c6e2b6786cd93c7dc39e9369dd4445c (commit)
from 9b2b5f453f09271ecb794a8f736ae884eb3e3de4 (commit)
- Log -----------------------------------------------------------------
commit e667253ed5deaa2c87975c8a61012e430bad3d45
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date: Wed Aug 22 15:52:37 2007 +0200
add proxy model for unicode view (crashes glyph editor now)
commit 7e6a2d7cfcaf52db693e99a69dfd2850aa6dd5d2
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date: Mon Aug 20 15:41:11 2007 +0200
remove "open" argument for contourToPath().
class Contour allready contains such insformation
commit 9c2316444c6e2b6786cd93c7dc39e9369dd4445c
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date: Mon Aug 20 15:07:16 2007 +0200
remove unused variable
-----------------------------------------------------------------------
Summary of changes:
gui/glyphgraphics.cxx | 11 +--
gui/glyphgraphics.h | 2 +-
gui/gui.rules | 6 +-
gui/mainwindow.cxx | 5 +-
gui/unicodeproxymodel.cxx | 134 +++++++++++++++++++++++++++++++++++++++++++++
gui/unicodeproxymodel.h | 29 ++++++++++
6 files changed, 176 insertions(+), 11 deletions(-)
create mode 100644 gui/unicodeproxymodel.cxx
create mode 100644 gui/unicodeproxymodel.h
diff --git a/gui/glyphgraphics.cxx b/gui/glyphgraphics.cxx
index c49b62d..39e7648 100644
--- a/gui/glyphgraphics.cxx
+++ b/gui/glyphgraphics.cxx
@@ -92,16 +92,15 @@ void GlyphGraphics::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
if (v.canConvert<Contour>()) {
Contour c = v.value<Contour>();
if (c.isOpen())
- painter->drawPath(contourToPath(c, true));
+ painter->drawPath(contourToPath(c));
}
}
}
-QPainterPath GlyphGraphics::contourToPath(const Contour &contour, bool open)
+QPainterPath GlyphGraphics::contourToPath(const Contour &contour)
{
QPainterPath path;
- bool moved = false;
for (int i = 0; i < contour.size(); i++) {
const GlyphPoint &pt = contour.at(i);
@@ -119,10 +118,8 @@ QPainterPath GlyphGraphics::contourToPath(const Contour &contour, bool open)
}
}
- if (pt.on()) {
+ if (pt.on())
path.lineTo(pt);
- moved = true;
- }
else {
const GlyphPoint &next = (i < contour.size() - 1) ? contour.at(i + 1) : contour.at(0);
@@ -136,7 +133,7 @@ QPainterPath GlyphGraphics::contourToPath(const Contour &contour, bool open)
}
}
}
- if (!open)
+ if (!contour.isOpen())
path.closeSubpath(); // TODO open paths
return path;
diff --git a/gui/glyphgraphics.h b/gui/glyphgraphics.h
index 1a6f5f0..472da3a 100644
--- a/gui/glyphgraphics.h
+++ b/gui/glyphgraphics.h
@@ -46,7 +46,7 @@ private:
QList<QVariant> content;
QList<ControlPoint *> points;
public:
- static QPainterPath contourToPath(const Contour &contour, bool open = false);
+ static QPainterPath contourToPath(const Contour &contour);
};
#endif
diff --git a/gui/gui.rules b/gui/gui.rules
index b6aa428..0a18db3 100644
--- a/gui/gui.rules
+++ b/gui/gui.rules
@@ -14,7 +14,8 @@ libfonduegui_a_SOURCES = \
gui/glyphsmodeldelegate.cxx \
gui/glyphpropertieseditor.cxx \
gui/colorcombobox.cxx \
- gui/unicodevalueeditor.cxx
+ gui/unicodevalueeditor.cxx \
+ gui/unicodeproxymodel.cxx
nodist_libfonduegui_a_SOURCES = \
gui/ttihighlighter.moc.cxx \
@@ -49,7 +50,8 @@ noinst_HEADERS += \
gui/glyphsmodeldelegate.h \
gui/glyphpropertieseditor.h \
gui/unicodevalueeditor.h \
- gui/colorcombobox.h
+ gui/colorcombobox.h \
+ gui/unicodeproxymodel.h
CLEANFILES += gui/*.moc.cxx gui/*.tbl.cxx
EXTRA_DIST += gui/instnames.xsl
diff --git a/gui/mainwindow.cxx b/gui/mainwindow.cxx
index 65cf8b3..3aacdc3 100644
--- a/gui/mainwindow.cxx
+++ b/gui/mainwindow.cxx
@@ -31,6 +31,7 @@
#include "glyphsgridwidget.h"
#include "glyphsmodel.h"
#include <QSettings>
+#include "unicodeproxymodel.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
@@ -168,7 +169,9 @@ void MainWindow::loadFile(const QString &fileName)
model = new GlyphsModel;
model->setDocument(m_doc);
- glyphsView->setModel(model); // FIXME
+ UnicodeProxyModel *proxy = new UnicodeProxyModel(model);
+ proxy->setSourceModel(model);
+ glyphsView->setModel(proxy); // FIXME
setCurrentFile(fileName);
changeDocumentName(m_doc->fontName());
diff --git a/gui/unicodeproxymodel.cxx b/gui/unicodeproxymodel.cxx
new file mode 100644
index 0000000..53a8490
--- /dev/null
+++ b/gui/unicodeproxymodel.cxx
@@ -0,0 +1,134 @@
+#include "unicodeproxymodel.h"
+#include "glyphsmodel.h"
+
+UnicodeProxyModel::UnicodeProxyModel(QObject *parent) : QAbstractProxyModel(parent),
+ unencodedGlyphs(0)
+{
+
+}
+
+QModelIndex UnicodeProxyModel::mapFromSource(const QModelIndex &sourceIndex) const
+{
+ if (sourceIndex.isValid()) {
+ Q_ASSERT(fromSourceMap.contains(sourceIndex.row()));
+ return index(fromSourceMap.value(sourceIndex.row()), sourceIndex.column());
+ }
+ return QModelIndex();
+}
+
+QModelIndex UnicodeProxyModel::mapToSource(const QModelIndex &proxyIndex) const
+{
+ if (proxyIndex.isValid()) {
+ if (toSourceMap.contains(proxyIndex.row())) {
+ return sourceModel()->index(toSourceMap.value(proxyIndex.row()), proxyIndex.column());
+ }
+ }
+ return QModelIndex();
+}
+
+#define MAX_UNICODE 0x10FFFF
+
+void UnicodeProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
+{
+ QAbstractProxyModel::setSourceModel(sourceModel);
+ toSourceMap.clear();
+ fromSourceMap.clear();
+ unencodedGlyphs = 0;
+
+ if (sourceModel) {
+ int numGlyphs = sourceModel->rowCount();
+ for (int i = 0; i < numGlyphs; i++) {
+ QModelIndex unicodeIdx = sourceModel->index(i, GlyphsModel::UnicodeColumn);
+ Q_ASSERT(unicodeIdx.isValid());
+ int unicode = unicodeIdx.data().toInt();
+ if (unicode < 0) {
+ unencodedGlyphs++;
+ fromSourceMap[i] = MAX_UNICODE + unencodedGlyphs;
+ toSourceMap[MAX_UNICODE + unencodedGlyphs] = i;
+ }
+ else {
+ //Q_ASSERT(unicode <= MAX_UNICODE); // FIXME this is not enforced in reader class
+ if (unicode <= MAX_UNICODE) {
+ Q_ASSERT(!toSourceMap.contains(unicode));
+ fromSourceMap[i] = unicode;
+ toSourceMap[unicode] = i;
+ }
+ }
+ }
+ }
+}
+
+int UnicodeProxyModel::rowCount(const QModelIndex &parent) const
+{
+ if (parent.isValid())
+ return 0;
+ return MAX_UNICODE + unencodedGlyphs;
+}
+
+int UnicodeProxyModel::columnCount(const QModelIndex &parent) const
+{
+ if (parent.isValid())
+ return 0;
+ return sourceModel()->columnCount();
+}
+
+QModelIndex UnicodeProxyModel::index(int row, int column, const QModelIndex &parent) const
+{
+ if (parent.isValid())
+ return QModelIndex();
+ if (column < sourceModel()->columnCount() && row < MAX_UNICODE + unencodedGlyphs)
+ return createIndex(row, column);
+ return QModelIndex();
+}
+
+QVariant UnicodeProxyModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+ if (index.column() < sourceModel()->columnCount() && index.row() < MAX_UNICODE + unencodedGlyphs) {
+ QModelIndex sourceIndex = mapToSource(index);
+ if (sourceIndex.isValid())
+ return sourceModel()->data(sourceIndex, role);
+ Q_ASSERT(index.row() <= MAX_UNICODE);
+
+ switch (index.column()) {
+ case GlyphsModel::GlyphColumn:
+ if (role == Qt::DisplayRole || role == Qt::ToolTipRole) {
+ QString name;
+ if (index.row() < 0x10000)
+ name = QString("uni%1").arg(index.row(), 4, 16, QLatin1Char('0'));
+ else
+ name = QString("u%1").arg(index.row(), 0, 16);
+ return name;
+ }
+ break;
+ case GlyphsModel::NameColumn:
+ if (role == Qt::DisplayRole || role == Qt::EditRole) {
+ QString name;
+ if (index.row() < 0x10000)
+ name = QString("uni%1").arg(index.row(), 4, 16, QLatin1Char('0'));
+ else
+ name = QString("u%1").arg(index.row(), 0, 16);
+ return name;
+ }
+ break;
+ case GlyphsModel::UnicodeColumn:
+ if (role == Qt::DisplayRole || role == Qt::EditRole)
+ return index.row();
+ break;
+ default:
+ return QVariant();
+ }
+ }
+ return QVariant();
+}
+
+Qt::ItemFlags UnicodeProxyModel::flags(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return 0;
+ QModelIndex sourceIndex = mapToSource(index);
+ if (sourceIndex.isValid())
+ return sourceModel()->flags(sourceIndex);
+ return Qt::ItemIsSelectable;
+}
diff --git a/gui/unicodeproxymodel.h b/gui/unicodeproxymodel.h
new file mode 100644
index 0000000..4b9bd8f
--- /dev/null
+++ b/gui/unicodeproxymodel.h
@@ -0,0 +1,29 @@
+#ifndef UNICODEPROXYMODEL_H
+#define UNICODEPROXYMODEL_H
+#include <QAbstractProxyModel>
+#include <QHash>
+
+// XXX TODO handle model updates
+
+class UnicodeProxyModel : public QAbstractProxyModel {
+public:
+ UnicodeProxyModel(QObject *parent = 0);
+ QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
+ QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
+ void setSourceModel(QAbstractItemModel *sourceModel);
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+
+ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
+ QModelIndex parent(const QModelIndex &index) const {Q_UNUSED(index); return QModelIndex();}
+
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+private:
+ QHash<int, int> toSourceMap;
+ QHash<int, int> fromSourceMap;
+ int unencodedGlyphs;
+};
+
+#endif
--
Fondue Font Editor
More information about the fondue-commits
mailing list