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

« back to all changes in this revision

Viewing changes to src/ipecanvas/ipecreators.cpp

  • 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
 
// --------------------------------------------------------------------
2
 
// Overlay factory for object creators
3
 
// --------------------------------------------------------------------
4
 
/*
5
 
 
6
 
    This file is part of the extensible drawing editor Ipe.
7
 
    Copyright (C) 1993-2007  Otfried Cheong
8
 
 
9
 
    Ipe is free software; you can redistribute it and/or modify it
10
 
    under the terms of the GNU General Public License as published by
11
 
    the Free Software Foundation; either version 2 of the License, or
12
 
    (at your option) any later version.
13
 
 
14
 
    As a special exception, you have permission to link Ipe with the
15
 
    CGAL library and distribute executables, as long as you follow the
16
 
    requirements of the Gnu General Public License in regard to all of
17
 
    the software in the executable aside from CGAL.
18
 
 
19
 
    Ipe is distributed in the hope that it will be useful, but WITHOUT
20
 
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21
 
    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
22
 
    License for more details.
23
 
 
24
 
    You should have received a copy of the GNU General Public License
25
 
    along with Ipe; if not, you can find it at
26
 
    "http://www.gnu.org/copyleft/gpl.html", or write to the Free
27
 
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28
 
 
29
 
*/
30
 
 
31
 
#include "ipemark.h"
32
 
 
33
 
#include "ipecanvas.h"
34
 
#include "ipeoverlay.h"
35
 
#include "ipecreatepath.h"
36
 
#include "ipecreatearc.h"
37
 
#include "ipecreatetext.h"
38
 
 
39
 
#include <QMouseEvent>
40
 
 
41
 
// --------------------------------------------------------------------
42
 
 
43
 
static const char *strings[3 * IpeOverlayFactory::Num] = {
44
 
  QT_TR_NOOP("Select objects (with Shift: non-destructively)"),
45
 
  "Mode|Select",
46
 
  "select",
47
 
  QT_TR_NOOP("Move objects (with Shift: horizontal/vertical)"),
48
 
  "Mode|Move",
49
 
  "move",
50
 
  QT_TR_NOOP("Rotate objects"),
51
 
  "Mode|Rotate",
52
 
  "rotate",
53
 
  QT_TR_NOOP("Stretch objects (with Shift: scale objects)"),
54
 
  "Mode|Stretch",
55
 
  "stretch",
56
 
  QT_TR_NOOP("Pan the canvas"),
57
 
  "Mode|Pan",
58
 
  "pan",
59
 
  QT_TR_NOOP("Text labels"),
60
 
  "Mode|Text labels",
61
 
  "label",
62
 
  QT_TR_NOOP("Mathematical symbols"),
63
 
  "Mode|Mathematical symbols",
64
 
  "math",
65
 
  QT_TR_NOOP("Paragraphs"),
66
 
  "Mode|Paragraphs",
67
 
  "paragraph",
68
 
  QT_TR_NOOP("Marks"),
69
 
  "Mode|Marks",
70
 
  "marks",
71
 
  QT_TR_NOOP("Rectangles (with Shift: squares)"),
72
 
  "Mode|Rectangles",
73
 
  "rectangles",
74
 
  QT_TR_NOOP("Lines and polylines"),
75
 
  "Mode|Lines",
76
 
  "lines",
77
 
  QT_TR_NOOP("Polygons"),
78
 
  "Mode|Polygons",
79
 
  "polygons",
80
 
  QT_TR_NOOP("Circular arcs (by center, right and left point)"),
81
 
  "Mode|Circular arcs (center, right, left)",
82
 
  "arc1",
83
 
  QT_TR_NOOP("Circular arcs (by center, left and right point)"),
84
 
  "Mode|Circular arcs (center, left, right)",
85
 
  "arc2",
86
 
  QT_TR_NOOP("Circular arcs (by 3 points)"),
87
 
  "Mode|Circular arcs (3 points)",
88
 
  "arc3",
89
 
  QT_TR_NOOP("Circles (by center and radius)"),
90
 
  "Mode|Circles (center, radius)",
91
 
  "circle1",
92
 
  QT_TR_NOOP("Circles (by diameter)"),
93
 
  "Mode|Circles (diameter)",
94
 
  "circle2",
95
 
  QT_TR_NOOP("Circles (by 3 points)"),
96
 
  "Mode|Circles (3 points)",
97
 
  "circle3",
98
 
  QT_TR_NOOP("Splines"),
99
 
  "Mode|Splines",
100
 
  "splines",
101
 
  QT_TR_NOOP("Splinegons"),
102
 
  "Mode|Splinegons",
103
 
  "splinegons" };
104
 
 
105
 
const char *whatsThisText = QT_TR_NOOP(
106
 
"<qt>With these buttons you select the current Ipe <em>mode</em>. "
107
 
"The current mode determines the function of the left mouse button. "
108
 
"<p>The leftmost five buttons set modes for selecting and transforming "
109
 
"objects.  The remaining buttons set modes for creating various kinds "
110
 
"of objects.</p></qt>");
111
 
 
112
 
// --------------------------------------------------------------------
113
 
 
114
 
/*! \class IpeOverlayFactory
115
 
  \brief Creates the various overlays for creating objects.
116
 
*/
117
 
 
118
 
IpeOverlayFactory::IpeOverlayFactory(QMouseEvent *ev, IpeCanvas *canvas,
119
 
                                     IpePage *page, int view,
120
 
                                     IpeOverlayServices *services)
121
 
  : iEvent(ev), iCanvas(canvas), iPage(page), iView(view),
122
 
    iServices(services)
123
 
