QTfrontend/ui/widget/themeprompt.cpp
author nemo
Tue, 29 Jan 2013 13:45:31 -0500
changeset 8460 75e771c3c039
parent 8434 4821897a0f10
child 8475 f605bc59c603
permissions -rw-r--r--
fix EndGame call. w/o a proper exit, demos weren't being saved
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
{
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    35
    setModal(true);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    36
    setWindowFlags(Qt::Sheet);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    37
    setWindowModality(Qt::WindowModal);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    38
    setMinimumSize(550, 430);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    39
    resize(550, 430);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    40
    setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    41
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    42
    // Grid
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    43
    QVBoxLayout * dialogLayout = new QVBoxLayout(this);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    44
    dialogLayout->setSpacing(0);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    45
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    46
    // Help/prompt message at top
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    47
    QLabel * lblDesc = new QLabel(tr("Select a theme for this map"));
8377
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
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    53
    // Scroll area and container for theme icons
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    54
    QWidget * themesContainer = new QWidget();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    55
    FlowLayout * themesGrid = new FlowLayout();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    56
    themesContainer->setLayout(themesGrid);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    57
    QScrollArea * scrollArea = new QScrollArea();
8377
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
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    65
    // Cancel button (closes dialog)
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    66
    QPushButton * btnCancel = new QPushButton(tr("Cancel"));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    67
    btnCancel->setStyleSheet("padding: 5px; margin-top: 10px;");
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    68
    connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    69
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    70
    // Add elements to layouts
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    71
    dialogLayout->addWidget(lblDesc, 0);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    72
    dialogLayout->addWidget(scrollArea, 1);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    73
    dialogLayout->addWidget(btnCancel, 0, Qt::AlignLeft);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    74
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    75
    // Tooltip label for theme name
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    76
    lblToolTip = new QLabel(this);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    77
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    78
    // Add theme buttons
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    79
    ThemeModel * themes = DataManager::instance().themeModel();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    80
    for (int i = 0; i < themes->rowCount(); i++)
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    81
    {
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    82
        QModelIndex index = themes->index(i, 0);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    83
        QToolButton * btn = new QToolButton();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    84
        bool dlc = themes->data(index, Qt::UserRole + 2).toBool();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    85
        btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    86
        btn->setIcon(qVariantValue<QIcon>(themes->data(index, Qt::UserRole)));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    87
        btn->setText((dlc ? "*" : "") + themes->data(index, Qt::DisplayRole).toString());
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    88
        btn->setIconSize(QSize(60, 60));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    89
        btn->setProperty("themeID", QVariant(i));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    90
        btn->setStyleSheet("padding: 2px;");
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    91
        connect(btn, SIGNAL(clicked()), this, SLOT(themeClicked()));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    92
        themesGrid->addWidget(btn);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    93
    }
8377
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
{
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    99
    QWidget * btn = (QWidget*)sender();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
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
}