Switched the object list from a QTreeWidget to a QListWidget-derivative. Derivative because I'm going to add a context menu.

Fri, 03 May 2013 18:14:18 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 03 May 2013 18:14:18 +0300
changeset 151
15fe6c51de54
parent 150
bcbbdc5454e6
child 152
552e46650a95

Switched the object list from a QTreeWidget to a QListWidget-derivative. Derivative because I'm going to add a context menu.

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_editactions.cpp file | annotate | diff | comparison | revisions
ldtypes.h file | annotate | diff | comparison | revisions
zz_addObjectDialog.h file | annotate | diff | comparison | revisions
--- a/gldraw.cpp	Fri May 03 17:30:44 2013 +0300
+++ b/gldraw.cpp	Fri May 03 18:14:18 2013 +0300
@@ -742,6 +742,14 @@
 }
 
 // =============================================================================
+void GLRenderer::leaveEvent (QEvent* ev) {
+	Q_UNUSED (ev);
+	drawToolTip = false;
+	toolTipTimer->stop ();
+	update ();
+}
+
+// =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 void GLRenderer::updateSelFlash () {
--- a/gldraw.h	Fri May 03 17:30:44 2013 +0300
+++ b/gldraw.h	Fri May 03 18:14:18 2013 +0300
@@ -77,6 +77,7 @@
 	void keyReleaseEvent (QKeyEvent* ev);
 	void wheelEvent (QWheelEvent* ev);
 	void paintEvent (QPaintEvent* ev);
+	void leaveEvent (QEvent* ev);
 
 private:
 	std::vector<GLuint> objLists;
--- a/gui.cpp	Fri May 03 17:30:44 2013 +0300
+++ b/gui.cpp	Fri May 03 18:14:18 2013 +0300
@@ -22,6 +22,7 @@
 #include <qmenubar.h>
 #include <qstatusbar.h>
 #include <qsplitter.h>
+#include <qlistwidget.h>
 #include <qcoreapplication.h>
 #include "common.h"
 #include "gldraw.h"
@@ -112,11 +113,10 @@
 	g_ForgeWindow = this;
 	R = new GLRenderer;
 	
-	qObjList = new QTreeWidget;
-	qObjList->setHeaderHidden (true);
-	qObjList->setSelectionMode (QTreeWidget::ExtendedSelection);
-	qObjList->setAlternatingRowColors (true);
-	connect (qObjList, SIGNAL (itemSelectionChanged ()), this, SLOT (slot_selectionChanged ()));
+	objList = new ObjectList;
+	objList->setSelectionMode (QListWidget::ExtendedSelection);
+	objList->setAlternatingRowColors (true);
+	connect (objList, SIGNAL (itemSelectionChanged ()), this, SLOT (slot_selectionChanged ()));
 	
 	qMessageLog = new QTextEdit;
 	qMessageLog->setReadOnly (true);
@@ -124,7 +124,7 @@
 	
 	hsplit = new QSplitter;
 	hsplit->addWidget (R);
-	hsplit->addWidget (qObjList);
+	hsplit->addWidget (objList);
 	
 	vsplit = new QSplitter (Qt::Vertical);
 	vsplit->addWidget (hsplit);
@@ -557,12 +557,10 @@
 	
 	// Lock the selection while we do this so that refreshing the object list
 	// doesn't trigger selection updating so that the selection doesn't get lost
-	// while this is done
+	// while this is done.
 	g_bSelectionLocked = true;
 	
-	QList<QTreeWidgetItem*> qaItems;
-	
-	qObjList->clear ();
+	objList->clear ();
 	
 	for (LDObject* obj : g_CurrentFile->objects) {
 		str zText;
@@ -669,33 +667,27 @@
 			break;
 		}
 		
-		QTreeWidgetItem* item = new QTreeWidgetItem ((QTreeWidget*) (null),
-			QStringList (zText.chars()), 0);
-		item->setIcon (0, getIcon (g_saObjTypeIcons[obj->getType ()]));
+		QListWidgetItem* item = new QListWidgetItem (zText.chars());
+		item->setIcon (getIcon (g_saObjTypeIcons[obj->getType ()]));
 		
 		// Color gibberish orange on red so it stands out.
 		if (obj->getType() == OBJ_Gibberish) {
-			item->setBackground (0, QColor ("#AA0000"));
-			item->setForeground (0, QColor ("#FFAA00"));
-		} else if (lv_colorize &&
-			obj->dColor != -1 &&
-			obj->dColor != maincolor &&
-			obj->dColor != edgecolor)
+			item->setBackground (QColor ("#AA0000"));
+			item->setForeground (QColor ("#FFAA00"));
+		} else if (lv_colorize && obj->dColor != -1 &&
+			obj->dColor != maincolor && obj->dColor != edgecolor)
 		{
 			// If the object isn't in the main or edge color, draw this
 			// list entry in said color.
 			color* col = getColor (obj->dColor);
 			if (col)
-				item->setForeground (0, col->qColor);
+				item->setForeground (col->qColor);
 		}
 		
 		obj->qObjListEntry = item;
-		
-		qaItems.append (item);
+		objList->insertItem (objList->count (), item);
 	}
 	
