Tue, 07 May 2013 15:07:23 +0300
Restructured the shortcut configuration tab a little, allowing it to be sorted.
file.cpp | file | annotate | diff | comparison | revisions | |
gui.cpp | file | annotate | diff | comparison | revisions | |
gui_actions.cpp | file | annotate | diff | comparison | revisions | |
ldtypes.h | file | annotate | diff | comparison | revisions | |
zz_addObjectDialog.cpp | file | annotate | diff | comparison | revisions | |
zz_configDialog.cpp | file | annotate | diff | comparison | revisions | |
zz_configDialog.h | file | annotate | diff | comparison | revisions |
--- a/file.cpp Tue May 07 01:16:58 2013 +0300 +++ b/file.cpp Tue May 07 15:07:23 2013 +0300 @@ -287,23 +287,20 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void openMainFile (str zPath) { +void openMainFile (str path) { closeAll (); - OpenFile* pFile = openDATFile (zPath, false); + OpenFile* file = openDATFile (path, false); - if (!pFile) { + if (!file) { // Tell the user loading failed. setlocale (LC_ALL, "C"); - QMessageBox::critical (g_win, "Load Failure", - fmt ("Failed to open %s\nReason: %s", zPath.chars(), strerror (errno)), - (QMessageBox::Close), QMessageBox::Close); - + critical (fmt ("Failed to open %s: %s", path.chars(), strerror (errno))); return; } - pFile->m_implicit = false; - g_curfile = pFile; + file->m_implicit = false; + g_curfile = file; // Recalculate the bounding box g_BBox.calculate(); @@ -311,9 +308,12 @@ // Rebuild the object tree view now. g_win->refresh (); g_win->setTitle (); + g_win->R ()->resetAngles (); + + History::clear (); // Add it to the recent files list. - addRecentFile (zPath); + addRecentFile (path); } // =============================================================================
--- a/gui.cpp Tue May 07 01:16:58 2013 +0300 +++ b/gui.cpp Tue May 07 15:07:23 2013 +0300 @@ -48,8 +48,10 @@ const QColor g_GroupBackgrounds[] = { QColor (0, 192, 255), // blue QColor (144, 255, 0), // green + QColor (255, 128, 0), // orange + QColor (255, 255, 0), // yellow QColor (160, 64, 255), // purple - QColor (255, 128, 0), // orange + QColor (0, 255, 160), // emerald }; const ushort g_numGroups = 2; @@ -203,17 +205,19 @@ addMenuAction ("del"); // Delete menu->addSeparator (); // ----- - for (uchar i = 0; i < LDObject::NumGroups; ++i) - addMenuAction (fmt ("group%c", 'A' + i)); // Group * - - addMenuAction ("ungroup"); // Ungroup - menu->addSeparator (); // ----- addMenuAction ("selectAll"); // Select All addMenuAction ("selectByColor"); // Select by Color addMenuAction ("selectByType"); // Select by Type + initMenu ("&Groups"); for (uchar i = 0; i < LDObject::NumGroups; ++i) - addMenuAction (fmt ("selGroup%c", 'A' + i)); // Select Group * + addMenuAction (fmt ("group%c", 'A' + i)); // Group * + + menu->addSeparator (); // ----- + addMenuAction ("ungroup"); // Ungroup + menu->addSeparator (); // ----- + for (uchar i = 0; i < LDObject::NumGroups; ++i) + addMenuAction (fmt ("selGroup%c", 'A' + i)); // Select Group * initMenu ("&Tools"); addMenuAction ("setColor"); // Set Color @@ -919,10 +923,11 @@ // ============================================================================= void ForgeWindow::spawnContextMenu (const QPoint pos) { const bool single = (g_win->sel ().size () == 1); + LDObject* singleObj = (single) ? g_win->sel ()[0] : null; QMenu* contextMenu = new QMenu; - if (single) { + if (single && singleObj->getType () != LDObject::Empty) { contextMenu->addAction (findAction ("editObject")); contextMenu->addSeparator (); } @@ -964,7 +969,7 @@ // ============================================================================= void critical (str msg) { - QMessageBox::critical (g_win, APPNAME ": Critical Error", msg, + QMessageBox::critical (g_win, "Critical Error", msg, (QMessageBox::Close), QMessageBox::Close); } @@ -972,47 +977,13 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= // Print to message log +// TODO: I don't think that the message log being a widget in the window +// is a very good idea... maybe this should log into the renderer? Or into +// another dialog that can be popped up? void ForgeWindow::logVA (LogType type, const char* fmtstr, va_list va) { - return; // FIXME: crashes for some reason o_O - - char* buf = vdynformat (fmtstr, va, 128); - str zText (buf); - delete[] buf; - - // Log it to standard output - printf ("%s", zText.chars ()); - - // Replace some things out with HTML entities - zText.replace ("<", "<"); - zText.replace (">", ">"); - zText.replace ("\n", "<br />"); - - str& log = m_msglogHTML; - - switch (type) { - case LOG_Normal: - log.append (zText); - break; - - case LOG_Error: - log.appendformat ("<span style=\"color: #F8F8F8; background-color: #800\"><b>[ERROR]</b> %s</span>", - zText.chars()); - break; - - case LOG_Warning: - log.appendformat ("<span style=\"color: #C50\"><b>[WARNING]</b> %s</span>", - zText.chars()); - break; - - case LOG_Dev: -#ifndef RELEASE - log.appendformat ("<span style=\"color: #0AC\"><b>[DEV]</b> %s</span>", - zText.chars()); -#endif // RELEASE - break; - } - - m_msglog->setHtml (log); + (void) type; + (void) fmtstr; + (void) va; } // =============================================================================
--- a/gui_actions.cpp Tue May 07 01:16:58 2013 +0300 +++ b/gui_actions.cpp Tue May 07 15:07:23 2013 +0300 @@ -414,21 +414,12 @@ // ============================================================================= void selGroup (const LDObject::Group group) { + g_win->sel ().clear (); + for (LDObject* obj : g_curfile->m_objs) { if (obj->group () != group) continue; // wrong group - bool selected = false; - for (LDObject* selobj : g_win->sel ()) { - if (selobj == obj) { - selected = true; - break; - } - } - - if (selected) - continue; // already selected - g_win->sel ().push_back (obj); } @@ -448,6 +439,8 @@ GROUP_ACTION (B, 2) GROUP_ACTION (C, 3) GROUP_ACTION (D, 4) +GROUP_ACTION (E, 5) +GROUP_ACTION (F, 6) MAKE_ACTION (ungroup, "Ungroup", "ungroup", "Unset the group of selected objects", CTRL_SHIFT (0)) { setGroup (LDObject::NoGroup);
--- a/ldtypes.h Tue May 07 01:16:58 2013 +0300 +++ b/ldtypes.h Tue May 07 15:07:23 2013 +0300 @@ -75,7 +75,7 @@ enum Group { NoGroup = -1, - A = 0, B, C, D, + A = 0, B, C, D, E, F, NumGroups };
--- a/zz_addObjectDialog.cpp Tue May 07 01:16:58 2013 +0300 +++ b/zz_addObjectDialog.cpp Tue May 07 15:07:23 2013 +0300 @@ -25,6 +25,7 @@ #include "colors.h" #include "zz_colorSelectDialog.h" #include "history.h" +#include "zz_setContentsDialog.h" #define APPLY_COORDS(OBJ, N) \ for (short i = 0; i < N; ++i) \ @@ -49,11 +50,6 @@ QDialog (parent) { short coordCount = 0; - QPixmap icon = getIcon (fmt ("add-%s", g_saObjTypeIcons[type])); - LDObject* defaults = LDObject::getDefault (type); - - lb_typeIcon = new QLabel; - lb_typeIcon->setPixmap (icon); switch (type) { case LDObject::Comment: @@ -179,9 +175,15 @@ break; default: - break; + return; } + QPixmap icon = getIcon (fmt ("add-%s", g_saObjTypeIcons[type])); + LDObject* defaults = LDObject::getDefault (type); + + lb_typeIcon = new QLabel; + lb_typeIcon->setPixmap (icon); + // Show a color edit dialog for the types that actually use the color if (defaults->isColored ()) { if (obj != null) @@ -337,6 +339,15 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void AddObjectDialog::staticDialog (const LDObject::Type type, LDObject* obj) { + // Redirect editing of gibberish to the set contents dialog + if (obj && obj->getType () == LDObject::Gibberish) { + SetContentsDialog::staticDialog (obj); + return; + } + + if (type == LDObject::Empty) + return; // Nothing to edit with empties + const bool newObject = (obj == null); AddObjectDialog dlg (type, obj);
--- a/zz_configDialog.cpp Tue May 07 01:16:58 2013 +0300 +++ b/zz_configDialog.cpp Tue May 07 15:07:23 2013 +0300 @@ -102,20 +102,24 @@ setButtonBackground (pb_viewBg, gl_bgcolor.value); connect (pb_viewBg, SIGNAL (clicked ()), this, SLOT (slot_setGLBackground ())); + pb_viewBg->setWhatsThis ("This is the background color for the viewport."); lb_viewFg = new QLabel ("Foreground color:"); pb_viewFg = new QPushButton; setButtonBackground (pb_viewFg, gl_maincolor.value); connect (pb_viewFg, SIGNAL (clicked ()), this, SLOT (slot_setGLForeground ())); + pb_viewFg->setWhatsThis ("This color is used for the main color."); // ========================================================================= // Alpha and line thickness sliders lb_viewFgAlpha = new QLabel ("Alpha:"); makeSlider (sl_viewFgAlpha, 1, 10, (gl_maincolor_alpha * 10.0f)); + sl_viewFgAlpha->setWhatsThis ("Opacity of main color in the viewport."); lb_lineThickness = new QLabel ("Line thickness:"); makeSlider (sl_lineThickness, 1, 8, gl_linethickness); + sl_lineThickness->setWhatsThis ("How thick lines should be drawn in the viewport."); // ========================================================================= // Tool bar icon size slider @@ -124,22 +128,34 @@ // ========================================================================= // List view colorizer and BFC red/green view checkboxes - cb_colorize = new QCheckBox ("Colorize polygons in list view"); - INIT_CHECKBOX (cb_colorize, lv_colorize) + cb_colorize = new QCheckBox ("Colorize polygons in object list"); + cb_colorize->setChecked (lv_colorize); + cb_colorize->setWhatsThis ("Makes colored objects (non-16 and 24) appear " + "colored in the object list. A red polygon will have its description " + "written in red text."); cb_colorBFC = new QCheckBox ("Red/green BFC view"); - INIT_CHECKBOX (cb_colorBFC, gl_colorbfc) + cb_colorBFC->setChecked (gl_colorbfc); + cb_colorBFC->setWhatsThis ("Polygons' front sides become green and back " + "sides red. Not implemented yet."); cb_selFlash = new QCheckBox ("Selection flash"); - INIT_CHECKBOX (cb_selFlash, gl_selflash) + cb_selFlash->setChecked (gl_selflash); + cb_colorBFC->setWhatsThis ("A pulse effect for clearer selection view."); cb_blackEdges = new QCheckBox ("Black edges"); - cb_blackEdges->setWhatsThis ("If this is set, all edgelines appear black. If this is " + cb_blackEdges->setWhatsThis ("Makes all edgelines appear black. If this is " "not set, edge lines take their color as defined in LDConfig.ldr"); - INIT_CHECKBOX (cb_blackEdges, gl_blackedges) + cb_blackEdges->setChecked (gl_blackedges); - cb_schemanticInline = new QCheckBox ("Only insert schemantic objects from a file"); - INIT_CHECKBOX (cb_schemanticInline, edit_schemanticinline) + cb_schemanticInline = new QCheckBox ("Schemantic insertion only"); + cb_schemanticInline->setChecked (edit_schemanticinline); + cb_colorBFC->setWhatsThis ("When inserting objects through inlining, file " + "inserting or through external programs, all non-schemantics (those without " + "actual meaning in the part file like comments and such) are filtered out."); + + cb_schemanticInline->setEnabled (false); + cb_colorBFC->setEnabled (false); QGridLayout* layout = new QGridLayout; layout->addWidget (lb_LDrawPath, 0, 0); @@ -187,18 +203,25 @@ // Init table items ulong i = 0; - for (actionmeta meta : g_ActionMeta) { - QAction* const qAct = *meta.qAct; + for (actionmeta& info : g_ActionMeta) { + QAction* const act = *info.qAct; + + ShortcutListItem* item = new ShortcutListItem; + setShortcutText (item, info); + item->setIcon (act->icon ()); + item->setActionInfo (&info); - QListWidgetItem* qItem = new QListWidgetItem; - setShortcutText (qItem, meta); - qItem->setIcon (qAct->icon ()); + // If the action doesn't have a valid icon, use an empty one + // so that the list is kept aligned. + if (act->icon ().isNull ()) + item->setIcon (getIcon ("empty")); - shortcutItems.push_back (qItem); - lw_shortcutList->insertItem (i, qItem); - ++i; + lw_shortcutList->insertItem (i++, item); } + lw_shortcutList->setSortingEnabled (true); + lw_shortcutList->sortItems (); + pb_setShortcut = new QPushButton ("Set"); pb_resetShortcut = new QPushButton ("Reset"); pb_clearShortcut = new QPushButton ("Clear"); @@ -454,14 +477,12 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void ConfigDialog::makeSlider (QSlider*& qSlider, short int dMin, short int dMax, - short dDefault) -{ - qSlider = new QSlider (Qt::Horizontal); - qSlider->setRange (dMin, dMax); - qSlider->setSliderPosition (dDefault); - qSlider->setTickPosition (QSlider::TicksAbove); - qSlider->setTickInterval (1); +void ConfigDialog::makeSlider (QSlider*& slider, short min, short max, short defval) { + slider = new QSlider (Qt::Horizontal); + slider->setRange (min, max); + slider->setSliderPosition (defval); + slider->setTickPosition (QSlider::TicksAbove); + slider->setTickInterval (1); } // ============================================================================= @@ -475,11 +496,11 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ConfigDialog::slot_findLDrawPath () { - str zDir = QFileDialog::getExistingDirectory (this, "Choose LDraw directory", + str dir = QFileDialog::getExistingDirectory (this, "Choose LDraw directory", le_LDrawPath->text()); - if (~zDir) - le_LDrawPath->setText (zDir.chars()); + if (~dir) + le_LDrawPath->setText (dir.chars()); } // ============================================================================= @@ -539,52 +560,54 @@ } // ============================================================================= +QList<ShortcutListItem*> ConfigDialog::getShortcutSelection () { + QList<ShortcutListItem*> out; + + for (QListWidgetItem* entry : lw_shortcutList->selectedItems ()) + out << static_cast<ShortcutListItem*> (entry); + + return out; +} + +// ============================================================================= void ConfigDialog::slot_setShortcut () { - QList<QListWidgetItem*> qaSel = lw_shortcutList->selectedItems (); + QList<ShortcutListItem*> sel = getShortcutSelection (); - if (qaSel.size() < 1) + if (sel.size() < 1) return; - QListWidgetItem* qItem = qaSel[0]; - - // Find the row this object is on. - long idx = getItemRow (qItem, shortcutItems); - - if (KeySequenceDialog::staticDialog (g_ActionMeta[idx], this)) - setShortcutText (qItem, g_ActionMeta[idx]); + ShortcutListItem* item = sel[0]; + if (KeySequenceDialog::staticDialog (*(item->getActionInfo ()), this)) + setShortcutText (item, *(item->getActionInfo ())); } // ============================================================================= void ConfigDialog::slot_resetShortcut () { - QList<QListWidgetItem*> qaSel = lw_shortcutList->selectedItems (); + QList<ShortcutListItem*> sel = getShortcutSelection (); - for (QListWidgetItem* qItem : qaSel) { - long idx = getItemRow (qItem, shortcutItems); - - actionmeta meta = g_ActionMeta[idx]; - keyseqconfig* conf = g_ActionMeta[idx].conf; + for (ShortcutListItem* item : sel) { + actionmeta* info = item->getActionInfo (); + keyseqconfig* conf = info->conf; conf->reset (); - (*meta.qAct)->setShortcut (*conf); + (*info->qAct)->setShortcut (*conf); - setShortcutText (qItem, meta); + setShortcutText (item, *info); } } // ============================================================================= void ConfigDialog::slot_clearShortcut () { - QList<QListWidgetItem*> qaSel = lw_shortcutList->selectedItems (); - QKeySequence qDummySeq; + QList<ShortcutListItem*> sel = getShortcutSelection (); + QKeySequence dummy; - for (QListWidgetItem* qItem : qaSel) { - long idx = getItemRow (qItem, shortcutItems); + for (ShortcutListItem* item : sel) { + actionmeta* info = item->getActionInfo (); + keyseqconfig* conf = info->conf; + conf->value = dummy; - actionmeta meta = g_ActionMeta[idx]; - keyseqconfig* conf = g_ActionMeta[idx].conf; - conf->value = qDummySeq; - - (*meta.qAct)->setShortcut (*conf); - setShortcutText (qItem, meta); + (*info->qAct)->setShortcut (*conf); + setShortcutText (item, *info); } } @@ -592,9 +615,9 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ConfigDialog::setShortcutText (QListWidgetItem* qItem, actionmeta meta) { - QAction* const qAct = *meta.qAct; - str zLabel = qAct->iconText (); - str zKeybind = qAct->shortcut ().toString (); + QAction* const act = *meta.qAct; + str zLabel = act->iconText (); + str zKeybind = act->shortcut ().toString (); qItem->setText (fmt ("%s (%s)", zLabel.chars () ,zKeybind.chars ()).chars()); } @@ -603,19 +626,19 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= str ConfigDialog::makeColorToolBarString () { - str zVal; + str val; for (quickColorMetaEntry entry : quickColorMeta) { - if (~zVal > 0) - zVal += ':'; + if (~val > 0) + val += ':'; if (entry.bSeparator) - zVal += '|'; + val += '|'; else - zVal.appendformat ("%d", entry.col->index ()); + val.appendformat ("%d", entry.col->index ()); } - return zVal; + return val; } // ============================================================================= @@ -627,11 +650,11 @@ if (dlg.exec ()) { io_ldpath = dlg.le_LDrawPath->text(); - APPLY_CHECKBOX (dlg.cb_colorize, lv_colorize) - APPLY_CHECKBOX (dlg.cb_colorBFC, gl_colorbfc) - APPLY_CHECKBOX (dlg.cb_selFlash, gl_selflash) - APPLY_CHECKBOX (dlg.cb_schemanticInline, edit_schemanticinline) - APPLY_CHECKBOX (dlg.cb_blackEdges, gl_blackedges) + lv_colorize = dlg.cb_colorize->isChecked (); + gl_colorbfc = dlg.cb_colorBFC->isChecked (); + gl_selflash = dlg.cb_selFlash->isChecked (); + edit_schemanticinline = dlg.cb_schemanticInline->isChecked (); + gl_blackedges = dlg.cb_blackEdges->isChecked (); gl_maincolor_alpha = ((double)dlg.sl_viewFgAlpha->value ()) / 10.0f; gl_linethickness = dlg.sl_lineThickness->value (); @@ -649,7 +672,7 @@ // Save the config config::save (); - // Reload all subfiles + // Reload all subfiles as the ldraw path potentially changed. reloadAllSubfiles (); g_win->R ()->setBackground ();
--- a/zz_configDialog.h Tue May 07 01:16:58 2013 +0300 +++ b/zz_configDialog.h Tue May 07 15:07:23 2013 +0300 @@ -29,6 +29,20 @@ #include <qlistwidget.h> #include <qspinbox.h> +// ============================================================================= +class ShortcutListItem : public QListWidgetItem { +public: + explicit ShortcutListItem (QListWidget* view = null, int type = Type) : + QListWidgetItem (view, type) {} + + actionmeta* getActionInfo () const { return m_info; } + void setActionInfo (actionmeta* info) { m_info = info; } + +private: + actionmeta* m_info; +}; + +// ============================================================================= class ConfigDialog : public QDialog { Q_OBJECT @@ -52,7 +66,6 @@ // Shortcuts tab QListWidget* lw_shortcutList; QPushButton* pb_setShortcut, *pb_resetShortcut, *pb_clearShortcut; - std::vector<QListWidgetItem*> shortcutItems; // ========================================================================= // Quick color toolbar tab @@ -82,7 +95,7 @@ void initGridTab (); void initExtProgTab (); - void makeSlider (QSlider*& qSlider, short int dMin, short int dMax, short int dDefault); + void makeSlider (QSlider*& slider, short min, short max, short defval); void setButtonBackground (QPushButton* qButton, str zValue); void pickColor (strconfig& cfg, QPushButton* qButton); void updateQuickColorList (quickColorMetaEntry* pSel = null); @@ -90,6 +103,7 @@ long getItemRow (QListWidgetItem* qItem, std::vector<QListWidgetItem*>& haystack); str makeColorToolBarString (); QListWidgetItem* getSelectedQuickColor (); + QList<ShortcutListItem*> getShortcutSelection (); private slots: void slot_findLDrawPath ();