Added context menu and uncolorize action

Fri, 03 May 2013 20:26:25 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 03 May 2013 20:26:25 +0300
changeset 154
cc53e5cbad54
parent 153
03a7bdcce50d
child 155
e21c24bfcdf3

Added context menu and uncolorize action

gldraw.cpp file | annotate | diff | comparison | revisions
gldraw.h file | annotate | diff | comparison | revisions
gui.cpp file | annotate | diff | comparison | revisions
gui.h file | annotate | diff | comparison | revisions
gui_actions.cpp file | annotate | diff | comparison | revisions
gui_editactions.cpp file | annotate | diff | comparison | revisions
icons/round-coords.png file | annotate | diff | comparison | revisions
icons/uncolorize.png file | annotate | diff | comparison | revisions
zz_addObjectDialog.cpp file | annotate | diff | comparison | revisions
--- a/gldraw.cpp	Fri May 03 18:49:23 2013 +0300
+++ b/gldraw.cpp	Fri May 03 20:26:25 2013 +0300
@@ -754,6 +754,11 @@
 }
 
 // =============================================================================
+void GLRenderer::contextMenuEvent (QContextMenuEvent* ev) {
+	g_ForgeWindow->spawnContextMenu (ev->globalPos ());
+}
+
+// =============================================================================
 void GLRenderer::setCamera (const GLRenderer::Camera cam) {
 	m_camera = cam;
 	gl_camera = (int) cam;
--- a/gldraw.h	Fri May 03 18:49:23 2013 +0300
+++ b/gldraw.h	Fri May 03 20:26:25 2013 +0300
@@ -78,6 +78,7 @@
 	void wheelEvent (QWheelEvent* ev);
 	void paintEvent (QPaintEvent* ev);
 	void leaveEvent (QEvent* ev);
+	void contextMenuEvent (QContextMenuEvent* ev);
 
 private:
 	std::vector<GLuint> objLists;
--- a/gui.cpp	Fri May 03 18:49:23 2013 +0300
+++ b/gui.cpp	Fri May 03 20:26:25 2013 +0300
@@ -91,6 +91,8 @@
 EXTERN_ACTION (insertFrom)
 EXTERN_ACTION (insertRaw)
 EXTERN_ACTION (screencap)
+EXTERN_ACTION (editObject)
+EXTERN_ACTION (uncolorize)
 
 #ifndef RELEASE
 EXTERN_ACTION (addTestQuad)
@@ -240,15 +242,18 @@
 	qEditMenu->addAction (ACTION (selectByColor));		// Select by Color
 	qEditMenu->addAction (ACTION (selectByType));		// Select by Type
 	qEditMenu->addSeparator ();							// -----
-	qEditMenu->addAction (ACTION (setColor));			// Set Color
-	qEditMenu->addAction (ACTION (invert));				// Invert
-	qEditMenu->addAction (ACTION (inlineContents));		// Inline
-	qEditMenu->addAction (ACTION (deepInline));			// Deep Inline
-	qEditMenu->addAction (ACTION (splitQuads));			// Split Quads
-	qEditMenu->addAction (ACTION (setContents));			// Set Contents
-	qEditMenu->addAction (ACTION (makeBorders));			// Make Borders
-	qEditMenu->addAction (ACTION (makeCornerVerts));		// Make Corner Vertices
-	qEditMenu->addAction (ACTION (roundCoords));			// Round Coordinates
+	
+	QMenu* toolsMenu = menuBar ()->addMenu (tr ("&Tools"));
+	toolsMenu->addAction (ACTION (setColor));			// Set Color
+	toolsMenu->addAction (ACTION (invert));				// Invert
+	toolsMenu->addAction (ACTION (inlineContents));		// Inline
+	toolsMenu->addAction (ACTION (deepInline));			// Deep Inline
+	toolsMenu->addAction (ACTION (splitQuads));			// Split Quads
+	toolsMenu->addAction (ACTION (setContents));			// Set Contents
+	toolsMenu->addAction (ACTION (makeBorders));			// Make Borders
+	toolsMenu->addAction (ACTION (makeCornerVerts));		// Make Corner Vertices
+	toolsMenu->addAction (ACTION (roundCoords));			// Round Coordinates
+	toolsMenu->addAction (ACTION (uncolorize));			// Uncolorize
 	
 	// Move menu
 	qMoveMenu = menuBar ()->addMenu (tr ("&Move"));
@@ -394,7 +399,7 @@
 	// ==========================================
 	// Left area toolbars
 	//g_ToolBarArea = Qt::LeftToolBarArea;
-	initSingleToolBar ("Objects");
+	initSingleToolBar ("Tools");
 	g_CurrentToolBar->addAction (ACTION (setColor));
 	g_CurrentToolBar->addAction (ACTION (invert));
 	g_CurrentToolBar->addAction (ACTION (inlineContents));
@@ -405,6 +410,7 @@
 	g_CurrentToolBar->addAction (ACTION (makeCornerVerts));
 	g_CurrentToolBar->addAction (ACTION (roundCoords));
 	g_CurrentToolBar->addAction (ACTION (screencap));
+	g_CurrentToolBar->addAction (ACTION (uncolorize));
 	
 	updateToolBars ();
 }
