Sat, 16 Mar 2013 03:42:04 +0200
Allow addition of dummy lines..
| 0 | 1 | #include <QtGui> |
| 2 | ||
| 3 | #include "common.h" | |
| 4 | #include "draw.h" | |
| 5 | #include "gui.h" | |
| 6 | #include "model.h" | |
| 7 | #include "io.h" | |
| 8 | ||
|
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
9 | #include "zz_setContentsDialog.h" |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
10 | |
| 0 | 11 | LDForgeWindow::LDForgeWindow () { |
| 12 | R = new renderer; | |
| 13 | ||
| 14 | qObjList = new QTreeWidget; | |
| 15 | qObjList->setHeaderHidden (true); | |
| 16 | qObjList->setMaximumWidth (256); | |
|
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
17 | qObjList->setSelectionMode (QTreeWidget::MultiSelection); |
|
17
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
18 | connect (qObjList, SIGNAL (itemSelectionChanged ()), this, SLOT (slot_selectionChanged ())); |
| 0 | 19 | |
| 20 | qMessageLog = new QTextEdit; | |
| 21 | qMessageLog->setReadOnly (true); | |
| 22 | qMessageLog->setMaximumHeight (96); | |
| 23 | ||
| 24 | QWidget* w = new QWidget; | |
| 25 | QGridLayout* layout = new QGridLayout; | |
| 26 | layout->setColumnMinimumWidth (0, 192); | |
| 27 | layout->setColumnStretch (0, 1); | |
| 28 | layout->addWidget (R, 0, 0); | |
| 29 | layout->addWidget (qObjList, 0, 1); | |
| 30 | layout->addWidget (qMessageLog, 1, 0, 1, 2); | |
| 31 | w->setLayout (layout); | |
| 32 | setCentralWidget (w); | |
| 33 | ||
| 34 | createMenuActions (); | |
| 35 | createMenus (); | |
| 36 | createToolbars (); | |
| 37 | ||
|
7
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
38 | setTitle (); |
| 0 | 39 | setMinimumSize (320, 200); |
| 40 | resize (800, 600); | |
| 41 | } | |
| 42 | ||
| 43 | #define MAKE_ACTION(OBJECT, DISPLAYNAME, IMAGENAME, DESCR) \ | |
| 44 | qAct_##OBJECT = new QAction (QIcon ("./icons/" IMAGENAME ".png"), tr (DISPLAYNAME), this); \ | |
| 45 | qAct_##OBJECT->setStatusTip (tr (DESCR)); \ | |
| 46 | connect (qAct_##OBJECT, SIGNAL (triggered ()), this, SLOT (slot_##OBJECT ())); | |
| 47 | ||
| 48 | void LDForgeWindow::createMenuActions () { | |
| 49 | // Long menu names go here so my cool action definition table doesn't get out of proportions | |
| 50 | const char* sNewCdLineText = "New Conditional Line", | |
| 51 | *sNewQuadText = "New Quadrilateral", | |
| 52 | *sAboutText = "About " APPNAME_DISPLAY; | |
| 53 | ||
| 54 | MAKE_ACTION (new, "&New", "file-new", "Create a new part model.") | |
|
5
727e02d6b87a
rename file-specific icons to file-*
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
55 | MAKE_ACTION (open, "&Open", "file-open", "Load a part model from a file.") |
|
727e02d6b87a
rename file-specific icons to file-*
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
56 | MAKE_ACTION (save, "&Save", "file-save", "Save the part model.") |
|
727e02d6b87a
rename file-specific icons to file-*
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
57 | MAKE_ACTION (saveAs, "Save &As", "file-save-as", "Save the part to a specific file.") |
| 0 | 58 | MAKE_ACTION (exit, "&Exit", "exit", "Close " APPNAME_DISPLAY ".") |
| 59 | ||
| 60 | MAKE_ACTION (cut, "Cut", "cut", "Cut the current selection to clipboard.") | |
| 61 | MAKE_ACTION (copy, "Copy", "copy", "Copy the current selection to clipboard.") | |
| 62 | MAKE_ACTION (paste, "Paste", "paste", "Paste clipboard contents.") | |
| 63 | MAKE_ACTION (about, sAboutText, "about", "Shows information about " APPNAME_DISPLAY ".") | |
| 64 | MAKE_ACTION (aboutQt, "About Qt", "aboutQt", "Shows information about Qt.") | |
| 65 | ||
|
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
66 | MAKE_ACTION (setContents, "Set Contents", "set-contents", "Set the raw code of this object.") |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
67 | |
| 0 | 68 | MAKE_ACTION (newSubfile, "New Subfile", "add-subfile", "Creates a new subfile reference.") |
| 69 | MAKE_ACTION (newLine, "New Line", "add-line", "Creates a new line.") | |
| 70 | MAKE_ACTION (newTriangle, "New Triangle", "add-triangle", "Creates a new triangle.") | |
| 71 | MAKE_ACTION (newQuad, sNewQuadText, "add-quad", "Creates a new quadrilateral.") | |
| 72 | MAKE_ACTION (newCondLine, sNewCdLineText, "add-condline", "Creates a new conditional line."); | |
| 73 | MAKE_ACTION (newComment, "New Comment", "add-comment", "Creates a new comment."); | |
| 74 | MAKE_ACTION (newVector, "New Vector", "add-vector", "Creates a new vector.") | |
| 75 | MAKE_ACTION (newVertex, "New Vertex", "add-vertex", "Creates a new vertex.") | |
| 76 | ||
| 77 | // Keyboard shortcuts | |
| 78 | qAct_new->setShortcut (Qt::CTRL | Qt::Key_N); | |
| 79 | qAct_open->setShortcut (Qt::CTRL | Qt::Key_O); | |
| 80 | qAct_save->setShortcut (Qt::CTRL | Qt::Key_S); | |
| 81 | qAct_saveAs->setShortcut (Qt::CTRL | Qt::SHIFT | Qt::Key_S); | |
| 82 | ||
| 83 | qAct_cut->setShortcut (Qt::CTRL | Qt::Key_X); | |
| 84 | qAct_copy->setShortcut (Qt::CTRL | Qt::Key_C); | |
| 85 | qAct_paste->setShortcut (Qt::CTRL | Qt::Key_V); | |
| 86 | ||
| 87 | // things not implemented yet | |
| 88 | QAction* qaDisabledActions[] = { | |
| 89 | qAct_save, | |
| 90 | qAct_saveAs, | |
| 91 | qAct_newSubfile, | |
| 92 | qAct_newTriangle, | |
| 93 | qAct_newQuad, | |
| 94 | qAct_newCondLine, | |
| 95 | qAct_newComment, | |
| 96 | qAct_newVector, | |
| 97 | qAct_newVertex, | |
| 98 | qAct_cut, | |
| 99 | qAct_copy, | |
| 100 | qAct_paste, | |
| 101 | qAct_about | |
| 102 | }; | |
| 103 | ||
| 104 | for (ushort i = 0; i < sizeof qaDisabledActions / sizeof *qaDisabledActions; ++i) | |
| 105 | qaDisabledActions[i]->setEnabled (false); | |
| 106 | } | |
| 107 | ||
| 108 | void LDForgeWindow::createMenus () { | |
| 109 | // File menu | |
| 110 | qFileMenu = menuBar ()->addMenu (tr ("&File")); | |
| 111 | qFileMenu->addAction (qAct_new); // New | |
| 112 | qFileMenu->addAction (qAct_open); // Open | |
| 113 | qFileMenu->addAction (qAct_save); // Save | |
| 114 | qFileMenu->addAction (qAct_saveAs); // Save As | |
| 115 | qFileMenu->addSeparator (); // ------- | |
| 116 | qFileMenu->addAction (qAct_exit); // Exit | |
| 117 | ||
| 118 | // Edit menu | |
| 119 | qInsertMenu = menuBar ()->addMenu (tr ("&Insert")); | |
| 120 | qInsertMenu->addAction (qAct_newSubfile); // New Subfile | |
| 121 | qInsertMenu->addAction (qAct_newLine); // New Line | |
| 122 | qInsertMenu->addAction (qAct_newTriangle); // New Triangle | |
| 123 | qInsertMenu->addAction (qAct_newQuad); // New Quad | |
| 124 | qInsertMenu->addAction (qAct_newCondLine); // New Conditional Line | |
| 125 | qInsertMenu->addAction (qAct_newComment); // New Comment | |
| 126 | qInsertMenu->addAction (qAct_newVector); // New Vector | |
| 127 | qInsertMenu->addAction (qAct_newVertex); // New Vertex | |
| 128 | ||
| 129 | qEditMenu = menuBar ()->addMenu (tr ("&Edit")); | |
| 130 | qEditMenu->addAction (qAct_cut); // Cut | |
| 131 | qEditMenu->addAction (qAct_copy); // Copy | |
| 132 | qEditMenu->addAction (qAct_paste); // Paste | |
|
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
133 | qEditMenu->addSeparator (); // ----- |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
134 | qEditMenu->addAction (qAct_setContents); // Set Contents |
| 0 | 135 | |
| 136 | // Help menu | |
| 137 | qHelpMenu = menuBar ()->addMenu (tr ("&Help")); | |
| 138 | qHelpMenu->addAction (qAct_about); // About | |
| 139 | qHelpMenu->addAction (qAct_aboutQt); // About Qt | |
| 140 | } | |
| 141 | ||
| 142 | void LDForgeWindow::createToolbars () { | |
| 143 | qFileToolBar = new QToolBar ("File"); | |
| 144 | qFileToolBar->addAction (qAct_new); | |
| 145 | qFileToolBar->addAction (qAct_open); | |
| 146 | qFileToolBar->addAction (qAct_save); | |
| 147 | qFileToolBar->addAction (qAct_saveAs); | |
| 148 | addToolBar (qFileToolBar); | |
| 149 | ||
| 150 | qInsertToolBar = new QToolBar ("Insert"); | |
| 151 | qInsertToolBar->addAction (qAct_newSubfile); | |
| 152 | qInsertToolBar->addAction (qAct_newLine); | |
| 153 | qInsertToolBar->addAction (qAct_newTriangle); | |
| 154 | qInsertToolBar->addAction (qAct_newQuad); | |
| 155 | qInsertToolBar->addAction (qAct_newCondLine); | |
| 156 | qInsertToolBar->addAction (qAct_newComment); | |
| 157 | qInsertToolBar->addAction (qAct_newVector); | |
| 158 | qInsertToolBar->addAction (qAct_newVertex); | |
| 159 | addToolBar (qInsertToolBar); | |
| 160 | ||
| 161 | qEditToolBar = new QToolBar ("Edit"); | |
| 162 | qEditToolBar->addAction (qAct_cut); | |
| 163 | qEditToolBar->addAction (qAct_copy); | |
| 164 | qEditToolBar->addAction (qAct_paste); | |
|
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
165 | qEditToolBar->addAction (qAct_setContents); |
| 0 | 166 | addToolBar (qEditToolBar); |
| 167 | } | |
| 168 | ||
|
7
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
169 | void LDForgeWindow::setTitle () { |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
170 | str zTitle = APPNAME_DISPLAY " v" VERSION_STRING; |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
171 | |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
172 | // Append our current file if we have one |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
173 | if (g_CurrentFile) { |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
174 | zTitle.appendformat (": %s", basename (g_CurrentFile->zFileName.chars())); |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
175 | |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
176 | if (g_CurrentFile->objects.size() > 0 && |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
177 | g_CurrentFile->objects[0]->getType() == OBJ_Comment) |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
178 | { |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
179 | // Append title |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
180 | LDComment* comm = static_cast<LDComment*> (g_CurrentFile->objects[0]); |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
181 | zTitle.appendformat (":%s", comm->zText.chars()); |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
182 | } |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
183 | } |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
184 | |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
185 | setWindowTitle (zTitle.chars()); |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
186 | } |
|
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
5
diff
changeset
|
187 | |
| 0 | 188 | void LDForgeWindow::slot_new () { |
| 189 | printf ("new file\n"); | |
| 190 | ||
| 191 | closeModel (); | |
| 192 | newModel (); | |
| 193 | } | |
| 194 | ||
| 195 | void LDForgeWindow::slot_open () { | |
|
4
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
196 | str name = QFileDialog::getOpenFileName (this, "Open File", |
| 0 | 197 | "", "LDraw files (*.dat *.ldr)").toStdString().c_str(); |
| 198 | ||
| 199 | if (g_LoadedFiles.size()) | |
| 200 | closeModel (); | |
| 201 | ||
|
4
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
202 | IO_OpenLDrawFile (name); |
| 0 | 203 | } |
| 204 | ||
| 205 | void LDForgeWindow::slot_save () { | |
| 206 | printf ("save file\n"); | |
| 207 | } | |
| 208 | ||
| 209 | void LDForgeWindow::slot_saveAs () { | |
| 210 | printf ("save as file\n"); | |
| 211 | } | |
| 212 | ||
| 213 | void LDForgeWindow::slot_exit () { | |
| 214 | printf ("exit\n"); | |
| 215 | exit (0); | |
| 216 | } | |
| 217 | ||
| 218 | void LDForgeWindow::slot_newSubfile () { | |
| 219 | ||
| 220 | } | |
| 221 | ||
| 222 | void LDForgeWindow::slot_newLine () { | |
|
17
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
223 | LDLine* line = new LDLine; |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
224 | const ulong ulSpot = getInsertionPoint (); |
| 0 | 225 | |
|
17
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
226 | memset (line->vaCoords, 0, sizeof line->vaCoords); |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
227 | line->dColor = 24; |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
228 | |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
229 | g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + ulSpot, line); |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
230 | |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
231 | buildObjList (); |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
232 | R->hardRefresh (); |
| 0 | 233 | } |
| 234 | ||
| 235 | void LDForgeWindow::slot_newTriangle () { | |
| 236 | ||
| 237 | } | |
| 238 | ||
| 239 | void LDForgeWindow::slot_newQuad () { | |
| 240 | ||
| 241 | } | |
| 242 | ||
| 243 | void LDForgeWindow::slot_newCondLine () { | |
| 244 | ||
| 245 | } | |
| 246 | ||
| 247 | void LDForgeWindow::slot_newComment () { | |
| 248 | ||
| 249 | } | |
| 250 | ||
| 251 | void LDForgeWindow::slot_about () { | |
| 252 | ||
| 253 | } | |
| 254 | ||
| 255 | void LDForgeWindow::slot_aboutQt () { | |
| 256 | QMessageBox::aboutQt (this); | |
| 257 | } | |
| 258 | ||
| 259 | void LDForgeWindow::slot_cut () { | |
| 260 | ||
| 261 | } | |
| 262 | ||
| 263 | void LDForgeWindow::slot_copy () { | |
| 264 | ||
| 265 | } | |
| 266 | ||
| 267 | void LDForgeWindow::slot_paste () { | |
| 268 | ||
| 269 | } | |
| 270 | ||
| 271 | void LDForgeWindow::slot_newVector () { | |
| 272 | ||
| 273 | } | |
| 274 | ||
| 275 | void LDForgeWindow::slot_newVertex () { | |
| 276 | ||
| 277 | } | |
| 278 | ||
|
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
279 | void LDForgeWindow::slot_setContents () { |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
280 | if (qObjList->selectedItems().size() != 1) |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
281 | return; |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
282 | |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
283 | ulong ulIndex; |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
284 | LDObject* obj = nullptr; |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
285 | |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
286 | QTreeWidgetItem* item = qObjList->selectedItems()[0]; |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
287 | for (ulIndex = 0; ulIndex < g_CurrentFile->objects.size(); ++ulIndex) { |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
288 | obj = g_CurrentFile->objects[ulIndex]; |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
289 | |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
290 | if (obj->qObjListEntry == item) |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
291 | break; |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
292 | } |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
293 | |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
294 | if (ulIndex >= g_CurrentFile->objects.size()) |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
295 | return; |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
296 | |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
297 | Dialog_SetContents::staticDialog (obj, this); |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
298 | } |
| 0 | 299 | |
| 300 | static QIcon IconForObjectType (LDObject* obj) { | |
| 301 | switch (obj->getType ()) { | |
| 302 | case OBJ_Empty: | |
| 303 | return QIcon ("icons/empty.png"); | |
| 304 | ||
| 305 | case OBJ_Line: | |
| 306 | return QIcon ("icons/line.png"); | |
| 307 | ||
| 308 | case OBJ_Quad: | |
| 309 | return QIcon ("icons/quad.png"); | |
| 310 | ||
| 311 | case OBJ_Subfile: | |
| 312 | return QIcon ("icons/subfile.png"); | |
| 313 | ||
| 314 | case OBJ_Triangle: | |
| 315 | return QIcon ("icons/triangle.png"); | |
| 316 | ||
| 317 | case OBJ_CondLine: | |
| 318 | return QIcon ("icons/condline.png"); | |
| 319 | ||
| 320 | case OBJ_Comment: | |
| 321 | return QIcon ("icons/comment.png"); | |
| 322 | ||
| 323 | case OBJ_Vector: | |
| 324 | return QIcon ("icons/vector.png"); | |
| 325 | ||
| 326 | case OBJ_Vertex: | |
| 327 | return QIcon ("icons/vertex.png"); | |
| 328 | ||
| 329 | case OBJ_Gibberish: | |
| 330 | case OBJ_Unidentified: | |
| 331 | return QIcon ("icons/error.png"); | |
| 332 | } | |
| 333 | ||
| 334 | return QIcon (); | |
| 335 | } | |
| 336 | ||
| 337 | void LDForgeWindow::buildObjList () { | |
|
3
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
338 | if (!g_CurrentFile) |
|
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
339 | return; |
|
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
340 | |
| 0 | 341 | QList<QTreeWidgetItem*> qaItems; |
|
3
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
342 | |
|
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
343 | qObjList->clear (); |
|
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
344 | |
| 0 | 345 | for (ushort i = 0; i < g_CurrentFile->objects.size(); ++i) { |
| 346 | LDObject* obj = g_CurrentFile->objects[i]; | |
| 347 | ||
| 348 | str zText; | |
| 349 | switch (obj->getType ()) { | |
| 350 | case OBJ_Comment: | |
|
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
351 | zText = static_cast<LDComment*> (obj)->zText.chars(); |
|
10
5b0579997e9b
remove leading whitespace from comments when drawing them in the list
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
352 | |
|
5b0579997e9b
remove leading whitespace from comments when drawing them in the list
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
353 | // Remove leading whitespace |
|
5b0579997e9b
remove leading whitespace from comments when drawing them in the list
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
354 | while (~zText && zText[0] == ' ') |
|
5b0579997e9b
remove leading whitespace from comments when drawing them in the list
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
355 | zText -= -1; |
| 0 | 356 | break; |
| 357 | ||
| 358 | case OBJ_Empty: | |
| 359 | break; // leave it empty | |
| 360 | ||
| 361 | case OBJ_Line: | |
| 362 | case OBJ_CondLine: | |
| 363 | { | |
| 364 | LDLine* line = static_cast<LDLine*> (obj); | |
| 365 | zText.format ("%s, %s", | |
| 366 | line->vaCoords[0].getStringRep ().chars(), | |
| 367 | line->vaCoords[1].getStringRep ().chars()); | |
| 368 | } | |
| 369 | break; | |
| 370 | ||
| 371 | case OBJ_Triangle: | |
| 372 | { | |
| 373 | LDTriangle* triangle = static_cast<LDTriangle*> (obj); | |
| 374 | zText.format ("%s, %s, %s", | |
| 375 | triangle->vaCoords[0].getStringRep ().chars(), | |
| 376 | triangle->vaCoords[1].getStringRep ().chars(), | |
| 377 | triangle->vaCoords[2].getStringRep ().chars()); | |
| 378 | } | |
| 379 | break; | |
| 380 | ||
| 381 | case OBJ_Quad: | |
| 382 | { | |
| 383 | LDQuad* quad = static_cast<LDQuad*> (obj); | |
|
10
5b0579997e9b
remove leading whitespace from comments when drawing them in the list
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
384 | zText.format ("%s, %s, %s, %s", |
| 0 | 385 | quad->vaCoords[0].getStringRep ().chars(), |
| 386 | quad->vaCoords[1].getStringRep ().chars(), | |
| 387 | quad->vaCoords[2].getStringRep ().chars(), | |
| 388 | quad->vaCoords[3].getStringRep ().chars()); | |
| 389 | } | |
| 390 | break; | |
| 391 | ||
| 392 | case OBJ_Gibberish: | |
| 393 | zText.format ("ERROR: %s", | |
|
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
394 | static_cast<LDGibberish*> (obj)->zContents.chars()); |
| 0 | 395 | break; |
| 396 | ||
| 397 | case OBJ_Vector: | |
| 398 | zText.format ("%s", static_cast<LDVector*> (obj)->vPos.getStringRep().chars()); | |
| 399 | break; | |
| 400 | ||
| 401 | case OBJ_Vertex: | |
| 402 | zText.format ("%s", static_cast<LDVertex*> (obj)->vPosition.getStringRep().chars()); | |
| 403 | break; | |
| 404 | ||
| 405 | default: | |
| 406 | zText = g_saObjTypeNames[obj->getType ()]; | |
| 407 | break; | |
| 408 | } | |
| 409 | ||
|
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
410 | QTreeWidgetItem* item = new QTreeWidgetItem ((QTreeWidget*) (nullptr), |
| 0 | 411 | QStringList (zText.chars()), 0); |
| 412 | item->setIcon (0, IconForObjectType (obj)); | |
| 413 | ||
|
11
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
414 | // Color gibberish red |
|
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
415 | if (obj->getType() == OBJ_Gibberish) { |
|
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
416 | item->setBackgroundColor (0, "#AA0000"); |
|
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
417 | item->setForeground (0, QColor ("#FFAA00")); |
|
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
418 | } |
|
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
419 | |
|
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
420 | obj->qObjListEntry = item; |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
421 | |
| 0 | 422 | qaItems.append (item); |
| 423 | } | |
| 424 | ||
| 425 | qObjList->insertTopLevelItems (0, qaItems); | |
|
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
426 | } |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
427 | |
|
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
428 | void LDForgeWindow::slot_selectionChanged () { |
|
17
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
429 | // If the selection isn't 1 exact, disable setting contents |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
430 | qAct_setContents->setEnabled (qObjList->selectedItems().size() == 1); |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
431 | } |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
432 | |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
433 | // ============================================================================= |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
434 | // ulong getInsertionPoint () |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
435 | // |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
436 | // Returns the index of where a new item should be placed at. |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
437 | // ============================================================================= |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
438 | ulong LDForgeWindow::getInsertionPoint () { |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
439 | ulong ulIndex; |
|
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
440 | |
|
17
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
441 | if (qObjList->selectedItems().size() == 1) { |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
442 | // If we have a selection, put the item after it. |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
443 | for (ulIndex = 0; ulIndex < g_CurrentFile->objects.size(); ++ulIndex) |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
444 | if (g_CurrentFile->objects[ulIndex]->qObjListEntry == qObjList->selectedItems()[0]) |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
445 | break; |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
446 | |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
447 | if (ulIndex >= g_CurrentFile->objects.size()) |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
448 | return ulIndex + 1; |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
449 | } |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
450 | |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
451 | // Otherwise place the object at the end. |
|
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
452 | return g_CurrentFile->objects.size(); |
| 0 | 453 | } |