author | koda |
Thu, 28 Feb 2013 22:59:22 +0100 | |
changeset 8609 | 3f6c08223aa1 |
parent 8488 | e72f3398a28b |
child 8731 | 924840dad6a0 |
permissions | -rw-r--r-- |
8374 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
|
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 |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
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 |
||
38 |
HatPrompt::HatPrompt(int currentIndex, QWidget* parent) : QDialog(parent) |
|
39 |
{ |
|
8434 | 40 |
setModal(true); |
41 |
setWindowFlags(Qt::Sheet); |
|
42 |
setWindowModality(Qt::WindowModal); |
|
43 |
setMinimumSize(550, 430); |
|
44 |
resize(550, 430); |
|
45 |
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); |
|
8374 | 46 |
|
8434 | 47 |
setStyleSheet("QPushButton { padding: 5px; margin-top: 10px; }"); |
8374 | 48 |
|
8434 | 49 |
// Hat model, and a model for setting a filter |
50 |
HatModel * hatModel = DataManager::instance().hatModel(); |
|
51 |
filterModel = new QSortFilterProxyModel(); |
|
52 |
filterModel->setSourceModel(hatModel); |
|
53 |
filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); |
|
8374 | 54 |
|
8434 | 55 |
// Grid |
56 |
QGridLayout * dialogLayout = new QGridLayout(this); |
|
57 |
dialogLayout->setSpacing(0); |
|
58 |
dialogLayout->setColumnStretch(1, 1); |
|
8374 | 59 |
|
8434 | 60 |
QHBoxLayout * topLayout = new QHBoxLayout(); |
8374 | 61 |
|
8434 | 62 |
// 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
|
63 |
QLabel * lblDesc = new QLabel(tr("Search for a hat:")); |
8434 | 64 |
lblDesc->setObjectName("lblDesc"); |
8374 | 65 |
lblDesc->setStyleSheet("#lblDesc { color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; border-top-left-radius: 10px; padding: 4px 10px;}"); |
66 |
lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
|
67 |
lblDesc->setFixedHeight(24); |
|
68 |
lblDesc->setMinimumWidth(0); |
|
69 |
||
70 |
// Filter text box |
|
71 |
QWidget * filterContainer = new QWidget(); |
|
72 |
filterContainer->setFixedHeight(24); |
|
73 |
filterContainer->setObjectName("filterContainer"); |
|
74 |
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
|
75 |
filterContainer->setFixedWidth(150); |
8374 | 76 |
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
|
77 |
txtFilter->setFixedWidth(150); |
8374 | 78 |
txtFilter->setFocus(); |
79 |
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
|
80 |
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 | 81 |
connect(txtFilter, SIGNAL(textChanged(const QString &)), this, SLOT(filterChanged(const QString &))); |
82 |
connect(txtFilter, SIGNAL(moveUp()), this, SLOT(moveUp())); |
|
83 |
connect(txtFilter, SIGNAL(moveDown()), this, SLOT(moveDown())); |
|
84 |
connect(txtFilter, SIGNAL(moveLeft()), this, SLOT(moveLeft())); |
|
85 |
connect(txtFilter, SIGNAL(moveRight()), this, SLOT(moveRight())); |
|
86 |
||
87 |
// Corner widget |
|
88 |
QLabel * corner = new QLabel(); |
|
89 |
corner->setPixmap(QPixmap(QString::fromUtf8(":/res/inverse-corner-bl.png"))); |
|
90 |
corner->setFixedSize(10, 10); |
|
91 |
||
92 |
// Add widgets to top layout |
|
93 |
topLayout->addWidget(lblDesc); |
|
94 |
topLayout->addWidget(filterContainer); |
|
95 |
topLayout->addWidget(corner, 0, Qt::AlignBottom); |
|
96 |
topLayout->addStretch(1); |
|
97 |
||
8434 | 98 |
// Cancel button (closes dialog) |
99 |
QPushButton * btnCancel = new QPushButton(tr("Cancel")); |
|
100 |
connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject())); |
|
8374 | 101 |
|
8434 | 102 |
// Select button |
103 |
QPushButton * btnSelect = new QPushButton(tr("Use selected hat")); |
|
104 |
btnSelect->setDefault(true); |
|
105 |
connect(btnSelect, SIGNAL(clicked()), this, SLOT(onAccepted())); |
|
8374 | 106 |
|
8434 | 107 |
// Add hats |
108 |
list = new HatListView(); |
|
109 |
list->setModel(filterModel); |
|
110 |
list->setViewMode(QListView::IconMode); |
|
111 |
list->setResizeMode(QListView::Adjust); |
|
112 |
list->setMovement(QListView::Static); |
|
113 |
list->setEditTriggers(QAbstractItemView::NoEditTriggers); |
|
114 |
list->setSpacing(8); |
|
115 |
list->setWordWrap(true); |
|
116 |
list->setSelectionMode(QAbstractItemView::SingleSelection); |
|
117 |
list->setObjectName("hatList"); |
|
118 |
list->setCurrentIndex(filterModel->index(currentIndex, 0)); |
|
119 |
connect(list, SIGNAL(activated(const QModelIndex &)), this, SLOT(hatChosen(const QModelIndex &))); |
|
120 |
connect(list, SIGNAL(clicked(const QModelIndex &)), this, SLOT(hatChosen(const QModelIndex &))); |
|
8374 | 121 |
|
8434 | 122 |
// Add elements to layouts |
123 |
dialogLayout->addLayout(topLayout, 0, 0, 1, 3); |
|
124 |
dialogLayout->addWidget(list, 1, 0, 1, 3); |
|
125 |
dialogLayout->addWidget(btnCancel, 2, 0, 1, 1, Qt::AlignLeft); |
|
126 |
dialogLayout->addWidget(btnSelect, 2, 2, 1, 1, Qt::AlignRight); |
|
8374 | 127 |
} |
128 |
||
129 |
void HatPrompt::moveUp() |
|
130 |
{ |
|
8434 | 131 |
list->setCurrentIndex(list->moveCursor(QAbstractItemView::MoveUp, Qt::NoModifier)); |
8374 | 132 |
} |
133 |
||
134 |
void HatPrompt::moveDown() |
|
135 |
{ |
|
8434 | 136 |
list->setCurrentIndex(list->moveCursor(QAbstractItemView::MoveDown, Qt::NoModifier)); |
8374 | 137 |
} |
138 |
||
139 |
void HatPrompt::moveLeft() |
|
140 |
{ |
|
8434 | 141 |
list->setCurrentIndex(list->moveCursor(QAbstractItemView::MoveLeft, Qt::NoModifier)); |
8374 | 142 |
} |
143 |
||
144 |
void HatPrompt::moveRight() |
|
145 |
{ |
|
8434 | 146 |
list->setCurrentIndex(list->moveCursor(QAbstractItemView::MoveRight, Qt::NoModifier)); |
8374 | 147 |
} |
148 |
||
149 |
void HatPrompt::onAccepted() |
|
150 |
{ |
|
8434 | 151 |
hatChosen(list->currentIndex()); |
8374 | 152 |
} |
153 |
||
154 |
// When a hat is selected |
|
155 |
void HatPrompt::hatChosen(const QModelIndex & index) |
|
156 |
{ |
|
8434 | 157 |
done(filterModel->mapToSource(index).row() + 1); // Since returning 0 means canceled |
8374 | 158 |
} |
159 |
||
160 |
// When the text in the filter text box is changed |
|
161 |
void HatPrompt::filterChanged(const QString & text) |
|
162 |
{ |
|
8434 | 163 |
filterModel->setFilterFixedString(text); |
164 |
list->setCurrentIndex(filterModel->index(0, 0)); |
|
8375 | 165 |
} |