gui.cpp

changeset 169
f562323760a2
parent 168
96691a009dff
child 170
2247a32e63a8
--- 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

mercurial