settings dialog

This commit is contained in:
brukie 2009-07-28 19:52:15 +02:00
parent 789db32b16
commit dfaa6b1d95
11 changed files with 420 additions and 120 deletions

View file

@ -63,16 +63,7 @@ CardInfo::CardInfo(CardDatabase *_db, const QString &_name, const QString &_mana
CardInfo::~CardInfo()
{
if (pixmap) {
qDebug(QString("Deleting pixmap for %1").arg(name).toLatin1());
delete pixmap;
QMapIterator<int, QPixmap *> i(scaledPixmapCache);
while (i.hasNext()) {
i.next();
qDebug(QString(" Deleting cached pixmap for width %1").arg(i.key()).toLatin1());
delete i.value();
}
}
clearPixmapCache();
}
QString CardInfo::getMainCardType() const
@ -114,9 +105,10 @@ QPixmap *CardInfo::loadPixmap()
{
if (pixmap)
return pixmap;
QString picsPath = db->getPicsPath();
pixmap = new QPixmap();
if (getName().isEmpty()) {
pixmap->load("../pics/back.jpg");
pixmap->load(QString("%1/back.jpg").arg(picsPath));
return pixmap;
}
sets.sortByKey();
@ -129,9 +121,9 @@ QPixmap *CardInfo::loadPixmap()
for (int i = 0; i < sets.size(); i++) {
// Fire // Ice, Circle of Protection: Red
QString correctedName = getName().remove(" // ").remove(":");
if (pixmap->load(QString("../pics/%1/%2.full.jpg").arg(sets[i]->getShortName()).arg(correctedName)))
if (pixmap->load(QString("%1/%2/%3.full.jpg").arg(picsPath).arg(sets[i]->getShortName()).arg(correctedName)))
return pixmap;
if (pixmap->load(QString("../pics/%1/%2%3.full.jpg").arg(sets[i]->getShortName()).arg(correctedName).arg(1)))
if (pixmap->load(QString("%1/%2/%3%4.full.jpg").arg(picsPath).arg(sets[i]->getShortName()).arg(correctedName).arg(1)))
return pixmap;
}
return pixmap;
@ -161,6 +153,22 @@ QPixmap *CardInfo::getPixmap(QSize size)
return result;
}
void CardInfo::clearPixmapCache()
{
if (pixmap) {
qDebug(QString("Deleting pixmap for %1").arg(name).toLatin1());
delete pixmap;
pixmap = 0;
QMapIterator<int, QPixmap *> i(scaledPixmapCache);
while (i.hasNext()) {
i.next();
qDebug(QString(" Deleting cached pixmap for width %1").arg(i.key()).toLatin1());
delete i.value();
}
scaledPixmapCache.clear();
}
}
QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info)
{
xml.writeStartElement("card");
@ -181,8 +189,12 @@ QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info)
return xml;
}
CardDatabase::CardDatabase()
CardDatabase::CardDatabase(QObject *parent)
: QObject(parent), noCard(0)
{
updateDatabasePath();
updatePicsPath();
noCard = new CardInfo(this);
noCard->loadPixmap(); // cache pixmap for card back
}
@ -247,6 +259,17 @@ SetList CardDatabase::getSetList() const
return result;
}
void CardDatabase::clearPixmapCache()
{
QHashIterator<QString, CardInfo *> i(cardHash);
while (i.hasNext()) {
i.next();
i.value()->clearPixmapCache();
}
if (noCard)
noCard->clearPixmapCache();
}
void CardDatabase::importOracleFile(const QString &fileName, CardSet *set)
{
QFile file(fileName);
@ -424,3 +447,25 @@ bool CardDatabase::saveToFile(const QString &fileName)
return true;
}
void CardDatabase::updatePicsPath(const QString &path)
{
if (path.isEmpty()) {
QSettings settings;
settings.beginGroup("paths");
picsPath = settings.value("pics").toString();
} else
picsPath = path;
clearPixmapCache();
}
void CardDatabase::updateDatabasePath(const QString &path)
{
if (path.isEmpty()) {
QSettings settings;
settings.beginGroup("paths");
cardDatabasePath = settings.value("carddatabase").toString();
} else
cardDatabasePath = path;
loadFromFile(cardDatabasePath);
}

View file