@@ -652,8 +658,7 @@
 		case OBJ_Radial:
 			{
 				LDRadial* pRad = static_cast<LDRadial*> (obj);
-				zText.format ("%s: %d / %d %s", pRad->makeFileName ().chars (),
-					pRad->dSegments, pRad->dDivisions, pRad->radialTypeName());
+				zText.format ("%d / %d %s", pRad->dSegments, pRad->dDivisions, pRad->radialTypeName());
 				
 				if (pRad->eRadialType == LDRadial::Ring || pRad->eRadialType == LDRadial::Cone)
 					zText.appendformat (" %d", pRad->dRingNum);
@@ -905,9 +910,23 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
+void ForgeWindow::spawnContextMenu (const QPoint pos) {
+	QMenu* contextMenu = new QMenu;
+	contextMenu->addAction (ACTION (editObject));
+	contextMenu->addSeparator ();
+	contextMenu->addAction (ACTION (cut));
+	contextMenu->addAction (ACTION (copy));
+	contextMenu->addAction (ACTION (paste));
+	contextMenu->addAction (ACTION (del));
+	
+	ACTION (editObject)->setEnabled (g_ForgeWindow->sel.size () == 1);
+	
+	contextMenu->exec (pos);
+}
+
+// =============================================================================
 void ObjectList::contextMenuEvent (QContextMenuEvent* ev) {
-	Q_UNUSED (ev);
-	printf ("context menu!\n");
+	g_ForgeWindow->spawnContextMenu (ev->globalPos ());
 }
 
 // =============================================================================
--- a/gui.h	Fri May 03 18:49:23 2013 +0300
+++ b/gui.h	Fri May 03 20:26:25 2013 +0300
@@ -161,6 +161,7 @@
 	short getSelectedColor();
 	LDObjectType_e uniformSelectedType ();
 	void scrollToSelection ();
+	void spawnContextMenu (const QPoint pos);
 	
 protected:
 	void closeEvent (QCloseEvent* ev);
--- a/gui_actions.cpp	Fri May 03 18:49:23 2013 +0300
+++ b/gui_actions.cpp	Fri May 03 20:26:25 2013 +0300
@@ -154,6 +154,14 @@
 	AddObjectDialog::staticDialog (OBJ_Radial, null);
 }
 
+MAKE_ACTION (editObject, "Edit Object", "edit-object", "Edits this object.", 0) {
+	if (g_ForgeWindow->sel.size () != 1)
+		return;
+	
+	LDObject* obj = g_ForgeWindow->sel[0];
+	AddObjectDialog::staticDialog (obj->getType (), obj);
+}
+
 MAKE_ACTION (help, "Help", "help", "Shows the " APPNAME_DISPLAY " help manual.", KEY (F1)) {
 	
 }
--- a/gui_editactions.cpp	Fri May 03 18:49:23 2013 +0300
+++ b/gui_editactions.cpp	Fri May 03 20:26:25 2013 +0300
@@ -656,4 +656,28 @@
 		obj->vaCoords[i][ax] = atof (format ("%.3f", obj->vaCoords[i][ax]));
 	
 	g_ForgeWindow->refresh ();
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+MAKE_ACTION (uncolorize, "Uncolorize", "uncolorize", "Reduce colors from everything selected to main and edge colors", (0)) {
+	vector<LDObject*> oldCopies, newCopies;
+	vector<ulong> indices;
+	
+	for (LDObject* obj : g_ForgeWindow->sel) {
+		if (obj->isColored () == false)
+			continue;
+		
+		indices.push_back (obj->getIndex (g_CurrentFile));
+		oldCopies.push_back (obj->clone ());
+		
+		obj->dColor = (obj->getType () == OBJ_Line || obj->getType () == OBJ_CondLine) ? edgecolor : maincolor;
+		newCopies.push_back (obj->clone ());
+	}
+	
+	if (indices.size () > 0) {
+		History::addEntry (new EditHistory (indices, oldCopies, newCopies));
+		g_ForgeWindow->refresh ();
+	}
 }
