8374
|
1 |
/*
|
|
2 |
* Hedgewars, a free turn based strategy game
|
9080
|
3 |
* Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com>
|
8374
|
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 |
|
|
19 |
#include <QDebug>
|
|
20 |
|
|
21 |
#include "hatprompt.h"
|
|
22 |
#include "DataManager.h"
|
8375
|
23 |
#include "HatModel.h"
|
8374
|
24 |
#include "hatbutton.h"
|
|
25 |
|
|
26 |
HatButton::HatButton(QWidget* parent) : QPushButton(parent)
|
|
27 |
{
|
8434
|
28 |
setIconSize(QSize(32, 37));
|
|
29 |
setFixedSize(44, 44);
|
8374
|
30 |
|
8434
|
31 |
m_hatModel = DataManager::instance().hatModel();
|
|
32 |
connect(this, SIGNAL(clicked()), this, SLOT(showPrompt()));
|
8374
|
33 |
|
8434
|
34 |
setCurrentIndex(0);
|
8374
|
35 |
}
|
|
36 |
|
|
37 |
void HatButton::setCurrentIndex(int index)
|
|
38 |
{
|
8434
|
39 |
m_hat = m_hatModel->index(index, 0);
|
|
40 |
setWhatsThis(QString(tr("Change hat (%1)")).arg(m_hat.data(Qt::DisplayRole).toString()));
|
|
41 |
setToolTip(m_hat.data(Qt::DisplayRole).toString());
|
|
42 |
setIcon(m_hat.data(Qt::DecorationRole).value<QIcon>());
|
8374
|
43 |
}
|
|
44 |
|
|
45 |
int HatButton::currentIndex()
|
|
46 |
{
|
8434
|
47 |
return m_hat.row();
|
8374
|
48 |
}
|
|
49 |
|
|
50 |
void HatButton::setCurrentHat(const QString & name)
|
|
51 |
{
|
8434
|
52 |
QList<QStandardItem *> hats = m_hatModel->findItems(name);
|
8374
|
53 |
|
8434
|
54 |
if (hats.count() > 0)
|
|
55 |
setCurrentIndex(hats[0]->row());
|
8374
|
56 |
}
|
|
57 |
|
|
58 |
QString HatButton::currentHat() const
|
|
59 |
{
|
8434
|
60 |
return m_hat.data(Qt::DisplayRole).toString();
|
8374
|
61 |
}
|
|
62 |
|
|
63 |
void HatButton::showPrompt()
|
|
64 |
{
|
8434
|
65 |
HatPrompt prompt(currentIndex(), this);
|
|
66 |
int hatID = prompt.exec() - 1; // Since 0 means canceled, so all indexes are +1'd
|
|
67 |
if (hatID < 0) return;
|
8374
|
68 |
|
8434
|
69 |
setCurrentIndex(hatID);
|
|
70 |
emit currentIndexChanged(hatID);
|
|
71 |
emit currentHatChanged(currentHat());
|
8375
|
72 |
}
|