Compile the icon resources to a QRC file, so that they are embedded in the application

Sat, 04 May 2013 04:19:03 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 04 May 2013 04:19:03 +0300
changeset 158
499286fcbf37
parent 157
635da3135bd4
child 159
7afedbbefeb0

Compile the icon resources to a QRC file, so that they are embedded in the application

gldraw.cpp file | annotate | diff | comparison | revisions
gui.cpp file | annotate | diff | comparison | revisions
gui.h file | annotate | diff | comparison | revisions
ldforge.pro file | annotate | diff | comparison | revisions
ldforge.qrc file | annotate | diff | comparison | revisions
mkqrc.sh file | annotate | diff | comparison | revisions
zz_aboutDialog.cpp file | annotate | diff | comparison | revisions
zz_addObjectDialog.cpp file | annotate | diff | comparison | revisions
zz_colorSelectDialog.cpp file | annotate | diff | comparison | revisions
zz_configDialog.cpp file | annotate | diff | comparison | revisions
zz_newPartDialog.cpp file | annotate | diff | comparison | revisions
zz_setContentsDialog.cpp file | annotate | diff | comparison | revisions
--- a/gldraw.cpp	Sat May 04 02:52:33 2013 +0300
+++ b/gldraw.cpp	Sat May 04 04:19:03 2013 +0300
@@ -101,11 +101,11 @@
 	
 	// Init camera icons
 	for (const GLRenderer::Camera cam : g_Cameras) {
-		str path;
-		path.format ("./icons/camera-%s.png", str (g_CameraNames[cam]).tolower ().chars ());
+		str iconname;
+		iconname.format ("camera-%s", str (g_CameraNames[cam]).tolower ().chars ());
 		
 		CameraIcon* info = &g_CameraIcons[cam];
-		info->img = new QPixmap (path);
+		info->img = new QPixmap (getIcon (iconname));
 		info->cam = cam;
 	}
 	
--- a/gui.cpp	Sat May 04 02:52:33 2013 +0300
+++ b/gui.cpp	Sat May 04 04:19:03 2013 +0300
@@ -146,7 +146,7 @@
 	slot_selectionChanged ();
 	
 	setStatusBar (new QStatusBar);
-	setWindowIcon (QIcon ("icons/ldforge.png"));
+	setWindowIcon (getIcon ("ldforge"));
 	setTitle ();
 	setMinimumSize (320, 200);
 	resize (800, 600);
