Turned the test palette action into a set color action for mass object coloring.

Wed, 20 Mar 2013 21:19:35 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Wed, 20 Mar 2013 21:19:35 +0200
changeset 50
7fd213c6b844
parent 49
242f6ea0f5e5
child 51
94c434a56961

Turned the test palette action into a set color action for mass object coloring.

gui.cpp file | annotate | diff | comparison | revisions
gui.h file | annotate | diff | comparison | revisions
ldtypes.cpp file | annotate | diff | comparison | revisions
ldtypes.h file | annotate | diff | comparison | revisions
--- a/gui.cpp	Wed Mar 20 20:44:04 2013 +0200
+++ b/gui.cpp	Wed Mar 20 21:19:35 2013 +0200
@@ -92,6 +92,7 @@
 	MAKE_ACTION (copy,			"Copy",			"copy",			"Copy the current selection to clipboard.")
 	MAKE_ACTION (paste,			"Paste",		"paste",		"Paste clipboard contents.")
 	
+	MAKE_ACTION (setColor,		"Set Color",	"palette",		"Set the color on given objects.")
 	MAKE_ACTION (inline,		"Inline",		"inline",		"Inline selected subfiles.")
 	MAKE_ACTION (splitQuads,	"Split Quads",	"quad-split",	"Split quads into triangles.")
 	MAKE_ACTION (setContents,	"Set Contents",	"set-contents",	"Set the raw code of this object.")
@@ -110,8 +111,6 @@
 	MAKE_ACTION (about,			sAboutText,		"ldforge",		"Shows information about " APPNAME_DISPLAY ".")
 	MAKE_ACTION (aboutQt,		"About Qt",		"aboutQt",		"Shows information about Qt.")
 	
-	MAKE_ACTION (testColorSelect, "Test colors", "palette",		"Test the color selection dialog")
-	
 	// Keyboard shortcuts
 	qAct_new->setShortcut (Qt::CTRL | Qt::Key_N);
 	qAct_open->setShortcut (Qt::CTRL | Qt::Key_O);
@@ -167,6 +166,8 @@
 	qEditMenu->addAction (qAct_copy);			// Copy
 	qEditMenu->addAction (qAct_paste);			// Paste
 	qEditMenu->addSeparator ();					// -----
+	qEditMenu->addAction (qAct_setColor);		// Set Color
+	qEditMenu->addSeparator ();					// -----
 	qEditMenu->addAction (qAct_inline);			// Inline
 	qEditMenu->addAction (qAct_splitQuads);		// Split Quads
 	qEditMenu->addAction (qAct_setContents);	// Set Contents
@@ -204,10 +205,10 @@
 	qEditToolBar->addAction (qAct_cut);
 	qEditToolBar->addAction (qAct_copy);
 	qEditToolBar->addAction (qAct_paste);
+	qEditToolBar->addAction (qAct_setColor);
 	qEditToolBar->addAction (qAct_inline);
 	qEditToolBar->addAction (qAct_splitQuads);
 	qEditToolBar->addAction (qAct_setContents);
-	qEditToolBar->addAction (qAct_testColorSelect);
 	addToolBar (qEditToolBar);
 }
 
