src/gui.h

changeset 629
b75c6cce02e2
parent 628
6b13e4c2e97b
child 630
42ec68fcad9e
child 675
450827da2376
equal deleted inserted replaced
628:6b13e4c2e97b 629:b75c6cce02e2
1 /*
2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013, 2014 Santeri Piippo
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef LDFORGE_GUI_H
20 #define LDFORGE_GUI_H
21
22 #include <QMainWindow>
23 #include <QAction>
24 #include <QListWidget>
25 #include <QRadioButton>
26 #include "config.h"
27 #include "ldtypes.h"
28 #include "ui_ldforge.h"
29
30 class MessageManager;
31 class ForgeWindow;
32 class LDColor;
33 class QToolButton;
34 class QDialogButtonBox;
35 class GLRenderer;
36 class QComboBox;
37 class QProgressBar;
38 class Ui_LDForgeUI;
39
40 // Stuff for dialogs
41 #define IMPLEMENT_DIALOG_BUTTONS \
42 bbx_buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); \
43 connect (bbx_buttons, SIGNAL (accepted()), this, SLOT (accept())); \
44 connect (bbx_buttons, SIGNAL (rejected()), this, SLOT (reject())); \
45
46 // =============================================================================
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
48 // =============================================================================
49 #define DEFINE_ACTION(NAME, DEFSHORTCUT) \
50 cfg (KeySequence, key_action##NAME, DEFSHORTCUT); \
51 void ForgeWindow::slot_action##NAME()
52
53 // Convenience macros for key sequences.
54 #define KEY(N) (Qt::Key_##N)
55 #define CTRL(N) (Qt::CTRL | Qt::Key_##N)
56 #define SHIFT(N) (Qt::SHIFT | Qt::Key_##N)
57 #define CTRL_SHIFT(N) (Qt::CTRL | Qt::SHIFT | Qt::Key_##N)
58
59 // =============================================================================
60 class LDQuickColor
61 {
62 PROPERTY (public, LDColor*, Color, NO_OPS, STOCK_WRITE)
63 PROPERTY (public, QToolButton*, ToolButton, NO_OPS, STOCK_WRITE)
64
65 public:
66 LDQuickColor (LDColor* color, QToolButton* toolButton);
67 bool isSeparator() const;
68
69 static LDQuickColor getSeparator();
70 };
71
72 // =============================================================================
73 // ObjectList
74 //
75 // Object list class for ForgeWindow
76 // =============================================================================
77 class ObjectList : public QListWidget
78 {
79 Q_OBJECT
80
81 protected:
82 void contextMenuEvent (QContextMenuEvent* ev);
83 };
84
85 // =============================================================================
86 // ForgeWindow
87 //
88 // The one main GUI class. Hosts the renderer, object list, message log. Contains
89 // slot_action, which is what all actions connect to. Manages menus and toolbars.
90 // Large and in charge.
91 // =============================================================================
92 class ForgeWindow : public QMainWindow
93 {
94 Q_OBJECT
95
96 public:
97 ForgeWindow();
98 void buildObjList();
99 void updateTitle();
100 void doFullRefresh();
101 void refresh();
102 int getInsertionPoint();
103 void updateToolBars();
104 void updateRecentFilesMenu();
105 void updateSelection();
106 void updateGridToolBar();
107 void updateEditModeActions();
108 void updateDocumentList();
109 void updateDocumentListItem (LDDocument* f);
110 int getSelectedColor();
111 LDObject::Type getUniformSelectedType();
112 void scrollToSelection();
113 void spawnContextMenu (const QPoint pos);
114 void deleteObjects (LDObjectList objs);
115 int deleteSelection();
116 void deleteByColor (const int colnum);
117 bool save (LDDocument* f, bool saveAs);
118 void updateActions();
119
120 inline GLRenderer* R()
121 {
122 return m_renderer;
123 }
124
125 inline void setQuickColors (QList<LDQuickColor>& colors)
126 {
127 m_quickColors = colors;
128 }
129
130 void addMessage (QString msg);
131 void refreshObjectList();
132 void updateActionShortcuts();
133 KeySequenceConfig* shortcutForAction (QAction* act);
134 void endAction();
135
136 public slots:
137 void changeCurrentFile();
138 void slot_action();
139 void slot_actionNew();
140 void slot_actionNewFile();
141 void slot_actionOpen();
142 void slot_actionDownloadFrom();
143 void slot_actionSave();
144 void slot_actionSaveAs();
145 void slot_actionSaveAll();
146 void slot_actionClose();
147 void slot_actionCloseAll();
148 void slot_actionInsertFrom();
149 void slot_actionExportTo();
150 void slot_actionSettings();
151 void slot_actionSetLDrawPath();
152 void slot_actionScanPrimitives();
153 void slot_actionExit();
154 void slot_actionResetView();
155 void slot_actionAxes();
156 void slot_actionWireframe();
157 void slot_actionBFCView();
158 void slot_actionSetOverlay();
159 void slot_actionClearOverlay();
160 void slot_actionScreenshot();
161 void slot_actionInsertRaw();
162 void slot_actionNewSubfile();
163 void slot_actionNewLine();
164 void slot_actionNewTriangle();
165 void slot_actionNewQuad();
166 void slot_actionNewCLine();
167 void slot_actionNewComment();
168 void slot_actionNewBFC();
169 void slot_actionNewVertex();
170 void slot_actionUndo();
171 void slot_actionRedo();
172 void slot_actionCut();
173 void slot_actionCopy();
174 void slot_actionPaste();
175 void slot_actionDelete();
176 void slot_actionSelectAll();
177 void slot_actionSelectByColor();
178 void slot_actionSelectByType();
179 void slot_actionModeDraw();
180 void slot_actionModeSelect();
181 void slot_actionModeCircle();
182 void slot_actionSetDrawDepth();
183 void slot_actionSetColor();
184 void slot_actionAutocolor();
185 void slot_actionUncolorize();
186 void slot_actionInline();
187 void slot_actionInlineDeep();
188 void slot_actionInvert();
189 void slot_actionMakePrimitive();
190 void slot_actionSplitQuads();
191 void slot_actionEditRaw();
192 void slot_actionBorders();
193 void slot_actionCornerVerts();
194 void slot_actionRoundCoordinates();
195 void slot_actionVisibilityHide();
196 void slot_actionVisibilityReveal();
197 void slot_actionVisibilityToggle();
198 void slot_actionReplaceCoords();
199 void slot_actionFlip();
200 void slot_actionDemote();
201 void slot_actionYtruder();
202 void slot_actionRectifier();
203 void slot_actionIntersector();
204 void slot_actionIsecalc();
205 void slot_actionCoverer();
206 void slot_actionEdger2();
207 void slot_actionHelp();
208 void slot_actionAbout();
209 void slot_actionAboutQt();
210 void slot_actionGridCoarse();
211 void slot_actionGridMedium();
212 void slot_actionGridFine();
213 void slot_actionEdit();
214 void slot_actionMoveUp();
215 void slot_actionMoveDown();
216 void slot_actionMoveXNeg();
217 void slot_actionMoveXPos();
218 void slot_actionMoveYNeg();
219 void slot_actionMoveYPos();
220 void slot_actionMoveZNeg();
221 void slot_actionMoveZPos();
222 void slot_actionRotateXNeg();
223 void slot_actionRotateXPos();
224 void slot_actionRotateYNeg();
225 void slot_actionRotateYPos();
226 void slot_actionRotateZNeg();
227 void slot_actionRotateZPos();
228 void slot_actionRotationPoint();
229 void slot_actionAddHistoryLine();
230 void slot_actionJumpTo();
231 void slot_actionSubfileSelection();
232 void slot_actionDrawAngles();
233
234 protected:
235 void closeEvent (QCloseEvent* ev);
236
237 private:
238 GLRenderer* m_renderer;
239 LDObjectList m_sel;
240 QList<LDQuickColor> m_quickColors;
241 QList<QToolButton*> m_colorButtons;
242 QList<QAction*> m_recentFiles;
243 MessageManager* m_msglog;
244 Ui_LDForgeUI* ui;
245
246 private slots:
247 void slot_selectionChanged();
248 void slot_recentFile();
249 void slot_quickColor();
250 void slot_lastSecondCleanup();
251 void slot_editObject (QListWidgetItem* listitem);
252 };
253
254 // -----------------------------------------------------------------------------
255 // Pointer to the instance of ForgeWindow.
256 extern ForgeWindow* g_win;
257
258 // -----------------------------------------------------------------------------
259 // Other GUI-related stuff not directly part of ForgeWindow:
260 QPixmap getIcon (QString iconName); // Get an icon from the resource dir
261 QList<LDQuickColor> quickColorsFromConfig(); // Make a list of quick colors based on config
262 bool confirm (QString title, QString msg); // Generic confirm prompt
263 bool confirm (QString msg); // Generic confirm prompt
264 void critical (QString msg); // Generic error prompt
265 QIcon makeColorIcon (LDColor* colinfo, const int size); // Makes an icon for the given color
266 void makeColorComboBox (QComboBox* box); // Fills the given combo-box with color information
267 QImage imageFromScreencap (uchar* data, int w, int h);
268
269 // =============================================================================
270 // -----------------------------------------------------------------------------
271 // Takes in pairs of radio buttons and respective values and returns the value of
272 // the first found radio button that was checked.
273 // =============================================================================
274 template<class T>
275 T radioSwitch (const T& defval, QList<pair<QRadioButton*, T>> haystack)
276 {
277 for (pair<QRadioButton*, const T&> i : haystack)
278 if (i.first->isChecked())
279 return i.second;
280
281 return defval;
282 }
283
284 // =============================================================================
285 // -----------------------------------------------------------------------------
286 // Takes in pairs of radio buttons and respective values and checks the first
287 // found radio button to have the given value.
288 // =============================================================================
289 template<class T>
290 void radioDefault (const T& expr, QList<pair<QRadioButton*, T>> haystack)
291 {
292 for (pair<QRadioButton*, const T&> i : haystack)
293 {
294 if (i.second == expr)
295 {
296 i.first->setChecked (true);
297 return;
298 }
299 }
300 }
301
302 #endif // LDFORGE_GUI_H

mercurial