diff --git a/glabels/CMakeLists.txt b/glabels/CMakeLists.txt index b2fc719..389416b 100644 --- a/glabels/CMakeLists.txt +++ b/glabels/CMakeLists.txt @@ -42,6 +42,7 @@ set (glabels_sources Preview.cpp PreviewOverlayItem.cpp SelectProductDialog.cpp + Settings.cpp SimplePreview.cpp StartupWizard.cpp TemplatePicker.cpp @@ -77,6 +78,7 @@ set (glabels_qobject_headers PropertiesView.h Preview.h SelectProductDialog.h + Settings.h SimplePreview.h StartupWizard.h TemplatePicker.h diff --git a/glabels/Settings.cpp b/glabels/Settings.cpp new file mode 100644 index 0000000..2699f0a --- /dev/null +++ b/glabels/Settings.cpp @@ -0,0 +1,120 @@ +/* Settings.cpp + * + * Copyright (C) 2016 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels-qt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels-qt. If not, see . + */ + +#include "Settings.h" + +#include +#include + + +Settings* Settings::mInstance = 0; + + +Settings::Settings() +{ +} + + +void Settings::init() +{ + if ( mInstance == 0 ) + { + mInstance = new Settings(); + } +} + + +Settings* Settings::instance() +{ + init(); + + return mInstance; +} + + +bool Settings::preferIsoPaperSizes() +{ + // Guess at a suitable default + bool defaultValue; + switch (QLocale::system().country()) + { + case QLocale::UnitedStates: + case QLocale::Canada: + defaultValue = false; + break; + + default: + defaultValue = true; + break; + } + + mInstance->beginGroup( "Locale" ); + bool returnValue = mInstance->value( "preferIsoPaperSizes", defaultValue ).toBool(); + mInstance->endGroup(); + + return returnValue; +} + + +void Settings::setPreferIsoPaperSizes( bool preferIsoPaperSizes ) +{ + + mInstance->beginGroup( "Locale" ); + mInstance->setValue( "preferIsoPaperSizes", preferIsoPaperSizes ); + mInstance->endGroup(); + + emit mInstance->changed(); +} + + +glabels::Distance::Units Settings::units() +{ + // Guess at a suitable default + QString defaultIdString; + switch (QLocale::system().country()) + { + case QLocale::UnitedStates: + case QLocale::Canada: + defaultIdString = "in"; + break; + + default: + defaultIdString = "mm"; + break; + } + + mInstance->beginGroup( "Locale" ); + QString idString = mInstance->value( "units", defaultIdString ).toString(); + mInstance->endGroup(); + + return glabels::Distance::toUnits( idString ); +} + + +void Settings::setUnits( glabels::Distance::Units units ) +{ + QString idString = glabels::Distance::toId( units ); + + mInstance->beginGroup( "Locale" ); + mInstance->setValue( "units", idString ); + mInstance->endGroup(); + + emit mInstance->changed(); +} diff --git a/glabels/Settings.h b/glabels/Settings.h new file mode 100644 index 0000000..36582a1 --- /dev/null +++ b/glabels/Settings.h @@ -0,0 +1,75 @@ +/* Settings.h + * + * Copyright (C) 2016 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels-qt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels-qt. If not, see . + */ + +#ifndef Settings_h +#define Settings_h + + +#include +#include "libglabels/Distance.h" + + +/// +/// Settings Singleton Class +/// +class Settings : public QSettings +{ + Q_OBJECT + +public: + enum class PageSizeFamilty { ISO, US, }; + + + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +private: + Settings(); + +public: + static void init(); + static Settings* instance(); + + + ///////////////////////////////// + // Signals + ///////////////////////////////// +signals: + void changed(); + + + ///////////////////////////////// + // Accessors + ///////////////////////////////// +public: + static bool preferIsoPaperSizes(); + static void setPreferIsoPaperSizes( bool preferIsoPaperSizes ); + + static glabels::Distance::Units units(); + static void setUnits( glabels::Distance::Units units ); + + +private: + static Settings* mInstance; + +}; + + +#endif // Settings_h