1 // -*- C++ -*-
2 // --------------------------------------------------------------------
3 // Appui for QT
4 // --------------------------------------------------------------------
5 /*
6 
7     This file is part of the extensible drawing editor Ipe.
8     Copyright (c) 1993-2020 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 3 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_QT_H
33 #define APPUI_QT_H
34 
35 #include "appui.h"
36 
37 #include <QApplication>
38 #include <QMainWindow>
39 #include <QAction>
40 #include <QCheckBox>
41 #include <QToolBar>
42 #include <QDockWidget>
43 #include <QActionGroup>
44 #include <QListWidget>
45 #include <QLabel>
46 #include <QComboBox>
47 #include <QToolButton>
48 #include <QTextEdit>
49 
50 using namespace ipe;
51 
52 // --------------------------------------------------------------------
53 
54 class PathView;
55 class LayerBox;
56 class QSignalMapper;
57 
58 // --------------------------------------------------------------------
59 
60 class AppUi : public QMainWindow, public AppUiBase {
61   Q_OBJECT
62 
63 public:
64   AppUi(lua_State *L0, int model, Qt::WindowFlags f=nullptr);
65   ~AppUi();
66 
67   QAction *findAction(const char *name) const;
68 
69   virtual void setLayers(const Page *page, int view) override;
70 
71   virtual void setZoom(double zoom) override;
72   virtual void setActionsEnabled(bool mode) override;
73   virtual void setNumbers(String vno, bool vm, String pno, bool pm) override;
74   virtual void setNotes(String notes) override;
75 
76   virtual WINID windowId() override;
77   virtual void closeWindow() override;
78   virtual bool actionState(const char *name) override;
79   virtual void setActionState(const char *name, bool value) override;
80   virtual void setWindowCaption(bool mod, const char *s) override;
81   virtual void explain(const char *s, int t) override;
82   virtual void showWindow(int width, int height, int x, int y) override;
83   virtual void setFullScreen(int mode) override;
84   virtual void setBookmarks(int no, const String *s) override;
85   virtual void setToolVisible(int m, bool vis) override;
86   virtual int pageSorter(lua_State *L, Document *doc, int pno,
87 			 int width, int height, int thumbWidth) override;
88   virtual int clipboard(lua_State *L) override;
89   virtual int setClipboard(lua_State *L) override;
90 
91   virtual void setRecentFileMenu(const std::vector<String> & names) override;
92 
93 public slots:
94   void action(String name) override;
95   void qAction(const QString &name);
96   void selectLayerAction(QAction *a);
97   void moveToLayerAction(QAction *a);
98   void textStyleAction(QAction *a);
99   void labelStyleAction(QAction *a);
100   void gridSizeAction(QAction *a);
101   void angleSizeAction(QAction *a);
102 
103   void layerAction(String name, String layer);
104   void toolbarModifiersChanged();
105   void abortDrawing();
106   void aboutIpe();
107 
108   void absoluteButton(int id);
109   void selector(int id, String value);
110   void comboSelector(int id);
111 
112   void bookmarkSelected(QListWidgetItem *item);
113   void recentFileAction(QAction *a);
114 
115   void aboutToShowSelectLayerMenu();
116   void aboutToShowMoveToLayerMenu();
117   void aboutToShowTextStyleMenu();
118   void aboutToShowLabelStyleMenu();
119   void aboutToShowGridSizeMenu();
120   void aboutToShowAngleSizeMenu();
121 
122   void showPathStylePopup(Vector v);
123   void showLayerBoxPopup(Vector v, String layer);
124 
125 private:
126   void addItem(QMenu *m, const QString &title, const char *name);
127   void addItem(int m, const QString &title, const char *name);
128   void addSnap(const char *name);
129   void addEdit(const char *name);
130   QIcon prefsIcon(String name);
131   QIcon prefsColorIcon(Color color);
132   QPixmap prefsPixmap(String name);
133   void aboutToShowStyleMenu(Kind kind, MENUHANDLE menu, String current);
134 
uiscale(int x)135   inline int uiscale(int x) { return iUiScale * x / 100; }
136 
137 private:
138   virtual void addRootMenu(int id, const char *name) override;
139   virtual void addItem(int id, const char *title, const char *name) override;
140   virtual void startSubMenu(int id, const char *name, int tag) override;
141   virtual void addSubItem(const char *title, const char *name) override;
142   virtual MENUHANDLE endSubMenu() override;
143   virtual void setMouseIndicator(const char *s) override;
144   virtual void setSnapIndicator(const char *s) override;
145   virtual void addCombo(int sel, String s) override;
146   virtual void resetCombos() override;
147   virtual void addComboColors(AttributeSeq &sym, AttributeSeq &abs) override;
148   virtual void setComboCurrent(int sel, int idx) override;
149   virtual void setCheckMark(String name, Attribute a) override;
150   virtual void setPathView(const AllAttributes &all, Cascade *sheet) override;
151   virtual void setButtonColor(int sel, Color color) override;
152 
153 protected:
154   void closeEvent(QCloseEvent *ev) override;
155 
156 private:
157   PathView *iPathView;
158 
159   QMenu *iMenu[ENumMenu];
160 
161   QToolButton *iButton[EUiOpacity]; // EUiDashStyle and EUiMarkShape are not used
162   QComboBox *iSelector[EUiView];
163 
164   QToolButton *iViewNumber;
165   QToolButton *iPageNumber;
166 
167   QCheckBox *iViewMarked;
168   QCheckBox *iPageMarked;
169 
170   QToolBar *iSnapTools;
171   QToolBar *iEditTools;
172   QToolBar *iObjectTools;
173 
174   QDockWidget *iPropertiesTools;
175   QDockWidget *iLayerTools;
176   QDockWidget *iBookmarkTools;
177   QDockWidget *iNotesTools;
178 
179   QActionGroup *iModeActionGroup;
180 
181   QAction *iShiftKey;
182   QAction *iAbortButton;
183 
184   QListWidget *iBookmarks;
185   LayerBox *iLayerList;
186   QTextEdit *iPageNotes;
187 
188   QLabel *iModeIndicator;
189   QLabel *iSnapIndicator;
190   QLabel *iMouse;
191   QLabel *iResolution;
192 
193   QSignalMapper *iActionMap;
194   std::map<String, QAction *> iActions;
195 };
196 
197 // --------------------------------------------------------------------
198 #endif
199