KVIrc 5.2.0
Developer APIs
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
38class 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
56class KviCanvasPolygon : public QCanvasPolygon
57{
58public:
59 KviCanvasPolygon(QCanvas * c, int x, int y, QPointArray & pnts, double dScaleFactor);
60 virtual ~KviCanvasPolygon();
61
62protected:
63 QMap<QString, QVariant> m_properties;
64 double m_dScaleFactor;
65 QPointArray m_points;
66
67public:
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
79class KviCanvasRectangleItem : public QCanvasRectangle
80{
81 friend class KviCanvasRectangle;
82 friend class KviCanvasRichText;
83 friend class KviCanvasEllipticItem;
84
85protected:
86 KviCanvasRectangleItem(QCanvas * c, int x, int y, int w, int h);
87
88public:
89 virtual ~KviCanvasRectangleItem();
90
91protected:
92 QMap<QString, QVariant> m_properties;
93
94public:
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]; };
100protected:
101 void drawSelection(QPainter & p);
102};
103
104class KviCanvasEllipticItem : public KviCanvasRectangleItem
105{
106 friend class KviCanvasEllipse;
107 friend class KviCanvasChord;
108 friend class KviCanvasPie;
109
110protected:
111 KviCanvasEllipticItem(QCanvas * c, int x, int y, int w, int h);
112 ~KviCanvasEllipticItem();
113
114public:
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
121class KviCanvasEllipse : public KviCanvasEllipticItem
122{
123public:
124 KviCanvasEllipse(QCanvas * c, int x, int y, int w, int h);
125 ~KviCanvasEllipse();
126
127public:
128 virtual void drawContent(QPainter & p);
129 virtual int rtti() const;
130};
131
132class KviCanvasPie : public KviCanvasEllipticItem
133{
134public:
135 KviCanvasPie(QCanvas * c, int x, int y, int w, int h);
136 ~KviCanvasPie();
137
138public:
139 virtual void drawContent(QPainter & p);
140 virtual int rtti() const;
141};
142
143class KviCanvasChord : public KviCanvasEllipticItem
144{
145public:
146 KviCanvasChord(QCanvas * c, int x, int y, int w, int h);
147 ~KviCanvasChord();
148
149public:
150 virtual void drawContent(QPainter & p);
151 virtual int rtti() const;
152};
153
154class KviCanvasLine : public QCanvasLine
155{
156public:
157 KviCanvasLine(QCanvas * c, int x1, int y1, int x2, int y2);
158 virtual ~KviCanvasLine();
159
160protected:
161 QMap<QString, QVariant> m_properties;
162
163public:
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
171class KviCanvasRectangle : public KviCanvasRectangleItem
172{
173public:
174 KviCanvasRectangle(QCanvas * c, int x, int y, int w, int h);
175 ~KviCanvasRectangle();
176
177public:
178 virtual void draw(QPainter & p);
179 virtual void setProperty(const QString & property, const QVariant & val);
180 virtual int rtti() const;
181};
182
183class KviCanvasRichText : public KviCanvasRectangleItem
184{
185public:
186 KviCanvasRichText(QCanvas * c, int x, int y, int w, int h);
187 ~KviCanvasRichText();
188
189public:
190 virtual void draw(QPainter & p);
191 virtual int rtti() const;
192};
193
194class KviCanvasView : public QCanvasView
195{
196 Q_OBJECT
197public:
198 KviCanvasView(QCanvas * c, DccCanvasWidget * cw, QWidget * par);
199 ~KviCanvasView();
200
201public:
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
237protected:
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
253protected:
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 void contentsMousePressEvent(QMouseEvent * e) override;
267 void contentsMouseMoveEvent(QMouseEvent * e) override;
268 void contentsMouseReleaseEvent(QMouseEvent * e) override;
269public 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
283class KviVariantTableItem : public QTableItem
284{
285public:
286 KviVariantTableItem(QTable * t, const QVariant & property);
287 ~KviVariantTableItem();
288
289private:
290 QVariant m_property;
291
292public:
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
299class KviCanvasItemPropertiesWidget : public QTable
300{
301 Q_OBJECT
302public:
303 KviCanvasItemPropertiesWidget(QWidget * par);
304 ~KviCanvasItemPropertiesWidget();
305
306public:
307 void editItem(QCanvasItem * it);
308protected slots:
309 void cellEdited(int row, int col);
310signals:
311 void propertyChanged(const QString & s, const QVariant & v);
312};
313
314class DccCanvasWidget : public QWidget
315{
316 friend class KviCanvasView;
317 Q_OBJECT
318public:
319 DccCanvasWidget(QWidget * par);
320 ~DccCanvasWidget();
321
322protected:
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
330protected:
331 void resizeEvent(QResizeEvent *) override;
332};
333#endif
334
335#endif //_CANVAS_WIDGET_H_
State
Definition NotifierSettings.h:62
Definition Idle.h:33
#define y
Definition detector.cpp:90
#define t
Definition detector.cpp:85
#define e
Definition detector.cpp:70
#define v
Definition detector.cpp:87
#define h
Definition detector.cpp:73
#define x
Definition detector.cpp:89
#define w
Definition detector.cpp:88
#define s
Definition detector.cpp:84
#define o
Definition detector.cpp:80
#define p
Definition detector.cpp:81