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; }