diff options
author | John Fultz <jfultz@wolfram.com> | 2015-08-03 19:30:11 -0500 |
---|---|---|
committer | John Fultz <jfultz@wolfram.com> | 2015-08-03 20:33:04 -0500 |
commit | b8024ae268e49c17c40da105b9e22aaa41fcffeb (patch) | |
tree | 1edb58d6f7d6470c55bc9e4840c9f96b7f4b0fdd | |
parent | 9eada6e94f345d0c1a2d93de5dc56613a93a3ea0 (diff) |
Finish Add/Edit/Remove for boards.
Delete functionality is now inside of the edit dialog.
Which will make things less messy when other
edit dialogs are introduced.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | quacker/boardsetupdialog.cpp | 21 | ||||
-rw-r--r-- | quacker/boardsetupdialog.h | 2 | ||||
-rw-r--r-- | quacker/settings.cpp | 64 | ||||
-rw-r--r-- | quacker/settings.h | 1 | ||||
-rw-r--r-- | quackle.sublime-project | 2 |
6 files changed, 41 insertions, 50 deletions
@@ -20,3 +20,4 @@ ChangeLog dawginput.raw playabilities.raw smaller.raw +DerivedData diff --git a/quacker/boardsetupdialog.cpp b/quacker/boardsetupdialog.cpp index 7198b17..379f79d 100644 --- a/quacker/boardsetupdialog.cpp +++ b/quacker/boardsetupdialog.cpp @@ -58,6 +58,7 @@ BoardSetupDialog::BoardSetupDialog(QWidget *parent) : QDialog(parent) m_saveChanges = new QPushButton(tr("&Save Changes")); m_cancel = new QPushButton(tr("&Cancel")); m_undoAll = new QPushButton(tr("&Undo All Changes")); + m_deleteBoard = new QPushButton(tr("&Delete Board")); QVBoxLayout * superLayout = new QVBoxLayout; Geometry::setupFramedLayout(superLayout); @@ -96,6 +97,8 @@ BoardSetupDialog::BoardSetupDialog(QWidget *parent) : QDialog(parent) leftSideLayout->addWidget(dimensionGroup); leftSideLayout->addWidget(symmetryGroup); leftSideLayout->addWidget(m_undoAll); + if (!m_originalName.isEmpty()) + leftSideLayout->addWidget(m_deleteBoard); leftSideLayout->addStretch(); mainLayout->addLayout(leftSideLayout); @@ -118,6 +121,7 @@ BoardSetupDialog::BoardSetupDialog(QWidget *parent) : QDialog(parent) connect(m_saveChanges, SIGNAL(clicked()), this, SLOT(accept())); connect(m_cancel, SIGNAL(clicked()), this, SLOT(reject())); connect(m_undoAll, SIGNAL(clicked()), this, SLOT(undoAllChanges())); + connect(m_deleteBoard, SIGNAL(clicked()), this, SLOT(deleteBoard())); connect(m_horizontalSymmetry, SIGNAL(stateChanged(int)), this, SLOT(symmetryChanged())); connect(m_verticalSymmetry, SIGNAL(stateChanged(int)), this, SLOT(symmetryChanged())); connect(m_diagonalSymmetry, SIGNAL(stateChanged(int)), this, SLOT(symmetryChanged())); @@ -239,3 +243,20 @@ void BoardSetupDialog::undoAllChanges() QUACKLE_DATAMANAGER->setBoardParameters(Quackle::BoardParameters::Deserialize(boardStream)); parametersChanged(QString()); } + +void BoardSetupDialog::deleteBoard() +{ + QString message = "Do you really want to delete the game board \""; + message += m_originalName; + message += "\"?"; + if (QMessageBox::warning(NULL, QString("Confirm Deletion"), message, + QMessageBox::Yes | QMessageBox::Default, + QMessageBox::No | QMessageBox::Escape) == QMessageBox::Yes) + { + CustomQSettings settings; + settings.beginGroup("quackle/boardparameters"); + settings.remove(m_originalName); + QDialog::reject(); + } +} + diff --git a/quacker/boardsetupdialog.h b/quacker/boardsetupdialog.h index e5432cc..0176d1a 100644 --- a/quacker/boardsetupdialog.h +++ b/quacker/boardsetupdialog.h @@ -48,6 +48,7 @@ protected slots: void parametersChanged(const QString &unused); void symmetryChanged(); void undoAllChanges(); + void deleteBoard(); private: QCheckBox *m_horizontalSymmetry; @@ -62,6 +63,7 @@ private: QPushButton *m_saveChanges; QPushButton *m_cancel; QPushButton *m_undoAll; + QPushButton *m_deleteBoard; Quackle::Game m_game; BoardSetupFrame * m_boardFrame; diff --git a/quacker/settings.cpp b/quacker/settings.cpp index 67804ad..15448f5 100644 --- a/quacker/settings.cpp +++ b/quacker/settings.cpp @@ -148,7 +148,7 @@ void Settings::createGUI() themeNameLabel->setBuddy(m_themeNameCombo); m_editTheme = new QPushButton(tr("Edit...")); m_editTheme->setMaximumWidth(60); - connect(m_editTheme, SIGNAL(clicked()), this, SLOT(editTheme)); + connect(m_editTheme, SIGNAL(clicked()), this, SLOT(editTheme())); themeLayout->addWidget(themeNameLabel); themeLayout->addWidget(m_themeNameCombo); @@ -160,41 +160,19 @@ void Settings::createGUI() QStringList boardItems; populateListFromFilenames(boardItems, "boards"); m_boardNameCombo->addItems(boardItems); + m_boardNameCombo->addItem(tr("Add new board...")); QHBoxLayout *boardLayout = new QHBoxLayout; QLabel *boardNameLabel = new QLabel(tr("&Board:")); boardNameLabel->setBuddy(m_boardNameCombo); m_editBoard = new QPushButton(tr("Edit...")); m_editBoard->setMaximumWidth(60); - connect(m_editBoard, SIGNAL(clicked()), this, SLOT(editBoard)); + connect(m_editBoard, SIGNAL(clicked()), this, SLOT(editBoard())); boardLayout->addWidget(boardNameLabel); boardLayout->addWidget(m_boardNameCombo); boardLayout->addWidget(m_editBoard); - // m_addBoard = new QPushButton(tr("Add Board")); - // connect(m_addBoard, SIGNAL(clicked()), this, SLOT(addBoard())); - - // m_editBoard = new QPushButton(tr("&Edit Board")); - // connect(m_editBoard, SIGNAL(clicked()), this, SLOT(editBoard())); - - // m_deleteBoard = new QPushButton(tr("&Delete Board")); - // connect(m_deleteBoard, SIGNAL(clicked()), this, SLOT(deleteBoard())); - - // loadBoardNameCombo(); - - // QGroupBox *boardGroup = new QGroupBox("Game Board Definitions"); - // QGridLayout *boardLayout = new QGridLayout(boardGroup); - // QLabel *boardNameLabel = new QLabel(tr("&Board:")); - // boardNameLabel->setBuddy(m_boardNameCombo); - - // boardLayout->addWidget(boardNameLabel, 0, 0); - // boardLayout->addWidget(m_boardNameCombo, 0, 1, 1, -1); - // boardLayout->addWidget(m_addBoard, 1, 0); - // boardLayout->addWidget(m_editBoard, 1, 1); - // boardLayout->addWidget(m_deleteBoard, 1, 2); - - vlayout->addLayout(lexiconLayout); vlayout->addLayout(alphabetLayout); vlayout->addLayout(themeLayout); @@ -357,6 +335,11 @@ void Settings::themeChanged(const QString &themeName) void Settings::boardChanged(const QString &boardName) { + if (m_boardNameCombo->currentIndex() == m_boardNameCombo->count() - 1) + { + addBoard(); + return; + } CustomQSettings settings; settings.setValue("quackle/settings/board-name", boardName); @@ -383,6 +366,7 @@ void Settings::addBoard() (const uchar *)boardParameterStream.str().data(), boardParameterStream.str().size()); settings.setValue(boardName, QVariant(boardParameterBytes)); + m_boardNameCombo->setCurrentIndex(-1); boardChanged(boardName); } else @@ -416,28 +400,8 @@ void Settings::editBoard() boardChanged(newBoardName); } PixmapCacher::self()->invalidate(); -} - -void Settings::deleteBoard() -{ - int oldIndex = m_boardNameCombo->currentIndex(); - QString boardName = m_boardNameCombo->currentText(); - QString message = "Do you really want to delete the game board \""; - message += boardName; - message += "\"?"; - if (QMessageBox::warning(NULL, QString("Confirm Deletion"), message, - QMessageBox::Yes | QMessageBox::Default, - QMessageBox::No | QMessageBox::Escape) == QMessageBox::Yes) - { - CustomQSettings settings; - settings.beginGroup("quackle/boardparameters"); - settings.remove(boardName); - loadBoardNameCombo(); - if (oldIndex != 0) - oldIndex--; - m_boardNameCombo->setCurrentIndex(oldIndex); - boardChanged(m_boardNameCombo->currentText()); - } + loadBoardNameCombo(); + emit refreshViews(); } void Settings::loadBoardNameCombo() @@ -453,10 +417,14 @@ void Settings::loadBoardNameCombo() QStringList boardNames = settings.childKeys(); boardNames.sort(); m_boardNameCombo->addItems(boardNames); + m_boardNameCombo->addItem("Add new board..."); settings.endGroup(); QString currentItem = settings.value("quackle/settings/board-name", QString("")).toString(); - m_boardNameCombo->setCurrentIndex(m_boardNameCombo->findText(currentItem)); + int currentItemIndex = m_boardNameCombo->findText(currentItem); + if (m_boardNameCombo->count() > 0 && currentItemIndex < 0) + currentItemIndex = 0; + m_boardNameCombo->setCurrentIndex(currentItemIndex); } void Settings::populateListFromFilenames(QStringList& list, const QString &path) diff --git a/quacker/settings.h b/quacker/settings.h index 5a05452..bc0e8fa 100644 --- a/quacker/settings.h +++ b/quacker/settings.h @@ -64,7 +64,6 @@ protected slots: void addBoard(); void editBoard(); - void deleteBoard(); void setQuackleToUseLexiconName(const string &lexiconName); void setQuackleToUseAlphabetName(const string &alphabetName); diff --git a/quackle.sublime-project b/quackle.sublime-project index 167db4b..a219eb1 100644 --- a/quackle.sublime-project +++ b/quackle.sublime-project @@ -7,7 +7,7 @@ "playabilities.raw", "smaller.raw", ".gitattributes", "*.Debug", "*.Release", "*.pfx", "*.cer"], "folder_exclude_patterns" : ["obj", "moc", "build", "*.xcodeproj", "lib", "lexica", - "strategy", "debug", "release", "makeswelexicon", "lisp"] + "strategy", "debug", "release", "makeswelexicon", "lisp", "DerivedData"] } ] } |