author | sheepluva |
Fri, 05 Dec 2014 15:30:34 +0100 | |
changeset 10631 | 3d164350cc48 |
parent 10108 | c68cf030eded |
child 11046 | 47a8c19ecb60 |
permissions | -rw-r--r-- |
8374 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
9998 | 3 |
* Copyright (c) 2004-2014 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); |
|
63 |
setMinimumSize(550, 430); |
|
64 |
resize(550, 430); |
|
65 |
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); |
|
8374 | 66 |
|
8434 | 67 |
setStyleSheet("QPushButton { padding: 5px; margin-top: 10px; }"); |
8374 | 68 |
|
8434 | 69 |
// Hat model, and a model for setting a filter |
70 |
HatModel * hatModel = DataManager::instance().hatModel(); |
|
71 |
filterModel = new QSortFilterProxyModel(); |
|
72 |
filterModel->setSourceModel(hatModel); |
|
73 |
filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); |
|
8374 | 74 |
|
8434 | 75 |
// Grid |
76 |
QGridLayout * dialogLayout = new QGridLayout(this); |
|
77 |
dialogLayout->setSpacing(0); |
|
78 |
dialogLayout->setColumnStretch(1, 1); |
|
8374 | 79 |
|
8434 | 80 |
QHBoxLayout * topLayout = new QHBoxLayout(); |
8374 | 81 |
|
8434 | 82 |
// 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
|
83 |
QLabel * lblDesc = new QLabel(tr("Search for a hat:")); |
8434 | 84 |
lblDesc->setObjectName("lblDesc"); |
8374 | 85 |
lblDesc->setStyleSheet("#lblDesc { color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; border-top-left-radius: 10px; padding: 4px 10px;}"); |
86 |
lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
|
87 |
lblDesc->setFixedHeight(24); |
|
88 |
lblDesc->setMinimumWidth(0); |
|
89 |
||
90 |
// Filter text box |
|
91 |
QWidget * filterContainer = new QWidget(); |
|
92 |
filterContainer->setFixedHeight(24); |
|
93 |
filterContainer->setObjectName("filterContainer"); |
|
94 |
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
|
95 |
filterContainer->setFixedWidth(150); |
8374 | 96 |
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
|
97 |
txtFilter->setFixedWidth(150); |
8374 | 98 |
txtFilter->setFocus(); |
99 |
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
|
100 |
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 | 101 |
connect(txtFilter, SIGNAL(textChanged(const QString &)), this, SLOT(filterChanged(const QString &))); |
102 |
connect(txtFilter, SIGNAL(moveUp()), this, SLOT(moveUp())); |
|
103 |
connect(txtFilter, SIGNAL(moveDown()), this, SLOT(moveDown())); |
|
104 |
connect(txtFilter, SIGNAL(moveLeft()), this, SLOT(moveLeft())); |
|
105 |
connect(txtFilter, SIGNAL(moveRight()), this, SLOT(moveRight())); |
|
106 |
||
107 |
// Corner widget |
|
108 |
QLabel * corner = new QLabel(); |
|
109 |
corner->setPixmap(QPixmap(QString::fromUtf8(":/res/inverse-corner-bl.png"))); |
|
110 |
corner->setFixedSize(10, 10); |
|
111 |
||
112 |
// Add widgets to top layout |
|
113 |
topLayout->addWidget(lblDesc); |
|
114 |
topLayout->addWidget(filterContainer); |
|
115 |
topLayout->addWidget(corner, 0, Qt::AlignBottom); |
|
116 |
topLayout->addStretch(1); |
|
117 |
||
8434 | 118 |
// Cancel button (closes dialog) |
119 |
QPushButton * btnCancel = new QPushButton(tr("Cancel")); |
|
120 |
connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject())); |
|
8374 | 121 |
|
8434 | 122 |
// Select button |
123 |
QPushButton * btnSelect = new QPushButton(tr("Use selected hat")); |
|
124 |
btnSelect->setDefault(true); |
|
125 |
connect(btnSelect, SIGNAL(clicked()), this, SLOT(onAccepted())); |
|
8374 | 126 |
|
8434 | 127 |
// Add hats |
128 |
list = new HatListView(); |
|
129 |
list->setModel(filterModel); |
|
130 |
list->setViewMode(QListView::IconMode); |
|
131 |
list->setResizeMode(QListView::Adjust); |
|
132 |
list->setMovement(QListView::Static); |
|
133 |
list->setEditTriggers(QAbstractItemView::NoEditTriggers); |
|
134 |
list->setSpacing(8); |
|
135 |
list->setWordWrap(true); |
|
136 |
list->setSelectionMode(QAbstractItemView::SingleSelection); |
|
137 |
list->setObjectName("hatList"); |
|
138 |
list->setCurrentIndex(filterModel->index(currentIndex, 0)); |
|
139 |
connect(list, SIGNAL(activated(const QModelIndex &)), this, SLOT(hatChosen(const QModelIndex &))); |
|
140 |
connect(list, SIGNAL(clicked(const QModelIndex &)), this, SLOT(hatChosen(const QModelIndex &))); |
|
8374 | 141 |
|
8434 | 142 |
// Add elements to layouts |
143 |
dialogLayout->addLayout(topLayout, 0, 0, 1, 3); |
|
144 |
dialogLayout->addWidget(list, 1, 0, 1, 3); |
|
145 |
dialogLayout->addWidget(btnCancel, 2, 0, 1, 1, Qt::AlignLeft); |
|
146 |
dialogLayout->addWidget(btnSelect, 2, 2, 1, 1, Qt::AlignRight); |
|
8374 | 147 |
} |
148 |
||
149 |
void HatPrompt::moveUp() |
|
150 |
{ |
|
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
|
151 |
list->moveUp(); |
8374 | 152 |
} |
153 |
||
154 |
void HatPrompt::moveDown() |
|
155 |
{ |
|
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
|
156 |
list->moveDown(); |
8374 | 157 |
} |
158 |
||
159 |
void HatPrompt::moveLeft() |
|
160 |
{ |
|
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
|
161 |
list->moveLeft(); |
8374 | 162 |
} |
163 |
||
164 |
void HatPrompt::moveRight() |
|
165 |
{ |
|
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
|
166 |
list->moveRight(); |
8374 | 167 |
} |
168 |
||
169 |
void HatPrompt::onAccepted() |
|
170 |
{ |
|
8434 | 171 |
hatChosen(list->currentIndex()); |
8374 | 172 |
} |
173 |
||
174 |
// When a hat is selected |
|
175 |
void HatPrompt::hatChosen(const QModelIndex & index) |
|
176 |
{ |
|
8434 | 177 |
done(filterModel->mapToSource(index).row() + 1); // Since returning 0 means canceled |
8374 | 178 |
} |
179 |
||
180 |
// When the text in the filter text box is changed |
|
181 |
void HatPrompt::filterChanged(const QString & text) |
|
182 |
{ |
|
8434 | 183 |
filterModel->setFilterFixedString(text); |
184 |
list->setCurrentIndex(filterModel->index(0, 0)); |
|
8375 | 185 |
} |