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

« back to all changes in this revision

Viewing changes to src/ipe/appui.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
// AppUi
 
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 APPUI_H
 
33
#define APPUI_H
 
34
 
 
35
#include "ipebase.h"
 
36
#include "ipecolor.h"
 
37
#include "ipestyle.h"
 
38
#include "ipesnap.h"
 
39
#include "ipelet.h"
 
40
#include "ipeundo.h"
 
41
 
 
42
#include "ipepdfdoc.h"
 
43
#include "ipeprefs.h"
 
44
 
 
45
#include "ipecanvas.h"
 
46
#include "ipeoverlay.h"
 
47
 
 
48
#include "master.h"
 
49
 
 
50
#include <qmainwindow.h>
 
51
#include <qscrollview.h>
 
52
#include <qpixmap.h>
 
53
#include <qtoolbutton.h>
 
54
#include <qtranslator.h>
 
55
#include <qspinbox.h>
 
56
 
 
57
class IpePage;
 
58
class IpeSpinBox;
 
59
 
 
60
class QSpinBox;
 
61
class QToolBar;
 
62
class QPopupMenu;
 
63
class QComboBox;
 
64
class QTextBrowser;
 
65
class QListBox;
 
66
class QLineEdit;
 
67
class QWidgetStack;
 
68
class DecimalSpinBox;
 
69
class QPushButton;
 
70
class QColor;
 
71
class QAction;
 
72
class QActionGroup;
 
73
class QListBoxItem;
 
74
 
 
75
// --------------------------------------------------------------------
 
76
 
 
77
// in main.cpp
 
78
void StartManual(QString url);
 
79
 
 
80
class ZoomSpinBox : public QSpinBox {
 
81
  Q_OBJECT
 
82
public:
 
83
  ZoomSpinBox(QWidget *parent = 0);
 
84
public slots:
 
85
  virtual void stepUp();
 
86
  virtual void stepDown();
 
87
protected:
 
88
  bool eventFilter(QObject* obj, QEvent* ev);
 
89
};
 
90
 
 
91
// --------------------------------------------------------------------
 
92
 
 
93
class AppUi : public QMainWindow, public IpeCanvasServices,
 
94
              public IpeOverlayServices, public IpeletHelper {
 
95
  Q_OBJECT
 
96
 
 
97
public:
 
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,
 
103
                   ECmdRedo, ECmdEdit,
 
104
                   ECmdSetArrows, ECmdArrowSize, ECmdStroke, ECmdFill,
 
105
                   ECmdComposePaths, ECmdJoinPaths, ECmdDecomposePath,
 
106
                   ECmdHere, ECmdSetOrigin, ECmdResetOrigin,
 
107
                   ECmdSetOriginSnap, ECmdSetDirection, ECmdSetDirectionSnap,
 
108
                   ECmdSetLine, ECmdSetLineSnap,
 
109
                   ECmdMoveToLayer,
 
110
                   ECmdNewLayerNewView, ECmdNewView, ECmdDeleteView,
 
111
                   ECmdFirstView, ECmdLastView,
 
112
  };
 
113
 
 
114
public:
 
115
  AppUi(QWidget* parent=0, const char* name=0, WFlags f=0);
 
116
  ~AppUi();
 
117
 
 
118
  bool Load(QString fileName);
 
119
  bool Save(QString fname, bool warnOverwrite);
 
120
 
 
121
  static QPixmap ToPng(const IpePdfDocument *doc,
 
122
                       const IpePage *page, double zoom);
 
123
 
 
124
public slots:
 
125
  void Cmd(int cmd);
 
126
  void UndoCmd(int cmd);
 
127
  void SnapCmd(int cmd);
 
128
 
 
129
  void Cut();
 
130
  void Copy();
 
131
  void Paste();
 
132
 
 
133
  void NewWindow();
 
134
 
 
135
  void About();
 
136
  void AboutQt();
 
137
 
 
138
  void NewDoc();
 
139
  bool Save();
 
140
  bool SaveAs();
 
141
  void SaveAsBitmap();
 
142
  void SaveKeys();
 
143
  void Load();
 
144
 
 
145
  void EditObject();
 
146
  void EditDocProps();
 
147
  void EditPrefs();
 
148
  void Manual();
 
149
  void ShowDebugWindow();
 
150
  bool RunLatex(int);
 
151
 
 
152
  void NextView();
 
153
  void PreviousView();
 
154
  void EditViews();
 
155
 
 
156
  void CreatePage();
 
157
  void DeletePage();
 
158
  void CopyPage(int cut);
 
159
  void PastePage();
 
160
 
 
161
  void NormalSize();
 
162
  void DefaultZoom();
 
163
  void FitPage();
 
164
  void FitObjects();
 
165
  void FitSelection();
 
166
 
 
167
  void StyleSheets();
 
168
 
 
169
  void FirstPage();
 
170
  void LastPage();
 
171
 
 
172
  void SetCreator(QAction *action);
 
173
  void InsertTextBox();
 
174
  void InsertItemBox();
 
175
 
 
176
  void RunIpelet(int);
 
177
 
 
178
protected:
 
179
  void closeEvent(QCloseEvent *ev);
 
180
 
 
181
private slots:
 
182
  void AboutToShowEditMenu();
 
183
 
 
184
  void PageChanged(int);
 
185
  void PageChanged();
 
186
  void ViewChanged(int);
 
187
  void ViewChanged();
 
188
  void ResolutionChanged(int);
 
189
  void AbsoluteAttributes();
 
190
  void AbsoluteSnapping();
 
191
  void HideLayersNotInView();
 
192
 
 
193
  void SetStrokeColor();
 
194
  void SetFillColor();
 
