QTfrontend/ui/widget/themeprompt.cpp
author dag10
Mon, 21 Jan 2013 14:07:39 -0500
changeset 8419 d99f46b676b5
parent 8385 9e8924ff9813
child 8434 4821897a0f10
permissions -rw-r--r--
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue #515)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     1
/*
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     4
 *
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     8
 *
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    12
 * GNU General Public License for more details.
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    13
 *
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    17
 */
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    18
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    19
#include <QDialog>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    20
#include <QVBoxLayout>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    21
#include <QScrollArea>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    22
#include <QPushButton>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    23
#include <QToolButton>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    24
#include <QWidgetItem>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    25
#include <QModelIndex>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    26
#include <QLabel>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    27
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    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
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    31
#include "themeprompt.h"
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    32
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    33
ThemePrompt::ThemePrompt(QWidget* parent) : QDialog(parent)
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    34
{
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    35
	setModal(true);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    36
	setWindowFlags(Qt::Sheet);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    37
	setWindowModality(Qt::WindowModal);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    38
	setMinimumSize(550, 430);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    39
	resize(550, 430);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    40
	setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    41
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    42
	// Grid
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    43
	QVBoxLayout * dialogLayout = new QVBoxLayout(this);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    44
	dialogLayout->setSpacing(0);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    45
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    46
	// Help/prompt message at top
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    47
	QLabel * lblDesc = new QLabel(tr("Select a theme for this map"));
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    48
    lblDesc->setStyleSheet("color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; border-top-left-radius: 10px; border-top-right-radius: 10px; padding: auto 20px;");
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    49
    lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    50
    lblDesc->setFixedHeight(24);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    51
    lblDesc->setMinimumWidth(0);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    52
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    53
	// Scroll area and container for theme icons
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    54
	QWidget * themesContainer = new QWidget();
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    55
	FlowLayout * themesGrid = new FlowLayout();
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    56
	themesContainer->setLayout(themesGrid);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    57
	QScrollArea * scrollArea = new QScrollArea();
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    58
    scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    59
    scrollArea->setObjectName("scrollArea");
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    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; }");
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    61
    scrollArea->setWidgetResizable(true);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    62
    scrollArea->setFrameShape(QFrame::NoFrame);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    63
    scrollArea->setWidget(themesContainer);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    64
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    65
	// Cancel button (closes dialog)
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    66
	QPushButton * btnCancel = new QPushButton(tr("Cancel"));
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    67
	btnCancel->setStyleSheet("padding: 5px; margin-top: 10px;");
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    68
	connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    69
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    70
	// Add elements to layouts
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    71
	dialogLayout->addWidget(lblDesc, 0);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    72
	dialogLayout->addWidget(scrollArea, 1);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    73
	dialogLayout->addWidget(btnCancel, 0, Qt::AlignLeft);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    74
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    75
	// Tooltip label for theme name
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    76
	lblToolTip = new QLabel(this);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    77
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    78
	// Add theme buttons
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    79
	ThemeModel * themes = DataManager::instance().themeModel();
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    80
	for (int i = 0; i < themes->rowCount(); i++)
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    81
	{
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    82
		QModelIndex index = themes->index(i, 0);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    83
		QToolButton * btn = new QToolButton();
8419
d99f46b676b5 Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents: 8385
diff changeset
    84
		bool dlc = themes->data(index, Qt::UserRole + 2).toBool();
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    85
		btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    86
		btn->setIcon(qVariantValue<QIcon>(themes->data(index, Qt::UserRole)));
8419
d99f46b676b5 Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents: 8385
diff changeset
    87
		btn->setText((dlc ? "*" : "") + themes->data(index, Qt::DisplayRole).toString());
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    88
		btn->setIconSize(QSize(60, 60));
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    89
		btn->setProperty("themeID", QVariant(i));
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    90
		btn->setStyleSheet("padding: 2px;");
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    91
		connect(btn, SIGNAL(clicked()), this, SLOT(themeClicked()));
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    92
		themesGrid->addWidget(btn);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    93
	}
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    94
}
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    95
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    96
// When a theme is selected
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    97
void ThemePrompt::themeClicked()
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    98
{
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    99
	QWidget * btn = (QWidget*)sender();
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   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
}