Refactored User Interface tab

- removed heap allocs
This commit is contained in:
Matt Lowe 2015-01-17 17:50:04 +01:00
parent a599fa1a63
commit 5cf801eb94
2 changed files with 35 additions and 42 deletions

View file

@ -449,63 +449,54 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage()
{ {
QIcon deleteIcon(":/resources/icon_delete.svg"); QIcon deleteIcon(":/resources/icon_delete.svg");
notificationsEnabledCheckBox = new QCheckBox; notificationsEnabledCheckBox.setChecked(settingsCache->getNotificationsEnabled());
notificationsEnabledCheckBox->setChecked(settingsCache->getNotificationsEnabled()); connect(&notificationsEnabledCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setNotificationsEnabled(int)));
connect(notificationsEnabledCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setNotificationsEnabled(int)));
doubleClickToPlayCheckBox = new QCheckBox; doubleClickToPlayCheckBox.setChecked(settingsCache->getDoubleClickToPlay());
doubleClickToPlayCheckBox->setChecked(settingsCache->getDoubleClickToPlay()); connect(&doubleClickToPlayCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setDoubleClickToPlay(int)));
connect(doubleClickToPlayCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setDoubleClickToPlay(int)));
playToStackCheckBox = new QCheckBox; playToStackCheckBox.setChecked(settingsCache->getPlayToStack());
playToStackCheckBox->setChecked(settingsCache->getPlayToStack()); connect(&playToStackCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setPlayToStack(int)));
connect(playToStackCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setPlayToStack(int)));
QGridLayout *generalGrid = new QGridLayout; QGridLayout *generalGrid = new QGridLayout;
generalGrid->addWidget(notificationsEnabledCheckBox, 0, 0); generalGrid->addWidget(&notificationsEnabledCheckBox, 0, 0);
generalGrid->addWidget(doubleClickToPlayCheckBox, 1, 0); generalGrid->addWidget(&doubleClickToPlayCheckBox, 1, 0);
generalGrid->addWidget(playToStackCheckBox, 2, 0); generalGrid->addWidget(&playToStackCheckBox, 2, 0);
generalGroupBox = new QGroupBox; generalGroupBox = new QGroupBox;
generalGroupBox->setLayout(generalGrid); generalGroupBox->setLayout(generalGrid);
tapAnimationCheckBox = new QCheckBox; tapAnimationCheckBox.setChecked(settingsCache->getTapAnimation());
tapAnimationCheckBox->setChecked(settingsCache->getTapAnimation()); connect(&tapAnimationCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setTapAnimation(int)));
connect(tapAnimationCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setTapAnimation(int)));
soundEnabledCheckBox = new QCheckBox; soundEnabledCheckBox.setChecked(settingsCache->getSoundEnabled());
soundEnabledCheckBox->setChecked(settingsCache->getSoundEnabled()); connect(&soundEnabledCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setSoundEnabled(int)));
connect(soundEnabledCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setSoundEnabled(int)));
soundPathLabel = new QLabel;
soundPathEdit = new QLineEdit(settingsCache->getSoundPath()); soundPathEdit = new QLineEdit(settingsCache->getSoundPath());
soundPathEdit->setReadOnly(true); soundPathEdit->setReadOnly(true);
QPushButton *soundPathClearButton = new QPushButton(deleteIcon, QString()); QPushButton *soundPathClearButton = new QPushButton(deleteIcon, QString());
connect(soundPathClearButton, SIGNAL(clicked()), this, SLOT(soundPathClearButtonClicked())); connect(soundPathClearButton, SIGNAL(clicked()), this, SLOT(soundPathClearButtonClicked()));
QPushButton *soundPathButton = new QPushButton("..."); QPushButton *soundPathButton = new QPushButton("...");
connect(soundPathButton, SIGNAL(clicked()), this, SLOT(soundPathButtonClicked())); connect(soundPathButton, SIGNAL(clicked()), this, SLOT(soundPathButtonClicked()));
soundTestButton = new QPushButton(); connect(&soundTestButton, SIGNAL(clicked()), soundEngine, SLOT(cuckoo()));
connect(soundTestButton, SIGNAL(clicked()), soundEngine, SLOT(cuckoo()));
QGridLayout *soundGrid = new QGridLayout; QGridLayout *soundGrid = new QGridLayout;
soundGrid->addWidget(soundEnabledCheckBox, 0, 0, 1, 4); soundGrid->addWidget(&soundEnabledCheckBox, 0, 0, 1, 4);
soundGrid->addWidget(soundPathLabel, 1, 0); soundGrid->addWidget(&soundPathLabel, 1, 0);
soundGrid->addWidget(soundPathEdit, 1, 1); soundGrid->addWidget(soundPathEdit, 1, 1);
soundGrid->addWidget(soundPathClearButton, 1, 2); soundGrid->addWidget(soundPathClearButton, 1, 2);
soundGrid->addWidget(soundPathButton, 1, 3); soundGrid->addWidget(soundPathButton, 1, 3);
soundGrid->addWidget(soundTestButton, 2, 1); soundGrid->addWidget(&soundTestButton, 2, 1);
soundGroupBox = new QGroupBox; soundGroupBox = new QGroupBox;
soundGroupBox->setLayout(soundGrid); soundGroupBox->setLayout(soundGrid);
QGridLayout *animationGrid = new QGridLayout; QGridLayout *animationGrid = new QGridLayout;
animationGrid->addWidget(tapAnimationCheckBox, 0, 0); animationGrid->addWidget(&tapAnimationCheckBox, 0, 0);
animationGroupBox = new QGroupBox; animationGroupBox = new QGroupBox;
animationGroupBox->setLayout(animationGrid); animationGroupBox->setLayout(animationGrid);
QVBoxLayout *mainLayout = new QVBoxLayout; QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(generalGroupBox); mainLayout->addWidget(generalGroupBox);
mainLayout->addWidget(animationGroupBox); mainLayout->addWidget(animationGroupBox);
@ -517,14 +508,14 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage()
void UserInterfaceSettingsPage::retranslateUi() void UserInterfaceSettingsPage::retranslateUi()
{ {
generalGroupBox->setTitle(tr("General interface settings")); generalGroupBox->setTitle(tr("General interface settings"));
notificationsEnabledCheckBox->setText(tr("Enable notifications in taskbar")); notificationsEnabledCheckBox.setText(tr("Enable notifications in taskbar"));
doubleClickToPlayCheckBox->setText(tr("&Double-click cards to play them (instead of single-click)")); doubleClickToPlayCheckBox.setText(tr("&Double-click cards to play them (instead of single-click)"));
playToStackCheckBox->setText(tr("&Play all nonlands onto the stack (not the battlefield) by default")); playToStackCheckBox.setText(tr("&Play all nonlands onto the stack (not the battlefield) by default"));
animationGroupBox->setTitle(tr("Animation settings")); animationGroupBox->setTitle(tr("Animation settings"));
tapAnimationCheckBox->setText(tr("&Tap/untap animation")); tapAnimationCheckBox.setText(tr("&Tap/untap animation"));
soundEnabledCheckBox->setText(tr("Enable &sounds")); soundEnabledCheckBox.setText(tr("Enable &sounds"));
soundPathLabel->setText(tr("Path to sounds directory:")); soundPathLabel.setText(tr("Path to sounds directory:"));
soundTestButton->setText(tr("Test system sound engine")); soundTestButton.setText(tr("Test system sound engine"));
soundGroupBox->setTitle(tr("Sound settings")); soundGroupBox->setTitle(tr("Sound settings"));
} }

View file

@ -118,15 +118,17 @@ private slots:
signals: signals:
void soundPathChanged(); void soundPathChanged();
private: private:
QCheckBox *notificationsEnabledCheckBox; QCheckBox notificationsEnabledCheckBox;
QCheckBox *doubleClickToPlayCheckBox; QCheckBox doubleClickToPlayCheckBox;
QCheckBox *playToStackCheckBox; QCheckBox playToStackCheckBox;
QCheckBox *tapAnimationCheckBox; QCheckBox tapAnimationCheckBox;
QCheckBox *soundEnabledCheckBox; QCheckBox soundEnabledCheckBox;
QLabel *soundPathLabel; QLabel soundPathLabel;
QLineEdit *soundPathEdit; QLineEdit *soundPathEdit;
QGroupBox *generalGroupBox, *animationGroupBox, *soundGroupBox; QGroupBox *generalGroupBox;
QPushButton *soundTestButton; QGroupBox *animationGroupBox;
QGroupBox *soundGroupBox;
QPushButton soundTestButton;
public: public:
UserInterfaceSettingsPage(); UserInterfaceSettingsPage();
void retranslateUi(); void retranslateUi();