SymbolEditor  1.3.0
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
Editor.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2011 by Stephen Allewell *
3  * sallewell@users.sourceforge.net *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  ********************************************************************************/
10 
11 
18 #ifndef Editor_H
19 #define Editor_H
20 
21 
22 #include <QMap>
23 #include <QPainterPath>
24 #include <QPair>
25 #include <QPointF>
26 #include <QUndoStack>
27 #include <QWidget>
28 
29 #include "Commands.h"
30 
31 
32 class QMousePressEvent;
33 class QMouseMoveEvent;
34 class QMouseReleaseEvent;
35 class QPaintEvent;
36 
37 class KCharSelect;
38 
39 
74 class Editor : public QWidget
75 {
76  Q_OBJECT
77 
78 public:
80 
81  explicit Editor(QWidget *parent = 0);
82  ~Editor();
83 
84  QPair<qint16, Symbol> symbol();
85  void setSymbol(const QPair<qint16, Symbol> &pair);
86 
87  QPainterPath moveTo(const QPointF &to);
88  QPainterPath lineTo(const QPointF &to);
89  QPainterPath cubicTo(const QPointF &control1, const QPointF &control2, const QPointF &to);
90  QPainterPath addRectangle(const QPointF &from, const QPointF &to);
91  QPainterPath addEllipse(const QPointF &from, const QPointF &to);
92  void removeLast(const QPainterPath &path);
93  void movePoint(int index, const QPointF &to);
94  void rotatePointsLeft();
95  void rotatePointsRight();
96  void flipPointsHorizontal();
97  void flipPointsVertical();
98  void setFilled(bool filled);
99  void setFillRule(Qt::FillRule rule);
100  void setCapStyle(Qt::PenCapStyle capStyle);
101  void setJoinStyle(Qt::PenJoinStyle joinStyle);
102  void setLineWidth(double width);
103  QPainterPath setPath(const QPainterPath &path);
104 
105  void clear();
106 
107  QUndoStack *undoStack();
108 
109 public slots:
110  void selectTool(QAction *action);
111  void charSelected(const QChar &character);
112  void enableSnap(bool enabled);
113  void selectFilled(bool enabled);
114  void selectFillRule(QAction *action);
115  void selectCapStyle(QAction *action);
116  void selectJoinStyle(QAction *action);
117  void increaseLineWidth();
118  void decreaseLineWidth();
119 
120  void rotateLeft();
121  void rotateRight();
122  void flipHorizontal();
123  void flipVertical();
124  void scalePreferred();
125 
126  void readSettings();
127 
128 signals:
129  void message(const QString &text);
130  void minLineWidth(bool reached);
131  void maxLineWidth(bool reached);
132 
133 protected:
134  void mousePressEvent(QMouseEvent *event);
135  void mouseMoveEvent(QMouseEvent *event);
136  void mouseReleaseEvent(QMouseEvent *event);
137 
138  void paintEvent(QPaintEvent *event);
139 
140  void keyPressEvent(QKeyEvent *event);
141 
142 private:
143  void addPoint(const QPointF &point);
144  QPointF snapPoint(const QPoint &point) const;
145  QPair<bool, QPointF> snapToGrid(const QPoint &point) const;
146  QPair<bool, QPointF> snapToGuide(const QPointF &point) const;
147  QPointF toSymbol(const QPoint &point) const;
148  QPoint toScreen(const QPointF &point) const;
149  bool node(const QPointF &point) const;
150  QPair<bool, int> nodeUnderCursor(const QPointF &point) const;
151  void deconstructPainterPath();
152  void constructPainterPath();
153  bool constructGuides(const QPointF &to);
154  void constructLineGuides(const QPointF &from, const QPointF &to);
155  void constructCircleGuides(const QPointF &from, const QPointF &to);
156  QLineF projected(const QLineF &line) const;
157 
158  int m_size;
160  bool m_snap;
161  bool m_fill;
163  QUndoStack m_undoStack;
167  QList<QPointF> m_points;
168  QList<QPainterPath::ElementType> m_elements;
170  QList<QPointF> m_activePoints;
172  qint16 m_index;
173  QPainterPath m_painterPath;
176  bool m_dragging;
177  QPointF m_start;
178  QPointF m_tracking;
179  QRectF m_rubberBand;
180  QPair<bool, int> m_dragPointIndex;
182  QVector<qreal> m_angles;
183  QList<QLineF> m_guideLines;
184  QList<qreal> m_guideCircles;
185  QList<QPointF> m_snapPoints;
186  QLineF m_topEdge;
187  QLineF m_bottomEdge;
188  QLineF m_leftEdge;
189  QLineF m_rightEdge;
191  KCharSelect *m_charSelect;
201 };
202 
203 
204 #endif
205