~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/ipecanvas/ipeoverlay.h

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2009-12-11 21:22:35 UTC
  • mfrom: (4.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20091211212235-5iio4nzpra64snab
Tags: 7.0.10-1
* New upstream.  Closes: #551192.
  - New build-depends: libcairo2-dev, liblua5.1-0-dev, gsfonts
  - patches/config.diff: Remove.  Upstream build system replaced.
  - Runtime lib package changed to libipe7.0.10 from libipe1c2a
  - Devel package renamed to libipe-dev (from libipe1-dev)
  - Package ipe depends on lua5.1 due to ipe-update-master.

* rules: Re-write to use dh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- C++ -*-
2
 
// --------------------------------------------------------------------
3
 
// Overlay for the canvas --- shows moving objects etc.
4
 
// --------------------------------------------------------------------
5
 
/*
6
 
 
7
 
    This file is part of the extensible drawing editor Ipe.
8
 
    Copyright (C) 1993-2007  Otfried Cheong
9
 
 
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.
14
 
 
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.
19
 
 
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.
24
 
 
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.
29
 
 
30
 
*/
31
 
 
32
 
#ifndef IPEOVERLAY_H
33
 
#define IPEOVERLAY_H
34
 
 
35
 
#include "ipegeo.h"
36
 
#include "ipepainter.h"
37
 
#include "ipepage.h"
38
 
 
39
 
#include <QColor>
40
 
#include <QPainterPath>
41
 
 
42
 
// --------------------------------------------------------------------
43
 
 
44
 
class IpePage;
45
 
class IpeStyleSheet;
46
 
class IpeCanvas;
47
 
class IpeAllAttributes;
48
 
 
49
 
class QPainter;
50
 
class QMouseEvent;
51
 
class QPaintEvent;
52
 
class QKeyEvent;
53
 
 
54
 
class IpeOverlayPainter : public IpePainter {
55
 
public:
56
 
  IpeOverlayPainter(const IpeStyleSheet *sheet, QPainter *painter);
57
 
  virtual ~IpeOverlayPainter() { }
58
 
 
59
 
protected:
60
 
  virtual void DoMoveTo(const IpeVector &v);
61
 
  virtual void DoLineTo(const IpeVector &v);
62
 
  virtual void DoCurveTo(const IpeVector &v1, const IpeVector &v2,
63
 
                         const IpeVector &v3);
64
 
  virtual void DoClosePath();
65
 
 
66
 
  virtual void DoDrawPath();
67
 
  virtual void DoDrawBitmap(IpeBitmap bitmap);
68
 
  virtual void DoDrawText(const IpeText *text);
69
 
 
70
 
private:
71
 
  QPainter *iPainter;
72
 
  QPainterPath iPath;
73
 
};
74
 
 
75
 
// --------------------------------------------------------------------
76
 
 
77
 
/*! \class IpeOverlayServices
78
 
  \brief Interface for callbacks from the overlays.
79
 
 
80
 
  Provides services to (object-creating) overlays.
81
 
*/
82
 
 
83
 
class IpeOverlayServices {
84
 
public:
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;
93
 
};
94
 
 
95
 
// --------------------------------------------------------------------
96
 
 
97
 
class IpeOverlay {
98
 
public:
99
 
  virtual ~IpeOverlay();
100
 
 
101
 
  //! Redraw the current overlay.
102
 
  virtual void Draw(QPaintEvent *ev, QPainter *painter) const = 0;
103
 
 
104
 
  virtual void MousePress(QMouseEvent *ev);
105
 
  virtual void MouseRelease(QMouseEvent *ev);
106
 
  virtual void MouseMove(QMouseEvent *ev);
107
 
  virtual void KeyPress(QKeyEvent *ev);
108
 
 
109
 
  inline QColor CreateColor() const { return QColor("navy"); }
110
 
 
111
 
 protected:
112
 
  IpeOverlay(IpeCanvas *canvas);
113
 
 
114
 
 protected:
115
 
  IpeCanvas *iCanvas;
116
 
};
117
 
 
118
 
// --------------------------------------------------------------------
119
 
 
120
 
class IpePanning : public IpeOverlay {
121
 
 public:
122
 
  IpePanning(QMouseEvent *ev, const IpePage *page, IpeCanvas *canvas);
123
 
 
124
 
  virtual void Draw(QPaintEvent *ev, QPainter *painter) const;
125
 
  virtual void MouseRelease(QMouseEvent *ev);
126
 
  virtual void MouseMove(QMouseEvent *ev);
127
 
 
128
 
 private:
129
 
  const IpePage *iPage;
130
 
  IpeVector iMouseDown;
131
 
  IpeVector iPan;
132
 
};
133
 
 
134
 
// --------------------------------------------------------------------
135
 
 
136
 
class IpeSelecting : public IpeOverlay {
137
 
 public:
138
 
  IpeSelecting(QMouseEvent *ev, IpePage *page, int view, IpeCanvas *canvas,
139
 
               bool nonDestructive, int selectDistance,
140
 
               IpeOverlayServices *services);
141
 
 
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);
146
 
 
147
 
private:
148
 
  void EnsurePrimary();
149
 
 
150
 
private:
151
 
  friend class SelectCompare;
152
 
 
153
 
  IpePage *iPage;
154
 
  IpeOverlayServices *iServices;
155
 
  bool iNonDestructive;
156
 
  int iSelectDistance;
157
 
  IpeVector iMouseDown;
158
 
  struct SObj {
159
 
    IpePage::iterator iIt;
160
 
    double iDistance;
161
 
  };
162
 
  std::vector<SObj> iObjs;
163
 
  int iCur;
164
 
  int iView;
165
 
 
166
 
  bool iDragging;
167
 
  IpeVector iCorner;
168
 
};
169
 
 
170
 
