author | Wuzzy <Wuzzy2@mail.ru> |
Fri, 21 Dec 2018 08:00:46 +0100 | |
changeset 14490 | 6ac723d0fcb6 |
parent 11490 | fb7817a5c2b1 |
permissions | -rw-r--r-- |
8374 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
8374 | 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 |
|
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 |
8374 | 17 |
*/ |
18 |
||
19 |
#include <QDialog> |
|
20 |
#include <QGridLayout> |
|
21 |
#include <QHBoxLayout> |
|
22 |
#include <QScrollArea> |
|
23 |
#include <QPushButton> |
|
24 |
#include <QToolButton> |
|
25 |
#include <QWidgetItem> |
|
26 |
#include <QModelIndex> |
|
27 |
#include <QListView> |
|
28 |
#include <QLineEdit> |
|
29 |
#include <QLabel> |
|
30 |
#include <QSortFilterProxyModel> |
|
31 |
#include <QDebug> |
|
32 |
||
8375 | 33 |
#include "DataManager.h" |
8374 | 34 |
#include "lineeditcursor.h" |
8375 | 35 |
#include "HatModel.h" |
8374 | 36 |
#include "hatprompt.h" |
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:
8488
diff
changeset
|
38 |
void HatListView::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:
8488
diff
changeset
|
39 |
{ |
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:
8488
diff
changeset
|
40 |
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:
8488
diff
changeset
|
41 |
} |
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:
8488
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:
8488
diff
changeset
|
43 |
void HatListView::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:
8488
diff
changeset
|
44 |
{ |
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:
8488
diff
changeset
|
45 |
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:
8488
diff
changeset
|
46 |
} |
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:
8488
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:
8488
diff
changeset
|
48 |
void HatListView::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:
8488
diff
changeset
|
49 |
{ |
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:
8488
diff
changeset
|
50 |
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:
8488
diff
changeset
|
51 |
} |
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:
8488
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:
8488
diff
changeset
|
53 |
void HatListView::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:
8488
diff
changeset
|
54 |
{ |
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:
8488
diff
changeset
|
55 |
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:
8488
diff
changeset
|
56 |
} |
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:
8488
diff
changeset
|
57 |
|
8374 | 58 |
HatPrompt::HatPrompt(int currentIndex, QWidget* parent) : QDialog(parent) |
59 |
{ |
|
8434 | 60 |
setModal(true); |
61 |
setWindowFlags(Qt::Sheet); |
|
62 |
setWindowModality(Qt::WindowModal); |
|
11490
fb7817a5c2b1
Add window titles for title-less windows
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
63 |
setWindowTitle(tr("Choose a hat")); |
8434 | 64 |
setMinimumSize(550, 430); |
65 |
resize(550, 430); |
|
66 |
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); |
|
8374 | 67 |
|
8434 | 68 |
setStyleSheet("QPushButton { padding: 5px; margin-top: 10px; }"); |
8374 | 69 |
|
8434 | 70 |
// Hat model, and a model for setting a filter |
71 |
HatModel * hatModel = DataManager::instance().hatModel(); |
|
72 |
filterModel = new QSortFilterProxyModel(); |
|
73 |
filterModel->setSourceModel(hatModel); |
|
74 |
filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); |
|
8374 | 75 |
|
8434 | 76 |
// Grid |
77 |
QGridLayout * dialogLayout = new QGridLayout(this); |
|
78 |
dialogLayout->setSpacing(0); |
|
79 |
dialogLayout->setColumnStretch(1, 1); |
|
8374 | 80 |
|
8434 | 81 |
QHBoxLayout * topLayout = new QHBoxLayout(); |
8374 | 82 |
|
8434 | 83 |
// 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:
8453
diff
changeset
|
84 |
QLabel * lblDesc = new QLabel(tr("Search for a hat:")); |
8434 | 85 |
lblDesc->setObjectName("lblDesc"); |
8374 | 86 |
lblDesc->setStyleSheet("#lblDesc { color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; border-top-left-radius: 10px; padding: 4px 10px;}"); |
87 |
lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
|
88 |
lblDesc->setFixedHeight(24); |
|
89 |
lblDesc->setMinimumWidth(0); |
|
90 |
||
91 |
// Filter text box |
|
92 |
QWidget * filterContainer = new QWidget(); |
|
93 |
filterContainer->setFixedHeight(24); |
|
94 |
filterContainer->setObjectName("filterContainer"); |
|
95 |
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:
8453
diff
changeset
|
96 |
filterContainer->setFixedWidth(150); |
8374 | 97 |
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:
8453
diff
changeset
|
98 |
txtFilter->setFixedWidth(150); |
8374 | 99 |
txtFilter->setFocus(); |
100 |
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:
8453
diff
changeset
|
101 |
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); }"); |
8374 | 102 |
connect(txtFilter, SIGNAL(textChanged(const QString &)), this, SLOT(filterChanged(const QString &))); |
103 |
connect(txtFilter, SIGNAL(moveUp()), this, SLOT(moveUp())); |
|
104 |
connect(txtFilter, SIGNAL(moveDown()), this, SLOT(moveDown())); |
|
105 |
connect(txtFilter, SIGNAL(moveLeft()), this, SLOT(moveLeft())); |
|
106 |
connect(txtFilter, SIGNAL(moveRight()), this, SLOT(moveRight())); |
|
107 |
||
108 |
// Corner widget |
|
109 |
QLabel * corner = new QLabel(); |
|
110 |
corner->setPixmap(QPixmap(QString::fromUtf8(":/res/inverse-corner-bl.png"))); |
|
111 |
corner->setFixedSize(10, 10); |
|
112 |
||
113 |
// Add widgets to top layout |
|
114 |
topLayout->addWidget(lblDesc); |
|
115 |
topLayout->addWidget(filterContainer); |
|
116 |
topLayout->addWidget(corner, 0, Qt::AlignBottom); |
|
117 |
topLayout->addStretch(1); |
|
118 |
||
8434 | 119 |
// Cancel button (closes dialog) |
120 |
QPushButton * btnCancel = new QPushButton(tr("Cancel")); |
|
121 |
connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject())); |
|
8374 | 122 |
|
8434 | 123 |
// Select button |
124 |
QPushButton * btnSelect = new QPushButton(tr("Use selected hat")); |
|
125 |
btnSelect->setDefault(true); |
|
126 |
connect(btnSelect, SIGNAL(clicked()), this, SLOT(onAccepted())); |
|
8374 | 127 |
|
8434 | 128 |
// Add hats |
129 |
list = new HatListView(); |
|
130 |
list->setModel(filterModel); |
|
131 |
list->setViewMode(QListView::IconMode); |
|
132 |
list->setResizeMode(QListView::Adjust); |
|
133 |
list->setMovement(QListView::Static); |
|
134 |
list->setEditTriggers(QAbstractItemView::NoEditTriggers); |
|
135 |
list->setSpacing(8); |
|
136 |
list->setWordWrap(true); |
|
137 |
list->setSelectionMode(QAbstractItemView::SingleSelection); |
|
138 |
list->setObjectName("hatList"); |
|
139 |
list->setCurrentIndex(filterModel->index(currentIndex, 0)); |
|
140 |
connect(list, SIGNAL(activated(const QModelIndex &)), this, SLOT(hatChosen(const QModelIndex &))); |
|
141 |
connect(list, SIGNAL(clicked(const QModelIndex &)), this, SLOT(hatChosen(const QModelIndex &))); |
|
8374 | 142 |
|
8434 | 143 |
// Add elements to layouts |
144 |
dialogLayout->addLayout(topLayout, 0, 0, 1, 3); |
|
145 |
dialogLayout->addWidget(list, 1, 0, 1, 3); |
|
146 |
dialogLayout->addWidget(btnCancel, 2, 0, 1, 1, Qt::AlignLeft); |
|
147 |
dialogLayout->addWidget(btnSelect, 2, 2, 1, 1, Qt::AlignRight); |
|
8374 | 148 |
} |
149 |
||
150 |
void HatPrompt::moveUp() |
|
151 |
{ |
|
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:
8488
diff
changeset
|
152 |
list->moveUp(); |
8374 | 153 |
} |
154 |
||
155 |
void HatPrompt::moveDown() |
|
156 |
{ |
|
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:
8488
diff
changeset
|
157 |
list->moveDown(); |
8374 | 158 |
} |
159 |
||
160 |
void HatPrompt::moveLeft() |
|
161 |
{ |
|
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:
8488
diff
changeset
|
162 |
list->moveLeft(); |
8374 | 163 |
} |
164 |
||
165 |
void HatPrompt::moveRight() |
|
166 |
{ |
|
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:
8488
diff
changeset
|
167 |
list->moveRight(); |
8374 | 168 |
} |
169 |
||
170 |
void HatPrompt::onAccepted() |
|
171 |
{ |
|
8434 | 172 |
hatChosen(list->currentIndex()); |
8374 | 173 |
} |
174 |
||
175 |
// When a hat is selected |
|
176 |
void HatPrompt::hatChosen(const QModelIndex & index) |
|
177 |
{ |
|
8434 | 178 |
done(filterModel->mapToSource(index).row() + 1); // Since returning 0 means canceled |
8374 | 179 |
} |
180 |
||
181 |
// When the text in the filter text box is changed |
|
182 |
void HatPrompt::filterChanged(const QString & text) |
|
183 |
{ |
|
8434 | 184 |
filterModel->setFilterFixedString(text); |
185 |
list->setCurrentIndex(filterModel->index(0, 0)); |
|
8375 | 186 |
} |