[fondue-commits] [SCM] Fondue Font Editor branch, master, updated. 15dc29fdd28eaab758c831e64aa615e54f82f5d8
Eugeniy Meshcheryakov
eugen at debian.org
Mon Oct 1 18:37:47 UTC 2007
The branch, master has been updated
via 15dc29fdd28eaab758c831e64aa615e54f82f5d8 (commit)
from 9f069f1d621e36de39a752ca090d8b41e630961b (commit)
- Shortlog ------------------------------------------------------------
15dc29f handle points movement in class Glyph (was: GlyphsModel)
Summary of changes:
gui/glyphcell.cxx | 2 +-
gui/glyphgraphics.cxx | 89 ++++++++++++++++++++++-------------------------
gui/glyphgraphics.h | 14 +++----
gui/glyphitem.cxx | 4 +-
gui/glyphsmodel.cxx | 41 +++-------------------
gui/glyphsmodel.h | 4 +--
nongui/fontdocument.cxx | 11 ++++++
nongui/fontdocument.h | 3 ++
nongui/glyph.cxx | 21 +++++++++++
nongui/glyph.h | 5 +++
10 files changed, 97 insertions(+), 97 deletions(-)
-----------------------------------------------------------------------
Details of changes:
commit 15dc29fdd28eaab758c831e64aa615e54f82f5d8
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date: Mon Oct 1 20:37:40 2007 +0200
handle points movement in class Glyph (was: GlyphsModel)
diff --git a/gui/glyphcell.cxx b/gui/glyphcell.cxx
index 90123ce..f573f7a 100644
--- a/gui/glyphcell.cxx
+++ b/gui/glyphcell.cxx
@@ -43,7 +43,7 @@ GlyphCell::GlyphCell(GlyphsModel *model, const QModelIndex &index) : QGraphicsVi
setScene(scene);
setTransformationAnchor(AnchorUnderMouse);
- gg = new GlyphGraphics(this, model, index);
+ gg = new GlyphGraphics(this, glyph);
fitGlyph();
}
diff --git a/gui/glyphgraphics.cxx b/gui/glyphgraphics.cxx
index 7a4d7f3..4d3803d 100644
--- a/gui/glyphgraphics.cxx
+++ b/gui/glyphgraphics.cxx
@@ -26,17 +26,17 @@
#include "glyphitem.h"
#include "glyphref.h"
-GlyphGraphics::GlyphGraphics(GlyphCell *parent, GlyphsModel *model, const QModelIndex &idx) :
- QObject(parent), p(parent), m_model(model), m_idx(idx)
+GlyphGraphics::GlyphGraphics(GlyphCell *parent, Glyph *glyph) :
+ QObject(parent), p(parent), m_glyph(glyph)
{
Q_ASSERT(p);
- Q_ASSERT(model);
+ Q_ASSERT(glyph);
+ Q_ASSERT(glyph->document());
item = new GlyphItemOutline(this);
- for (int i = 0; i < glyph()->content.size(); i++) {
- const QVariant &v = glyph()->content.at(i);
- // TODO add references
+ for (int i = 0; i < m_glyph->content.size(); i++) {
+ const QVariant &v = m_glyph->content.at(i);
if (v.canConvert<Contour>()) {
Contour c = v.value<Contour>();
for (int j = 0; j < c.size(); j++) {
@@ -50,35 +50,40 @@ GlyphGraphics::GlyphGraphics(GlyphCell *parent, GlyphsModel *model, const QModel
// TODO make it useable
Q_ASSERT(v.canConvert<GlyphRef>());
GlyphRef ref = v.value<GlyphRef>();
- QModelIndex other = m_model->findGlyphByName(ref.glyphName());
- if (other.isValid()) {
+ FontDocument *doc = m_glyph->document();
+
+ Glyph *other = doc->getGlyph(ref.glyphName());
+ if (other) {
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)));
+ connect(m_glyph, SIGNAL(outlineChanged(Glyph *)), this, SLOT(glyphOutlineChanged()));
+ connect(m_glyph, SIGNAL(pointMoved(Glyph *, int, int, QPointF)),
+ this, SLOT(glyphPointMoved(Glyph *, int, int, QPointF)));
}
-GlyphGraphics::GlyphGraphics(GlyphGraphics *parent, const QModelIndex &idx, const QPointF &pos) :
- QObject(parent), p(parent->p), m_model(parent->m_model), m_idx(idx)
+GlyphGraphics::GlyphGraphics(GlyphGraphics *parent, Glyph *glyph, const QPointF &pos) :
+ QObject(parent), p(parent->p), m_glyph(glyph)
{
Q_ASSERT(p);
- Q_ASSERT(m_model);
+ Q_ASSERT(m_glyph);
+ Q_ASSERT(m_glyph->parent());
+
item = new GlyphItemOutline(this, parent->item);
- for (int i = 0; i < glyph()->content.size(); i++) {
- const QVariant &v = glyph()->content.at(i);
- // TODO add references
+ for (int i = 0; i < m_glyph->content.size(); i++) {
+ const QVariant &v = m_glyph->content.at(i);
if (v.canConvert<GlyphRef>()) {
// TODO make it useable
Q_ASSERT(v.canConvert<GlyphRef>());
GlyphRef ref = v.value<GlyphRef>();
- QModelIndex other = m_model->findGlyphByName(ref.glyphName());
- if (other.isValid()) {
+
+ FontDocument *doc = m_glyph->document();
+ Glyph *other = doc->getGlyph(ref.glyphName());
+
+ if (other) {
new GlyphGraphics(this, other, ref.offset());
// TODO account them
}
@@ -86,15 +91,7 @@ GlyphGraphics::GlyphGraphics(GlyphGraphics *parent, const QModelIndex &idx, cons
}
item->setPos(pos.x(), -pos.y());
- connect(m_model, SIGNAL(glyphOutlineChanged(QModelIndex)),
- this, SLOT(glyphOutlineChanged(QModelIndex)));
-}
-
-const Glyph *GlyphGraphics::glyph() const
-{
- Q_ASSERT(m_idx.isValid());
- const Glyph *g = qobject_cast<Glyph *>(m_idx.data(GlyphsModel::GlyphRole).value<QObject *>());
- return g;
+ connect(m_glyph, SIGNAL(outlineChanged(Glyph *)), this, SLOT(glyphOutlineChanged()));
}
QPainterPath GlyphGraphics::contourToPath(const Contour &contour)
@@ -134,38 +131,36 @@ QPainterPath GlyphGraphics::contourToPath(const Contour &contour)
}
}
if (!contour.isOpen())
- path.closeSubpath(); // TODO open paths
+ path.closeSubpath();
return path;
}
-void GlyphGraphics::glyphOutlineChanged(const QModelIndex &index)
+void GlyphGraphics::glyphOutlineChanged()
{
- if (index.row() == m_idx.row())
- item->update();
+ item->update();
}
-void GlyphGraphics::glyphPointMoved(const QModelIndex &index, int component, int pointNo, const QPointF &newPos)
+void GlyphGraphics::glyphPointMoved(Glyph *glyph, int component, int pointNo, const QPointF &newPos)
{
- if (index.row() == m_idx.row()) {
- ControlPoint *pt = 0;
+ Q_UNUSED(glyph);
+ 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;
- }
- }
- Q_ASSERT(pt);
- QPointF realPos(newPos.x(), -newPos.y());
- if (pt->pos() != realPos) {
- pt->setPos(realPos);
+ 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);
+ }
}
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);
+ m_glyph->movePoint(idx.element, idx.num, newCoord);
}
diff --git a/gui/glyphgraphics.h b/gui/glyphgraphics.h
index fbe8a34..de8477f 100644
--- a/gui/glyphgraphics.h
+++ b/gui/glyphgraphics.h
@@ -19,7 +19,6 @@
#include <QObject>
#include <QPainterPath>
#include "contour.h"
-#include <QPersistentModelIndex>
class GlyphCell;
class ControlPoint;
@@ -31,6 +30,7 @@ class GlyphItemBase;
class GlyphGraphics: public QObject {
Q_OBJECT
+ friend class GlyphItemBase;
public:
struct PointIndex {
PointIndex(int e, int n) : element(e), num(n) {}
@@ -38,20 +38,18 @@ public:
int num;
};
- GlyphGraphics(GlyphCell *parent, GlyphsModel *model, const QModelIndex &idx);
+ GlyphGraphics(GlyphCell *parent, Glyph *glyph);
// FIXME destructor may be needed
//~GlyphGraphics();
- 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);
+ void glyphOutlineChanged();
+ void glyphPointMoved(Glyph *glyph, int component, int pointNo, const QPointF &newPos);
private:
- GlyphGraphics(GlyphGraphics *parent, const QModelIndex &idx, const QPointF &pos);
+ GlyphGraphics(GlyphGraphics *parent, Glyph *glyph, const QPointF &pos);
GlyphCell *p;
- GlyphsModel *m_model;
- QPersistentModelIndex m_idx;
+ Glyph *m_glyph;
QList<ControlPoint *> points;
GlyphItemBase *item;
public:
diff --git a/gui/glyphitem.cxx b/gui/glyphitem.cxx
index 3cc59c8..0da478a 100644
--- a/gui/glyphitem.cxx
+++ b/gui/glyphitem.cxx
@@ -23,13 +23,13 @@ GlyphItemBase::GlyphItemBase(GlyphGraphics *gfx, QGraphicsItem *parent) :
QGraphicsItem(parent), m_gfx(gfx)
{
Q_ASSERT(m_gfx);
- m_content = m_gfx->glyph()->content;
+ m_content = m_gfx->m_glyph->content;
}
void GlyphItemBase::update()
{
prepareGeometryChange();
- m_content = m_gfx->glyph()->content;
+ m_content = m_gfx->m_glyph->content;
}
QRectF GlyphItemBase::boundingRect() const
diff --git a/gui/glyphsmodel.cxx b/gui/glyphsmodel.cxx
index d0baae1..e75f074 100644
--- a/gui/glyphsmodel.cxx
+++ b/gui/glyphsmodel.cxx
@@ -206,6 +206,8 @@ void GlyphsModel::setDocument(FontDocument *d)
doc = d;
beginInsertRows(QModelIndex(), 0, doc->glyphs().size() + 1);
endInsertRows();
+
+ connect(doc, SIGNAL(glyphChanged(int)), this, SLOT(glyphChanged(int)));
}
// XXX does this really belong here?
@@ -290,41 +292,8 @@ bool GlyphsModel::removeRows(int row, int count, const QModelIndex &index)
return true;
}
-void GlyphsModel::moveGlyphPoint(const QModelIndex &index, int component, int pointNo, const QPointF &newPoint) // XXX GlyphPoint
-{
- Q_ASSERT(index.isValid());
-
- Glyph *glyph = doc->glyphs().at(index.row());
- Q_ASSERT(glyph);
-
- Q_ASSERT(component < glyph->content.size());
- QVariant v = glyph->content.at(component);
- Q_ASSERT(v.canConvert<Contour>());
-
- Contour contour = v.value<Contour>();
- Q_ASSERT(pointNo < contour.size());
- GlyphPoint pt = contour.at(pointNo);
- if (pt.x() != newPoint.x() || pt.y() != newPoint.y()) {
- pt.setX(newPoint.x());
- pt.setY(newPoint.y());
- contour[pointNo] = pt;
- glyph->content[component] = qVariantFromValue(contour);
- emit glyphPointMoved(index, component, pointNo, newPoint);
- emit glyphOutlineChanged(index);
- emit dataChanged(index, index); // FIXME
- // TODO emit glyphOutlineChanged for glyphs that reference index
- doc->setChanged();
- }
-}
-
-QModelIndex GlyphsModel::findGlyphByName(const QString &name) const
+void GlyphsModel::glyphChanged(int glyphNo)
{
- 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();
+ QModelIndex idx = createIndex(glyphNo, GlyphColumn);
+ emit dataChanged(idx, idx);
}
diff --git a/gui/glyphsmodel.h b/gui/glyphsmodel.h
index 5d84950..146be4f 100644
--- a/gui/glyphsmodel.h
+++ b/gui/glyphsmodel.h
@@ -47,10 +47,8 @@ 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);
+ void glyphChanged(int glyphNo);
signals:
void glyphPointMoved(const QModelIndex &index, int component, int pointNo, const QPointF &newPos);
void glyphOutlineChanged(const QModelIndex &index);
diff --git a/nongui/fontdocument.cxx b/nongui/fontdocument.cxx
index 2338efd..db0d6b9 100644
--- a/nongui/fontdocument.cxx
+++ b/nongui/fontdocument.cxx
@@ -37,6 +37,8 @@ bool FontDocument::addGlyph(Glyph *glyph)
unicodeHash[unicode] = glyph;
glyph->setParent(this);
+ connect(glyph, SIGNAL(outlineChanged(Glyph *)), this, SLOT(glyphOutlineChanged(Glyph *)));
+
return true;
}
@@ -212,3 +214,12 @@ bool FontDocument::setMaxStackDepth(unsigned depth)
}
return true;
}
+
+void FontDocument::glyphOutlineChanged(Glyph *g)
+{
+ int idx = m_glyphs.indexOf(g);
+ Q_ASSERT(idx != -1);
+
+ emit glyphChanged(idx);
+ setChanged();
+}
diff --git a/nongui/fontdocument.h b/nongui/fontdocument.h
index 7344dbb..68e6ef1 100644
--- a/nongui/fontdocument.h
+++ b/nongui/fontdocument.h
@@ -139,8 +139,11 @@ public:
bool setMaxIDEFs(unsigned count);
unsigned maxStackDepth() const {return maxp.maxStackDepth;}
bool setMaxStackDepth(unsigned depth);
+protected slots:
+ void glyphOutlineChanged(Glyph *g);
signals:
void documentChanged();
+ void glyphChanged(int index);
private:
class FontFace {
public:
diff --git a/nongui/glyph.cxx b/nongui/glyph.cxx
index 7a1c536..9539924 100644
--- a/nongui/glyph.cxx
+++ b/nongui/glyph.cxx
@@ -71,3 +71,24 @@ void Glyph::countParts(unsigned &nContours, unsigned &nRefs) const
}
}
}
+
+void Glyph::movePoint(int component, int pointNo, const QPointF &newPos)
+{
+ Q_ASSERT(component < content.size());
+ QVariant v = content.at(component);
+ Q_ASSERT(v.canConvert<Contour>());
+
+ Contour contour = v.value<Contour>();
+ Q_ASSERT(pointNo < contour.size());
+
+ GlyphPoint pt = contour.at(pointNo);
+ if (pt.x() != newPos.x() || pt.y() != newPos.y()) {
+ pt.setX(newPos.x());
+ pt.setY(newPos.y());
+ contour[pointNo] = pt;
+ content[component] = qVariantFromValue(contour);
+
+ emit pointMoved(this, component, pointNo, newPos);
+ emit outlineChanged(this);
+ }
+}
diff --git a/nongui/glyph.h b/nongui/glyph.h
index 2e1ae70..2a3e5ab 100644
--- a/nongui/glyph.h
+++ b/nongui/glyph.h
@@ -113,6 +113,11 @@ public:
bool computeMetrics(qreal &xMin, qreal &xMax, qreal &yMin, qreal &yMax) const;
void countParts(unsigned &nContours, unsigned &nRefs) const;
+
+ void movePoint(int component, int pointNo, const QPointF &newPos);
+signals:
+ void pointMoved(Glyph *g, int component, int pointNo, const QPointF &newPos);
+ void outlineChanged(Glyph *g);
private:
qreal horiz_adv_x;
bool horiz_adv_x_set;
--
Fondue Font Editor
More information about the fondue-commits
mailing list