# HG changeset patch # User Santeri Piippo # Date 1367875321 -10800 # Node ID f562323760a2c86fb37601079e18d32ff6c8e9dc # Parent 96691a009dff779641064c6b5989bc936a1566bd Added grouping basics - will be needed for ext programs (Intersector, Isecalc and a lot of others use 2 or more inputs, need to get all of those in somehow...) plus I think they can be useful for the actual authoring process diff -r 96691a009dff -r f562323760a2 common.h --- a/common.h Mon May 06 15:39:45 2013 +0300 +++ b/common.h Tue May 07 00:22:01 2013 +0300 @@ -129,11 +129,14 @@ static const double pi = 3.14159265358979323846f; +#ifdef IN_IDE_PARSER // KDevelop workaround +// Current function name +static const char* __func__ = ""; +#endif // IN_IDE_PARSER + // ----------------------------------------------------------------------------- enum LogType { LOG_Normal, - LOG_Success, - LOG_Info, LOG_Warning, LOG_Error, LOG_Dev, @@ -145,8 +148,6 @@ void logf (const char* fmtstr, ...) FORMAT_PRINTF (1, 2); void logf (LogType type, const char* fmtstr, ...) FORMAT_PRINTF (2, 3); void warnf (const char* fmtstr, ...) FORMAT_PRINTF (1, 2); -void infof (const char* fmtstr, ...) FORMAT_PRINTF (1, 2); -void succf (const char* fmtstr, ...) FORMAT_PRINTF (1, 2); void errf (const char* fmtstr, ...) FORMAT_PRINTF (1, 2); #ifndef RELEASE diff -r 96691a009dff -r f562323760a2 file.cpp --- a/file.cpp Mon May 06 15:39:45 2013 +0300 +++ b/file.cpp Tue May 07 00:22:01 2013 +0300 @@ -176,7 +176,7 @@ fclose (fp); g_loadedFiles.push_back (load); - logf (LOG_Success, "File %s parsed successfully (%lu warning%s).\n", + logf ("File %s parsed successfully (%lu warning%s).\n", path.chars(), numWarnings, PLURAL (numWarnings)); return load; diff -r 96691a009dff -r f562323760a2 gui.cpp --- a/gui.cpp Mon May 06 15:39:45 2013 +0300 +++ b/gui.cpp Tue May 07 00:22:01 2013 +0300 @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "common.h" #include "gldraw.h" @@ -44,6 +45,15 @@ extern_cfg (str, io_recentfiles); extern_cfg (bool, gl_axes); +const QColor g_GroupBackgrounds[] = { + QColor (0, 192, 255), // blue + QColor (144, 255, 0), // green + QColor (160, 64, 255), // purple + QColor (255, 128, 0), // orange +}; + +const ushort g_numGroups = 2; + // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= @@ -126,8 +136,8 @@ // ============================================================================= QMenu* g_CurrentMenu; -void ForgeWindow::initMenu (const char* name) { - g_CurrentMenu = menuBar ()->addMenu (tr (name)); +QMenu* ForgeWindow::initMenu (const char* name) { + return g_CurrentMenu = menuBar ()->addMenu (tr (name)); } void ForgeWindow::addMenuAction (const char* name) { @@ -195,6 +205,11 @@ addMenuAction ("selectAll"); // Select All addMenuAction ("selectByColor"); // Select by Color addMenuAction ("selectByType"); // Select by Type + menu->addSeparator (); // ----- + + for (uchar i = 0; i < LDObject::NumGroups; ++i) + addMenuAction (fmt ("group%c", 'A' + i)); // Group * + addMenuAction ("groupNone"); // No Group initMenu ("&Tools"); addMenuAction ("setColor"); // Set Color @@ -249,6 +264,7 @@ addMenuAction ("aboutQt"); // About Qt } + // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= @@ -382,6 +398,21 @@ initSingleToolBar ("External Programs"); addToolBarAction ("ytruder"); + initSingleToolBar ("Groups"); + + // We need to create the group toolbar buttons manually so that we can + // set a custom background for them. + for (uchar i = 0; i < LDObject::NumGroups; ++i) { + QToolButton* btn = new QToolButton (this); + QColor col = g_GroupBackgrounds[i]; + + btn->setDefaultAction (findAction (fmt ("group%c", 'A' + i))); + btn->setStyleSheet (fmt ("QToolButton { background-color: \"#%.2X%.2X%.2X\"; }", + col.red (), col.green (), col.blue ())); + g_CurrentToolBar->addWidget (btn); + } + + addToolBarAction ("groupNone"); updateToolBars (); } @@ -391,11 +422,11 @@ std::vector parseQuickColorMeta () { std::vector meta; - for (str zColor : gui_colortoolbar.value / ":") { - if (zColor == "|") { + for (str colorname : gui_colortoolbar.value / ":") { + if (colorname == "|") { meta.push_back ({null, null, true}); } else { - color* col = getColor (atoi (zColor)); + color* col = getColor (atoi (colorname)); meta.push_back ({col, null, false}); } } @@ -657,6 +688,8 @@ color* col = getColor (obj->dColor); if (col) item->setForeground (col->qColor); + } else if (obj->group () != LDObject::NoGroup) { + item->setBackground (g_GroupBackgrounds[obj->group ()]); } obj->qObjListEntry = item; @@ -954,16 +987,6 @@ zText.chars()); break; - case LOG_Info: - log.appendformat ("[INFO] %s", - zText.chars()); - break; - - case LOG_Success: - log.appendformat ("[SUCCESS] %s", - zText.chars()); - break; - case LOG_Warning: log.appendformat ("[WARNING] %s", zText.chars()); @@ -986,5 +1009,7 @@ if (name == meta.name) return *meta.qAct; + fprintf (stderr, "%s: couldn't find action named `%s'!\n", __func__, name.chars ()); + assert (false); return null; } \ No newline at end of file diff -r 96691a009dff -r f562323760a2 gui.h --- a/gui.h Mon May 06 15:39:45 2013 +0300 +++ b/gui.h Tue May 07 00:22:01 2013 +0300 @@ -174,7 +174,7 @@ void initSingleToolBar (const char* name); void addToolBarAction (const char* name); - void initMenu (const char* name); + QMenu* initMenu (const char* name); void addMenuAction (const char* name); private slots: diff -r 96691a009dff -r f562323760a2 gui_editactions.cpp --- a/gui_editactions.cpp Mon May 06 15:39:45 2013 +0300 +++ b/gui_editactions.cpp Tue May 07 00:22:01 2013 +0300 @@ -684,4 +684,28 @@ History::addEntry (new EditHistory (indices, oldCopies, newCopies)); g_win->refresh (); } +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +void setGroup (const LDObject::Group group) { + for (LDObject* obj : g_win->sel ()) + obj->setGroup (group); + + g_win->refresh (); +} + +#define GROUP_ACTION(N, KEY) \ + MAKE_ACTION (group##N, "Group " #N, "group", "Set group of selected objects to " #N, CTRL_SHIFT (KEY)) { \ + setGroup (LDObject::N); \ + } + +GROUP_ACTION (A, 1) +GROUP_ACTION (B, 2) +GROUP_ACTION (C, 3) +GROUP_ACTION (D, 4) + +MAKE_ACTION (groupNone, "No Group", "group-no", "Unset objects' group", CTRL_SHIFT (0)) { + setGroup (LDObject::NoGroup); } \ No newline at end of file diff -r 96691a009dff -r f562323760a2 icons/group.png Binary file icons/group.png has changed diff -r 96691a009dff -r f562323760a2 icons/ungroup.png Binary file icons/ungroup.png has changed diff -r 96691a009dff -r f562323760a2 ldforge.pro --- a/ldforge.pro Mon May 06 15:39:45 2013 +0300 +++ b/ldforge.pro Tue May 07 00:22:01 2013 +0300 @@ -34,11 +34,11 @@ zz_setContentsDialog.h SOURCES += \ + config.cpp \ + gui.cpp \ gldraw.cpp \ - gui.cpp \ bbox.cpp \ colors.cpp \ - config.cpp \ extprogs.cpp \ file.cpp \ gui_actions.cpp \ diff -r 96691a009dff -r f562323760a2 ldforge.qrc --- a/ldforge.qrc Mon May 06 15:39:45 2013 +0300 +++ b/ldforge.qrc Tue May 07 00:22:01 2013 +0300 @@ -47,6 +47,7 @@ ./icons/grid-coarse.png ./icons/grid-fine.png ./icons/grid-medium.png + ./icons/group.png ./icons/help.png ./icons/history.png ./icons/inline-deep.png @@ -81,6 +82,7 @@ ./icons/triangle.png ./icons/uncolorize.png ./icons/undo.png + ./icons/ungroup.png ./icons/vertex.png ./icons/ytruder.png ./docs/test2.html diff -r 96691a009dff -r f562323760a2 ldtypes.cpp --- a/ldtypes.cpp Mon May 06 15:39:45 2013 +0300 +++ b/ldtypes.cpp Tue May 07 00:22:01 2013 +0300 @@ -60,6 +60,7 @@ LDObject::LDObject () { qObjListEntry = null; parent = null; + m_group = NoGroup; } LDGibberish::LDGibberish (str _zContent, str _zReason) { @@ -655,7 +656,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= #define CHECK_FOR_OBJ(N) \ - if (type == LDObject::##N) \ + if (type == LDObject::N) \ return new LD##N; LDObject* LDObject::getDefault (const LDObject::Type type) { CHECK_FOR_OBJ (Comment) diff -r 96691a009dff -r f562323760a2 ldtypes.h --- a/ldtypes.h Mon May 06 15:39:45 2013 +0300 +++ b/ldtypes.h Tue May 07 00:22:01 2013 +0300 @@ -72,7 +72,13 @@ Unidentified, // Object is an uninitialized (SHOULD NEVER HAPPEN) NumTypes // Amount of object types }; - + + enum Group { + NoGroup = -1, + A = 0, B, C, D, + NumGroups + }; + LDObject (); virtual ~LDObject (); @@ -138,11 +144,14 @@ // Object list entry for this object QListWidgetItem* qObjListEntry; - uint32 groups () const { return m_groups; } - void setGroups (const uint32 groups) { m_groups = groups; } - + Group group () const { return m_group; } + void setGroup (const Group group) { m_group = group; } + bool hidden () const { return m_hidden; } + void setHidden (const bool hidden) { m_hidden = hidden; } + private: - uint32 m_groups; + Group m_group; + bool m_hidden; }; // ============================================================================= diff -r 96691a009dff -r f562323760a2 main.cpp --- a/main.cpp Mon May 06 15:39:45 2013 +0300 +++ b/main.cpp Tue May 07 00:22:01 2013 +0300 @@ -85,13 +85,6 @@ va_end (va); } -void succf (const char* fmtstr, ...) { - va_list va; - va_start (va, fmtstr); - g_win->logVA (LOG_Success, fmtstr, va); - va_end (va); -} - void errf (const char* fmtstr, ...) { va_list va; va_start (va, fmtstr); @@ -99,13 +92,6 @@ va_end (va); } -void infof (const char* fmtstr, ...) { - va_list va; - va_start (va, fmtstr); - g_win->logVA (LOG_Info, fmtstr, va); - va_end (va); -} - #ifndef RELEASE void devf (const char* fmtstr, ...) { va_list va;