1
// --------------------------------------------------------------------
2
// Overlay factory for object creators
3
// --------------------------------------------------------------------
6
This file is part of the extensible drawing editor Ipe.
7
Copyright (C) 1993-2007 Otfried Cheong
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.
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.
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.
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.
33
#include "ipecanvas.h"
34
#include "ipeoverlay.h"
35
#include "ipecreatepath.h"
36
#include "ipecreatearc.h"
37
#include "ipecreatetext.h"
39
#include <QMouseEvent>
41
// --------------------------------------------------------------------
43
static const char *strings[3 * IpeOverlayFactory::Num] = {
44
QT_TR_NOOP("Select objects (with Shift: non-destructively)"),
47
QT_TR_NOOP("Move objects (with Shift: horizontal/vertical)"),
50
QT_TR_NOOP("Rotate objects"),
53
QT_TR_NOOP("Stretch objects (with Shift: scale objects)"),
56
QT_TR_NOOP("Pan the canvas"),
59
QT_TR_NOOP("Text labels"),
62
QT_TR_NOOP("Mathematical symbols"),
63
"Mode|Mathematical symbols",
65
QT_TR_NOOP("Paragraphs"),
71
QT_TR_NOOP("Rectangles (with Shift: squares)"),
74
QT_TR_NOOP("Lines and polylines"),
77
QT_TR_NOOP("Polygons"),
80
QT_TR_NOOP("Circular arcs (by center, right and left point)"),
81
"Mode|Circular arcs (center, right, left)",
83
QT_TR_NOOP("Circular arcs (by center, left and right point)"),
84
"Mode|Circular arcs (center, left, right)",
86
QT_TR_NOOP("Circular arcs (by 3 points)"),
87
"Mode|Circular arcs (3 points)",
89
QT_TR_NOOP("Circles (by center and radius)"),
90
"Mode|Circles (center, radius)",
92
QT_TR_NOOP("Circles (by diameter)"),
93
"Mode|Circles (diameter)",
95
QT_TR_NOOP("Circles (by 3 points)"),
96
"Mode|Circles (3 points)",
98
QT_TR_NOOP("Splines"),
101
QT_TR_NOOP("Splinegons"),
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>");
112
// --------------------------------------------------------------------
114
/*! \class IpeOverlayFactory
115
\brief Creates the various overlays for creating objects.
118
IpeOverlayFactory::IpeOverlayFactory(QMouseEvent *ev, IpeCanvas *canvas,
119
IpePage *page, int view,
120
IpeOverlayServices *services)
121
: iEvent(ev), iCanvas(canvas), iPage(page), iView(view),
127
IpeOverlay *IpeOverlayFactory::StartTransforming(IpeTransforming::TType type)
129
IpeTransforming *t = new IpeTransforming(iEvent, iPage, iView, iCanvas,
131
if (!t->findObjects(iCanvas->SnapData().iSelectDistance)) {
133
iServices->OvSvcMessage(QObject::tr("No object selected"));
136
if (!t->checkOrigin()) {
138
iServices->OvSvcMessage(QObject::tr("Cannot start transformation in the origin"));
141
if (!t->checkPinned()) {
143
iServices->OvSvcMessage(QObject::tr("Cannot transform pinned objects"));
149
//! Create a new overlay for the canvas.
150
void IpeOverlayFactory::CreateOverlay(int index)
152
IpeOverlay *ov = MakeOverlay(index);
153
// mark and label modes perform action immediately,
154
// and return 0 for overlay
156
iCanvas->SetOverlay(ov);
159
//! Return appropriate object creator.
160
IpeOverlay *IpeOverlayFactory::MakeOverlay(int index)
164
return new IpeSelecting(iEvent, iPage, iView, iCanvas,
165
(iEvent->modifiers() & Qt::ShiftModifier),
166
iCanvas->SnapData().iSelectDistance,
169
return new IpePanning(iEvent, iPage, iCanvas);
171
return StartTransforming(IpeTransforming::EMove);
173
return StartTransforming(IpeTransforming::ERotate);
175
if (iEvent->modifiers() & Qt::ShiftModifier)
176
return StartTransforming(IpeTransforming::EScale);
178
return StartTransforming(IpeTransforming::EStretch);
180
return new IpeCreateRectangle(iEvent, iCanvas, iServices);
182
return new IpeCreatePath(iEvent, iCanvas, iServices, false, false);
184
return new IpeCreatePath(iEvent, iCanvas, iServices, true, false);
186
return new IpeCreatePath(iEvent, iCanvas, iServices, false, true);
188
return new IpeCreateSplinegon(iEvent, iCanvas, iServices);
190
return new IpeCreateCircle(iEvent, iCanvas, iServices,
191
IpeCreateCircle::ECenterRadius);
193
return new IpeCreateCircle(iEvent, iCanvas, iServices,
194
IpeCreateCircle::EDiameter);
196
return new IpeCreateCircle(iEvent, iCanvas, iServices,
197
IpeCreateCircle::E3Points);
199
return new IpeCreateArc(iEvent, iCanvas, iServices,
200
IpeCreateArc::ECenterRightLeft);
202
return new IpeCreateArc(iEvent, iCanvas, iServices,
203
IpeCreateArc::ECenterLeftRight);
205
return new IpeCreateArc(iEvent, iCanvas, iServices,
206
IpeCreateArc::E3Points);
208
IpeCreateText::New(iEvent, iCanvas, iServices, IpeCreateText::ELabel);
211
IpeCreateText::New(iEvent, iCanvas, iServices, IpeCreateText::EMath);
214
return new IpeCreateText(iEvent, iCanvas, iServices);
217
iServices->OvSvcAddObject
218
(new IpeMark(iServices->OvSvcAttributes(), iCanvas->Pos()));
227
const char *IpeOverlayFactory::PixmapName(int index)
229
return strings[3 * index + 2];
232
QString IpeOverlayFactory::Tooltip(int index)
234
return qApp->translate("IpeOverlayFactory", strings[3 * index + 0]);
237
const char *IpeOverlayFactory::Context(int index)
239
return strings[3 * index + 1];
242
QString IpeOverlayFactory::WhatsThis(int)
244
return qApp->translate("IpeOverlayFactory", whatsThisText);
247
// --------------------------------------------------------------------