@ -66,30 +66,36 @@ public:
void addToSet(CardSet *set);
QPixmap *loadPixmap();
QPixmap *getPixmap(QSize size);
void clearPixmapCache();
};
class CardDatabase {
class CardDatabase : public QObject {
Q_OBJECT
private:
QHash<QString, CardInfo *> cardHash;
QHash<QString, CardSet *> setHash;
CardInfo *noCard;
static const unsigned int magicNumber = 0x12345678;
static const unsigned int fileVersion = 1;
QString picsPath, cardDatabasePath;
void loadCardsFromXml(QXmlStreamReader &xml);
void loadSetsFromXml(QXmlStreamReader &xml);
public:
CardDatabase();
CardDatabase(QObject *parent = 0);
~CardDatabase();
void clear();
CardInfo *getCard(const QString &cardName = QString());
CardSet *getSet(const QString &setName);
QList<CardInfo *> getCardList() const { return cardHash.values(); }
SetList getSetList() const;
void clearPixmapCache();
void importOracleFile(const QString &fileName, CardSet *set);
void importOracleDir();
int loadFromFile(const QString &fileName);
bool saveToFile(const QString &fileName);
const QString &getPicsPath() const { return picsPath; }
public slots:
void updatePicsPath(const QString &path = QString());
void updateDatabasePath(const QString &path = QString());
};
#endif

View file

@ -8,30 +8,30 @@
CardInfoWidget::CardInfoWidget(CardDatabase *_db, QWidget *parent)
: QFrame(parent), db(_db), pixmapHeight(pixmapWidth)
{
cardPicture = new QLabel();
cardPicture = new QLabel;
cardPicture->setAlignment(Qt::AlignCenter);
QFont f;
f.setPixelSize(11);
nameLabel1 = new QLabel(tr("Name:"));
nameLabel1 = new QLabel;
nameLabel1->setFont(f);
nameLabel2 = new QLabel();
nameLabel2 = new QLabel;
nameLabel2->setWordWrap(true);
nameLabel2->setFont(f);
manacostLabel1 = new QLabel(tr("Mana cost:"));
manacostLabel1 = new QLabel;
manacostLabel1->setFont(f);
manacostLabel2 = new QLabel();
manacostLabel2 = new QLabel;
manacostLabel2->setFont(f);
manacostLabel2->setWordWrap(true);
cardtypeLabel1 = new QLabel(tr("Card type:"));
cardtypeLabel1 = new QLabel;
cardtypeLabel1->setFont(f);
cardtypeLabel2 = new QLabel();
cardtypeLabel2 = new QLabel;
cardtypeLabel2->setFont(f);
cardtypeLabel2->setWordWrap(true);
powtoughLabel1 = new QLabel(tr("P / T:"));
powtoughLabel1 = new QLabel;
powtoughLabel1->setFont(f);
powtoughLabel2 = new QLabel();
powtoughLabel2 = new QLabel;
powtoughLabel2->setFont(f);
textLabel = new QTextEdit();
@ -60,6 +60,7 @@ CardInfoWidget::CardInfoWidget(CardDatabase *_db, QWidget *parent)
pixmapHeight = pixmapWidth * bigPixmap->height() / bigPixmap->width();
setCard(cardBack);
retranslateUi();
setFrameStyle(QFrame::Panel | QFrame::Raised);
setFixedSize(sizeHint());
}
@ -86,3 +87,11 @@ void CardInfoWidget::setCard(const QString &cardName)
{
setCard(db->getCard(cardName));
}
void CardInfoWidget::retranslateUi()
{
nameLabel1->setText(tr("Name:"));
manacostLabel1->setText(tr("Mana cost:"));
cardtypeLabel1->setText(tr("Card type:"));
powtoughLabel1->setText(tr("P / T:"));
}

View file

@ -22,6 +22,7 @@ private:
QTextEdit *textLabel;
public:
CardInfoWidget(CardDatabase *_db, QWidget *parent = 0);
void retranslateUi();
public slots:
void setCard(CardInfo *card);
void setCard(const QString &cardName);

View file

@ -1,37 +1,64 @@
#include <QtGui>
#include "carddatabase.h"
#include "dlg_settings.h"
GeneralSettingsPage::GeneralSettingsPage()
{
QGroupBox *personalGroupBox = new QGroupBox(tr("Personal settings"));
QLabel *languageLabel = new QLabel(tr("Language:"));
QComboBox *languageBox = new QComboBox;
QSettings settings;
personalGroupBox = new QGroupBox;
languageLabel = new QLabel;
languageBox = new QComboBox;
settings.beginGroup("personal");
QString setLanguage = settings.value("lang").toString();
QStringList qmFiles = findQmFiles();
for (int i = 0; i < qmFiles.size(); i++)
languageBox->addItem(languageName(qmFiles[i]), qmFiles[i]);
for (int i = 0; i < qmFiles.size(); i++) {
QString langName = languageName(qmFiles[i]);
languageBox->addItem(langName, qmFiles[i]);
if ((qmFiles[i] == settings.value("lang").toString()) || (setLanguage.isEmpty() && langName == tr("English")))
languageBox->setCurrentIndex(i);
}
settings.endGroup();
connect(languageBox, SIGNAL(currentIndexChanged(int)), this, SLOT(languageBoxChanged(int)));
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;
pathsGroupBox = new QGroupBox;
settings.beginGroup("paths");
deckPathLabel = new QLabel;
deckPathEdit = new QLineEdit(settings.value("decks").toString());
deckPathEdit->setReadOnly(true);
QPushButton *deckPathButton = new QPushButton("...");
connect(deckPathButton, SIGNAL(clicked()), this, SLOT(deckPathButtonClicked()));
picsPathLabel = new QLabel;
picsPathEdit = new QLineEdit(settings.value("pics").toString());
picsPathEdit->setReadOnly(true);
QPushButton *picsPathButton = new QPushButton("...");
connect(picsPathButton, SIGNAL(clicked()), this, SLOT(picsPathButtonClicked()));
cardDatabasePathLabel = new QLabel;
cardDatabasePathEdit = new QLineEdit(settings.value("carddatabase").toString());
cardDatabasePathEdit->setReadOnly(true);
QPushButton *cardDatabasePathButton = new QPushButton("...");
connect(cardDatabasePathButton, SIGNAL(clicked()), this, SLOT(cardDatabasePathButtonClicked()));
QGridLayout *pathsGrid = new QGridLayout;
pathsGrid->addWidget(deckPathLabel, 0, 0);
pathsGrid->addWidget(deckPathEdit, 0, 1);
pathsGrid->addWidget(deckPathButton, 0, 2);
pathsGrid->addWidget(picsPathLabel, 1, 0);
pathsGrid->addWidget(picsPathEdit, 1, 1);
pathsGrid->addWidget(picsPathButton, 1, 2);
pathsGrid->addWidget(cardDatabasePathLabel, 2, 0);
pathsGrid->addWidget(cardDatabasePathEdit, 2, 1);
pathsGrid->addWidget(cardDatabasePathButton, 2, 2);
pathsGroupBox->setLayout(pathsGrid);
QVBoxLayout *mainLayout = new QVBoxLayout;
@ -61,16 +88,77 @@ QString GeneralSettingsPage::languageName(const QString &qmFile)
return translator.translate("GeneralSettingsPage", "English");
}
void GeneralSettingsPage::deckPathButtonClicked()
{
QString path = QFileDialog::getExistingDirectory(this, tr("Choose path"));
if (path.isEmpty())
return;
QSettings settings;
settings.beginGroup("paths");
settings.setValue("decks", path);
deckPathEdit->setText(path);
}
void GeneralSettingsPage::picsPathButtonClicked()
{
QString path = QFileDialog::getExistingDirectory(this, tr("Choose path"));
if (path.isEmpty())
return;
QSettings settings;
settings.beginGroup("paths");
settings.setValue("pics", path);
picsPathEdit->setText(path);
emit picsPathChanged(path);
}
void GeneralSettingsPage::cardDatabasePathButtonClicked()
{
QString path = QFileDialog::getOpenFileName(this, tr("Choose path"));
if (path.isEmpty())
return;
QSettings settings;
settings.beginGroup("paths");
settings.setValue("carddatabase", path);
cardDatabasePathEdit->setText(path);
emit cardDatabasePathChanged(path);
}
void GeneralSettingsPage::languageBoxChanged(int index)
{
QString qmFile = languageBox->itemData(index).toString();
QSettings settings;
settings.beginGroup("personal");
settings.setValue("lang", qmFile);
emit changeLanguage(qmFile);
}
void GeneralSettingsPage::retranslateUi()
{
personalGroupBox->setTitle(tr("Personal settings"));
languageLabel->setText(tr("Language:"));
pathsGroupBox->setTitle(tr("Paths"));
deckPathLabel->setText(tr("Decks directory:"));
picsPathLabel->setText(tr("Pictures directory:"));
cardDatabasePathLabel->setText(tr("Path to card database:"));
}
AppearanceSettingsPage::AppearanceSettingsPage()
{
}
void AppearanceSettingsPage::retranslateUi()
{
}
MessagesSettingsPage::MessagesSettingsPage()
{
aAdd = new QAction(tr("Add"), this);
aAdd = new QAction(this);
connect(aAdd, SIGNAL(triggered()), this, SLOT(actAdd()));
aRemove = new QAction(tr("Remove"), this);
aRemove = new QAction(this);
connect(aRemove, SIGNAL(triggered()), this, SLOT(actRemove()));
messageList = new QListWidget;
@ -90,6 +178,8 @@ MessagesSettingsPage::MessagesSettingsPage()
mainLayout->addWidget(messageToolBar);
setLayout(mainLayout);
retranslateUi();
}
void MessagesSettingsPage::storeSettings()
@ -119,8 +209,14 @@ void MessagesSettingsPage::actRemove()
}
}
DlgSettings::DlgSettings()
: QDialog()
void MessagesSettingsPage::retranslateUi()
{
aAdd->setText(tr("&Add"));
aRemove->setText(tr("&Remove"));
}
DlgSettings::DlgSettings(CardDatabase *_db, QTranslator *_translator, QWidget *parent)
: QDialog(parent), db(_db), translator(_translator)
{
contentsWidget = new QListWidget;
contentsWidget->setViewMode(QListView::IconMode);
@ -130,11 +226,15 @@ DlgSettings::DlgSettings()
contentsWidget->setSpacing(12);
pagesWidget = new QStackedWidget;
pagesWidget->addWidget(new GeneralSettingsPage);
GeneralSettingsPage *general = new GeneralSettingsPage;
connect(general, SIGNAL(picsPathChanged(const QString &)), db, SLOT(updatePicsPath(const QString &)));
connect(general, SIGNAL(cardDatabasePathChanged(const QString &)), db, SLOT(updateDatabasePath(const QString &)));
connect(general, SIGNAL(changeLanguage(const QString &)), this, SLOT(changeLanguage(const QString &)));
pagesWidget->addWidget(general);
pagesWidget->addWidget(new AppearanceSettingsPage);
pagesWidget->addWidget(new MessagesSettingsPage);
QPushButton *closeButton = new QPushButton(tr("&Close"));
closeButton = new QPushButton;
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
createIcons();
@ -155,23 +255,20 @@ DlgSettings::DlgSettings()
mainLayout->addLayout(buttonsLayout);
setLayout(mainLayout);
setWindowTitle(tr("Settings"));
retranslateUi();
}
void DlgSettings::createIcons()
{
QListWidgetItem *generalButton = new QListWidgetItem(contentsWidget);
generalButton->setText(tr("General"));
generalButton = new QListWidgetItem(contentsWidget);
generalButton->setTextAlignment(Qt::AlignHCenter);
generalButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
QListWidgetItem *appearanceButton = new QListWidgetItem(contentsWidget);
appearanceButton->setText(tr("Appearance"));
appearanceButton = new QListWidgetItem(contentsWidget);
appearanceButton->setTextAlignment(Qt::AlignHCenter);
appearanceButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
QListWidgetItem *messagesButton = new QListWidgetItem(contentsWidget);
messagesButton->setText(tr("Messages"));
messagesButton = new QListWidgetItem(contentsWidget);
messagesButton->setTextAlignment(Qt::AlignHCenter);
messagesButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
@ -185,3 +282,31 @@ void DlgSettings::changePage(QListWidgetItem *current, QListWidgetItem *previous
pagesWidget->setCurrentIndex(contentsWidget->row(current));
}
void DlgSettings::changeLanguage(const QString &qmFile)
{
qApp->removeTranslator(translator);
translator->load(qmFile);
qApp->installTranslator(translator);
}
void DlgSettings::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();
QDialog::changeEvent(event);
}
void DlgSettings::retranslateUi()
{
setWindowTitle(tr("Settings"));
generalButton->setText(tr("General"));
appearanceButton->setText(tr("Appearance"));
messagesButton->setText(tr("Messages"));
closeButton->setText(tr("&Close"));
for (int i = 0; i < pagesWidget->count(); i++)
dynamic_cast<AbstractSettingsPage *>(pagesWidget->widget(i))->retranslateUi();
}

