mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-29 01:53:54 -07:00
initial commit for settings dialog, unfinished
This commit is contained in:
parent
84f06503c6
commit
f703004b6c
10 changed files with 261 additions and 118 deletions
|
|
@ -1,76 +0,0 @@
|
|||
#include <QtGui>
|
||||
#include "dlg_editmessages.h"
|
||||
|
||||
DlgEditMessages::DlgEditMessages(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
aAdd = new QAction(tr("Add"), this);
|
||||
connect(aAdd, SIGNAL(triggered()), this, SLOT(actAdd()));
|
||||
aRemove = new QAction(tr("Remove"), this);
|
||||
connect(aRemove, SIGNAL(triggered()), this, SLOT(actRemove()));
|
||||
|
||||
messageList = new QListWidget;
|
||||
QToolBar *messageToolBar = new QToolBar;
|
||||
messageToolBar->setOrientation(Qt::Vertical);
|
||||
messageToolBar->addAction(aAdd);
|
||||
messageToolBar->addAction(aRemove);
|
||||
|
||||
QSettings settings;
|
||||
settings.beginGroup("messages");
|
||||
int count = settings.value("count", 0).toInt();
|
||||
for (int i = 0; i < count; i++)
|
||||
messageList->addItem(settings.value(QString("msg%1").arg(i)).toString());
|
||||
|
||||
QHBoxLayout *listLayout = new QHBoxLayout;
|
||||
listLayout->addWidget(messageList);
|
||||
listLayout->addWidget(messageToolBar);
|
||||
|
||||
cancelButton = new QPushButton(tr("&Cancel"));
|
||||
okButton = new QPushButton(tr("O&K"));
|
||||
okButton->setAutoDefault(true);
|
||||
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addStretch();
|
||||
buttonLayout->addWidget(cancelButton);
|
||||
buttonLayout->addWidget(okButton);
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(listLayout);
|
||||
mainLayout->addLayout(buttonLayout);
|
||||
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Edit messages"));
|
||||
setMinimumWidth(sizeHint().width());
|
||||
resize(300, 300);
|
||||
|
||||
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
|
||||
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
|
||||
}
|
||||
|
||||
void DlgEditMessages::storeSettings()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.beginGroup("messages");
|
||||
settings.setValue("count", messageList->count());
|
||||
for (int i = 0; i < messageList->count(); i++)
|
||||
settings.setValue(QString("msg%1").arg(i), messageList->item(i)->text());
|
||||
}
|
||||
|
||||
void DlgEditMessages::actAdd()
|
||||
{
|
||||
bool ok;
|
||||
QString msg = QInputDialog::getText(this, tr("Add message"), QString("Message:"), QLineEdit::Normal, QString(), &ok);
|
||||
if (ok) {
|
||||
messageList->addItem(msg);
|
||||
storeSettings();
|
||||
}
|
||||
}
|
||||
|
||||
void DlgEditMessages::actRemove()
|
||||
{
|
||||
if (messageList->currentItem()) {
|
||||
delete messageList->takeItem(messageList->currentRow());
|
||||
storeSettings();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
#ifndef DLG_EDITMESSAGES_H
|
||||
#define DLG_EDITMESSAGES_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class QListWidget;
|
||||
class QPushButton;
|
||||
|
||||
class DlgEditMessages: public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DlgEditMessages(QWidget *parent = 0);
|
||||
private slots:
|
||||
void actAdd();
|
||||
void actRemove();
|
||||
private:
|
||||
QListWidget *messageList;
|
||||
QAction *aAdd, *aRemove;
|
||||
QPushButton *cancelButton, *okButton;
|
||||
|
||||
void storeSettings();
|
||||
};
|
||||
|
||||
#endif
|
||||
187
cockatrice/src/dlg_settings.cpp
Normal file
187
cockatrice/src/dlg_settings.cpp
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
#include <QtGui>
|
||||
|
||||
#include "dlg_settings.h"
|
||||
|
||||
GeneralSettingsPage::GeneralSettingsPage()
|
||||
{
|
||||
QGroupBox *personalGroupBox = new QGroupBox(tr("Personal settings"));
|
||||
QLabel *languageLabel = new QLabel(tr("Language:"));
|
||||
QComboBox *languageBox = new QComboBox;
|
||||
|
||||
QStringList qmFiles = findQmFiles();
|
||||
for (int i = 0; i < qmFiles.size(); i++)
|
||||
languageBox->addItem(languageName(qmFiles[i]), qmFiles[i]);
|
||||
|
||||
QGridLayout *personalGrid = new QGridLayout;
|
||||
personalGrid->addWidget(languageLabel, 0, 0);
|
||||
personalGrid->addWidget(languageBox, 0, 1);
|
||||
personalGroupBox->setLayout(personalGrid);
|
||||
|
||||
QGroupBox *pathsGroupBox = new QGroupBox(tr("Paths"));
|
||||
QLabel *deckPathLabel = new QLabel(tr("Decks directory:"));
|
||||
QLineEdit *deckPathEdit = new QLineEdit;
|
||||
QLabel *picsPathLabel = new QLabel(tr("Pictures directory:"));
|
||||
QLineEdit *picsPathEdit = new QLineEdit;
|
||||
QLabel *cardDatabasePathLabel = new QLabel(tr("Path to card database:"));
|
||||
QLineEdit *cardDatabasePathEdit = new QLineEdit;
|
||||
|
||||
QGridLayout *pathsGrid = new QGridLayout;
|
||||
pathsGrid->addWidget(deckPathLabel, 0, 0);
|
||||
pathsGrid->addWidget(deckPathEdit, 0, 1);
|
||||
pathsGrid->addWidget(picsPathLabel, 1, 0);
|
||||
pathsGrid->addWidget(picsPathEdit, 1, 1);
|
||||
pathsGrid->addWidget(cardDatabasePathLabel, 2, 0);
|
||||
pathsGrid->addWidget(cardDatabasePathEdit, 2, 1);
|
||||
pathsGroupBox->setLayout(pathsGrid);
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addWidget(personalGroupBox);
|
||||
mainLayout->addWidget(pathsGroupBox);
|
||||
|
||||
setLayout(mainLayout);
|
||||
}
|
||||
|
||||
QStringList GeneralSettingsPage::findQmFiles()
|
||||
{
|
||||
QDir dir(":/translations");
|
||||
QStringList fileNames = dir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
|
||||
QMutableStringListIterator i(fileNames);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
i.setValue(dir.filePath(i.value()));
|
||||
}
|
||||
return fileNames;
|
||||
}
|
||||
|
||||
QString GeneralSettingsPage::languageName(const QString &qmFile)
|
||||
{
|
||||
QTranslator translator;
|
||||
translator.load(qmFile);
|
||||
|
||||
return translator.translate("GeneralSettingsPage", "English");
|
||||
}
|
||||
|
||||
AppearanceSettingsPage::AppearanceSettingsPage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MessagesSettingsPage::MessagesSettingsPage()
|
||||
{
|
||||
aAdd = new QAction(tr("Add"), this);
|
||||
connect(aAdd, SIGNAL(triggered()), this, SLOT(actAdd()));
|
||||
aRemove = new QAction(tr("Remove"), this);
|
||||
connect(aRemove, SIGNAL(triggered()), this, SLOT(actRemove()));
|
||||
|
||||
messageList = new QListWidget;
|
||||
QToolBar *messageToolBar = new QToolBar;
|
||||
messageToolBar->setOrientation(Qt::Vertical);
|
||||
messageToolBar->addAction(aAdd);
|
||||
messageToolBar->addAction(aRemove);
|
||||
|
||||
QSettings settings;
|
||||
settings.beginGroup("messages");
|
||||
int count = settings.value("count", 0).toInt();
|
||||
for (int i = 0; i < count; i++)
|
||||
messageList->addItem(settings.value(QString("msg%1").arg(i)).toString());
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
mainLayout->addWidget(messageList);
|
||||
mainLayout->addWidget(messageToolBar);
|
||||
|
||||
setLayout(mainLayout);
|
||||
}
|
||||
|
||||
void MessagesSettingsPage::storeSettings()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.beginGroup("messages");
|
||||
settings.setValue("count", messageList->count());
|
||||
for (int i = 0; i < messageList->count(); i++)
|
||||
settings.setValue(QString("msg%1").arg(i), messageList->item(i)->text());
|
||||
}
|
||||
|
||||
void MessagesSettingsPage::actAdd()
|
||||
{
|
||||
bool ok;
|
||||
QString msg = QInputDialog::getText(this, tr("Add message"), tr("Message:"), QLineEdit::Normal, QString(), &ok);
|
||||
if (ok) {
|
||||
messageList->addItem(msg);
|
||||
storeSettings();
|
||||
}
|
||||
}
|
||||
|
||||
void MessagesSettingsPage::actRemove()
|
||||
{
|
||||
if (messageList->currentItem()) {
|
||||
delete messageList->takeItem(messageList->currentRow());
|
||||
storeSettings();
|
||||
}
|
||||
}
|
||||
|
||||
DlgSettings::DlgSettings()
|
||||
: QDialog()
|
||||
{
|
||||
contentsWidget = new QListWidget;
|
||||
contentsWidget->setViewMode(QListView::IconMode);
|
||||
contentsWidget->setIconSize(QSize(96, 84));
|
||||
contentsWidget->setMovement(QListView::Static);
|
||||
contentsWidget->setMaximumWidth(128);
|
||||
contentsWidget->setSpacing(12);
|
||||
|
||||
pagesWidget = new QStackedWidget;
|
||||
pagesWidget->addWidget(new GeneralSettingsPage);
|
||||
pagesWidget->addWidget(new AppearanceSettingsPage);
|
||||
pagesWidget->addWidget(new MessagesSettingsPage);
|
||||
|
||||
QPushButton *closeButton = new QPushButton(tr("&Close"));
|
||||
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
|
||||
|
||||
createIcons();
|
||||
contentsWidget->setCurrentRow(0);
|
||||
|
||||
QHBoxLayout *hboxLayout = new QHBoxLayout;
|
||||
hboxLayout->addWidget(contentsWidget);
|
||||
hboxLayout->addWidget(pagesWidget, 1);
|
||||
|
||||
QHBoxLayout *buttonsLayout = new QHBoxLayout;
|
||||
buttonsLayout->addStretch(1);
|
||||
buttonsLayout->addWidget(closeButton);
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(hboxLayout);
|
||||
mainLayout->addStretch(1);
|
||||
mainLayout->addSpacing(12);
|
||||
mainLayout->addLayout(buttonsLayout);
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Settings"));
|
||||
}
|
||||
|
||||
void DlgSettings::createIcons()
|
||||
{
|
||||
QListWidgetItem *generalButton = new QListWidgetItem(contentsWidget);
|
||||
generalButton->setText(tr("General"));
|
||||
generalButton->setTextAlignment(Qt::AlignHCenter);
|
||||
generalButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
|
||||
QListWidgetItem *appearanceButton = new QListWidgetItem(contentsWidget);
|
||||
appearanceButton->setText(tr("Appearance"));
|
||||
appearanceButton->setTextAlignment(Qt::AlignHCenter);
|
||||
appearanceButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
|
||||
QListWidgetItem *messagesButton = new QListWidgetItem(contentsWidget);
|
||||
messagesButton->setText(tr("Messages"));
|
||||
messagesButton->setTextAlignment(Qt::AlignHCenter);
|
||||
messagesButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
|
||||
connect(contentsWidget, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(changePage(QListWidgetItem *, QListWidgetItem *)));
|
||||
}
|
||||
|
||||
void DlgSettings::changePage(QListWidgetItem *current, QListWidgetItem *previous)
|
||||
{
|
||||
if (!current)
|
||||
current = previous;
|
||||
|
||||
pagesWidget->setCurrentIndex(contentsWidget->row(current));
|
||||
}
|
||||
51
cockatrice/src/dlg_settings.h
Normal file
51
cockatrice/src/dlg_settings.h
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#ifndef DLG_SETTINGS_H
|
||||
#define DLG_SETTINGS_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class QListWidget;
|
||||
class QListWidgetItem;
|
||||
class QStackedWidget;
|
||||
|
||||
class GeneralSettingsPage : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
GeneralSettingsPage();
|
||||
private:
|
||||
QStringList findQmFiles();
|
||||
QString languageName(const QString &qmFile);
|
||||
};
|
||||
|
||||
class AppearanceSettingsPage : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AppearanceSettingsPage();
|
||||
};
|
||||
|
||||
class MessagesSettingsPage : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
MessagesSettingsPage();
|
||||
private slots:
|
||||
void actAdd();
|
||||
void actRemove();
|
||||
private:
|
||||
QListWidget *messageList;
|
||||
QAction *aAdd, *aRemove;
|
||||
|
||||
void storeSettings();
|
||||
};
|
||||
|
||||
class DlgSettings : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DlgSettings();
|
||||
public slots:
|
||||
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
|
||||
private:
|
||||
QListWidget *contentsWidget;
|
||||
QStackedWidget *pagesWidget;
|
||||
void createIcons();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -10,7 +10,6 @@
|
|||
#include "handzone.h"
|
||||
#include "carddatabase.h"
|
||||
#include "dlg_startgame.h"
|
||||
#include "dlg_editmessages.h"
|
||||
#include "playerarea.h"
|
||||
#include "counter.h"
|
||||
|
||||
|
|
@ -54,9 +53,6 @@ Game::Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_a
|
|||
aCreateToken->setShortcut(tr("Ctrl+T"));
|
||||
connect(aCreateToken, SIGNAL(triggered()), this, SLOT(actCreateToken()));
|
||||
|
||||
aEditMessages = new QAction(tr("&Edit messages..."), this);
|
||||
connect(aEditMessages, SIGNAL(triggered()), this, SLOT(actEditMessages()));
|
||||
|
||||
actionsMenu->addAction(aUntapAll);
|
||||
actionsMenu->addSeparator();
|
||||
actionsMenu->addAction(aDecLife);
|
||||
|
|
@ -115,8 +111,6 @@ Game::~Game()
|
|||
void Game::initSayMenu()
|
||||
{
|
||||
sayMenu->clear();
|
||||
sayMenu->addAction(aEditMessages);
|
||||
sayMenu->addSeparator();
|
||||
|
||||
QSettings settings;
|
||||
settings.beginGroup("messages");
|
||||
|
|
@ -325,13 +319,6 @@ void Game::actCreateToken()
|
|||
client->createToken("table", cardname, QString(), 0, 0);
|
||||
}
|
||||
|
||||
void Game::actEditMessages()
|
||||
{
|
||||
DlgEditMessages dlg;
|
||||
if (dlg.exec())
|
||||
initSayMenu();
|
||||
}
|
||||
|
||||
void Game::showCardMenu(QPoint p)
|
||||
{
|
||||
cardMenu->exec(p);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class Game : public QObject {
|
|||
private:
|
||||
QMenu *actionsMenu, *sayMenu, *cardMenu;
|
||||
QAction *aTap, *aUntap, *aDoesntUntap, *aFlip, *aAddCounter, *aRemoveCounter, *aSetCounters,
|
||||
*aUntapAll, *aDecLife, *aIncLife, *aSetLife, *aShuffle, *aDraw, *aDrawCards, *aRollDice, *aCreateToken, *aEditMessages;
|
||||
*aUntapAll, *aDecLife, *aIncLife, *aSetLife, *aShuffle, *aDraw, *aDrawCards, *aRollDice, *aCreateToken;
|
||||
DlgStartGame *dlgStartGame;
|
||||
|
||||
CardDatabase *db;
|
||||
|
|
@ -37,7 +37,6 @@ private slots:
|
|||
void actDrawCards();
|
||||
void actRollDice();
|
||||
void actCreateToken();
|
||||
void actEditMessages();
|
||||
|
||||
void showCardMenu(QPoint p);
|
||||
void actDoesntUntap();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "window_main.h"
|
||||
#include "dlg_connect.h"
|
||||
#include "dlg_settings.h"
|
||||
#include "gameselector.h"
|
||||
#include "window_deckeditor.h"
|
||||
#include "cardinfowidget.h"
|
||||
|
|
@ -130,6 +131,12 @@ void MainWindow::actFullScreen(bool checked)
|
|||
setWindowState(windowState() & ~Qt::WindowFullScreen);
|
||||
}
|
||||
|
||||
void MainWindow::actSettings()
|
||||
{
|
||||
DlgSettings dlg;
|
||||
dlg.exec();
|
||||
}
|
||||
|
||||
void MainWindow::actExit()
|
||||
{
|
||||
close();
|
||||
|
|
@ -193,6 +200,8 @@ void MainWindow::createActions()
|
|||
aFullScreen->setShortcut(tr("Ctrl+F"));
|
||||
aFullScreen->setCheckable(true);
|
||||
connect(aFullScreen, SIGNAL(toggled(bool)), this, SLOT(actFullScreen(bool)));
|
||||
aSettings = new QAction(tr("&Settings..."), this);
|
||||
connect(aSettings, SIGNAL(triggered()), this, SLOT(actSettings()));
|
||||
aExit = new QAction(tr("&Exit"), this);
|
||||
connect(aExit, SIGNAL(triggered()), this, SLOT(actExit()));
|
||||
|
||||
|
|
@ -215,6 +224,8 @@ void MainWindow::createMenus()
|
|||
gameMenu->addSeparator();
|
||||
gameMenu->addAction(aFullScreen);
|
||||
gameMenu->addSeparator();
|
||||
gameMenu->addAction(aSettings);
|
||||
gameMenu->addSeparator();
|
||||
gameMenu->addAction(aExit);
|
||||
|
||||
actionsMenu = menuBar()->addMenu(tr("&Actions"));
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ private slots:
|
|||
void actLeaveGame();
|
||||
void actDeckEditor();
|
||||
void actFullScreen(bool checked);
|
||||
void actSettings();
|
||||
void actExit();
|
||||
|
||||
void updateSceneSize();
|
||||
|
|
@ -66,7 +67,7 @@ private:
|
|||
void createActions();
|
||||
void createMenus();
|
||||
QMenu *gameMenu, *actionsMenu, *cardMenu;
|
||||
QAction *aConnect, *aDisconnect, *aRestartGame, *aLeaveGame, *aDeckEditor, *aFullScreen, *aExit;
|
||||
QAction *aConnect, *aDisconnect, *aRestartGame, *aLeaveGame, *aDeckEditor, *aFullScreen, *aSettings, *aExit;
|
||||
QAction *aCloseMostRecentZoneView;
|
||||
QVBoxLayout *viewLayout;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue