[fondue-commits] [SCM] Fondue Font Editor branch, master, updated. 097b323e15f08ea5e8c1070c59c211e384fc8003
Eugeniy Meshcheryakov
eugen at debian.org
Thu May 15 18:58:04 UTC 2008
The following commit has been merged in the master branch:
commit 8a3342a983efbd622fa56877e01b3ed623a92245
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date: Thu May 15 17:41:42 2008 +0200
implement Contour and OffContour edit modes
diff --git a/gui/glyphcell.cxx b/gui/glyphcell.cxx
index 5a8eaf8..3fd9023 100644
--- a/gui/glyphcell.cxx
+++ b/gui/glyphcell.cxx
@@ -176,7 +176,7 @@ void GlyphCell::mousePressEvent(QMouseEvent *event)
ControlPoint *pt = 0;
foreach (QGraphicsItem *i, itms) {
if (i->type() == ControlPoint::Type) {
- pt = dynamic_cast<ControlPoint *>(i);
+ pt = dynamic_cast<ControlPoint *>(i); // qgraphicsitem_cast?
Q_ASSERT(pt);
break;
}
@@ -212,6 +212,73 @@ void GlyphCell::mousePressEvent(QMouseEvent *event)
m_actionOrigin = event->pos();
setCursor(Qt::ClosedHandCursor);
}
+ else if (m_editMode == Contour || m_editMode == OffContour) {
+ // If there is only one point selected and this is first/last
+ // point of an open contour, then add a new point to this contour.
+ // Else, start a new open contour, make the new point selected.
+ //
+ // If user clicks on a point, make it selected.
+ // TODO make it possible to insert points inside a closed contour
+ // TODO make it possible to close open contours
+
+ // First check, it there is point under cursor
+ QList<QGraphicsItem *> its = items(event->pos());
+ ControlPoint *pt = 0;
+ foreach (QGraphicsItem *i, its) {
+ if (i->type() == ControlPoint::Type) {
+ pt = qgraphicsitem_cast<ControlPoint *>(i);
+ Q_ASSERT(pt);
+ break;
+ }
+ }
+ if (pt) {
+ // oh! select this point
+ scene()->clearSelection();
+ pt->setSelected(true);
+ }
+ else {
+ bool startContour = false;
+ ControlPoint *pt = 0;
+ int firstPoint = false;
+
+ QList<QGraphicsItem *> sel = scene()->selectedItems();
+ if (sel.size() != 1)
+ startContour = true;
+ else {
+ pt = qgraphicsitem_cast<ControlPoint *>(sel.at(0));
+ if (!pt)
+ startContour = true;
+ else {
+ // is it first or last point?
+ Q_ASSERT(pt->contour());
+ if (pt->pointNumber() == 0)
+ firstPoint = true;
+ else if (pt->pointNumber() != pt->contour()->points().size()-1)
+ startContour = true;
+ }
+ }
+
+ scene()->clearSelection();
+
+ if (startContour) {
+ GlyphContour *cnt = new GlyphContour(true);
+ QPointF pnt = mapToScene(event->pos());
+ GlyphPoint gpt(pnt.x(), -pnt.y(), m_editMode == Contour);
+ cnt->appendPoint(gpt);
+ m_glyph->appendContour(cnt);
+ selectPoint(cnt, 0);
+ }
+ else {
+ Q_ASSERT(pt);
+ QPointF pnt = mapToScene(event->pos());
+ GlyphPoint gpt(pnt.x(), -pnt.y(), m_editMode == Contour);
+ int ptNo = firstPoint ? 0 : pt->contour()->points().size();
+ pt->contour()->insertPoint(gpt, ptNo);
+ selectPoint(pt->contour(), ptNo);
+ }
+ }
+ }
+
event->accept();
}
@@ -324,3 +391,23 @@ void GlyphCell::setEditMode(EditMode mode)
emit editModeChanged(mode);
}
}
+
+/**
+ * Try to select point number pointNo belonging to given contour
+ */
+void GlyphCell::selectPoint(const GlyphContour *contour, int pointNo)
+{
+ Q_ASSERT(scene());
+ Q_ASSERT(contour);
+
+ QList<QGraphicsItem *> its = scene()->items();
+ foreach (QGraphicsItem *i, its) {
+ ControlPoint *pt = qgraphicsitem_cast<ControlPoint *>(i);
+ if (pt) {
+ if (pt->contour() == contour && pt->pointNumber() == pointNo) {
+ pt->setSelected(true);
+ break;
+ }
+ }
+ }
+}
diff --git a/gui/glyphcell.h b/gui/glyphcell.h
index 4c8ce1c..eda71cd 100644
--- a/gui/glyphcell.h
+++ b/gui/glyphcell.h
@@ -20,6 +20,7 @@
class GlyphGraphics;
class Glyph;
class QRubberBand;
+class GlyphContour;
class GlyphCell : public QGraphicsView
{
@@ -50,6 +51,8 @@ protected:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
+
+ void selectPoint(const GlyphContour *contour, int pointNo);
private:
GlyphGraphics *gg;
Glyph *m_glyph;
--
Fondue Font Editor
More information about the fondue-commits
mailing list