QTfrontend/model/hats.cpp
changeset 6616 f77bb02b669f
parent 6196 c16e84558f71
child 6700 e04da46ee43c
equal deleted inserted replaced
6615:65602f1ef0f8 6616:f77bb02b669f
    24 #include "hats.h"
    24 #include "hats.h"
    25 
    25 
    26 #include "HWDataManager.h"
    26 #include "HWDataManager.h"
    27 
    27 
    28 HatsModel::HatsModel(QObject* parent) :
    28 HatsModel::HatsModel(QObject* parent) :
    29   QAbstractListModel(parent)
    29     QAbstractListModel(parent)
    30 {
    30 {
    31     HWDataManager & dataMgr = HWDataManager::instance();
    31     HWDataManager & dataMgr = HWDataManager::instance();
    32 
    32 
    33     QPixmap hhpix = QPixmap(
    33     QPixmap hhpix = QPixmap(
    34         dataMgr.findFileForRead("Graphics/Hedgehog/Idle.png")
    34                         dataMgr.findFileForRead("Graphics/Hedgehog/Idle.png")
    35     ).copy(0, 0, 32, 32);
    35                     ).copy(0, 0, 32, 32);
    36 
    36 
    37     // my reserved hats
    37     // my reserved hats
    38     QStringList hatsList = dataMgr.entryList(
    38     QStringList hatsList = dataMgr.entryList(
    39                                    "Graphics/Hats/Reserved",
    39                                "Graphics/Hats/Reserved",
    40                                    QDir::Files,
    40                                QDir::Files,
    41                                    QStringList(playerHash+"*.png")
    41                                QStringList(playerHash+"*.png")
    42                                );
    42                            );
    43 
    43 
    44     int nReserved = hatsList.size();
    44     int nReserved = hatsList.size();
    45 
    45 
    46     // regular hats
    46     // regular hats
    47     hatsList.append(dataMgr.entryList(
    47     hatsList.append(dataMgr.entryList(
    48                                    "Graphics/Hats",
    48                         "Graphics/Hats",
    49                                    QDir::Files,
    49                         QDir::Files,
    50                                    QStringList("*.png")
    50                         QStringList("*.png")
    51                                )
    51                     )
    52                    );
    52                    );
    53 
    53 
    54 
    54 
    55     int nHats = hatsList.size();
    55     int nHats = hatsList.size();
    56 
    56 
    60 
    60 
    61         QString str = hatsList.at(i);
    61         QString str = hatsList.at(i);
    62         str = str.remove(QRegExp("\\.png$"));
    62         str = str.remove(QRegExp("\\.png$"));
    63         QPixmap pix(
    63         QPixmap pix(
    64             dataMgr.findFileForRead(
    64             dataMgr.findFileForRead(
    65                 "Graphics/Hats/" + QString(isReserved?"Reserved/":"") + str + 
    65                 "Graphics/Hats/" + QString(isReserved?"Reserved/":"") + str +
    66                 ".png"
    66                 ".png"
    67             )
    67             )
    68         );
    68         );
    69 
    69 
    70         // rename properly
    70         // rename properly
    87             hats.append(qMakePair(str, QIcon(tmppix)));
    87             hats.append(qMakePair(str, QIcon(tmppix)));
    88     }
    88     }
    89 }
    89 }
    90 
    90 
    91 QVariant HatsModel::headerData(int section,
    91 QVariant HatsModel::headerData(int section,
    92             Qt::Orientation orientation, int role) const
    92                                Qt::Orientation orientation, int role) const
    93 {
    93 {
    94     Q_UNUSED(section);
    94     Q_UNUSED(section);
    95     Q_UNUSED(orientation);
    95     Q_UNUSED(orientation);
    96     Q_UNUSED(role);
    96     Q_UNUSED(role);
    97 
    97 
   116 */
   116 */
   117 QVariant HatsModel::data(const QModelIndex &index,
   117 QVariant HatsModel::data(const QModelIndex &index,
   118                          int role) const
   118                          int role) const
   119 {
   119 {
   120     if (!index.isValid() || index.row() < 0
   120     if (!index.isValid() || index.row() < 0
   121         || index.row() >= hats.size()
   121             || index.row() >= hats.size()
   122         || (role != Qt::DisplayRole && role != Qt::DecorationRole))
   122             || (role != Qt::DisplayRole && role != Qt::DecorationRole))
   123         return QVariant();
   123         return QVariant();
   124 
   124 
   125     if (role == Qt::DisplayRole)
   125     if (role == Qt::DisplayRole)
   126         return hats.at(index.row()).first;
   126         return hats.at(index.row()).first;
   127     else // role == Qt::DecorationRole
   127     else // role == Qt::DecorationRole