author | unc0rr |
Sun, 18 Oct 2009 14:44:16 +0000 | |
changeset 2551 | 01eb81cd3198 |
parent 2377 | f3fab2b09e0c |
child 2874 | 3c7c2bf1ba38 |
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> |
|
1281 | 21 |
#include <QPainter> |
1239 | 22 |
#include "hwconsts.h" |
1237 | 23 |
#include "hats.h" |
24 |
||
1236 | 25 |
HatsModel::HatsModel(QObject* parent) : |
1239 | 26 |
QAbstractListModel(parent) |
1236 | 27 |
{ |
1281 | 28 |
QPixmap hhpix = QPixmap(datadir->absolutePath() + "/Graphics/Hedgehog/Idle.png").copy(0, 0, 32, 32); |
29 |
||
1239 | 30 |
QDir tmpdir; |
31 |
tmpdir.cd(datadir->absolutePath()); |
|
32 |
tmpdir.cd("Graphics"); |
|
33 |
tmpdir.cd("Hats"); |
|
34 |
||
35 |
tmpdir.setFilter(QDir::Files); |
|
36 |
||
1281 | 37 |
|
1239 | 38 |
QStringList hatsList = tmpdir.entryList(QStringList("*.png")); |
39 |
for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it ) |
|
40 |
{ |
|
41 |
QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1"); |
|
42 |
QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/" + str + ".png"); |
|
1281 | 43 |
|
44 |
QPixmap tmppix(32, 37); |
|
45 |
tmppix.fill(QColor(Qt::transparent)); |
|
2377 | 46 |
|
1281 | 47 |
QPainter painter(&tmppix); |
48 |
painter.drawPixmap(QPoint(0, 5), hhpix); |
|
49 |
painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32)); |
|
50 |
painter.end(); |
|
51 |
||
52 |
hats.append(qMakePair(str, QIcon(tmppix))); |
|
1239 | 53 |
} |
1236 | 54 |
} |
1237 | 55 |
|
56 |
QVariant HatsModel::headerData(int section, |
|
57 |
Qt::Orientation orientation, int role) const |
|
58 |
{ |
|
59 |
return QVariant(); |
|
60 |
} |
|
61 |
||
62 |
int HatsModel::rowCount(const QModelIndex &parent) const |
|
63 |
{ |
|
64 |
if (parent.isValid()) |
|
65 |
return 0; |
|
66 |
else |
|
1239 | 67 |
return hats.size(); |
1237 | 68 |
} |
69 |
||
1239 | 70 |
/*int HatsModel::columnCount(const QModelIndex & parent) const |
1237 | 71 |
{ |
72 |
if (parent.isValid()) |
|
73 |
return 0; |
|
74 |
else |
|
75 |
return 2; |
|
76 |
} |
|
1239 | 77 |
*/ |
1238
914bd2a9a249
Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents:
1237
diff
changeset
|
78 |
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
|
79 |
int role) const |
914bd2a9a249
Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents:
1237
diff
changeset
|
80 |
{ |
914bd2a9a249
Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents:
1237
diff
changeset
|
81 |
if (!index.isValid() || index.row() < 0 |
1239 | 82 |
|| index.row() >= hats.size() |
83 |
|| (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
|
84 |
return QVariant(); |
914bd2a9a249
Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents:
1237
diff
changeset
|
85 |
|
1239 | 86 |
if (role == Qt::DisplayRole) |
87 |
return hats.at(index.row()).first; |
|
88 |
else // role == Qt::DecorationRole |
|
89 |
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
|
90 |
} |