mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 16:44:48 -07:00
Major Directory Refactoring (#5118)
* refactored cardzone.cpp, added doc and changed if to switch case * started moving every files into different folders * remove undercase to match with other files naming convention * refactored dialog files * ran format.sh * refactored client/tabs folder * refactored client/tabs folder * refactored client/tabs folder * refactored client folder * refactored carddbparser * refactored dialogs * Create sonar-project.properties temporary file for lint * Create build.yml temporary file for lint * removed all files from root directory * removed all files from root directory * added current branch to workflow * fixed most broken import * fixed issues while renaming files * fixed oracle importer * fixed dbconverter * updated translations * made sub-folders for client * removed linter * removed linter folder * fixed oracle import * revert card_zone documentation * renamed db parser files name and deck_view imports * fixed dlg file issue * ran format file and fixed test file * fixed carddb test files * moved player folder in game * updated translations and format files * fixed peglib import * format cmake files * removing vcpkg to try to add it back later * tried fixing vcpkg file * renamed filter to filters and moved database parser to cards folder * reverted translation files * reverted oracle translated * Update cockatrice/src/dialogs/dlg_register.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * Update cockatrice/src/client/ui/window_main.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * removed empty line at file start * removed useless include from tab_supervisor.cpp * refactored cardzone.cpp, added doc and changed if to switch case * started moving every files into different folders * remove undercase to match with other files naming convention * refactored dialog files * ran format.sh * refactored client/tabs folder * refactored client folder * refactored carddbparser * refactored dialogs * removed all files from root directory * Create sonar-project.properties temporary file for lint * Create build.yml temporary file for lint * added current branch to workflow * fixed most broken import * fixed issues while renaming files * fixed oracle importer * fixed dbconverter * updated translations * made sub-folders for client * removed linter * removed linter folder * fixed oracle import * revert card_zone documentation * renamed db parser files name and deck_view imports * fixed dlg file issue * ran format file and fixed test file * fixed carddb test files * moved player folder in game * updated translations and format files * fixed peglib import * reverted translation files * format cmake files * removing vcpkg to try to add it back later * tried fixing vcpkg file * pre-updating of cockatrice changes * removed empty line at file start * reverted oracle translated * Update cockatrice/src/dialogs/dlg_register.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * Update cockatrice/src/client/ui/window_main.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * removed useless include from tab_supervisor.cpp --------- Co-authored-by: tooomm <tooomm@users.noreply.github.com>
This commit is contained in:
parent
d1e0f9dfc5
commit
fa999880ee
261 changed files with 735 additions and 729 deletions
364
cockatrice/src/dialogs/dlg_connect.cpp
Normal file
364
cockatrice/src/dialogs/dlg_connect.cpp
Normal file
|
|
@ -0,0 +1,364 @@
|
|||
#include "dlg_connect.h"
|
||||
|
||||
#include "../server/user/user_info_connection.h"
|
||||
#include "../settings/cache_settings.h"
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QDebug>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QEvent>
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QKeyEvent>
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
|
||||
DlgConnect::DlgConnect(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
previousHostButton = new QRadioButton(tr("Known Hosts"), this);
|
||||
previousHosts = new QComboBox(this);
|
||||
previousHosts->installEventFilter(new DeleteHighlightedItemWhenShiftDelPressedEventFilter);
|
||||
|
||||
hps = new HandlePublicServers(this);
|
||||
btnRefreshServers = new QPushButton(this);
|
||||
btnRefreshServers->setIcon(QPixmap("theme:icons/sync"));
|
||||
btnRefreshServers->setToolTip(tr("Refresh the server list with known public servers"));
|
||||
btnRefreshServers->setFixedWidth(30);
|
||||
|
||||
connect(hps, SIGNAL(sigPublicServersDownloadedSuccessfully()), this, SLOT(rebuildComboBoxList()));
|
||||
connect(hps, SIGNAL(sigPublicServersDownloadedUnsuccessfully(int)), this, SLOT(rebuildComboBoxList(int)));
|
||||
connect(btnRefreshServers, SIGNAL(released()), this, SLOT(downloadThePublicServers()));
|
||||
|
||||
connect(this, SIGNAL(sigPublicServersDownloaded()), this, SLOT(rebuildComboBoxList()));
|
||||
preRebuildComboBoxList();
|
||||
|
||||
newHostButton = new QRadioButton(tr("New Host"), this);
|
||||
|
||||
saveLabel = new QLabel(tr("Name:"));
|
||||
saveEdit = new QLineEdit;
|
||||
saveEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
saveLabel->setBuddy(saveEdit);
|
||||
|
||||
hostLabel = new QLabel(tr("&Host:"));
|
||||
hostEdit = new QLineEdit;
|
||||
hostEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
hostLabel->setBuddy(hostEdit);
|
||||
|
||||
portLabel = new QLabel(tr("&Port:"));
|
||||
portEdit = new QLineEdit;
|
||||
portEdit->setValidator(new QIntValidator(0, 0xffff, portEdit));
|
||||
portLabel->setBuddy(portEdit);
|
||||
|
||||
playernameLabel = new QLabel(tr("Player &name:"));
|
||||
playernameEdit = new QLineEdit;
|
||||
playernameEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
playernameLabel->setBuddy(playernameEdit);
|
||||
|
||||
passwordLabel = new QLabel(tr("P&assword:"));
|
||||
passwordEdit = new QLineEdit;
|
||||
passwordEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
passwordLabel->setBuddy(passwordEdit);
|
||||
passwordEdit->setEchoMode(QLineEdit::Password);
|
||||
|
||||
savePasswordCheckBox = new QCheckBox(tr("&Save password"));
|
||||
|
||||
autoConnectCheckBox = new QCheckBox(tr("A&uto connect"));
|
||||
autoConnectCheckBox->setToolTip(tr("Automatically connect to the most recent login when Cockatrice opens"));
|
||||
|
||||
auto &servers = SettingsCache::instance().servers();
|
||||
if (servers.getSavePassword()) {
|
||||
autoConnectCheckBox->setChecked(servers.getAutoConnect() > 0);
|
||||
autoConnectCheckBox->setEnabled(true);
|
||||
} else {
|
||||
servers.setAutoConnect(0);
|
||||
autoConnectCheckBox->setChecked(false);
|
||||
autoConnectCheckBox->setEnabled(false);
|
||||
}
|
||||
|
||||
connect(savePasswordCheckBox, SIGNAL(stateChanged(int)), this, SLOT(passwordSaved(int)));
|
||||
|
||||
serverIssuesLabel =
|
||||
new QLabel(tr("If you have any trouble connecting or registering then contact the server staff for help!"));
|
||||
serverIssuesLabel->setWordWrap(true);
|
||||
serverContactLabel = new QLabel(tr("Webpage") + ":");
|
||||
serverContactLink = new QLabel;
|
||||
serverContactLink->setTextFormat(Qt::RichText);
|
||||
serverContactLink->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
serverContactLink->setOpenExternalLinks(true);
|
||||
|
||||
updateDisplayInfo(previousHosts->currentText());
|
||||
|
||||
btnForgotPassword = new QPushButton(this);
|
||||
btnForgotPassword->setIcon(QPixmap("theme:icons/forgot_password"));
|
||||
btnForgotPassword->setToolTip(tr("Reset Password"));
|
||||
btnForgotPassword->setFixedWidth(30);
|
||||
connect(btnForgotPassword, SIGNAL(released()), this, SLOT(actForgotPassword()));
|
||||
|
||||
btnConnect = new QPushButton(tr("&Connect"));
|
||||
connect(btnConnect, SIGNAL(released()), this, SLOT(actOk()));
|
||||
|
||||
auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel);
|
||||
buttonBox->addButton(btnConnect, QDialogButtonBox::AcceptRole);
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
newHolderLayout = new QHBoxLayout;
|
||||
newHolderLayout->addWidget(previousHosts);
|
||||
newHolderLayout->addWidget(btnRefreshServers);
|
||||
|
||||
connectionLayout = new QGridLayout;
|
||||
connectionLayout->addWidget(previousHostButton, 0, 1);
|
||||
connectionLayout->addLayout(newHolderLayout, 1, 1, 1, 2);
|
||||
connectionLayout->addWidget(newHostButton, 2, 1);
|
||||
connectionLayout->addWidget(saveLabel, 3, 0);
|
||||
connectionLayout->addWidget(saveEdit, 3, 1);
|
||||
connectionLayout->addWidget(hostLabel, 4, 0);
|
||||
connectionLayout->addWidget(hostEdit, 4, 1);
|
||||
connectionLayout->addWidget(portLabel, 5, 0);
|
||||
connectionLayout->addWidget(portEdit, 5, 1);
|
||||
connectionLayout->addWidget(autoConnectCheckBox, 6, 1);
|
||||
|
||||
restrictionsGroupBox = new QGroupBox(tr("Server"));
|
||||
restrictionsGroupBox->setLayout(connectionLayout);
|
||||
|
||||
serverInfoLayout = new QGridLayout;
|
||||
serverInfoLayout->addWidget(serverIssuesLabel, 0, 0, 1, 4, Qt::AlignTop);
|
||||
serverInfoLayout->addWidget(serverContactLabel, 1, 0);
|
||||
serverInfoLayout->addWidget(serverContactLink, 1, 1, 1, 3);
|
||||
|
||||
loginLayout = new QGridLayout;
|
||||
loginLayout->addWidget(playernameLabel, 0, 0);
|
||||
loginLayout->addWidget(playernameEdit, 0, 1, 1, 2);
|
||||
loginLayout->addWidget(passwordLabel, 1, 0);
|
||||
loginLayout->addWidget(passwordEdit, 1, 1);
|
||||
loginLayout->addWidget(btnForgotPassword, 1, 2);
|
||||
loginLayout->addWidget(savePasswordCheckBox, 2, 1);
|
||||
|
||||
loginGroupBox = new QGroupBox(tr("Login"));
|
||||
loginGroupBox->setLayout(loginLayout);
|
||||
|
||||
serverInfoGroupBox = new QGroupBox(tr("Server Contact"));
|
||||
serverInfoGroupBox->setLayout(serverInfoLayout);
|
||||
|
||||
grid = new QGridLayout;
|
||||
grid->addWidget(restrictionsGroupBox, 0, 0);
|
||||
grid->addWidget(serverInfoGroupBox, 1, 0);
|
||||
grid->addWidget(loginGroupBox, 2, 0);
|
||||
|
||||
mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(grid);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Connect to Server"));
|
||||
setFixedHeight(sizeHint().height());
|
||||
setMinimumWidth(300);
|
||||
|
||||
connect(previousHostButton, SIGNAL(toggled(bool)), this, SLOT(previousHostSelected(bool)));
|
||||
connect(newHostButton, SIGNAL(toggled(bool)), this, SLOT(newHostSelected(bool)));
|
||||
|
||||
previousHostButton->setChecked(true);
|
||||
|
||||
connect(previousHosts, SIGNAL(currentTextChanged(const QString &)), this, SLOT(updateDisplayInfo(const QString &)));
|
||||
|
||||
playernameEdit->setFocus();
|
||||
}
|
||||
|
||||
DlgConnect::~DlgConnect() = default;
|
||||
|
||||
void DlgConnect::downloadThePublicServers()
|
||||
{
|
||||
btnRefreshServers->setDisabled(true);
|
||||
previousHosts->clear();
|
||||
previousHosts->addItem(placeHolderText);
|
||||
hps->downloadPublicServers();
|
||||
}
|
||||
|
||||
void DlgConnect::preRebuildComboBoxList()
|
||||
{
|
||||
UserConnection_Information uci;
|
||||
savedHostList = uci.getServerInfo();
|
||||
|
||||
if (savedHostList.size() == 1) {
|
||||
downloadThePublicServers();
|
||||
} else {
|
||||
rebuildComboBoxList();
|
||||
}
|
||||
}
|
||||
|
||||
void DlgConnect::rebuildComboBoxList(int failure)
|
||||
{
|
||||
Q_UNUSED(failure);
|
||||
|
||||
previousHosts->clear();
|
||||
|
||||
UserConnection_Information uci;
|
||||
savedHostList = uci.getServerInfo();
|
||||
|
||||
auto &servers = SettingsCache::instance().servers();
|
||||
bool autoConnectEnabled = servers.getAutoConnect() > 0;
|
||||
QString previousHostName = servers.getPrevioushostName();
|
||||
QString autoConnectSaveName = servers.getSaveName();
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (const auto &pair : savedHostList) {
|
||||
const auto &tmp = pair.second;
|
||||
QString saveName = tmp.getSaveName();
|
||||
if (saveName.size()) {
|
||||
previousHosts->addItem(saveName);
|
||||
|
||||
if (autoConnectEnabled) {
|
||||
if (saveName.compare(autoConnectSaveName) == 0) {
|
||||
previousHosts->setCurrentIndex(index);
|
||||
}
|
||||
} else if (saveName.compare(previousHostName) == 0) {
|
||||
previousHosts->setCurrentIndex(index);
|
||||
}
|
||||
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
// Re-enable the refresh server button
|
||||
btnRefreshServers->setDisabled(false);
|
||||
}
|
||||
|
||||
void DlgConnect::previousHostSelected(bool state)
|
||||
{
|
||||
if (state) {
|
||||
saveEdit->setDisabled(true);
|
||||
hostEdit->setDisabled(true);
|
||||
portEdit->setDisabled(true);
|
||||
previousHosts->setDisabled(false);
|
||||
btnRefreshServers->setDisabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void DlgConnect::updateDisplayInfo(const QString &saveName)
|
||||
{
|
||||
if (saveEdit == nullptr || saveName == placeHolderText) {
|
||||
return;
|
||||
}
|
||||
|
||||
UserConnection_Information uci;
|
||||
QStringList _data = uci.getServerInfo(saveName);
|
||||
|
||||
bool savePasswordStatus = (_data.at(5) == "1");
|
||||
|
||||
saveEdit->setText(_data.at(0));
|
||||
hostEdit->setText(_data.at(1));
|
||||
portEdit->setText(_data.at(2));
|
||||
playernameEdit->setText(_data.at(3));
|
||||
savePasswordCheckBox->setChecked(savePasswordStatus);
|
||||
|
||||
if (savePasswordStatus) {
|
||||
passwordEdit->setText(_data.at(4));
|
||||
}
|
||||
|
||||
if (!_data.at(6).isEmpty()) {
|
||||
QString formattedLink = "<a href=\"" + _data.at(6) + "\">" + _data.at(6) + "</a>";
|
||||
serverContactLabel->setText(tr("Webpage") + ":");
|
||||
serverContactLink->setText(formattedLink);
|
||||
} else {
|
||||
serverContactLabel->setText("");
|
||||
serverContactLink->setText("");
|
||||
}
|
||||
}
|
||||
|
||||
void DlgConnect::newHostSelected(bool state)
|
||||
{
|
||||
if (state) {
|
||||
previousHosts->setDisabled(true);
|
||||
btnRefreshServers->setDisabled(true);
|
||||
hostEdit->clear();
|
||||
hostEdit->setPlaceholderText(tr("Server URL"));
|
||||
hostEdit->setDisabled(false);
|
||||
portEdit->clear();
|
||||
portEdit->setPlaceholderText(tr("Communication Port"));
|
||||
portEdit->setDisabled(false);
|
||||
playernameEdit->clear();
|
||||
passwordEdit->clear();
|
||||
saveEdit->clear();
|
||||
saveEdit->setPlaceholderText(tr("Unique Server Name"));
|
||||
saveEdit->setDisabled(false);
|
||||
serverContactLabel->setText("");
|
||||
serverContactLink->setText("");
|
||||
} else {
|
||||
preRebuildComboBoxList();
|
||||
}
|
||||
}
|
||||
|
||||
void DlgConnect::passwordSaved(int state)
|
||||
{
|
||||
Q_UNUSED(state);
|
||||
if (savePasswordCheckBox->isChecked()) {
|
||||
autoConnectCheckBox->setEnabled(true);
|
||||
} else {
|
||||
autoConnectCheckBox->setChecked(false);
|
||||
autoConnectCheckBox->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void DlgConnect::actOk()
|
||||
{
|
||||
ServersSettings &servers = SettingsCache::instance().servers();
|
||||
|
||||
if (newHostButton->isChecked()) {
|
||||
if (saveEdit->text().isEmpty()) {
|
||||
QMessageBox::critical(this, tr("Connection Warning"), tr("You need to name your new connection profile."));
|
||||
return;
|
||||
}
|
||||
|
||||
servers.addNewServer(saveEdit->text().trimmed(), hostEdit->text().trimmed(), portEdit->text().trimmed(),
|
||||
playernameEdit->text().trimmed(), passwordEdit->text(), savePasswordCheckBox->isChecked());
|
||||
} else {
|
||||
servers.updateExistingServer(saveEdit->text().trimmed(), hostEdit->text().trimmed(), portEdit->text().trimmed(),
|
||||
playernameEdit->text().trimmed(), passwordEdit->text(),
|
||||
savePasswordCheckBox->isChecked());
|
||||
}
|
||||
|
||||
servers.setPrevioushostName(saveEdit->text());
|
||||
servers.setAutoConnect(autoConnectCheckBox->isChecked());
|
||||
|
||||
if (playernameEdit->text().isEmpty()) {
|
||||
QMessageBox::critical(this, tr("Connect Warning"), tr("The player name can't be empty."));
|
||||
return;
|
||||
}
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
QString DlgConnect::getHost() const
|
||||
{
|
||||
return hostEdit->text().trimmed();
|
||||
}
|
||||
|
||||
bool DeleteHighlightedItemWhenShiftDelPressedEventFilter::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
auto *keyEvent = dynamic_cast<QKeyEvent *>(event);
|
||||
|
||||
if (keyEvent->key() == Qt::Key_Delete) {
|
||||
auto *combobox = reinterpret_cast<QComboBox *>(obj);
|
||||
combobox->removeItem(combobox->currentIndex());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void DlgConnect::actForgotPassword()
|
||||
{
|
||||
ServersSettings &servers = SettingsCache::instance().servers();
|
||||
servers.setFPHostName(hostEdit->text());
|
||||
servers.setFPPort(portEdit->text());
|
||||
servers.setFPPlayerName(playernameEdit->text().trimmed());
|
||||
|
||||
emit sigStartForgotPasswordRequest();
|
||||
reject();
|
||||
}
|
||||
81
cockatrice/src/dialogs/dlg_connect.h
Normal file
81
cockatrice/src/dialogs/dlg_connect.h
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#ifndef DLG_CONNECT_H
|
||||
#define DLG_CONNECT_H
|
||||
|
||||
#include "../server/handle_public_servers.h"
|
||||
#include "../server/user/user_info_connection.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
|
||||
class QCheckBox;
|
||||
class QComboBox;
|
||||
class QGridLayout;
|
||||
class QGroupBox;
|
||||
class QHBoxLayout;
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QRadioButton;
|
||||
class QVBoxLayout;
|
||||
|
||||
class DeleteHighlightedItemWhenShiftDelPressedEventFilter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
};
|
||||
|
||||
class DlgConnect : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void sigStartForgotPasswordRequest();
|
||||
void sigPublicServersDownloaded();
|
||||
|
||||
public:
|
||||
explicit DlgConnect(QWidget *parent = nullptr);
|
||||
~DlgConnect() override;
|
||||
QString getHost() const;
|
||||
int getPort() const
|
||||
{
|
||||
return portEdit->text().toInt();
|
||||
}
|
||||
QString getPlayerName() const
|
||||
{
|
||||
return playernameEdit->text();
|
||||
}
|
||||
QString getPassword() const
|
||||
{
|
||||
return passwordEdit->text();
|
||||
}
|
||||
|
||||
public slots:
|
||||
void downloadThePublicServers();
|
||||
|
||||
private slots:
|
||||
void actOk();
|
||||
|
||||
void passwordSaved(int state);
|
||||
void previousHostSelected(bool state);
|
||||
void newHostSelected(bool state);
|
||||
void actForgotPassword();
|
||||
void updateDisplayInfo(const QString &saveName);
|
||||
void preRebuildComboBoxList();
|
||||
void rebuildComboBoxList(int failure = -1);
|
||||
|
||||
private:
|
||||
QGridLayout *connectionLayout, *loginLayout, *serverInfoLayout, *grid;
|
||||
QHBoxLayout *newHolderLayout;
|
||||
QGroupBox *loginGroupBox, *serverInfoGroupBox, *restrictionsGroupBox;
|
||||
QVBoxLayout *mainLayout;
|
||||
QLabel *hostLabel, *portLabel, *playernameLabel, *passwordLabel, *saveLabel, *serverIssuesLabel,
|
||||
*serverContactLabel, *serverContactLink;
|
||||
QLineEdit *hostEdit, *portEdit, *playernameEdit, *passwordEdit, *saveEdit;
|
||||
QCheckBox *savePasswordCheckBox, *autoConnectCheckBox;
|
||||
QComboBox *previousHosts;
|
||||
QRadioButton *newHostButton, *previousHostButton;
|
||||
QPushButton *btnConnect, *btnForgotPassword, *btnRefreshServers;
|
||||
QMap<QString, std::pair<QString, UserConnection_Information>> savedHostList;
|
||||
HandlePublicServers *hps;
|
||||
const QString placeHolderText = tr("Downloading...");
|
||||
};
|
||||
#endif
|
||||
285
cockatrice/src/dialogs/dlg_create_game.cpp
Normal file
285
cockatrice/src/dialogs/dlg_create_game.cpp
Normal file
|
|
@ -0,0 +1,285 @@
|
|||
#include "dlg_create_game.h"
|
||||
|
||||
#include "../client/tabs/tab_room.h"
|
||||
#include "../server/pending_command.h"
|
||||
#include "../settings/cache_settings.h"
|
||||
#include "pb/serverinfo_game.pb.h"
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCheckBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
#include <QSet>
|
||||
#include <QSpinBox>
|
||||
#include <QWizard>
|
||||
|
||||
void DlgCreateGame::sharedCtor()
|
||||
{
|
||||
rememberGameSettings = new QCheckBox(tr("Re&member settings"));
|
||||
descriptionLabel = new QLabel(tr("&Description:"));
|
||||
descriptionEdit = new QLineEdit;
|
||||
descriptionEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
descriptionLabel->setBuddy(descriptionEdit);
|
||||
|
||||
maxPlayersLabel = new QLabel(tr("P&layers:"));
|
||||
maxPlayersEdit = new QSpinBox();
|
||||
maxPlayersEdit->setMinimum(1);
|
||||
maxPlayersEdit->setMaximum(100);
|
||||
maxPlayersEdit->setValue(2);
|
||||
maxPlayersLabel->setBuddy(maxPlayersEdit);
|
||||
|
||||
QGridLayout *generalGrid = new QGridLayout;
|
||||
generalGrid->addWidget(descriptionLabel, 0, 0);
|
||||
generalGrid->addWidget(descriptionEdit, 0, 1);
|
||||
generalGrid->addWidget(maxPlayersLabel, 1, 0);
|
||||
generalGrid->addWidget(maxPlayersEdit, 1, 1);
|
||||
generalGroupBox = new QGroupBox(tr("General"));
|
||||
generalGroupBox->setLayout(generalGrid);
|
||||
|
||||
QVBoxLayout *gameTypeLayout = new QVBoxLayout;
|
||||
QMapIterator<int, QString> gameTypeIterator(gameTypes);
|
||||
while (gameTypeIterator.hasNext()) {
|
||||
gameTypeIterator.next();
|
||||
QRadioButton *gameTypeRadioButton = new QRadioButton(gameTypeIterator.value(), this);
|
||||
gameTypeLayout->addWidget(gameTypeRadioButton);
|
||||
gameTypeCheckBoxes.insert(gameTypeIterator.key(), gameTypeRadioButton);
|
||||
bool isChecked = SettingsCache::instance().getGameTypes().contains(gameTypeIterator.value() + ", ");
|
||||
gameTypeCheckBoxes[gameTypeIterator.key()]->setChecked(isChecked);
|
||||
}
|
||||
QGroupBox *gameTypeGroupBox = new QGroupBox(tr("Game type"));
|
||||
gameTypeGroupBox->setLayout(gameTypeLayout);
|
||||
|
||||
passwordLabel = new QLabel(tr("&Password:"));
|
||||
passwordEdit = new QLineEdit;
|
||||
passwordEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
passwordLabel->setBuddy(passwordEdit);
|
||||
|
||||
onlyBuddiesCheckBox = new QCheckBox(tr("Only &buddies can join"));
|
||||
onlyRegisteredCheckBox = new QCheckBox(tr("Only ®istered users can join"));
|
||||
if (room && room->getUserInfo()->user_level() & ServerInfo_User::IsRegistered) {
|
||||
onlyRegisteredCheckBox->setChecked(true);
|
||||
} else {
|
||||
onlyBuddiesCheckBox->setEnabled(false);
|
||||
onlyRegisteredCheckBox->setEnabled(false);
|
||||
}
|
||||
|
||||
QGridLayout *joinRestrictionsLayout = new QGridLayout;
|
||||
joinRestrictionsLayout->addWidget(passwordLabel, 0, 0);
|
||||
joinRestrictionsLayout->addWidget(passwordEdit, 0, 1);
|
||||
joinRestrictionsLayout->addWidget(onlyBuddiesCheckBox, 1, 0, 1, 2);
|
||||
joinRestrictionsLayout->addWidget(onlyRegisteredCheckBox, 2, 0, 1, 2);
|
||||
|
||||
QGroupBox *joinRestrictionsGroupBox = new QGroupBox(tr("Joining restrictions"));
|
||||
joinRestrictionsGroupBox->setLayout(joinRestrictionsLayout);
|
||||
|
||||
spectatorsAllowedCheckBox = new QCheckBox(tr("&Spectators can watch"));
|
||||
spectatorsAllowedCheckBox->setChecked(true);
|
||||
connect(spectatorsAllowedCheckBox, SIGNAL(stateChanged(int)), this, SLOT(spectatorsAllowedChanged(int)));
|
||||
spectatorsNeedPasswordCheckBox = new QCheckBox(tr("Spectators &need a password to watch"));
|
||||
spectatorsCanTalkCheckBox = new QCheckBox(tr("Spectators can &chat"));
|
||||
spectatorsSeeEverythingCheckBox = new QCheckBox(tr("Spectators can see &hands"));
|
||||
createGameAsSpectatorCheckBox = new QCheckBox(tr("Create game as spectator"));
|
||||
QVBoxLayout *spectatorsLayout = new QVBoxLayout;
|
||||
spectatorsLayout->addWidget(spectatorsAllowedCheckBox);
|
||||
spectatorsLayout->addWidget(spectatorsNeedPasswordCheckBox);
|
||||
spectatorsLayout->addWidget(spectatorsCanTalkCheckBox);
|
||||
spectatorsLayout->addWidget(spectatorsSeeEverythingCheckBox);
|
||||
spectatorsLayout->addWidget(createGameAsSpectatorCheckBox);
|
||||
spectatorsGroupBox = new QGroupBox(tr("Spectators"));
|
||||
spectatorsGroupBox->setLayout(spectatorsLayout);
|
||||
|
||||
QGridLayout *grid = new QGridLayout;
|
||||
grid->addWidget(generalGroupBox, 0, 0);
|
||||
grid->addWidget(joinRestrictionsGroupBox, 0, 1);
|
||||
grid->addWidget(gameTypeGroupBox, 1, 0);
|
||||
grid->addWidget(spectatorsGroupBox, 1, 1, Qt::AlignTop);
|
||||
grid->addWidget(rememberGameSettings, 2, 0);
|
||||
|
||||
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(grid);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
|
||||
setLayout(mainLayout);
|
||||
|
||||
setFixedHeight(sizeHint().height());
|
||||
}
|
||||
|
||||
DlgCreateGame::DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameTypes, QWidget *parent)
|
||||
: QDialog(parent), room(_room), gameTypes(_gameTypes)
|
||||
{
|
||||
sharedCtor();
|
||||
|
||||
rememberGameSettings->setChecked(SettingsCache::instance().getRememberGameSettings());
|
||||
descriptionEdit->setText(SettingsCache::instance().getGameDescription());
|
||||
maxPlayersEdit->setValue(SettingsCache::instance().getMaxPlayers());
|
||||
if (room && room->getUserInfo()->user_level() & ServerInfo_User::IsRegistered) {
|
||||
onlyBuddiesCheckBox->setChecked(SettingsCache::instance().getOnlyBuddies());
|
||||
onlyRegisteredCheckBox->setChecked(SettingsCache::instance().getOnlyRegistered());
|
||||
} else {
|
||||
onlyBuddiesCheckBox->setEnabled(false);
|
||||
onlyRegisteredCheckBox->setEnabled(false);
|
||||
}
|
||||
spectatorsAllowedCheckBox->setChecked(SettingsCache::instance().getSpectatorsAllowed());
|
||||
spectatorsNeedPasswordCheckBox->setChecked(SettingsCache::instance().getSpectatorsNeedPassword());
|
||||
spectatorsCanTalkCheckBox->setChecked(SettingsCache::instance().getSpectatorsCanTalk());
|
||||
spectatorsSeeEverythingCheckBox->setChecked(SettingsCache::instance().getSpectatorsCanSeeEverything());
|
||||
createGameAsSpectatorCheckBox->setChecked(SettingsCache::instance().getCreateGameAsSpectator());
|
||||
|
||||
if (!rememberGameSettings->isChecked()) {
|
||||
actReset();
|
||||
}
|
||||
|
||||
descriptionEdit->setFocus();
|
||||
clearButton = new QPushButton(tr("&Clear"));
|
||||
buttonBox->addButton(QDialogButtonBox::Cancel);
|
||||
buttonBox->addButton(clearButton, QDialogButtonBox::ActionRole);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOK()));
|
||||
connect(clearButton, SIGNAL(clicked()), this, SLOT(actReset()));
|
||||
|
||||
setWindowTitle(tr("Create game"));
|
||||
}
|
||||
|
||||
DlgCreateGame::DlgCreateGame(const ServerInfo_Game &gameInfo, const QMap<int, QString> &_gameTypes, QWidget *parent)
|
||||
: QDialog(parent), room(0), gameTypes(_gameTypes)
|
||||
{
|
||||
sharedCtor();
|
||||
|
||||
rememberGameSettings->setEnabled(false);
|
||||
descriptionEdit->setEnabled(false);
|
||||
maxPlayersEdit->setEnabled(false);
|
||||
passwordEdit->setEnabled(false);
|
||||
onlyBuddiesCheckBox->setEnabled(false);
|
||||
onlyRegisteredCheckBox->setEnabled(false);
|
||||
spectatorsAllowedCheckBox->setEnabled(false);
|
||||
spectatorsNeedPasswordCheckBox->setEnabled(false);
|
||||
spectatorsCanTalkCheckBox->setEnabled(false);
|
||||
spectatorsSeeEverythingCheckBox->setEnabled(false);
|
||||
createGameAsSpectatorCheckBox->setEnabled(false);
|
||||
|
||||
descriptionEdit->setText(QString::fromStdString(gameInfo.description()));
|
||||
maxPlayersEdit->setValue(gameInfo.max_players());
|
||||
onlyBuddiesCheckBox->setChecked(gameInfo.only_buddies());
|
||||
onlyRegisteredCheckBox->setChecked(gameInfo.only_registered());
|
||||
spectatorsAllowedCheckBox->setChecked(gameInfo.spectators_allowed());
|
||||
spectatorsNeedPasswordCheckBox->setChecked(gameInfo.spectators_need_password());
|
||||
spectatorsCanTalkCheckBox->setChecked(gameInfo.spectators_can_chat());
|
||||
spectatorsSeeEverythingCheckBox->setChecked(gameInfo.spectators_omniscient());
|
||||
|
||||
QSet<int> types;
|
||||
for (int i = 0; i < gameInfo.game_types_size(); ++i)
|
||||
types.insert(gameInfo.game_types(i));
|
||||
|
||||
QMapIterator<int, QString> gameTypeIterator(gameTypes);
|
||||
while (gameTypeIterator.hasNext()) {
|
||||
gameTypeIterator.next();
|
||||
|
||||
QRadioButton *gameTypeCheckBox = gameTypeCheckBoxes.value(gameTypeIterator.key());
|
||||
gameTypeCheckBox->setEnabled(false);
|
||||
gameTypeCheckBox->setChecked(types.contains(gameTypeIterator.key()));
|
||||
}
|
||||
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
|
||||
setWindowTitle(tr("Game information"));
|
||||
}
|
||||
|
||||
void DlgCreateGame::actReset()
|
||||
{
|
||||
descriptionEdit->setText("");
|
||||
maxPlayersEdit->setValue(2);
|
||||
|
||||
passwordEdit->setText("");
|
||||
onlyBuddiesCheckBox->setChecked(false);
|
||||
onlyRegisteredCheckBox->setChecked(room && room->getUserInfo()->user_level() & ServerInfo_User::IsRegistered);
|
||||
|
||||
spectatorsAllowedCheckBox->setChecked(true);
|
||||
spectatorsNeedPasswordCheckBox->setChecked(false);
|
||||
spectatorsCanTalkCheckBox->setChecked(false);
|
||||
spectatorsSeeEverythingCheckBox->setChecked(false);
|
||||
createGameAsSpectatorCheckBox->setChecked(false);
|
||||
|
||||
QMapIterator<int, QRadioButton *> gameTypeCheckBoxIterator(gameTypeCheckBoxes);
|
||||
while (gameTypeCheckBoxIterator.hasNext()) {
|
||||
gameTypeCheckBoxIterator.next();
|
||||
// must set auto enclusive to false to be able to set the check to false
|
||||
gameTypeCheckBoxIterator.value()->setAutoExclusive(false);
|
||||
gameTypeCheckBoxIterator.value()->setChecked(false);
|
||||
gameTypeCheckBoxIterator.value()->setAutoExclusive(true);
|
||||
}
|
||||
|
||||
descriptionEdit->setFocus();
|
||||
}
|
||||
|
||||
void DlgCreateGame::actOK()
|
||||
{
|
||||
Command_CreateGame cmd;
|
||||
cmd.set_description(descriptionEdit->text().simplified().toStdString());
|
||||
cmd.set_password(passwordEdit->text().toStdString());
|
||||
cmd.set_max_players(maxPlayersEdit->value());
|
||||
cmd.set_only_buddies(onlyBuddiesCheckBox->isChecked());
|
||||
cmd.set_only_registered(onlyRegisteredCheckBox->isChecked());
|
||||
cmd.set_spectators_allowed(spectatorsAllowedCheckBox->isChecked());
|
||||
cmd.set_spectators_need_password(spectatorsNeedPasswordCheckBox->isChecked());
|
||||
cmd.set_spectators_can_talk(spectatorsCanTalkCheckBox->isChecked());
|
||||
cmd.set_spectators_see_everything(spectatorsSeeEverythingCheckBox->isChecked());
|
||||
cmd.set_join_as_judge(QApplication::keyboardModifiers() & Qt::ShiftModifier);
|
||||
cmd.set_join_as_spectator(createGameAsSpectatorCheckBox->isChecked());
|
||||
|
||||
QString _gameTypes = QString();
|
||||
QMapIterator<int, QRadioButton *> gameTypeCheckBoxIterator(gameTypeCheckBoxes);
|
||||
while (gameTypeCheckBoxIterator.hasNext()) {
|
||||
gameTypeCheckBoxIterator.next();
|
||||
if (gameTypeCheckBoxIterator.value()->isChecked()) {
|
||||
cmd.add_game_type_ids(gameTypeCheckBoxIterator.key());
|
||||
_gameTypes += gameTypeCheckBoxIterator.value()->text() + ", ";
|
||||
}
|
||||
}
|
||||
|
||||
SettingsCache::instance().setRememberGameSettings(rememberGameSettings->isChecked());
|
||||
if (rememberGameSettings->isChecked()) {
|
||||
SettingsCache::instance().setGameDescription(descriptionEdit->text());
|
||||
SettingsCache::instance().setMaxPlayers(maxPlayersEdit->value());
|
||||
SettingsCache::instance().setOnlyBuddies(onlyBuddiesCheckBox->isChecked());
|
||||
SettingsCache::instance().setOnlyRegistered(onlyRegisteredCheckBox->isChecked());
|
||||
SettingsCache::instance().setSpectatorsAllowed(spectatorsAllowedCheckBox->isChecked());
|
||||
SettingsCache::instance().setSpectatorsNeedPassword(spectatorsNeedPasswordCheckBox->isChecked());
|
||||
SettingsCache::instance().setSpectatorsCanTalk(spectatorsCanTalkCheckBox->isChecked());
|
||||
SettingsCache::instance().setSpectatorsCanSeeEverything(spectatorsSeeEverythingCheckBox->isChecked());
|
||||
SettingsCache::instance().setCreateGameAsSpectator(createGameAsSpectatorCheckBox->isChecked());
|
||||
SettingsCache::instance().setGameTypes(_gameTypes);
|
||||
}
|
||||
PendingCommand *pend = room->prepareRoomCommand(cmd);
|
||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(checkResponse(Response)));
|
||||
room->sendRoomCommand(pend);
|
||||
|
||||
buttonBox->setEnabled(false);
|
||||
}
|
||||
|
||||
void DlgCreateGame::checkResponse(const Response &response)
|
||||
{
|
||||
buttonBox->setEnabled(true);
|
||||
|
||||
if (response.response_code() == Response::RespOk)
|
||||
accept();
|
||||
else {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Server error."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void DlgCreateGame::spectatorsAllowedChanged(int state)
|
||||
{
|
||||
spectatorsNeedPasswordCheckBox->setEnabled(state);
|
||||
spectatorsCanTalkCheckBox->setEnabled(state);
|
||||
spectatorsSeeEverythingCheckBox->setEnabled(state);
|
||||
}
|
||||
50
cockatrice/src/dialogs/dlg_create_game.h
Normal file
50
cockatrice/src/dialogs/dlg_create_game.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#ifndef DLG_CREATEGAME_H
|
||||
#define DLG_CREATEGAME_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QMap>
|
||||
|
||||
class QCheckBox;
|
||||
class QDialogButtonBox;
|
||||
class QGroupBox;
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class QPushButton;
|
||||
class QRadioButton;
|
||||
class QSpinBox;
|
||||
class Response;
|
||||
class ServerInfo_Game;
|
||||
class TabRoom;
|
||||
|
||||
class DlgCreateGame : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameTypes, QWidget *parent = nullptr);
|
||||
DlgCreateGame(const ServerInfo_Game &game, const QMap<int, QString> &_gameTypes, QWidget *parent = nullptr);
|
||||
private slots:
|
||||
void actOK();
|
||||
void actReset();
|
||||
void checkResponse(const Response &response);
|
||||
void spectatorsAllowedChanged(int state);
|
||||
|
||||
private:
|
||||
TabRoom *room;
|
||||
QMap<int, QString> gameTypes;
|
||||
QMap<int, QRadioButton *> gameTypeCheckBoxes;
|
||||
|
||||
QGroupBox *generalGroupBox, *spectatorsGroupBox;
|
||||
QLabel *descriptionLabel, *passwordLabel, *maxPlayersLabel;
|
||||
QLineEdit *descriptionEdit, *passwordEdit;
|
||||
QSpinBox *maxPlayersEdit;
|
||||
QCheckBox *onlyBuddiesCheckBox, *onlyRegisteredCheckBox;
|
||||
QCheckBox *spectatorsAllowedCheckBox, *spectatorsNeedPasswordCheckBox, *spectatorsCanTalkCheckBox,
|
||||
*spectatorsSeeEverythingCheckBox, *createGameAsSpectatorCheckBox;
|
||||
QDialogButtonBox *buttonBox;
|
||||
QPushButton *clearButton;
|
||||
QCheckBox *rememberGameSettings;
|
||||
|
||||
void sharedCtor();
|
||||
};
|
||||
|
||||
#endif
|
||||
245
cockatrice/src/dialogs/dlg_create_token.cpp
Normal file
245
cockatrice/src/dialogs/dlg_create_token.cpp
Normal file
|
|
@ -0,0 +1,245 @@
|
|||
#include "dlg_create_token.h"
|
||||
|
||||
#include "../game/cards/card_database_model.h"
|
||||
#include "../game/cards/card_info_picture.h"
|
||||
#include "../main.h"
|
||||
#include "../settings/cache_settings.h"
|
||||
#include "decklist.h"
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QCloseEvent>
|
||||
#include <QComboBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QRadioButton>
|
||||
#include <QTreeView>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *parent)
|
||||
: QDialog(parent), predefinedTokens(_predefinedTokens)
|
||||
{
|
||||
pic = new CardInfoPicture();
|
||||
pic->setObjectName("pic");
|
||||
|
||||
nameLabel = new QLabel(tr("&Name:"));
|
||||
nameEdit = new QLineEdit(tr("Token"));
|
||||
nameEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
nameEdit->selectAll();
|
||||
connect(nameEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateSearch(const QString &)));
|
||||
nameLabel->setBuddy(nameEdit);
|
||||
|
||||
colorLabel = new QLabel(tr("C&olor:"));
|
||||
colorEdit = new QComboBox;
|
||||
colorEdit->addItem(tr("white"), QChar('w'));
|
||||
colorEdit->addItem(tr("blue"), QChar('u'));
|
||||
colorEdit->addItem(tr("black"), QChar('b'));
|
||||
colorEdit->addItem(tr("red"), QChar('r'));
|
||||
colorEdit->addItem(tr("green"), QChar('g'));
|
||||
colorEdit->addItem(tr("multicolor"), QChar('m'));
|
||||
colorEdit->addItem(tr("colorless"), QChar());
|
||||
colorLabel->setBuddy(colorEdit);
|
||||
|
||||
ptLabel = new QLabel(tr("&P/T:"));
|
||||
ptEdit = new QLineEdit;
|
||||
ptEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
ptLabel->setBuddy(ptEdit);
|
||||
|
||||
annotationLabel = new QLabel(tr("&Annotation:"));
|
||||
annotationEdit = new QLineEdit;
|
||||
annotationEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
annotationLabel->setBuddy(annotationEdit);
|
||||
|
||||
destroyCheckBox = new QCheckBox(tr("&Destroy token when it leaves the table"));
|
||||
destroyCheckBox->setChecked(true);
|
||||
|
||||
QGridLayout *grid = new QGridLayout;
|
||||
grid->addWidget(nameLabel, 0, 0);
|
||||
grid->addWidget(nameEdit, 0, 1);
|
||||
grid->addWidget(colorLabel, 1, 0);
|
||||
grid->addWidget(colorEdit, 1, 1);
|
||||
grid->addWidget(ptLabel, 2, 0);
|
||||
grid->addWidget(ptEdit, 2, 1);
|
||||
grid->addWidget(annotationLabel, 3, 0);
|
||||
grid->addWidget(annotationEdit, 3, 1);
|
||||
grid->addWidget(destroyCheckBox, 4, 0, 1, 2);
|
||||
|
||||
QGroupBox *tokenDataGroupBox = new QGroupBox(tr("Token data"));
|
||||
tokenDataGroupBox->setLayout(grid);
|
||||
|
||||
cardDatabaseModel = new CardDatabaseModel(db, false, this);
|
||||
cardDatabaseDisplayModel = new TokenDisplayModel(this);
|
||||
cardDatabaseDisplayModel->setSourceModel(cardDatabaseModel);
|
||||
|
||||
chooseTokenFromAllRadioButton = new QRadioButton(tr("Show &all tokens"));
|
||||
connect(chooseTokenFromAllRadioButton, SIGNAL(toggled(bool)), this, SLOT(actChooseTokenFromAll(bool)));
|
||||
chooseTokenFromDeckRadioButton = new QRadioButton(tr("Show tokens from this &deck"));
|
||||
connect(chooseTokenFromDeckRadioButton, SIGNAL(toggled(bool)), this, SLOT(actChooseTokenFromDeck(bool)));
|
||||
|
||||
QByteArray deckHeaderState = SettingsCache::instance().layouts().getDeckEditorDbHeaderState();
|
||||
chooseTokenView = new QTreeView;
|
||||
chooseTokenView->setModel(cardDatabaseDisplayModel);
|
||||
chooseTokenView->setUniformRowHeights(true);
|
||||
chooseTokenView->setRootIsDecorated(false);
|
||||
chooseTokenView->setAlternatingRowColors(true);
|
||||
chooseTokenView->setSortingEnabled(true);
|
||||
chooseTokenView->sortByColumn(0, Qt::AscendingOrder);
|
||||
chooseTokenView->resizeColumnToContents(0);
|
||||
chooseTokenView->setWordWrap(true);
|
||||
|
||||
if (!deckHeaderState.isNull())
|
||||
chooseTokenView->header()->restoreState(deckHeaderState);
|
||||
|
||||
chooseTokenView->header()->setStretchLastSection(false);
|
||||
chooseTokenView->header()->hideSection(1); // Sets
|
||||
chooseTokenView->header()->hideSection(2); // Mana Cost
|
||||
chooseTokenView->header()->setSectionResizeMode(5, QHeaderView::ResizeToContents); // Color(s)
|
||||
connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this,
|
||||
SLOT(tokenSelectionChanged(QModelIndex, QModelIndex)));
|
||||
connect(chooseTokenView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(actOk()));
|
||||
|
||||
if (predefinedTokens.isEmpty()) {
|
||||
chooseTokenFromAllRadioButton->setChecked(true);
|
||||
chooseTokenFromDeckRadioButton->setDisabled(true); // No tokens in deck = no need for option
|
||||
} else {
|
||||
chooseTokenFromDeckRadioButton->setChecked(true);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>(predefinedTokens.begin(), predefinedTokens.end()));
|
||||
#else
|
||||
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>::fromList(predefinedTokens));
|
||||
#endif
|
||||
}
|
||||
|
||||
QVBoxLayout *tokenChooseLayout = new QVBoxLayout;
|
||||
tokenChooseLayout->addWidget(chooseTokenFromAllRadioButton);
|
||||
tokenChooseLayout->addWidget(chooseTokenFromDeckRadioButton);
|
||||
tokenChooseLayout->addWidget(chooseTokenView);
|
||||
|
||||
QGroupBox *tokenChooseGroupBox = new QGroupBox(tr("Choose token from list"));
|
||||
tokenChooseGroupBox->setLayout(tokenChooseLayout);
|
||||
|
||||
QGridLayout *hbox = new QGridLayout;
|
||||
hbox->addWidget(pic, 0, 0, 1, 1);
|
||||
hbox->addWidget(tokenDataGroupBox, 1, 0, 1, 1);
|
||||
hbox->addWidget(tokenChooseGroupBox, 0, 1, 2, 1);
|
||||
hbox->setColumnStretch(1, 1);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(actReject()));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(hbox);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Create token"));
|
||||
|
||||
resize(600, 500);
|
||||
restoreGeometry(SettingsCache::instance().getTokenDialogGeometry());
|
||||
}
|
||||
|
||||
void DlgCreateToken::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
SettingsCache::instance().setTokenDialogGeometry(saveGeometry());
|
||||
}
|
||||
|
||||
void DlgCreateToken::tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex & /*previous*/)
|
||||
{
|
||||
const QModelIndex realIndex = cardDatabaseDisplayModel->mapToSource(current);
|
||||
|
||||
CardInfoPtr cardInfo;
|
||||
|
||||
if (current.row() >= 0) {
|
||||
cardInfo = cardDatabaseModel->getCard(realIndex.row());
|
||||
}
|
||||
|
||||
if (cardInfo) {
|
||||
updateSearchFieldWithoutUpdatingFilter(cardInfo->getName());
|
||||
const QChar cardColor = cardInfo->getColorChar();
|
||||
colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString));
|
||||
ptEdit->setText(cardInfo->getPowTough());
|
||||
if (SettingsCache::instance().getAnnotateTokens())
|
||||
annotationEdit->setText(cardInfo->getText());
|
||||
} else {
|
||||
nameEdit->setText("");
|
||||
colorEdit->setCurrentIndex(colorEdit->findData(QString(), Qt::UserRole, Qt::MatchFixedString));
|
||||
ptEdit->setText("");
|
||||
annotationEdit->setText("");
|
||||
}
|
||||
|
||||
pic->setCard(cardInfo);
|
||||
}
|
||||
|
||||
void DlgCreateToken::updateSearchFieldWithoutUpdatingFilter(const QString &newValue) const
|
||||
{
|
||||
nameEdit->blockSignals(true);
|
||||
nameEdit->setText(newValue);
|
||||
nameEdit->blockSignals(false);
|
||||
}
|
||||
|
||||
void DlgCreateToken::updateSearch(const QString &search)
|
||||
{
|
||||
cardDatabaseDisplayModel->setCardName(search);
|
||||
}
|
||||
|
||||
void DlgCreateToken::actChooseTokenFromAll(bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>());
|
||||
}
|
||||
}
|
||||
|
||||
void DlgCreateToken::actChooseTokenFromDeck(bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>(predefinedTokens.begin(), predefinedTokens.end()));
|
||||
#else
|
||||
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>::fromList(predefinedTokens));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void DlgCreateToken::actOk()
|
||||
{
|
||||
SettingsCache::instance().setTokenDialogGeometry(saveGeometry());
|
||||
accept();
|
||||
}
|
||||
|
||||
void DlgCreateToken::actReject()
|
||||
{
|
||||
SettingsCache::instance().setTokenDialogGeometry(saveGeometry());
|
||||
reject();
|
||||
}
|
||||
|
||||
QString DlgCreateToken::getName() const
|
||||
{
|
||||
return nameEdit->text();
|
||||
}
|
||||
|
||||
QString DlgCreateToken::getColor() const
|
||||
{
|
||||
return QString(colorEdit->itemData(colorEdit->currentIndex()).toChar());
|
||||
}
|
||||
|
||||
QString DlgCreateToken::getPT() const
|
||||
{
|
||||
return ptEdit->text();
|
||||
}
|
||||
|
||||
QString DlgCreateToken::getAnnotation() const
|
||||
{
|
||||
return annotationEdit->text();
|
||||
}
|
||||
|
||||
bool DlgCreateToken::getDestroy() const
|
||||
{
|
||||
return destroyCheckBox->isChecked();
|
||||
}
|
||||
56
cockatrice/src/dialogs/dlg_create_token.h
Normal file
56
cockatrice/src/dialogs/dlg_create_token.h
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#ifndef DLG_CREATETOKEN_H
|
||||
#define DLG_CREATETOKEN_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QModelIndex>
|
||||
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class QComboBox;
|
||||
class QCheckBox;
|
||||
class QPushButton;
|
||||
class QRadioButton;
|
||||
class QCloseEvent;
|
||||
class QTreeView;
|
||||
class DeckList;
|
||||
class CardDatabaseModel;
|
||||
class TokenDisplayModel;
|
||||
class CardInfoPicture;
|
||||
|
||||
class DlgCreateToken : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DlgCreateToken(const QStringList &_predefinedTokens, QWidget *parent = nullptr);
|
||||
QString getName() const;
|
||||
QString getColor() const;
|
||||
QString getPT() const;
|
||||
QString getAnnotation() const;
|
||||
bool getDestroy() const;
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
private slots:
|
||||
void tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
void updateSearch(const QString &search);
|
||||
void actChooseTokenFromAll(bool checked);
|
||||
void actChooseTokenFromDeck(bool checked);
|
||||
void actOk();
|
||||
void actReject();
|
||||
|
||||
private:
|
||||
CardDatabaseModel *cardDatabaseModel;
|
||||
TokenDisplayModel *cardDatabaseDisplayModel;
|
||||
QStringList predefinedTokens;
|
||||
QLabel *nameLabel, *colorLabel, *ptLabel, *annotationLabel;
|
||||
QComboBox *colorEdit;
|
||||
QLineEdit *nameEdit, *ptEdit, *annotationEdit;
|
||||
QCheckBox *destroyCheckBox;
|
||||
QRadioButton *chooseTokenFromAllRadioButton, *chooseTokenFromDeckRadioButton;
|
||||
CardInfoPicture *pic;
|
||||
QTreeView *chooseTokenView;
|
||||
|
||||
void updateSearchFieldWithoutUpdatingFilter(const QString &newValue) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
88
cockatrice/src/dialogs/dlg_edit_avatar.cpp
Normal file
88
cockatrice/src/dialogs/dlg_edit_avatar.cpp
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
#include "dlg_edit_avatar.h"
|
||||
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QDebug>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QImageReader>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
DlgEditAvatar::DlgEditAvatar(QWidget *parent) : QDialog(parent), image()
|
||||
{
|
||||
imageLabel = new QLabel(tr("No image chosen."));
|
||||
imageLabel->setFixedSize(400, 200);
|
||||
imageLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
imageLabel->setStyleSheet("border: 1px solid #000");
|
||||
|
||||
textLabel = new QLabel(tr("To change your avatar, choose a new image.\nTo remove your current avatar, confirm "
|
||||
"without choosing a new image."));
|
||||
browseButton = new QPushButton(tr("Browse..."));
|
||||
connect(browseButton, SIGNAL(clicked()), this, SLOT(actBrowse()));
|
||||
|
||||
QGridLayout *grid = new QGridLayout;
|
||||
grid->addWidget(imageLabel, 0, 0, 1, 2);
|
||||
grid->addWidget(textLabel, 1, 0);
|
||||
grid->addWidget(browseButton, 1, 1);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(grid);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Change avatar"));
|
||||
setFixedHeight(sizeHint().height());
|
||||
setMinimumWidth(300);
|
||||
}
|
||||
|
||||
void DlgEditAvatar::actOk()
|
||||
{
|
||||
accept();
|
||||
}
|
||||
|
||||
void DlgEditAvatar::actBrowse()
|
||||
{
|
||||
QString fileName =
|
||||
QFileDialog::getOpenFileName(this, tr("Open Image"), QDir::homePath(), tr("Image Files (*.png *.jpg *.bmp)"));
|
||||
if (fileName.isEmpty()) {
|
||||
imageLabel->setText(tr("No image chosen."));
|
||||
return;
|
||||
}
|
||||
|
||||
QImageReader imgReader;
|
||||
imgReader.setDecideFormatFromContent(true);
|
||||
imgReader.setFileName(fileName);
|
||||
if (!imgReader.read(&image)) {
|
||||
qDebug() << "Avatar image loading failed for file:" << fileName;
|
||||
imageLabel->setText(tr("Invalid image chosen."));
|
||||
return;
|
||||
}
|
||||
imageLabel->setPixmap(QPixmap::fromImage(image).scaled(400, 200, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
}
|
||||
|
||||
QByteArray DlgEditAvatar::getImage()
|
||||
{
|
||||
if (image.isNull()) {
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
image.save(&buffer, "JPG");
|
||||
if (ba.length() > MAX_FILE_LENGTH) {
|
||||
image = image.scaledToWidth(image.width() / 2); // divide the amount of pixels in four to get the size down
|
||||
} else {
|
||||
return ba;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
cockatrice/src/dialogs/dlg_edit_avatar.h
Normal file
28
cockatrice/src/dialogs/dlg_edit_avatar.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef DLG_EDITAVATAR_H
|
||||
#define DLG_EDITAVATAR_H
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QCheckBox;
|
||||
|
||||
class DlgEditAvatar : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DlgEditAvatar(QWidget *parent = nullptr);
|
||||
QByteArray getImage();
|
||||
private slots:
|
||||
void actOk();
|
||||
void actBrowse();
|
||||
|
||||
private:
|
||||
QImage image;
|
||||
QLabel *textLabel, *imageLabel;
|
||||
QPushButton *browseButton;
|
||||
};
|
||||
|
||||
#endif
|
||||
72
cockatrice/src/dialogs/dlg_edit_password.cpp
Normal file
72
cockatrice/src/dialogs/dlg_edit_password.cpp
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#include "dlg_edit_password.h"
|
||||
|
||||
#include "../settings/cache_settings.h"
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
|
||||
DlgEditPassword::DlgEditPassword(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
oldPasswordLabel = new QLabel(tr("Old password:"));
|
||||
oldPasswordEdit = new QLineEdit();
|
||||
oldPasswordEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
|
||||
auto &servers = SettingsCache::instance().servers();
|
||||
if (servers.getSavePassword()) {
|
||||
oldPasswordEdit->setText(servers.getPassword());
|
||||
}
|
||||
|
||||
oldPasswordLabel->setBuddy(oldPasswordEdit);
|
||||
oldPasswordEdit->setEchoMode(QLineEdit::Password);
|
||||
|
||||
newPasswordLabel = new QLabel(tr("New password:"));
|
||||
newPasswordEdit = new QLineEdit();
|
||||
newPasswordEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
newPasswordLabel->setBuddy(newPasswordLabel);
|
||||
newPasswordEdit->setEchoMode(QLineEdit::Password);
|
||||
|
||||
newPasswordLabel2 = new QLabel(tr("Confirm new password:"));
|
||||
newPasswordEdit2 = new QLineEdit();
|
||||
newPasswordEdit2->setMaxLength(MAX_NAME_LENGTH);
|
||||
newPasswordLabel2->setBuddy(newPasswordLabel2);
|
||||
newPasswordEdit2->setEchoMode(QLineEdit::Password);
|
||||
|
||||
QGridLayout *grid = new QGridLayout;
|
||||
grid->addWidget(oldPasswordLabel, 0, 0);
|
||||
grid->addWidget(oldPasswordEdit, 0, 1);
|
||||
grid->addWidget(newPasswordLabel, 1, 0);
|
||||
grid->addWidget(newPasswordEdit, 1, 1);
|
||||
grid->addWidget(newPasswordLabel2, 2, 0);
|
||||
grid->addWidget(newPasswordEdit2, 2, 1);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(grid);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Change password"));
|
||||
setFixedHeight(sizeHint().height());
|
||||
setMinimumWidth(300);
|
||||
}
|
||||
|
||||
void DlgEditPassword::actOk()
|
||||
{
|
||||
// TODO this stuff should be using qvalidators
|
||||
if (newPasswordEdit->text().length() < 8) {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Your password is too short."));
|
||||
return;
|
||||
} else if (newPasswordEdit->text() != newPasswordEdit2->text()) {
|
||||
QMessageBox::warning(this, tr("Error"), tr("The new passwords don't match."));
|
||||
return;
|
||||
}
|
||||
|
||||
accept();
|
||||
}
|
||||
33
cockatrice/src/dialogs/dlg_edit_password.h
Normal file
33
cockatrice/src/dialogs/dlg_edit_password.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef DLG_EDITPASSWORD_H
|
||||
#define DLG_EDITPASSWORD_H
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QCheckBox;
|
||||
|
||||
class DlgEditPassword : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DlgEditPassword(QWidget *parent = nullptr);
|
||||
QString getOldPassword() const
|
||||
{
|
||||
return oldPasswordEdit->text();
|
||||
}
|
||||
QString getNewPassword() const
|
||||
{
|
||||
return newPasswordEdit->text();
|
||||
}
|
||||
private slots:
|
||||
void actOk();
|
||||
|
||||
private:
|
||||
QLabel *oldPasswordLabel, *newPasswordLabel, *newPasswordLabel2;
|
||||
QLineEdit *oldPasswordEdit, *newPasswordEdit, *newPasswordEdit2;
|
||||
};
|
||||
|
||||
#endif
|
||||
198
cockatrice/src/dialogs/dlg_edit_tokens.cpp
Normal file
198
cockatrice/src/dialogs/dlg_edit_tokens.cpp
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
#include "dlg_edit_tokens.h"
|
||||
|
||||
#include "../client/get_text_with_max.h"
|
||||
#include "../game/cards/card_database.h"
|
||||
#include "../game/cards/card_database_model.h"
|
||||
#include "../main.h"
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QComboBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QInputDialog>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QToolBar>
|
||||
#include <QTreeView>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
DlgEditTokens::DlgEditTokens(QWidget *parent) : QDialog(parent), currentCard(nullptr)
|
||||
{
|
||||
nameLabel = new QLabel(tr("&Name:"));
|
||||
nameEdit = new QLineEdit;
|
||||
nameEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
nameEdit->setEnabled(false);
|
||||
nameLabel->setBuddy(nameEdit);
|
||||
|
||||
colorLabel = new QLabel(tr("C&olor:"));
|
||||
colorEdit = new QComboBox;
|
||||
colorEdit->addItem(tr("white"), QChar('w'));
|
||||
colorEdit->addItem(tr("blue"), QChar('u'));
|
||||
colorEdit->addItem(tr("black"), QChar('b'));
|
||||
colorEdit->addItem(tr("red"), QChar('r'));
|
||||
colorEdit->addItem(tr("green"), QChar('g'));
|
||||
colorEdit->addItem(tr("multicolor"), QChar('m'));
|
||||
colorEdit->addItem(tr("colorless"), QChar());
|
||||
colorLabel->setBuddy(colorEdit);
|
||||
connect(colorEdit, SIGNAL(currentIndexChanged(int)), this, SLOT(colorChanged(int)));
|
||||
|
||||
ptLabel = new QLabel(tr("&P/T:"));
|
||||
ptEdit = new QLineEdit;
|
||||
ptEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
ptLabel->setBuddy(ptEdit);
|
||||
connect(ptEdit, SIGNAL(textChanged(QString)), this, SLOT(ptChanged(QString)));
|
||||
|
||||
annotationLabel = new QLabel(tr("&Annotation:"));
|
||||
annotationEdit = new QLineEdit;
|
||||
annotationEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
annotationLabel->setBuddy(annotationEdit);
|
||||
connect(annotationEdit, SIGNAL(textChanged(QString)), this, SLOT(annotationChanged(QString)));
|
||||
|
||||
auto *grid = new QGridLayout;
|
||||
grid->addWidget(nameLabel, 0, 0);
|
||||
grid->addWidget(nameEdit, 0, 1);
|
||||
grid->addWidget(colorLabel, 1, 0);
|
||||
grid->addWidget(colorEdit, 1, 1);
|
||||
grid->addWidget(ptLabel, 2, 0);
|
||||
grid->addWidget(ptEdit, 2, 1);
|
||||
grid->addWidget(annotationLabel, 3, 0);
|
||||
grid->addWidget(annotationEdit, 3, 1);
|
||||
|
||||
QGroupBox *tokenDataGroupBox = new QGroupBox(tr("Token data"));
|
||||
tokenDataGroupBox->setLayout(grid);
|
||||
|
||||
databaseModel = new CardDatabaseModel(db, false, this);
|
||||
databaseModel->setObjectName("databaseModel");
|
||||
cardDatabaseDisplayModel = new TokenEditModel(this);
|
||||
cardDatabaseDisplayModel->setSourceModel(databaseModel);
|
||||
cardDatabaseDisplayModel->setIsToken(CardDatabaseDisplayModel::ShowTrue);
|
||||
|
||||
chooseTokenView = new QTreeView;
|
||||
chooseTokenView->setModel(cardDatabaseDisplayModel);
|
||||
chooseTokenView->setUniformRowHeights(true);
|
||||
chooseTokenView->setRootIsDecorated(false);
|
||||
chooseTokenView->setAlternatingRowColors(true);
|
||||
chooseTokenView->setSortingEnabled(true);
|
||||
chooseTokenView->sortByColumn(0, Qt::AscendingOrder);
|
||||
chooseTokenView->resizeColumnToContents(0);
|
||||
chooseTokenView->header()->setStretchLastSection(false);
|
||||
chooseTokenView->header()->hideSection(1);
|
||||
chooseTokenView->header()->hideSection(2);
|
||||
chooseTokenView->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
||||
chooseTokenView->header()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
|
||||
|
||||
connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this,
|
||||
SLOT(tokenSelectionChanged(QModelIndex, QModelIndex)));
|
||||
|
||||
QAction *aAddToken = new QAction(tr("Add token"), this);
|
||||
aAddToken->setIcon(QPixmap("theme:icons/increment"));
|
||||
connect(aAddToken, SIGNAL(triggered()), this, SLOT(actAddToken()));
|
||||
QAction *aRemoveToken = new QAction(tr("Remove token"), this);
|
||||
aRemoveToken->setIcon(QPixmap("theme:icons/decrement"));
|
||||
connect(aRemoveToken, SIGNAL(triggered()), this, SLOT(actRemoveToken()));
|
||||
|
||||
auto *databaseToolBar = new QToolBar;
|
||||
databaseToolBar->addAction(aAddToken);
|
||||
databaseToolBar->addAction(aRemoveToken);
|
||||
|
||||
auto *leftVBox = new QVBoxLayout;
|
||||
leftVBox->addWidget(chooseTokenView);
|
||||
leftVBox->addWidget(databaseToolBar);
|
||||
|
||||
auto *hbox = new QHBoxLayout;
|
||||
hbox->addLayout(leftVBox);
|
||||
hbox->addWidget(tokenDataGroupBox);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
auto *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(hbox);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
|
||||
setLayout(mainLayout);
|
||||
setWindowTitle(tr("Edit custom tokens"));
|
||||
}
|
||||
|
||||
void DlgEditTokens::tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex & /* previous */)
|
||||
{
|
||||
const QModelIndex realIndex = cardDatabaseDisplayModel->mapToSource(current);
|
||||
|
||||
if (current.row() >= 0) {
|
||||
currentCard = databaseModel->getCard(realIndex.row());
|
||||
} else {
|
||||
currentCard.clear();
|
||||
}
|
||||
|
||||
if (currentCard) {
|
||||
nameEdit->setText(currentCard->getName());
|
||||
const QChar cardColor = currentCard->getColorChar();
|
||||
colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString));
|
||||
ptEdit->setText(currentCard->getPowTough());
|
||||
annotationEdit->setText(currentCard->getText());
|
||||
} else {
|
||||
nameEdit->setText("");
|
||||
colorEdit->setCurrentIndex(colorEdit->findData(QChar(), Qt::UserRole, Qt::MatchFixedString));
|
||||
ptEdit->setText("");
|
||||
annotationEdit->setText("");
|
||||
}
|
||||
}
|
||||
|
||||
void DlgEditTokens::actAddToken()
|
||||
{
|
||||
QString name;
|
||||
for (;;) {
|
||||
name = getTextWithMax(this, tr("Add token"), tr("Please enter the name of the token:"));
|
||||
if (name.isEmpty())
|
||||
return;
|
||||
if (databaseModel->getDatabase()->getCard(name)) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("The chosen name conflicts with an existing card or token.\nMake sure to enable "
|
||||
"the 'Token' set in the \"Manage sets\" dialog to display them correctly."));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString setName = CardDatabase::TOKENS_SETNAME;
|
||||
CardInfoPerSetMap sets;
|
||||
sets.insert(setName, CardInfoPerSet(databaseModel->getDatabase()->getSet(setName)));
|
||||
CardInfoPtr card = CardInfo::newInstance(name, "", true, QVariantHash(), QList<CardRelation *>(),
|
||||
QList<CardRelation *>(), sets, false, -1, false);
|
||||
card->setCardType("Token");
|
||||
|
||||
databaseModel->getDatabase()->addCard(card);
|
||||
}
|
||||
|
||||
void DlgEditTokens::actRemoveToken()
|
||||
{
|
||||
if (currentCard) {
|
||||
CardInfoPtr cardToRemove = currentCard; // the currentCard property gets modified during db->removeCard()
|
||||
currentCard.clear();
|
||||
databaseModel->getDatabase()->removeCard(cardToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
void DlgEditTokens::colorChanged(int colorIndex)
|
||||
{
|
||||
if (currentCard)
|
||||
currentCard->setColors(QString(colorEdit->itemData(colorIndex).toChar()));
|
||||
}
|
||||
|
||||
void DlgEditTokens::ptChanged(const QString &_pt)
|
||||
{
|
||||
if (currentCard)
|
||||
currentCard->setPowTough(_pt);
|
||||
}
|
||||
|
||||
void DlgEditTokens::annotationChanged(const QString &_annotation)
|
||||
{
|
||||
if (currentCard)
|
||||
currentCard->setText(_annotation);
|
||||
}
|
||||
42
cockatrice/src/dialogs/dlg_edit_tokens.h
Normal file
42
cockatrice/src/dialogs/dlg_edit_tokens.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef DLG_EDIT_TOKENS_H
|
||||
#define DLG_EDIT_TOKENS_H
|
||||
|
||||
#include "../game/cards/card_database.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class QModelIndex;
|
||||
class CardDatabaseModel;
|
||||
class TokenEditModel;
|
||||
class QLabel;
|
||||
class QComboBox;
|
||||
class QLineEdit;
|
||||
class QTreeView;
|
||||
|
||||
class DlgEditTokens : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
void colorChanged(int _colorIndex);
|
||||
void ptChanged(const QString &_pt);
|
||||
void annotationChanged(const QString &_annotation);
|
||||
|
||||
void actAddToken();
|
||||
void actRemoveToken();
|
||||
|
||||
private:
|
||||
CardInfoPtr currentCard;
|
||||
CardDatabaseModel *databaseModel;
|
||||
TokenEditModel *cardDatabaseDisplayModel;
|
||||
QStringList predefinedTokens;
|
||||
QLabel *nameLabel, *colorLabel, *ptLabel, *annotationLabel;
|
||||
QComboBox *colorEdit;
|
||||
QLineEdit *nameEdit, *ptEdit, *annotationEdit;
|
||||
QTreeView *chooseTokenView;
|
||||
|
||||
public:
|
||||
explicit DlgEditTokens(QWidget *parent = nullptr);
|
||||
};
|
||||
|
||||
#endif
|
||||
67
cockatrice/src/dialogs/dlg_edit_user.cpp
Normal file
67
cockatrice/src/dialogs/dlg_edit_user.cpp
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#include "dlg_edit_user.h"
|
||||
|
||||
#include "../settings/cache_settings.h"
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
|
||||
DlgEditUser::DlgEditUser(QWidget *parent, QString email, QString country, QString realName) : QDialog(parent)
|
||||
{
|
||||
emailLabel = new QLabel(tr("Email:"));
|
||||
emailEdit = new QLineEdit();
|
||||
emailEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
emailLabel->setBuddy(emailEdit);
|
||||
emailEdit->setText(email);
|
||||
|
||||
countryLabel = new QLabel(tr("Country:"));
|
||||
countryEdit = new QComboBox();
|
||||
countryLabel->setBuddy(countryEdit);
|
||||
countryEdit->insertItem(0, tr("Undefined"));
|
||||
countryEdit->setCurrentIndex(0);
|
||||
|
||||
QStringList countries = SettingsCache::instance().getCountries();
|
||||
int i = 1;
|
||||
foreach (QString c, countries) {
|
||||
countryEdit->addItem(QPixmap("theme:countries/" + c.toLower()), c);
|
||||
if (c == country)
|
||||
countryEdit->setCurrentIndex(i);
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
realnameLabel = new QLabel(tr("Real name:"));
|
||||
realnameEdit = new QLineEdit();
|
||||
realnameEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
realnameLabel->setBuddy(realnameEdit);
|
||||
realnameEdit->setText(realName);
|
||||
|
||||
QGridLayout *grid = new QGridLayout;
|
||||
grid->addWidget(emailLabel, 0, 0);
|
||||
grid->addWidget(emailEdit, 0, 1);
|
||||
grid->addWidget(countryLabel, 2, 0);
|
||||
grid->addWidget(countryEdit, 2, 1);
|
||||
grid->addWidget(realnameLabel, 3, 0);
|
||||
grid->addWidget(realnameEdit, 3, 1);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(grid);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Edit user profile"));
|
||||
setFixedHeight(sizeHint().height());
|
||||
setMinimumWidth(300);
|
||||
}
|
||||
|
||||
void DlgEditUser::actOk()
|
||||
{
|
||||
accept();
|
||||
}
|
||||
41
cockatrice/src/dialogs/dlg_edit_user.h
Normal file
41
cockatrice/src/dialogs/dlg_edit_user.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef DLG_EDITUSER_H
|
||||
#define DLG_EDITUSER_H
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QCheckBox;
|
||||
|
||||
class DlgEditUser : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DlgEditUser(QWidget *parent = nullptr,
|
||||
QString email = QString(),
|
||||
QString country = QString(),
|
||||
QString realName = QString());
|
||||
QString getEmail() const
|
||||
{
|
||||
return emailEdit->text();
|
||||
}
|
||||
QString getCountry() const
|
||||
{
|
||||
return countryEdit->currentIndex() == 0 ? "" : countryEdit->currentText();
|
||||
}
|
||||
QString getRealName() const
|
||||
{
|
||||
return realnameEdit->text();
|
||||
}
|
||||
private slots:
|
||||
void actOk();
|
||||
|
||||
private:
|
||||
QLabel *emailLabel, *countryLabel, *realnameLabel;
|
||||
QLineEdit *emailEdit, *realnameEdit;
|
||||
QComboBox *countryEdit;
|
||||
};
|
||||
|
||||
#endif
|
||||
313
cockatrice/src/dialogs/dlg_filter_games.cpp
Normal file
313
cockatrice/src/dialogs/dlg_filter_games.cpp
Normal file
|
|
@ -0,0 +1,313 @@
|
|||
#include "dlg_filter_games.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QCryptographicHash>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QSpinBox>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_allGameTypes,
|
||||
const GamesProxyModel *_gamesProxyModel,
|
||||
QWidget *parent)
|
||||
: QDialog(parent), allGameTypes(_allGameTypes), gamesProxyModel(_gamesProxyModel),
|
||||
gameAgeMap({{QTime(), tr("no limit")},
|
||||
{QTime(0, 5), tr("5 minutes")},
|
||||
{QTime(0, 10), tr("10 minutes")},
|
||||
{QTime(0, 30), tr("30 minutes")},
|
||||
{QTime(1, 0), tr("1 hour")},
|
||||
{QTime(2, 0), tr("2 hours")}})
|
||||
{
|
||||
showBuddiesOnlyGames = new QCheckBox(tr("Show '&buddies only' games"));
|
||||
showBuddiesOnlyGames->setChecked(gamesProxyModel->getShowBuddiesOnlyGames());
|
||||
|
||||
showFullGames = new QCheckBox(tr("Show &full games"));
|
||||
showFullGames->setChecked(gamesProxyModel->getShowFullGames());
|
||||
|
||||
showGamesThatStarted = new QCheckBox(tr("Show games &that have started"));
|
||||
showGamesThatStarted->setChecked(gamesProxyModel->getShowGamesThatStarted());
|
||||
|
||||
showPasswordProtectedGames = new QCheckBox(tr("Show &password protected games"));
|
||||
showPasswordProtectedGames->setChecked(gamesProxyModel->getShowPasswordProtectedGames());
|
||||
|
||||
hideIgnoredUserGames = new QCheckBox(tr("Hide '&ignored user' games"));
|
||||
hideIgnoredUserGames->setChecked(gamesProxyModel->getHideIgnoredUserGames());
|
||||
|
||||
maxGameAgeComboBox = new QComboBox();
|
||||
maxGameAgeComboBox->setEditable(false);
|
||||
maxGameAgeComboBox->addItems(gameAgeMap.values());
|
||||
QTime gameAge = gamesProxyModel->getMaxGameAge();
|
||||
maxGameAgeComboBox->setCurrentIndex(gameAgeMap.keys().indexOf(gameAge)); // index is -1 if unknown
|
||||
auto *maxGameAgeLabel = new QLabel(tr("&Newer than:"));
|
||||
maxGameAgeLabel->setBuddy(maxGameAgeComboBox);
|
||||
|
||||
gameNameFilterEdit = new QLineEdit;
|
||||
gameNameFilterEdit->setText(gamesProxyModel->getGameNameFilter());
|
||||
auto *gameNameFilterLabel = new QLabel(tr("Game &description:"));
|
||||
gameNameFilterLabel->setBuddy(gameNameFilterEdit);
|
||||
creatorNameFilterEdit = new QLineEdit;
|
||||
creatorNameFilterEdit->setText(gamesProxyModel->getCreatorNameFilter());
|
||||
auto *creatorNameFilterLabel = new QLabel(tr("&Creator name:"));
|
||||
creatorNameFilterLabel->setBuddy(creatorNameFilterEdit);
|
||||
|
||||
auto *generalGrid = new QGridLayout;
|
||||
generalGrid->addWidget(gameNameFilterLabel, 0, 0);
|
||||
generalGrid->addWidget(gameNameFilterEdit, 0, 1);
|
||||
generalGrid->addWidget(creatorNameFilterLabel, 1, 0);
|
||||
generalGrid->addWidget(creatorNameFilterEdit, 1, 1);
|
||||
generalGrid->addWidget(maxGameAgeLabel, 2, 0);
|
||||
generalGrid->addWidget(maxGameAgeComboBox, 2, 1);
|
||||
generalGroupBox = new QGroupBox(tr("General"));
|
||||
generalGroupBox->setLayout(generalGrid);
|
||||
|
||||
auto *gameTypeFilterLayout = new QVBoxLayout;
|
||||
QMapIterator<int, QString> gameTypesIterator(allGameTypes);
|
||||
while (gameTypesIterator.hasNext()) {
|
||||
gameTypesIterator.next();
|
||||
|
||||
auto *temp = new QCheckBox(gameTypesIterator.value());
|
||||
temp->setChecked(gamesProxyModel->getGameTypeFilter().contains(gameTypesIterator.key()));
|
||||
|
||||
gameTypeFilterCheckBoxes.insert(gameTypesIterator.key(), temp);
|
||||
gameTypeFilterLayout->addWidget(temp);
|
||||
}
|
||||
QGroupBox *gameTypeFilterGroupBox;
|
||||
if (!allGameTypes.isEmpty()) {
|
||||
gameTypeFilterGroupBox = new QGroupBox(tr("&Game types"));
|
||||
gameTypeFilterGroupBox->setLayout(gameTypeFilterLayout);
|
||||
} else
|
||||
gameTypeFilterGroupBox = nullptr;
|
||||
|
||||
auto *maxPlayersFilterMinLabel = new QLabel(tr("at &least:"));
|
||||
maxPlayersFilterMinSpinBox = new QSpinBox;
|
||||
maxPlayersFilterMinSpinBox->setMinimum(0);
|
||||
maxPlayersFilterMinSpinBox->setMaximum(99);
|
||||
maxPlayersFilterMinSpinBox->setValue(gamesProxyModel->getMaxPlayersFilterMin());
|
||||
maxPlayersFilterMinLabel->setBuddy(maxPlayersFilterMinSpinBox);
|
||||
|
||||
auto *maxPlayersFilterMaxLabel = new QLabel(tr("at &most:"));
|
||||
maxPlayersFilterMaxSpinBox = new QSpinBox;
|
||||
maxPlayersFilterMaxSpinBox->setMinimum(0);
|
||||
maxPlayersFilterMaxSpinBox->setMaximum(99);
|
||||
maxPlayersFilterMaxSpinBox->setValue(gamesProxyModel->getMaxPlayersFilterMax());
|
||||
maxPlayersFilterMaxLabel->setBuddy(maxPlayersFilterMaxSpinBox);
|
||||
|
||||
auto *maxPlayersFilterLayout = new QGridLayout;
|
||||
maxPlayersFilterLayout->addWidget(maxPlayersFilterMinLabel, 0, 0);
|
||||
maxPlayersFilterLayout->addWidget(maxPlayersFilterMinSpinBox, 0, 1);
|
||||
maxPlayersFilterLayout->addWidget(maxPlayersFilterMaxLabel, 1, 0);
|
||||
maxPlayersFilterLayout->addWidget(maxPlayersFilterMaxSpinBox, 1, 1);
|
||||
|
||||
auto *maxPlayersGroupBox = new QGroupBox(tr("Maximum player count"));
|
||||
maxPlayersGroupBox->setLayout(maxPlayersFilterLayout);
|
||||
|
||||
auto *restrictionsLayout = new QGridLayout;
|
||||
restrictionsLayout->addWidget(showFullGames, 0, 0);
|
||||
restrictionsLayout->addWidget(showGamesThatStarted, 1, 0);
|
||||
restrictionsLayout->addWidget(showPasswordProtectedGames, 2, 0);
|
||||
restrictionsLayout->addWidget(showBuddiesOnlyGames, 3, 0);
|
||||
restrictionsLayout->addWidget(hideIgnoredUserGames, 4, 0);
|
||||
|
||||
auto *restrictionsGroupBox = new QGroupBox(tr("Restrictions"));
|
||||
restrictionsGroupBox->setLayout(restrictionsLayout);
|
||||
|
||||
showOnlyIfSpectatorsCanWatch = new QCheckBox(tr("Show games only if &spectators can watch"));
|
||||
showOnlyIfSpectatorsCanWatch->setChecked(gamesProxyModel->getShowOnlyIfSpectatorsCanWatch());
|
||||
connect(showOnlyIfSpectatorsCanWatch, SIGNAL(toggled(bool)), this, SLOT(toggleSpectatorCheckboxEnabledness(bool)));
|
||||
|
||||
showSpectatorPasswordProtected = new QCheckBox(tr("Show spectator password p&rotected games"));
|
||||
showSpectatorPasswordProtected->setChecked(gamesProxyModel->getShowSpectatorPasswordProtected());
|
||||
showOnlyIfSpectatorsCanChat = new QCheckBox(tr("Show only if spectators can ch&at"));
|
||||
showOnlyIfSpectatorsCanChat->setChecked(gamesProxyModel->getShowOnlyIfSpectatorsCanChat());
|
||||
showOnlyIfSpectatorsCanSeeHands = new QCheckBox(tr("Show only if spectators can see &hands"));
|
||||
showOnlyIfSpectatorsCanSeeHands->setChecked(gamesProxyModel->getShowOnlyIfSpectatorsCanSeeHands());
|
||||
toggleSpectatorCheckboxEnabledness(getShowOnlyIfSpectatorsCanWatch());
|
||||
|
||||
auto *spectatorsLayout = new QGridLayout;
|
||||
spectatorsLayout->addWidget(showOnlyIfSpectatorsCanWatch, 0, 0);
|
||||
spectatorsLayout->addWidget(showSpectatorPasswordProtected, 1, 0);
|
||||
spectatorsLayout->addWidget(showOnlyIfSpectatorsCanChat, 2, 0);
|
||||
spectatorsLayout->addWidget(showOnlyIfSpectatorsCanSeeHands, 3, 0);
|
||||
|
||||
auto *spectatorsGroupBox = new QGroupBox(tr("Spectators"));
|
||||
spectatorsGroupBox->setLayout(spectatorsLayout);
|
||||
|
||||
auto *leftGrid = new QGridLayout;
|
||||
leftGrid->addWidget(generalGroupBox, 0, 0, 1, 2);
|
||||
leftGrid->addWidget(maxPlayersGroupBox, 2, 0, 1, 2);
|
||||
leftGrid->addWidget(restrictionsGroupBox, 3, 0, 1, 2);
|
||||
|
||||
auto *leftColumn = new QVBoxLayout;
|
||||
leftColumn->addLayout(leftGrid);
|
||||
leftColumn->addStretch();
|
||||
|
||||
auto *rightGrid = new QGridLayout;
|
||||
rightGrid->addWidget(gameTypeFilterGroupBox, 0, 0, 1, 1);
|
||||
rightGrid->addWidget(spectatorsGroupBox, 1, 0, 1, 1);
|
||||
|
||||
auto *rightColumn = new QVBoxLayout;
|
||||
rightColumn->addLayout(rightGrid);
|
||||
rightColumn->addStretch();
|
||||
|
||||
auto *hbox = new QHBoxLayout;
|
||||
hbox->addLayout(leftColumn);
|
||||
hbox->addLayout(rightColumn);
|
||||
|
||||
auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
auto *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(hbox);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
|
||||
setLayout(mainLayout);
|
||||
setWindowTitle(tr("Filter games"));
|
||||
|
||||
setFixedHeight(sizeHint().height());
|
||||
}
|
||||
|
||||
void DlgFilterGames::actOk()
|
||||
{
|
||||
accept();
|
||||
}
|
||||
|
||||
void DlgFilterGames::toggleSpectatorCheckboxEnabledness(bool spectatorsEnabled)
|
||||
{
|
||||
showSpectatorPasswordProtected->setDisabled(!spectatorsEnabled);
|
||||
showOnlyIfSpectatorsCanChat->setDisabled(!spectatorsEnabled);
|
||||
showOnlyIfSpectatorsCanSeeHands->setDisabled(!spectatorsEnabled);
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getShowFullGames() const
|
||||
{
|
||||
return showFullGames->isChecked();
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getShowGamesThatStarted() const
|
||||
{
|
||||
return showGamesThatStarted->isChecked();
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getShowBuddiesOnlyGames() const
|
||||
{
|
||||
return showBuddiesOnlyGames->isChecked();
|
||||
}
|
||||
|
||||
void DlgFilterGames::setShowBuddiesOnlyGames(bool _showBuddiesOnlyGames)
|
||||
{
|
||||
showBuddiesOnlyGames->setChecked(_showBuddiesOnlyGames);
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getShowPasswordProtectedGames() const
|
||||
{
|
||||
return showPasswordProtectedGames->isChecked();
|
||||
}
|
||||
|
||||
void DlgFilterGames::setShowPasswordProtectedGames(bool _passwordProtectedGamesHidden)
|
||||
{
|
||||
showPasswordProtectedGames->setChecked(_passwordProtectedGamesHidden);
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getHideIgnoredUserGames() const
|
||||
{
|
||||
return hideIgnoredUserGames->isChecked();
|
||||
}
|
||||
|
||||
void DlgFilterGames::setHideIgnoredUserGames(bool _hideIgnoredUserGames)
|
||||
{
|
||||
hideIgnoredUserGames->setChecked(_hideIgnoredUserGames);
|
||||
}
|
||||
|
||||
QString DlgFilterGames::getGameNameFilter() const
|
||||
{
|
||||
return gameNameFilterEdit->text();
|
||||
}
|
||||
|
||||
void DlgFilterGames::setGameNameFilter(const QString &_gameNameFilter)
|
||||
{
|
||||
gameNameFilterEdit->setText(_gameNameFilter);
|
||||
}
|
||||
|
||||
QString DlgFilterGames::getCreatorNameFilter() const
|
||||
{
|
||||
return creatorNameFilterEdit->text();
|
||||
}
|
||||
|
||||
void DlgFilterGames::setCreatorNameFilter(const QString &_creatorNameFilter)
|
||||
{
|
||||
creatorNameFilterEdit->setText(_creatorNameFilter);
|
||||
}
|
||||
|
||||
QSet<int> DlgFilterGames::getGameTypeFilter() const
|
||||
{
|
||||
QSet<int> result;
|
||||
QMapIterator<int, QCheckBox *> i(gameTypeFilterCheckBoxes);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (i.value()->isChecked())
|
||||
result.insert(i.key());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void DlgFilterGames::setGameTypeFilter(const QSet<int> &_gameTypeFilter)
|
||||
{
|
||||
QMapIterator<int, QCheckBox *> i(gameTypeFilterCheckBoxes);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
i.value()->setChecked(_gameTypeFilter.contains(i.key()));
|
||||
}
|
||||
}
|
||||
|
||||
int DlgFilterGames::getMaxPlayersFilterMin() const
|
||||
{
|
||||
return maxPlayersFilterMinSpinBox->value();
|
||||
}
|
||||
|
||||
int DlgFilterGames::getMaxPlayersFilterMax() const
|
||||
{
|
||||
return maxPlayersFilterMaxSpinBox->value();
|
||||
}
|
||||
|
||||
const QTime &DlgFilterGames::getMaxGameAge() const
|
||||
{
|
||||
int index = maxGameAgeComboBox->currentIndex();
|
||||
if (index < 0 || index >= gameAgeMap.size()) { // index is out of bounds
|
||||
return gamesProxyModel->getMaxGameAge(); // leave the setting unchanged
|
||||
}
|
||||
return gameAgeMap.keys().at(index);
|
||||
}
|
||||
|
||||
void DlgFilterGames::setMaxPlayersFilter(int _maxPlayersFilterMin, int _maxPlayersFilterMax)
|
||||
{
|
||||
maxPlayersFilterMinSpinBox->setValue(_maxPlayersFilterMin);
|
||||
maxPlayersFilterMaxSpinBox->setValue(_maxPlayersFilterMax == -1 ? maxPlayersFilterMaxSpinBox->maximum()
|
||||
: _maxPlayersFilterMax);
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getShowOnlyIfSpectatorsCanWatch() const
|
||||
{
|
||||
return showOnlyIfSpectatorsCanWatch->isChecked();
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getShowSpectatorPasswordProtected() const
|
||||
{
|
||||
return showSpectatorPasswordProtected->isEnabled() && showSpectatorPasswordProtected->isChecked();
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getShowOnlyIfSpectatorsCanChat() const
|
||||
{
|
||||
return showOnlyIfSpectatorsCanChat->isEnabled() && showOnlyIfSpectatorsCanChat->isChecked();
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getShowOnlyIfSpectatorsCanSeeHands() const
|
||||
{
|
||||
return showOnlyIfSpectatorsCanSeeHands->isEnabled() && showOnlyIfSpectatorsCanSeeHands->isChecked();
|
||||
}
|
||||
78
cockatrice/src/dialogs/dlg_filter_games.h
Normal file
78
cockatrice/src/dialogs/dlg_filter_games.h
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
#ifndef DLG_FILTER_GAMES_H
|
||||
#define DLG_FILTER_GAMES_H
|
||||
|
||||
#include "../game/games_model.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QMap>
|
||||
#include <QSet>
|
||||
#include <QTime>
|
||||
|
||||
class QCheckBox;
|
||||
class QComboBox;
|
||||
class QGroupBox;
|
||||
class QLineEdit;
|
||||
class QSpinBox;
|
||||
|
||||
class DlgFilterGames : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
QGroupBox *generalGroupBox;
|
||||
QCheckBox *showBuddiesOnlyGames;
|
||||
QCheckBox *showFullGames;
|
||||
QCheckBox *showGamesThatStarted;
|
||||
QCheckBox *showPasswordProtectedGames;
|
||||
QCheckBox *hideIgnoredUserGames;
|
||||
QLineEdit *gameNameFilterEdit;
|
||||
QLineEdit *creatorNameFilterEdit;
|
||||
QMap<int, QCheckBox *> gameTypeFilterCheckBoxes;
|
||||
QSpinBox *maxPlayersFilterMinSpinBox;
|
||||
QSpinBox *maxPlayersFilterMaxSpinBox;
|
||||
QComboBox *maxGameAgeComboBox;
|
||||
|
||||
QCheckBox *showOnlyIfSpectatorsCanWatch;
|
||||
QCheckBox *showSpectatorPasswordProtected;
|
||||
QCheckBox *showOnlyIfSpectatorsCanChat;
|
||||
QCheckBox *showOnlyIfSpectatorsCanSeeHands;
|
||||
|
||||
const QMap<int, QString> &allGameTypes;
|
||||
const GamesProxyModel *gamesProxyModel;
|
||||
|
||||
private slots:
|
||||
void actOk();
|
||||
void toggleSpectatorCheckboxEnabledness(bool spectatorsEnabled);
|
||||
|
||||
public:
|
||||
DlgFilterGames(const QMap<int, QString> &_allGameTypes,
|
||||
const GamesProxyModel *_gamesProxyModel,
|
||||
QWidget *parent = nullptr);
|
||||
|
||||
bool getShowFullGames() const;
|
||||
bool getShowGamesThatStarted() const;
|
||||
bool getShowPasswordProtectedGames() const;
|
||||
void setShowPasswordProtectedGames(bool _passwordProtectedGamesHidden);
|
||||
bool getShowBuddiesOnlyGames() const;
|
||||
void setShowBuddiesOnlyGames(bool _showBuddiesOnlyGames);
|
||||
bool getHideIgnoredUserGames() const;
|
||||
void setHideIgnoredUserGames(bool _hideIgnoredUserGames);
|
||||
QString getGameNameFilter() const;
|
||||
void setGameNameFilter(const QString &_gameNameFilter);
|
||||
QString getCreatorNameFilter() const;
|
||||
void setCreatorNameFilter(const QString &_creatorNameFilter);
|
||||
QSet<int> getGameTypeFilter() const;
|
||||
void setGameTypeFilter(const QSet<int> &_gameTypeFilter);
|
||||
int getMaxPlayersFilterMin() const;
|
||||
int getMaxPlayersFilterMax() const;
|
||||
void setMaxPlayersFilter(int _maxPlayersFilterMin, int _maxPlayersFilterMax);
|
||||
const QTime &getMaxGameAge() const;
|
||||
const QMap<QTime, QString> gameAgeMap;
|
||||
bool getShowOnlyIfSpectatorsCanWatch() const;
|
||||
bool getShowSpectatorPasswordProtected() const;
|
||||
bool getShowOnlyIfSpectatorsCanChat() const;
|
||||
bool getShowOnlyIfSpectatorsCanSeeHands() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
107
cockatrice/src/dialogs/dlg_forgot_password_challenge.cpp
Normal file
107
cockatrice/src/dialogs/dlg_forgot_password_challenge.cpp
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
#include "dlg_forgot_password_challenge.h"
|
||||
|
||||
#include "../settings/cache_settings.h"
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QDebug>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
|
||||
DlgForgotPasswordChallenge::DlgForgotPasswordChallenge(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
QString lastfphost;
|
||||
QString lastfpport;
|
||||
QString lastfpplayername;
|
||||
ServersSettings &servers = SettingsCache::instance().servers();
|
||||
lastfphost = servers.getHostname();
|
||||
lastfpport = servers.getPort();
|
||||
lastfpplayername = servers.getPlayerName();
|
||||
|
||||
if (!servers.getFPHostname().isEmpty() && !servers.getFPPort().isEmpty() && !servers.getFPPlayerName().isEmpty()) {
|
||||
lastfphost = servers.getFPHostname();
|
||||
lastfpport = servers.getFPPort();
|
||||
lastfpplayername = servers.getFPPlayerName();
|
||||
}
|
||||
|
||||
if (servers.getFPHostname().isEmpty() && servers.getFPPort().isEmpty() && servers.getFPPlayerName().isEmpty()) {
|
||||
QMessageBox::warning(this, tr("Reset Password Challenge Warning"),
|
||||
tr("A problem has occurred. Please try to request a new password again."));
|
||||
reject();
|
||||
}
|
||||
|
||||
infoLabel =
|
||||
new QLabel(tr("Enter the information of the server and the account you'd like to request a new password for."));
|
||||
infoLabel->setWordWrap(true);
|
||||
|
||||
hostLabel = new QLabel(tr("&Host:"));
|
||||
hostEdit = new QLineEdit(lastfphost);
|
||||
hostEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
hostLabel->setBuddy(hostEdit);
|
||||
|
||||
portLabel = new QLabel(tr("&Port:"));
|
||||
portEdit = new QLineEdit(lastfpport);
|
||||
portEdit->setValidator(new QIntValidator(0, 0xffff, portEdit));
|
||||
portLabel->setBuddy(portEdit);
|
||||
|
||||
playernameLabel = new QLabel(tr("Player &name:"));
|
||||
playernameEdit = new QLineEdit(lastfpplayername);
|
||||
playernameEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
playernameLabel->setBuddy(playernameEdit);
|
||||
|
||||
emailLabel = new QLabel(tr("Email:"));
|
||||
emailEdit = new QLineEdit();
|
||||
emailEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
emailLabel->setBuddy(emailLabel);
|
||||
|
||||
if (!servers.getFPHostname().isEmpty() && !servers.getFPPort().isEmpty() && !servers.getFPPlayerName().isEmpty()) {
|
||||
hostLabel->hide();
|
||||
hostEdit->hide();
|
||||
portLabel->hide();
|
||||
portEdit->hide();
|
||||
playernameLabel->hide();
|
||||
playernameEdit->hide();
|
||||
}
|
||||
|
||||
QGridLayout *grid = new QGridLayout;
|
||||
grid->addWidget(infoLabel, 0, 0, 1, 2);
|
||||
grid->addWidget(hostLabel, 1, 0);
|
||||
grid->addWidget(hostEdit, 1, 1);
|
||||
grid->addWidget(portLabel, 2, 0);
|
||||
grid->addWidget(portEdit, 2, 1);
|
||||
grid->addWidget(playernameLabel, 3, 0);
|
||||
grid->addWidget(playernameEdit, 3, 1);
|
||||
grid->addWidget(emailLabel, 4, 0);
|
||||
grid->addWidget(emailEdit, 4, 1);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(grid);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Reset Password Challenge"));
|
||||
setFixedHeight(sizeHint().height());
|
||||
setMinimumWidth(300);
|
||||
}
|
||||
|
||||
void DlgForgotPasswordChallenge::actOk()
|
||||
{
|
||||
if (emailEdit->text().isEmpty()) {
|
||||
QMessageBox::critical(this, tr("Reset Password Challenge Error"), tr("The email address can't be empty."));
|
||||
return;
|
||||
}
|
||||
|
||||
ServersSettings &servers = SettingsCache::instance().servers();
|
||||
servers.setFPHostName(hostEdit->text());
|
||||
servers.setFPPort(portEdit->text());
|
||||
servers.setFPPlayerName(playernameEdit->text());
|
||||
|
||||
accept();
|
||||
}
|
||||
41
cockatrice/src/dialogs/dlg_forgot_password_challenge.h
Normal file
41
cockatrice/src/dialogs/dlg_forgot_password_challenge.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef DLG_FORGOTPASSWORDCHALLENGE_H
|
||||
#define DLG_FORGOTPASSWORDCHALLENGE_H
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QCheckBox;
|
||||
|
||||
class DlgForgotPasswordChallenge : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DlgForgotPasswordChallenge(QWidget *parent = nullptr);
|
||||
QString getHost() const
|
||||
{
|
||||
return hostEdit->text();
|
||||
}
|
||||
int getPort() const
|
||||
{
|
||||
return portEdit->text().toInt();
|
||||
}
|
||||
QString getPlayerName() const
|
||||
{
|
||||
return playernameEdit->text();
|
||||
}
|
||||
QString getEmail() const
|
||||
{
|
||||
return emailEdit->text();
|
||||
}
|
||||
private slots:
|
||||
void actOk();
|
||||
|
||||
private:
|
||||
QLabel *infoLabel, *hostLabel, *portLabel, *playernameLabel, *emailLabel;
|
||||
QLineEdit *hostEdit, *portEdit, *playernameEdit, *emailEdit;
|
||||
};
|
||||
|
||||
#endif
|
||||
84
cockatrice/src/dialogs/dlg_forgot_password_request.cpp
Normal file
84
cockatrice/src/dialogs/dlg_forgot_password_request.cpp
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
#include "dlg_forgot_password_request.h"
|
||||
|
||||
#include "../settings/cache_settings.h"
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QDebug>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
|
||||
DlgForgotPasswordRequest::DlgForgotPasswordRequest(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
QString lastfphost;
|
||||
QString lastfpport;
|
||||
QString lastfpplayername;
|
||||
ServersSettings &servers = SettingsCache::instance().servers();
|
||||
lastfphost = servers.getHostname();
|
||||
lastfpport = servers.getPort();
|
||||
lastfpplayername = servers.getPlayerName();
|
||||
|
||||
if (!servers.getFPHostname().isEmpty() && !servers.getFPPort().isEmpty() && !servers.getFPPlayerName().isEmpty()) {
|
||||
lastfphost = servers.getFPHostname();
|
||||
lastfpport = servers.getFPPort();
|
||||
lastfpplayername = servers.getFPPlayerName();
|
||||
}
|
||||
|
||||
infoLabel = new QLabel(tr("Enter the information of the server you'd like to request a new password for."));
|
||||
infoLabel->setWordWrap(true);
|
||||
|
||||
hostLabel = new QLabel(tr("&Host:"));
|
||||
hostEdit = new QLineEdit(lastfphost);
|
||||
hostEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
hostLabel->setBuddy(hostEdit);
|
||||
|
||||
portLabel = new QLabel(tr("&Port:"));
|
||||
portEdit = new QLineEdit(lastfpport);
|
||||
portEdit->setValidator(new QIntValidator(0, 0xffff, portEdit));
|
||||
portLabel->setBuddy(portEdit);
|
||||
|
||||
playernameLabel = new QLabel(tr("Player &name:"));
|
||||
playernameEdit = new QLineEdit(lastfpplayername);
|
||||
playernameEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
playernameLabel->setBuddy(playernameEdit);
|
||||
|
||||
QGridLayout *grid = new QGridLayout;
|
||||
grid->addWidget(infoLabel, 0, 0, 1, 2);
|
||||
grid->addWidget(hostLabel, 1, 0);
|
||||
grid->addWidget(hostEdit, 1, 1);
|
||||
grid->addWidget(portLabel, 2, 0);
|
||||
grid->addWidget(portEdit, 2, 1);
|
||||
grid->addWidget(playernameLabel, 3, 0);
|
||||
grid->addWidget(playernameEdit, 3, 1);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(grid);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Reset Password Request"));
|
||||
setFixedHeight(sizeHint().height());
|
||||
setMinimumWidth(300);
|
||||
}
|
||||
|
||||
void DlgForgotPasswordRequest::actOk()
|
||||
{
|
||||
if (playernameEdit->text().isEmpty()) {
|
||||
QMessageBox::critical(this, tr("Reset Password Error"), tr("The player name can't be empty."));
|
||||
return;
|
||||
}
|
||||
|
||||
ServersSettings &servers = SettingsCache::instance().servers();
|
||||
servers.setFPHostName(hostEdit->text());
|
||||
servers.setFPPort(portEdit->text());
|
||||
servers.setFPPlayerName(playernameEdit->text());
|
||||
|
||||
accept();
|
||||
}
|
||||
37
cockatrice/src/dialogs/dlg_forgot_password_request.h
Normal file
37
cockatrice/src/dialogs/dlg_forgot_password_request.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef DLG_FORGOTPASSWORDREQUEST_H
|
||||
#define DLG_FORGOTPASSWORDREQUEST_H
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QCheckBox;
|
||||
|
||||
class DlgForgotPasswordRequest : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DlgForgotPasswordRequest(QWidget *parent = nullptr);
|
||||
QString getHost() const
|
||||
{
|
||||
return hostEdit->text();
|
||||
}
|
||||
int getPort() const
|
||||
{
|
||||
return portEdit->text().toInt();
|
||||
}
|
||||
QString getPlayerName() const
|
||||
{
|
||||
return playernameEdit->text();
|
||||
}
|
||||
private slots:
|
||||
void actOk();
|
||||
|
||||
private:
|
||||
QLabel *infoLabel, *hostLabel, *portLabel, *playernameLabel;
|
||||
QLineEdit *hostEdit, *portEdit, *playernameEdit;
|
||||
};
|
||||
|
||||
#endif
|
||||
141
cockatrice/src/dialogs/dlg_forgot_password_reset.cpp
Normal file
141
cockatrice/src/dialogs/dlg_forgot_password_reset.cpp
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
#include "dlg_forgot_password_reset.h"
|
||||
|
||||
#include "../settings/cache_settings.h"
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QDebug>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
|
||||
DlgForgotPasswordReset::DlgForgotPasswordReset(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
QString lastfphost;
|
||||
QString lastfpport;
|
||||
QString lastfpplayername;
|
||||
ServersSettings &servers = SettingsCache::instance().servers();
|
||||
lastfphost = servers.getHostname();
|
||||
lastfpport = servers.getPort();
|
||||
lastfpplayername = servers.getPlayerName();
|
||||
|
||||
if (!servers.getFPHostname().isEmpty() && !servers.getFPPort().isEmpty() && !servers.getFPPlayerName().isEmpty()) {
|
||||
lastfphost = servers.getFPHostname();
|
||||
lastfpport = servers.getFPPort();
|
||||
lastfpplayername = servers.getFPPlayerName();
|
||||
}
|
||||
|
||||
if (servers.getFPHostname().isEmpty() && servers.getFPPort().isEmpty() && servers.getFPPlayerName().isEmpty()) {
|
||||
QMessageBox::warning(this, tr("Reset Password Warning"),
|
||||
tr("A problem has occurred. Please try to request a new password again."));
|
||||
reject();
|
||||
}
|
||||
|
||||
infoLabel = new QLabel(tr("Enter the received token and the new password in order to set your new password."));
|
||||
infoLabel->setWordWrap(true);
|
||||
|
||||
hostLabel = new QLabel(tr("&Host:"));
|
||||
hostEdit = new QLineEdit(lastfphost);
|
||||
hostEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
hostLabel->setBuddy(hostEdit);
|
||||
|
||||
portLabel = new QLabel(tr("&Port:"));
|
||||
portEdit = new QLineEdit(lastfpport);
|
||||
portEdit->setValidator(new QIntValidator(0, 0xffff, portEdit));
|
||||
portLabel->setBuddy(portEdit);
|
||||
|
||||
playernameLabel = new QLabel(tr("Player &name:"));
|
||||
playernameEdit = new QLineEdit(lastfpplayername);
|
||||
playernameEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
playernameLabel->setBuddy(playernameEdit);
|
||||
|
||||
tokenLabel = new QLabel(tr("Token:"));
|
||||
tokenEdit = new QLineEdit();
|
||||
tokenEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
tokenLabel->setBuddy(tokenLabel);
|
||||
|
||||
newpasswordLabel = new QLabel(tr("New Password:"));
|
||||
newpasswordEdit = new QLineEdit();
|
||||
newpasswordEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
newpasswordLabel->setBuddy(newpasswordEdit);
|
||||
newpasswordEdit->setEchoMode(QLineEdit::Password);
|
||||
|
||||
newpasswordverifyLabel = new QLabel(tr("New Password:"));
|
||||
newpasswordverifyEdit = new QLineEdit();
|
||||
newpasswordverifyEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
newpasswordverifyLabel->setBuddy(newpasswordEdit);
|
||||
newpasswordverifyEdit->setEchoMode(QLineEdit::Password);
|
||||
|
||||
if (!servers.getFPHostname().isEmpty() && !servers.getFPPort().isEmpty() && !servers.getFPPlayerName().isEmpty()) {
|
||||
hostLabel->hide();
|
||||
hostEdit->hide();
|
||||
portLabel->hide();
|
||||
portEdit->hide();
|
||||
playernameLabel->hide();
|
||||
playernameEdit->hide();
|
||||
}
|
||||
|
||||
QGridLayout *grid = new QGridLayout;
|
||||
grid->addWidget(infoLabel, 0, 0, 1, 2);
|
||||
grid->addWidget(hostLabel, 1, 0);
|
||||
grid->addWidget(hostEdit, 1, 1);
|
||||
grid->addWidget(portLabel, 2, 0);
|
||||
grid->addWidget(portEdit, 2, 1);
|
||||
grid->addWidget(playernameLabel, 3, 0);
|
||||
grid->addWidget(playernameEdit, 3, 1);
|
||||
grid->addWidget(tokenLabel, 4, 0);
|
||||
grid->addWidget(tokenEdit, 4, 1);
|
||||
grid->addWidget(newpasswordLabel, 5, 0);
|
||||
grid->addWidget(newpasswordEdit, 5, 1);
|
||||
grid->addWidget(newpasswordverifyLabel, 6, 0);
|
||||
grid->addWidget(newpasswordverifyEdit, 6, 1);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(grid);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Reset Password"));
|
||||
setFixedHeight(sizeHint().height());
|
||||
setMinimumWidth(300);
|
||||
}
|
||||
|
||||
void DlgForgotPasswordReset::actOk()
|
||||
{
|
||||
if (playernameEdit->text().isEmpty()) {
|
||||
QMessageBox::critical(this, tr("Reset Password Error"), tr("The player name can't be empty."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (tokenEdit->text().isEmpty()) {
|
||||
QMessageBox::critical(this, tr("Reset Password Error"), tr("The token can't be empty."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (newpasswordEdit->text().isEmpty()) {
|
||||
QMessageBox::critical(this, tr("Reset Password Error"), tr("The new password can't be empty."));
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO this stuff should be using qvalidators
|
||||
if (newpasswordEdit->text().length() < 8) {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Your password is too short."));
|
||||
return;
|
||||
} else if (newpasswordEdit->text() != newpasswordverifyEdit->text()) {
|
||||
QMessageBox::critical(this, tr("Reset Password Error"), tr("The passwords do not match."));
|
||||
return;
|
||||
}
|
||||
|
||||
ServersSettings &servers = SettingsCache::instance().servers();
|
||||
servers.setFPHostName(hostEdit->text());
|
||||
servers.setFPPort(portEdit->text());
|
||||
servers.setFPPlayerName(playernameEdit->text());
|
||||
|
||||
accept();
|
||||
}
|
||||
46
cockatrice/src/dialogs/dlg_forgot_password_reset.h
Normal file
46
cockatrice/src/dialogs/dlg_forgot_password_reset.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#ifndef DLG_FORGOTPASSWORDRESET_H
|
||||
#define DLG_FORGOTPASSWORDRESET_H
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QCheckBox;
|
||||
|
||||
class DlgForgotPasswordReset : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DlgForgotPasswordReset(QWidget *parent = nullptr);
|
||||
QString getHost() const
|
||||
{
|
||||
return hostEdit->text();
|
||||
}
|
||||
int getPort() const
|
||||
{
|
||||
return portEdit->text().toInt();
|
||||
}
|
||||
QString getPlayerName() const
|
||||
{
|
||||
return playernameEdit->text();
|
||||
}
|
||||
QString getToken() const
|
||||
{
|
||||
return tokenEdit->text();
|
||||
}
|
||||
QString getPassword() const
|
||||
{
|
||||
return newpasswordEdit->text();
|
||||
}
|
||||
private slots:
|
||||
void actOk();
|
||||
|
||||
private:
|
||||
QLabel *infoLabel, *hostLabel, *portLabel, *playernameLabel, *tokenLabel, *newpasswordLabel,
|
||||
*newpasswordverifyLabel;
|
||||
QLineEdit *hostEdit, *portEdit, *playernameEdit, *tokenEdit, *newpasswordEdit, *newpasswordverifyEdit;
|
||||
};
|
||||
|
||||
#endif
|
||||
73
cockatrice/src/dialogs/dlg_load_deck_from_clipboard.cpp
Normal file
73
cockatrice/src/dialogs/dlg_load_deck_from_clipboard.cpp
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
#include "dlg_load_deck_from_clipboard.h"
|
||||
|
||||
#include "../deck/deck_loader.h"
|
||||
#include "../settings/cache_settings.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QMessageBox>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QPushButton>
|
||||
#include <QTextStream>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
DlgLoadDeckFromClipboard::DlgLoadDeckFromClipboard(QWidget *parent) : QDialog(parent), deckList(nullptr)
|
||||
{
|
||||
contentsEdit = new QPlainTextEdit;
|
||||
|
||||
refreshButton = new QPushButton(tr("&Refresh"));
|
||||
connect(refreshButton, SIGNAL(clicked()), this, SLOT(actRefresh()));
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
buttonBox->addButton(refreshButton, QDialogButtonBox::ActionRole);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOK()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
auto *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addWidget(contentsEdit);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Load deck from clipboard"));
|
||||
resize(500, 500);
|
||||
|
||||
actRefresh();
|
||||
connect(&SettingsCache::instance().shortcuts(), SIGNAL(shortCutChanged()), this, SLOT(refreshShortcuts()));
|
||||
refreshShortcuts();
|
||||
}
|
||||
|
||||
void DlgLoadDeckFromClipboard::actRefresh()
|
||||
{
|
||||
contentsEdit->setPlainText(QApplication::clipboard()->text());
|
||||
}
|
||||
|
||||
void DlgLoadDeckFromClipboard::refreshShortcuts()
|
||||
{
|
||||
refreshButton->setShortcut(
|
||||
SettingsCache::instance().shortcuts().getSingleShortcut("DlgLoadDeckFromClipboard/refreshButton"));
|
||||
}
|
||||
|
||||
void DlgLoadDeckFromClipboard::actOK()
|
||||
{
|
||||
QString buffer = contentsEdit->toPlainText();
|
||||
QTextStream stream(&buffer);
|
||||
|
||||
auto *deckLoader = new DeckLoader;
|
||||
if (buffer.contains("<cockatrice_deck version=\"1\">")) {
|
||||
if (deckLoader->loadFromString_Native(buffer)) {
|
||||
deckList = deckLoader;
|
||||
accept();
|
||||
} else {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Invalid deck list."));
|
||||
delete deckLoader;
|
||||
}
|
||||
} else if (deckLoader->loadFromStream_Plain(stream)) {
|
||||
deckList = deckLoader;
|
||||
accept();
|
||||
} else {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Invalid deck list."));
|
||||
delete deckLoader;
|
||||
}
|
||||
}
|
||||
31
cockatrice/src/dialogs/dlg_load_deck_from_clipboard.h
Normal file
31
cockatrice/src/dialogs/dlg_load_deck_from_clipboard.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef DLG_LOAD_DECK_FROM_CLIPBOARD_H
|
||||
#define DLG_LOAD_DECK_FROM_CLIPBOARD_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class DeckLoader;
|
||||
class QPlainTextEdit;
|
||||
class QPushButton;
|
||||
|
||||
class DlgLoadDeckFromClipboard : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void actOK();
|
||||
void actRefresh();
|
||||
void refreshShortcuts();
|
||||
|
||||
private:
|
||||
DeckLoader *deckList;
|
||||
QPlainTextEdit *contentsEdit;
|
||||
QPushButton *refreshButton;
|
||||
|
||||
public:
|
||||
explicit DlgLoadDeckFromClipboard(QWidget *parent = nullptr);
|
||||
DeckLoader *getDeckList() const
|
||||
{
|
||||
return deckList;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
45
cockatrice/src/dialogs/dlg_load_remote_deck.cpp
Normal file
45
cockatrice/src/dialogs/dlg_load_remote_deck.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#include "dlg_load_remote_deck.h"
|
||||
|
||||
#include "../main.h"
|
||||
#include "../server/remote/remote_decklist_tree_widget.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
DlgLoadRemoteDeck::DlgLoadRemoteDeck(AbstractClient *_client, QWidget *parent) : QDialog(parent), client(_client)
|
||||
{
|
||||
dirView = new RemoteDeckList_TreeWidget(client);
|
||||
|
||||
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addWidget(dirView);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Load deck"));
|
||||
setMinimumWidth(sizeHint().width());
|
||||
resize(400, 600);
|
||||
|
||||
connect(dirView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this,
|
||||
SLOT(currentItemChanged(const QModelIndex &, const QModelIndex &)));
|
||||
}
|
||||
|
||||
void DlgLoadRemoteDeck::currentItemChanged(const QModelIndex ¤t, const QModelIndex & /*previous*/)
|
||||
{
|
||||
buttonBox->button(QDialogButtonBox::Ok)
|
||||
->setEnabled(dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(dirView->getNode(current)));
|
||||
}
|
||||
|
||||
int DlgLoadRemoteDeck::getDeckId() const
|
||||
{
|
||||
return dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(
|
||||
dirView->getNode(dirView->selectionModel()->currentIndex()))
|
||||
->getId();
|
||||
}
|
||||
27
cockatrice/src/dialogs/dlg_load_remote_deck.h
Normal file
27
cockatrice/src/dialogs/dlg_load_remote_deck.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef DLG_STARTGAME_H
|
||||
#define DLG_STARTGAME_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class RemoteDeckList_TreeWidget;
|
||||
class QModelIndex;
|
||||
class AbstractClient;
|
||||
class QPushButton;
|
||||
class QDialogButtonBox;
|
||||
|
||||
class DlgLoadRemoteDeck : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
AbstractClient *client;
|
||||
RemoteDeckList_TreeWidget *dirView;
|
||||
QDialogButtonBox *buttonBox;
|
||||
private slots:
|
||||
void currentItemChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
|
||||
public:
|
||||
DlgLoadRemoteDeck(AbstractClient *_client, QWidget *parent = nullptr);
|
||||
int getDeckId() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
459
cockatrice/src/dialogs/dlg_manage_sets.cpp
Normal file
459
cockatrice/src/dialogs/dlg_manage_sets.cpp
Normal file
|
|
@ -0,0 +1,459 @@
|
|||
#include "dlg_manage_sets.h"
|
||||
|
||||
#include "../client/network/sets_model.h"
|
||||
#include "../client/ui/picture_loader.h"
|
||||
#include "../deck/custom_line_edit.h"
|
||||
#include "../main.h"
|
||||
#include "../settings/cache_settings.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QItemSelection>
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QToolBar>
|
||||
#include <QTreeView>
|
||||
#include <algorithm>
|
||||
|
||||
#define SORT_RESET -1
|
||||
|
||||
WndSets::WndSets(QWidget *parent) : QMainWindow(parent)
|
||||
{
|
||||
setOrderIsSorted = false;
|
||||
|
||||
// left toolbar
|
||||
setsEditToolBar = new QToolBar;
|
||||
setsEditToolBar->setOrientation(Qt::Vertical);
|
||||
setsEditToolBar->setIconSize(QSize(24, 24));
|
||||
setsEditToolBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
|
||||
aTop = new QAction(QString(), this);
|
||||
aTop->setIcon(QPixmap("theme:icons/arrow_top_green"));
|
||||
aTop->setToolTip(tr("Move selected set to the top"));
|
||||
aTop->setEnabled(false);
|
||||
connect(aTop, SIGNAL(triggered()), this, SLOT(actTop()));
|
||||
setsEditToolBar->addAction(aTop);
|
||||
|
||||
aUp = new QAction(QString(), this);
|
||||
aUp->setIcon(QPixmap("theme:icons/arrow_up_green"));
|
||||
aUp->setToolTip(tr("Move selected set up"));
|
||||
aUp->setEnabled(false);
|
||||
connect(aUp, SIGNAL(triggered()), this, SLOT(actUp()));
|
||||
setsEditToolBar->addAction(aUp);
|
||||
|
||||
aDown = new QAction(QString(), this);
|
||||
aDown->setIcon(QPixmap("theme:icons/arrow_down_green"));
|
||||
aDown->setToolTip(tr("Move selected set down"));
|
||||
aDown->setEnabled(false);
|
||||
connect(aDown, SIGNAL(triggered()), this, SLOT(actDown()));
|
||||
setsEditToolBar->addAction(aDown);
|
||||
|
||||
aBottom = new QAction(QString(), this);
|
||||
aBottom->setIcon(QPixmap("theme:icons/arrow_bottom_green"));
|
||||
aBottom->setToolTip(tr("Move selected set to the bottom"));
|
||||
aBottom->setEnabled(false);
|
||||
connect(aBottom, SIGNAL(triggered()), this, SLOT(actBottom()));
|
||||
setsEditToolBar->addAction(aBottom);
|
||||
|
||||
// search field
|
||||
searchField = new LineEditUnfocusable;
|
||||
searchField->setObjectName("searchEdit");
|
||||
searchField->setPlaceholderText(tr("Search by set name, code, or type"));
|
||||
searchField->addAction(QPixmap("theme:icons/search"), LineEditUnfocusable::LeadingPosition);
|
||||
searchField->setClearButtonEnabled(true);
|
||||
setFocusProxy(searchField);
|
||||
|
||||
defaultSortButton = new QPushButton(tr("Default order"));
|
||||
defaultSortButton->setToolTip(tr("Restore original art priority order"));
|
||||
|
||||
connect(defaultSortButton, SIGNAL(clicked()), this, SLOT(actRestoreOriginalOrder()));
|
||||
|
||||
filterBox = new QHBoxLayout;
|
||||
filterBox->addWidget(searchField);
|
||||
filterBox->addWidget(defaultSortButton);
|
||||
|
||||
// view
|
||||
model = new SetsModel(db, this);
|
||||
displayModel = new SetsDisplayModel(this);
|
||||
displayModel->setSourceModel(model);
|
||||
displayModel->setDynamicSortFilter(false);
|
||||
view = new QTreeView;
|
||||
view->setModel(displayModel);
|
||||
|
||||
view->setAlternatingRowColors(true);
|
||||
view->setUniformRowHeights(true);
|
||||
view->setAllColumnsShowFocus(true);
|
||||
view->setSortingEnabled(true);
|
||||
view->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
view->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
|
||||
view->setDragEnabled(true);
|
||||
view->setAcceptDrops(true);
|
||||
view->setDropIndicatorShown(true);
|
||||
view->setDragDropMode(QAbstractItemView::InternalMove);
|
||||
|
||||
view->sortByColumn(SetsModel::SortKeyCol, Qt::AscendingOrder);
|
||||
view->setColumnHidden(SetsModel::SortKeyCol, true);
|
||||
view->setColumnHidden(SetsModel::IsKnownCol, true);
|
||||
view->setRootIsDecorated(false);
|
||||
|
||||
connect(view->header(), SIGNAL(sectionClicked(int)), this, SLOT(actSort(int)));
|
||||
|
||||
// bottom buttons
|
||||
enableAllButton = new QPushButton(tr("Enable all sets"));
|
||||
disableAllButton = new QPushButton(tr("Disable all sets"));
|
||||
enableSomeButton = new QPushButton(tr("Enable selected set(s)"));
|
||||
disableSomeButton = new QPushButton(tr("Disable selected set(s)"));
|
||||
|
||||
connect(enableAllButton, SIGNAL(clicked()), this, SLOT(actEnableAll()));
|
||||
connect(disableAllButton, SIGNAL(clicked()), this, SLOT(actDisableAll()));
|
||||
connect(enableSomeButton, SIGNAL(clicked()), this, SLOT(actEnableSome()));
|
||||
connect(disableSomeButton, SIGNAL(clicked()), this, SLOT(actDisableSome()));
|
||||
connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this,
|
||||
SLOT(actToggleButtons(const QItemSelection &, const QItemSelection &)));
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
||||
connect(searchField, SIGNAL(textChanged(const QString &)), displayModel,
|
||||
SLOT(setFilterRegularExpression(const QString &)));
|
||||
#else
|
||||
connect(searchField, SIGNAL(textChanged(const QString &)), displayModel, SLOT(setFilterRegExp(const QString &)));
|
||||
#endif
|
||||
connect(view->header(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), this, SLOT(actDisableSortButtons(int)));
|
||||
connect(searchField, SIGNAL(textChanged(const QString &)), this, SLOT(actDisableResetButton(const QString &)));
|
||||
|
||||
labNotes = new QLabel;
|
||||
labNotes->setWordWrap(true);
|
||||
labNotes->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
labNotes->setOpenExternalLinks(true);
|
||||
labNotes->setText(tr("Use CTRL+A to select all sets in the view.") + "<br><b>" + tr("Deck Editor") + ":</b> " +
|
||||
tr("Only cards in enabled sets will appear in the card list of the deck editor.") + "<br><b>" +
|
||||
tr("Card Art") + ":</b> " + tr("Image priority is decided in the following order:") + "<br>" +
|
||||
tr("first the CUSTOM Folder (%1), then the Enabled Sets in this dialog (Top to Bottom)",
|
||||
"%1 is a link to the wiki")
|
||||
.arg("<a href='https://github.com/Cockatrice/Cockatrice/wiki/Custom-Cards-%26-Sets"
|
||||
"#to-add-custom-art-for-cards-the-easiest-way-is-to-use-the-custom-folder'>" +
|
||||
tr("How to use custom card art") + "</a>"));
|
||||
|
||||
QGridLayout *hintsGrid = new QGridLayout;
|
||||
hintsGrid->addWidget(labNotes, 0, 0);
|
||||
hintsGroupBox = new QGroupBox(tr("Hints"));
|
||||
hintsGroupBox->setLayout(hintsGrid);
|
||||
|
||||
sortWarning = new QGroupBox(tr("Note"));
|
||||
QGridLayout *sortWarningLayout = new QGridLayout;
|
||||
sortWarningText = new QLabel;
|
||||
sortWarningText->setWordWrap(true);
|
||||
sortWarningText->setText(tr("Sorting by column allows you to find a set while not changing set priority.") + " " +
|
||||
tr("To enable ordering again, click the column header until this message disappears."));
|
||||
sortWarningLayout->addWidget(sortWarningText, 0, 0, 1, 2);
|
||||
sortWarningButton = new QPushButton;
|
||||
sortWarningButton->setText(tr("Use the current sorting as the set priority instead"));
|
||||
sortWarningButton->setToolTip(tr("Sorts the set priority using the same column"));
|
||||
sortWarningButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
connect(sortWarningButton, SIGNAL(released()), this, SLOT(actIgnoreWarning()));
|
||||
sortWarningLayout->addWidget(sortWarningButton, 1, 0);
|
||||
sortWarning->setLayout(sortWarningLayout);
|
||||
sortWarning->setVisible(false);
|
||||
|
||||
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actSave()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(actRestore()));
|
||||
|
||||
mainLayout = new QGridLayout;
|
||||
mainLayout->addLayout(filterBox, 0, 1, 1, 2);
|
||||
mainLayout->addWidget(setsEditToolBar, 1, 0, 4, 1);
|
||||
mainLayout->addWidget(view, 1, 1, 1, 2);
|
||||
mainLayout->addWidget(enableAllButton, 2, 1);
|
||||
mainLayout->addWidget(disableAllButton, 2, 2);
|
||||
mainLayout->addWidget(enableSomeButton, 2, 1);
|
||||
mainLayout->addWidget(disableSomeButton, 2, 2);
|
||||
mainLayout->addWidget(sortWarning, 3, 1, 1, 2);
|
||||
mainLayout->addWidget(hintsGroupBox, 4, 1, 1, 2);
|
||||
mainLayout->addWidget(buttonBox, 5, 1, 1, 2);
|
||||
mainLayout->setColumnStretch(1, 1);
|
||||
mainLayout->setColumnStretch(2, 1);
|
||||
|
||||
enableSomeButton->hide();
|
||||
disableSomeButton->hide();
|
||||
|
||||
QWidget *centralWidget = new QWidget;
|
||||
centralWidget->setLayout(mainLayout);
|
||||
setCentralWidget(centralWidget);
|
||||
|
||||
setWindowTitle(tr("Manage sets"));
|
||||
setMinimumSize(800, 500);
|
||||
auto &geometry = SettingsCache::instance().getSetsDialogGeometry();
|
||||
if (!geometry.isEmpty()) {
|
||||
restoreGeometry(geometry);
|
||||
}
|
||||
auto &headerState = SettingsCache::instance().layouts().getSetsDialogHeaderState();
|
||||
if (!headerState.isEmpty()) {
|
||||
view->header()->restoreState(headerState);
|
||||
view->header()->setSortIndicator(SORT_RESET, Qt::DescendingOrder);
|
||||
} else {
|
||||
view->header()->resizeSections(QHeaderView::ResizeToContents);
|
||||
}
|
||||
connect(view->header(), &QHeaderView::geometriesChanged, this, &WndSets::saveHeaderState);
|
||||
}
|
||||
|
||||
WndSets::~WndSets()
|
||||
{
|
||||
}
|
||||
|
||||
void WndSets::closeEvent(QCloseEvent * /*ev*/)
|
||||
{
|
||||
SettingsCache::instance().setSetsDialogGeometry(saveGeometry());
|
||||
}
|
||||
|
||||
void WndSets::saveHeaderState()
|
||||
{
|
||||
SettingsCache::instance().layouts().setSetsDialogHeaderState(view->header()->saveState());
|
||||
}
|
||||
|
||||
void WndSets::rebuildMainLayout(int actionToTake)
|
||||
{
|
||||
if (mainLayout == nullptr)
|
||||
return;
|
||||
|
||||
switch (actionToTake) {
|
||||
case NO_SETS_SELECTED:
|
||||
enableAllButton->show();
|
||||
disableAllButton->show();
|
||||
enableSomeButton->hide();
|
||||
disableSomeButton->hide();
|
||||
break;
|
||||
|
||||
case SOME_SETS_SELECTED:
|
||||
enableAllButton->hide();
|
||||
disableAllButton->hide();
|
||||
enableSomeButton->show();
|
||||
disableSomeButton->show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void WndSets::actSave()
|
||||
{
|
||||
model->save(db);
|
||||
PictureLoader::clearPixmapCache();
|
||||
close();
|
||||
}
|
||||
|
||||
void WndSets::actRestore()
|
||||
{
|
||||
model->restore(db);
|
||||
close();
|
||||
}
|
||||
|
||||
void WndSets::actRestoreOriginalOrder()
|
||||
{
|
||||
view->header()->setSortIndicator(SORT_RESET, Qt::DescendingOrder);
|
||||
model->sort(model->ReleaseDateCol, Qt::DescendingOrder);
|
||||
sortWarning->setVisible(false);
|
||||
}
|
||||
|
||||
void WndSets::actDisableResetButton(const QString &filterString)
|
||||
{
|
||||
if (filterString.isEmpty()) {
|
||||
defaultSortButton->setEnabled(true);
|
||||
} else {
|
||||
defaultSortButton->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void WndSets::actSort(int index)
|
||||
{
|
||||
if (sortIndex != index) {
|
||||
view->sortByColumn(index, Qt::AscendingOrder);
|
||||
sortOrder = Qt::AscendingOrder;
|
||||
sortIndex = index;
|
||||
sortWarning->setVisible(true);
|
||||
} else {
|
||||
if (sortOrder == Qt::AscendingOrder) {
|
||||
view->sortByColumn(index, Qt::DescendingOrder);
|
||||
sortOrder = Qt::DescendingOrder;
|
||||
sortIndex = index;
|
||||
sortWarning->setVisible(true);
|
||||
} else {
|
||||
view->header()->setSortIndicator(SORT_RESET, Qt::DescendingOrder);
|
||||
sortIndex = -1;
|
||||
sortWarning->setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WndSets::actIgnoreWarning()
|
||||
{
|
||||
if (sortIndex < 0) {
|
||||
return;
|
||||
}
|
||||
model->sort(sortIndex, sortOrder);
|
||||
view->header()->setSortIndicator(SORT_RESET, Qt::DescendingOrder);
|
||||
sortIndex = -1;
|
||||
sortWarning->setVisible(false);
|
||||
}
|
||||
|
||||
void WndSets::actDisableSortButtons(int index)
|
||||
{
|
||||
if (index != SORT_RESET) {
|
||||
view->setDragEnabled(false);
|
||||
setOrderIsSorted = true;
|
||||
} else {
|
||||
setOrderIsSorted = false;
|
||||
view->setDragEnabled(true);
|
||||
}
|
||||
if (!view->selectionModel()->selection().empty()) {
|
||||
view->scrollTo(view->selectionModel()->selectedRows().first());
|
||||
}
|
||||
actToggleButtons(view->selectionModel()->selection(), QItemSelection());
|
||||
}
|
||||
|
||||
void WndSets::actToggleButtons(const QItemSelection &selected, const QItemSelection &)
|
||||
{
|
||||
bool emptySelection = selected.empty();
|
||||
aTop->setDisabled(emptySelection || setOrderIsSorted);
|
||||
aUp->setDisabled(emptySelection || setOrderIsSorted);
|
||||
aDown->setDisabled(emptySelection || setOrderIsSorted);
|
||||
aBottom->setDisabled(emptySelection || setOrderIsSorted);
|
||||
|
||||
int rows = view->selectionModel()->selectedRows().size();
|
||||
rebuildMainLayout((rows > 1) ? SOME_SETS_SELECTED : NO_SETS_SELECTED);
|
||||
}
|
||||
|
||||
void WndSets::selectRows(QSet<int> rows)
|
||||
{
|
||||
for (auto i : rows) {
|
||||
QModelIndex idx = model->index(i, 0);
|
||||
view->selectionModel()->select(idx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||
view->scrollTo(idx, QAbstractItemView::EnsureVisible);
|
||||
}
|
||||
}
|
||||
|
||||
void WndSets::actEnableAll()
|
||||
{
|
||||
model->toggleAll(true);
|
||||
}
|
||||
|
||||
void WndSets::actDisableAll()
|
||||
{
|
||||
model->toggleAll(false);
|
||||
}
|
||||
|
||||
void WndSets::actEnableSome()
|
||||
{
|
||||
QModelIndexList rows = view->selectionModel()->selectedRows();
|
||||
|
||||
for (auto i : rows) {
|
||||
model->toggleRow(displayModel->mapToSource(i).row(), true);
|
||||
}
|
||||
}
|
||||
|
||||
void WndSets::actDisableSome()
|
||||
{
|
||||
QModelIndexList rows = view->selectionModel()->selectedRows();
|
||||
|
||||
for (auto i : rows) {
|
||||
model->toggleRow(displayModel->mapToSource(i).row(), false);
|
||||
}
|
||||
}
|
||||
|
||||
void WndSets::actUp()
|
||||
{
|
||||
QModelIndexList rows = view->selectionModel()->selectedRows();
|
||||
std::sort(rows.begin(), rows.end(), std::less<QModelIndex>());
|
||||
QSet<int> newRows;
|
||||
|
||||
if (rows.empty())
|
||||
return;
|
||||
|
||||
for (auto i : rows) {
|
||||
if (i.row() <= 0)
|
||||
continue;
|
||||
int oldRow = displayModel->mapToSource(i).row();
|
||||
int newRow = i.row() - 1;
|
||||
|
||||
model->swapRows(oldRow, displayModel->mapToSource(displayModel->index(newRow, 0)).row());
|
||||
newRows.insert(newRow);
|
||||
}
|
||||
|
||||
selectRows(newRows);
|
||||
}
|
||||
|
||||
void WndSets::actDown()
|
||||
{
|
||||
QModelIndexList rows = view->selectionModel()->selectedRows();
|
||||
// QModelIndex only implements operator<, so we can't use std::greater
|
||||
std::sort(rows.begin(), rows.end(), [](const QModelIndex &a, const QModelIndex &b) { return b < a; });
|
||||
QSet<int> newRows;
|
||||
|
||||
if (rows.empty())
|
||||
return;
|
||||
|
||||
for (auto i : rows) {
|
||||
if (i.row() >= displayModel->rowCount() - 1)
|
||||
continue;
|
||||
int oldRow = displayModel->mapToSource(i).row();
|
||||
int newRow = i.row() + 1;
|
||||
|
||||
model->swapRows(oldRow, displayModel->mapToSource(displayModel->index(newRow, 0)).row());
|
||||
newRows.insert(newRow);
|
||||
}
|
||||
|
||||
selectRows(newRows);
|
||||
}
|
||||
|
||||
void WndSets::actTop()
|
||||
{
|
||||
QModelIndexList rows = view->selectionModel()->selectedRows();
|
||||
std::sort(rows.begin(), rows.end(), std::less<QModelIndex>());
|
||||
QSet<int> newRows;
|
||||
int newRow = 0;
|
||||
|
||||
if (rows.empty())
|
||||
return;
|
||||
|
||||
for (int i = 0; i < rows.length(); i++) {
|
||||
int oldRow = displayModel->mapToSource(rows.at(i)).row();
|
||||
|
||||
if (oldRow <= 0) {
|
||||
newRow++;
|
||||
continue;
|
||||
}
|
||||
|
||||
newRows.insert(newRow);
|
||||
model->swapRows(oldRow, newRow++);
|
||||
}
|
||||
|
||||
selectRows(newRows);
|
||||
}
|
||||
|
||||
void WndSets::actBottom()
|
||||
{
|
||||
QModelIndexList rows = view->selectionModel()->selectedRows();
|
||||
// QModelIndex only implements operator<, so we can't use std::greater
|
||||
std::sort(rows.begin(), rows.end(), [](const QModelIndex &a, const QModelIndex &b) { return b < a; });
|
||||
QSet<int> newRows;
|
||||
int newRow = model->rowCount() - 1;
|
||||
|
||||
if (rows.empty())
|
||||
return;
|
||||
|
||||
for (int i = 0; i < rows.length(); i++) {
|
||||
int oldRow = displayModel->mapToSource(rows.at(i)).row();
|
||||
|
||||
if (oldRow >= newRow) {
|
||||
newRow--;
|
||||
continue;
|
||||
}
|
||||
|
||||
newRows.insert(newRow);
|
||||
model->swapRows(oldRow, newRow--);
|
||||
}
|
||||
|
||||
selectRows(newRows);
|
||||
}
|
||||
78
cockatrice/src/dialogs/dlg_manage_sets.h
Normal file
78
cockatrice/src/dialogs/dlg_manage_sets.h
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
#ifndef DLG_MANAGE_SETS_H
|
||||
#define DLG_MANAGE_SETS_H
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QMainWindow>
|
||||
#include <QSet>
|
||||
|
||||
class CardDatabase;
|
||||
class LineEditUnfocusable;
|
||||
class QGroupBox;
|
||||
class QItemSelection;
|
||||
class QPushButton;
|
||||
class QTreeView;
|
||||
class SetsDisplayModel;
|
||||
class SetsModel;
|
||||
class SetsProxyModel;
|
||||
|
||||
class WndSets : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
SetsModel *model;
|
||||
SetsDisplayModel *displayModel;
|
||||
QGroupBox *hintsGroupBox;
|
||||
QTreeView *view;
|
||||
QPushButton *toggleAllButton, *toggleSelectedButton;
|
||||
QPushButton *enableAllButton, *disableAllButton, *enableSomeButton, *disableSomeButton;
|
||||
QPushButton *defaultSortButton;
|
||||
QAction *aUp, *aDown, *aBottom, *aTop;
|
||||
QToolBar *setsEditToolBar;
|
||||
QDialogButtonBox *buttonBox;
|
||||
QLabel *labNotes, *searchLabel;
|
||||
QGroupBox *sortWarning;
|
||||
QLabel *sortWarningText;
|
||||
QPushButton *sortWarningButton;
|
||||
LineEditUnfocusable *searchField;
|
||||
QGridLayout *mainLayout;
|
||||
QHBoxLayout *filterBox;
|
||||
int sortIndex;
|
||||
Qt::SortOrder sortOrder;
|
||||
void closeEvent(QCloseEvent *ev) override;
|
||||
void saveHeaderState();
|
||||
void rebuildMainLayout(int actionToTake);
|
||||
bool setOrderIsSorted;
|
||||
enum
|
||||
{
|
||||
NO_SETS_SELECTED,
|
||||
SOME_SETS_SELECTED
|
||||
};
|
||||
|
||||
public:
|
||||
WndSets(QWidget *parent = nullptr);
|
||||
~WndSets();
|
||||
|
||||
protected:
|
||||
void selectRows(QSet<int> rows);
|
||||
private slots:
|
||||
void actEnableAll();
|
||||
void actDisableAll();
|
||||
void actEnableSome();
|
||||
void actDisableSome();
|
||||
void actSave();
|
||||
void actRestore();
|
||||
void actUp();
|
||||
void actDown();
|
||||
void actTop();
|
||||
void actBottom();
|
||||
void actToggleButtons(const QItemSelection &selected, const QItemSelection &deselected);
|
||||
void actDisableSortButtons(int index);
|
||||
void actRestoreOriginalOrder();
|
||||
void actDisableResetButton(const QString &filterText);
|
||||
void actSort(int index);
|
||||
void actIgnoreWarning();
|
||||
};
|
||||
|
||||
#endif
|
||||
379
cockatrice/src/dialogs/dlg_register.cpp
Normal file
379
cockatrice/src/dialogs/dlg_register.cpp
Normal file
|
|
@ -0,0 +1,379 @@
|
|||
#include "dlg_register.h"
|
||||
|
||||
#include "../settings/cache_settings.h"
|
||||
#include "pb/serverinfo_user.pb.h"
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QDebug>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
|
||||
DlgRegister::DlgRegister(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
ServersSettings &servers = SettingsCache::instance().servers();
|
||||
infoLabel = new QLabel(tr("Enter your information and the information of the server you'd like to register to.\n"
|
||||
"Your email will be used to verify your account."));
|
||||
infoLabel->setWordWrap(true);
|
||||
|
||||
hostLabel = new QLabel(tr("&Host:"));
|
||||
hostEdit = new QLineEdit(servers.getHostname());
|
||||
hostEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
hostLabel->setBuddy(hostEdit);
|
||||
|
||||
portLabel = new QLabel(tr("&Port:"));
|
||||
portEdit = new QLineEdit(servers.getPort());
|
||||
portEdit->setValidator(new QIntValidator(0, 0xffff, portEdit));
|
||||
portLabel->setBuddy(portEdit);
|
||||
|
||||
playernameLabel = new QLabel(tr("Player &name:"));
|
||||
playernameEdit = new QLineEdit(servers.getPlayerName());
|
||||
playernameEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
playernameLabel->setBuddy(playernameEdit);
|
||||
|
||||
passwordLabel = new QLabel(tr("P&assword:"));
|
||||
passwordEdit = new QLineEdit();
|
||||
passwordEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
passwordLabel->setBuddy(passwordEdit);
|
||||
passwordEdit->setEchoMode(QLineEdit::Password);
|
||||
|
||||
passwordConfirmationLabel = new QLabel(tr("Password (again):"));
|
||||
passwordConfirmationEdit = new QLineEdit();
|
||||
passwordConfirmationEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
passwordConfirmationLabel->setBuddy(passwordConfirmationEdit);
|
||||
passwordConfirmationEdit->setEchoMode(QLineEdit::Password);
|
||||
|
||||
emailLabel = new QLabel(tr("Email:"));
|
||||
emailEdit = new QLineEdit();
|
||||
emailEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
emailLabel->setBuddy(emailEdit);
|
||||
|
||||
emailConfirmationLabel = new QLabel(tr("Email (again):"));
|
||||
emailConfirmationEdit = new QLineEdit();
|
||||
emailConfirmationEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
emailConfirmationLabel->setBuddy(emailConfirmationEdit);
|
||||
|
||||
countryLabel = new QLabel(tr("Country:"));
|
||||
countryEdit = new QComboBox();
|
||||
countryLabel->setBuddy(countryEdit);
|
||||
countryEdit->insertItem(0, tr("Undefined"));
|
||||
countryEdit->addItem(QPixmap("theme:countries/ad"), "ad");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ae"), "ae");
|
||||
countryEdit->addItem(QPixmap("theme:countries/af"), "af");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ag"), "ag");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ai"), "ai");
|
||||
countryEdit->addItem(QPixmap("theme:countries/al"), "al");
|
||||
countryEdit->addItem(QPixmap("theme:countries/am"), "am");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ao"), "ao");
|
||||
countryEdit->addItem(QPixmap("theme:countries/aq"), "aq");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ar"), "ar");
|
||||
countryEdit->addItem(QPixmap("theme:countries/as"), "as");
|
||||
countryEdit->addItem(QPixmap("theme:countries/at"), "at");
|
||||
countryEdit->addItem(QPixmap("theme:countries/au"), "au");
|
||||
countryEdit->addItem(QPixmap("theme:countries/aw"), "aw");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ax"), "ax");
|
||||
countryEdit->addItem(QPixmap("theme:countries/az"), "az");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ba"), "ba");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bb"), "bb");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bd"), "bd");
|
||||
countryEdit->addItem(QPixmap("theme:countries/be"), "be");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bf"), "bf");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bg"), "bg");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bh"), "bh");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bi"), "bi");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bj"), "bj");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bl"), "bl");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bm"), "bm");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bn"), "bn");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bo"), "bo");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bq"), "bq");
|
||||
countryEdit->addItem(QPixmap("theme:countries/br"), "br");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bs"), "bs");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bt"), "bt");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bv"), "bv");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bw"), "bw");
|
||||
countryEdit->addItem(QPixmap("theme:countries/by"), "by");
|
||||
countryEdit->addItem(QPixmap("theme:countries/bz"), "bz");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ca"), "ca");
|
||||
countryEdit->addItem(QPixmap("theme:countries/cc"), "cc");
|
||||
countryEdit->addItem(QPixmap("theme:countries/cd"), "cd");
|
||||
countryEdit->addItem(QPixmap("theme:countries/cf"), "cf");
|
||||
countryEdit->addItem(QPixmap("theme:countries/cg"), "cg");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ch"), "ch");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ci"), "ci");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ck"), "ck");
|
||||
countryEdit->addItem(QPixmap("theme:countries/cl"), "cl");
|
||||
countryEdit->addItem(QPixmap("theme:countries/cm"), "cm");
|
||||
countryEdit->addItem(QPixmap("theme:countries/cn"), "cn");
|
||||
countryEdit->addItem(QPixmap("theme:countries/co"), "co");
|
||||
countryEdit->addItem(QPixmap("theme:countries/cr"), "cr");
|
||||
countryEdit->addItem(QPixmap("theme:countries/cu"), "cu");
|
||||
countryEdit->addItem(QPixmap("theme:countries/cv"), "cv");
|
||||
countryEdit->addItem(QPixmap("theme:countries/cw"), "cw");
|
||||
countryEdit->addItem(QPixmap("theme:countries/cx"), "cx");
|
||||
countryEdit->addItem(QPixmap("theme:countries/cy"), "cy");
|
||||
countryEdit->addItem(QPixmap("theme:countries/cz"), "cz");
|
||||
countryEdit->addItem(QPixmap("theme:countries/de"), "de");
|
||||
countryEdit->addItem(QPixmap("theme:countries/dj"), "dj");
|
||||
countryEdit->addItem(QPixmap("theme:countries/dk"), "dk");
|
||||
countryEdit->addItem(QPixmap("theme:countries/dm"), "dm");
|
||||
countryEdit->addItem(QPixmap("theme:countries/do"), "do");
|
||||
countryEdit->addItem(QPixmap("theme:countries/dz"), "dz");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ec"), "ec");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ee"), "ee");
|
||||
countryEdit->addItem(QPixmap("theme:countries/eg"), "eg");
|
||||
countryEdit->addItem(QPixmap("theme:countries/eh"), "eh");
|
||||
countryEdit->addItem(QPixmap("theme:countries/er"), "er");
|
||||
countryEdit->addItem(QPixmap("theme:countries/es"), "es");
|
||||
countryEdit->addItem(QPixmap("theme:countries/et"), "et");
|
||||
countryEdit->addItem(QPixmap("theme:countries/eu"), "eu");
|
||||
countryEdit->addItem(QPixmap("theme:countries/fi"), "fi");
|
||||
countryEdit->addItem(QPixmap("theme:countries/fj"), "fj");
|
||||
countryEdit->addItem(QPixmap("theme:countries/fk"), "fk");
|
||||
countryEdit->addItem(QPixmap("theme:countries/fm"), "fm");
|
||||
countryEdit->addItem(QPixmap("theme:countries/fo"), "fo");
|
||||
countryEdit->addItem(QPixmap("theme:countries/fr"), "fr");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ga"), "ga");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gb"), "gb");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gd"), "gd");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ge"), "ge");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gf"), "gf");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gg"), "gg");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gh"), "gh");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gi"), "gi");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gl"), "gl");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gm"), "gm");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gn"), "gn");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gp"), "gp");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gq"), "gq");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gr"), "gr");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gs"), "gs");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gt"), "gt");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gu"), "gu");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gw"), "gw");
|
||||
countryEdit->addItem(QPixmap("theme:countries/gy"), "gy");
|
||||
countryEdit->addItem(QPixmap("theme:countries/hk"), "hk");
|
||||
countryEdit->addItem(QPixmap("theme:countries/hm"), "hm");
|
||||
countryEdit->addItem(QPixmap("theme:countries/hn"), "hn");
|
||||
countryEdit->addItem(QPixmap("theme:countries/hr"), "hr");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ht"), "ht");
|
||||
countryEdit->addItem(QPixmap("theme:countries/hu"), "hu");
|
||||
countryEdit->addItem(QPixmap("theme:countries/id"), "id");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ie"), "ie");
|
||||
countryEdit->addItem(QPixmap("theme:countries/il"), "il");
|
||||
countryEdit->addItem(QPixmap("theme:countries/im"), "im");
|
||||
countryEdit->addItem(QPixmap("theme:countries/in"), "in");
|
||||
countryEdit->addItem(QPixmap("theme:countries/io"), "io");
|
||||
countryEdit->addItem(QPixmap("theme:countries/iq"), "iq");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ir"), "ir");
|
||||
countryEdit->addItem(QPixmap("theme:countries/is"), "is");
|
||||
countryEdit->addItem(QPixmap("theme:countries/it"), "it");
|
||||
countryEdit->addItem(QPixmap("theme:countries/je"), "je");
|
||||
countryEdit->addItem(QPixmap("theme:countries/jm"), "jm");
|
||||
countryEdit->addItem(QPixmap("theme:countries/jo"), "jo");
|
||||
countryEdit->addItem(QPixmap("theme:countries/jp"), "jp");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ke"), "ke");
|
||||
countryEdit->addItem(QPixmap("theme:countries/kg"), "kg");
|
||||
countryEdit->addItem(QPixmap("theme:countries/kh"), "kh");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ki"), "ki");
|
||||
countryEdit->addItem(QPixmap("theme:countries/km"), "km");
|
||||
countryEdit->addItem(QPixmap("theme:countries/kn"), "kn");
|
||||
countryEdit->addItem(QPixmap("theme:countries/kp"), "kp");
|
||||
countryEdit->addItem(QPixmap("theme:countries/kr"), "kr");
|
||||
countryEdit->addItem(QPixmap("theme:countries/kw"), "kw");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ky"), "ky");
|
||||
countryEdit->addItem(QPixmap("theme:countries/kz"), "kz");
|
||||
countryEdit->addItem(QPixmap("theme:countries/la"), "la");
|
||||
countryEdit->addItem(QPixmap("theme:countries/lb"), "lb");
|
||||
countryEdit->addItem(QPixmap("theme:countries/lc"), "lc");
|
||||
countryEdit->addItem(QPixmap("theme:countries/li"), "li");
|
||||
countryEdit->addItem(QPixmap("theme:countries/lk"), "lk");
|
||||
countryEdit->addItem(QPixmap("theme:countries/lr"), "lr");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ls"), "ls");
|
||||
countryEdit->addItem(QPixmap("theme:countries/lt"), "lt");
|
||||
countryEdit->addItem(QPixmap("theme:countries/lu"), "lu");
|
||||
countryEdit->addItem(QPixmap("theme:countries/lv"), "lv");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ly"), "ly");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ma"), "ma");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mc"), "mc");
|
||||
countryEdit->addItem(QPixmap("theme:countries/md"), "md");
|
||||
countryEdit->addItem(QPixmap("theme:countries/me"), "me");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mf"), "mf");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mg"), "mg");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mh"), "mh");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mk"), "mk");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ml"), "ml");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mm"), "mm");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mn"), "mn");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mo"), "mo");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mp"), "mp");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mq"), "mq");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mr"), "mr");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ms"), "ms");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mt"), "mt");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mu"), "mu");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mv"), "mv");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mw"), "mw");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mx"), "mx");
|
||||
countryEdit->addItem(QPixmap("theme:countries/my"), "my");
|
||||
countryEdit->addItem(QPixmap("theme:countries/mz"), "mz");
|
||||
countryEdit->addItem(QPixmap("theme:countries/na"), "na");
|
||||
countryEdit->addItem(QPixmap("theme:countries/nc"), "nc");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ne"), "ne");
|
||||
countryEdit->addItem(QPixmap("theme:countries/nf"), "nf");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ng"), "ng");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ni"), "ni");
|
||||
countryEdit->addItem(QPixmap("theme:countries/nl"), "nl");
|
||||
countryEdit->addItem(QPixmap("theme:countries/no"), "no");
|
||||
countryEdit->addItem(QPixmap("theme:countries/np"), "np");
|
||||
countryEdit->addItem(QPixmap("theme:countries/nr"), "nr");
|
||||
countryEdit->addItem(QPixmap("theme:countries/nu"), "nu");
|
||||
countryEdit->addItem(QPixmap("theme:countries/nz"), "nz");
|
||||
countryEdit->addItem(QPixmap("theme:countries/om"), "om");
|
||||
countryEdit->addItem(QPixmap("theme:countries/pa"), "pa");
|
||||
countryEdit->addItem(QPixmap("theme:countries/pe"), "pe");
|
||||
countryEdit->addItem(QPixmap("theme:countries/pf"), "pf");
|
||||
countryEdit->addItem(QPixmap("theme:countries/pg"), "pg");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ph"), "ph");
|
||||
countryEdit->addItem(QPixmap("theme:countries/pk"), "pk");
|
||||
countryEdit->addItem(QPixmap("theme:countries/pl"), "pl");
|
||||
countryEdit->addItem(QPixmap("theme:countries/pm"), "pm");
|
||||
countryEdit->addItem(QPixmap("theme:countries/pn"), "pn");
|
||||
countryEdit->addItem(QPixmap("theme:countries/pr"), "pr");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ps"), "ps");
|
||||
countryEdit->addItem(QPixmap("theme:countries/pt"), "pt");
|
||||
countryEdit->addItem(QPixmap("theme:countries/pw"), "pw");
|
||||
countryEdit->addItem(QPixmap("theme:countries/py"), "py");
|
||||
countryEdit->addItem(QPixmap("theme:countries/qa"), "qa");
|
||||
countryEdit->addItem(QPixmap("theme:countries/re"), "re");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ro"), "ro");
|
||||
countryEdit->addItem(QPixmap("theme:countries/rs"), "rs");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ru"), "ru");
|
||||
countryEdit->addItem(QPixmap("theme:countries/rw"), "rw");
|
||||
countryEdit->addItem(QPixmap("theme:countries/sa"), "sa");
|
||||
countryEdit->addItem(QPixmap("theme:countries/sb"), "sb");
|
||||
countryEdit->addItem(QPixmap("theme:countries/sc"), "sc");
|
||||
countryEdit->addItem(QPixmap("theme:countries/sd"), "sd");
|
||||
countryEdit->addItem(QPixmap("theme:countries/se"), "se");
|
||||
countryEdit->addItem(QPixmap("theme:countries/sg"), "sg");
|
||||
countryEdit->addItem(QPixmap("theme:countries/sh"), "sh");
|
||||
countryEdit->addItem(QPixmap("theme:countries/si"), "si");
|
||||
countryEdit->addItem(QPixmap("theme:countries/sj"), "sj");
|
||||
countryEdit->addItem(QPixmap("theme:countries/sk"), "sk");
|
||||
countryEdit->addItem(QPixmap("theme:countries/sl"), "sl");
|
||||
countryEdit->addItem(QPixmap("theme:countries/sm"), "sm");
|
||||
countryEdit->addItem(QPixmap("theme:countries/sn"), "sn");
|
||||
countryEdit->addItem(QPixmap("theme:countries/so"), "so");
|
||||
countryEdit->addItem(QPixmap("theme:countries/sr"), "sr");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ss"), "ss");
|
||||
countryEdit->addItem(QPixmap("theme:countries/st"), "st");
|
||||
countryEdit->addItem(QPixmap("theme:countries/sv"), "sv");
|
||||
countryEdit->addItem(QPixmap("theme:countries/sx"), "sx");
|
||||
countryEdit->addItem(QPixmap("theme:countries/sy"), "sy");
|
||||
countryEdit->addItem(QPixmap("theme:countries/sz"), "sz");
|
||||
countryEdit->addItem(QPixmap("theme:countries/tc"), "tc");
|
||||
countryEdit->addItem(QPixmap("theme:countries/td"), "td");
|
||||
countryEdit->addItem(QPixmap("theme:countries/tf"), "tf");
|
||||
countryEdit->addItem(QPixmap("theme:countries/tg"), "tg");
|
||||
countryEdit->addItem(QPixmap("theme:countries/th"), "th");
|
||||
countryEdit->addItem(QPixmap("theme:countries/tj"), "tj");
|
||||
countryEdit->addItem(QPixmap("theme:countries/tk"), "tk");
|
||||
countryEdit->addItem(QPixmap("theme:countries/tl"), "tl");
|
||||
countryEdit->addItem(QPixmap("theme:countries/tm"), "tm");
|
||||
countryEdit->addItem(QPixmap("theme:countries/tn"), "tn");
|
||||
countryEdit->addItem(QPixmap("theme:countries/to"), "to");
|
||||
countryEdit->addItem(QPixmap("theme:countries/tr"), "tr");
|
||||
countryEdit->addItem(QPixmap("theme:countries/tt"), "tt");
|
||||
countryEdit->addItem(QPixmap("theme:countries/tv"), "tv");
|
||||
countryEdit->addItem(QPixmap("theme:countries/tw"), "tw");
|
||||
countryEdit->addItem(QPixmap("theme:countries/tz"), "tz");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ua"), "ua");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ug"), "ug");
|
||||
countryEdit->addItem(QPixmap("theme:countries/um"), "um");
|
||||
countryEdit->addItem(QPixmap("theme:countries/us"), "us");
|
||||
countryEdit->addItem(QPixmap("theme:countries/uy"), "uy");
|
||||
countryEdit->addItem(QPixmap("theme:countries/uz"), "uz");
|
||||
countryEdit->addItem(QPixmap("theme:countries/va"), "va");
|
||||
countryEdit->addItem(QPixmap("theme:countries/vc"), "vc");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ve"), "ve");
|
||||
countryEdit->addItem(QPixmap("theme:countries/vg"), "vg");
|
||||
countryEdit->addItem(QPixmap("theme:countries/vi"), "vi");
|
||||
countryEdit->addItem(QPixmap("theme:countries/vn"), "vn");
|
||||
countryEdit->addItem(QPixmap("theme:countries/vu"), "vu");
|
||||
countryEdit->addItem(QPixmap("theme:countries/wf"), "wf");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ws"), "ws");
|
||||
countryEdit->addItem(QPixmap("theme:countries/xk"), "xk");
|
||||
countryEdit->addItem(QPixmap("theme:countries/ye"), "ye");
|
||||
countryEdit->addItem(QPixmap("theme:countries/yt"), "yt");
|
||||
countryEdit->addItem(QPixmap("theme:countries/za"), "za");
|
||||
countryEdit->addItem(QPixmap("theme:countries/zm"), "zm");
|
||||
countryEdit->addItem(QPixmap("theme:countries/zw"), "zw");
|
||||
countryEdit->setCurrentIndex(0);
|
||||
QStringList countries = SettingsCache::instance().getCountries();
|
||||
foreach (QString c, countries)
|
||||
countryEdit->addItem(QPixmap("theme:countries/" + c.toLower()), c);
|
||||
|
||||
realnameLabel = new QLabel(tr("Real name:"));
|
||||
realnameEdit = new QLineEdit();
|
||||
realnameEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
realnameLabel->setBuddy(realnameEdit);
|
||||
|
||||
QGridLayout *grid = new QGridLayout;
|
||||
grid->addWidget(infoLabel, 0, 0, 1, 2);
|
||||
grid->addWidget(hostLabel, 1, 0);
|
||||
grid->addWidget(hostEdit, 1, 1);
|
||||
grid->addWidget(portLabel, 2, 0);
|
||||
grid->addWidget(portEdit, 2, 1);
|
||||
grid->addWidget(playernameLabel, 3, 0);
|
||||
grid->addWidget(playernameEdit, 3, 1);
|
||||
grid->addWidget(passwordLabel, 4, 0);
|
||||
grid->addWidget(passwordEdit, 4, 1);
|
||||
grid->addWidget(passwordConfirmationLabel, 5, 0);
|
||||
grid->addWidget(passwordConfirmationEdit, 5, 1);
|
||||
grid->addWidget(emailLabel, 6, 0);
|
||||
grid->addWidget(emailEdit, 6, 1);
|
||||
grid->addWidget(emailConfirmationLabel, 7, 0);
|
||||
grid->addWidget(emailConfirmationEdit, 7, 1);
|
||||
grid->addWidget(countryLabel, 9, 0);
|
||||
grid->addWidget(countryEdit, 9, 1);
|
||||
grid->addWidget(realnameLabel, 10, 0);
|
||||
grid->addWidget(realnameEdit, 10, 1);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(grid);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Register to server"));
|
||||
setFixedHeight(sizeHint().height());
|
||||
setMinimumWidth(300);
|
||||
}
|
||||
|
||||
void DlgRegister::actOk()
|
||||
{
|
||||
// TODO this stuff should be using qvalidators
|
||||
if (passwordEdit->text().length() < 8) {
|
||||
QMessageBox::critical(this, tr("Registration Warning"), tr("Your password is too short."));
|
||||
return;
|
||||
} else if (passwordEdit->text() != passwordConfirmationEdit->text()) {
|
||||
QMessageBox::critical(this, tr("Registration Warning"), tr("Your passwords do not match, please try again."));
|
||||
return;
|
||||
} else if (emailConfirmationEdit->text() != emailEdit->text()) {
|
||||
QMessageBox::critical(this, tr("Registration Warning"),
|
||||
tr("Your email addresses do not match, please try again."));
|
||||
return;
|
||||
}
|
||||
if (playernameEdit->text().isEmpty()) {
|
||||
QMessageBox::critical(this, tr("Registration Warning"), tr("The player name can't be empty."));
|
||||
return;
|
||||
}
|
||||
|
||||
accept();
|
||||
}
|
||||
56
cockatrice/src/dialogs/dlg_register.h
Normal file
56
cockatrice/src/dialogs/dlg_register.h
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#ifndef DLG_REGISTER_H
|
||||
#define DLG_REGISTER_H
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QCheckBox;
|
||||
|
||||
class DlgRegister : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DlgRegister(QWidget *parent = nullptr);
|
||||
QString getHost() const
|
||||
{
|
||||
return hostEdit->text();
|
||||
}
|
||||
int getPort() const
|
||||
{
|
||||
return portEdit->text().toInt();
|
||||
}
|
||||
QString getPlayerName() const
|
||||
{
|
||||
return playernameEdit->text();
|
||||
}
|
||||
QString getPassword() const
|
||||
{
|
||||
return passwordEdit->text();
|
||||
}
|
||||
QString getEmail() const
|
||||
{
|
||||
return emailEdit->text();
|
||||
}
|
||||
QString getCountry() const
|
||||
{
|
||||
return countryEdit->currentIndex() == 0 ? "" : countryEdit->currentText();
|
||||
}
|
||||
QString getRealName() const
|
||||
{
|
||||
return realnameEdit->text();
|
||||
}
|
||||
private slots:
|
||||
void actOk();
|
||||
|
||||
private:
|
||||
QLabel *infoLabel, *hostLabel, *portLabel, *playernameLabel, *passwordLabel, *passwordConfirmationLabel,
|
||||
*emailLabel, *emailConfirmationLabel, *countryLabel, *realnameLabel;
|
||||
QLineEdit *hostEdit, *portEdit, *playernameEdit, *passwordEdit, *passwordConfirmationEdit, *emailEdit,
|
||||
*emailConfirmationEdit, *realnameEdit;
|
||||
QComboBox *countryEdit;
|
||||
};
|
||||
|
||||
#endif
|
||||
52
cockatrice/src/dialogs/dlg_roll_dice.cpp
Normal file
52
cockatrice/src/dialogs/dlg_roll_dice.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#include "dlg_roll_dice.h"
|
||||
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
#include <QSpinBox>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
DlgRollDice::DlgRollDice(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
numberOfSidesLabel = new QLabel(tr("Number of sides:"));
|
||||
numberOfSidesEdit = new QSpinBox(this);
|
||||
numberOfSidesEdit->setValue(DEFAULT_NUMBER_SIDES_DIE);
|
||||
numberOfSidesEdit->setRange(MINIMUM_DIE_SIDES, MAXIMUM_DIE_SIDES);
|
||||
numberOfSidesEdit->setFocus();
|
||||
numberOfSidesLabel->setBuddy(numberOfSidesEdit);
|
||||
|
||||
numberOfDiceLabel = new QLabel(tr("Number of dice:"));
|
||||
numberOfDiceEdit = new QSpinBox(this);
|
||||
numberOfDiceEdit->setValue(DEFAULT_NUMBER_DICE_TO_ROLL);
|
||||
numberOfDiceEdit->setRange(MINIMUM_DICE_TO_ROLL, MAXIMUM_DICE_TO_ROLL);
|
||||
numberOfDiceLabel->setBuddy(numberOfDiceEdit);
|
||||
|
||||
auto *grid = new QGridLayout;
|
||||
grid->addWidget(numberOfSidesLabel, 0, 0);
|
||||
grid->addWidget(numberOfSidesEdit, 0, 1);
|
||||
grid->addWidget(numberOfDiceLabel, 1, 0);
|
||||
grid->addWidget(numberOfDiceEdit, 1, 1);
|
||||
|
||||
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
|
||||
auto *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addItem(grid);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
|
||||
setLayout(mainLayout);
|
||||
setWindowTitle(tr("Roll Dice"));
|
||||
}
|
||||
|
||||
uint DlgRollDice::getDieSideCount() const
|
||||
{
|
||||
return numberOfSidesEdit->text().toUInt();
|
||||
}
|
||||
|
||||
uint DlgRollDice::getDiceToRollCount() const
|
||||
{
|
||||
return numberOfDiceEdit->text().toUInt();
|
||||
}
|
||||
26
cockatrice/src/dialogs/dlg_roll_dice.h
Normal file
26
cockatrice/src/dialogs/dlg_roll_dice.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef DLG_ROLL_DICE_H
|
||||
#define DLG_ROLL_DICE_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
#include <QSpinBox>
|
||||
|
||||
class DlgRollDice : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
static constexpr uint DEFAULT_NUMBER_SIDES_DIE = 20;
|
||||
static constexpr uint DEFAULT_NUMBER_DICE_TO_ROLL = 1;
|
||||
|
||||
QLabel *numberOfSidesLabel, *numberOfDiceLabel;
|
||||
QSpinBox *numberOfSidesEdit, *numberOfDiceEdit;
|
||||
QDialogButtonBox *buttonBox;
|
||||
|
||||
public:
|
||||
explicit DlgRollDice(QWidget *parent = nullptr);
|
||||
[[nodiscard]] uint getDieSideCount() const;
|
||||
[[nodiscard]] uint getDiceToRollCount() const;
|
||||
};
|
||||
|
||||
#endif // DLG_ROLL_DICE_H
|
||||
1503
cockatrice/src/dialogs/dlg_settings.cpp
Normal file
1503
cockatrice/src/dialogs/dlg_settings.cpp
Normal file
File diff suppressed because it is too large
Load diff
300
cockatrice/src/dialogs/dlg_settings.h
Normal file
300
cockatrice/src/dialogs/dlg_settings.h
Normal file
|
|
@ -0,0 +1,300 @@
|
|||
#ifndef DLG_SETTINGS_H
|
||||
#define DLG_SETTINGS_H
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QSpinBox>
|
||||
|
||||
class CardDatabase;
|
||||
class QCloseEvent;
|
||||
class QGridLayout;
|
||||
class QHBoxLayout;
|
||||
class QLineEdit;
|
||||
class QListWidget;
|
||||
class QListWidgetItem;
|
||||
class QRadioButton;
|
||||
class QSlider;
|
||||
class QStackedWidget;
|
||||
class QTreeWidget;
|
||||
class QTreeWidgetItem;
|
||||
class QVBoxLayout;
|
||||
class SequenceEdit;
|
||||
|
||||
class AbstractSettingsPage : public QWidget
|
||||
{
|
||||
public:
|
||||
virtual void retranslateUi() = 0;
|
||||
};
|
||||
|
||||
class GeneralSettingsPage : public AbstractSettingsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GeneralSettingsPage();
|
||||
void retranslateUi() override;
|
||||
|
||||
private slots:
|
||||
void deckPathButtonClicked();
|
||||
void replaysPathButtonClicked();
|
||||
void picsPathButtonClicked();
|
||||
void cardDatabasePathButtonClicked();
|
||||
void customCardDatabaseButtonClicked();
|
||||
void tokenDatabasePathButtonClicked();
|
||||
void resetAllPathsClicked();
|
||||
void languageBoxChanged(int index);
|
||||
|
||||
private:
|
||||
QStringList findQmFiles();
|
||||
QString languageName(const QString &lang);
|
||||
QLineEdit *deckPathEdit;
|
||||
QLineEdit *replaysPathEdit;
|
||||
QLineEdit *picsPathEdit;
|
||||
QLineEdit *cardDatabasePathEdit;
|
||||
QLineEdit *customCardDatabasePathEdit;
|
||||
QLineEdit *tokenDatabasePathEdit;
|
||||
QPushButton *resetAllPathsButton;
|
||||
QLabel *allPathsResetLabel;
|
||||
QGroupBox *personalGroupBox;
|
||||
QGroupBox *pathsGroupBox;
|
||||
QComboBox languageBox;
|
||||
QCheckBox updateNotificationCheckBox;
|
||||
QCheckBox newVersionOracleCheckBox;
|
||||
QComboBox updateReleaseChannelBox;
|
||||
QLabel languageLabel;
|
||||
QLabel deckPathLabel;
|
||||
QLabel replaysPathLabel;
|
||||
QLabel picsPathLabel;
|
||||
QLabel cardDatabasePathLabel;
|
||||
QLabel customCardDatabasePathLabel;
|
||||
QLabel tokenDatabasePathLabel;
|
||||
QLabel updateReleaseChannelLabel;
|
||||
QCheckBox showTipsOnStartup;
|
||||
};
|
||||
|
||||
class AppearanceSettingsPage : public AbstractSettingsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void themeBoxChanged(int index);
|
||||
void openThemeLocation();
|
||||
|
||||
private:
|
||||
QLabel themeLabel;
|
||||
QComboBox themeBox;
|
||||
QPushButton openThemeButton;
|
||||
QLabel minPlayersForMultiColumnLayoutLabel;
|
||||
QLabel maxFontSizeForCardsLabel;
|
||||
QCheckBox displayCardNamesCheckBox;
|
||||
QCheckBox cardScalingCheckBox;
|
||||
QLabel verticalCardOverlapPercentLabel;
|
||||
QSpinBox verticalCardOverlapPercentBox;
|
||||
QCheckBox horizontalHandCheckBox;
|
||||
QCheckBox leftJustifiedHandCheckBox;
|
||||
QCheckBox invertVerticalCoordinateCheckBox;
|
||||
QGroupBox *themeGroupBox;
|
||||
QGroupBox *cardsGroupBox;
|
||||
QGroupBox *handGroupBox;
|
||||
QGroupBox *tableGroupBox;
|
||||
QSpinBox minPlayersForMultiColumnLayoutEdit;
|
||||
QSpinBox maxFontSizeForCardsEdit;
|
||||
|
||||
public:
|
||||
AppearanceSettingsPage();
|
||||
void retranslateUi() override;
|
||||
};
|
||||
|
||||
class UserInterfaceSettingsPage : public AbstractSettingsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void setNotificationEnabled(int);
|
||||
|
||||
private:
|
||||
QCheckBox notificationsEnabledCheckBox;
|
||||
QCheckBox specNotificationsEnabledCheckBox;
|
||||
QCheckBox buddyConnectNotificationsEnabledCheckBox;
|
||||
QCheckBox doubleClickToPlayCheckBox;
|
||||
QCheckBox playToStackCheckBox;
|
||||
QCheckBox annotateTokensCheckBox;
|
||||
QCheckBox useTearOffMenusCheckBox;
|
||||
QCheckBox tapAnimationCheckBox;
|
||||
QGroupBox *generalGroupBox;
|
||||
QGroupBox *notificationsGroupBox;
|
||||
QGroupBox *animationGroupBox;
|
||||
|
||||
public:
|
||||
UserInterfaceSettingsPage();
|
||||
void retranslateUi() override;
|
||||
};
|
||||
|
||||
class DeckEditorSettingsPage : public AbstractSettingsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DeckEditorSettingsPage();
|
||||
void retranslateUi() override;
|
||||
QString getLastUpdateTime();
|
||||
|
||||
private slots:
|
||||
void storeSettings();
|
||||
void urlListChanged(const QModelIndex &, int, int, const QModelIndex &, int);
|
||||
void setSpoilersEnabled(bool);
|
||||
void spoilerPathButtonClicked();
|
||||
void updateSpoilers();
|
||||
void unlockSettings();
|
||||
void actAddURL();
|
||||
void actRemoveURL();
|
||||
void actEditURL();
|
||||
void clearDownloadedPicsButtonClicked();
|
||||
void resetDownloadedURLsButtonClicked();
|
||||
|
||||
private:
|
||||
QPushButton clearDownloadedPicsButton;
|
||||
QPushButton resetDownloadURLs;
|
||||
QLabel urlLinkLabel;
|
||||
QCheckBox picDownloadCheckBox;
|
||||
QListWidget *urlList;
|
||||
QCheckBox mcDownloadSpoilersCheckBox;
|
||||
QLabel msDownloadSpoilersLabel;
|
||||
QGroupBox *mpGeneralGroupBox;
|
||||
QGroupBox *mpSpoilerGroupBox;
|
||||
QLineEdit *mpSpoilerSavePathLineEdit;
|
||||
QLabel mcSpoilerSaveLabel;
|
||||
QLabel lastUpdatedLabel;
|
||||
QLabel infoOnSpoilersLabel;
|
||||
QPushButton *mpSpoilerPathButton;
|
||||
QPushButton *updateNowButton;
|
||||
QLabel networkCacheLabel;
|
||||
QSpinBox networkCacheEdit;
|
||||
QSpinBox pixmapCacheEdit;
|
||||
QLabel pixmapCacheLabel;
|
||||
};
|
||||
|
||||
class MessagesSettingsPage : public AbstractSettingsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MessagesSettingsPage();
|
||||
void retranslateUi() override;
|
||||
|
||||
private slots:
|
||||
void actAdd();
|
||||
void actEdit();
|
||||
void actRemove();
|
||||
void updateColor(const QString &value);
|
||||
void updateHighlightColor(const QString &value);
|
||||
void updateTextColor(int value);
|
||||
void updateTextHighlightColor(int value);
|
||||
|
||||
private:
|
||||
QListWidget *messageList;
|
||||
QAction *aAdd;
|
||||
QAction *aEdit;
|
||||
QAction *aRemove;
|
||||
QCheckBox chatMentionCheckBox;
|
||||
QCheckBox chatMentionCompleterCheckbox;
|
||||
QCheckBox invertMentionForeground;
|
||||
QCheckBox invertHighlightForeground;
|
||||
QCheckBox ignoreUnregUsersMainChat;
|
||||
QCheckBox ignoreUnregUserMessages;
|
||||
QCheckBox messagePopups;
|
||||
QCheckBox mentionPopups;
|
||||
QCheckBox roomHistory;
|
||||
QGroupBox *chatGroupBox;
|
||||
QGroupBox *highlightGroupBox;
|
||||
QGroupBox *messageGroupBox;
|
||||
QLineEdit *mentionColor;
|
||||
QLineEdit *highlightColor;
|
||||
QLineEdit *customAlertString;
|
||||
QLabel hexLabel;
|
||||
QLabel hexHighlightLabel;
|
||||
QLabel customAlertStringLabel;
|
||||
QLabel explainMessagesLabel;
|
||||
|
||||
void storeSettings();
|
||||
void updateMentionPreview();
|
||||
void updateHighlightPreview();
|
||||
};
|
||||
|
||||
class SoundSettingsPage : public AbstractSettingsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SoundSettingsPage();
|
||||
void retranslateUi() override;
|
||||
|
||||
private:
|
||||
QLabel themeLabel;
|
||||
QComboBox themeBox;
|
||||
QGroupBox *soundGroupBox;
|
||||
QPushButton soundTestButton;
|
||||
QCheckBox soundEnabledCheckBox;
|
||||
QLabel masterVolumeLabel;
|
||||
QSlider *masterVolumeSlider;
|
||||
QSpinBox *masterVolumeSpinBox;
|
||||
|
||||
private slots:
|
||||
void masterVolumeChanged(int value);
|
||||
void themeBoxChanged(int index);
|
||||
};
|
||||
|
||||
class ShortcutSettingsPage : public AbstractSettingsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ShortcutSettingsPage();
|
||||
void retranslateUi() override;
|
||||
|
||||
private:
|
||||
QTreeWidget *shortcutsTable;
|
||||
QVBoxLayout *mainLayout;
|
||||
QHBoxLayout *buttonsLayout;
|
||||
QGroupBox *editShortcutGroupBox;
|
||||
QGridLayout *editLayout;
|
||||
QLabel *currentActionGroupLabel;
|
||||
QLabel *currentActionGroupName;
|
||||
QLabel *currentActionLabel;
|
||||
QLabel *currentActionName;
|
||||
QLabel *currentShortcutLabel;
|
||||
SequenceEdit *editTextBox;
|
||||
QLabel *faqLabel;
|
||||
QPushButton *btnResetAll;
|
||||
QPushButton *btnClearAll;
|
||||
|
||||
private slots:
|
||||
void resetShortcuts();
|
||||
void refreshShortcuts();
|
||||
void createShortcuts();
|
||||
void clearShortcuts();
|
||||
void currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||
};
|
||||
|
||||
class DlgSettings : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DlgSettings(QWidget *parent = nullptr);
|
||||
void setTab(int index);
|
||||
|
||||
private slots:
|
||||
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
|
||||
void updateLanguage();
|
||||
|
||||
private:
|
||||
QListWidget *contentsWidget;
|
||||
QStackedWidget *pagesWidget;
|
||||
QListWidgetItem *generalButton, *appearanceButton, *userInterfaceButton, *deckEditorButton, *messagesButton,
|
||||
*soundButton, *shortcutsButton;
|
||||
void createIcons();
|
||||
void retranslateUi();
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *event) override;
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
169
cockatrice/src/dialogs/dlg_tip_of_the_day.cpp
Normal file
169
cockatrice/src/dialogs/dlg_tip_of_the_day.cpp
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
#include "dlg_tip_of_the_day.h"
|
||||
|
||||
#include "../client/ui/tip_of_the_day.h"
|
||||
#include "../settings/cache_settings.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QDate>
|
||||
#include <QDebug>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
|
||||
#define MIN_TIP_IMAGE_HEIGHT 200
|
||||
#define MIN_TIP_IMAGE_WIDTH 200
|
||||
#define MAX_TIP_IMAGE_HEIGHT 300
|
||||
#define MAX_TIP_IMAGE_WIDTH 500
|
||||
|
||||
DlgTipOfTheDay::DlgTipOfTheDay(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
successfulInit = false;
|
||||
QString xmlPath = "theme:tips/tips_of_the_day.xml";
|
||||
tipDatabase = new TipsOfTheDay(xmlPath, this);
|
||||
|
||||
if (tipDatabase->rowCount() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
title = new QLabel();
|
||||
title->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
tipTextContent = new QLabel();
|
||||
tipTextContent->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
tipTextContent->setWordWrap(true);
|
||||
tipTextContent->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
tipTextContent->setOpenExternalLinks(true);
|
||||
imageLabel = new QLabel();
|
||||
imageLabel->setFixedHeight(MAX_TIP_IMAGE_HEIGHT + 50);
|
||||
imageLabel->setFixedWidth(MAX_TIP_IMAGE_WIDTH + 50);
|
||||
image = new QPixmap();
|
||||
date = new QLabel();
|
||||
date->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
tipNumber = new QLabel();
|
||||
tipNumber->setAlignment(Qt::AlignCenter);
|
||||
|
||||
QList<int> seenTips = SettingsCache::instance().getSeenTips();
|
||||
newTipsAvailable = false;
|
||||
currentTip = 0;
|
||||
for (int i = 0; i < tipDatabase->rowCount(); i++) {
|
||||
if (!seenTips.contains(i)) {
|
||||
newTipsAvailable = true;
|
||||
currentTip = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
connect(this, SIGNAL(newTipRequested(int)), this, SLOT(updateTip(int)));
|
||||
newTipRequested(currentTip);
|
||||
|
||||
content = new QVBoxLayout;
|
||||
content->addWidget(title);
|
||||
content->addWidget(tipTextContent);
|
||||
content->addWidget(imageLabel);
|
||||
content->addWidget(date);
|
||||
|
||||
buttonBox = new QDialogButtonBox(Qt::Horizontal);
|
||||
nextButton = new QPushButton(tr("Next"));
|
||||
previousButton = new QPushButton(tr("Previous"));
|
||||
buttonBox->addButton(previousButton, QDialogButtonBox::ActionRole);
|
||||
buttonBox->addButton(nextButton, QDialogButtonBox::ActionRole);
|
||||
buttonBox->addButton(QDialogButtonBox::Ok);
|
||||
buttonBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(nextButton, SIGNAL(clicked()), this, SLOT(nextClicked()));
|
||||
connect(previousButton, SIGNAL(clicked()), this, SLOT(previousClicked()));
|
||||
|
||||
showTipsOnStartupCheck = new QCheckBox("Show tips on startup");
|
||||
showTipsOnStartupCheck->setChecked(SettingsCache::instance().getShowTipsOnStartup());
|
||||
connect(showTipsOnStartupCheck, SIGNAL(clicked(bool)), &SettingsCache::instance(),
|
||||
SLOT(setShowTipsOnStartup(bool)));
|
||||
buttonBar = new QHBoxLayout();
|
||||
buttonBar->addWidget(showTipsOnStartupCheck);
|
||||
buttonBar->addWidget(tipNumber);
|
||||
buttonBar->addWidget(buttonBox);
|
||||
|
||||
mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(content);
|
||||
mainLayout->addLayout(buttonBar);
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Tip of the Day"));
|
||||
setMinimumWidth(500);
|
||||
setMinimumHeight(300);
|
||||
successfulInit = true;
|
||||
}
|
||||
|
||||
DlgTipOfTheDay::~DlgTipOfTheDay()
|
||||
{
|
||||
tipDatabase->deleteLater();
|
||||
title->deleteLater();
|
||||
tipTextContent->deleteLater();
|
||||
imageLabel->deleteLater();
|
||||
tipNumber->deleteLater();
|
||||
showTipsOnStartupCheck->deleteLater();
|
||||
content->deleteLater();
|
||||
mainLayout->deleteLater();
|
||||
buttonBox->deleteLater();
|
||||
nextButton->deleteLater();
|
||||
previousButton->deleteLater();
|
||||
buttonBar->deleteLater();
|
||||
delete image;
|
||||
}
|
||||
|
||||
void DlgTipOfTheDay::nextClicked()
|
||||
{
|
||||
emit newTipRequested(currentTip + 1);
|
||||
}
|
||||
|
||||
void DlgTipOfTheDay::previousClicked()
|
||||
{
|
||||
emit newTipRequested(currentTip - 1);
|
||||
}
|
||||
|
||||
void DlgTipOfTheDay::updateTip(int tipId)
|
||||
{
|
||||
QString titleText, contentText, imagePath;
|
||||
|
||||
if (tipId < 0) {
|
||||
tipId = tipDatabase->rowCount() - 1;
|
||||
} else if (tipId >= tipDatabase->rowCount()) {
|
||||
tipId = tipId % tipDatabase->rowCount();
|
||||
}
|
||||
|
||||
// Store tip id as seen
|
||||
QList<int> seenTips = SettingsCache::instance().getSeenTips();
|
||||
if (!seenTips.contains(tipId)) {
|
||||
seenTips.append(tipId);
|
||||
SettingsCache::instance().setSeenTips(seenTips);
|
||||
}
|
||||
|
||||
TipOfTheDay tip = tipDatabase->getTip(tipId);
|
||||
titleText = tip.getTitle();
|
||||
contentText = tip.getContent();
|
||||
imagePath = tip.getImagePath();
|
||||
|
||||
title->setText("<h2>" + titleText + "</h2>");
|
||||
tipTextContent->setText(contentText);
|
||||
|
||||
if (!image->load(imagePath)) {
|
||||
qDebug() << "Image failed to load from" << imagePath;
|
||||
imageLabel->clear();
|
||||
} else {
|
||||
int h = std::min(std::max(imageLabel->height(), MIN_TIP_IMAGE_HEIGHT), MAX_TIP_IMAGE_HEIGHT);
|
||||
int w = std::min(std::max(imageLabel->width(), MIN_TIP_IMAGE_WIDTH), MAX_TIP_IMAGE_WIDTH);
|
||||
imageLabel->setPixmap(image->scaled(w, h, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
}
|
||||
|
||||
date->setText("<i>Tip added on: " + tip.getDate().toString("yyyy-MM-dd") + "</i>");
|
||||
|
||||
tipNumber->setText("Tip " + QString::number(tipId + 1) + " / " + QString::number(tipDatabase->rowCount()));
|
||||
|
||||
currentTip = static_cast<unsigned int>(tipId);
|
||||
}
|
||||
|
||||
void DlgTipOfTheDay::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
imageLabel->setPixmap(image->scaled(imageLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
|
||||
QWidget::resizeEvent(event);
|
||||
}
|
||||
49
cockatrice/src/dialogs/dlg_tip_of_the_day.h
Normal file
49
cockatrice/src/dialogs/dlg_tip_of_the_day.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#ifndef DLG_TIPOFDAY_H
|
||||
#define DLG_TIPOFDAY_H
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QCheckBox;
|
||||
class TipsOfTheDay;
|
||||
|
||||
class DlgTipOfTheDay : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DlgTipOfTheDay(QWidget *parent = nullptr);
|
||||
~DlgTipOfTheDay() override;
|
||||
bool successfulInit;
|
||||
bool newTipsAvailable;
|
||||
signals:
|
||||
void newTipRequested(int tipId);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
private:
|
||||
unsigned int currentTip;
|
||||
TipsOfTheDay *tipDatabase;
|
||||
QLabel *title, *tipTextContent, *imageLabel, *tipNumber, *date;
|
||||
QCheckBox *showTipsOnStartupCheck;
|
||||
QPixmap *image;
|
||||
|
||||
QVBoxLayout *content, *mainLayout;
|
||||
QDialogButtonBox *buttonBox;
|
||||
QPushButton *nextButton, *previousButton;
|
||||
QHBoxLayout *buttonBar;
|
||||
|
||||
private slots:
|
||||
void nextClicked();
|
||||
void previousClicked();
|
||||
void updateTip(int tipId);
|
||||
};
|
||||
|
||||
#endif
|
||||
238
cockatrice/src/dialogs/dlg_update.cpp
Normal file
238
cockatrice/src/dialogs/dlg_update.cpp
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
#include "dlg_update.h"
|
||||
|
||||
#include "../client/network/release_channel.h"
|
||||
#include "../client/ui/window_main.h"
|
||||
#include "../settings/cache_settings.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopServices>
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
#include <QProgressBar>
|
||||
#include <QProgressDialog>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
#include <QtNetwork>
|
||||
#include <version_string.h>
|
||||
|
||||
DlgUpdate::DlgUpdate(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
|
||||
// Handle layout
|
||||
statusLabel = new QLabel(this);
|
||||
statusLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
||||
statusLabel->setWordWrap(true);
|
||||
descriptionLabel =
|
||||
new QLabel(tr("Current release channel") +
|
||||
QString(": %1").arg(tr(SettingsCache::instance().getUpdateReleaseChannel()->getName().toUtf8())),
|
||||
this);
|
||||
progress = new QProgressBar(this);
|
||||
|
||||
buttonBox = new QDialogButtonBox(this);
|
||||
buttonBox->setFixedWidth(350);
|
||||
|
||||
ok = new QPushButton("Close", this);
|
||||
manualDownload = new QPushButton(tr("Reinstall"), this);
|
||||
stopDownload = new QPushButton(tr("Cancel Download"), this);
|
||||
gotoDownload = new QPushButton(tr("Open Download Page"), this);
|
||||
|
||||
addStopDownloadAndRemoveOthers(false); // Add all buttons to box
|
||||
enableUpdateButton(false); // Unless we know there's an update available, you can't install
|
||||
buttonBox->addButton(ok, QDialogButtonBox::AcceptRole);
|
||||
|
||||
connect(gotoDownload, SIGNAL(clicked()), this, SLOT(gotoDownloadPage()));
|
||||
connect(manualDownload, SIGNAL(clicked()), this, SLOT(downloadUpdate()));
|
||||
connect(stopDownload, SIGNAL(clicked()), this, SLOT(cancelDownload()));
|
||||
connect(ok, SIGNAL(clicked()), this, SLOT(closeDialog()));
|
||||
|
||||
auto *parentLayout = new QVBoxLayout(this);
|
||||
parentLayout->addWidget(descriptionLabel);
|
||||
parentLayout->addWidget(statusLabel);
|
||||
parentLayout->addWidget(progress);
|
||||
parentLayout->addWidget(buttonBox);
|
||||
|
||||
setLayout(parentLayout);
|
||||
setWindowTitle(tr("Check for Client Updates"));
|
||||
|
||||
setFixedHeight(this->sizeHint().height());
|
||||
setFixedWidth(this->sizeHint().width());
|
||||
|
||||
// Check for SSL (this probably isn't necessary)
|
||||
if (!QSslSocket::supportsSsl()) {
|
||||
enableUpdateButton(false);
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("Cockatrice was not built with SSL support, therefore you cannot download updates "
|
||||
"automatically! \nPlease visit the download page to update manually."));
|
||||
}
|
||||
|
||||
// Initialize the checker and downloader class
|
||||
uDownloader = new UpdateDownloader(this);
|
||||
connect(uDownloader, SIGNAL(downloadSuccessful(QUrl)), this, SLOT(downloadSuccessful(QUrl)));
|
||||
connect(uDownloader, SIGNAL(progressMade(qint64, qint64)), this, SLOT(downloadProgressMade(qint64, qint64)));
|
||||
connect(uDownloader, SIGNAL(error(QString)), this, SLOT(downloadError(QString)));
|
||||
|
||||
ReleaseChannel *channel = SettingsCache::instance().getUpdateReleaseChannel();
|
||||
connect(channel, SIGNAL(finishedCheck(bool, bool, Release *)), this,
|
||||
SLOT(finishedUpdateCheck(bool, bool, Release *)));
|
||||
connect(channel, SIGNAL(error(QString)), this, SLOT(updateCheckError(QString)));
|
||||
|
||||
// Check for updates
|
||||
beginUpdateCheck();
|
||||
}
|
||||
|
||||
void DlgUpdate::closeDialog()
|
||||
{
|
||||
accept();
|
||||
}
|
||||
|
||||
void DlgUpdate::gotoDownloadPage()
|
||||
{
|
||||
QDesktopServices::openUrl(SettingsCache::instance().getUpdateReleaseChannel()->getManualDownloadUrl());
|
||||
}
|
||||
|
||||
void DlgUpdate::downloadUpdate()
|
||||
{
|
||||
setLabel(tr("Downloading update..."));
|
||||
addStopDownloadAndRemoveOthers(true); // Will remove all other buttons
|
||||
uDownloader->beginDownload(updateUrl);
|
||||
}
|
||||
|
||||
void DlgUpdate::cancelDownload()
|
||||
{
|
||||
emit uDownloader->stopDownload();
|
||||
setLabel("Download canceled");
|
||||
addStopDownloadAndRemoveOthers(false);
|
||||
downloadProgressMade(0, 1);
|
||||
}
|
||||
|
||||
void DlgUpdate::beginUpdateCheck()
|
||||
{
|
||||
progress->setMinimum(0);
|
||||
progress->setMaximum(0);
|
||||
setLabel(tr("Checking for updates..."));
|
||||
SettingsCache::instance().getUpdateReleaseChannel()->checkForUpdates();
|
||||
}
|
||||
|
||||
void DlgUpdate::finishedUpdateCheck(bool needToUpdate, bool isCompatible, Release *release)
|
||||
{
|
||||
|
||||
QString publishDate, versionName;
|
||||
|
||||
// Update the UI to say we've finished
|
||||
progress->setMaximum(100);
|
||||
setLabel(tr("Finished checking for updates"));
|
||||
|
||||
// If there are no available builds, then they can't auto update.
|
||||
enableUpdateButton(isCompatible);
|
||||
|
||||
if (isCompatible) {
|
||||
// If there is an update, save its URL and work out its name
|
||||
updateUrl = release->getDownloadUrl();
|
||||
}
|
||||
|
||||
// Give the user the appropriate message
|
||||
if (!needToUpdate) {
|
||||
// If there's no need to update, tell them that. However we still allow them to run the
|
||||
// downloader themselves if there's a compatible build
|
||||
QMessageBox::information(
|
||||
this, tr("No Update Available"),
|
||||
tr("Cockatrice is up to date!") + "<br><br>" +
|
||||
tr("You are already running the latest version available in the chosen release channel.") + "<br>" +
|
||||
"<b>" + tr("Current version") + QString(":</b> %1<br>").arg(VERSION_STRING) + "<b>" +
|
||||
tr("Selected release channel") +
|
||||
QString(":</b> %1").arg(tr(SettingsCache::instance().getUpdateReleaseChannel()->getName().toUtf8())));
|
||||
return;
|
||||
}
|
||||
|
||||
publishDate = release->getPublishDate().toString(QLocale().dateFormat(QLocale::LongFormat));
|
||||
if (isCompatible) {
|
||||
int reply;
|
||||
reply = QMessageBox::question(
|
||||
this, tr("Update Available"),
|
||||
tr("A new version of Cockatrice is available!") + "<br><br>" + "<b>" + tr("New version") +
|
||||
QString(":</b> %1<br>").arg(release->getName()) + "<b>" + tr("Released") +
|
||||
QString(":</b> %1 (<a href=\"%2\">").arg(publishDate, release->getDescriptionUrl()) + tr("Changelog") +
|
||||
"</a>)<br><br>" + tr("Do you want to update now?"),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
if (reply == QMessageBox::Yes)
|
||||
downloadUpdate();
|
||||
} else {
|
||||
QMessageBox::information(
|
||||
this, tr("Update Available"),
|
||||
tr("A new version of Cockatrice is available!") + "<br><br>" + "<b>" + tr("New version") +
|
||||
QString(":</b> %1<br>").arg(release->getName()) + "<b>" + tr("Released") +
|
||||
QString(":</b> %1 (<a href=\"%2\">").arg(publishDate, release->getDescriptionUrl()) + tr("Changelog") +
|
||||
"</a>)<br><br>" +
|
||||
tr("Unfortunately there are no download packages available for your operating system. \nYou may have "
|
||||
"to build from source yourself.") +
|
||||
"<br><br>" +
|
||||
tr("Please check the download page manually and visit the wiki for instructions on compiling."));
|
||||
}
|
||||
}
|
||||
|
||||
void DlgUpdate::enableUpdateButton(bool enable)
|
||||
{
|
||||
manualDownload->setEnabled(enable);
|
||||
}
|
||||
|
||||
void DlgUpdate::addStopDownloadAndRemoveOthers(bool enable)
|
||||
{
|
||||
if (enable) {
|
||||
buttonBox->addButton(stopDownload, QDialogButtonBox::ActionRole);
|
||||
buttonBox->removeButton(manualDownload);
|
||||
buttonBox->removeButton(gotoDownload);
|
||||
} else {
|
||||
buttonBox->removeButton(stopDownload);
|
||||
buttonBox->addButton(manualDownload, QDialogButtonBox::ActionRole);
|
||||
buttonBox->addButton(gotoDownload, QDialogButtonBox::ActionRole);
|
||||
}
|
||||
}
|
||||
|
||||
void DlgUpdate::enableOkButton(bool enable)
|
||||
{
|
||||
ok->setEnabled(enable);
|
||||
}
|
||||
|
||||
void DlgUpdate::setLabel(const QString &newText)
|
||||
{
|
||||
statusLabel->setText(newText);
|
||||
}
|
||||
|
||||
void DlgUpdate::updateCheckError(const QString &errorString)
|
||||
{
|
||||
setLabel(tr("Error"));
|
||||
QMessageBox::critical(this, tr("Update Error"),
|
||||
tr("An error occurred while checking for updates:") + QString(" ") + errorString);
|
||||
}
|
||||
|
||||
void DlgUpdate::downloadError(const QString &errorString)
|
||||
{
|
||||
setLabel(tr("Error"));
|
||||
enableUpdateButton(true);
|
||||
QMessageBox::critical(this, tr("Update Error"),
|
||||
tr("An error occurred while downloading an update:") + QString(" ") + errorString);
|
||||
}
|
||||
|
||||
void DlgUpdate::downloadSuccessful(const QUrl &filepath)
|
||||
{
|
||||
setLabel(tr("Installing..."));
|
||||
// Try to open the installer. If it opens, quit Cockatrice
|
||||
if (QDesktopServices::openUrl(filepath)) {
|
||||
QMetaObject::invokeMethod(static_cast<MainWindow *>(parent()), "close", Qt::QueuedConnection);
|
||||
qDebug() << "Opened downloaded update file successfully - closing Cockatrice";
|
||||
close();
|
||||
} else {
|
||||
setLabel(tr("Error"));
|
||||
QMessageBox::critical(this, tr("Update Error"),
|
||||
tr("Cockatrice is unable to open the installer.") + "<br><br>" +
|
||||
tr("Try to update manually by closing Cockatrice and running the installer.") +
|
||||
"<br>" + tr("Download location") + QString(": %1").arg(filepath.toLocalFile()));
|
||||
}
|
||||
}
|
||||
|
||||
void DlgUpdate::downloadProgressMade(qint64 bytesRead, qint64 totalBytes)
|
||||
{
|
||||
progress->setMaximum(totalBytes);
|
||||
progress->setValue(bytesRead);
|
||||
}
|
||||
43
cockatrice/src/dialogs/dlg_update.h
Normal file
43
cockatrice/src/dialogs/dlg_update.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef DLG_UPDATE_H
|
||||
#define DLG_UPDATE_H
|
||||
|
||||
#include "../client/update_downloader.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QProgressDialog>
|
||||
#include <QtNetwork>
|
||||
class Release;
|
||||
|
||||
class DlgUpdate : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DlgUpdate(QWidget *parent);
|
||||
|
||||
private slots:
|
||||
void finishedUpdateCheck(bool needToUpdate, bool isCompatible, Release *release);
|
||||
void gotoDownloadPage();
|
||||
void downloadUpdate();
|
||||
void cancelDownload();
|
||||
void updateCheckError(const QString &errorString);
|
||||
void downloadSuccessful(const QUrl &filepath);
|
||||
void downloadProgressMade(qint64 bytesRead, qint64 totalBytes);
|
||||
void downloadError(const QString &errorString);
|
||||
void closeDialog();
|
||||
|
||||
private:
|
||||
QUrl updateUrl;
|
||||
void enableUpdateButton(bool enable);
|
||||
void enableOkButton(bool enable);
|
||||
void addStopDownloadAndRemoveOthers(bool enable);
|
||||
void beginUpdateCheck();
|
||||
void setLabel(const QString &text);
|
||||
QLabel *statusLabel, *descriptionLabel;
|
||||
QProgressBar *progress;
|
||||
QPushButton *manualDownload, *gotoDownload, *ok, *stopDownload;
|
||||
QPushButton *cancel;
|
||||
UpdateDownloader *uDownloader;
|
||||
QDialogButtonBox *buttonBox;
|
||||
};
|
||||
|
||||
#endif
|
||||
58
cockatrice/src/dialogs/dlg_view_log.cpp
Normal file
58
cockatrice/src/dialogs/dlg_view_log.cpp
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#include "dlg_view_log.h"
|
||||
|
||||
#include "../settings/cache_settings.h"
|
||||
#include "../utility/logger.h"
|
||||
|
||||
#include <QPlainTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
DlgViewLog::DlgViewLog(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
|
||||
logArea = new QPlainTextEdit;
|
||||
logArea->setReadOnly(true);
|
||||
|
||||
auto *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addWidget(logArea);
|
||||
|
||||
coClearLog = new QCheckBox;
|
||||
coClearLog->setText(tr("Clear log when closing"));
|
||||
coClearLog->setChecked(SettingsCache::instance().servers().getClearDebugLogStatus(false));
|
||||
connect(coClearLog, SIGNAL(toggled(bool)), this, SLOT(actCheckBoxChanged(bool)));
|
||||
mainLayout->addWidget(coClearLog);
|
||||
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Debug Log"));
|
||||
resize(800, 500);
|
||||
|
||||
loadInitialLogBuffer();
|
||||
connect(&Logger::getInstance(), SIGNAL(logEntryAdded(QString)), this, SLOT(logEntryAdded(QString)));
|
||||
}
|
||||
|
||||
void DlgViewLog::actCheckBoxChanged(bool abNewValue)
|
||||
{
|
||||
SettingsCache::instance().servers().setClearDebugLogStatus(abNewValue);
|
||||
}
|
||||
|
||||
void DlgViewLog::loadInitialLogBuffer()
|
||||
{
|
||||
QList<QString> logBuffer = Logger::getInstance().getLogBuffer();
|
||||
foreach (QString message, logBuffer)
|
||||
logEntryAdded(message);
|
||||
}
|
||||
|
||||
void DlgViewLog::logEntryAdded(QString message)
|
||||
{
|
||||
logArea->appendPlainText(message);
|
||||
}
|
||||
|
||||
void DlgViewLog::closeEvent(QCloseEvent * /* event */)
|
||||
{
|
||||
if (coClearLog->isChecked()) {
|
||||
logArea->clear();
|
||||
|
||||
logArea->appendPlainText(Logger::getInstance().getClientVersion());
|
||||
logArea->appendPlainText(Logger::getInstance().getSystemArchitecture());
|
||||
}
|
||||
}
|
||||
29
cockatrice/src/dialogs/dlg_view_log.h
Normal file
29
cockatrice/src/dialogs/dlg_view_log.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef DLG_VIEWLOG_H
|
||||
#define DLG_VIEWLOG_H
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QDialog>
|
||||
|
||||
class QPlainTextEdit;
|
||||
class QCloseEvent;
|
||||
|
||||
class DlgViewLog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DlgViewLog(QWidget *parent);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
private:
|
||||
QPlainTextEdit *logArea;
|
||||
QCheckBox *coClearLog;
|
||||
|
||||
void loadInitialLogBuffer();
|
||||
private slots:
|
||||
void logEntryAdded(QString message);
|
||||
void actCheckBoxChanged(bool abNewValue);
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue