[fondue-commits] [SCM] Fondue Font Editor branch, master, updated. 971de6bcf423346b890296e422186dd6894039ba

Eugeniy Meshcheryakov eugen at debian.org
Fri Jan 4 22:49:29 UTC 2008


The branch, master has been updated
       via  971de6bcf423346b890296e422186dd6894039ba (commit)
       via  03a7fd86a767e4dafcaf24f5859745225812bd2f (commit)
      from  9244b062f6474ab42379f03f66445023683278d1 (commit)


- Shortlog ------------------------------------------------------------
971de6b make it possible to remove points from glyph (using <Del> in glyph editor)
03a7fd8 make GlyphPoint class known to QtScript

Summary of changes:
 gui/controlpoint.cxx     |   16 ++++++++++++++++
 gui/controlpoint.h       |    4 +++-
 gui/glyphcell.cxx        |   19 +++++++++++++++++++
 gui/glyphcell.h          |    1 +
 gui/glyphgraphics.cxx    |   26 ++++++++++++++++++++++++++
 gui/glyphgraphics.h      |    1 +
 nongui/glyphcontour.cxx  |   13 +++++++++++++
 nongui/glyphcontour.h    |    3 +++
 qscript/constructors.cxx |   17 +++++++++++++++++
 9 files changed, 99 insertions(+), 1 deletions(-)
-----------------------------------------------------------------------
Details of changes:

commit 971de6bcf423346b890296e422186dd6894039ba
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Fri Jan 4 23:49:14 2008 +0100

    make it possible to remove points from glyph (using <Del> in glyph editor)

diff --git a/gui/controlpoint.cxx b/gui/controlpoint.cxx
index 8723f91..e2fe5f5 100644
--- a/gui/controlpoint.cxx
+++ b/gui/controlpoint.cxx
@@ -34,6 +34,8 @@ ControlPoint::ControlPoint(GlyphContour *contour, int pointNumber, QGraphicsItem
 	setPos(pt.x(), -pt.y());
 
 	connect(m_contour, SIGNAL(pointChanged(int)), this, SLOT(glyphPointChanged(int)));
+	connect(m_contour, SIGNAL(pointsAdded(int, int)), this, SLOT(glyphPointsAdded(int, int)));
+	connect(m_contour, SIGNAL(pointsRemoved(int, int)), this, SLOT(glyphPointsRemoved(int, int)));
 }
 
 QRectF ControlPoint::boundingRect() const
@@ -92,3 +94,17 @@ void ControlPoint::glyphPointChanged(int number)
 		}
 	}
 }
+
+void ControlPoint::glyphPointsAdded(int start, int end)
+{
+	// renumber points after first one
+	if (m_pointNumber > start)
+		m_pointNumber += end - start + 1;
+}
+
+void ControlPoint::glyphPointsRemoved(int start, int end)
+{
+	// renumber points after last one
+	if (m_pointNumber > end)
+		m_pointNumber -= end - start + 1;
+}
diff --git a/gui/controlpoint.h b/gui/controlpoint.h
index b95dd4c..e2beafe 100644
--- a/gui/controlpoint.h
+++ b/gui/controlpoint.h
@@ -31,7 +31,7 @@ public:
 	QPainterPath shape() const;
 	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
 
-	const GlyphContour *contour() const {return m_contour;}
+	GlyphContour *contour() const {return m_contour;}
 	int pointNumber() const {return m_pointNumber;}
 protected:
 	QVariant itemChange(GraphicsItemChange change, const QVariant &value);
@@ -40,6 +40,8 @@ private:
 	int m_pointNumber;
 private slots:
 	void glyphPointChanged(int number);
+	void glyphPointsAdded(int start, int end);
+	void glyphPointsRemoved(int start, int end);
 };
 
 #endif
diff --git a/gui/glyphcell.cxx b/gui/glyphcell.cxx
index 4679e18..fdf3058 100644
--- a/gui/glyphcell.cxx
+++ b/gui/glyphcell.cxx
@@ -122,3 +122,22 @@ void GlyphCell::mouseDoubleClickEvent(QMouseEvent *e)
 		qDebug() << "Item at double click pos!";
 	QGraphicsView::mouseDoubleClickEvent(e);
 }
+
+void GlyphCell::keyPressEvent(QKeyEvent *e)
+{
+	if (e->key() == Qt::Key_Delete && !e->modifiers()) {
+		qDebug() << "Delete pressed";
+		// let's try to delete some points
+		QList<QGraphicsItem *> items = scene()->selectedItems();
+		foreach (QGraphicsItem *item, items) {
+			if (item->type() == ControlPoint::Type) {
+				ControlPoint *cp = dynamic_cast<ControlPoint *>(item);
+				Q_ASSERT(cp);
+
+				// FIXME points will be automatically renumbered after deletion
+				GlyphContour *c = cp->contour();
+				c->removePoints(cp->pointNumber(), 1);
+			}
+		}
+	}
+}
diff --git a/gui/glyphcell.h b/gui/glyphcell.h
index ca02db3..4392ba7 100644
--- a/gui/glyphcell.h
+++ b/gui/glyphcell.h
@@ -32,6 +32,7 @@ public slots:
 protected:
 	void drawForeground(QPainter *painter, const QRectF &rect);
 	void mouseDoubleClickEvent(QMouseEvent *e);
+	void keyPressEvent(QKeyEvent *e);
 private:
 	GlyphGraphics *gg;
 	Glyph *m_glyph;