195
  void SetStrokeColorName(int item);
 
196
  void SetFillColorName(int item);
 
197
 
 
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);
 
213
 
 
214
  void SnapChanged(bool);
 
215
  void GridVisible();
 
216
  void LayerRightPress(QListBoxItem *item, const QPoint &);
 
217
  void LayerSelectionChanged();
 
218
 
 
219
  void PreferencesChanged();
 
220
 
 
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);
 
229
 
 
230
 
 
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);
 
238
 
 
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;
 
252
 
 
253
private:
 
254
#if QT_VERSION >= 300
 
255
  QKeySequence Key(const char *src, const char *comment);
 
256
#else
 
257
  int Key(const char *src, const char *comment);
 
258
#endif
 
259
  inline IpePage *Page() { return (*iDoc)[iPno]; }
 
260
  void FitBox(const IpeRect &box);
 
261
  void UpdateLayers();
 
262
  void SetGridSizeFromPage();
 
263
  void SwitchAttributeUi();
 
264
  void SwitchSnapUi();
 
265
  void SetCaption();
 
266
  void ShowStyleInUi();
 
267
  void AddUndo(IpeUndoItem *item);
 
268
  IpeAttribute PageColor();
 
269
 
 
270
  void ErrMsg(QString str);
 
271
 
 
272
  IpePage *NewPage();
 
273
 
 
274
  double AbsValue(IpeAttribute attr);
 
275
  void ConvertAbsolute(DecimalSpinBox *spin, IpeAttribute &attr);
 
276
 
 
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);
 
282
 
 
283
  virtual void keyPressEvent(QKeyEvent *ev);
 
284
 
 
285
private:
 
286
  enum TMenuIds { EZoomMenuId = 1000, ESnapMenuId, EAbsoluteAttributesMenuId,
 
287
                  EAbsoluteSnappingMenuId, EGridVisibleMenuId,
 
288
                  EHideLayersMenuId };
 
289
 
 
290
  // UI components
 
291
  IpeCanvas *iCanvas;
 
292
 
 
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;
 
302
 
 
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;
 
312
 
 
313
  QWidgetStack *iStrokeColorStack;
 
314
  QWidgetStack *iFillColorStack;
 
315
  QWidgetStack *iLineWidthStack;
 
316
  QWidgetStack *iArrowSizeStack;
 
317
  QWidgetStack *iTextSizeStack;
 
318
  QWidgetStack *iMarkSizeStack;
 
319
  QWidgetStack *iGridSizeStack;
 
320
  QWidgetStack *iAngleSizeStack;
 
321
 
 
322
  QSpinBox *iResolution;
 
323
 
 
324
  IpeSpinBox *iPageNumber;
 
325
  IpeSpinBox *iViewNumber;
 
326
 
 
327
  QComboBox *iStrokeColor;
 
328
  QPushButton *iAbsStrokeColor;
 
329
  QComboBox *iFillColor;
 
330
  QPushButton *iAbsFillColor;
 
331
 
 
332
  QComboBox *iLineWidth;
 
333
  DecimalSpinBox *iAbsLineWidth;
 
334
  QComboBox *iDashStyle;
 
335
  QComboBox *iArrow;
 
336
  QComboBox *iArrowSize;
 
337
  DecimalSpinBox *iAbsArrowSize;
 
338
 
 
339
  QActionGroup *iModeActionGroup;
 
340
  QAction *iModeAction[IpeOverlayFactory::Num];
 
341
  QComboBox *iMarkShape;
 
342
  QComboBox *iMarkSize;
 
343
  DecimalSpinBox *iAbsMarkSize;
 
344
  QComboBox *iTextSize;
 
345
  DecimalSpinBox *iAbsTextSize;
 
346
 
 
347
  QActionGroup *iSnapActionGroup;
 
348
  QAction *iSnapAction[6];
 
349
  QComboBox *iGridSize;
 
350
  DecimalSpinBox *iAbsGridSize;
 
351
  QComboBox *iAngleSize;
 
352
  DecimalSpinBox *iAbsAngleSize;
 
353
 
 
354
  QListBox *iLayerList;
 
355
 
 
356
  int iPasteBitmapId;
 
357
 
 
358
  //! The most recently used file format on saving
 
359
  QString iSaveFilter;
 
360
 
 
361
  // Information about the document
 
362
 
 
363
  //! The document's filename (null if not yet saved).
 
364
  QString iFileName;
 
365
  //! The document.
 
366
  IpePdfDocument *iDoc;
 
367
  //! The currently displayed page no.
 
368
  int iPno;
 
369
  //! The current view.
 
370
  int iVno;
 
371
  //! The current layer.
 
372
  int iLayer;
 
373
  //! Whether latex needs to be run.
 
374
  bool iNeedLatex;
 
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.
 
380
  bool iHideLayers;
 
381
  //! The attributes set in the UI.
 
382
  IpeAllAttributes iAttributes;
 
383
  //! Snapping state
 
384
  IpeSnapData iSnapData;
 
385
  //! Current Ipe mode.
 
386
  int iMode;
 
387
  //! All symbolic attributes in style sheet
 
388
  IpeAttributeSeq iSyms[IpeAttribute::ETemplate + 1];
 
389
 
 
390
  //! Undo stack
 
391
  IpeUndoStack iUndo;
 
392
  // Ipelets
 
393
  //! Ipelet repository
 
394
  IpeletMaster iIpeletMaster;
 
395
  bool iIpeletNoUndo;
 
396
 
 
397
  //! Configurable key sequences
 
398
  QTranslator iKeyTranslator;
 
399
};
 
400
 
 
401
// --------------------------------------------------------------------
 
402
#endif