View file

@ -3,29 +3,57 @@
#include <QDialog>
class CardDatabase;
class QTranslator;
class QListWidget;
class QListWidgetItem;
class QStackedWidget;
class QLineEdit;
class QPushButton;
class QComboBox;
class QGroupBox;
class QLabel;
class GeneralSettingsPage : public QWidget {
class AbstractSettingsPage : public QWidget {
public:
virtual void retranslateUi() = 0;
};
class GeneralSettingsPage : public AbstractSettingsPage {
Q_OBJECT
public:
GeneralSettingsPage();
void retranslateUi();
private slots:
void deckPathButtonClicked();
void picsPathButtonClicked();
void cardDatabasePathButtonClicked();
void languageBoxChanged(int index);
signals:
void picsPathChanged(const QString &path);
void cardDatabasePathChanged(const QString &path);
void changeLanguage(const QString &qmFile);
private:
QStringList findQmFiles();
QString languageName(const QString &qmFile);
QLineEdit *deckPathEdit, *picsPathEdit, *cardDatabasePathEdit;
QGroupBox *personalGroupBox, *pathsGroupBox;
QComboBox *languageBox;
QLabel *languageLabel, *deckPathLabel, *picsPathLabel, *cardDatabasePathLabel;
};
class AppearanceSettingsPage : public QWidget {
class AppearanceSettingsPage : public AbstractSettingsPage {
Q_OBJECT
public:
AppearanceSettingsPage();
void retranslateUi();
};
class MessagesSettingsPage : public QWidget {
class MessagesSettingsPage : public AbstractSettingsPage {
Q_OBJECT
public:
MessagesSettingsPage();
void retranslateUi();
private slots:
void actAdd();
void actRemove();
@ -39,13 +67,21 @@ private:
class DlgSettings : public QDialog {
Q_OBJECT
public:
DlgSettings();
public slots:
DlgSettings(CardDatabase *_db, QTranslator *_translator, QWidget *parent = 0);
private slots:
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
void changeLanguage(const QString &qmFile);
private:
CardDatabase *db;
QTranslator *translator;
QListWidget *contentsWidget;
QStackedWidget *pagesWidget;
QListWidgetItem *generalButton, *appearanceButton, *messagesButton;
QPushButton *closeButton;
void createIcons();
void retranslateUi();
protected:
void changeEvent(QEvent *event);
};
#endif

View file

@ -22,6 +22,9 @@
#include <QApplication>
#include <QTextCodec>
#include <QtPlugin>
#include <QTranslator>
#include <QLibraryInfo>
#include <QSettings>
#include <stdio.h>
#include "window_main.h"
@ -48,10 +51,25 @@ int main(int argc, char *argv[])
QCoreApplication::setOrganizationDomain("cockatrice.de");
QCoreApplication::setApplicationName("Cockatrice");
MainWindow *ui = new MainWindow;
QString localeName = QLocale::system().name();
QTranslator qtTranslator;
qtTranslator.load("qt_" + localeName, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qtTranslator);
QTranslator translator;
QSettings settings;
settings.beginGroup("personal");
QString lang = settings.value("lang").toString();
if (lang.isEmpty())
translator.load("cockatrice_" + localeName, ":/translations", QString(), ".qm");
else
translator.load(lang);
app.installTranslator(&translator);
MainWindow ui(&translator);
qDebug("main(): MainWindow constructor finished");
ui->show();
qDebug("main(): ui->show() finished");
ui.show();
qDebug("main(): ui.show() finished");
return app.exec();
}

View file

@ -133,7 +133,7 @@ void MainWindow::actFullScreen(bool checked)
void MainWindow::actSettings()
{
DlgSettings dlg;
DlgSettings dlg(db, translator, this);
dlg.exec();
}
@ -180,40 +180,61 @@ void MainWindow::serverTimeout()
QMessageBox::critical(this, tr("Error"), tr("Server timeout"));
}
void MainWindow::retranslateUi()
{
aConnect->setText(tr("&Connect..."));
aDisconnect->setText(tr("&Disconnect"));
aRestartGame->setText(tr("&Restart game..."));
aRestartGame->setShortcut(tr("F2"));
aLeaveGame->setText(tr("&Leave game"));
aDeckEditor->setText(tr("&Deck editor"));
aFullScreen->setText(tr("&Full screen"));
aFullScreen->setShortcut(tr("Ctrl+F"));
aSettings->setText(tr("&Settings..."));
aExit->setText(tr("&Exit"));
aCloseMostRecentZoneView->setText(tr("Close most recent zone view"));
aCloseMostRecentZoneView->setShortcut(tr("Esc"));
gameMenu->setTitle(tr("&Game"));
actionsMenu->setTitle(tr("&Actions"));
cardMenu->setTitle(tr("&Card"));
sayLabel->setText(tr("&Say:"));
cardInfo->retranslateUi();
}
void MainWindow::createActions()
{
aConnect = new QAction(tr("&Connect..."), this);
aConnect = new QAction(this);
connect(aConnect, SIGNAL(triggered()), this, SLOT(actConnect()));
aDisconnect = new QAction(tr("&Disconnect"), this);
aDisconnect = new QAction(this);
aDisconnect->setEnabled(false);
connect(aDisconnect, SIGNAL(triggered()), this, SLOT(actDisconnect()));
aRestartGame = new QAction(tr("&Restart game..."), this);
aRestartGame->setShortcut(tr("F2"));
aRestartGame = new QAction(this);
aRestartGame->setEnabled(false);
connect(aRestartGame, SIGNAL(triggered()), this, SLOT(actRestartGame()));
aLeaveGame = new QAction(tr("&Leave game"), this);
aLeaveGame = new QAction(this);
aLeaveGame->setEnabled(false);
connect(aLeaveGame, SIGNAL(triggered()), this, SLOT(actLeaveGame()));
aDeckEditor = new QAction(tr("&Deck editor"), this);
aDeckEditor = new QAction(this);
connect(aDeckEditor, SIGNAL(triggered()), this, SLOT(actDeckEditor()));
aFullScreen = new QAction(tr("&Full screen"), this);
aFullScreen->setShortcut(tr("Ctrl+F"));
aFullScreen = new QAction(this);
aFullScreen->setCheckable(true);
connect(aFullScreen, SIGNAL(toggled(bool)), this, SLOT(actFullScreen(bool)));
aSettings = new QAction(tr("&Settings..."), this);
aSettings = new QAction(this);
connect(aSettings, SIGNAL(triggered()), this, SLOT(actSettings()));
aExit = new QAction(tr("&Exit"), this);
aExit = new QAction(this);
connect(aExit, SIGNAL(triggered()), this, SLOT(actExit()));
aCloseMostRecentZoneView = new QAction(tr("Close most recent zone view"), this);
aCloseMostRecentZoneView->setShortcut(tr("Esc"));
aCloseMostRecentZoneView = new QAction(this);
connect(aCloseMostRecentZoneView, SIGNAL(triggered()), zoneLayout, SLOT(closeMostRecentZoneView()));
addAction(aCloseMostRecentZoneView);
}
void MainWindow::createMenus()
{
gameMenu = menuBar()->addMenu(tr("&Game"));
gameMenu = menuBar()->addMenu(QString());
gameMenu->addAction(aConnect);
gameMenu->addAction(aDisconnect);
gameMenu->addSeparator();
@ -228,18 +249,17 @@ void MainWindow::createMenus()
gameMenu->addSeparator();
gameMenu->addAction(aExit);
actionsMenu = menuBar()->addMenu(tr("&Actions"));
actionsMenu = menuBar()->addMenu(QString());
cardMenu = menuBar()->addMenu(tr("&Card"));
cardMenu = menuBar()->addMenu(QString());
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), game(NULL)
MainWindow::MainWindow(QTranslator *_translator, QWidget *parent)
: QMainWindow(parent), game(NULL), translator(_translator)
{
QPixmapCache::setCacheLimit(200000);
db = new CardDatabase;
db->loadFromFile("../cards.xml");
db = new CardDatabase(this);
// db->importOracleDir();
// db->saveToFile("../cards.xml");
@ -255,7 +275,7 @@ MainWindow::MainWindow(QWidget *parent)
cardInfo = new CardInfoWidget(db);
messageLog = new MessageLogWidget;
QLabel *sayLabel = new QLabel(tr("&Say:"));
sayLabel = new QLabel;
sayEdit = new QLineEdit;
sayLabel->setBuddy(sayEdit);
@ -294,8 +314,18 @@ MainWindow::MainWindow(QWidget *parent)
createActions();
createMenus();
retranslateUi();
}
void MainWindow::closeEvent(QCloseEvent */*event*/)
{
delete game;
}
void MainWindow::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();
QMainWindow::changeEvent(event);
}

View file

@ -29,9 +29,11 @@ class Game;
class CardDatabase;
class Player;
class QTranslator;
class QVBoxLayout;
class CardInfoWidget;
class MessageLogWidget;
class QLabel;
class QLineEdit;
class QPushButton;
class ServerZoneCard;
@ -64,6 +66,7 @@ signals:
void logConnecting(QString hostname);
void logDisconnected();
private:
void retranslateUi();
void createActions();
void createMenus();
QMenu *gameMenu, *actionsMenu, *cardMenu;
@ -73,6 +76,7 @@ private:
CardInfoWidget *cardInfo;
MessageLogWidget *messageLog;
QLabel *sayLabel;
QLineEdit *sayEdit;
Client *client;
@ -81,10 +85,12 @@ private:
Game *game;
CardDatabase *db;
ZoneViewLayout *zoneLayout;
QTranslator *translator;
public:
MainWindow(QWidget *parent = 0);
MainWindow(QTranslator *_translator, QWidget *parent = 0);
protected:
void closeEvent(QCloseEvent *event);
void changeEvent(QEvent *event);
};
#endif

