QTfrontend/hats.cpp
author unc0rr
Thu, 11 Sep 2008 20:13:23 +0000
changeset 1253 79f47495b346
parent 1239 4901abe4c3b0
child 1281 1f8456577a39
permissions -rw-r--r--
Draw hat when hedgehog is aiming
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1236
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     1
/*
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2008 Andrey Korotaev <unC0Rr@gmail.com>
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     4
 *
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     8
 *
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    13
 *
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    17
 */
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    18
1239
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    19
#include <QDir>
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    20
#include <QPixmap>
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    21
#include "hwconsts.h"
1237
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    22
#include "hats.h"
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    23
1236
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    24
HatsModel::HatsModel(QObject* parent) :
1239
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    25
  QAbstractListModel(parent)
1236
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    26
{
1239
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    27
	QDir tmpdir;
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    28
	tmpdir.cd(datadir->absolutePath());
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    29
	tmpdir.cd("Graphics");
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    30
	tmpdir.cd("Hats");
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    31
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    32
	tmpdir.setFilter(QDir::Files);
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    33
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    34
	QStringList hatsList = tmpdir.entryList(QStringList("*.png"));
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    35
	for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it )
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    36
	{
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    37
		QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1");
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    38
		QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/" + str + ".png");
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    39
		hats.append(qMakePair(str, QIcon(pix.copy(0, 0, 32, 32))));
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    40
	}
1236
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    41
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    42
}
1237
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    43
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    44
QVariant HatsModel::headerData(int section,
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    45
            Qt::Orientation orientation, int role) const
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    46
{
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    47
	return QVariant();
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    48
}
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    49
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    50
int HatsModel::rowCount(const QModelIndex &parent) const
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    51
{
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    52
	if (parent.isValid())
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    53
		return 0;
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    54
	else
1239
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    55
		return hats.size();
1237
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    56
}
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    57
1239
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    58
/*int HatsModel::columnCount(const QModelIndex & parent) const
1237
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    59
{
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    60
	if (parent.isValid())
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    61
		return 0;
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    62
	else
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    63
		return 2;
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    64
}
1239
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    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
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    70
		|| index.row() >= hats.size()
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    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
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    74
	if (role == Qt::DisplayRole)
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    75
		return hats.at(index.row()).first;
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    76
	else // role == Qt::DecorationRole
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    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
}