// --------------------------------------------------------------------
171
 
 
172
 
class IpeTransforming : public IpeOverlay {
173
 
 public:
174
 
  enum TType { EMove, EScale, EStretch, ERotate };
175
 
 
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;
181
 
  bool checkPinned();
182
 
 
183
 
  virtual void Draw(QPaintEvent *ev, QPainter *painter) const;
184
 
  virtual void MouseMove(QMouseEvent *ev);
185
 
  virtual void MouseRelease(QMouseEvent *ev);
186
 
 
187
 
 private:
188
 
  void Compute(const IpeVector &v);
189
 
  bool UpdateCloseSelection(int selectDistance);
190
 
 
191
 
 private:
192
 
  IpePage *iPage;
193
 
  int iView;
194
 
  IpeOverlayServices *iServices;
195
 
  TType iType;
196
 
  bool iWithShift;
197
 
  bool iOnlyHorizontal;
198
 
  bool iOnlyVertical;
199
 
  IpeVector iMouseDown;
200
 
  IpeMatrix iTransform;
201
 
  IpeVector iOrigin;
202
 
};
203
 
 
204
 
// --------------------------------------------------------------------
205
 
 
206
 
class IpeOverlayFactory {
207
 
public:
208
 
  enum { ESelecting, EMoving, ERotating, EStretching, EPanning,
209
 
         ELabel, EMath, EParagraph, EMark,
210
 
         ERectangle, EPolyline, EPolygon,
211
 
         EArc1, EArc2, EArc3,
212
 
         ECircle1, ECircle2, ECircle3,
213
 
         ESpline, ESplinegon, Num };
214
 
 
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);
224
 
private:
225
 
  IpeOverlay *StartTransforming(IpeTransforming::TType type);
226
 
private:
227
 
  QMouseEvent *iEvent;
228
 
  IpeCanvas *iCanvas;
229
 
  IpePage *iPage;
230
 
  int iView;
231
 
  IpeOverlayServices *iServices;
232
 
};
233
 
 
234
 
// --------------------------------------------------------------------
235
 
#endif