2
* Hedgewars, a free turn based strategy game
3
* Copyright (c) 2008-2011 Andrey Korotaev <unC0Rr@gmail.com>
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
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.
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
26
HatsModel::HatsModel(QObject* parent) :
27
QAbstractListModel(parent)
30
hhfile.setFileName(cfgdir->absolutePath() + "/Data/Graphics/Hedgehog/Idle.png");
31
if (!hhfile.exists()) hhfile.setFileName(datadir->absolutePath() + "/Graphics/Hedgehog/Idle.png");
32
QPixmap hhpix = QPixmap(QFileInfo(hhfile).absoluteFilePath()).copy(0, 0, 32, 32);
35
tmpdir.cd(cfgdir->absolutePath());
37
tmpdir.cd("Graphics");
40
tmpdir.setFilter(QDir::Files);
42
QStringList userhatsList = tmpdir.entryList(QStringList("*.png"));
43
for (QStringList::Iterator it = userhatsList.begin(); it != userhatsList.end(); ++it )
45
QString str = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1");
46
QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Hats/" + str + ".png");
48
QPixmap tmppix(32, 37);
49
tmppix.fill(QColor(Qt::transparent));
51
QPainter painter(&tmppix);
52
painter.drawPixmap(QPoint(0, 5), hhpix);
53
painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32));
55
painter.drawPixmap(QPoint(0, 0), pix.copy(32, 0, 32, 32));
58
hats.append(qMakePair(str, QIcon(tmppix)));
61
tmpdir.cd(datadir->absolutePath());
62
tmpdir.cd("Graphics");
65
QStringList hatsList = tmpdir.entryList(QStringList("*.png"));
66
for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it )
68
if (userhatsList.contains(*it,Qt::CaseInsensitive)) continue;
69
QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1");
70
QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/" + str + ".png");
72
QPixmap tmppix(32, 37);
73
tmppix.fill(QColor(Qt::transparent));
75
QPainter painter(&tmppix);
76
painter.drawPixmap(QPoint(0, 5), hhpix);
77
painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32));
79
painter.drawPixmap(QPoint(0, 0), pix.copy(32, 0, 32, 32));
82
hats.append(qMakePair(str, QIcon(tmppix)));
85
tmpdir.cd("Reserved");
86
hatsList = tmpdir.entryList(QStringList(playerHash+"*.png"));
87
for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it )
89
QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1");
90
QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/Reserved/" + str + ".png");
92
QPixmap tmppix(32, 37);
93
tmppix.fill(QColor(Qt::transparent));
95
QPainter painter(&tmppix);
96
painter.drawPixmap(QPoint(0, 5), hhpix);
97
painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32));
100
hats.append(qMakePair("Reserved "+str.remove(0,32), QIcon(tmppix)));
104
QVariant HatsModel::headerData(int section,
105
Qt::Orientation orientation, int role) const
108
Q_UNUSED(orientation);
114
int HatsModel::rowCount(const QModelIndex &parent) const
116
if (parent.isValid())
122
/*int HatsModel::columnCount(const QModelIndex & parent) const
124
if (parent.isValid())
130
QVariant HatsModel::data(const QModelIndex &index,
133
if (!index.isValid() || index.row() < 0
134
|| index.row() >= hats.size()
135
|| (role != Qt::DisplayRole && role != Qt::DecorationRole))
138
if (role == Qt::DisplayRole)
139
return hats.at(index.row()).first;
140
else // role == Qt::DecorationRole
141
return hats.at(index.row()).second;