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

Tue, 07 May 2013 00:22:01 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 07 May 2013 00:22:01 +0300
changeset 169
f562323760a2
parent 168
96691a009dff
child 170
2247a32e63a8

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

common.h file | annotate | diff | comparison | revisions
file.cpp file | annotate | diff | comparison | revisions
gui.cpp file | annotate | diff | comparison | revisions
gui.h file | annotate | diff | comparison | revisions
gui_editactions.cpp file | annotate | diff | comparison | revisions
icons/group.png file | annotate | diff | comparison | revisions
icons/ungroup.png file | annotate | diff | comparison | revisions
ldforge.pro file | annotate | diff | comparison | revisions
ldforge.qrc file | annotate | diff | comparison | revisions
ldtypes.cpp file | annotate | diff | comparison | revisions
ldtypes.h file | annotate | diff | comparison | revisions
main.cpp file | annotate | diff | comparison | revisions
--- 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
--- 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;
--- 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 <qstatusbar.h>
 #include <qsplitter.h>
 #include <qlistwidget.h>
+#include <qtoolbutton.h>
 #include <qcoreapplication.h>
 #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<quickColorMetaEntry> parseQuickColorMeta () {
 	std::vector<quickColorMetaEntry> 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 ("<span style=\"color: #0AC\"><b>[INFO]</b> %s</span>",
-			zText.chars());
-		break;
-	
-	case LOG_Success:
-		log.appendformat ("<span style=\"color: #6A0\"><b>[SUCCESS]</b> %s</span>",
-			zText.chars());
-		break;
-	
 	case LOG_Warning:
 		log.appendformat ("<span style=\"color: #C50\"><b>[WARNING]</b> %s</span>",
 			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
--- 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:
--- 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
Binary file icons/group.png has changed
Binary file icons/ungroup.png has changed
--- 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 \
--- 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 @@
 	<file>./icons/grid-coarse.png</file>
 	<file>./icons/grid-fine.png</file>
 	<file>./icons/grid-medium.png</file>
+	<file>./icons/group.png</file>
 	<file>./icons/help.png</file>
 	<file>./icons/history.png</file>
 	<file>./icons/inline-deep.png</file>
@@ -81,6 +82,7 @@
 	<file>./icons/triangle.png</file>
 	<file>./icons/uncolorize.png</file>
 	<file>./icons/undo.png</file>
+	<file>./icons/ungroup.png</file>
 	<file>./icons/vertex.png</file>
 	<file>./icons/ytruder.png</file>
 	<file>./docs/test2.html</file>
--- 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)
--- 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;
 };
 
 // =============================================================================
--- 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;

mercurial