[fondue-commits] [SCM] Fondue Font Editor branch, master, updated. 716be40324676b3a67c836b44e051010800c04a1
Eugeniy Meshcheryakov
eugen at debian.org
Wed Sep 12 14:27:47 UTC 2007
The branch, master has been updated
via 716be40324676b3a67c836b44e051010800c04a1 (commit)
via be95771a21b8fa6f429cc39c25d612e673928630 (commit)
via db5cd3408fd2a46375af5ffb725c4d3f770f4603 (commit)
from 48a8bad171f5af9adb1235b0d69b6c56ee071080 (commit)
- Shortlog ------------------------------------------------------------
716be40 reorganise GlyphGraphics class
be95771 add function for getting index for named glyph
db5cd34 add unicodenameslist.h to noinst_HEADERS
Summary of changes:
gui/controlpoint.cxx | 5 +-
gui/controlpoint.h | 8 +--
gui/glyphcell.cxx | 37 ++++----------
gui/glyphcell.h | 5 --
gui/glyphgraphics.cxx | 129 +++++++++++++++++++++++--------------------------
gui/glyphgraphics.h | 33 ++++++++-----
gui/glyphsmodel.cxx | 11 ++++
gui/glyphsmodel.h | 1 +
gui/gui.rules | 9 ++-
nongui/nongui.rules | 3 +-
10 files changed, 118 insertions(+), 123 deletions(-)
-----------------------------------------------------------------------
Details of changes:
commit 716be40324676b3a67c836b44e051010800c04a1
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date: Wed Sep 12 16:27:31 2007 +0200
reorganise GlyphGraphics class
add basic support for references in glyph editor (not safe, can crash)
diff --git a/gui/controlpoint.cxx b/gui/controlpoint.cxx
index b98906e..613879f 100644
--- a/gui/controlpoint.cxx
+++ b/gui/controlpoint.cxx
@@ -21,7 +21,8 @@
#include "glyphcell.h"
#include <QDebug>
-ControlPoint::ControlPoint(GlyphCell *cell, const GlyphGraphics::PointIndex &idx) : QGraphicsItem(), m_cell(cell), m_idx(idx)
+ControlPoint::ControlPoint(GlyphGraphics *gfx, const GlyphGraphics::PointIndex &idx, QGraphicsItem *parent) :
+ QGraphicsItem(parent), m_gfx(gfx), m_idx(idx)
{
setFlag(ItemIsMovable);
setFlag(ItemIsSelectable);
@@ -59,7 +60,7 @@ QVariant ControlPoint::itemChange(GraphicsItemChange change, const QVariant &val
{
if (change == ItemPositionHasChanged) {
QPointF newpoint = value.toPointF();
- m_cell->changePoint(m_idx, newpoint);
+ m_gfx->changePoint(m_idx, newpoint);
}
return QGraphicsItem::itemChange(change, value);
}
diff --git a/gui/controlpoint.h b/gui/controlpoint.h
index 51373e3..e30a7ef 100644
--- a/gui/controlpoint.h
+++ b/gui/controlpoint.h
@@ -20,12 +20,10 @@
#include "glyphgraphics.h"
class GlyphPoint;
-class GlyphCell;
-class ControlPoint: public QGraphicsItem
-{
+class ControlPoint: public QGraphicsItem {
public:
- ControlPoint(GlyphCell *cell, const GlyphGraphics::PointIndex &idx);
+ ControlPoint(GlyphGraphics *gfx, const GlyphGraphics::PointIndex &idx, QGraphicsItem *parent);
enum {Type = UserType + 1};
int type() const {return Type;}
QRectF boundingRect() const;
@@ -35,7 +33,7 @@ public:
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
private:
- GlyphCell *m_cell;
+ GlyphGraphics *m_gfx;
GlyphGraphics::PointIndex m_idx;
};
diff --git a/gui/glyphcell.cxx b/gui/glyphcell.cxx
index ced1879..90123ce 100644
--- a/gui/glyphcell.cxx
+++ b/gui/glyphcell.cxx
@@ -43,14 +43,8 @@ GlyphCell::GlyphCell(GlyphsModel *model, const QModelIndex &index) : QGraphicsVi
setScene(scene);
setTransformationAnchor(AnchorUnderMouse);
- gg = new GlyphGraphics(this, glyph);
- scene->addItem(gg);
- gg->setPos(0, 0);
+ gg = new GlyphGraphics(this, model, index);
fitGlyph();
- connect(m_model, SIGNAL(glyphOutlineChanged(const QModelIndex&)),
- this, SLOT(glyphOutlineChanged(const QModelIndex&)));
- connect(m_model, SIGNAL(glyphPointMoved(const QModelIndex&, int, int, const QPointF&)),
- this, SLOT(glyphPointMoved(const QModelIndex&, int, int, const QPointF&)));
}
void GlyphCell::wheelEvent(QWheelEvent *event)
@@ -66,7 +60,14 @@ void GlyphCell::wheelEvent(QWheelEvent *event)
void GlyphCell::fitGlyph()
{
- fitInView(gg, Qt::KeepAspectRatio);
+ QRectF rect = scene()->itemsBoundingRect();
+ FontDocument *doc = qobject_cast<FontDocument *>(glyphIndex.data(GlyphsModel::DocumentRole).value<QObject *>());
+ Q_ASSERT(doc);
+ if (rect.top() > -doc->ascent() - 50)
+ rect.setTop(-doc->ascent() - 50);
+ if (rect.bottom() < doc->descent() + 50)
+ rect.setBottom(doc->descent() + 50);
+ fitInView(rect, Qt::KeepAspectRatio);
}
void GlyphCell::drawForeground(QPainter *painter, const QRectF &rect)
@@ -80,7 +81,7 @@ void GlyphCell::drawForeground(QPainter *painter, const QRectF &rect)
FontDocument *doc = qobject_cast<FontDocument *>(glyphIndex.data(GlyphsModel::DocumentRole).value<QObject *>());
Glyph *g = qobject_cast<Glyph *>(glyphIndex.data(GlyphsModel::GlyphRole).value<QObject *>());
- // TODO those values should be3 cached and updated by signals
+ // TODO those values should be cached and updated by signals
Q_ASSERT(doc);
Q_ASSERT(g);
@@ -97,21 +98,3 @@ void GlyphCell::drawForeground(QPainter *painter, const QRectF &rect)
painter->drawLine(QLineF(g->horizAdvX(), rect.bottom(), g->horizAdvX(), rect.top()));
}
}
-
-void GlyphCell::changePoint(const GlyphGraphics::PointIndex &idx, const QPointF &newPoint)
-{
- QPointF newCoord(newPoint.x(), -newPoint.y());
- m_model->moveGlyphPoint(glyphIndex, idx.element, idx.num, newCoord);
-}
-
-void GlyphCell::glyphOutlineChanged(const QModelIndex &index)
-{
- if (index.row() == glyphIndex.row())
- gg->reloadContent();
-}
-
-void GlyphCell::glyphPointMoved(const QModelIndex &index, int component, int pointNo, const QPointF &newPos)
-{
- if (index.row() == glyphIndex.row())
- gg->movePoint(component, pointNo, newPos);
-}
diff --git a/gui/glyphcell.h b/gui/glyphcell.h
index 77b887c..f92af5b 100644
--- a/gui/glyphcell.h
+++ b/gui/glyphcell.h
@@ -21,7 +21,6 @@
#include "glyphgraphics.h"
class GlyphGraphics;
-class Glyph;
class QModelIndex;
class GlyphsModel;
@@ -31,16 +30,12 @@ class GlyphCell : public QGraphicsView
public:
GlyphCell(GlyphsModel *model, const QModelIndex &index);
void wheelEvent(QWheelEvent *event);
- void changePoint(const GlyphGraphics::PointIndex &idx, const QPointF &newPoint);
public slots:
void fitGlyph();
- void glyphOutlineChanged(const QModelIndex &index);
- void glyphPointMoved(const QModelIndex &index, int component, int pointNo, const QPointF &newPos);
protected:
void drawForeground(QPainter *painter, const QRectF &rect);
private:
GlyphGraphics *gg;
- /* FIXME use model/view */
QPersistentModelIndex glyphIndex;
GlyphsModel *m_model;
};
diff --git a/gui/glyphgraphics.cxx b/gui/glyphgraphics.cxx
index 39e7648..f758127 100644
--- a/gui/glyphgraphics.cxx
+++ b/gui/glyphgraphics.cxx
@@ -22,79 +22,64 @@
#include <QIcon>
#include <QDebug>
#include "fontdocument.h"
+#include "glyphsmodel.h"
+#include "glyphitem.h"
+#include "glyphref.h"
-GlyphGraphics::GlyphGraphics(GlyphCell *parent, Glyph *glyph) : QGraphicsItem()
+GlyphGraphics::GlyphGraphics(GlyphCell *parent, GlyphsModel *model, const QModelIndex &idx) :
+ QObject(parent), p(parent), m_model(model), m_idx(idx)
{
- p = parent;
- this->glyph = glyph;
+ Q_ASSERT(p);
+ Q_ASSERT(model);
- content = glyph->content;
- for (int i = 0; i < content.size(); i++) {
- const QVariant &v = content.at(i);
+ item = new GlyphItemOutline(this);
+
+ for (int i = 0; i < glyph()->content.size(); i++) {
+ const QVariant &v = glyph()->content.at(i);
// TODO add references
if (v.canConvert<Contour>()) {
Contour c = v.value<Contour>();
for (int j = 0; j < c.size(); j++) {
const GlyphPoint &pt = c.at(j);
- ControlPoint *cp = new ControlPoint(p, PointIndex(i, j)); // XXX delete them too!
+ ControlPoint *cp = new ControlPoint(this, PointIndex(i, j), item);
points.append(cp);
- p->scene()->addItem(cp);
cp->setPos(pt.x(), -pt.y());
}
}
+ else {
+ // TODO make it useable
+ Q_ASSERT(v.canConvert<GlyphRef>());
+ GlyphRef ref = v.value<GlyphRef>();
+ QModelIndex other = model->findGlyphByName(ref.glyphName());
+ if (other.isValid()) {
+ new GlyphGraphics(this, other, ref.offset());
+ // TODO account them
+ }
+ }
}
+ p->scene()->addItem(item);
+ connect(m_model, SIGNAL(glyphOutlineChanged(QModelIndex)),
+ this, SLOT(glyphOutlineChanged(QModelIndex)));
+ connect(m_model, SIGNAL(glyphPointMoved(QModelIndex, int, int, QPointF)),
+ this, SLOT(glyphPointMoved(QModelIndex, int, int, QPointF)));
}
-QRectF GlyphGraphics::boundingRect() const
+GlyphGraphics::GlyphGraphics(GlyphGraphics *parent, const QModelIndex &idx, const QPointF &pos) :
+ QObject(parent), p(parent->p), m_model(parent->m_model), m_idx(idx)
{
- QPainterPath path;
- bool hadContours = false;
-
- foreach (const QVariant &v, content) {
- if (v.canConvert<Contour>()) {
- Contour c = v.value<Contour>();
- path.addPath(contourToPath(c));
- hadContours = true;
- }
- }
- if (hadContours) {
- QRectF rect = path.boundingRect();
- qreal top = rect.bottom(), left = rect.left();
- QSizeF size = rect.size();
- return QRectF(QPointF(left, -top), size);
- }
- return QRectF();
+ Q_ASSERT(p);
+ Q_ASSERT(m_model);
+ item = new GlyphItemOutline(this, parent->item);
+ item->setPos(pos.x(), -pos.y());
+ connect(m_model, SIGNAL(glyphOutlineChanged(QModelIndex)),
+ this, SLOT(glyphOutlineChanged(QModelIndex)));
}
-void GlyphGraphics::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+const Glyph *GlyphGraphics::glyph() const
{
- Q_UNUSED(option);
- Q_UNUSED(widget);
-
- QPainterPath path;
-
- foreach (const QVariant &v, content) {
- // TODO add refs
- if (v.canConvert<Contour>()) {
- Contour c = v.value<Contour>();
- if (!c.isOpen())
- path.addPath(contourToPath(c));
- }
- }
-
- painter->scale(1, -1);
- painter->setPen(Qt::black);
- painter->setBrush(Qt::NoBrush); // filling should be moved to other place
- painter->drawPath(path);
-
- // draw open contours
- foreach (const QVariant &v, content) {
- if (v.canConvert<Contour>()) {
- Contour c = v.value<Contour>();
- if (c.isOpen())
- painter->drawPath(contourToPath(c));
- }
- }
+ Q_ASSERT(m_idx.isValid());
+ const Glyph *g = qobject_cast<Glyph *>(m_idx.data(GlyphsModel::GlyphRole).value<QObject *>());
+ return g;
}
QPainterPath GlyphGraphics::contourToPath(const Contour &contour)
@@ -139,25 +124,33 @@ QPainterPath GlyphGraphics::contourToPath(const Contour &contour)
return path;
}
-void GlyphGraphics::reloadContent()
+void GlyphGraphics::glyphOutlineChanged(const QModelIndex &index)
{
- prepareGeometryChange();
- content = glyph->content;
+ if (index.row() == m_idx.row())
+ item->update();
}
-void GlyphGraphics::movePoint(int component, int pointNo, const QPointF &newPos)
+void GlyphGraphics::glyphPointMoved(const QModelIndex &index, int component, int pointNo, const QPointF &newPos)
{
- ControlPoint *pt = 0;
+ if (index.row() == m_idx.row()) {
+ ControlPoint *pt = 0;
- for (int i = 0; i < points.size(); i++) {
- if (points.at(i)->idx().element == component && points.at(i)->idx().num == pointNo) {
- pt = points.at(i);
- break;
+ for (int i = 0; i < points.size(); i++) {
+ if (points.at(i)->idx().element == component && points.at(i)->idx().num == pointNo) {
+ pt = points.at(i);
+ break;
+ }
+ }
+ Q_ASSERT(pt);
+ QPointF realPos(newPos.x(), -newPos.y());
+ if (pt->pos() != realPos) {
+ pt->setPos(realPos);
}
}
- Q_ASSERT(pt);
- QPointF realPos(newPos.x(), -newPos.y());
- if (pt->pos() != realPos) {
- pt->setPos(realPos);
- }
+}
+
+void GlyphGraphics::changePoint(const GlyphGraphics::PointIndex &idx, const QPointF &newPoint)
+{
+ QPointF newCoord(newPoint.x(), -newPoint.y());
+ m_model->moveGlyphPoint(m_idx, idx.element, idx.num, newCoord);
}
diff --git a/gui/glyphgraphics.h b/gui/glyphgraphics.h
index 472da3a..fbe8a34 100644
--- a/gui/glyphgraphics.h
+++ b/gui/glyphgraphics.h
@@ -16,17 +16,21 @@
*/
#ifndef GLYPHGRAPHICS_H
#define GLYPHGRAPHICS_H
-#include <QGraphicsItem>
+#include <QObject>
+#include <QPainterPath>
#include "contour.h"
+#include <QPersistentModelIndex>
class GlyphCell;
-class GlyphPoint;
class ControlPoint;
class Glyph;
-class OutlineItem;
+class QPointF;
+class QModelIndex;
+class GlyphsModel;
+class GlyphItemBase;
-class GlyphGraphics: public QGraphicsItem
-{
+class GlyphGraphics: public QObject {
+ Q_OBJECT
public:
struct PointIndex {
PointIndex(int e, int n) : element(e), num(n) {}
@@ -34,17 +38,22 @@ public:
int num;
};
- GlyphGraphics(GlyphCell *parent, Glyph *glyph);
+ GlyphGraphics(GlyphCell *parent, GlyphsModel *model, const QModelIndex &idx);
+ // FIXME destructor may be needed
+ //~GlyphGraphics();
- QRectF boundingRect() const;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
- void reloadContent();
- void movePoint(int component, int pointNo, const QPointF &newPos);
+ const Glyph *glyph() const;
+ void changePoint(const GlyphGraphics::PointIndex &idx, const QPointF &newPoint);
+public slots:
+ void glyphOutlineChanged(const QModelIndex &index);
+ void glyphPointMoved(const QModelIndex &index, int component, int pointNo, const QPointF &newPos);
private:
+ GlyphGraphics(GlyphGraphics *parent, const QModelIndex &idx, const QPointF &pos);
GlyphCell *p;
- Glyph *glyph;
- QList<QVariant> content;
+ GlyphsModel *m_model;
+ QPersistentModelIndex m_idx;
QList<ControlPoint *> points;
+ GlyphItemBase *item;
public:
static QPainterPath contourToPath(const Contour &contour);
};
diff --git a/gui/gui.rules b/gui/gui.rules
index 597d266..e57baad 100644
--- a/gui/gui.rules
+++ b/gui/gui.rules
@@ -17,7 +17,8 @@ libfonduegui_a_SOURCES = \
gui/unicodevalueeditor.cxx \
gui/unicodeproxymodel.cxx \
gui/cvteditor.cxx \
- gui/maxpeditor.cxx
+ gui/maxpeditor.cxx \
+ gui/glyphitem.cxx
nodist_libfonduegui_a_SOURCES = \
gui/ttihighlighter.moc.cxx \
@@ -34,7 +35,8 @@ nodist_libfonduegui_a_SOURCES = \
gui/glyphsmodeldelegate.moc.cxx \
gui/unicodeproxymodel.moc.cxx \
gui/cvteditor.moc.cxx \
- gui/maxpeditor.moc.cxx
+ gui/maxpeditor.moc.cxx \
+ gui/glyphgraphics.moc.cxx
gui/instnames.tbl.cxx: data/instructions.xml
gui/instnames.tbl.cxx: DATAFILE=$(srcdir)/data/instructions.xml
@@ -58,7 +60,8 @@ noinst_HEADERS += \
gui/colorcombobox.h \
gui/unicodeproxymodel.h \
gui/cvteditor.h \
- gui/maxpeditor.h
+ gui/maxpeditor.h \
+ gui/glyphitem.h
CLEANFILES += gui/*.moc.cxx gui/*.tbl.cxx
EXTRA_DIST += gui/instnames.xsl
commit be95771a21b8fa6f429cc39c25d612e673928630
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date: Wed Sep 12 16:10:16 2007 +0200
add function for getting index for named glyph
diff --git a/gui/glyphsmodel.cxx b/gui/glyphsmodel.cxx
index e3105de..d0baae1 100644
--- a/gui/glyphsmodel.cxx
+++ b/gui/glyphsmodel.cxx
@@ -317,3 +317,14 @@ void GlyphsModel::moveGlyphPoint(const QModelIndex &index, int component, int po
}
}
+QModelIndex GlyphsModel::findGlyphByName(const QString &name) const
+{
+ const Glyph *g = doc->getGlyph(name);
+ if (!g)
+ return QModelIndex();
+ for (int i = 0; i < doc->glyphs().size(); i++) {
+ if (doc->glyphs().at(i) == g)
+ return createIndex(i, 0);
+ }
+ return QModelIndex();
+}
diff --git a/gui/glyphsmodel.h b/gui/glyphsmodel.h
index a7c1f47..5d84950 100644
--- a/gui/glyphsmodel.h
+++ b/gui/glyphsmodel.h
@@ -47,6 +47,7 @@ public:
int columnCount(const QModelIndex &parent) const;
void setDocument(FontDocument *d);
bool removeRows(int row, int count, const QModelIndex &index);
+ QModelIndex findGlyphByName(const QString &name) const;
public slots:
void moveGlyphPoint(const QModelIndex &index, int component, int pointNo, const QPointF &newPos);
commit db5cd3408fd2a46375af5ffb725c4d3f770f4603
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date: Tue Sep 11 21:22:24 2007 +0200
add unicodenameslist.h to noinst_HEADERS
diff --git a/nongui/nongui.rules b/nongui/nongui.rules
index 6fb33a2..dd9ccfb 100644
--- a/nongui/nongui.rules
+++ b/nongui/nongui.rules
@@ -48,7 +48,8 @@ noinst_HEADERS += \
nongui/ttfencode.h \
nongui/cvtmodel.h \
nongui/ttfwriter.h \
- nongui/maxpmodel.h
+ nongui/maxpmodel.h \
+ nongui/unicodenameslist.h
EXTRA_DIST += \
nongui/decodertable.xsl \
--
Fondue Font Editor
More information about the fondue-commits
mailing list