diff --git a/gui/glyphgraphics.cxx b/gui/glyphgraphics.cxx
index 723142d..10e3f66 100644
--- a/gui/glyphgraphics.cxx
+++ b/gui/glyphgraphics.cxx
@@ -46,6 +46,7 @@ GlyphGraphics::GlyphGraphics(GlyphCell *parent, Glyph *glyph) :
 				points.append(cp);
 			}
 			connect(c, SIGNAL(pointsAdded(int, int)), this, SLOT(contourPointsAdded(int, int)));
+			connect(c, SIGNAL(pointsAboutToBeRemoved(int, int)), this, SLOT(contourPointsAboutToBeRemoved(int, int)));
 		}
 		else {
 			// TODO make it useable
@@ -155,3 +156,28 @@ void GlyphGraphics::contourPointsAdded(int start, int end)
 		points.append(cp);
 	}
 }
+
+void GlyphGraphics::contourPointsAboutToBeRemoved(int start, int end)
+{
+	qDebug() << "remove points notifier";
+
+	GlyphContour *contour = qobject_cast<GlyphContour *>(sender());
+	if (!contour)
+		return;
+
+	for (int i = start; i <= end; i++) {
+		ControlPoint *cp = 0;
+		qDebug() << "Looking for:" << i << contour;
+		foreach (ControlPoint *p, points) {
+			if (p->contour() == contour && p->pointNumber() == i) {
+				cp = p;
+				break;
+			}
+		}
+		if (cp) {
+			qDebug() << "removing point from scene";
+			points.removeAll(cp);
+			cp->deleteLater();
+		}
+	}
+}
diff --git a/gui/glyphgraphics.h b/gui/glyphgraphics.h
index 027eacb..4f5d5ec 100644
--- a/gui/glyphgraphics.h
+++ b/gui/glyphgraphics.h
@@ -38,6 +38,7 @@ public:
 public slots:
 	void glyphOutlineChanged();
 	void contourPointsAdded(int start, int end);
+	void contourPointsAboutToBeRemoved(int start, int end);
 private:
 	GlyphGraphics(GlyphGraphics *parent, Glyph *glyph, const QPointF &pos);
 	GlyphCell *p;
diff --git a/nongui/glyphcontour.cxx b/nongui/glyphcontour.cxx
index 0b7b91a..5f34a7f 100644
--- a/nongui/glyphcontour.cxx
+++ b/nongui/glyphcontour.cxx
@@ -53,3 +53,16 @@ void GlyphContour::changePoint(int number, const GlyphPoint &newPoint)
 		emit pointChanged(number);
 	}
 }
+
+void GlyphContour::removePoints(int first, int count)
+{
+	int last = first + count - 1;
+	Q_ASSERT(first < m_points.size());
+	Q_ASSERT(count > 0);
+	Q_ASSERT(last < m_points.size());
+
+	emit pointsAboutToBeRemoved(first, last);
+	for (int i = 0; i < count; i++)
+		m_points.removeAt(first);
+	emit pointsRemoved(first, last);
+}
diff --git a/nongui/glyphcontour.h b/nongui/glyphcontour.h
index 29c156c..7e20058 100644
--- a/nongui/glyphcontour.h
+++ b/nongui/glyphcontour.h
@@ -33,6 +33,7 @@ public:
 	GlyphPointList points() const {return m_points;}
 
 	Q_INVOKABLE void appendPoint(const GlyphPoint &point);
+	Q_INVOKABLE void removePoints(int first, int count);
 	Q_INVOKABLE void changePoint(int number, const GlyphPoint &newPoint);
 signals:
 	void pointChanged(int number);
@@ -40,6 +41,8 @@ signals:
 
 	void pointsAboutToBeAdded(int start, int end);
 	void pointsAdded(int start, int end);
+	void pointsAboutToBeRemoved(int start, int end);
+	void pointsRemoved(int start, int end);
 private:
 	bool m_open;
 	GlyphPointList m_points;

commit 03a7fd86a767e4dafcaf24f5859745225812bd2f
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Fri Jan 4 22:50:37 2008 +0100

    make GlyphPoint class known to QtScript

diff --git a/qscript/constructors.cxx b/qscript/constructors.cxx
index b896da0..758165b 100644
--- a/qscript/constructors.cxx
+++ b/qscript/constructors.cxx
@@ -109,6 +109,22 @@ static void pointFromScriptValue(const QScriptValue &obj, QPointF &point)
 	point.setY(obj.property("y").toNumber());
 }
 
+static QScriptValue glyphPointToScriptValue(QScriptEngine *engine, const GlyphPoint &point)
+{
+	QScriptValue obj = engine->newObject();
+	obj.setProperty("x", QScriptValue(engine, point.x()));
+	obj.setProperty("y", QScriptValue(engine, point.y()));
+	obj.setProperty("on", QScriptValue(engine, point.on()));
+	return obj;
+}
+
+static void glyphPointFromScriptValue(const QScriptValue &obj, GlyphPoint &point)
+{
+	point.setX(obj.property("x").toNumber());
+	point.setY(obj.property("y").toNumber());
+	point.setOn(obj.property("on").toBoolean());
+}
+
 void initScripting(QScriptEngine *engine)
 {
 	QScriptValue global = engine->globalObject();
@@ -139,4 +155,5 @@ void initScripting(QScriptEngine *engine)
 	qScriptRegisterMetaType<GlyphContentBase *>(engine, qObjectToScriptValue, qObjectFromScriptValue);
 	qScriptRegisterSequenceMetaType<GlyphContentList>(engine);
 	qScriptRegisterMetaType<QPointF>(engine, pointToScriptValue, pointFromScriptValue);
+	qScriptRegisterMetaType<GlyphPoint>(engine, glyphPointToScriptValue, glyphPointFromScriptValue);
 }

-- 
Fondue Font Editor



More information about the fondue-commits mailing list