1 /* |
1 /* |
2 * Hedgewars, a free turn based strategy game |
2 * Hedgewars, a free turn based strategy game |
3 * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com> |
3 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
4 * |
4 * |
5 * This program is free software; you can redistribute it and/or modify |
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 |
6 * it under the terms of the GNU General Public License as published by |
7 * the Free Software Foundation; version 2 of the License |
7 * the Free Software Foundation; version 2 of the License |
8 * |
8 * |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. |
12 * GNU General Public License for more details. |
13 * |
13 * |
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
17 */ |
17 */ |
18 |
18 |
19 #include <QVBoxLayout> |
19 #include <QVBoxLayout> |
20 #include <QHBoxLayout> |
20 #include <QHBoxLayout> |
21 #include <QGridLayout> |
21 #include <QGridLayout> |
51 setCurrentIndex(moveCursor(QAbstractItemView::MoveUp, Qt::NoModifier)); |
51 setCurrentIndex(moveCursor(QAbstractItemView::MoveUp, Qt::NoModifier)); |
52 } |
52 } |
53 |
53 |
54 QLayout * PageRoomsList::bodyLayoutDefinition() |
54 QLayout * PageRoomsList::bodyLayoutDefinition() |
55 { |
55 { |
|
56 // TODO move stylesheet stuff into css/qt.css |
|
57 |
56 QVBoxLayout * pageLayout = new QVBoxLayout(); |
58 QVBoxLayout * pageLayout = new QVBoxLayout(); |
57 pageLayout->setSpacing(0); |
59 pageLayout->setSpacing(0); |
58 |
60 |
59 QGridLayout * topLayout = new QGridLayout(); |
61 QGridLayout * topLayout = new QGridLayout(); |
60 topLayout->setSpacing(0); |
62 topLayout->setSpacing(0); |
61 pageLayout->addLayout(topLayout, 0); |
63 pageLayout->addLayout(topLayout, 0); |
62 |
64 |
|
65 // State button |
|
66 |
|
67 QPushButton * btnState = new QPushButton(tr("Room state")); |
|
68 btnState->setStyleSheet("QPushButton { background-color: #F6CB1C; border-color: #F6CB1C; color: #130F2A; padding: 1px 3px 3px 3px; margin: 0px; border-bottom: none; border-radius: 0px; border-top-left-radius: 10px; } QPushButton:hover { background-color: #FFEB3C; border-color: #F6CB1C; color: #000000 } QPushButton:pressed { background-color: #FFEB3C; border-color: #F6CB1C; color: #000000; }"); |
|
69 btnState->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); |
|
70 |
|
71 // State menu |
|
72 |
|
73 QMenu * stateMenu = new QMenu(btnState); |
|
74 showGamesInLobby = new QAction(QAction::tr("Show games in lobby"), stateMenu); |
|
75 showGamesInLobby->setCheckable(true); |
|
76 showGamesInLobby->setChecked(true); |
|
77 showGamesInProgress = new QAction(QAction::tr("Show games in-progress"), stateMenu); |
|
78 showGamesInProgress->setCheckable(true); |
|
79 showGamesInProgress->setChecked(true); |
|
80 showPassword = new QAction(QAction::tr("Show password protected"), stateMenu); |
|
81 showPassword->setCheckable(true); |
|
82 showPassword->setChecked(true); |
|
83 showJoinRestricted = new QAction(QAction::tr("Show join restricted"), stateMenu); |
|
84 showJoinRestricted->setCheckable(true); |
|
85 showJoinRestricted->setChecked(true); |
|
86 stateMenu->addAction(showGamesInLobby); |
|
87 stateMenu->addAction(showGamesInProgress); |
|
88 stateMenu->addAction(showPassword); |
|
89 stateMenu->addAction(showJoinRestricted); |
|
90 btnState->setMenu(stateMenu); |
|
91 |
63 // Help/prompt message at top |
92 // Help/prompt message at top |
64 QLabel * lblDesc = new QLabel(tr("Search for a room:")); |
93 QLabel * lblDesc = new QLabel(tr("Search for a room:")); |
65 lblDesc->setObjectName("lblDesc"); |
94 lblDesc->setObjectName("lblDesc"); |
66 lblDesc->setStyleSheet("#lblDesc { color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; border-top-left-radius: 10px; padding: 4px 10px;}"); |
95 lblDesc->setStyleSheet("#lblDesc { color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; padding: 5px 10px 3px 6px;}"); |
67 lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
96 lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
68 lblDesc->setFixedHeight(24); |
97 lblDesc->setFixedHeight(24); |
69 lblDesc->setMinimumWidth(0); |
98 lblDesc->setMinimumWidth(0); |
70 |
99 |
71 // Search text box |
100 // Search text box |
95 BtnJoin = new QPushButton(tr("Join room")); |
124 BtnJoin = new QPushButton(tr("Join room")); |
96 BtnJoin->setStyleSheet("padding: 4px 8px; margin-bottom: 6px; margin-left: 6px;"); |
125 BtnJoin->setStyleSheet("padding: 4px 8px; margin-bottom: 6px; margin-left: 6px;"); |
97 BtnJoin->setEnabled(false); |
126 BtnJoin->setEnabled(false); |
98 |
127 |
99 // Add widgets to top layout |
128 // Add widgets to top layout |
100 topLayout->addWidget(lblDesc, 1, 0); |
129 topLayout->addWidget(btnState, 1, 0); |
101 topLayout->addWidget(searchContainer, 1, 1); |
130 topLayout->addWidget(lblDesc, 1, 1); |
102 topLayout->addWidget(corner, 1, 2, Qt::AlignBottom); |
131 topLayout->addWidget(searchContainer, 1, 2); |
103 topLayout->addWidget(BtnCreate, 0, 4, 2, 1); |
132 topLayout->addWidget(corner, 1, 3, Qt::AlignBottom); |
104 topLayout->addWidget(BtnJoin, 0, 5, 2, 1); |
133 topLayout->addWidget(BtnCreate, 0, 5, 2, 1); |
|
134 topLayout->addWidget(BtnJoin, 0, 6, 2, 1); |
105 |
135 |
106 // Top layout stretch |
136 // Top layout stretch |
107 topLayout->setRowStretch(0, 1); |
137 topLayout->setRowStretch(0, 1); |
108 topLayout->setRowStretch(1, 0); |
138 topLayout->setRowStretch(1, 0); |
109 topLayout->setColumnStretch(3, 1); |
139 topLayout->setColumnStretch(4, 1); |
110 |
140 |
111 // Rooms list and chat with splitter |
141 // Rooms list and chat with splitter |
112 m_splitter = new QSplitter(); |
142 m_splitter = new QSplitter(); |
113 m_splitter->setChildrenCollapsible(false); |
143 m_splitter->setChildrenCollapsible(false); |
114 pageLayout->addWidget(m_splitter, 100); |
144 pageLayout->addWidget(m_splitter, 100); |
130 roomsList->setSelectionMode(QAbstractItemView::SingleSelection); |
160 roomsList->setSelectionMode(QAbstractItemView::SingleSelection); |
131 roomsList->setStyleSheet("QTableView { border-top-left-radius: 0px; }"); |
161 roomsList->setStyleSheet("QTableView { border-top-left-radius: 0px; }"); |
132 roomsList->setFocusPolicy(Qt::NoFocus); |
162 roomsList->setFocusPolicy(Qt::NoFocus); |
133 roomsLayout->addWidget(roomsList, 200); |
163 roomsLayout->addWidget(roomsList, 200); |
134 |
164 |
135 // Room filters container |
|
136 |
|
137 QWidget * filtersContainer = new QWidget(); |
|
138 filtersContainer->setMaximumWidth(800); |
|
139 filtersContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
|
140 |
|
141 roomsLayout->addSpacing(7); |
|
142 roomsLayout->addWidget(filtersContainer, 0, Qt::AlignHCenter); |
|
143 roomsLayout->addSpacing(7); |
|
144 |
|
145 QHBoxLayout * filterLayout = new QHBoxLayout(filtersContainer); |
|
146 filterLayout->setSpacing(0); |
|
147 filterLayout->setMargin(0); |
|
148 |
|
149 const int filterSpacing = 20; |
|
150 |
|
151 // State button |
|
152 |
|
153 QPushButton * btnState = new QPushButton(tr("Room state")); |
|
154 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; }"); |
|
155 btnState->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); |
|
156 filterLayout->addWidget(btnState); |
|
157 filterLayout->addSpacing(filterSpacing); |
|
158 |
|
159 // State menu |
|
160 |
|
161 QMenu * stateMenu = new QMenu(btnState); |
|
162 showGamesInLobby = new QAction(QAction::tr("Show games in lobby"), stateMenu); |
|
163 showGamesInLobby->setCheckable(true); |
|
164 showGamesInLobby->setChecked(true); |
|
165 showGamesInProgress = new QAction(QAction::tr("Show games in-progress"), stateMenu); |
|
166 showGamesInProgress->setCheckable(true); |
|
167 showGamesInProgress->setChecked(true); |
|
168 stateMenu->addAction(showGamesInLobby); |
|
169 stateMenu->addAction(showGamesInProgress); |
|
170 btnState->setMenu(stateMenu); |
|
171 |
|
172 // Lobby chat |
165 // Lobby chat |
173 |
166 |
174 chatWidget = new HWChatWidget(this, false); |
167 chatWidget = new HWChatWidget(this, false); |
175 m_splitter->addWidget(chatWidget); |
168 m_splitter->addWidget(chatWidget); |
176 |
169 |
199 connect(searchText, SIGNAL(returnPressed()), this, SLOT(onJoinClick())); |
192 connect(searchText, SIGNAL(returnPressed()), this, SLOT(onJoinClick())); |
200 connect(roomsList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(onJoinClick())); |
193 connect(roomsList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(onJoinClick())); |
201 connect(roomsList, SIGNAL(clicked (const QModelIndex &)), searchText, SLOT(setFocus())); |
194 connect(roomsList, SIGNAL(clicked (const QModelIndex &)), searchText, SLOT(setFocus())); |
202 connect(showGamesInLobby, SIGNAL(triggered()), this, SLOT(onFilterChanged())); |
195 connect(showGamesInLobby, SIGNAL(triggered()), this, SLOT(onFilterChanged())); |
203 connect(showGamesInProgress, SIGNAL(triggered()), this, SLOT(onFilterChanged())); |
196 connect(showGamesInProgress, SIGNAL(triggered()), this, SLOT(onFilterChanged())); |
|
197 connect(showPassword, SIGNAL(triggered()), this, SLOT(onFilterChanged())); |
|
198 connect(showJoinRestricted, SIGNAL(triggered()), this, SLOT(onFilterChanged())); |
204 connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onFilterChanged())); |
199 connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onFilterChanged())); |
205 connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection); |
200 connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection); |
206 |
201 |
207 // Set focus on search box |
202 // Set focus on search box |
208 connect(this, SIGNAL(pageEnter()), searchText, SLOT(setFocus())); |
203 connect(this, SIGNAL(pageEnter()), searchText, SLOT(setFocus())); |
643 |
638 |
644 roomsModel->setFilterFixedString(searchText->text()); |
639 roomsModel->setFilterFixedString(searchText->text()); |
645 |
640 |
646 bool stateLobby = showGamesInLobby->isChecked(); |
641 bool stateLobby = showGamesInLobby->isChecked(); |
647 bool stateProgress = showGamesInProgress->isChecked(); |
642 bool stateProgress = showGamesInProgress->isChecked(); |
648 |
643 bool statePassword = showPassword->isChecked(); |
649 if (stateLobby && stateProgress) |
644 bool stateJoinRestricted = showJoinRestricted->isChecked(); |
650 stateFilteredModel->setFilterFixedString(QString()); // "any" |
645 |
651 else if (stateLobby != stateProgress) |
646 QString filter; |
652 stateFilteredModel->setFilterFixedString(QString(stateProgress)); |
647 if (!stateLobby && !stateProgress) |
|
648 filter = "O_o"; |
|
649 else if (stateLobby && stateProgress && statePassword && stateJoinRestricted) |
|
650 filter = ""; |
653 else |
651 else |
654 stateFilteredModel->setFilterFixedString(QString("none")); // Basically, none. |
652 { |
|
653 QString exclude = "[^"; |
|
654 if (!stateProgress) exclude += "g"; |
|
655 if (!statePassword) exclude += "p"; |
|
656 if (!stateJoinRestricted) exclude += "j"; |
|
657 exclude += "]*"; |
|
658 if (stateProgress && statePassword && stateJoinRestricted) exclude = ".*"; |
|
659 filter = "^" + exclude; |
|
660 if (!stateLobby) filter += "g" + exclude; |
|
661 filter += "$"; |
|
662 } |
|
663 //qDebug() << filter; |
|
664 |
|
665 stateFilteredModel->setFilterRegExp(filter); |
655 } |
666 } |
656 |
667 |
657 void PageRoomsList::setSettings(QSettings *settings) |
668 void PageRoomsList::setSettings(QSettings *settings) |
658 { |
669 { |
659 m_gameSettings = settings; |
670 m_gameSettings = settings; |