14 * You should have received a copy of the GNU General Public License |
14 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software |
15 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
17 */ |
17 */ |
18 |
18 |
|
19 #include <QDir> |
|
20 #include <QPixmap> |
|
21 #include "hwconsts.h" |
19 #include "hats.h" |
22 #include "hats.h" |
20 |
23 |
21 HatsModel::HatsModel(QObject* parent) : |
24 HatsModel::HatsModel(QObject* parent) : |
22 QAbstractTableModel(parent) |
25 QAbstractListModel(parent) |
23 { |
26 { |
|
27 QDir tmpdir; |
|
28 tmpdir.cd(datadir->absolutePath()); |
|
29 tmpdir.cd("Graphics"); |
|
30 tmpdir.cd("Hats"); |
|
31 |
|
32 tmpdir.setFilter(QDir::Files); |
|
33 |
|
34 QStringList hatsList = tmpdir.entryList(QStringList("*.png")); |
|
35 for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it ) |
|
36 { |
|
37 QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1"); |
|
38 QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/" + str + ".png"); |
|
39 hats.append(qMakePair(str, QIcon(pix.copy(0, 0, 32, 32)))); |
|
40 } |
24 |
41 |
25 } |
42 } |
26 |
43 |
27 QVariant HatsModel::headerData(int section, |
44 QVariant HatsModel::headerData(int section, |
28 Qt::Orientation orientation, int role) const |
45 Qt::Orientation orientation, int role) const |
33 int HatsModel::rowCount(const QModelIndex &parent) const |
50 int HatsModel::rowCount(const QModelIndex &parent) const |
34 { |
51 { |
35 if (parent.isValid()) |
52 if (parent.isValid()) |
36 return 0; |
53 return 0; |
37 else |
54 else |
38 return 60; |
55 return hats.size(); |
39 } |
56 } |
40 |
57 |
41 int HatsModel::columnCount(const QModelIndex & parent) const |
58 /*int HatsModel::columnCount(const QModelIndex & parent) const |
42 { |
59 { |
43 if (parent.isValid()) |
60 if (parent.isValid()) |
44 return 0; |
61 return 0; |
45 else |
62 else |
46 return 2; |
63 return 2; |
47 } |
64 } |
48 |
65 */ |
49 QVariant HatsModel::data(const QModelIndex &index, |
66 QVariant HatsModel::data(const QModelIndex &index, |
50 int role) const |
67 int role) const |
51 { |
68 { |
52 if (!index.isValid() || index.row() < 0 |
69 if (!index.isValid() || index.row() < 0 |
53 || index.row() >= 60 |
70 || index.row() >= hats.size() |
54 || role != Qt::DisplayRole) |
71 || (role != Qt::DisplayRole && role != Qt::DecorationRole)) |
55 return QVariant(); |
72 return QVariant(); |
56 |
73 |
57 return QVariant();//games[index.row()][index.column()]; |
74 if (role == Qt::DisplayRole) |
|
75 return hats.at(index.row()).first; |
|
76 else // role == Qt::DecorationRole |
|
77 return hats.at(index.row()).second; |
58 } |
78 } |