-	qObjList->insertTopLevelItems (0, qaItems);
-	
 	g_bSelectionLocked = false;
 	updateSelection ();
 }
@@ -708,7 +700,7 @@
 		return;
 	
 	LDObject* obj = sel[sel.size () - 1];
-	qObjList->scrollToItem (obj->qObjListEntry);
+	objList->scrollToItem (obj->qObjListEntry);
 }
 
 // =============================================================================
@@ -815,10 +807,10 @@
 	if (g_CurrentFile == nullptr)
 		return objs;
 	
-	QList<QTreeWidgetItem*> const qaItems = qObjList->selectedItems ();
+	QList<QListWidgetItem*> const qaItems = objList->selectedItems ();
 	
 	for (LDObject* obj : g_CurrentFile->objects)
-	for (QTreeWidgetItem* qItem : qaItems) {
+	for (QListWidgetItem* qItem : qaItems) {
 		if (qItem == obj->qObjListEntry) {
 			objs.push_back (obj);
 			break;
@@ -834,7 +826,7 @@
 void ForgeWindow::updateSelection () {
 	g_bSelectionLocked = true;
 	
-	qObjList->clearSelection ();
+	objList->clearSelection ();
 	for (LDObject* obj : sel)
 		obj->qObjListEntry->setSelected (true);
 	
@@ -913,6 +905,14 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
+void ObjectList::contextMenuEvent (QContextMenuEvent* ev) {
+	Q_UNUSED (ev);
+	printf ("context menu!\n");
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
 QIcon getIcon (const char* sIconName) {
 	return (QIcon (format ("./icons/%s.png", sIconName)));
 }
--- a/gui.h	Fri May 03 17:30:44 2013 +0300
+++ b/gui.h	Fri May 03 18:14:18 2013 +0300
@@ -23,10 +23,10 @@
 #include <QMenu>
 #include <QToolBar>
 #include <QAction>
-#include <QTreeWidget>
 #include <QToolBar>
 #include <QTextEdit>
 #include <qpushbutton.h>
+#include <qlistwidget.h>
 #include "gldraw.h"
 #include "config.h"
 
@@ -96,6 +96,18 @@
 };
 
 // =============================================================================
+// ObjectList
+// 
+// Object list class for ForgeWindow
+// =============================================================================
+class ObjectList : public QListWidget {
+	Q_OBJECT
+	
+protected:
+	void contextMenuEvent (QContextMenuEvent* ev);
+};
+
+// =============================================================================
 // ForgeWindow
 // 
 // The one main GUI class. Hosts the renderer, object list, message log. Contains
@@ -109,7 +121,7 @@
 	GLRenderer* R;
 	
 	// Object list view
-	QTreeWidget* qObjList;
+	ObjectList* objList;
 	QTextEdit* qMessageLog;
 	QMenu* qFileMenu, *qEditMenu, *qViewMenu, *qInsertMenu, *qMoveMenu,
 		*qHelpMenu, *qControlMenu;
--- a/gui_editactions.cpp	Fri May 03 17:30:44 2013 +0300
+++ b/gui_editactions.cpp	Fri May 03 18:14:18 2013 +0300
@@ -223,7 +223,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 MAKE_ACTION (setContents, "Set Contents", "set-contents", "Set the raw code of this object.", KEY (F9)) {
-	if (g_ForgeWindow->qObjList->selectedItems().size() != 1)
+	if (g_ForgeWindow->objList->selectedItems().size() != 1)
 		return;
 	
 	LDObject* obj = g_ForgeWindow->sel[0];
@@ -234,7 +234,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 MAKE_ACTION (setColor, "Set Color", "palette", "Set the color on given objects.", KEY (F10)) {
-	if (g_ForgeWindow->qObjList->selectedItems().size() <= 0)
+	if (g_ForgeWindow->objList->selectedItems().size() <= 0)
 		return;
 	
 	short dColor;
--- a/ldtypes.h	Fri May 03 17:30:44 2013 +0300
+++ b/ldtypes.h	Fri May 03 18:14:18 2013 +0300
@@ -37,7 +37,7 @@
 
 #define LDOBJ_COLORED(V) virtual bool isColored () const { return V; }
 
-class QTreeWidgetItem;
+class QListWidgetItem;
 class LDSubfile;
 
 // =============================================================================
@@ -134,7 +134,8 @@
 	static void moveObjects (std::vector<LDObject*> objs, const bool bUp);
 	static str objectListContents (const std::vector<LDObject*>& objs);
 	
-	QTreeWidgetItem* qObjListEntry;
+	// Object list entry for this object
+	QListWidgetItem* qObjListEntry;
 };
 
 // =============================================================================
--- a/zz_addObjectDialog.h	Fri May 03 17:30:44 2013 +0300
+++ b/zz_addObjectDialog.h	Fri May 03 18:14:18 2013 +0300
@@ -29,6 +29,7 @@
 #include <qlabel.h>
 #include <qradiobutton.h>
 #include <qlistwidget.h>
+#include <qtreewidget.h>
 
 class AddObjectDialog : public QDialog {
 	Q_OBJECT

mercurial