author | unc0rr |
Mon, 14 Jan 2013 21:37:04 +0400 | |
changeset 8386 | 2aaa2995a32e |
parent 8385 | 9e8924ff9813 |
child 8419 | d99f46b676b5 |
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 |
{ |
|
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); |
|
41 |
||
42 |
// Grid |
|
43 |
QVBoxLayout * dialogLayout = new QVBoxLayout(this); |
|
44 |
dialogLayout->setSpacing(0); |
|
45 |
||
46 |
// Help/prompt message at top |
|
47 |
QLabel * lblDesc = new QLabel(tr("Select a theme for this map")); |
|
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 |
||
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(); |
|
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 |
||
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())); |
|
69 |
||
70 |
// Add elements to layouts |
|
71 |
dialogLayout->addWidget(lblDesc, 0); |
|
72 |
dialogLayout->addWidget(scrollArea, 1); |
|
73 |
dialogLayout->addWidget(btnCancel, 0, Qt::AlignLeft); |
|
74 |
||
75 |
// Tooltip label for theme name |
|
76 |
lblToolTip = new QLabel(this); |
|
77 |
||
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 |
btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); |
|
85 |
btn->setIcon(qVariantValue<QIcon>(themes->data(index, Qt::UserRole))); |
|
86 |
btn->setText(themes->data(index, Qt::DisplayRole).toString()); |
|
87 |
btn->setIconSize(QSize(60, 60)); |
|
88 |
btn->setProperty("themeID", QVariant(i)); |
|
89 |
btn->setStyleSheet("padding: 2px;"); |
|
90 |
connect(btn, SIGNAL(clicked()), this, SLOT(themeClicked())); |
|
91 |
themesGrid->addWidget(btn); |
|
92 |
} |
|
93 |
} |
|
94 |
||
95 |
// When a theme is selected |
|
96 |
void ThemePrompt::themeClicked() |
|
97 |
{ |
|
98 |
QWidget * btn = (QWidget*)sender(); |
|
99 |
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
|
100 |
} |