@@ -955,8 +955,8 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-QIcon getIcon (const char* sIconName) {
-	return (QIcon (format ("./icons/%s.png", sIconName)));
+QPixmap getIcon (const char* sIconName) {
+	return (QPixmap (format (":/icons/%s.png", sIconName)));
 }
 
 // =============================================================================
--- a/gui.h	Sat May 04 02:52:33 2013 +0300
+++ b/gui.h	Sat May 04 04:19:03 2013 +0300
@@ -182,7 +182,7 @@
 
 // -----------------------------------------------------------------------------
 // Other GUI-related stuff not directly part of ForgeWindow:
-QIcon getIcon (const char* sIconName);
+QPixmap getIcon (const char* sIconName);
 std::vector<quickColorMetaEntry> parseQuickColorMeta ();
 bool confirm (str title, str msg);
 bool confirm (str msg);
--- a/ldforge.pro	Sat May 04 02:52:33 2013 +0300
+++ b/ldforge.pro	Sat May 04 04:19:03 2013 +0300
@@ -8,6 +8,7 @@
 INCLUDEPATH += .
 OBJECTS_DIR = build/
 RC_FILE = ldforge.rc
+RESOURCES = ldforge.qrc
 
 # Input
 HEADERS += bbox.h \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ldforge.qrc	Sat May 04 04:19:03 2013 +0300
@@ -0,0 +1,89 @@
+<!DOCTYPE RCC>
+<RCC version="1.0">
+<qresource>
+	<file>./icons/add-bfc.png</file>
+	<file>./icons/add-comment.png</file>
+	<file>./icons/add-condline.png</file>
+	<file>./icons/add-line.png</file>
+	<file>./icons/add-quad.png</file>
+	<file>./icons/add-radial.png</file>
+	<file>./icons/add-subfile.png</file>
+	<file>./icons/add-triangle.png</file>
+	<file>./icons/add-vertex.png</file>
+	<file>./icons/arrow-down.png</file>
+	<file>./icons/arrow-left.png</file>
+	<file>./icons/arrow-right.png</file>
+	<file>./icons/arrow-up.png</file>
+	<file>./icons/axes.png</file>
+	<file>./icons/bfc.png</file>
+	<file>./icons/brick-new.png</file>
+	<file>./icons/brick.png</file>
+	<file>./icons/camera-back.png</file>
+	<file>./icons/camera-bottom.png</file>
+	<file>./icons/camera-free.png</file>
+	<file>./icons/camera-front.png</file>
+	<file>./icons/camera-left.png</file>
+	<file>./icons/camera-right.png</file>
+	<file>./icons/camera-top.png</file>
+	<file>./icons/checkerboard.png</file>
+	<file>./icons/colorcursor.png</file>
+	<file>./icons/colorselect.png</file>
+	<file>./icons/comment.png</file>
+	<file>./icons/condline.png</file>
+	<file>./icons/copy.png</file>
+	<file>./icons/corner-verts.png</file>
+	<file>./icons/cut.png</file>
+	<file>./icons/delete.png</file>
+	<file>./icons/del-line.png</file>
+	<file>./icons/empty.png</file>
+	<file>./icons/error.png</file>
+	<file>./icons/exit.png</file>
+	<file>./icons/file-new.png</file>
+	<file>./icons/file-open.png</file>
+	<file>./icons/file.png</file>
+	<file>./icons/file-save-as.png</file>
+	<file>./icons/file-save.png</file>
+	<file>./icons/folder.png</file>
+	<file>./icons/grid-coarse.png</file>
+	<file>./icons/grid-fine.png</file>
+	<file>./icons/grid-medium.png</file>
+	<file>./icons/help.png</file>
+	<file>./icons/history.png</file>
+	<file>./icons/inline-deep.png</file>
+	<file>./icons/inline.png</file>
+	<file>./icons/ldforge.ico</file>
+	<file>./icons/ldforge.png</file>
+	<file>./icons/line.png</file>
+	<file>./icons/mail.png</file>
+	<file>./icons/make-borders.png</file>
+	<file>./icons/move-x-neg.png</file>
+	<file>./icons/move-x-pos.png</file>
+	<file>./icons/move-y-neg.png</file>
+	<file>./icons/move-y-pos.png</file>
+	<file>./icons/move-z-neg.png</file>
+	<file>./icons/move-z-pos.png</file>
+	<file>./icons/open-recent.png</file>
+	<file>./icons/palette.png</file>
+	<file>./icons/paste.png</file>
+	<file>./icons/qt.png</file>
+	<file>./icons/quad.png</file>
+	<file>./icons/quad-split.png</file>
+	<file>./icons/radial.png</file>
+	<file>./icons/redo.png</file>
+	<file>./icons/round-coords.png</file>
+	<file>./icons/screencap.png</file>
+	<file>./icons/select-all.png</file>
+	<file>./icons/select-color.png</file>
+	<file>./icons/select-type.png</file>
+	<file>./icons/set-contents.png</file>
+	<file>./icons/settings.png</file>
+	<file>./icons/subfile.png</file>
+	<file>./icons/triangle.png</file>
+	<file>./icons/uncolorize.png</file>
+	<file>./icons/undo.png</file>
+	<file>./icons/vertex.png</file>
+	<file>./docs/test2.html</file>
+	<file>./docs/test.html</file>
+	<file>LICENSE</file>
+</qresource>
+</RCC>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mkqrc.sh	Sat May 04 04:19:03 2013 +0300
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+QRCFILE=ldforge.qrc
+printf "" > $QRCFILE
+
+printf "<!DOCTYPE RCC>\n<RCC version=\"1.0\">\n<qresource>\n" >> $QRCFILE
+
+for img in ./icons/*.* ./docs/*.* LICENSE; do
+	printf "\t<file>$img</file>\n" >> $QRCFILE
+done
+
+printf "</qresource>\n</RCC>\n" >> $QRCFILE
\ No newline at end of file
--- a/zz_aboutDialog.cpp	Sat May 04 02:52:33 2013 +0300
+++ b/zz_aboutDialog.cpp	Sat May 04 04:19:03 2013 +0300
@@ -34,7 +34,7 @@
 		
 		// Application icon - in full 64 x 64 glory.
 		QLabel* icon = new QLabel;
-		icon->setPixmap (QPixmap ("icons/ldforge.png"));
+		icon->setPixmap (getIcon ("ldforge"));
 		
 		// Heading - application label and copyright information
 		QLabel* title = new QLabel (format ("<b>" APPNAME_DISPLAY " v%d.%d</b><br />"
--- a/zz_addObjectDialog.cpp	Sat May 04 02:52:33 2013 +0300
+++ b/zz_addObjectDialog.cpp	Sat May 04 04:19:03 2013 +0300
@@ -49,11 +49,11 @@
 	QDialog (parent)
 {
 	short coordCount = 0;
-	str iconName = format ("icons/add-%s.png", g_saObjTypeIcons[type]);
+	QPixmap icon = getIcon (format ("add-%s", g_saObjTypeIcons[type]));
 	LDObject* defaults = LDObject::getDefault (type);
 	
 	lb_typeIcon = new QLabel;
-	lb_typeIcon->setPixmap (QPixmap (iconName));
+	lb_typeIcon->setPixmap (icon);
 	
 	switch (type) {
 	case OBJ_Comment:
@@ -274,7 +274,7 @@
 	setWindowTitle (format (APPNAME_DISPLAY ": New %s",
 		g_saObjTypeNames[type]).chars());
 	
-	setWindowIcon (QIcon (iconName.chars ()));
+	setWindowIcon (icon);
 	delete defaults;
 }
 
@@ -282,7 +282,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 void AddObjectDialog::setButtonBackground (QPushButton* button, short color) {
-	button->setIcon (QIcon ("icons/palette.png"));
+	button->setIcon (getIcon ("palette"));
 	button->setAutoFillBackground (true);
 	button->setStyleSheet (
 		format ("background-color: %s", getColor (color)->zColorString.chars()).chars()
--- a/zz_colorSelectDialog.cpp	Sat May 04 02:52:33 2013 +0300
+++ b/zz_colorSelectDialog.cpp	Sat May 04 04:19:03 2013 +0300
@@ -53,7 +53,7 @@
 	selColor = dDefault;
 	
 	// not really an icon but eh
-	gs_scene->setBackgroundBrush (QPixmap ("icons/checkerboard.png"));
+	gs_scene->setBackgroundBrush (getIcon ("checkerboard"));
 	
 	gs_scene->setSceneRect (0, 0, g_lWidth, g_lMaxHeight);
 	gv_view->setSceneRect (0, 0, g_lWidth, g_lMaxHeight);
@@ -86,8 +86,8 @@
 	qLayout->addWidget (bbx_buttons);
 	setLayout (qLayout);
 	
-	setWindowIcon (QIcon ("icons/palette.png"));
-	setWindowTitle (APPNAME_DISPLAY " - choose a color");
+	setWindowIcon (getIcon ("palette"));
+	setWindowTitle (APPNAME_DISPLAY);
 }
 
 // =============================================================================
@@ -125,7 +125,7 @@
 		
 		if (i == selColor) {
 			QGraphicsPixmapItem* qCursorPic;
-			qCursorPic = gs_scene->addPixmap (QPixmap ("icons/colorcursor.png"));
+			qCursorPic = gs_scene->addPixmap (getIcon ("colorcursor"));
 			qCursorPic->setPos (x, y);
 		}
 	}
--- a/zz_configDialog.cpp	Sat May 04 02:52:33 2013 +0300
+++ b/zz_configDialog.cpp	Sat May 04 04:19:03 2013 +0300
@@ -70,7 +70,7 @@
 	setLayout (layout);
 	
 	setWindowTitle (APPNAME_DISPLAY " - Settings");
-	setWindowIcon (QIcon ("icons/settings.png"));
+	setWindowIcon (getIcon ("settings"));
 }
 
 // =============================================================================
@@ -87,7 +87,7 @@
 	le_LDrawPath->setText (io_ldpath.value.chars());
 	
 	pb_findLDrawPath = new QPushButton;
-	pb_findLDrawPath->setIcon (QIcon ("icons/folder.png"));
+	pb_findLDrawPath->setIcon (getIcon ("folder"));
 	connect (pb_findLDrawPath, SIGNAL (clicked ()),
 		this, SLOT (slot_findLDrawPath ()));
 	
@@ -286,7 +286,7 @@
 	for (int i = 0; i < g_NumGrids; ++i) {
 		// Icon
 		lb_gridIcons[i] = new QLabel;
-		lb_gridIcons[i]->setPixmap (QPixmap (format ("icons/grid-%s", str (g_GridInfo[i].name).tolower ().chars ())));
+		lb_gridIcons[i]->setPixmap (getIcon (format ("grid-%s", str (g_GridInfo[i].name).tolower ().chars ())));
 		
 		// Text label
 		lb_gridLabels[i] = new QLabel (format ("%s:", g_GridInfo[i].name));
@@ -478,7 +478,7 @@
 // =============================================================================
 void ConfigDialog::pickColor (strconfig& cfg, QPushButton* qButton) {
 	QColorDialog dlg (QColor (cfg.value.chars()));
-	dlg.setWindowIcon (QIcon ("icons/colorselect.png"));
+	dlg.setWindowIcon (getIcon ("colorselect"));
 	
 	if (dlg.exec ()) {
 		uchar r = dlg.currentColor ().red (),
@@ -501,7 +501,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 void ConfigDialog::setButtonBackground (QPushButton* qButton, str zValue) {
-	qButton->setIcon (QIcon ("icons/colorselect.png"));
+	qButton->setIcon (getIcon ("colorselect"));
 	qButton->setAutoFillBackground (true);
 	qButton->setStyleSheet (
 		format ("background-color: %s", zValue.chars()).chars()
--- a/zz_newPartDialog.cpp	Sat May 04 02:52:33 2013 +0300
+++ b/zz_newPartDialog.cpp	Sat May 04 04:19:03 2013 +0300
@@ -39,7 +39,7 @@
 // =============================================================================
 NewPartDialog::NewPartDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) {
 	lb_brickIcon = new QLabel;
-	lb_brickIcon->setPixmap (QPixmap ("icons/brick.png"));
+	lb_brickIcon->setPixmap (getIcon ("brick"));
 	
 	lb_name = new QLabel ("Name:");
 	le_name = new QLineEdit;
@@ -76,8 +76,8 @@
 	layout->addWidget (bbx_buttons, 3, 2);
 	
 	setLayout (layout);
-	setWindowIcon (QIcon ("icons/brick.png"));
-	setWindowTitle (APPNAME_DISPLAY " - new part");
+	setWindowIcon (getIcon ("brick"));
+	setWindowTitle (APPNAME_DISPLAY ": New Part");
 }
 
 // =============================================================================
--- a/zz_setContentsDialog.cpp	Sat May 04 02:52:33 2013 +0300
+++ b/zz_setContentsDialog.cpp	Sat May 04 04:19:03 2013 +0300
@@ -45,7 +45,7 @@
 		lb_error->setText (format ("<span style=\"color: #900\">%s</span>",
 			static_cast<LDGibberish*> (obj)->zReason.chars()));
 		
-		QPixmap qErrorPixmap = QPixmap ("icons/error.png").scaledToHeight (16);
+		QPixmap qErrorPixmap = getIcon ("error").scaledToHeight (16);
 		
 		lb_errorIcon = new QLabel;
 		lb_errorIcon->setPixmap (qErrorPixmap);
@@ -68,8 +68,8 @@
 	layout->addLayout (layout2);
 	setLayout (layout);
 	
-	setWindowTitle (APPNAME_DISPLAY " - setting contents");
-	setWindowIcon (QIcon ("icons/set-contents.png"));
+	setWindowTitle (APPNAME_DISPLAY ": Set Contents");
+	setWindowIcon (getIcon ("set-contents"));
 }
 
 // =============================================================================

mercurial