Added color picker functionality to the context menu
authorDmitriy Morozov <morozov@cs.duke.edu>
Sat, 29 Jul 2006 23:25:10 -0400
changeset 6 8752e612ec07
parent 5 4928fc0f292d
child 10 240ec9bb3d92
Added color picker functionality to the context menu
VEFViewer.cpp
VEFViewer.h
--- a/VEFViewer.cpp	Mon Jun 19 09:00:02 2006 -0400
+++ b/VEFViewer.cpp	Sat Jul 29 23:25:10 2006 -0400
@@ -232,14 +232,16 @@
 }
 
 
-// QVertices
-void QVerticesLWI::draw() const
+// QDisplayListLWI
+void QDisplayListLWI::draw() const
 {
 	if (!isVisible()) return;
 		
-	glColor3f(.5, .65, .65);
+	glColor3f(color.redF(), color.greenF(), color.blueF());
 	glCallList(display_list);
 }
+
+// QVertices
 void QVerticesLWI::drawWithNames(int offset) const
 {}
 int QVerticesLWI::numElements() const
@@ -248,7 +250,7 @@
 {}
 
 QVerticesLWI::QVerticesLWI(QString name, FILE* file, VEFViewer* v): 
-	QDisplayListLWI(name)
+	QDisplayListLWI(name, QColor::fromRgbF(.5, .65, .65))
 {
 	display_list = glGenLists(1);
 	glNewList(display_list, GL_COMPILE);
@@ -276,7 +278,7 @@
 	// Draw selected
 	if (highlighted >= 0)
 	{
-	   	glColor3f(.9, .4, 0);
+		glColor3f(color.light(200).redF(), color.light(200).greenF(), color.light(200).blueF());
 		glBegin(GL_TRIANGLES);
 			const Triangle& t = triangles[highlighted];
 			glNormal3f(t.nx, t.ny, t.nz);
@@ -289,12 +291,12 @@
 	// Draw the object
 	if (!isWireframe())	
     {
-	    glColor3f(0., .4, .6);
+		glColor3f(color.light(150).redF(), color.light(150).greenF(), color.light(150).blueF());
 		glCallList(display_list);
     }
 	else
     {
-	    glColor3f(1., 0, 0);
+		glColor3f(color.redF(), color.greenF(), color.blueF());
 		glCallList(wireframe_display_list);
     }
 }
@@ -325,7 +327,7 @@
 }
 
 QFacesLWI::QFacesLWI(QString name, FILE* file, VEFViewer* v):
-	QDisplayListLWI(name), highlighted(-1), isWireframe_(false)
+	QDisplayListLWI(name, QColor::fromRgbF(0,.4,.6)), highlighted(-1), isWireframe_(false)
 {
 	float nx,ny,nz;			// not used
 	float x0,y0,z0;
@@ -404,13 +406,6 @@
 
 
 /* QEdges */
-void QEdgesLWI::draw() const
-{
-	if (!isVisible()) return;
-
-	glColor3f(.6, .2, .6);
-	glCallList(display_list);
-}
 void QEdgesLWI::drawWithNames(int offset) const
 {}
 int QEdgesLWI::numElements() const
@@ -419,7 +414,7 @@
 {}
 
 QEdgesLWI::QEdgesLWI(QString name, FILE* file, VEFViewer* v):
-	QDisplayListLWI(name)
+	QDisplayListLWI(name, QColor::fromRgbF(.6,.2,.6))
 {
 	display_list = glGenLists(1);
 	glNewList(display_list, GL_COMPILE);
--- a/VEFViewer.h	Mon Jun 19 09:00:02 2006 -0400
+++ b/VEFViewer.h	Sat Jul 29 23:25:10 2006 -0400
@@ -5,6 +5,7 @@
 #include <QFileDialog>
 #include <QListWidgetItem>
 #include <QMenu>
+#include <QColorDialog>
 
 class VEFViewer: public QGLViewer
 {
@@ -47,13 +48,13 @@
 	Q_OBJECT
 
 	public:
-		QDisplayListLWI(QString name):
-			QListWidgetItem(name), visible(false)
+		QDisplayListLWI(QString name, QColor color_):
+			QListWidgetItem(name), color(color_), visible(false)
 		{ toggleVisible(); }
 		GLuint getDisplayList() const	{ return display_list; }
 		~QDisplayListLWI()				{ glDeleteLists(display_list, 1); }
 
-		virtual void draw() const =0;
+		virtual void draw() const;
 		virtual void drawWithNames(int offset) const =0;
 		virtual int numElements() const =0;
 		virtual void highlight(int selected) =0;
@@ -63,6 +64,9 @@
 			connect(visible, SIGNAL(triggered()), this, SLOT(toggleVisible()));
 			visible->setCheckable(true);
 			visible->setChecked(isVisible());
+			
+			QAction* color = m.addAction("Pick color");
+			connect(color, SIGNAL(triggered()), this, SLOT(changeColor()));
 		}
 		
 		bool isVisible() const			{ return visible; }
@@ -70,10 +74,13 @@
 	public slots:
 		void setVisible(bool vis = true)	{ visible = !vis; adjustFont(); }
 		void toggleVisible()				{ visible = !visible; adjustFont(); }
+		void changeColor()					
+		{ QColor nw = QColorDialog::getColor(color); if (nw.isValid()) color = nw; }
 
 	protected:
 		GLuint display_list;
 		bool visible;
+		QColor color;
 
 	private:
 		void adjustFont()				{ QFont f; if (visible)	f.setBold(true); setFont(f); }
@@ -84,7 +91,6 @@
 {
 	public:
 		QVerticesLWI(QString name, FILE* file, VEFViewer* v);
-		virtual void draw() const;
 		virtual void drawWithNames(int offset) const;
 		virtual int numElements() const;
 		virtual void highlight(int selected);
@@ -136,7 +142,6 @@
 {
 	public:
 		QEdgesLWI(QString name, FILE* file, VEFViewer* v);
-		virtual void draw() const;
 		virtual void drawWithNames(int offset) const;
 		virtual int numElements() const;
 		virtual void highlight(int selected);