{
124
 
  // nothing
125
 
}
126
 
 
127
 
IpeOverlay *IpeOverlayFactory::StartTransforming(IpeTransforming::TType type)
128
 
{
129
 
  IpeTransforming *t = new IpeTransforming(iEvent, iPage, iView, iCanvas,
130
 
                                           type, iServices);
131
 
  if (!t->findObjects(iCanvas->SnapData().iSelectDistance)) {
132
 
    delete t;
133
 
    iServices->OvSvcMessage(QObject::tr("No object selected"));
134
 
    return 0;
135
 
  }
136
 
  if (!t->checkOrigin()) {
137
 
    delete t;
138
 
    iServices->OvSvcMessage(QObject::tr("Cannot start transformation in the origin"));
139
 
    return 0;
140
 
  }
141
 
  if (!t->checkPinned()) {
142
 
    delete t;
143
 
    iServices->OvSvcMessage(QObject::tr("Cannot transform pinned objects"));
144
 
    return 0;
145
 
  }
146
 
  return t;
147
 
}
148
 
 
149
 
//! Create a new overlay for the canvas.
150
 
void IpeOverlayFactory::CreateOverlay(int index)
151
 
{
152
 
  IpeOverlay *ov = MakeOverlay(index);
153
 
  // mark and label modes perform action immediately,
154
 
  // and return 0 for overlay
155
 
  if (ov)
156
 
    iCanvas->SetOverlay(ov);
157
 
}
158
 
 
159
 
//! Return appropriate object creator.
160
 
IpeOverlay *IpeOverlayFactory::MakeOverlay(int index)
161
 
{
162
 
  switch (index) {
163
 
  case ESelecting:
164
 
    return new IpeSelecting(iEvent, iPage, iView, iCanvas,
165
 
                            (iEvent->modifiers() & Qt::ShiftModifier),
166
 
                            iCanvas->SnapData().iSelectDistance,
167
 
                            iServices);
168
 
  case EPanning:
169
 
    return new IpePanning(iEvent, iPage, iCanvas);
170
 
  case EMoving:
171
 
    return StartTransforming(IpeTransforming::EMove);
172
 
  case ERotating:
173
 
    return StartTransforming(IpeTransforming::ERotate);
174
 
  case EStretching:
175
 
    if (iEvent->modifiers() & Qt::ShiftModifier)
176
 
      return StartTransforming(IpeTransforming::EScale);
177
 
    else
178
 
      return StartTransforming(IpeTransforming::EStretch);
179
 
  case ERectangle:
180
 
    return new IpeCreateRectangle(iEvent, iCanvas, iServices);
181
 
  case EPolyline:
182
 
    return new IpeCreatePath(iEvent, iCanvas, iServices, false, false);
183
 
  case EPolygon:
184
 
    return new IpeCreatePath(iEvent, iCanvas, iServices, true, false);
185
 
  case ESpline:
186
 
    return new IpeCreatePath(iEvent, iCanvas, iServices, false, true);
187
 
  case ESplinegon:
188
 
    return new IpeCreateSplinegon(iEvent, iCanvas, iServices);
189
 
  case ECircle1:
190
 
    return new IpeCreateCircle(iEvent, iCanvas, iServices,
191
 
                               IpeCreateCircle::ECenterRadius);
192
 
  case ECircle2:
193
 
    return new IpeCreateCircle(iEvent, iCanvas, iServices,
194
 
                               IpeCreateCircle::EDiameter);
195
 
  case ECircle3:
196
 
    return new IpeCreateCircle(iEvent, iCanvas, iServices,
197
 
                               IpeCreateCircle::E3Points);
198
 
  case EArc1:
199
 
    return new IpeCreateArc(iEvent, iCanvas, iServices,
200
 
                            IpeCreateArc::ECenterRightLeft);
201
 
  case EArc2:
202
 
    return new IpeCreateArc(iEvent, iCanvas, iServices,
203
 
                            IpeCreateArc::ECenterLeftRight);
204
 
  case EArc3:
205
 
    return new IpeCreateArc(iEvent, iCanvas, iServices,
206
 
                            IpeCreateArc::E3Points);
207
 
  case ELabel:
208
 
    IpeCreateText::New(iEvent, iCanvas, iServices, IpeCreateText::ELabel);
209
 
    return 0;
210
 
  case EMath:
211
 
    IpeCreateText::New(iEvent, iCanvas, iServices, IpeCreateText::EMath);
212
 
    return 0;
213
 
  case EParagraph:
214
 
    return new IpeCreateText(iEvent, iCanvas, iServices);
215
 
  case EMark:
216
 
    {
217
 
      iServices->OvSvcAddObject
218
 
        (new IpeMark(iServices->OvSvcAttributes(), iCanvas->Pos()));
219
 
      iCanvas->Update();
220
 
      return 0;
221
 
    }
222
 
  default:
223
 
    return 0;
224
 
  }
225
 
}
226
 
 
227
 
const char *IpeOverlayFactory::PixmapName(int index)
228
 
{
229
 
  return strings[3 * index + 2];
230
 
}
231
 
 
232
 
QString IpeOverlayFactory::Tooltip(int index)
233
 
{
234
 
  return qApp->translate("IpeOverlayFactory", strings[3 * index + 0]);
235
 
}
236
 
 
237
 
const char *IpeOverlayFactory::Context(int index)
238
 
{
239
 
  return strings[3 * index + 1];
240
 
}
241
 
 
242
 
QString IpeOverlayFactory::WhatsThis(int)
243
 
{
244
 
  return qApp->translate("IpeOverlayFactory", whatsThisText);
245
 
}
246
 
 
247
 
// --------------------------------------------------------------------