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