KVIrc  4.9.2
DeveloperAPIs
canvaswidget.h
Go to the documentation of this file.
1 #ifndef _CANVAS_WIDGET_H_
2 #define _CANVAS_WIDGET_H_
3 //=============================================================================
4 //
5 // File : canvaswidget.h
6 // Creation date : Mon Jul 30 07 2001 04:49:49 by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 2001-2010 Szymon Stefanek (pragma at kvirc dot net)
10 //
11 // This program is FREE software. You can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the HOPE that it will be USEFUL,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 // See the GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
27 #include "DccBroker.h"
28 
29 #ifdef COMPILE_DCC_CANVAS
30 #include <QCanvas>
31 #include <QMenuBar>
32 #include <QLabel>
33 #include <QMap>
34 #include <QVariant>
35 #include <QTable>
36 #include <QSplitter>
37 
38 class DccCanvasWidget;
39 
40 #define KVI_CANVAS_RTTI_CONTROL_TYPE_RECTANGLE 1
41 #define KVI_CANVAS_RTTI_CONTROL_TYPE_LINE 2
42 #define KVI_CANVAS_RTTI_CONTROL_TYPE_POLYGON 4
43 
44 #define KVI_CANVAS_RTTI_CONTROL_TYPE_MASK 255
45 
46 #define KVI_CANVAS_RTTI_RECTANGLE (KVI_CANVAS_RTTI_CONTROL_TYPE_RECTANGLE | (1 << 8))
47 #define KVI_CANVAS_RTTI_RICHTEXT (KVI_CANVAS_RTTI_CONTROL_TYPE_RECTANGLE | (2 << 8))
48 #define KVI_CANVAS_RTTI_LINE (KVI_CANVAS_RTTI_CONTROL_TYPE_LINE | (3 << 8))
49 #define KVI_CANVAS_RTTI_ELLIPSE (KVI_CANVAS_RTTI_CONTROL_TYPE_RECTANGLE | (4 << 8))
50 #define KVI_CANVAS_RTTI_CHORD (KVI_CANVAS_RTTI_CONTROL_TYPE_RECTANGLE | (5 << 8))
51 #define KVI_CANVAS_RTTI_PIE (KVI_CANVAS_RTTI_CONTROL_TYPE_RECTANGLE | (6 << 8))
52 #define KVI_CANVAS_RTTI_POLYGON (KVI_CANVAS_RTTI_CONTROL_TYPE_POLYGON | (7 << 8))
53 
54 #define KVI_CANVAS_RTTI_CONTROL_TYPE(__item) (__item->rtti() & KVI_CANVAS_RTTI_CONTROL_TYPE_MASK)
55 
56 class KviCanvasPolygon : public QCanvasPolygon
57 {
58 public:
59  KviCanvasPolygon(QCanvas * c, int x, int y, QPointArray & pnts, double dScaleFactor);
60  virtual ~KviCanvasPolygon();
61 
62 protected:
63  QMap<QString, QVariant> m_properties;
64  double m_dScaleFactor;
65  QPointArray m_points;
66 
67 public:
68  virtual void draw(QPainter & p);
69  double scaleFactor() { return m_dScaleFactor; };
70  void setScaleFactor(double dScaleFactor);
71  void resetPoints();
72  const QPointArray & internalPoints() { return m_points; };
73  void setInternalPoints(const QPointArray & pnts);
74  QMap<QString, QVariant> * properties() { return &m_properties; };
75  virtual void setProperty(const QString & property, const QVariant & val);
76  virtual int rtti() const;
77 };
78 
79 class KviCanvasRectangleItem : public QCanvasRectangle
80 {
81  friend class KviCanvasRectangle;
82  friend class KviCanvasRichText;
83  friend class KviCanvasEllipticItem;
84 
85 protected:
86  KviCanvasRectangleItem(QCanvas * c, int x, int y, int w, int h);
87 
88 public:
89  virtual ~KviCanvasRectangleItem();
90 
91 protected:
92  QMap<QString, QVariant> m_properties;
93 
94 public:
95  int right() { return ((int)x()) + width(); };
96  int bottom() { return ((int)y()) + height(); };
97  QMap<QString, QVariant> * properties() { return &m_properties; };
98  virtual void setProperty(const QString & property, const QVariant & val);
99  // QVariant property(const QString &name){ return m_properties[name]; };
100 protected:
101  void drawSelection(QPainter & p);
102 };
103 
104 class KviCanvasEllipticItem : public KviCanvasRectangleItem
105 {
106  friend class KviCanvasEllipse;
107  friend class KviCanvasChord;
108  friend class KviCanvasPie;
109 
110 protected:
111  KviCanvasEllipticItem(QCanvas * c, int x, int y, int w, int h);
112  ~KviCanvasEllipticItem();
113 
114 public:
115  virtual void setProperty(const QString & property, const QVariant & val);
116  virtual void draw(QPainter & p);
117  virtual void drawContent(QPainter & p);
118  virtual int rtti() const;
119 };
120 
121 class KviCanvasEllipse : public KviCanvasEllipticItem
122 {
123 public:
124  KviCanvasEllipse(QCanvas * c, int x, int y, int w, int h);
125  ~KviCanvasEllipse();
126 
127 public:
128  virtual void drawContent(QPainter & p);
129  virtual int rtti() const;
130 };
131 
132 class KviCanvasPie : public KviCanvasEllipticItem
133 {
134 public:
135  KviCanvasPie(QCanvas * c, int x, int y, int w, int h);
136  ~KviCanvasPie();
137 
138 public:
139  virtual void drawContent(QPainter & p);
140  virtual int rtti() const;
141 };
142 
143 class KviCanvasChord : public KviCanvasEllipticItem
144 {
145 public:
146  KviCanvasChord(QCanvas * c, int x, int y, int w, int h);
147  ~KviCanvasChord();
148 
149 public:
150  virtual void drawContent(QPainter & p);
151  virtual int rtti() const;
152 };
153 
154 class KviCanvasLine : public QCanvasLine
155 {
156 public:
157  KviCanvasLine(QCanvas * c, int x1, int y1, int x2, int y2);
158  virtual ~KviCanvasLine();
159 
160 protected:
161  QMap<QString, QVariant> m_properties;
162 
163 public:
164  QMap<QString, QVariant> * properties() { return &m_properties; };
165  virtual void setProperty(const QString & property, const QVariant & val);
166  // QVariant property(const QString &name){ return m_properties[name]; };
167  virtual void draw(QPainter & p);
168  virtual int rtti() const;
169 };
170 
171 class KviCanvasRectangle : public KviCanvasRectangleItem
172 {
173 public:
174  KviCanvasRectangle(QCanvas * c, int x, int y, int w, int h);
175  ~KviCanvasRectangle();
176 
177 public:
178  virtual void draw(QPainter & p);
179  virtual void setProperty(const QString & property, const QVariant & val);
180  virtual int rtti() const;
181 };
182 
183 class KviCanvasRichText : public KviCanvasRectangleItem
184 {
185 public:
186  KviCanvasRichText(QCanvas * c, int x, int y, int w, int h);
187  ~KviCanvasRichText();
188 
189 public:
190  virtual void draw(QPainter & p);
191  virtual int rtti() const;
192 };
193 
194 class KviCanvasView : public QCanvasView
195 {
196  Q_OBJECT
197 public:
198  KviCanvasView(QCanvas * c, DccCanvasWidget * cw, QWidget * par);
199  ~KviCanvasView();
200 
201 public:
202  enum State
203  {
204  Idle,
205  SelectOrigin
206  };
207  enum ObjectType
208  {
209  Rectangle,
210  RichText,
211  Line,
212  Ellipse,
213  Chord,
214  Pie,
215  PolygonTriangle,
216  PolygonRectangle,
217  PolygonPentagon,
218  PolygonHexagon
219  };
220  enum DragMode
221  {
222  None,
223  All,
224  Left,
225  Right,
226  Top,
227  Bottom,
228  LeftTop,
229  RightTop,
230  LeftBottom,
231  RightBottom,
232  Scale,
233  SinglePoint,
234  Rotate
235  };
236 
237 protected:
238  DccCanvasWidget * m_pCanvasWidget;
239 
240  // Insertion of objects
241  State m_state;
242  ObjectType m_objectToInsert;
243 
244  // Selected item
245  QCanvasItem * m_pSelectedItem;
246 
247  DragMode m_dragMode;
248  QPoint m_dragBegin;
249  double m_dragScaleFactor;
250  unsigned int m_dragPointIndex;
251  QPointArray m_dragPointArray;
252 
253 protected:
254  void beginDragRectangle(KviCanvasRectangleItem * it, const QPoint & p, bool bInitial = false);
255  void dragRectangle(KviCanvasRectangleItem * it, const QPoint & p);
256 
257  void beginDragLine(KviCanvasLine * it, const QPoint & p, bool bInitial = false);
258  void dragLine(KviCanvasLine * it, const QPoint & p);
259 
260  void beginDragPolygon(KviCanvasPolygon * it, const QPoint & p, bool bShift = false, bool bCtrl = false);
261  void dragPolygon(KviCanvasPolygon * it, const QPoint & p);
262 
263  void setItemSelected(QCanvasItem * it);
264  void clearSelection();
265  void insertObjectAt(const QPoint & pnt, ObjectType o);
266  virtual void contentsMousePressEvent(QMouseEvent * e);
267  virtual void contentsMouseMoveEvent(QMouseEvent * e);
268  virtual void contentsMouseReleaseEvent(QMouseEvent * e);
269 public slots:
270  void insertRectangle();
271  void insertRichText();
272  void insertLine();
273  void insertPie();
274  void insertChord();
275  void insertEllipse();
276  void insertPolygonTriangle();
277  void insertPolygonRectangle();
278  void insertPolygonPentagon();
279  void insertPolygonHexagon();
280  void propertyChanged(const QString & s, const QVariant & v);
281 };
282 
283 class KviVariantTableItem : public QTableItem
284 {
285 public:
286  KviVariantTableItem(QTable * t, const QVariant & property);
287  ~KviVariantTableItem();
288 
289 private:
290  QVariant m_property;
291 
292 public:
293  virtual QWidget * createEditor() const;
294  virtual void setContentFromEditor(QWidget * w);
295  QVariant & property() { return m_property; };
296  virtual void paint(QPainter * p, const QColorGroup & cg, const QRect & cr, bool selected);
297 };
298 
299 class KviCanvasItemPropertiesWidget : public QTable
300 {
301  Q_OBJECT
302 public:
303  KviCanvasItemPropertiesWidget(QWidget * par);
304  ~KviCanvasItemPropertiesWidget();
305 
306 public:
307  void editItem(QCanvasItem * it);
308 protected slots:
309  void cellEdited(int row, int col);
310 signals:
311  void propertyChanged(const QString & s, const QVariant & v);
312 };
313 
314 class DccCanvasWidget : public QWidget
315 {
316  friend class KviCanvasView;
317  Q_OBJECT
318 public:
319  DccCanvasWidget(QWidget * par);
320  ~DccCanvasWidget();
321 
322 protected:
323  QSplitter * m_pSplitter;
324  QCanvas * m_pCanvas;
325  QMenuBar * m_pMenuBar;
326  KviCanvasView * m_pCanvasView;
327  QLabel * m_pStatusLabel;
328  KviCanvasItemPropertiesWidget * m_pPropertiesWidget;
329 
330 protected:
331  virtual void resizeEvent(QResizeEvent *);
332 };
333 #endif
334 
335 #endif //_CANVAS_WIDGET_H_
char s char s char s s s s s char char c s *s c s s s d c s *s d c d d d d c
Definition: KviIrcNumericCodes.h:391
State
Definition: NotifierSettings.h:61
#define e
Definition: detector.cpp:69
#define h
Definition: detector.cpp:72
char s char s s
Definition: KviIrcNumericCodes.h:391
QHashIterator< int, QFile * > t(getDict)
#define o
Definition: detector.cpp:79
#define w
Definition: detector.cpp:87
#define x
Definition: detector.cpp:88
#define y
Definition: detector.cpp:89
#define v
Definition: detector.cpp:86
#define p
Definition: detector.cpp:80
Definition: Idle.h:32