author | nemo |
Wed, 03 Mar 2010 02:36:52 +0000 | |
changeset 2914 | 7db64c269a5b |
parent 2874 | 3c7c2bf1ba38 |
child 2948 | 3f21a9dc93d0 |
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" |
2874
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
23 |
#include "hwform.h" |
1237 | 24 |
#include "hats.h" |
25 |
||
1236 | 26 |
HatsModel::HatsModel(QObject* parent) : |
1239 | 27 |
QAbstractListModel(parent) |
1236 | 28 |
{ |
1281 | 29 |
QPixmap hhpix = QPixmap(datadir->absolutePath() + "/Graphics/Hedgehog/Idle.png").copy(0, 0, 32, 32); |
30 |
||
1239 | 31 |
QDir tmpdir; |
32 |
tmpdir.cd(datadir->absolutePath()); |
|
33 |
tmpdir.cd("Graphics"); |
|
34 |
tmpdir.cd("Hats"); |
|
35 |
||
36 |
tmpdir.setFilter(QDir::Files); |
|
37 |
||
1281 | 38 |
|
1239 | 39 |
QStringList hatsList = tmpdir.entryList(QStringList("*.png")); |
40 |
for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it ) |
|
41 |
{ |
|
42 |
QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1"); |
|
43 |
QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/" + str + ".png"); |
|
1281 | 44 |
|
45 |
QPixmap tmppix(32, 37); |
|
46 |
tmppix.fill(QColor(Qt::transparent)); |
|
2377 | 47 |
|
1281 | 48 |
QPainter painter(&tmppix); |
49 |
painter.drawPixmap(QPoint(0, 5), hhpix); |
|
50 |
painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32)); |
|
51 |
painter.end(); |
|
52 |
||
53 |
hats.append(qMakePair(str, QIcon(tmppix))); |
|
1239 | 54 |
} |
2874
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
55 |
// Reserved hats |
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
56 |
tmpdir.cd("Reserved"); |
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
57 |
hatsList = tmpdir.entryList(QStringList(playerHash+"*.png")); |
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
58 |
for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it ) |
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
59 |
{ |
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
60 |
QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1"); |
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
61 |
QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/Reserved/" + str + ".png"); |
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
62 |
|
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
63 |
QPixmap tmppix(32, 37); |
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
64 |
tmppix.fill(QColor(Qt::transparent)); |
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
65 |
|
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
66 |
QPainter painter(&tmppix); |
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
67 |
painter.drawPixmap(QPoint(0, 5), hhpix); |
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
68 |
painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32)); |
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
69 |
painter.end(); |
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
70 |
|
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
71 |
hats.append(qMakePair("Reserved "+str.remove(0,32), QIcon(tmppix))); |
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2377
diff
changeset
|
72 |
} |
1236 | 73 |
} |
1237 | 74 |
|
75 |
QVariant HatsModel::headerData(int section, |
|
76 |
Qt::Orientation orientation, int role) const |
|
77 |
{ |
|
78 |
return QVariant(); |
|
79 |
} |
|
80 |
||
81 |
int HatsModel::rowCount(const QModelIndex &parent) const |
|
82 |
{ |
|
83 |
if (parent.isValid()) |
|
84 |
return 0; |
|
85 |
else |
|
1239 | 86 |
return hats.size(); |
1237 | 87 |
} |
88 |
||
1239 | 89 |
/*int HatsModel::columnCount(const QModelIndex & parent) const |
1237 | 90 |
{ |
91 |
if (parent.isValid()) |
|
92 |
return 0; |
|
93 |
else |
|
94 |
return 2; |
|
95 |
} |
|
1239 | 96 |
*/ |
1238
914bd2a9a249
Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents:
1237
diff
changeset
|
97 |
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
|
98 |
int role) const |
914bd2a9a249
Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents:
1237
diff
changeset
|
99 |
{ |
914bd2a9a249
Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents:
1237
diff
changeset
|
100 |
if (!index.isValid() || index.row() < 0 |
1239 | 101 |
|| index.row() >= hats.size() |
102 |
|| (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
|
103 |
return QVariant(); |
914bd2a9a249
Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents:
1237
diff
changeset
|
104 |
|
1239 | 105 |
if (role == Qt::DisplayRole) |
106 |
return hats.at(index.row()).first; |
|
107 |
else // role == Qt::DecorationRole |
|
108 |
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
|
109 |
} |