- Finish hat selection widget
authorunc0rr
Fri, 29 Aug 2008 22:04:50 +0000
changeset 1239 4901abe4c3b0
parent 1238 914bd2a9a249
child 1240 16b85f292030
- Finish hat selection widget - Now we need to pass hat to engine, save to file, send via net, whatever...
QTfrontend/hats.cpp
QTfrontend/hats.h
QTfrontend/pages.cpp
share/hedgewars/Data/Graphics/Hats/NoHat.png
share/hedgewars/Data/Graphics/Hats/Samurai.png
--- a/QTfrontend/hats.cpp	Fri Aug 29 21:05:31 2008 +0000
+++ b/QTfrontend/hats.cpp	Fri Aug 29 22:04:50 2008 +0000
@@ -16,11 +16,28 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <QDir>
+#include <QPixmap>
+#include "hwconsts.h"
 #include "hats.h"
 
 HatsModel::HatsModel(QObject* parent) :
-  QAbstractTableModel(parent)
+  QAbstractListModel(parent)
 {
+	QDir tmpdir;
+	tmpdir.cd(datadir->absolutePath());
+	tmpdir.cd("Graphics");
+	tmpdir.cd("Hats");
+
+	tmpdir.setFilter(QDir::Files);
+
+	QStringList hatsList = tmpdir.entryList(QStringList("*.png"));
+	for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it )
+	{
+		QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1");
+		QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/" + str + ".png");
+		hats.append(qMakePair(str, QIcon(pix.copy(0, 0, 32, 32))));
+	}
 
 }
 
@@ -35,24 +52,27 @@
 	if (parent.isValid())
 		return 0;
 	else
-		return 60;
+		return hats.size();
 }
 
-int HatsModel::columnCount(const QModelIndex & parent) const
+/*int HatsModel::columnCount(const QModelIndex & parent) const
 {
 	if (parent.isValid())
 		return 0;
 	else
 		return 2;
 }
-
+*/
 QVariant HatsModel::data(const QModelIndex &index,
                          int role) const
 {
 	if (!index.isValid() || index.row() < 0
-		|| index.row() >= 60
-		|| role != Qt::DisplayRole)
+		|| index.row() >= hats.size()
+		|| (role != Qt::DisplayRole && role != Qt::DecorationRole))
 		return QVariant();
 
-	return QVariant();//games[index.row()][index.column()];
+	if (role == Qt::DisplayRole)
+		return hats.at(index.row()).first;
+	else // role == Qt::DecorationRole
+		return hats.at(index.row()).second;
 }
--- a/QTfrontend/hats.h	Fri Aug 29 21:05:31 2008 +0000
+++ b/QTfrontend/hats.h	Fri Aug 29 22:04:50 2008 +0000
@@ -19,10 +19,13 @@
 #ifndef _HATS_INCLUDED
 #define _HATS_INCLUDED
 
-#include <QAbstractTableModel>
+#include <QAbstractListModel>
 #include <QStringList>
+#include <QVector>
+#include <QPair>
+#include <QIcon>
 
-class HatsModel : public QAbstractTableModel
+class HatsModel : public QAbstractListModel
 {
 	Q_OBJECT
 
@@ -31,11 +34,11 @@
 
 	QVariant headerData(int section, Qt::Orientation orientation, int role) const;
 	int rowCount(const QModelIndex & parent) const;
-	int columnCount(const QModelIndex & parent) const;
+	//int columnCount(const QModelIndex & parent) const;
 
 	QVariant data(const QModelIndex &index, int role) const;
-//protected:
-//	QList<QStringList> games;
+protected:
+	QVector<QPair<QString, QIcon> > hats;
 };
 
 #endif // _HATS_INCLUDED
--- a/QTfrontend/pages.cpp	Fri Aug 29 21:05:31 2008 +0000
+++ b/QTfrontend/pages.cpp	Fri Aug 29 22:04:50 2008 +0000
@@ -124,6 +124,8 @@
 		
 		HHHats[i] = new QComboBox(GBoxHedgehogs);
 		HHHats[i]->setModel(hatsModel);
+		//HHHats[i]->setModelColumn(1);
+		HHHats[i]->setMinimumWidth(132);
 		GBHLayout->addWidget(HHHats[i], i, 1);
 	}
 	pageLayout->addWidget(GBoxHedgehogs, 1, 0, 2, 1);
Binary file share/hedgewars/Data/Graphics/Hats/NoHat.png has changed
Binary file share/hedgewars/Data/Graphics/Hats/Samurai.png has changed