View file

@ -209,27 +209,27 @@
<context>
<name>DlgSettings</name>
<message>
<location filename="../src/dlg_settings.cpp" line="158"/>
<location filename="../src/dlg_settings.cpp" line="302"/>
<source>Settings</source>
<translation>Einstellungen</translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="164"/>
<location filename="../src/dlg_settings.cpp" line="304"/>
<source>General</source>
<translation>Allgemeines</translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="169"/>
<location filename="../src/dlg_settings.cpp" line="305"/>
<source>Appearance</source>
<translation>Erscheinungsbild</translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="174"/>
<location filename="../src/dlg_settings.cpp" line="306"/>
<source>Messages</source>
<translation>Nachrichten</translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="137"/>
<location filename="../src/dlg_settings.cpp" line="308"/>
<source>&amp;Close</source>
<translation>S&amp;chließen</translation>
</message>
@ -543,37 +543,45 @@
<context>
<name>GeneralSettingsPage</name>
<message>
<location filename="../src/dlg_settings.cpp" line="7"/>
<location filename="../src/dlg_settings.cpp" line="93"/>
<location filename="../src/dlg_settings.cpp" line="104"/>
<location filename="../src/dlg_settings.cpp" line="117"/>
<source>Choose path</source>
<translation>Pfad auswählen</translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="139"/>
<source>Personal settings</source>
<translation>Persönliche Einstellungen</translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="8"/>
<location filename="../src/dlg_settings.cpp" line="140"/>
<source>Language:</source>
<translation>Sprache:</translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="20"/>
<location filename="../src/dlg_settings.cpp" line="141"/>
<source>Paths</source>
<translation>Pfade</translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="21"/>
<location filename="../src/dlg_settings.cpp" line="142"/>
<source>Decks directory:</source>
<translation>Verzeichnis mit Decklisten:</translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="23"/>
<location filename="../src/dlg_settings.cpp" line="143"/>
<source>Pictures directory:</source>
<translation>Verzeichnis mit Bilddateien:</translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="25"/>
<location filename="../src/dlg_settings.cpp" line="144"/>
<source>Path to card database:</source>
<translation>Pfad zur Kartendatenbank:</translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="61"/>
<location filename="../src/dlg_settings.cpp" line="20"/>
<location filename="../src/dlg_settings.cpp" line="88"/>
<source>English</source>
<translation>Deutsch</translation>
</message>
@ -666,7 +674,7 @@
<translation>&amp;Karte</translation>
</message>
<message>
<location filename="../src/window_main.cpp" line="258"/>
<location filename="../src/window_main.cpp" line="257"/>
<source>&amp;Say:</source>
<translation>&amp;Sagen:</translation>
</message>
@ -797,22 +805,30 @@
<context>
<name>MessagesSettingsPage</name>
<message>
<location filename="../src/dlg_settings.cpp" line="71"/>
<location filename="../src/dlg_settings.cpp" line="214"/>
<source>&amp;Add</source>
<translation>&amp;Hinzufügen</translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="215"/>
<source>&amp;Remove</source>
<translation>&amp;Entfernen</translation>
</message>
<message>
<source>Add</source>
<translation>Hinzufügen</translation>
<translation type="obsolete">Hinzufügen</translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="73"/>
<source>Remove</source>
<translation>Entfernen</translation>
<translation type="obsolete">Entfernen</translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="107"/>
<location filename="../src/dlg_settings.cpp" line="197"/>
<source>Add message</source>
<translation>Nachricht hinzufügen</translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="107"/>
<location filename="../src/dlg_settings.cpp" line="197"/>
<source>Message:</source>
<translation>Nachricht:</translation>
</message>

