QTfrontend/ui/widget/themeprompt.cpp
author Wuzzy <Wuzzy2@mail.ru>
Mon, 01 Apr 2019 20:08:34 +0200
changeset 14740 2d859d34e6f6
parent 13288 f816b9e73fcb
permissions -rw-r--r--
Fix turn end if placing air attack in bouncy world edge map was denied Fixes bug #728.
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
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10108
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
8377
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
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 9998
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
8377
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>
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    20
#include <QGridLayout>
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    21
#include <QHBoxLayout>
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    22
#include <QScrollArea>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    23
#include <QPushButton>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    24
#include <QToolButton>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    25
#include <QWidgetItem>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    26
#include <QModelIndex>
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    27
#include <QListView>
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    28
#include <QLineEdit>
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    29
#include <QLabel>
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    30
#include <QSortFilterProxyModel>
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    31
#include <QDebug>
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    32
8385
9e8924ff9813 Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents: 8377
diff changeset
    33
#include "DataManager.h"
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    34
#include "lineeditcursor.h"
8385
9e8924ff9813 Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents: 8377
diff changeset
    35
#include "ThemeModel.h"
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    36
#include "themeprompt.h"
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    37
8731
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    38
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    39
void ThemeListView::moveUp()
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    40
{
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    41
    setCurrentIndex(moveCursor(QAbstractItemView::MoveUp, Qt::NoModifier));
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    42
}
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    43
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    44
void ThemeListView::moveDown()
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    45
{
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    46
    setCurrentIndex(moveCursor(QAbstractItemView::MoveDown, Qt::NoModifier));
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    47
}
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    48
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    49
void ThemeListView::moveLeft()
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    50
{
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    51
    setCurrentIndex(moveCursor(QAbstractItemView::MoveLeft, Qt::NoModifier));
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    52
}
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    53
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    54
void ThemeListView::moveRight()
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    55
{
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    56
    setCurrentIndex(moveCursor(QAbstractItemView::MoveRight, Qt::NoModifier));
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    57
}
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
    58
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    59
ThemePrompt::ThemePrompt(int currentIndex, QWidget* parent) : QDialog(parent)
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    60
{
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    61
    setModal(true);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    62
    setWindowFlags(Qt::Sheet);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    63
    setWindowModality(Qt::WindowModal);
11495
fb7817a5c2b1 Add window titles for title-less windows
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    64
    setWindowTitle(tr("Choose a theme"));
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    65
    setMinimumSize(550, 430);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    66
    resize(550, 430);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    67
    setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    68
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    69
    setStyleSheet("QPushButton { padding: 5px; margin-top: 10px; }");
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    70
13253
b0022324fb4e Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents: 11495
diff changeset
    71
    // Theme model
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    72
    ThemeModel * themeModel = DataManager::instance().themeModel();
13253
b0022324fb4e Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents: 11495
diff changeset
    73
    filterModel = themeModel->withoutHidden();
b0022324fb4e Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents: 11495
diff changeset
    74
    // Custom filter extension
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    75
    filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
13262
7d7eb27dab31 Fix theme chooser failing to filter themes by name
Wuzzy <Wuzzy2@mail.ru>
parents: 13253
diff changeset
    76
    // Reset search field
7d7eb27dab31 Fix theme chooser failing to filter themes by name
Wuzzy <Wuzzy2@mail.ru>
parents: 13253
diff changeset
    77
    filterModel->setFilterFixedString(QString());
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    78
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    79
    // Grid
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    80
    QGridLayout * dialogLayout = new QGridLayout(this);
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    81
    dialogLayout->setSpacing(0);
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    82
    dialogLayout->setColumnStretch(1, 1);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    83
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    84
    QHBoxLayout * topLayout = new QHBoxLayout();
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    85
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
    86
    // Help/prompt message at top
8488
e72f3398a28b Removed in-lineedit labels such as "search:" and "room name:" due to size issues with localization and platform differences.
dag10
parents: 8475
diff changeset
    87
    QLabel * lblDesc = new QLabel(tr("Search for a theme:"));
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    88
    lblDesc->setObjectName("lblDesc");
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    89
    lblDesc->setStyleSheet("#lblDesc { color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; border-top-left-radius: 10px; padding: 4px 10px;}");
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    90
    lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    91
    lblDesc->setFixedHeight(24);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    92
    lblDesc->setMinimumWidth(0);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    93
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    94
    // Filter text box
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    95
    QWidget * filterContainer = new QWidget();
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    96
    filterContainer->setFixedHeight(24);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    97
    filterContainer->setObjectName("filterContainer");
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
    98
    filterContainer->setStyleSheet("#filterContainer { background: #F6CB1C; border-top-right-radius: 10px; padding: 3px; }");
8488
e72f3398a28b Removed in-lineedit labels such as "search:" and "room name:" due to size issues with localization and platform differences.
dag10
parents: 8475
diff changeset
    99
    filterContainer->setFixedWidth(150);
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   100
    txtFilter = new LineEditCursor(filterContainer);
8488
e72f3398a28b Removed in-lineedit labels such as "search:" and "room name:" due to size issues with localization and platform differences.
dag10
parents: 8475
diff changeset
   101
    txtFilter->setFixedWidth(150);
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   102
    txtFilter->setFocus();
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   103
    txtFilter->setFixedHeight(22);
8488
e72f3398a28b Removed in-lineedit labels such as "search:" and "room name:" due to size issues with localization and platform differences.
dag10
parents: 8475
diff changeset
   104
    txtFilter->setStyleSheet("LineEditCursor { border-width: 0px; border-radius: 6px; margin-top: 3px; margin-right: 3px; padding-left: 4px; padding-bottom: 2px; background-color: rgb(23, 11, 54); } LineEditCursor:hover, LineEditCursor:focus { background-color: rgb(13, 5, 68); }");
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   105
    connect(txtFilter, SIGNAL(textChanged(const QString &)), this, SLOT(filterChanged(const QString &)));
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   106
    connect(txtFilter, SIGNAL(moveUp()), this, SLOT(moveUp()));
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   107
    connect(txtFilter, SIGNAL(moveDown()), this, SLOT(moveDown()));
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   108
    connect(txtFilter, SIGNAL(moveLeft()), this, SLOT(moveLeft()));
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   109
    connect(txtFilter, SIGNAL(moveRight()), this, SLOT(moveRight()));
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   110
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   111
    // Corner widget
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   112
    QLabel * corner = new QLabel();
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   113
    corner->setPixmap(QPixmap(QString::fromUtf8(":/res/inverse-corner-bl.png")));
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   114
    corner->setFixedSize(10, 10);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   115
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   116
    // Add widgets to top layout
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   117
    topLayout->addWidget(lblDesc);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   118
    topLayout->addWidget(filterContainer);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   119
    topLayout->addWidget(corner, 0, Qt::AlignBottom);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   120
    topLayout->addStretch(1);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   121
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
   122
    // Cancel button (closes dialog)
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
   123
    QPushButton * btnCancel = new QPushButton(tr("Cancel"));
13288
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13262
diff changeset
   124
    connect(btnCancel, SIGNAL(clicked()), this, SLOT(onRejected()));
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   125
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   126
    // Select button
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   127
    QPushButton * btnSelect = new QPushButton(tr("Use selected theme"));
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   128
    btnSelect->setDefault(true);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   129
    connect(btnSelect, SIGNAL(clicked()), this, SLOT(onAccepted()));
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   130
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   131
    // Add themes
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   132
    list = new ThemeListView();
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   133
    list->setModel(filterModel);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   134
    list->setViewMode(QListView::IconMode);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   135
    list->setResizeMode(QListView::Adjust);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   136
    list->setMovement(QListView::Static);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   137
    list->setEditTriggers(QAbstractItemView::NoEditTriggers);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   138
    list->setSpacing(8);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   139
    list->setWordWrap(true);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   140
    list->setSelectionMode(QAbstractItemView::SingleSelection);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   141
    list->setObjectName("themeList");
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   142
    list->setCurrentIndex(filterModel->index(currentIndex, 0));
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   143
    connect(list, SIGNAL(activated(const QModelIndex &)), this, SLOT(themeChosen(const QModelIndex &)));
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   144
    connect(list, SIGNAL(clicked(const QModelIndex &)), this, SLOT(themeChosen(const QModelIndex &)));
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   145
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8419
diff changeset
   146
    // Add elements to layouts
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   147
    dialogLayout->addLayout(topLayout, 0, 0, 1, 3);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   148
    dialogLayout->addWidget(list, 1, 0, 1, 3);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   149
    dialogLayout->addWidget(btnCancel, 2, 0, 1, 1, Qt::AlignLeft);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   150
    dialogLayout->addWidget(btnSelect, 2, 2, 1, 1, Qt::AlignRight);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   151
}
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   152
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   153
void ThemePrompt::moveUp()
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   154
{
8731
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
   155
    list->moveUp();
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   156
}
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   157
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   158
void ThemePrompt::moveDown()
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   159
{
8731
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
   160
    list->moveDown();
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   161
}
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   162
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   163
void ThemePrompt::moveLeft()
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   164
{
8731
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
   165
    list->moveLeft();
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   166
}
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   167
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   168
void ThemePrompt::moveRight()
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   169
{
8731
924840dad6a0 fix compilation with clang. fixes issue 553 - thanks to julien for reporting and to drew for the first part of the fix
sheepluva
parents: 8534
diff changeset
   170
    list->moveRight();
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   171
}
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   172
13288
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13262
diff changeset
   173