@@ -396,6 +397,48 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
+void ForgeWindow::slot_setColor () {
+	if (qObjList->selectedItems().size() <= 0)
+		return;
+	
+	short dColor;
+	short dDefault = -1;
+	
+	std::vector<LDObject*> objs = getSelectedObjects ();
+	
+	// Try to get a consensus on the color used for use as a default.
+	for (ulong i = 0; i < objs.size(); ++i) {
+		LDObject* obj = objs[i];
+		
+		if (obj->dColor == -1)
+			continue; // doesn't use colors
+		
+		if (dDefault != -1 && obj->dColor != dDefault) {
+			// No unanimosity in object color, therefore we don't have a
+			// proper default value to use.
+			dDefault = -1;
+			break;
+		}
+		
+		if (dDefault == -1)
+			dDefault = obj->dColor;
+	}
+	
+	// Show the dialog to the user now and ask him for a color.
+	if (ColorSelectDialog::staticDialog (dColor, dDefault, this)) {
+		for (ulong i = 0; i < objs.size(); ++i) {
+			LDObject* obj = objs[i];
+			if (obj->dColor != -1)
+				obj->dColor = dColor;
+		}
+		
+		refresh ();
+	}
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
 void ForgeWindow::buildObjList () {
 	if (!g_CurrentFile)
 		return;
@@ -548,9 +591,23 @@
 	R->hardRefresh ();
 }
 
-void ForgeWindow::slot_testColorSelect () {
-	short dColor;
-	if (ColorSelectDialog::staticDialog (dColor, -1, this)) {
-		printf ("you selected %s!\n", g_LDColors[dColor]->zName.chars());
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+std::vector<LDObject*> ForgeWindow::getSelectedObjects () {
+	std::vector<LDObject*> objs;
+	
+	QList<QTreeWidgetItem*> const qaItems = qObjList->selectedItems();
+	for (ulong i = 0; i < g_CurrentFile->objects.size(); ++i) {
+		LDObject* obj = g_CurrentFile->objects[i];
+		
+		for (long j = 0; j < qaItems.size(); ++j) {
+			if (qaItems[j] == obj->qObjListEntry) {
+				objs.push_back (obj);
+				break;
+			}
+		}
 	}
+	
+	return objs;
 }
\ No newline at end of file
--- a/gui.h	Wed Mar 20 20:44:04 2013 +0200
+++ b/gui.h	Wed Mar 20 21:19:35 2013 +0200
@@ -62,12 +62,13 @@
 	QAction* qAct_splitQuads, *qAct_setContents, *qAct_inline;
 	QAction* qAct_settings;
 	QAction* qAct_help, *qAct_about, *qAct_aboutQt;
-	QAction* qAct_testColorSelect;
+	QAction* qAct_setColor;
 	
 	ForgeWindow ();
 	void buildObjList ();
 	void setTitle ();
 	void refresh ();
+	std::vector<LDObject*> getSelectedObjects ();
 	
 	// Where would a new item be inserted into?
 	ulong getInsertionPoint ();
@@ -108,7 +109,7 @@
 	void slot_about ();
 	void slot_aboutQt ();
 	
-	void slot_testColorSelect ();
+	void slot_setColor ();
 };
 
 enum {
--- a/ldtypes.cpp	Wed Mar 20 20:44:04 2013 +0200
+++ b/ldtypes.cpp	Wed Mar 20 21:19:35 2013 +0200
@@ -61,21 +61,25 @@
 
 LDGibberish::LDGibberish () {
 	commonInit ();
+	dColor = -1;
 }
 
 LDGibberish::LDGibberish (str _zContent, str _zReason) {
 	zContents = _zContent;
 	zReason = _zReason;
+	dColor = -1;
 	
 	commonInit ();
 }
 
 LDEmpty::LDEmpty () {
 	commonInit ();
+	dColor = -1;
 }
 
 LDComment::LDComment () {
 	commonInit ();
+	dColor = -1;
 }
 
 LDSubfile::LDSubfile () {
--- a/ldtypes.h	Wed Mar 20 20:44:04 2013 +0200
+++ b/ldtypes.h	Wed Mar 20 21:19:35 2013 +0200
@@ -65,6 +65,10 @@
 	// Index (i.e. line number) of this object
 	unsigned long getIndex ();
 	
+	// Color used by this object. Comments, gibberish and empty entries
+	// do not use this field.
+	short dColor;
+	
 	// Type enumerator of this object
 	virtual LDObjectType_e getType () const {
 		return OBJ_Unidentified;
@@ -137,7 +141,6 @@
 public:
 	IMPLEMENT_LDTYPE (Subfile)
 	
-	short dColor; // Color used by the reference
 	vertex vPosition; // Position of the subpart
 	double faMatrix[9]; // Transformation matrix for the subpart
 	str zFileName; // Filename of the subpart
@@ -155,7 +158,6 @@
 public:
 	IMPLEMENT_LDTYPE (Line)
 	
-	short dColor; // Color of this line
 	vertex vaCoords[2]; // End points of this line
 };
 
@@ -169,7 +171,6 @@
 public:
 	IMPLEMENT_LDTYPE (CondLine)
 	
-	short dColor; // Color of this line
 	vertex vaCoords[4]; // End points + control points of this line
 };
 
@@ -184,7 +185,6 @@
 public:
 	IMPLEMENT_LDTYPE (Triangle)
 	
-	short dColor;
 	vertex vaCoords[3];
 	
 	LDTriangle (vertex _v0, vertex _v1, vertex _v2) {
@@ -204,7 +204,6 @@
 public:
 	IMPLEMENT_LDTYPE (Quad)
 	
-	short dColor;
 	vertex vaCoords[4];
 	
 	// Split this quad into two triangles
@@ -223,7 +222,6 @@
 public:
 	IMPLEMENT_LDTYPE (Vertex)
 	
-	short dColor;
 	vertex vPosition;
 };
 

mercurial