diff options
author | John Fultz <jfultz@wolfram.com> | 2013-12-30 03:15:50 -0600 |
---|---|---|
committer | John Fultz <jfultz@wolfram.com> | 2013-12-30 03:15:50 -0600 |
commit | 32c211a5487e0148a438b8c9d109e918e69e1ffa (patch) | |
tree | 5fef6001ff965ff887fdc429f1afdea6fbd414ac /quacker | |
parent | f3f60195ba3500c7d12b73f18343273e364025a1 (diff) |
Add color theme feature.
This allows you to choose between preset themes stored in .ini files
in the layout. While I was at it, I changed other things in the
Settings panel to auto-populate from the layout rather than have
hard-coded versions. So there's no longer a need to recompile
Quackle to add new languages or alphabets to get it to show up in
the popup menu.
Diffstat (limited to 'quacker')
-rw-r--r-- | quacker/graphicalboard.cpp | 42 | ||||
-rw-r--r-- | quacker/graphicalboard.h | 4 | ||||
-rw-r--r-- | quacker/settings.cpp | 128 | ||||
-rw-r--r-- | quacker/settings.h | 8 |
4 files changed, 128 insertions, 54 deletions
diff --git a/quacker/graphicalboard.cpp b/quacker/graphicalboard.cpp index 194d4c9..05ed86b 100644 --- a/quacker/graphicalboard.cpp +++ b/quacker/graphicalboard.cpp @@ -967,32 +967,40 @@ void PixmapCacher::cleanUp() PixmapCacher::PixmapCacher() { - arrowColor = QColor("black"); - letterColor = QColor("#6e6e6e"); - britishLetterColor = QColor("#703d3d"); + readTheme(""); +} + +void PixmapCacher::readTheme(const QString& themeFile) +{ + QSettings settings(themeFile, QSettings::IniFormat); + + arrowColor = QColor(settings.value("arrow", "black").toString()); + letterColor = QColor(settings.value("letter", "#6e6e6e").toString()); + britishLetterColor = QColor(settings.value("britishLetter", "#703d3d").toString()); // tiles on rack will be of different sizes and thus are slightly // altered to fool the pixmap cacher rackColor = letterColor.light(101); - DLSColor = QColor("cornflowerblue"); - TLSColor = QColor("slateblue"); - DWSColor = QColor("palevioletred"); - TWSColor = QColor("firebrick"); - - QLSColor = QColor("blueviolet").light(); - QWSColor = QColor("goldenrod"); + DLSColor = QColor(settings.value("DLS", "cornflowerblue").toString()); + TLSColor = QColor(settings.value("TLS", "slateblue").toString()); + DWSColor = QColor(settings.value("DWS", "palevioletred").toString()); + TWSColor = QColor(settings.value("TWS", "firebrick").toString()); + QLSColor = QColor(settings.value("QLS", "blueviolet").toString()); + QWSColor = QColor(settings.value("QWS", "goldenrod").toString()); + bonusTextColor = QColor(settings.value("bonusLabel", "gainsboro").toString()); - nothingColor = QColor("gainsboro"); + nothingColor = QColor(settings.value("nothing", "gainsboro").toString()); - cementedLetterTextColor = QColor("#f8f8ff"); - cementedBritishLetterTextColor = QColor("#FFC0C0"); - uncementedLetterTextColor = QColor("khaki"); + cementedLetterTextColor = QColor(settings.value("cementedLetterText", "#f8f8ff").toString()); + cementedBritishLetterTextColor = QColor(settings.value("cementedBritishLetterText", "#FFC0C0").toString()); + uncementedLetterTextColor = QColor(settings.value("uncementedLetterText", "khaki").toString()); - markColor = QColor("tan"); - markTextColor = markColor.dark(); + markColor = QColor(settings.value("mark", "tan").toString()); + markTextColor = QColor(settings.value("markLabel", "tan").toString()); } + bool PixmapCacher::contains(const QColor &color) const { return m_pixmaps.contains(color); @@ -1180,7 +1188,7 @@ QColor TileWidget::letterTextColor() else if (m_information.letter == QUACKLE_NULL_MARK && m_information.isStartLocation) ret = PixmapCacher::self()->arrowColor; else if (m_information.letter == QUACKLE_NULL_MARK) - ret = tileColor().light(145); + ret = PixmapCacher::self()->bonusTextColor; else ret = PixmapCacher::self()->uncementedLetterTextColor; diff --git a/quacker/graphicalboard.h b/quacker/graphicalboard.h index 433bafc..312d4f3 100644 --- a/quacker/graphicalboard.h +++ b/quacker/graphicalboard.h @@ -55,6 +55,8 @@ public: // deletes self and resets static void cleanUp(); + void readTheme(const QString& themeFile); + QColor arrowColor; QColor letterColor; QColor britishLetterColor; @@ -62,9 +64,9 @@ public: QColor TLSColor; QColor DWSColor; QColor TWSColor; - QColor QLSColor; QColor QWSColor; + QColor bonusTextColor; QColor nothingColor; QColor rackColor; diff --git a/quacker/settings.cpp b/quacker/settings.cpp index 2bba0d8..7c3d6bd 100644 --- a/quacker/settings.cpp +++ b/quacker/settings.cpp @@ -24,18 +24,18 @@ #include <QtGui> #include <QMessageBox> -#include <alphabetparameters.h> -#include <board.h> -#include <boardparameters.h> -#include <computerplayercollection.h> -#include <datamanager.h> -#include <game.h> -#include <lexiconparameters.h> -#include <rack.h> -#include <strategyparameters.h> - -#include <quackleio/flexiblealphabet.h> -#include <quackleio/util.h> +#include "alphabetparameters.h" +#include "board.h" +#include "boardparameters.h" +#include "computerplayercollection.h" +#include "datamanager.h" +#include "game.h" +#include "lexiconparameters.h" +#include "rack.h" +#include "strategyparameters.h" + +#include "quackleio/flexiblealphabet.h" +#include "quackleio/util.h" #include "settings.h" #include "boardsetupdialog.h" @@ -49,9 +49,24 @@ Settings *Settings::self() } Settings::Settings(QWidget *parent) - : QWidget(parent), m_lexiconNameCombo(0), m_alphabetNameCombo(0) + : QWidget(parent), m_lexiconNameCombo(0), m_alphabetNameCombo(0), m_themeNameCombo(0) { m_self = this; + + if (QFile::exists("data")) + m_dataDir = "data"; + else if (QFile::exists("../data")) + m_dataDir = "../data"; + else if (QFile::exists("Quackle.app/Contents/data")) + m_dataDir = "Quackle.app/Contents/data"; + + else + { + QDir directory = QFileInfo(qApp->arguments().at(0)).absoluteDir(); + if (!directory.cd("data") || !directory.cd("../data")) + QMessageBox::critical(0, tr("Error Initializing Data Files - Quacker"), tr("<p>Could not open data directory. Quackle will be useless. Try running the quacker executable with quackle/quacker/ as the current directory.</p>")); + m_dataDir = directory.absolutePath(); + } } void Settings::createGUI() @@ -65,10 +80,10 @@ void Settings::createGUI() connect(m_lexiconNameCombo, SIGNAL(activated(const QString &)), this, SLOT(lexiconChanged(const QString &))); QStringList items; - items << "csw12" << "cswapr07" << "sowpods" << "twl06" << "twl98" << "ods5" << "korean" << "greek"; + populateListFromFilenames(items, m_dataDir + "/lexica"); m_lexiconNameCombo->addItems(items); - QLabel *cswText = new QLabel(tr("The WESPA wordlist (CSW12) is copyright Harper Collins 2011.")); + QLabel *cswText = new QLabel(tr("The WESPA wordlist (CSW12) is copyright Harper Collins 2011.")); QHBoxLayout *lexiconLayout = new QHBoxLayout; QLabel *lexiconNameLabel = new QLabel(tr("&Lexicon:")); @@ -81,8 +96,7 @@ void Settings::createGUI() connect(m_alphabetNameCombo, SIGNAL(activated(const QString &)), this, SLOT(alphabetChanged(const QString &))); QStringList alphabetItems; - //alphabetItems << "english" << "english_super" << "french" << "korean" << "greek" << "mandarin" << "zhuyin" << "pinyin"; - alphabetItems << "english" << "english_super" << "french" << "korean" << "greek"; + populateListFromFilenames(alphabetItems, m_dataDir + "/alphabets"); m_alphabetNameCombo->addItems(alphabetItems); QHBoxLayout *alphabetLayout = new QHBoxLayout; @@ -92,6 +106,20 @@ void Settings::createGUI() alphabetLayout->addWidget(alphabetNameLabel); alphabetLayout->addWidget(m_alphabetNameCombo); + m_themeNameCombo = new QComboBox; + connect(m_themeNameCombo, SIGNAL(activated(const QString &)), this, SLOT(themeChanged(const QString &))); + + QStringList themeItems; + populateListFromFilenames(themeItems, m_dataDir + "/themes"); + m_themeNameCombo->addItems(themeItems); + + QHBoxLayout *themeLayout = new QHBoxLayout; + QLabel *themeNameLabel = new QLabel(tr("&Theme:")); + themeNameLabel->setBuddy(m_themeNameCombo); + + themeLayout->addWidget(themeNameLabel); + themeLayout->addWidget(m_themeNameCombo); + m_boardNameCombo = new QComboBox(); connect(m_boardNameCombo, SIGNAL(activated(const QString &)), this, SLOT(boardChanged(const QString &))); @@ -117,9 +145,10 @@ void Settings::createGUI() boardLayout->addWidget(m_editBoard, 1, 1); boardLayout->addWidget(m_deleteBoard, 1, 2); - vlayout->addWidget(cswText); + vlayout->addWidget(cswText); vlayout->addLayout(lexiconLayout); vlayout->addLayout(alphabetLayout); + vlayout->addLayout(themeLayout); vlayout->addWidget(boardGroup); vlayout->addStretch(); @@ -130,6 +159,7 @@ void Settings::load() { m_lexiconNameCombo->setCurrentIndex(m_lexiconNameCombo->findText(QuackleIO::Util::stdStringToQString(QUACKLE_LEXICON_PARAMETERS->lexiconName()))); m_alphabetNameCombo->setCurrentIndex(m_alphabetNameCombo->findText(QuackleIO::Util::stdStringToQString(QUACKLE_ALPHABET_PARAMETERS->alphabetName()))); + m_themeNameCombo->setCurrentIndex(m_themeNameCombo->findText(m_themeName)); m_boardNameCombo->setCurrentIndex(m_boardNameCombo->findText(QuackleIO::Util::uvStringToQString(QUACKLE_BOARD_PARAMETERS->name()))); } @@ -144,24 +174,7 @@ void Settings::initialize() CustomQSettings settings; QUACKLE_DATAMANAGER->setBackupLexicon("twl06"); - - if (QFile::exists("data")) - QUACKLE_DATAMANAGER->setDataDirectory("data"); - else if (QFile::exists("../data")) - QUACKLE_DATAMANAGER->setDataDirectory("../data"); - else if (QFile::exists("Quackle.app/Contents/data")) - QUACKLE_DATAMANAGER->setDataDirectory("Quackle.app/Contents/data"); - - else - { - QDir directory = QFileInfo(qApp->arguments().at(0)).absoluteDir(); - if (directory.cd("data")) - QUACKLE_DATAMANAGER->setDataDirectory(directory.absolutePath().toStdString()); - else if (directory.cd("../data")) // For OSX - QUACKLE_DATAMANAGER->setDataDirectory(directory.absolutePath().toStdString()); - else - QMessageBox::critical(0, tr("Error Initializing Data Files - Quacker"), tr("<p>Could not open data directory. Quackle will be useless. Try running the quacker executable with quackle/quacker/ as the current directory.</p>")); - } + QUACKLE_DATAMANAGER->setDataDirectory(m_dataDir.toStdString()); QString lexiconName = settings.value("quackle/settings/lexicon-name", QString("twl06")).toString(); @@ -171,6 +184,7 @@ void Settings::initialize() setQuackleToUseLexiconName(QuackleIO::Util::qstringToStdString(lexiconName)); setQuackleToUseAlphabetName(QuackleIO::Util::qstringToStdString(settings.value("quackle/settings/alphabet-name", QString("english")).toString())); + setQuackleToUseThemeName(settings.value("quackle/settings/theme-name", QString("traditional")).toString()); setQuackleToUseBoardName(settings.value("quackle/settings/board-name", QString("")).toString()); } @@ -228,6 +242,18 @@ void Settings::setQuackleToUseAlphabetName(const string &alphabetName) } } +void Settings::setQuackleToUseThemeName(const QString &themeName) +{ + m_themeName = themeName; + QString themeFile = m_dataDir + "/themes/" + themeName + ".ini"; + if (!QFile::exists(themeFile)) + { + m_themeName = "traditional"; + themeFile = m_dataDir + "/themes/traditional.ini"; + } + PixmapCacher::self()->readTheme(themeFile); +} + void Settings::setQuackleToUseBoardName(const QString &boardName) { CustomQSettings settings; @@ -270,6 +296,16 @@ void Settings::alphabetChanged(const QString &alphabetName) emit refreshViews(); } +void Settings::themeChanged(const QString &themeName) +{ + setQuackleToUseThemeName(themeName); + + CustomQSettings settings; + settings.setValue("quackle/settings/theme-name", themeName); + + emit refreshViews(); +} + void Settings::boardChanged(const QString &boardName) { CustomQSettings settings; @@ -377,3 +413,23 @@ void Settings::loadBoardNameCombo() m_deleteBoard->setEnabled(boardNames.count() > 0); } +void Settings::populateListFromFilenames(QStringList& list, const QString &path) +{ + QDir dir(path); + QStringList fileList = dir.entryList(QDir::Files | QDir::Readable, QDir::Name); + QStringListIterator i(fileList); + QString fileName; + int periodPos; + + while (i.hasNext()) + { + fileName = i.next(); + periodPos = fileName.indexOf('.'); + if (periodPos) + { + fileName.truncate(periodPos); + list << fileName; + } + } + list.removeDuplicates(); +} diff --git a/quacker/settings.h b/quacker/settings.h index d741921..1796753 100644 --- a/quacker/settings.h +++ b/quacker/settings.h @@ -61,6 +61,7 @@ public slots: protected slots: void lexiconChanged(const QString &lexiconName); void alphabetChanged(const QString &alphabetName); + void themeChanged(const QString &themeName); void boardChanged(const QString &boardName); void addBoard(); @@ -69,19 +70,26 @@ protected slots: void setQuackleToUseLexiconName(const string &lexiconName); void setQuackleToUseAlphabetName(const string &alphabetName); + void setQuackleToUseThemeName(const QString &themeName); void setQuackleToUseBoardName(const QString &lexiconName); protected: QComboBox *m_lexiconNameCombo; QComboBox *m_alphabetNameCombo; + QComboBox *m_themeNameCombo; QComboBox *m_boardNameCombo; QPushButton *m_addBoard; QPushButton *m_editBoard; QPushButton *m_deleteBoard; + QString m_dataDir; + QString m_themeName; private: // populate the popup based on what's in QSettings void loadBoardNameCombo(); + + // load up an item list based on a list of filenames + void populateListFromFilenames(QStringList& list, const QString &path); static Settings *m_self; }; |