2
// --------------------------------------------------------------------
4
// --------------------------------------------------------------------
7
This file is part of the extensible drawing editor Ipe.
8
Copyright (C) 1993-2004 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.
42
#include "ipepdfdoc.h"
45
#include "ipecanvas.h"
46
#include "ipeoverlay.h"
50
#include <qmainwindow.h>
51
#include <qscrollview.h>
53
#include <qtoolbutton.h>
54
#include <qtranslator.h>
75
// --------------------------------------------------------------------
78
void StartManual(QString url);
80
class ZoomSpinBox : public QSpinBox {
83
ZoomSpinBox(QWidget *parent = 0);
85
virtual void stepUp();
86
virtual void stepDown();
88
bool eventFilter(QObject* obj, QEvent* ev);
91
// --------------------------------------------------------------------
93
class AppUi : public QMainWindow, public IpeCanvasServices,
94
public IpeOverlayServices, public IpeletHelper {
98
enum TCommands { ECmdGroup, ECmdUngroup, ECmdDuplicate, ECmdFront, ECmdBack,
99
ECmdCut, ECmdCopy, ECmdPaste, ECmdDelete, ECmdSelectAll,
100
ECmdNewLayer, ECmdRenameLayer,
101
ECmdSelectLayer, ECmdLineWidth, ECmdDashStyle,
102
ECmdTextSize, ECmdMarkShape, ECmdMarkSize, ECmdUndo,
104
ECmdSetArrows, ECmdArrowSize, ECmdStroke, ECmdFill,
105
ECmdComposePaths, ECmdJoinPaths, ECmdDecomposePath,
106
ECmdHere, ECmdSetOrigin, ECmdResetOrigin,
107
ECmdSetOriginSnap, ECmdSetDirection, ECmdSetDirectionSnap,
108
ECmdSetLine, ECmdSetLineSnap,
110
ECmdNewLayerNewView, ECmdNewView, ECmdDeleteView,
111
ECmdFirstView, ECmdLastView,
115
AppUi(QWidget* parent=0, const char* name=0, WFlags f=0);
118
bool Load(QString fileName);
119
bool Save(QString fname, bool warnOverwrite);
121
static QPixmap ToPng(const IpePdfDocument *doc,
122
const IpePage *page, double zoom);
126
void UndoCmd(int cmd);
127
void SnapCmd(int cmd);
149
void ShowDebugWindow();
158
void CopyPage(int cut);
172
void SetCreator(QAction *action);
173
void InsertTextBox();
174
void InsertItemBox();
179
void closeEvent(QCloseEvent *ev);
182
void AboutToShowEditMenu();
184
void PageChanged(int);
186
void ViewChanged(int);
188
void ResolutionChanged(int);
189
void AbsoluteAttributes();
190
void AbsoluteSnapping();
191
void HideLayersNotInView();
193
void SetStrokeColor();
195
void SetStrokeColorName(int item);
196
void SetFillColorName(int item);
198
void LineWidthChanged(int id);
199
void AbsLineWidthChanged(int val);
200
void DashStyleChanged(int id);
201
void TextSizeChanged(int id);
202
void AbsTextSizeChanged(int val);
203
void MarkShapeChanged(int id);
204
void MarkSizeChanged(int id);
205
void AbsMarkSizeChanged(int val);
206
void ArrowSizeChanged(int id);
207
void AbsArrowSizeChanged(int val);
208
void ArrowChanged(int id);
209
void GridSizeChanged(int id);
210
void AbsGridSizeChanged(int val);
211
void AngleSizeChanged(int id);
212
void AbsAngleSizeChanged(int val);
214
void SnapChanged(bool);
216
void LayerRightPress(QListBoxItem *item, const QPoint &);
217
void LayerSelectionChanged();
219
void PreferencesChanged();
221
private: // from IpeCanvasServices
222
virtual void CvSvcRequestOverlay(QMouseEvent *ev);
223
virtual void CvSvcSetDrawingMode(bool mode);
224
virtual void CvSvcWheelZoom(int delta);
225
virtual void CvSvcSetRenderData(IpeBitmap &bitmap);
226
virtual void CvSvcRenderCharacter(QPixmap *pixmap, int fontObject,
227
const IpeMatrix &m, const IpeVector &pos,
228
QRgb cRgb, uint charCode, uint uniCode);
231
private: // from IpeOverlayServices
232
virtual void OvSvcAddObject(IpeObject *obj);
233
virtual const IpeAllAttributes &OvSvcAttributes();
234
virtual const IpeStyleSheet *OvSvcStyleSheet();
235
virtual void OvSvcAddUndoItem(IpePage *page, QString s);
236
virtual void OvSvcAddUndoItem(IpePage::iterator it, IpePage *page,
237
const IpePgObject &original, QString s);
239
private: // from IpeletHelper
240
virtual void Message(const char *msg);
241
virtual int MessageBox(const char *text, const char *button1,
242
const char *button2, const char *button3);
243
virtual bool GetString(const char *prompt, IpeString &str);
244
virtual const IpeStyleSheet *StyleSheet();
245
virtual const IpeDocument *Document();
246
virtual IpeDocument *EditDocument();
247
virtual int CurrentPage() const;
248
virtual int CurrentView() const;
249
virtual int CurrentLayer() const;
250
virtual const IpeSnapData &SnapData() const;
251
virtual const IpeAllAttributes &Attributes() const;
254
#if QT_VERSION >= 300
255
QKeySequence Key(const char *src, const char *comment);
257
int Key(const char *src, const char *comment);
259
inline IpePage *Page() { return (*iDoc)[iPno]; }
260
void FitBox(const IpeRect &box);
262
void SetGridSizeFromPage();
263
void SwitchAttributeUi();
266
void ShowStyleInUi();
267
void AddUndo(IpeUndoItem *item);
268
IpeAttribute PageColor();
270
void ErrMsg(QString str);
274
double AbsValue(IpeAttribute attr);
275
void ConvertAbsolute(DecimalSpinBox *spin, IpeAttribute &attr);
277
void ResetCombo(IpeKind kind, QComboBox *combo,
278
IpeAttribute &attr, QPixmap *pixmap = 0);
279
void InsertColor(QComboBox *combo, IpeAttribute sym);
280
void SetColorFromQColor(IpeAttribute &colorToSet, QColor &qColor,
281
QPushButton *button);
283
virtual void keyPressEvent(QKeyEvent *ev);
286
enum TMenuIds { EZoomMenuId = 1000, ESnapMenuId, EAbsoluteAttributesMenuId,
287
EAbsoluteSnappingMenuId, EGridVisibleMenuId,
293
QPopupMenu *iFileMenu;
294
QPopupMenu *iEditMenu;
295
QPopupMenu *iSnapMenu;
296
QPopupMenu *iModeMenu;
297
QPopupMenu *iZoomMenu;
298
QPopupMenu *iLayerMenu;
299
QPopupMenu *iViewMenu;
300
QPopupMenu *iPageMenu;
301
QPopupMenu *iIpeletMenu;
303
QToolBar *iFileTools;
304
QToolBar *iResolutionTools;
305
QToolBar *iObjectTools;
306
QToolBar *iPageTools;
307
QToolBar *iLineTools;
308
QToolBar *iSizeTools;
309
QToolBar *iColorTools;
310
QToolBar *iSnapTools;
311
QToolBar *iLayerTools;
313
QWidgetStack *iStrokeColorStack;
314
QWidgetStack *iFillColorStack;
315
QWidgetStack *iLineWidthStack;
316
QWidgetStack *iArrowSizeStack;
317
QWidgetStack *iTextSizeStack;
318
QWidgetStack *iMarkSizeStack;
319
QWidgetStack *iGridSizeStack;
320
QWidgetStack *iAngleSizeStack;
322
QSpinBox *iResolution;
324
IpeSpinBox *iPageNumber;
325
IpeSpinBox *iViewNumber;
327
QComboBox *iStrokeColor;
328
QPushButton *iAbsStrokeColor;
329
QComboBox *iFillColor;
330
QPushButton *iAbsFillColor;
332
QComboBox *iLineWidth;
333
DecimalSpinBox *iAbsLineWidth;
334
QComboBox *iDashStyle;
336
QComboBox *iArrowSize;
337
DecimalSpinBox *iAbsArrowSize;
339
QActionGroup *iModeActionGroup;
340
QAction *iModeAction[IpeOverlayFactory::Num];
341
QComboBox *iMarkShape;
342
QComboBox *iMarkSize;
343
DecimalSpinBox *iAbsMarkSize;
344
QComboBox *iTextSize;
345
DecimalSpinBox *iAbsTextSize;
347
QActionGroup *iSnapActionGroup;
348
QAction *iSnapAction[6];
349
QComboBox *iGridSize;
350
DecimalSpinBox *iAbsGridSize;
351
QComboBox *iAngleSize;
352
DecimalSpinBox *iAbsAngleSize;
354
QListBox *iLayerList;
358
//! The most recently used file format on saving
361
// Information about the document
363
//! The document's filename (null if not yet saved).
366
IpePdfDocument *iDoc;
367
//! The currently displayed page no.
369
//! The current view.
371
//! The current layer.
373
//! Whether latex needs to be run.
375
//! Displaying attributes absolute (or symbolic)
376
bool iAbsoluteAttributes;
377
//! Displaying absolute snap sizes.
378
bool iAbsoluteSnapping;
379
//! Hide layers that are not in the current view.
381
//! The attributes set in the UI.
382
IpeAllAttributes iAttributes;
384
IpeSnapData iSnapData;
385
//! Current Ipe mode.
387
//! All symbolic attributes in style sheet
388
IpeAttributeSeq iSyms[IpeAttribute::ETemplate + 1];
393
//! Ipelet repository
394
IpeletMaster iIpeletMaster;
397
//! Configurable key sequences
398
QTranslator iKeyTranslator;
401
// --------------------------------------------------------------------