View file

@ -173,27 +173,27 @@
<context>
<name>DlgSettings</name>
<message>
<location filename="../src/dlg_settings.cpp" line="158"/>
<location filename="../src/dlg_settings.cpp" line="302"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="164"/>
<location filename="../src/dlg_settings.cpp" line="304"/>
<source>General</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="169"/>
<location filename="../src/dlg_settings.cpp" line="305"/>
<source>Appearance</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="174"/>
<location filename="../src/dlg_settings.cpp" line="306"/>
<source>Messages</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="137"/>
<location filename="../src/dlg_settings.cpp" line="308"/>
<source>&amp;Close</source>
<translation type="unfinished"></translation>
</message>
@ -499,37 +499,45 @@
<context>
<name>GeneralSettingsPage</name>
<message>
<location filename="../src/dlg_settings.cpp" line="7"/>
<location filename="../src/dlg_settings.cpp" line="93"/>
<location filename="../src/dlg_settings.cpp" line="104"/>
<location filename="../src/dlg_settings.cpp" line="117"/>
<source>Choose path</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="139"/>
<source>Personal settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="8"/>
<location filename="../src/dlg_settings.cpp" line="140"/>
<source>Language:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="20"/>
<location filename="../src/dlg_settings.cpp" line="141"/>
<source>Paths</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="21"/>
<location filename="../src/dlg_settings.cpp" line="142"/>
<source>Decks directory:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="23"/>
<location filename="../src/dlg_settings.cpp" line="143"/>
<source>Pictures directory:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="25"/>
<location filename="../src/dlg_settings.cpp" line="144"/>
<source>Path to card database:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="61"/>
<location filename="../src/dlg_settings.cpp" line="20"/>
<location filename="../src/dlg_settings.cpp" line="88"/>
<source>English</source>
<translation>English</translation>
</message>
@ -622,7 +630,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/window_main.cpp" line="258"/>
<location filename="../src/window_main.cpp" line="257"/>
<source>&amp;Say:</source>
<translation type="unfinished"></translation>
</message>
@ -753,22 +761,22 @@
<context>
<name>MessagesSettingsPage</name>
<message>
<location filename="../src/dlg_settings.cpp" line="71"/>
<source>Add</source>
<location filename="../src/dlg_settings.cpp" line="214"/>
<source>&amp;Add</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="73"/>
<source>Remove</source>
<location filename="../src/dlg_settings.cpp" line="215"/>
<source>&amp;Remove</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="107"/>
<location filename="../src/dlg_settings.cpp" line="197"/>
<source>Add message</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/dlg_settings.cpp" line="107"/>
<location filename="../src/dlg_settings.cpp" line="197"/>
<source>Message:</source>
<translation type="unfinished"></translation>
</message>