author | Wuzzy <Wuzzy2@mail.ru> |
Mon, 28 Oct 2019 20:40:07 +0100 | |
changeset 15495 | 0039baa9895e |
parent 11046 | 47a8c19ecb60 |
permissions | -rw-r--r-- |
8374 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
9998
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
8374 | 17 |
*/ |
18 |
||
19 |
#include <QDebug> |
|
20 |
||
21 |
#include "hatprompt.h" |
|
8375 | 22 |
#include "HatModel.h" |
8374 | 23 |
#include "hatbutton.h" |
24 |
||
25 |
HatButton::HatButton(QWidget* parent) : QPushButton(parent) |
|
26 |
{ |
|
8434 | 27 |
setIconSize(QSize(32, 37)); |
28 |
setFixedSize(44, 44); |
|
8374 | 29 |
|
9738 | 30 |
m_hatModel = 0; |
8434 | 31 |
connect(this, SIGNAL(clicked()), this, SLOT(showPrompt())); |
9738 | 32 |
} |
33 |
||
34 |
void HatButton::setModel(HatModel *model) |
|
35 |
{ |
|
36 |
m_hatModel = model; |
|
8374 | 37 |
|
8434 | 38 |
setCurrentIndex(0); |
8374 | 39 |
} |
40 |
||
41 |
void HatButton::setCurrentIndex(int index) |
|
42 |
{ |
|
8434 | 43 |
m_hat = m_hatModel->index(index, 0); |
44 |
setWhatsThis(QString(tr("Change hat (%1)")).arg(m_hat.data(Qt::DisplayRole).toString())); |
|
45 |
setToolTip(m_hat.data(Qt::DisplayRole).toString()); |
|
46 |
setIcon(m_hat.data(Qt::DecorationRole).value<QIcon>()); |
|
8374 | 47 |
} |
48 |
||
49 |
int HatButton::currentIndex() |
|
50 |
{ |
|
8434 | 51 |
return m_hat.row(); |
8374 | 52 |
} |
53 |
||
54 |
void HatButton::setCurrentHat(const QString & name) |
|
55 |
{ |
|
8434 | 56 |
QList<QStandardItem *> hats = m_hatModel->findItems(name); |
8374 | 57 |
|
8434 | 58 |
if (hats.count() > 0) |
59 |
setCurrentIndex(hats[0]->row()); |
|
8374 | 60 |
} |
61 |
||
62 |
QString HatButton::currentHat() const |
|
63 |
{ |
|
8434 | 64 |
return m_hat.data(Qt::DisplayRole).toString(); |
8374 | 65 |
} |
66 |
||
67 |
void HatButton::showPrompt() |
|
68 |
{ |
|
8434 | 69 |
HatPrompt prompt(currentIndex(), this); |
70 |
int hatID = prompt.exec() - 1; // Since 0 means canceled, so all indexes are +1'd |
|
71 |
if (hatID < 0) return; |
|
8374 | 72 |
|
8434 | 73 |
setCurrentIndex(hatID); |
74 |
emit currentIndexChanged(hatID); |
|
75 |
emit currentHatChanged(currentHat()); |
|
8375 | 76 |
} |