QTfrontend/ui/widget/themeprompt.cpp
changeset 8434 4821897a0f10
parent 8419 d99f46b676b5
child 8475 f605bc59c603
equal deleted inserted replaced
8432:f2d57e987ba9 8434:4821897a0f10
    30 #include "ThemeModel.h"
    30 #include "ThemeModel.h"
    31 #include "themeprompt.h"
    31 #include "themeprompt.h"
    32 
    32 
    33 ThemePrompt::ThemePrompt(QWidget* parent) : QDialog(parent)
    33 ThemePrompt::ThemePrompt(QWidget* parent) : QDialog(parent)
    34 {
    34 {
    35 	setModal(true);
    35     setModal(true);
    36 	setWindowFlags(Qt::Sheet);
    36     setWindowFlags(Qt::Sheet);
    37 	setWindowModality(Qt::WindowModal);
    37     setWindowModality(Qt::WindowModal);
    38 	setMinimumSize(550, 430);
    38     setMinimumSize(550, 430);
    39 	resize(550, 430);
    39     resize(550, 430);
    40 	setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    40     setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    41 
    41 
    42 	// Grid
    42     // Grid
    43 	QVBoxLayout * dialogLayout = new QVBoxLayout(this);
    43     QVBoxLayout * dialogLayout = new QVBoxLayout(this);
    44 	dialogLayout->setSpacing(0);
    44     dialogLayout->setSpacing(0);
    45 
    45 
    46 	// Help/prompt message at top
    46     // Help/prompt message at top
    47 	QLabel * lblDesc = new QLabel(tr("Select a theme for this map"));
    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;");
    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);
    49     lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    50     lblDesc->setFixedHeight(24);
    50     lblDesc->setFixedHeight(24);
    51     lblDesc->setMinimumWidth(0);
    51     lblDesc->setMinimumWidth(0);
    52 
    52 
    53 	// Scroll area and container for theme icons
    53     // Scroll area and container for theme icons
    54 	QWidget * themesContainer = new QWidget();
    54     QWidget * themesContainer = new QWidget();
    55 	FlowLayout * themesGrid = new FlowLayout();
    55     FlowLayout * themesGrid = new FlowLayout();
    56 	themesContainer->setLayout(themesGrid);
    56     themesContainer->setLayout(themesGrid);
    57 	QScrollArea * scrollArea = new QScrollArea();
    57     QScrollArea * scrollArea = new QScrollArea();
    58     scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    58     scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    59     scrollArea->setObjectName("scrollArea");
    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; }");
    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);
    61     scrollArea->setWidgetResizable(true);
    62     scrollArea->setFrameShape(QFrame::NoFrame);
    62     scrollArea->setFrameShape(QFrame::NoFrame);
    63     scrollArea->setWidget(themesContainer);
    63     scrollArea->setWidget(themesContainer);
    64 
    64 
    65 	// Cancel button (closes dialog)
    65     // Cancel button (closes dialog)
    66 	QPushButton * btnCancel = new QPushButton(tr("Cancel"));
    66     QPushButton * btnCancel = new QPushButton(tr("Cancel"));
    67 	btnCancel->setStyleSheet("padding: 5px; margin-top: 10px;");
    67     btnCancel->setStyleSheet("padding: 5px; margin-top: 10px;");
    68 	connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
    68     connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
    69 
    69 
    70 	// Add elements to layouts
    70     // Add elements to layouts
    71 	dialogLayout->addWidget(lblDesc, 0);
    71     dialogLayout->addWidget(lblDesc, 0);
    72 	dialogLayout->addWidget(scrollArea, 1);
    72     dialogLayout->addWidget(scrollArea, 1);
    73 	dialogLayout->addWidget(btnCancel, 0, Qt::AlignLeft);
    73     dialogLayout->addWidget(btnCancel, 0, Qt::AlignLeft);
    74 
    74 
    75 	// Tooltip label for theme name
    75     // Tooltip label for theme name
    76 	lblToolTip = new QLabel(this);
    76     lblToolTip = new QLabel(this);
    77 
    77 
    78 	// Add theme buttons
    78     // Add theme buttons
    79 	ThemeModel * themes = DataManager::instance().themeModel();
    79     ThemeModel * themes = DataManager::instance().themeModel();
    80 	for (int i = 0; i < themes->rowCount(); i++)
    80     for (int i = 0; i < themes->rowCount(); i++)
    81 	{
    81     {
    82 		QModelIndex index = themes->index(i, 0);
    82         QModelIndex index = themes->index(i, 0);
    83 		QToolButton * btn = new QToolButton();
    83         QToolButton * btn = new QToolButton();
    84 		bool dlc = themes->data(index, Qt::UserRole + 2).toBool();
    84         bool dlc = themes->data(index, Qt::UserRole + 2).toBool();
    85 		btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    85         btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    86 		btn->setIcon(qVariantValue<QIcon>(themes->data(index, Qt::UserRole)));
    86         btn->setIcon(qVariantValue<QIcon>(themes->data(index, Qt::UserRole)));
    87 		btn->setText((dlc ? "*" : "") + themes->data(index, Qt::DisplayRole).toString());
    87         btn->setText((dlc ? "*" : "") + themes->data(index, Qt::DisplayRole).toString());
    88 		btn->setIconSize(QSize(60, 60));
    88         btn->setIconSize(QSize(60, 60));
    89 		btn->setProperty("themeID", QVariant(i));
    89         btn->setProperty("themeID", QVariant(i));
    90 		btn->setStyleSheet("padding: 2px;");
    90         btn->setStyleSheet("padding: 2px;");
    91 		connect(btn, SIGNAL(clicked()), this, SLOT(themeClicked()));
    91         connect(btn, SIGNAL(clicked()), this, SLOT(themeClicked()));
    92 		themesGrid->addWidget(btn);
    92         themesGrid->addWidget(btn);
    93 	}
    93     }
    94 }
    94 }
    95 
    95 
    96 // When a theme is selected
    96 // When a theme is selected
    97 void ThemePrompt::themeClicked()
    97 void ThemePrompt::themeClicked()
    98 {
    98 {
    99 	QWidget * btn = (QWidget*)sender();
    99     QWidget * btn = (QWidget*)sender();
   100 	done(btn->property("themeID").toInt() + 1); // Since returning 0 means canceled
   100     done(btn->property("themeID").toInt() + 1); // Since returning 0 means canceled
   101 }
   101 }