~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: 2004-06-08 00:44:02 UTC
  • Revision ID: james.westby@ubuntu.com-20040608004402-72yu51xlh7vt6p9m
Tags: upstream-6.0pre16
ImportĀ upstreamĀ versionĀ 6.0pre16

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-2004  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 <qpoint.h>
 
40
#include <qcolor.h>
 
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
  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,
 
63
                       const IpeVector &v3);
 
64
  virtual void EndPath();
 
65
  virtual void EndClosedPath();
 
66
 
 
67
  virtual void DrawBitmap(IpeBitmap bitmap);
 
68
  virtual void DrawText(const IpeText *text);
 
69
 
 
70
private:
 
71
  QPainter *iPainter;
 
72
  QPoint iPathBegin;
 
73
  QPoint iPos;
 
74
};
 
75
 
 
76
// --------------------------------------------------------------------
 
77
 
 
78
/*! \class IpeOverlayServices
 
79
  \brief Interface for callbacks from the overlays.
 
80
 
 
81
  Provides services to (object-creating) overlays.
 
82
*/
 
83
 
 
84
class IpeOverlayServices {
 
85
public:
 
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
};
 
93
 
 
94
// --------------------------------------------------------------------
 
95
 
 
96
class IpeOverlay {
 
97
public:
 
98
  virtual ~IpeOverlay();
 
99
 
 
100
  //! Redraw the current overlay.
 
101
  virtual void Draw(QPaintEvent *ev, QPainter *painter) const = 0;
 
102
 
 
103
  virtual void MousePress(QMouseEvent *ev);
 
104
  virtual void MouseRelease(QMouseEvent *ev);
 
105
  virtual void MouseMove(QMouseEvent *ev);
 
106
  virtual void KeyPress(QKeyEvent *ev);
 
107
 
 
108
  inline QColor CreateColor() const { return QColor("navy"); }
 
109
 
 
110
 protected:
 
111
  IpeOverlay(IpeCanvas *canvas);
 
112
 
 
113
 protected:
 
114
  IpeCanvas *iCanvas;
 
115
};
 
116
 
 
117
// --------------------------------------------------------------------
 
118
 
 
119
class IpePanning : public IpeOverlay {
 
120
 public:
 
121
  IpePanning(QMouseEvent *ev, const IpePage *page, IpeCanvas *canvas);
 
122
 
 
123
  virtual void Draw(QPaintEvent *ev, QPainter *painter) const;
 
124
  virtual void MouseRelease(QMouseEvent *ev);
 
125
  virtual void MouseMove(QMouseEvent *ev);
 
126
 
 
127
 private:
 
128
  const IpePage *iPage;
 
129
  IpeVector iMouseDown;
 
130
  IpeVector iPan;
 
131
};
 
132
 
 
133
// --------------------------------------------------------------------
 
134
 
 
135
class IpeSelecting : public IpeOverlay {
 
136
 public:
 
137
  IpeSelecting(QMouseEvent *ev, IpePage *page, IpeCanvas *canvas,
 
138
               bool nonDestructive, int selectDistance, int view,
 
139
               IpeOverlayServices *services);
 
140
 
 
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);
 
145
 
 
146
private:
 
147
  void EnsurePrimary();
 
148
 
 
149
private:
 
150
  friend class SelectCompare;
 
151
 
 
152
  IpePage *iPage;
 
153
  IpeOverlayServices *iServices;
 
154
  bool iNonDestructive;
 
155
  int iSelectDistance;
 
156
  IpeVector iMouseDown;
 
157
  struct SObj {
 
158
    IpePage::iterator iIt;
 
159
    double iDistance;
 
160
  };
 
161
  std::vector<SObj> iObjs;
 
162
  int iCur;
 
163
 
 
164
  bool iDragging;
 
165
  IpeVector iCorner;
 
166
};
 
167
 
 
168
// --------------------------------------------------------------------
 
169
 
 
170
class IpeTransforming : public IpeOverlay {
 
171
 public:
 
172
  enum TType { EMove, EScale, EStretch, ERotate };
 
173
 
 
174
  IpeTransforming(QMouseEvent *ev, IpePage *page,
 
175
                  IpeCanvas *canvas, TType type,
 
176
                  IpeOverlayServices *services);
 
177
  bool FindObjects(int selectDistance);
 
178
 
 
179
  virtual void Draw(QPaintEvent *ev, QPainter *painter) const;
 
180
  virtual void MouseMove(QMouseEvent *ev);
 
181
  virtual void MouseRelease(QMouseEvent *ev);
 
182
 
 
183
 private:
 
184
  void Compute(const IpeVector &v);
 
185
  bool UpdateCloseSelection(int selectDistance);
 
186
 
 
187
 private:
 
188
  IpePage *iPage;
 
189
  IpeOverlayServices *iServices;
 
190
  TType iType;
 
191
  bool iWithShift;
 
192
  IpeVector iMouseDown;
 
193
  IpeMatrix iTransform;
 
194
  IpeVector iOrigin;
 
195
};
 
196
 
 
197
// --------------------------------------------------------------------
 
198
 
 
199
class IpeOverlayFactory {
 
200
public:
 
201
  enum { ESelecting, EMoving, ERotating, EStretching, EPanning,
 
202
         ELabel, EMath, EParagraph, EMark,
 
203
         ERectangle, EPolyline, EPolygon,
 
204
         EArc1, EArc2, EArc3,
 
205
         ECircle1, ECircle2, ECircle3,
 
206
         ESpline, ESplinegon, Num };
 
207
 
 
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);
 
218
private:
 
219
  IpeOverlay *StartTransforming(IpeTransforming::TType type);
 
220
private:
 
221
  QMouseEvent *iEvent;
 
222
  IpeCanvas *iCanvas;
 
223
  IpePage *iPage;
 
224
  int iView;
 
225
  IpeOverlayServices *iServices;
 
226
};
 
227
 
 
228
// --------------------------------------------------------------------
 
229
#endif