void ThemePrompt::onRejected()
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13262
diff changeset
   174
{
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13262
diff changeset
   175
    reject();
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13262
diff changeset
   176
    filterModel->setFilterFixedString(QString());
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13262
diff changeset
   177
}
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13262
diff changeset
   178
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   179
void ThemePrompt::onAccepted()
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   180
{
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   181
    themeChosen(list->currentIndex());
13288
f816b9e73fcb ThemeFilterProxyModel: Fix filter function containing a path with no return value
Wuzzy <Wuzzy2@mail.ru>
parents: 13262
diff changeset
   182
    filterModel->setFilterFixedString(QString());
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   183
}
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   184
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   185
// When a theme is selected
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   186
void ThemePrompt::themeChosen(const QModelIndex & index)
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   187
{
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   188
    done(filterModel->mapToSource(index).row() + 1); // Since returning 0 means canceled
8385
9e8924ff9813 Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents: 8377
diff changeset
   189
}
8475
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   190
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   191
// When the text in the filter text box is changed
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   192
void ThemePrompt::filterChanged(const QString & text)
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   193
{
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   194
    filterModel->setFilterFixedString(text);
f605bc59c603 Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents: 8434
diff changeset
   195
    list->setCurrentIndex(filterModel->index(0, 0));
8534
92da587691c9 Workaround queued signals problem in netclient instead. Should fix everything.
unc0rr
parents: 8488
diff changeset
   196
}