kivio_canvas.h
1/*
2 * Kivio - Visual Modelling and Flowcharting
3 * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#ifndef __kivio_canvas_h__
20#define __kivio_canvas_h__
21
22#include <tqpainter.h>
23#include <tqbitmap.h>
24#include <tqlineedit.h>
25#include <tqwidget.h>
26#include <tqpoint.h>
27#include <tqrect.h>
28#include <tqstring.h>
29#include <tqptrlist.h>
30
31#include <KoQueryTrader.h>
32#include <KoPoint.h>
33#include <KoRect.h>
34#include <KoGuides.h>
35#include <koffice_export.h>
36#include "kivio_intra_stencil_data.h"
37
38class KivioView;
39class KivioCanvas;
40class KivioPage;
41class KivioDoc;
42class KivioRuler;
43class KivioGuideLineData;
44
45class KivioScreenPainter;
46class KivioStencil;
47
48class TQPainter;
49class TQLabel;
50class TQPixmap;
51class TQScrollBar;
52class TQTimer;
53
54class KoSize;
55class KoRect;
56
57#define YBORDER_WIDTH 50
58#define XBORDER_HEIGHT 20
59
60class KIVIO_EXPORT KivioCanvas : public TQWidget
61{
62 TQ_OBJECT
63
64 friend class KivioView;
65 public:
66 KivioCanvas( TQWidget*, KivioView*, KivioDoc*, TQScrollBar*, TQScrollBar* );
67 ~KivioCanvas();
68
69 int xOffset() const { return m_iXOffset; }
70 int yOffset() const { return m_iYOffset; }
71
72 const KivioPage* activePage() const;
73 KivioPage* activePage();
74 KivioPage* findPage( const TQString& _name );
75
76 KivioView* view()const { return m_pView; }
77 KivioDoc* doc()const { return m_pDoc; }
78
79 TQSize actualSize() const;
80
81 virtual bool event(TQEvent*);
82
83 enum RectType { Insert, Rubber };
84 void startRectDraw( const TQPoint &p, RectType t );
85 void continueRectDraw( const TQPoint &p, RectType t );
86 void endRectDraw();
87 TQRect rect()const { return currRect; }
88
89 void startSpawnerDragDraw( const TQPoint &p );
90 void continueSpawnerDragDraw( const TQPoint &p );
91 void endSpawnerDragDraw();
92
93 void drawSelectedStencilsXOR();
94 void drawStencilXOR( KivioStencil * );
95
96 KoPoint snapToGrid(const KoPoint&);
97 KoPoint snapToGuides(const KoPoint&, bool &, bool &);
98 KoPoint snapToGridAndGuides(const KoPoint&);
99
100 KoPoint mapFromScreen(const TQPoint&);
101 TQPoint mapToScreen(const KoPoint&);
102
103 void beginUnclippedSpawnerPainter();
104 void endUnclippedSpawnerPainter();
105
106 void setViewCenterPoint(const KoPoint &);
107
108 KoRect visibleArea();
109 void setVisibleArea(KoRect, int margin = 0);
110 void setVisibleAreaByWidth(KoRect, int margin = 0);
111 void setVisibleAreaByHeight(KoRect, int margin = 0);
112
113 KoGuides& guideLines() { return m_guides; }
114
115 int pageOffsetX() const { return m_pageOffsetX; }
116 int pageOffsetY() const { return m_pageOffsetY; }
117
118 void setShowConnectorTargets(bool state) { m_showConnectorTargets = state; }
119 bool showConnectorTargets() const { return m_showConnectorTargets; }
120
121 signals:
122 void visibleAreaChanged();
123
124 public slots:
125 virtual void setUpdatesEnabled(bool);
126
127 void zoomIn(const TQPoint&);
128 void zoomOut(const TQPoint&);
129
130 void scrollDx(int dx);
131 void scrollDy(int dy);
132
133 void scrollV(int value);
134 void scrollH(int value);
135
136 void updateScrollBars();
137
138 void startPasteMoving();
139
140 void updateAutoGuideLines();
141
142 protected:
143 virtual void mousePressEvent( TQMouseEvent* );
144 virtual void mouseReleaseEvent( TQMouseEvent* );
145 virtual void mouseMoveEvent( TQMouseEvent* );
146
147 virtual void enterEvent( TQEvent* );
148 virtual void leaveEvent( TQEvent* );
149
150 virtual void resizeEvent( TQResizeEvent* );
151 virtual void paintEvent( TQPaintEvent* );
152 virtual void wheelEvent( TQWheelEvent* );
153
154 virtual void dragEnterEvent( TQDragEnterEvent * );
155 virtual void dragMoveEvent( TQDragMoveEvent * );
156 virtual void dragLeaveEvent( TQDragLeaveEvent * );
157 virtual void dropEvent( TQDropEvent * );
158
159 virtual void keyPressEvent( TQKeyEvent * );
160
161 void beginUnclippedPainter();
162 void endUnclippedPainter();
163
164 void paintSelectedXOR();
165
166 void continuePasteMoving(const TQPoint &pos);
167 void endPasteMoving();
168
169 protected slots:
170 void borderTimerTimeout();
171
172 private:
173 KivioView* m_pView;
174 KivioDoc* m_pDoc;
175
176 TQScrollBar* m_pVertScrollBar;
177 TQScrollBar* m_pHorzScrollBar;
178
179 int m_iXOffset;
180 int m_iYOffset;
181
182 TQPixmap* m_buffer;
183
184 int m_pScrollX;
185 int m_pScrollY;
186 TQPointArray gridLines;
187
188 bool oldRectValid;
189 TQRect currRect;
190 TQPoint rectAnchor;
191 TQPainter* unclippedPainter;
192 TQPoint sizePreviewPos;
193
194 KivioScreenPainter* unclippedSpawnerPainter;
195 KivioIntraStencilData m_dragStencilData;
196 KivioStencil* m_pDragStencil;
197
198 TQTimer* m_borderTimer;
199
200 bool delegateThisEvent;
201 TQPoint lastPoint;
202
203 bool m_pasteMoving;
204 TQPtrList<KoRect> m_lstOldGeometry;
205 KoPoint m_origPoint;
206
207 KoGuides m_guides;
208
209 int m_pageOffsetX;
210 int m_pageOffsetY;
211
212 bool m_showConnectorTargets;
213};
214
215#endif