2
// --------------------------------------------------------------------
3
// Overlay for the canvas --- shows moving objects etc.
4
// --------------------------------------------------------------------
7
This file is part of the extensible drawing editor Ipe.
8
Copyright (C) 1993-2004 Otfried Cheong
10
Ipe is free software; you can redistribute it and/or modify it
11
under the terms of the GNU General Public License as published by
12
the Free Software Foundation; either version 2 of the License, or
13
(at your option) any later version.
15
As a special exception, you have permission to link Ipe with the
16
CGAL library and distribute executables, as long as you follow the
17
requirements of the Gnu General Public License in regard to all of
18
the software in the executable aside from CGAL.
20
Ipe is distributed in the hope that it will be useful, but WITHOUT
21
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
23
License for more details.
25
You should have received a copy of the GNU General Public License
26
along with Ipe; if not, you can find it at
27
"http://www.gnu.org/copyleft/gpl.html", or write to the Free
28
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36
#include "ipepainter.h"
42
// --------------------------------------------------------------------
47
class IpeAllAttributes;
54
class IpeOverlayPainter : public IpePainter {
56
IpeOverlayPainter(const IpeStyleSheet *sheet, QPainter *painter);
57
virtual ~IpeOverlayPainter() { }
59
virtual void BeginPath(const IpeVector &v);
60
virtual void BeginClosedPath(const IpeVector &v);
61
virtual void LineTo(const IpeVector &v);
62
virtual void CurveTo(const IpeVector &v1, const IpeVector &v2,
64
virtual void EndPath();
65
virtual void EndClosedPath();
67
virtual void DrawBitmap(IpeBitmap bitmap);
68
virtual void DrawText(const IpeText *text);
76
// --------------------------------------------------------------------
78
/*! \class IpeOverlayServices
79
\brief Interface for callbacks from the overlays.
81
Provides services to (object-creating) overlays.
84
class IpeOverlayServices {
86
virtual void OvSvcAddObject(IpeObject *obj) = 0;
87
virtual const IpeAllAttributes &OvSvcAttributes() = 0;
88
virtual const IpeStyleSheet *OvSvcStyleSheet() = 0;
89
virtual void OvSvcAddUndoItem(IpePage *page, QString s) = 0;
90
virtual void OvSvcAddUndoItem(IpePage::iterator it, IpePage *page,
91
const IpePgObject &original, QString s) = 0;
94
// --------------------------------------------------------------------
98
virtual ~IpeOverlay();
100
//! Redraw the current overlay.
101
virtual void Draw(QPaintEvent *ev, QPainter *painter) const = 0;
103
virtual void MousePress(QMouseEvent *ev);
104
virtual void MouseRelease(QMouseEvent *ev);
105
virtual void MouseMove(QMouseEvent *ev);
106
virtual void KeyPress(QKeyEvent *ev);
108
inline QColor CreateColor() const { return QColor("navy"); }
111
IpeOverlay(IpeCanvas *canvas);
117
// --------------------------------------------------------------------
119
class IpePanning : public IpeOverlay {
121
IpePanning(QMouseEvent *ev, const IpePage *page, IpeCanvas *canvas);
123
virtual void Draw(QPaintEvent *ev, QPainter *painter) const;
124
virtual void MouseRelease(QMouseEvent *ev);
125
virtual void MouseMove(QMouseEvent *ev);
128
const IpePage *iPage;
129
IpeVector iMouseDown;
133
// --------------------------------------------------------------------
135
class IpeSelecting : public IpeOverlay {
137
IpeSelecting(QMouseEvent *ev, IpePage *page, IpeCanvas *canvas,
138
bool nonDestructive, int selectDistance, int view,
139
IpeOverlayServices *services);
141
virtual void Draw(QPaintEvent *ev, QPainter *painter) const;
142
virtual void MouseRelease(QMouseEvent *ev);
143
virtual void MouseMove(QMouseEvent *ev);
144
virtual void KeyPress(QKeyEvent *ev);
147
void EnsurePrimary();
150
friend class SelectCompare;
153
IpeOverlayServices *iServices;
154
bool iNonDestructive;
156
IpeVector iMouseDown;
158
IpePage::iterator iIt;
161
std::vector<SObj> iObjs;
168
// --------------------------------------------------------------------
170
class IpeTransforming : public IpeOverlay {
172
enum TType { EMove, EScale, EStretch, ERotate };
174
IpeTransforming(QMouseEvent *ev, IpePage *page,
175
IpeCanvas *canvas, TType type,
176
IpeOverlayServices *services);
177
bool FindObjects(int selectDistance);
179
virtual void Draw(QPaintEvent *ev, QPainter *painter) const;
180
virtual void MouseMove(QMouseEvent *ev);
181
virtual void MouseRelease(QMouseEvent *ev);
184
void Compute(const IpeVector &v);
185
bool UpdateCloseSelection(int selectDistance);
189
IpeOverlayServices *iServices;
192
IpeVector iMouseDown;
193
IpeMatrix iTransform;
197
// --------------------------------------------------------------------
199
class IpeOverlayFactory {
201
enum { ESelecting, EMoving, ERotating, EStretching, EPanning,
202
ELabel, EMath, EParagraph, EMark,
203
ERectangle, EPolyline, EPolygon,
205
ECircle1, ECircle2, ECircle3,
206
ESpline, ESplinegon, Num };
208
IpeOverlayFactory(QMouseEvent *ev, IpeCanvas *canvas,
209
IpePage *page, int view,
210
IpeOverlayServices *services);
211
void CreateOverlay(int index);
212
IpeOverlay *MakeOverlay(int index);
213
static const char *PixmapName(int index);
214
static const char *Tooltip(int index);
215
static const char *WhatsThis(int index);
216
static const char *Shortcut(int index);
217
static const char *Context(int index);
219
IpeOverlay *StartTransforming(IpeTransforming::TType type);
225
IpeOverlayServices *iServices;
228
// --------------------------------------------------------------------