author | dag10 |
Tue, 29 Jan 2013 01:41:41 -0500 | |
changeset 8456 | cc76826f14c2 |
parent 8434 | 4821897a0f10 |
child 8475 | f605bc59c603 |
permissions | -rw-r--r-- |
8377 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2004-2012 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 |
||
19 |
#include <QDialog> |
|
20 |
#include <QVBoxLayout> |
|
21 |
#include <QScrollArea> |
|
22 |
#include <QPushButton> |
|
23 |
#include <QToolButton> |
|
24 |
#include <QWidgetItem> |
|
25 |
#include <QModelIndex> |
|
26 |
#include <QLabel> |
|
27 |
||
28 |
#include "flowlayout.h" |
|
8385
9e8924ff9813
Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents:
8377
diff
changeset
|
29 |
#include "DataManager.h" |
9e8924ff9813
Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents:
8377
diff
changeset
|
30 |
#include "ThemeModel.h" |
8377 | 31 |
#include "themeprompt.h" |
32 |
||
33 |
ThemePrompt::ThemePrompt(QWidget* parent) : QDialog(parent) |
|
34 |
{ |
|
8434 | 35 |
setModal(true); |
36 |
setWindowFlags(Qt::Sheet); |
|
37 |
setWindowModality(Qt::WindowModal); |
|
38 |
setMinimumSize(550, 430); |
|
39 |
resize(550, 430); |
|
40 |
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); |
|
8377 | 41 |
|
8434 | 42 |
// Grid |
43 |
QVBoxLayout * dialogLayout = new QVBoxLayout(this); |
|
44 |
dialogLayout->setSpacing(0); |
|
8377 | 45 |
|
8434 | 46 |
// Help/prompt message at top |
47 |
QLabel * lblDesc = new QLabel(tr("Select a theme for this map")); |
|
8377 | 48 |
lblDesc->setStyleSheet("color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; border-top-left-radius: 10px; border-top-right-radius: 10px; padding: auto 20px;"); |
49 |
lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
|
50 |
lblDesc->setFixedHeight(24); |
|
51 |
lblDesc->setMinimumWidth(0); |
|
52 |
||
8434 | 53 |
// Scroll area and container for theme icons |
54 |
QWidget * themesContainer = new QWidget(); |
|
55 |
FlowLayout * themesGrid = new FlowLayout(); |
|
56 |
themesContainer->setLayout(themesGrid); |
|
57 |
QScrollArea * scrollArea = new QScrollArea(); |
|
8377 | 58 |
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); |
59 |
scrollArea->setObjectName("scrollArea"); |
|
60 |
scrollArea->setStyleSheet("QScrollBar, #scrollArea { background-color: #130F2A; } #scrollArea { border-color: #F6CB1C; border-width: 3px; border-top-width: 0; border-style: solid; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; }"); |
|
61 |
scrollArea->setWidgetResizable(true); |
|
62 |
scrollArea->setFrameShape(QFrame::NoFrame); |
|
63 |
scrollArea->setWidget(themesContainer); |
|
64 |
||
8434 | 65 |
// Cancel button (closes dialog) |
66 |
QPushButton * btnCancel = new QPushButton(tr("Cancel")); |
|
67 |
btnCancel->setStyleSheet("padding: 5px; margin-top: 10px;"); |
|
68 |
connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject())); |
|
8377 | 69 |
|
8434 | 70 |
// Add elements to layouts |
71 |
dialogLayout->addWidget(lblDesc, 0); |
|
72 |
dialogLayout->addWidget(scrollArea, 1); |
|
73 |
dialogLayout->addWidget(btnCancel, 0, Qt::AlignLeft); |
|
8377 | 74 |
|
8434 | 75 |
// Tooltip label for theme name |
76 |
lblToolTip = new QLabel(this); |
|
8377 | 77 |
|
8434 | 78 |
// Add theme buttons |
79 |
ThemeModel * themes = DataManager::instance().themeModel(); |
|
80 |
for (int i = 0; i < themes->rowCount(); i++) |
|
81 |
{ |
|
82 |
QModelIndex index = themes->index(i, 0); |
|
83 |
QToolButton * btn = new QToolButton(); |
|
84 |
bool dlc = themes->data(index, Qt::UserRole + 2).toBool(); |
|
85 |
btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); |
|
86 |
btn->setIcon(qVariantValue<QIcon>(themes->data(index, Qt::UserRole))); |
|
87 |
btn->setText((dlc ? "*" : "") + themes->data(index, Qt::DisplayRole).toString()); |
|
88 |
btn->setIconSize(QSize(60, 60)); |
|
89 |
btn->setProperty("themeID", QVariant(i)); |
|
90 |
btn->setStyleSheet("padding: 2px;"); |
|
91 |
connect(btn, SIGNAL(clicked()), this, SLOT(themeClicked())); |
|
92 |
themesGrid->addWidget(btn); |
|
93 |
} |
|
8377 | 94 |
} |
95 |
||
96 |
// When a theme is selected |
|
97 |
void ThemePrompt::themeClicked() |
|
98 |
{ |
|
8434 | 99 |
QWidget * btn = (QWidget*)sender(); |
100 |
done(btn->property("themeID").toInt() + 1); // Since returning 0 means canceled |
|
8385
9e8924ff9813
Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents:
8377
diff
changeset
|
101 |
} |