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-2007 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"
40
#include <QPainterPath>
42
// --------------------------------------------------------------------
47
class IpeAllAttributes;
54
class IpeOverlayPainter : public IpePainter {
56
IpeOverlayPainter(const IpeStyleSheet *sheet, QPainter *painter);
57
virtual ~IpeOverlayPainter() { }
60
virtual void DoMoveTo(const IpeVector &v);
61
virtual void DoLineTo(const IpeVector &v);
62
virtual void DoCurveTo(const IpeVector &v1, const IpeVector &v2,
64
virtual void DoClosePath();
66
virtual void DoDrawPath();
67
virtual void DoDrawBitmap(IpeBitmap bitmap);
68
virtual void DoDrawText(const IpeText *text);
75
// --------------------------------------------------------------------
77
/*! \class IpeOverlayServices
78
\brief Interface for callbacks from the overlays.
80
Provides services to (object-creating) overlays.
83
class IpeOverlayServices {
85
virtual ~IpeOverlayServices() { /* nothing */ } // placate compiler
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;
92
virtual void OvSvcMessage(QString s) = 0;
95
// --------------------------------------------------------------------
99
virtual ~IpeOverlay();
101
//! Redraw the current overlay.
102
virtual void Draw(QPaintEvent *ev, QPainter *painter) const = 0;
104
virtual void MousePress(QMouseEvent *ev);
105
virtual void MouseRelease(QMouseEvent *ev);
106
virtual void MouseMove(QMouseEvent *ev);
107
virtual void KeyPress(QKeyEvent *ev);
109
inline QColor CreateColor() const { return QColor("navy"); }
112
IpeOverlay(IpeCanvas *canvas);
118
// --------------------------------------------------------------------
120
class IpePanning : public IpeOverlay {
122
IpePanning(QMouseEvent *ev, const IpePage *page, IpeCanvas *canvas);
124
virtual void Draw(QPaintEvent *ev, QPainter *painter) const;
125
virtual void MouseRelease(QMouseEvent *ev);
126
virtual void MouseMove(QMouseEvent *ev);
129
const IpePage *iPage;
130
IpeVector iMouseDown;
134
// --------------------------------------------------------------------
136
class IpeSelecting : public IpeOverlay {
138
IpeSelecting(QMouseEvent *ev, IpePage *page, int view, IpeCanvas *canvas,
139
bool nonDestructive, int selectDistance,
140
IpeOverlayServices *services);
142
virtual void Draw(QPaintEvent *ev, QPainter *painter) const;
143
virtual void MouseRelease(QMouseEvent *ev);
144
virtual void MouseMove(QMouseEvent *ev);
145
virtual void KeyPress(QKeyEvent *ev);
148
void EnsurePrimary();
151
friend class SelectCompare;
154
IpeOverlayServices *iServices;
155
bool iNonDestructive;
157
IpeVector iMouseDown;
159
IpePage::iterator iIt;
162
std::vector<SObj> iObjs;
170
// --------------------------------------------------------------------
172
class IpeTransforming : public IpeOverlay {
174
enum TType { EMove, EScale, EStretch, ERotate };
176
IpeTransforming(QMouseEvent *ev, IpePage *page, int view,
177
IpeCanvas *canvas, TType type,
178
IpeOverlayServices *services);
179
bool findObjects(int selectDistance);
180
bool checkOrigin() const;
183
virtual void Draw(QPaintEvent *ev, QPainter *painter) const;
184
virtual void MouseMove(QMouseEvent *ev);
185
virtual void MouseRelease(QMouseEvent *ev);
188
void Compute(const IpeVector &v);
189
bool UpdateCloseSelection(int selectDistance);
194
IpeOverlayServices *iServices;
197
bool iOnlyHorizontal;
199
IpeVector iMouseDown;
200
IpeMatrix iTransform;
204
// --------------------------------------------------------------------
206
class IpeOverlayFactory {
208
enum { ESelecting, EMoving, ERotating, EStretching, EPanning,
209
ELabel, EMath, EParagraph, EMark,
210
ERectangle, EPolyline, EPolygon,
212
ECircle1, ECircle2, ECircle3,
213
ESpline, ESplinegon, Num };
215
IpeOverlayFactory(QMouseEvent *ev, IpeCanvas *canvas,
216
IpePage *page, int view,
217
IpeOverlayServices *services);
218
void CreateOverlay(int index);
219
IpeOverlay *MakeOverlay(int index);
220
static const char *PixmapName(int index);
221
static QString Tooltip(int index);
222
static QString WhatsThis(int index);
223
static const char *Context(int index);
225
IpeOverlay *StartTransforming(IpeTransforming::TType type);
231
IpeOverlayServices *iServices;
234
// --------------------------------------------------------------------