basic framework for new user settings system
parent
49b37ce8bf
commit
36ce8f97d7
@ -0,0 +1,68 @@
|
||||
|
||||
#include "state.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
CSMPrefs::State *CSMPrefs::State::sThis = 0;
|
||||
|
||||
void CSMPrefs::State::load()
|
||||
{
|
||||
// default settings file
|
||||
boost::filesystem::path local = mConfigurationManager.getLocalPath() / mConfigFile;
|
||||
boost::filesystem::path global = mConfigurationManager.getGlobalPath() / mConfigFile;
|
||||
|
||||
if (boost::filesystem::exists (local))
|
||||
mSettings.loadDefault (local.string());
|
||||
else if (boost::filesystem::exists (global))
|
||||
mSettings.loadDefault (global.string());
|
||||
else
|
||||
throw std::runtime_error ("No default settings file found! Make sure the file \"opencs.ini\" was properly installed.");
|
||||
|
||||
// user settings file
|
||||
boost::filesystem::path user = mConfigurationManager.getUserConfigPath() / mConfigFile;
|
||||
|
||||
if (boost::filesystem::exists (user))
|
||||
mSettings.loadUser (user.string());
|
||||
}
|
||||
|
||||
void CSMPrefs::State::declare()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CSMPrefs::State::State (const Files::ConfigurationManager& configurationManager)
|
||||
: mConfigFile ("opencs.ini"), mConfigurationManager (configurationManager)
|
||||
{
|
||||
if (sThis)
|
||||
throw std::logic_error ("An instance of CSMPRefs::State already exists");
|
||||
|
||||
load();
|
||||
declare();
|
||||
|
||||
sThis = this;
|
||||
}
|
||||
|
||||
CSMPrefs::State::~State()
|
||||
{
|
||||
sThis = 0;
|
||||
}
|
||||
|
||||
void CSMPrefs::State::save()
|
||||
{
|
||||
boost::filesystem::path user = mConfigurationManager.getUserConfigPath() / mConfigFile;
|
||||
mSettings.saveUser (user.string());
|
||||
}
|
||||
|
||||
CSMPrefs::State& CSMPrefs::State::get()
|
||||
{
|
||||
if (!sThis)
|
||||
throw std::logic_error ("No instance of CSMPrefs::State");
|
||||
|
||||
return *sThis;
|
||||
}
|
||||
|
||||
|
||||
CSMPrefs::State& CSMPrefs::get()
|
||||
{
|
||||
return State::get();
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
#ifndef CSV_PREFS_STATE_H
|
||||
#define CSM_PREFS_STATE_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#ifndef Q_MOC_RUN
|
||||
#include <components/files/configurationmanager.hpp>
|
||||
#endif
|
||||
|
||||
#include <components/settings/settings.hpp>
|
||||
|
||||
namespace CSMPrefs
|
||||
{
|
||||
class State : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
static State *sThis;
|
||||
|
||||
const std::string mConfigFile;
|
||||
const Files::ConfigurationManager& mConfigurationManager;
|
||||
Settings::Manager mSettings;
|
||||
|
||||
// not implemented
|
||||
State (const State&);
|
||||
State& operator= (const State&);
|
||||
|
||||
private:
|
||||
|
||||
void load();
|
||||
|
||||
void declare();
|
||||
|
||||
public:
|
||||
|
||||
State (const Files::ConfigurationManager& configurationManager);
|
||||
|
||||
~State();
|
||||
|
||||
void save();
|
||||
|
||||
static State& get();
|
||||
};
|
||||
|
||||
// convenience function
|
||||
State& get();
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,72 @@
|
||||
|
||||
#include "dialogue.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QSplitter>
|
||||
#include <QListWidget>
|
||||
#include <QStackedWidget>
|
||||
|
||||
#include "../../model/prefs/state.hpp"
|
||||
|
||||
void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main)
|
||||
{
|
||||
mList = new QListWidget (main);
|
||||
mList->setMinimumWidth (50);
|
||||
mList->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
mList->setSelectionBehavior (QAbstractItemView::SelectItems);
|
||||
|
||||
main->addWidget (mList);
|
||||
|
||||
/// \todo connect to selection signal
|
||||
}
|
||||
|
||||
void CSVPrefs::Dialogue::buildContentArea (QSplitter *main)
|
||||
{
|
||||
mContent = new QStackedWidget (main);
|
||||
mContent->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||
|
||||
main->addWidget (mContent);
|
||||
}
|
||||
|
||||
CSVPrefs::Dialogue::Dialogue()
|
||||
{
|
||||
setWindowTitle ("User Settings");
|
||||
|
||||
setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
|
||||
setMinimumSize (600, 400);
|
||||
|
||||
QSplitter *main = new QSplitter (this);
|
||||
|
||||
setCentralWidget (main);
|
||||
buildCategorySelector (main);
|
||||
buildContentArea (main);
|
||||
}
|
||||
|
||||
void CSVPrefs::Dialogue::closeEvent (QCloseEvent *event)
|
||||
{
|
||||
QMainWindow::closeEvent (event);
|
||||
|
||||
CSMPrefs::State::get().save();
|
||||
}
|
||||
|
||||
void CSVPrefs::Dialogue::show()
|
||||
{
|
||||
if (QWidget *active = QApplication::activeWindow())
|
||||
{
|
||||
// place at the centre of the window with focus
|
||||
QSize size = active->size();
|
||||
move (active->geometry().x()+(size.width() - frameGeometry().width())/2,
|
||||
active->geometry().y()+(size.height() - frameGeometry().height())/2);
|
||||
}
|
||||
else
|
||||
{
|
||||
// otherwise place at the centre of the screen
|
||||
QPoint screenCenter = QApplication::desktop()->screenGeometry().center();
|
||||
move (screenCenter - QPoint(frameGeometry().width()/2, frameGeometry().height()/2));
|
||||
}
|
||||
|
||||
QWidget::show();
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
#ifndef CSV_PREFS_DIALOGUE_H
|
||||
#define CSV_PREFS_DIALOGUE_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
class QSplitter;
|
||||
class QListWidget;
|
||||
class QStackedWidget;
|
||||
|
||||
namespace CSVPrefs
|
||||
{
|
||||
class Dialogue : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QListWidget *mList;
|
||||
QStackedWidget *mContent;
|
||||
|
||||
private:
|
||||
|
||||
void buildCategorySelector (QSplitter *main);
|
||||
|
||||
void buildContentArea (QSplitter *main);
|
||||
|
||||
public:
|
||||
|
||||
Dialogue();
|
||||
|
||||
protected:
|
||||
|
||||
void closeEvent (QCloseEvent *event);
|
||||
|
||||
public slots:
|
||||
|
||||
void show();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue