gui.h

changeset 79
f8917e9d07f6
parent 78
c190fe218506
child 87
8dbf0fdf3374
equal deleted inserted replaced
78:c190fe218506 79:f8917e9d07f6
33 #define IMPLEMENT_DIALOG_BUTTONS \ 33 #define IMPLEMENT_DIALOG_BUTTONS \
34 qButtons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); \ 34 qButtons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); \
35 connect (qButtons, SIGNAL (accepted ()), this, SLOT (accept ())); \ 35 connect (qButtons, SIGNAL (accepted ()), this, SLOT (accept ())); \
36 connect (qButtons, SIGNAL (rejected ()), this, SLOT (reject ())); \ 36 connect (qButtons, SIGNAL (rejected ()), this, SLOT (reject ())); \
37 37
38 // =============================================================================
39 // Metadata for actions
40 typedef struct {
41 QAction** const qAct;
42 keyseqconfig* const conf;
43 const char* const sDisplayName, *sIconName, *sDescription;
44 void (*const handler) ();
45 } actionmeta;
46
47 extern vector<actionmeta> g_ActionMeta;
48
49 // =============================================================================
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
51 // =============================================================================
52 #define ACTION(NAME, DISPLAYNAME, ICONNAME, DESCR, DEFSHORTCUT) \
53 QAction* ACTION_NAME (NAME); \
54 cfg (keyseq, key_##NAME, DEFSHORTCUT); \
55 static void actionHandler_##NAME (); \
56 static ActionAdder ActionAdderInstance_##NAME (&ACTION_NAME(NAME), DISPLAYNAME, \
57 ICONNAME, DESCR, &key_##NAME, actionHandler_##NAME); \
58 static void actionHandler_##NAME ()
59
60 #define EXTERN_ACTION(NAME) extern QAction* ACTION_NAME (NAME);
61 #define ACTION_NAME(N) (LDForgeAction_##N)
62
63 // Convenience macros for key sequences.
64 #define KEY(N) (Qt::Key_##N)
65 #define CTRL(N) (Qt::CTRL | Qt::Key_##N)
66 #define SHIFT(N) (Qt::SHIFT | Qt::Key_##N)
67 #define CTRL_SHIFT(N) (Qt::CTRL | Qt::SHIFT | Qt::Key_##N)
68
69 // =============================================================================
70 // ActionAdder
71 //
72 // The ACTION macro expands into - among other stuff - into an instance of this.
73 // This class' constructor creates meta for the newly defined action and stores
74 // it in g_ActionMeta. It is not supposed to be used directly!
75 // =============================================================================
76 class ActionAdder {
77 public:
78 ActionAdder (QAction** qAct, const char* sDisplayName, const char* sIconName,
79 const char* sDescription, keyseqconfig* conf, void (*const handler) ())
80 {
81 actionmeta meta = {qAct, conf, sDisplayName, sIconName, sDescription, handler};
82 g_ActionMeta.push_back (meta);
83 }
84 };
85
86 // =============================================================================
87 // ForgeWindow
88 //
89 // The one main GUI class. Hosts the renderer, object list, message log. Contains
90 // slot_action, which is what all actions connect to. Manages menus and toolbars.
91 // Large and in charge.
92 // =============================================================================
38 class ForgeWindow : public QMainWindow { 93 class ForgeWindow : public QMainWindow {
39 Q_OBJECT 94 Q_OBJECT
40 95
41 public: 96 public:
42 renderer* R; 97 renderer* R;
43 98
44 // Object list view 99 // Object list view
45 QTreeWidget* qObjList; 100 QTreeWidget* qObjList;
101 QTextEdit* qMessageLog;
102 QMenu* qFileMenu, *qEditMenu, *qInsertMenu, *qHelpMenu;
103 QToolBar* qFileToolBar, *qEditToolBar, *qInsertToolBar;
46 104
47 // Message log
48 QTextEdit* qMessageLog;
49 str zMessageLogHTML; 105 str zMessageLogHTML;
50
51 // Menus
52 QMenu* qFileMenu, *qEditMenu, *qInsertMenu, *qHelpMenu;
53
54 // Toolbars
55 QToolBar* qFileToolBar, *qEditToolBar, *qInsertToolBar;
56 106
57 ForgeWindow (); 107 ForgeWindow ();
58 void buildObjList (); 108 void buildObjList ();
59 void setTitle (); 109 void setTitle ();
60 void refresh (); 110 void refresh ();
61 std::vector<LDObject*> getSelectedObjects (); 111 std::vector<LDObject*> getSelectedObjects ();
62
63 // Where would a new item be inserted into?
64 ulong getInsertionPoint (); 112 ulong getInsertionPoint ();
65 113 void deleteSelection ();
114
66 private: 115 private:
67 void createMenuActions (); 116 void createMenuActions ();
68 void createMenus (); 117 void createMenus ();
69 void createToolbars (); 118 void createToolbars ();
70 bool copyToClipboard ();
71 void deleteSelection ();
72 void doInline (bool bDeep);
73 119
74 private slots: 120 private slots:
75 void slot_selectionChanged (); 121 void slot_selectionChanged ();
76 122 void slot_action ();
77 void slot_newFile ();
78 void slot_open ();
79 void slot_save ();
80 void slot_saveAs ();
81 void slot_exit ();
82
83 void slot_newSubfile ();
84 void slot_newLine ();
85 void slot_newTriangle ();
86 void slot_newQuad ();
87 void slot_newCondLine ();
88 void slot_newComment ();
89 void slot_newVertex ();
90
91 void slot_inlineContents ();
92 void slot_deepInline ();
93 void slot_splitQuads ();
94 void slot_setContents ();
95 void slot_makeBorders ();
96
97 void slot_cut ();
98 void slot_copy ();
99 void slot_paste ();
100 void slot_del ();
101
102 void slot_settings ();
103
104 void slot_help ();
105 void slot_about ();
106 void slot_aboutQt ();
107
108 void slot_setColor ();
109 }; 123 };
110 124
125 // -----------------------------------------------------------------------------
126 // Other GUI-related stuff not directly part of ForgeWindow:
127 QIcon getIcon (const char* sIconName);
128
129 // -----------------------------------------------------------------------------
130 // Pointer to the instance of ForgeWindow.
131 extern ForgeWindow* g_ForgeWindow;
132
133 // Is this still needed?
111 enum { 134 enum {
112 LDOLC_Icon, 135 LDOLC_Icon,
113 LDOLC_Data, 136 LDOLC_Data,
114 NUM_LDOL_Columns 137 NUM_LDOL_Columns
115 }; 138 };
116 139
117 // =============================================================================
118 // Metadata for actions
119 typedef struct {
120 QAction** const qAct;
121 keyseqconfig* const conf;
122 } actionmeta;
123
124 extern vector<actionmeta> g_ActionMeta;
125
126 #endif 140 #endif

mercurial