\ No newline at end of file
Binary file icons/round-coords.png has changed
Binary file icons/uncolorize.png has changed
--- a/zz_addObjectDialog.cpp	Fri May 03 18:49:23 2013 +0300
+++ b/zz_addObjectDialog.cpp	Fri May 03 20:26:25 2013 +0300
@@ -88,6 +88,9 @@
 			
 			bb_bfcType->addButton (new QRadioButton (LDBFC::saStatements[i]));
 		}
+		
+		if (obj)
+			bb_bfcType->setValue ((int) static_cast<LDBFC*> (obj)->eStatement);
 		break;
 	
 	case OBJ_Subfile:
@@ -135,6 +138,11 @@
 		
 		connect (tw_subfileList, SIGNAL (itemSelectionChanged ()), this, SLOT (slot_subfileTypeChanged ()));
 		le_subfileName = new QLineEdit ();
+		
+		if (obj) {
+			LDSubfile* ref = static_cast<LDSubfile*> (obj);
+			le_subfileName->setText (ref->zFileName);
+		}
 		break;
 	
 	case OBJ_Radial:
@@ -180,7 +188,10 @@
 	
 	// Show a color edit dialog for the types that actually use the color
 	if (defaults->isColored ()) {
-		dColor = (type == OBJ_CondLine || type == OBJ_Line) ? edgecolor : maincolor;
+		if (obj != null)
+			dColor = obj->dColor;
+		else
+			dColor = (type == OBJ_CondLine || type == OBJ_Line) ? edgecolor : maincolor;
 		
 		pb_color = new QPushButton;
 		setButtonBackground (pb_color, dColor);
@@ -189,6 +200,7 @@
 	
 	for (short i = 0; i < coordCount; ++i) {
 		dsb_coords[i] = new QDoubleSpinBox;
+		dsb_coords[i]->setDecimals (5);
 		dsb_coords[i]->setMinimum (-10000.0);
 		dsb_coords[i]->setMaximum (10000.0);
 	}
@@ -229,7 +241,7 @@
 		
 		if (obj)
 			for (short i = 0; i < 3; ++i)
-				dsb_coords[0]->setValue (static_cast<LDRadial*> (obj)->vPosition.coord (i));
+				dsb_coords[i]->setValue (static_cast<LDRadial*> (obj)->vPosition.coord (i));
 		break;
 	
 	case OBJ_Subfile:
@@ -238,7 +250,7 @@
 		
 		if (obj)
 			for (short i = 0; i < 3; ++i)
-				dsb_coords[0]->setValue (static_cast<LDSubfile*> (obj)->vPosition.coord (i));
+				dsb_coords[i]->setValue (static_cast<LDSubfile*> (obj)->vPosition.coord (i));
 		break;
 	
 	default:
@@ -329,6 +341,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 void AddObjectDialog::staticDialog (const LDObjectType_e type, LDObject* obj) {
+	const bool newObject = (obj == null);
 	AddObjectDialog dlg (type, obj);
 	
 	if (obj)
@@ -337,6 +350,10 @@
 	if (dlg.exec () == false)
 		return;
 	
+	LDObject* backup = null;
+	if (!newObject)
+		backup = obj->clone ();
+	
 	switch (type) {
 	case OBJ_Comment:
 		{
@@ -432,8 +449,13 @@
 		break;
 	}
 	
-	ulong idx = g_ForgeWindow->getInsertionPoint ();
-	g_CurrentFile->insertObj (idx, obj);
-	History::addEntry (new AddHistory ({idx}, {obj->clone ()}));
+	if (newObject) {
+		ulong idx = g_ForgeWindow->getInsertionPoint ();
+		g_CurrentFile->insertObj (idx, obj);
+		History::addEntry (new AddHistory ({idx}, {obj->clone ()}));
+	} else {
+		History::addEntry (new EditHistory ({obj->getIndex (g_CurrentFile)}, {backup}, {obj->clone ()}));
+	}
+	
 	g_ForgeWindow->refresh ();
 }
\ No newline at end of file

mercurial