Merge remote-tracking branch 'upstream/master' into cmake_qt5
This commit is contained in:
commit
ea8c55b2c9
3 changed files with 84 additions and 13 deletions
|
@ -9,26 +9,53 @@
|
|||
#include <QVBoxLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QSettings>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_allGameTypes, QWidget *parent)
|
||||
: QDialog(parent),
|
||||
allGameTypes(_allGameTypes)
|
||||
{
|
||||
QSettings settings;
|
||||
settings.beginGroup("filter_games");
|
||||
|
||||
unavailableGamesVisibleCheckBox = new QCheckBox(tr("Show &unavailable games"));
|
||||
unavailableGamesVisibleCheckBox->setChecked(
|
||||
settings.value("unavailable_games_visible", false).toBool()
|
||||
);
|
||||
|
||||
passwordProtectedGamesVisibleCheckBox = new QCheckBox(tr("Show &password protected games"));
|
||||
passwordProtectedGamesVisibleCheckBox->setChecked(
|
||||
settings.value("password_protected_games_visible", false).toBool()
|
||||
);
|
||||
|
||||
QLabel *gameNameFilterLabel = new QLabel(tr("Game &description:"));
|
||||
gameNameFilterEdit = new QLineEdit;
|
||||
gameNameFilterEdit->setText(
|
||||
settings.value("game_name_filter", "").toString()
|
||||
);
|
||||
QLabel *gameNameFilterLabel = new QLabel(tr("Game &description:"));
|
||||
gameNameFilterLabel->setBuddy(gameNameFilterEdit);
|
||||
|
||||
QLabel *creatorNameFilterLabel = new QLabel(tr("&Creator name:"));
|
||||
creatorNameFilterEdit = new QLineEdit;
|
||||
creatorNameFilterEdit->setText(
|
||||
settings.value("creator_name_filter", "").toString()
|
||||
);
|
||||
QLabel *creatorNameFilterLabel = new QLabel(tr("&Creator name:"));
|
||||
creatorNameFilterLabel->setBuddy(creatorNameFilterEdit);
|
||||
|
||||
QVBoxLayout *gameTypeFilterLayout = new QVBoxLayout;
|
||||
QMapIterator<int, QString> gameTypesIterator(allGameTypes);
|
||||
while (gameTypesIterator.hasNext()) {
|
||||
gameTypesIterator.next();
|
||||
|
||||
QCheckBox *temp = new QCheckBox(gameTypesIterator.value());
|
||||
temp->setChecked(
|
||||
settings.value(
|
||||
"game_type/" + hashGameType(gameTypesIterator.value()),
|
||||
false
|
||||
).toBool()
|
||||
);
|
||||
|
||||
gameTypeFilterCheckBoxes.insert(gameTypesIterator.key(), temp);
|
||||
gameTypeFilterLayout->addWidget(temp);
|
||||
}
|
||||
|
@ -43,14 +70,18 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *
|
|||
maxPlayersFilterMinSpinBox = new QSpinBox;
|
||||
maxPlayersFilterMinSpinBox->setMinimum(1);
|
||||
maxPlayersFilterMinSpinBox->setMaximum(99);
|
||||
maxPlayersFilterMinSpinBox->setValue(1);
|
||||
maxPlayersFilterMinSpinBox->setValue(
|
||||
settings.value("min_players", 1).toInt()
|
||||
);
|
||||
maxPlayersFilterMinLabel->setBuddy(maxPlayersFilterMinSpinBox);
|
||||
|
||||
QLabel *maxPlayersFilterMaxLabel = new QLabel(tr("at &most:"));
|
||||
maxPlayersFilterMaxSpinBox = new QSpinBox;
|
||||
maxPlayersFilterMaxSpinBox->setMinimum(1);
|
||||
maxPlayersFilterMaxSpinBox->setMaximum(99);
|
||||
maxPlayersFilterMaxSpinBox->setValue(99);
|
||||
maxPlayersFilterMaxSpinBox->setValue(
|
||||
settings.value("max_players", 99).toInt()
|
||||
);
|
||||
maxPlayersFilterMaxLabel->setBuddy(maxPlayersFilterMaxSpinBox);
|
||||
|
||||
QGridLayout *maxPlayersFilterLayout = new QGridLayout;
|
||||
|
@ -83,7 +114,7 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *
|
|||
hbox->addLayout(rightColumn);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
|
@ -94,6 +125,42 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *
|
|||
setWindowTitle(tr("Filter games"));
|
||||
}
|
||||
|
||||
void DlgFilterGames::actOk() {
|
||||
QSettings settings;
|
||||
settings.beginGroup("filter_games");
|
||||
settings.setValue(
|
||||
"unavailable_games_visible",
|
||||
unavailableGamesVisibleCheckBox->isChecked()
|
||||
);
|
||||
settings.setValue(
|
||||
"password_protected_games_visible",
|
||||
passwordProtectedGamesVisibleCheckBox->isChecked()
|
||||
);
|
||||
settings.setValue("game_name_filter", gameNameFilterEdit->text());
|
||||
settings.setValue("creator_name_filter", creatorNameFilterEdit->text());
|
||||
|
||||
QMapIterator<int, QString> gameTypeIterator(allGameTypes);
|
||||
QMapIterator<int, QCheckBox *> checkboxIterator(gameTypeFilterCheckBoxes);
|
||||
while (gameTypeIterator.hasNext()) {
|
||||
gameTypeIterator.next();
|
||||
checkboxIterator.next();
|
||||
|
||||
settings.setValue(
|
||||
"game_type/" + hashGameType(gameTypeIterator.value()),
|
||||
checkboxIterator.value()->isChecked()
|
||||
);
|
||||
}
|
||||
|
||||
settings.setValue("min_players", maxPlayersFilterMinSpinBox->value());
|
||||
settings.setValue("max_players", maxPlayersFilterMaxSpinBox->value());
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
QString DlgFilterGames::hashGameType(const QString &gameType) const {
|
||||
return QCryptographicHash::hash(gameType.toUtf8(), QCryptographicHash::Md5).toHex();
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getUnavailableGamesVisible() const
|
||||
{
|
||||
return unavailableGamesVisibleCheckBox->isChecked();
|
||||
|
|
|
@ -19,6 +19,16 @@ private:
|
|||
QMap<int, QCheckBox *> gameTypeFilterCheckBoxes;
|
||||
QSpinBox *maxPlayersFilterMinSpinBox;
|
||||
QSpinBox *maxPlayersFilterMaxSpinBox;
|
||||
|
||||
const QMap<int, QString> &allGameTypes;
|
||||
|
||||
/*
|
||||
* The game type might contain special characters, so to use it in
|
||||
* QSettings we just hash it.
|
||||
*/
|
||||
QString hashGameType(const QString &gameType) const;
|
||||
private slots:
|
||||
void actOk();
|
||||
public:
|
||||
DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *parent = 0);
|
||||
|
||||
|
|
|
@ -84,12 +84,6 @@ void GameSelector::actSetFilter()
|
|||
if (room)
|
||||
gameTypeMap = gameListModel->getGameTypes().value(room->getRoomId());
|
||||
DlgFilterGames dlg(gameTypeMap, this);
|
||||
dlg.setUnavailableGamesVisible(gameListProxyModel->getUnavailableGamesVisible());
|
||||
dlg.setPasswordProtectedGamesVisible(gameListProxyModel->getPasswordProtectedGamesVisible());
|
||||
dlg.setGameNameFilter(gameListProxyModel->getGameNameFilter());
|
||||
dlg.setCreatorNameFilter(gameListProxyModel->getCreatorNameFilter());
|
||||
dlg.setGameTypeFilter(gameListProxyModel->getGameTypeFilter());
|
||||
dlg.setMaxPlayersFilter(gameListProxyModel->getMaxPlayersFilterMin(), gameListProxyModel->getMaxPlayersFilterMax());
|
||||
|
||||
if (!dlg.exec())
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue