14 * You should have received a copy of the GNU General Public License |
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 |
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 |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
17 */ |
17 */ |
18 |
18 |
|
19 #include <QVBoxLayout> |
|
20 #include <QHBoxLayout> |
19 #include <QGridLayout> |
21 #include <QGridLayout> |
20 #include <QHBoxLayout> |
|
21 #include <QPushButton> |
22 #include <QPushButton> |
22 #include <QComboBox> |
23 #include <QComboBox> |
23 #include <QLabel> |
24 #include <QLabel> |
24 #include <QLineEdit> |
25 #include <QLineEdit> |
25 #include <QMessageBox> |
26 #include <QMessageBox> |
26 #include <QHeaderView> |
27 #include <QHeaderView> |
27 #include <QTableView> |
28 #include <QGroupBox> |
|
29 #include <QFontMetrics> |
|
30 #include <QMenu> |
|
31 #include <QDebug> |
28 |
32 |
29 #include <QSortFilterProxyModel> |
33 #include <QSortFilterProxyModel> |
30 |
34 |
31 #include "roomslistmodel.h" |
35 #include "roomslistmodel.h" |
32 |
36 |
33 #include "ammoSchemeModel.h" |
37 #include "ammoSchemeModel.h" |
34 #include "pageroomslist.h" |
|
35 #include "hwconsts.h" |
38 #include "hwconsts.h" |
36 #include "chatwidget.h" |
39 #include "chatwidget.h" |
|
40 #include "roomnameprompt.h" |
|
41 #include "lineeditcursor.h" |
|
42 #include "pageroomslist.h" |
37 |
43 |
38 QLayout * PageRoomsList::bodyLayoutDefinition() |
44 QLayout * PageRoomsList::bodyLayoutDefinition() |
39 { |
45 { |
40 QGridLayout * pageLayout = new QGridLayout(); |
46 QVBoxLayout * pageLayout = new QVBoxLayout(); |
41 |
47 pageLayout->setSpacing(0); |
42 QHBoxLayout * newRoomLayout = new QHBoxLayout(); |
48 |
43 QLabel * roomNameLabel = new QLabel(this); |
49 QGridLayout * topLayout = new QGridLayout(); |
44 roomNameLabel->setText(tr("Room Name:")); |
50 topLayout->setSpacing(0); |
45 roomName = new QLineEdit(this); |
51 pageLayout->addLayout(topLayout, 0); |
46 roomName->setMaxLength(60); |
52 |
47 newRoomLayout->addWidget(roomNameLabel); |
53 // Help/prompt message at top |
48 newRoomLayout->addWidget(roomName); |
54 QLabel * lblDesc = new QLabel(tr("Join a room")); |
49 pageLayout->addLayout(newRoomLayout, 0, 0, 1, 2); |
55 lblDesc->setObjectName("lblDesc"); |
50 |
56 lblDesc->setStyleSheet("#lblDesc { color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; border-top-left-radius: 10px; padding: 4px 10px;}"); |
51 roomsList = new QTableView(this); |
57 lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
|
58 lblDesc->setFixedHeight(24); |
|
59 lblDesc->setMinimumWidth(0); |
|
60 |
|
61 // Search text box |
|
62 QWidget * searchContainer = new QWidget(); |
|
63 searchContainer->setFixedHeight(24); |
|
64 searchContainer->setObjectName("searchContainer"); |
|
65 searchContainer->setStyleSheet("#searchContainer { background: #F6CB1C; border-top-right-radius: 10px; padding: 3px; }"); |
|
66 searchContainer->setFixedWidth(250); |
|
67 searchText = new LineEditCursor(searchContainer); |
|
68 searchText->setFixedWidth(250); |
|
69 searchText->setMaxLength(60); |
|
70 searchText->setFixedHeight(22); |
|
71 |
|
72 // Search label |
|
73 QLabel * lblSearch = new QLabel(tr("Search: "), searchText); |
|
74 QFontMetrics lblMetrics(lblSearch->font()); |
|
75 int lblSearchWidth = lblMetrics.width(lblSearch->text()); |
|
76 lblSearch->setStyleSheet(QString("background: none; margin-left: -%1px; margin-top: 4px;").arg(lblSearchWidth + 5)); |
|
77 searchText->setStyleSheet(QString("LineEditCursor, QLabel { border-width: 0px; border-radius: 6px; margin-top: 3px; margin-right: 3px; padding-left: %1px; padding-bottom: 2px; background-color: rgb(23, 11, 54); } LineEditCursor:hover, LineEditCursor:focus { background-color: rgb(13, 5, 68); }").arg(lblSearchWidth + 5)); |
|
78 |
|
79 // Corner widget |
|
80 QLabel * corner = new QLabel(); |
|
81 corner->setPixmap(QPixmap(QString::fromUtf8(":/res/inverse-corner-bl.png"))); |
|
82 corner->setFixedSize(10, 10); |
|
83 |
|
84 const QIcon& lp = QIcon(":/res/new.png"); |
|
85 QSize sz = lp.actualSize(QSize(65535, 65535)); |
|
86 BtnCreate = new QPushButton(); |
|
87 BtnCreate->setText(tr("Create room")); |
|
88 BtnCreate->setIcon(lp); |
|
89 BtnCreate->setStyleSheet("padding: 4px 8px; margin-bottom: 6px;"); |
|
90 |
|
91 BtnJoin = new QPushButton(tr("Join room")); |
|
92 BtnJoin->setStyleSheet("padding: 4px 8px; margin-bottom: 6px; margin-left: 6px;"); |
|
93 BtnJoin->setEnabled(false); |
|
94 |
|
95 // Add widgets to top layout |
|
96 topLayout->addWidget(lblDesc, 1, 0); |
|
97 topLayout->addWidget(searchContainer, 1, 1); |
|
98 topLayout->addWidget(corner, 1, 2, Qt::AlignBottom); |
|
99 topLayout->addWidget(BtnCreate, 0, 4, 2, 1); |
|
100 topLayout->addWidget(BtnJoin, 0, 5, 2, 1); |
|
101 |
|
102 // Top layout stretch |
|
103 topLayout->setRowStretch(0, 1); |
|
104 topLayout->setRowStretch(1, 0); |
|
105 topLayout->setColumnStretch(3, 1); |
|
106 |
|
107 // Room list |
|
108 |
|
109 roomsList = new RoomTableView(this); |
52 roomsList->setSelectionBehavior(QAbstractItemView::SelectRows); |
110 roomsList->setSelectionBehavior(QAbstractItemView::SelectRows); |
53 roomsList->verticalHeader()->setVisible(false); |
111 roomsList->verticalHeader()->setVisible(false); |
54 roomsList->horizontalHeader()->setResizeMode(QHeaderView::Interactive); |
112 roomsList->horizontalHeader()->setResizeMode(QHeaderView::Interactive); |
55 roomsList->setAlternatingRowColors(true); |
113 roomsList->setAlternatingRowColors(true); |
56 roomsList->setShowGrid(false); |
114 roomsList->setShowGrid(false); |
57 roomsList->setSelectionMode(QAbstractItemView::SingleSelection); |
115 roomsList->setSelectionMode(QAbstractItemView::SingleSelection); |
58 pageLayout->addWidget(roomsList, 1, 0, 3, 2); |
116 roomsList->setStyleSheet("QTableView { border-top-left-radius: 0px; }"); |
59 pageLayout->setRowStretch(2, 100); |
117 roomsList->setFocusPolicy(Qt::NoFocus); |
60 |
118 pageLayout->addWidget(roomsList, 200); |
61 QHBoxLayout * filterLayout = new QHBoxLayout(); |
119 |
62 |
120 // Room filters container |
63 QLabel * stateLabel = new QLabel(this); |
121 |
64 CBState = new QComboBox(this); |
122 QWidget * filtersContainer = new QWidget(); |
65 |
123 filtersContainer->setMaximumWidth(800); |
66 filterLayout->addWidget(stateLabel); |
124 filtersContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
67 filterLayout->addWidget(CBState); |
125 |
68 filterLayout->addStretch(1); |
126 pageLayout->addSpacing(7); |
69 |
127 pageLayout->addWidget(filtersContainer, 0, Qt::AlignHCenter); |
70 QLabel * ruleLabel = new QLabel(this); |
128 pageLayout->addSpacing(7); |
71 ruleLabel->setText(tr("Rules:")); |
129 |
|
130 QHBoxLayout * filterLayout = new QHBoxLayout(filtersContainer); |
|
131 filterLayout->setSpacing(0); |
|
132 filterLayout->setMargin(0); |
|
133 |
|
134 const int filterSpacing = 20; |
|
135 |
|
136 // State button |
|
137 |
|
138 QPushButton * btnState = new QPushButton(tr("Room state")); |
|
139 btnState->setStyleSheet("QPushButton { padding: 2px 4px; } QPushButton:pressed { background-color: #ffcc00; border-color: #ffcc00; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; color: #11084A; }"); |
|
140 btnState->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); |
|
141 filterLayout->addWidget(btnState); |
|
142 filterLayout->addSpacing(filterSpacing); |
|
143 |
|
144 // State menu |
|
145 |
|
146 QMenu * stateMenu = new QMenu(btnState); |
|
147 showGamesInLobby = new QAction(QAction::tr("Show games in lobby"), stateMenu); |
|
148 showGamesInLobby->setCheckable(true); |
|
149 showGamesInLobby->setChecked(true); |
|
150 showGamesInProgress = new QAction(QAction::tr("Show games in-progress"), stateMenu); |
|
151 showGamesInProgress->setCheckable(true); |
|
152 showGamesInProgress->setChecked(true); |
|
153 stateMenu->addAction(showGamesInLobby); |
|
154 stateMenu->addAction(showGamesInProgress); |
|
155 btnState->setMenu(stateMenu); |
|
156 |
|
157 // Rules dropdown |
|
158 |
72 CBRules = new QComboBox(this); |
159 CBRules = new QComboBox(this); |
|
160 CBRules->setStyleSheet("QComboBox { border-top-left-radius: 0px; border-bottom-left-radius: 0px; border-left-width: 2px; }"); |
|
161 |
|
162 QLabel * ruleLabel = new QLabel(tr("Rules:"), this); |
|
163 ruleLabel->setFixedHeight(CBRules->height()); |
|
164 ruleLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
|
165 ruleLabel->setStyleSheet("border: solid; border-width: 3px; border-right-width: 0px; border-color: #ffcc00; border-top-left-radius: 10px; border-bottom-left-radius: 10px; background-color: rgba(13, 5, 68, 70%);"); |
73 |
166 |
74 filterLayout->addWidget(ruleLabel); |
167 filterLayout->addWidget(ruleLabel); |
75 filterLayout->addWidget(CBRules); |
168 filterLayout->addWidget(CBRules); |
76 filterLayout->addStretch(1); |
169 filterLayout->addSpacing(filterSpacing); |
77 |
170 |
78 QLabel * weaponLabel = new QLabel(this); |
171 // Weapons dropdown |
79 weaponLabel->setText(tr("Weapons:")); |
172 |
80 CBWeapons = new QComboBox(this); |
173 CBWeapons = new QComboBox(this); |
|
174 CBWeapons->setStyleSheet("QComboBox { border-top-left-radius: 0px; border-bottom-left-radius: 0px; border-left-width: 2px; }"); |
|
175 |
|
176 QLabel * weaponLabel = new QLabel(tr("Weapons:"), this); |
|
177 weaponLabel->setFixedHeight(CBWeapons->height()); |
|
178 weaponLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
|
179 weaponLabel->setStyleSheet("border: solid; border-width: 3px; border-right-width: 0px; border-color: #ffcc00; border-top-left-radius: 10px; border-bottom-left-radius: 10px; background-color: rgba(13, 5, 68, 70%);"); |
81 |
180 |
82 filterLayout->addWidget(weaponLabel); |
181 filterLayout->addWidget(weaponLabel); |
83 filterLayout->addWidget(CBWeapons); |
182 filterLayout->addWidget(CBWeapons); |
84 filterLayout->addStretch(1); |
183 filterLayout->addSpacing(filterSpacing); |
85 |
184 |
86 QLabel * searchLabel = new QLabel(this); |
185 // Clear filters button |
87 searchLabel->setText(tr("Search:")); |
186 |
88 searchText = new QLineEdit(this); |
187 BtnClear = addButton(tr("Clear filters"), filterLayout, 0); |
89 searchText->setMaxLength(60); |
188 weaponLabel->setFixedHeight(CBWeapons->height()); |
90 searchText->setMinimumWidth(100); |
189 BtnClear->setStyleSheet("padding: 4px;"); |
91 searchText->setMaximumWidth(360); |
190 |
92 filterLayout->addWidget(searchLabel); |
191 // Lobby chat |
93 filterLayout->addWidget(searchText); |
|
94 filterLayout->setStretchFactor(searchText, 2); |
|
95 |
|
96 pageLayout->addLayout(filterLayout, 4, 0, 1, 2); |
|
97 |
192 |
98 chatWidget = new HWChatWidget(this, false); |
193 chatWidget = new HWChatWidget(this, false); |
99 pageLayout->addWidget(chatWidget, 5, 0, 1, 3); |
194 pageLayout->addWidget(chatWidget, 350); |
100 pageLayout->setRowStretch(5, 350); |
|
101 |
|
102 BtnCreate = addButton(tr("Create"), pageLayout, 0, 2); |
|
103 BtnJoin = addButton(tr("Join"), pageLayout, 1, 2); |
|
104 BtnClear = addButton(tr("Clear"), pageLayout, 4, 2); |
|
105 |
|
106 // strech all but the buttons column |
|
107 pageLayout->setColumnStretch(0, 1); |
|
108 pageLayout->setColumnStretch(1, 1); |
|
109 pageLayout->setColumnStretch(2, 0); |
|
110 |
195 |
111 CBRules->addItem(QComboBox::tr("Any")); |
196 CBRules->addItem(QComboBox::tr("Any")); |
112 CBState->addItem(QComboBox::tr("Any")); |
|
113 CBState->addItem(QComboBox::tr("In lobby")); |
|
114 CBState->addItem(QComboBox::tr("In progress")); |
|
115 |
197 |
116 return pageLayout; |
198 return pageLayout; |
117 } |
199 } |
118 |
200 |
119 QLayout * PageRoomsList::footerLayoutDefinition() |
201 QLayout * PageRoomsList::footerLayoutDefinition() |
120 { |
202 { |
121 QHBoxLayout * bottomLayout = new QHBoxLayout(); |
203 QHBoxLayout * bottomLayout = new QHBoxLayout(); |
122 |
204 |
123 lblCount = new QLabel(this); |
205 BtnAdmin = addButton(tr("Admin features"), bottomLayout, 0); |
124 bottomLayout->addWidget(lblCount, 0, Qt::AlignHCenter); |
206 BtnAdmin->setStyleSheet("padding: 4px auto;"); |
125 bottomLayout->setStretchFactor(lblCount, 1); |
207 BtnAdmin->setWhatsThis(tr("Open server administration page")); |
126 lblCount->setText("?"); |
|
127 lblCount->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
|
128 |
|
129 BtnAdmin = addButton(tr("Admin features"), bottomLayout, 1); |
|
130 BtnAdmin->setMinimumWidth(160); |
|
131 |
|
132 // strech left part |
|
133 bottomLayout->setStretch(0, 1); |
|
134 bottomLayout->setStretch(1, 0); |
|
135 |
208 |
136 return bottomLayout; |
209 return bottomLayout; |
137 } |
210 } |
138 |
211 |
139 void PageRoomsList::connectSignals() |
212 void PageRoomsList::connectSignals() |
141 connect(chatWidget, SIGNAL(nickCountUpdate(const int)), this, SLOT(updateNickCounter(const int))); |
214 connect(chatWidget, SIGNAL(nickCountUpdate(const int)), this, SLOT(updateNickCounter(const int))); |
142 |
215 |
143 connect(BtnCreate, SIGNAL(clicked()), this, SLOT(onCreateClick())); |
216 connect(BtnCreate, SIGNAL(clicked()), this, SLOT(onCreateClick())); |
144 connect(BtnJoin, SIGNAL(clicked()), this, SLOT(onJoinClick())); |
217 connect(BtnJoin, SIGNAL(clicked()), this, SLOT(onJoinClick())); |
145 connect(BtnClear, SIGNAL(clicked()), this, SLOT(onClearClick())); |
218 connect(BtnClear, SIGNAL(clicked()), this, SLOT(onClearClick())); |
|
219 connect(searchText, SIGNAL(moveUp()), this, SLOT(moveSelectionUp())); |
|
220 connect(searchText, SIGNAL(moveDown()), this, SLOT(moveSelectionDown())); |
|
221 connect(searchText, SIGNAL(returnPressed()), this, SLOT(onJoinClick())); |
146 connect(roomsList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(onJoinClick())); |
222 connect(roomsList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(onJoinClick())); |
147 connect(CBState, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged())); |
223 connect(roomsList, SIGNAL(clicked (const QModelIndex &)), searchText, SLOT(setFocus())); |
|
224 connect(showGamesInLobby, SIGNAL(triggered()), this, SLOT(onFilterChanged())); |
|
225 connect(showGamesInProgress, SIGNAL(triggered()), this, SLOT(onFilterChanged())); |
148 connect(CBRules, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged())); |
226 connect(CBRules, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged())); |
149 connect(CBWeapons, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged())); |
227 connect(CBWeapons, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged())); |
150 connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onFilterChanged())); |
228 connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onFilterChanged())); |
151 connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection); |
229 connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection); |
152 |
230 |
|
231 // Set focus on search box |
|
232 connect(this, SIGNAL(pageEnter()), searchText, SLOT(setFocus())); |
|
233 |
153 // sorting |
234 // sorting |
154 connect(roomsList->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), |
235 connect(roomsList->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), |
155 this, SLOT(onSortIndicatorChanged(int, Qt::SortOrder))); |
236 this, SLOT(onSortIndicatorChanged(int, Qt::SortOrder))); |
156 } |
237 } |
157 |
238 |
|
239 void PageRoomsList::moveSelectionUp() |
|
240 { |
|
241 roomsList->setCurrentIndex(roomsList->moveCursor(QAbstractItemView::MoveUp, Qt::NoModifier)); |
|
242 } |
|
243 |
|
244 void PageRoomsList::moveSelectionDown() |
|
245 { |
|
246 roomsList->setCurrentIndex(roomsList->moveCursor(QAbstractItemView::MoveDown, Qt::NoModifier)); |
|
247 } |
|
248 |
|
249 void PageRoomsList::roomSelectionChanged(const QModelIndex & current, const QModelIndex & previous) |
|
250 { |
|
251 BtnJoin->setEnabled(current.isValid()); |
|
252 } |
158 |
253 |
159 PageRoomsList::PageRoomsList(QWidget* parent) : |
254 PageRoomsList::PageRoomsList(QWidget* parent) : |
160 AbstractPage(parent) |
255 AbstractPage(parent) |
161 { |
256 { |
162 roomsModel = NULL; |
257 roomsModel = NULL; |