# HG changeset patch # User unc0rr # Date 1220047490 0 # Node ID 4901abe4c3b0c770ea26b69f05abebb85ae6f4f1 # Parent 914bd2a9a249cf68b5bbdbf8734505804369b196 - Finish hat selection widget - Now we need to pass hat to engine, save to file, send via net, whatever... diff -r 914bd2a9a249 -r 4901abe4c3b0 QTfrontend/hats.cpp --- 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 +#include +#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; } diff -r 914bd2a9a249 -r 4901abe4c3b0 QTfrontend/hats.h --- 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 +#include #include +#include +#include +#include -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 games; +protected: + QVector > hats; }; #endif // _HATS_INCLUDED diff -r 914bd2a9a249 -r 4901abe4c3b0 QTfrontend/pages.cpp --- 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); diff -r 914bd2a9a249 -r 4901abe4c3b0 share/hedgewars/Data/Graphics/Hats/NoHat.png Binary file share/hedgewars/Data/Graphics/Hats/NoHat.png has changed diff -r 914bd2a9a249 -r 4901abe4c3b0 share/hedgewars/Data/Graphics/Hats/Samurai.png Binary file share/hedgewars/Data/Graphics/Hats/Samurai.png has changed