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
323
324
325
|
#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 <tqcanvas.h>
//#ifdef TQT_NO_CANVAS
// #warning "HEre is not"
//#endif
#include <tqmenubar.h>
#include <tqlabel.h>
#include <tqmap.h>
#include <tqvariant.h>
#include <tqtable.h>
#include <tqsplitter.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 TQCanvasPolygon
{
public:
KviCanvasPolygon(TQCanvas * c,int x,int y,TQPointArray &pnts,double dScaleFactor);
virtual ~KviCanvasPolygon();
protected:
TQMap<TQString,TQVariant> m_properties;
double m_dScaleFactor;
TQPointArray m_points;
public:
virtual void draw(TQPainter & p);
double scaleFactor(){ return m_dScaleFactor; };
void setScaleFactor(double dScaleFactor);
void resetPoints();
const TQPointArray & internalPoints(){ return m_points; };
void setInternalPoints(const TQPointArray &pnts);
TQMap<TQString,TQVariant> * properties(){ return &m_properties; };
virtual void setProperty(const TQString &property,const TQVariant &val);
virtual int rtti() const;
};
class KviCanvasRectangleItem : public TQCanvasRectangle
{
friend class KviCanvasRectangle;
friend class KviCanvasRichText;
friend class KviCanvasEllipticItem;
protected:
KviCanvasRectangleItem(TQCanvas * c,int x,int y,int w,int h);
public:
virtual ~KviCanvasRectangleItem();
protected:
TQMap<TQString,TQVariant> m_properties;
public:
int right(){ return ((int)x()) + width(); };
int bottom(){ return ((int)y()) + height(); };
TQMap<TQString,TQVariant> * properties(){ return &m_properties; };
virtual void setProperty(const TQString &property,const TQVariant &val);
// TQVariant property(const TQString &name){ return m_properties[name]; };
protected:
void drawSelection(TQPainter &p);
};
class KviCanvasEllipticItem : public KviCanvasRectangleItem
{
friend class KviCanvasEllipse;
friend class KviCanvasChord;
friend class KviCanvasPie;
protected:
KviCanvasEllipticItem(TQCanvas * c,int x,int y,int w,int h);
~KviCanvasEllipticItem();
public:
virtual void setProperty(const TQString & property,const TQVariant &val);
virtual void draw(TQPainter & p);
virtual void drawContent(TQPainter & p);
virtual int rtti() const;
};
class KviCanvasEllipse : public KviCanvasEllipticItem
{
public:
KviCanvasEllipse(TQCanvas * c,int x,int y,int w,int h);
~KviCanvasEllipse();
public:
virtual void drawContent(TQPainter & p);
virtual int rtti() const;
};
class KviCanvasPie : public KviCanvasEllipticItem
{
public:
KviCanvasPie(TQCanvas * c,int x,int y,int w,int h);
~KviCanvasPie();
public:
virtual void drawContent(TQPainter & p);
virtual int rtti() const;
};
class KviCanvasChord : public KviCanvasEllipticItem
{
public:
KviCanvasChord(TQCanvas * c,int x,int y,int w,int h);
~KviCanvasChord();
public:
virtual void drawContent(TQPainter & p);
virtual int rtti() const;
};
class KviCanvasLine : public TQCanvasLine
{
public:
KviCanvasLine(TQCanvas * c,int x1,int y1,int x2,int y2);
virtual ~KviCanvasLine();
protected:
TQMap<TQString,TQVariant> m_properties;
public:
TQMap<TQString,TQVariant> * properties(){ return &m_properties; };
virtual void setProperty(const TQString &property,const TQVariant &val);
// TQVariant property(const TQString &name){ return m_properties[name]; };
virtual void draw(TQPainter & p);
virtual int rtti() const;
};
class KviCanvasRectangle : public KviCanvasRectangleItem
{
public:
KviCanvasRectangle(TQCanvas * c,int x,int y,int w,int h);
~KviCanvasRectangle();
public:
virtual void draw(TQPainter & p);
virtual void setProperty(const TQString &property,const TQVariant &val);
virtual int rtti() const;
};
class KviCanvasRichText : public KviCanvasRectangleItem
{
public:
KviCanvasRichText(TQCanvas * c,int x,int y,int w,int h);
~KviCanvasRichText();
public:
virtual void draw(TQPainter & p);
virtual int rtti() const;
};
class KviCanvasView : public TQCanvasView
{
Q_OBJECT
public:
KviCanvasView(TQCanvas * c,KviCanvasWidget * cw,TQWidget * 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
TQCanvasItem * m_pSelectedItem;
DragMode m_dragMode;
TQPoint m_dragBegin;
double m_dragScaleFactor;
unsigned int m_dragPointIndex;
TQPointArray m_dragPointArray;
protected:
void beginDragRectangle(KviCanvasRectangleItem * it,const TQPoint &p,bool bInitial = false);
void dragRectangle(KviCanvasRectangleItem * it,const TQPoint & p);
void beginDragLine(KviCanvasLine * it,const TQPoint &p,bool bInitial = false);
void dragLine(KviCanvasLine * it,const TQPoint &p);
void beginDragPolygon(KviCanvasPolygon * it,const TQPoint &p,bool bShift = false,bool bCtrl = false);
void dragPolygon(KviCanvasPolygon * it,const TQPoint &p);
void setItemSelected(TQCanvasItem * it);
void clearSelection();
void insertObjectAt(const TQPoint & pnt,ObjectType o);
virtual void contentsMousePressEvent(TQMouseEvent *e);
virtual void contentsMouseMoveEvent(TQMouseEvent *e);
virtual void contentsMouseReleaseEvent(TQMouseEvent *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 TQString &s,const TQVariant &v);
};
// For TQt3.0 this might need to be changed
class KviVariantTableItem : public TQTableItem
{
public:
KviVariantTableItem(TQTable * t,const TQVariant & property);
~KviVariantTableItem();
private:
TQVariant m_property;
public:
virtual TQWidget * createEditor() const;
virtual void setContentFromEditor(TQWidget *w);
TQVariant & property(){ return m_property; };
virtual void paint(TQPainter *p,const TQColorGroup &cg,const TQRect &cr,bool selected);
};
class KviCanvasItemPropertiesWidget : public TQTable
{
Q_OBJECT
public:
KviCanvasItemPropertiesWidget(TQWidget * par);
~KviCanvasItemPropertiesWidget();
public:
void editItem(TQCanvasItem * it);
protected slots:
void cellEdited(int row,int col);
signals:
void propertyChanged(const TQString &s,const TQVariant &v);
};
class KviCanvasWidget : public TQWidget
{
friend class KviCanvasView;
Q_OBJECT
public:
KviCanvasWidget(TQWidget * par);
~KviCanvasWidget();
protected:
TQSplitter * m_pSplitter;
TQCanvas * m_pCanvas;
TQMenuBar * m_pMenuBar;
KviCanvasView * m_pCanvasView;
TQLabel * m_pStatusLabel;
KviCanvasItemPropertiesWidget * m_pPropertiesWidget;
protected:
virtual void resizeEvent(TQResizeEvent *);
};
#endif
#endif //_CANVAS_WIDGET_H_
|