author | unc0rr |
Thu, 18 Sep 2008 14:44:44 +0000 | |
changeset 1262 | e9191c693e44 |
parent 1239 | 4901abe4c3b0 |
child 1281 | 1f8456577a39 |
permissions | -rw-r--r-- |
1236 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2008 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
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 |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
1239 | 19 |
#include <QDir> |
20 |
#include <QPixmap> |
|
21 |
#include "hwconsts.h" |
|
1237 | 22 |
#include "hats.h" |
23 |
||
1236 | 24 |
HatsModel::HatsModel(QObject* parent) : |
1239 | 25 |
QAbstractListModel(parent) |
1236 | 26 |
{ |
1239 | 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 |
} |
|
1236 | 41 |
|
42 |
} |
|
1237 | 43 |
|
44 |
QVariant HatsModel::headerData(int section, |
|
45 |
Qt::Orientation orientation, int role) const |
|
46 |
{ |
|
47 |
return QVariant(); |
|
48 |
} |
|
49 |
||
50 |
int HatsModel::rowCount(const QModelIndex &parent) const |
|
51 |
{ |
|
52 |
if (parent.isValid()) |
|
53 |
return 0; |
|
54 |
else |
|
1239 | 55 |
return hats.size(); |
1237 | 56 |
} |
57 |
||
1239 | 58 |
/*int HatsModel::columnCount(const QModelIndex & parent) const |
1237 | 59 |
{ |
60 |
if (parent.isValid()) |
|
61 |
return 0; |
|
62 |
else |
|
63 |
return 2; |
|
64 |
} |
|
1239 | 65 |
*/ |
1238
914bd2a9a249
Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents:
1237
diff
changeset
|
66 |
QVariant HatsModel::data(const QModelIndex &index, |
914bd2a9a249
Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents:
1237
diff
changeset
|
67 |
int role) const |
914bd2a9a249
Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents:
1237
diff
changeset
|
68 |
{ |
914bd2a9a249
Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents:
1237
diff
changeset
|
69 |
if (!index.isValid() || index.row() < 0 |
1239 | 70 |
|| index.row() >= hats.size() |
71 |
|| (role != Qt::DisplayRole && role != Qt::DecorationRole)) |
|
1238
914bd2a9a249
Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents:
1237
diff
changeset
|
72 |
return QVariant(); |
914bd2a9a249
Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents:
1237
diff
changeset
|
73 |
|
1239 | 74 |
if (role == Qt::DisplayRole) |
75 |
return hats.at(index.row()).first; |
|
76 |
else // role == Qt::DecorationRole |
|
77 |
return hats.at(index.row()).second; |
|
1238
914bd2a9a249
Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents:
1237
diff
changeset
|
78 |
} |