Merge remote-tracking branch 'glorf/cs-windows'

actorid
Marc Zinnschlag 12 years ago
commit df1f1bd5c8

@ -79,6 +79,7 @@ opencs_units (view/settings
abstractwidget
usersettingsdialog
editorpage
windowpage
)
opencs_units_noqt (view/settings

@ -61,6 +61,17 @@ void CS::Editor::setupDataFiles()
QString path = QString::fromStdString(iter->string());
mFileDialog.addFiles(path);
}
//Settings setup
QStringList settingFiles;
QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string());
settingFiles.append(QString("opencs.cfg"));
settingFiles.append(userPath + QString("opencs.cfg"));
mUserSettings.setSettingsFiles(settingFiles);
mUserSettings.readSettings();
}
void CS::Editor::createDocument()

@ -10,6 +10,7 @@
#include "view/doc/viewmanager.hpp"
#include "view/doc/startup.hpp"
#include "view/doc/filedialog.hpp"
#include "model/settings/usersettings.hpp"
namespace CS
{
@ -17,6 +18,7 @@ namespace CS
{
Q_OBJECT
CSMSettings::UserSettings mUserSettings;
CSMDoc::DocumentManager mDocumentManager;
CSVDoc::ViewManager mViewManager;
CSVDoc::StartupDialogue mStartup;

@ -7,6 +7,7 @@
#include <QMap>
#include <QMessageBox>
#include <QTextCodec>
#include <QDebug>
#include <components/files/configurationmanager.hpp>
@ -29,17 +30,25 @@ namespace boost
} /* namespace boost */
#endif /* (BOOST_VERSION <= 104600) */
CSMSettings::UserSettings *CSMSettings::UserSettings::mUserSettingsInstance = 0;
CSMSettings::UserSettings::UserSettings()
{
assert(!mUserSettingsInstance);
mUserSettingsInstance = this;
}
CSMSettings::UserSettings::~UserSettings()
{
mUserSettingsInstance = 0;
}
QFile *CSMSettings::UserSettings::openFile (const QString &filename)
CSMSettings::SectionMap CSMSettings::UserSettings::getSettingsMap() const
{
return mSectionMap;
}
QFile *CSMSettings::UserSettings::openFile (const QString &filename) const
{
QFile *file = new QFile(filename);
@ -63,7 +72,7 @@ QFile *CSMSettings::UserSettings::openFile (const QString &filename)
return file;
}
bool CSMSettings::UserSettings::writeFile(QFile *file, QMap<QString, CSMSettings::SettingList *> &settings)
bool CSMSettings::UserSettings::writeFile(QFile *file, QMap<QString, CSMSettings::SettingList *> &settings) const
{
if (!file)
return false;
@ -88,7 +97,7 @@ bool CSMSettings::UserSettings::writeFile(QFile *file, QMap<QString, CSMSettings
return true;
}
void CSMSettings::UserSettings::getSettings(QTextStream &stream, SectionMap &sections)
void CSMSettings::UserSettings::getSettings(QTextStream &stream, SectionMap &sections) const
{
//looks for a square bracket, "'\\["
//that has one or more "not nothing" in it, "([^]]+)"
@ -135,3 +144,70 @@ void CSMSettings::UserSettings::getSettings(QTextStream &stream, SectionMap &sec
}
sections.insert(section, settings);
}
void CSMSettings::UserSettings::readSettings()
{
CSMSettings::SectionMap sectionMap;
foreach (const QString &path, mSettingsFiles)
{
qDebug() << "Loading config file:" << qPrintable(path);
QFile file(path);
if (file.exists())
{
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error opening OpenCS configuration file"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(QObject::tr("<br><b>Could not open %0 for reading</b><br><br> \
Please make sure you have the right permissions \
and try again.<br>").arg(file.fileName()));
msgBox.exec();
return;
}
QTextStream stream(&file);
stream.setCodec(QTextCodec::codecForName("UTF-8"));
getSettings(stream, mSectionMap);
}
file.close();
}
}
void CSMSettings::UserSettings::setSettingsFiles(QStringList files)
{
mSettingsFiles = files;
}
QStringList CSMSettings::UserSettings::getSettingsFiles () const
{
return mSettingsFiles;
}
QString CSMSettings::UserSettings::getSettingValue(QString section, QString setting) const
{
if(mSectionMap.find(section) == mSectionMap.end())
return QString();
CSMSettings::SettingMap *settings = mSectionMap.value(section);
if(settings->find(setting) == settings->end())
return QString();
CSMSettings::SettingContainer *settingContainer = settings->value(setting);
return settingContainer->getValue();
}
const CSMSettings::UserSettings& CSMSettings::UserSettings::instance()
{
assert(mUserSettingsInstance);
return *mUserSettingsInstance;
}

@ -24,22 +24,27 @@ namespace CSMSettings {
public:
static UserSettings &instance()
{
static UserSettings instance;
UserSettings();
~UserSettings();
static const UserSettings& instance();
return instance;
}
void readSettings();
void setSettingsFiles(QStringList files);
QFile *openFile (const QString &);
bool writeFile(QFile *file, QMap<QString, SettingList *> &sections);
void getSettings (QTextStream &stream, SectionMap &settings);
QFile *openFile (const QString &) const;
bool writeFile(QFile *file, QMap<QString, SettingList *> &sections) const;
void getSettings (QTextStream &stream, SectionMap &settings) const;
QStringList getSettingsFiles () const;
CSMSettings::SectionMap getSettingsMap() const;
QString getSettingValue(QString section, QString setting) const;
private:
UserSettings *mUserSettingsInstance;
UserSettings();
~UserSettings();
static UserSettings *mUserSettingsInstance;
CSMSettings::SectionMap mSectionMap;
QStringList mSettingsFiles;
UserSettings (UserSettings const &); //not implemented
void operator= (UserSettings const &); //not implemented

@ -8,6 +8,7 @@
#include <QMdiArea>
#include <QDockWidget>
#include <QtGui/QApplication>
#include <QDebug>
#include "../../model/doc/document.hpp"
#include "../world/subviews.hpp"
@ -179,7 +180,12 @@ CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int to
: mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1),
mViewTotal (totalViews)
{
resize (300, 300); /// \todo get default size from settings and set reasonable minimal size
QString width = CSMSettings::UserSettings::instance().getSettingValue(QString("Window Size"), QString("Width"));
QString height = CSMSettings::UserSettings::instance().getSettingValue(QString("Window Size"), QString("Height"));
if(width==QString() || height==QString())
resize(800, 600);
else
resize (width.toInt(), height.toInt());
mSubViewWindow.setDockOptions (QMainWindow::AllowNestedDocks);

@ -9,20 +9,21 @@
#include <QFile>
#include <QPushButton>
#include <QDockWidget>
#include <QDebug>
#include "blankpage.hpp"
#include "editorpage.hpp"
#include "windowpage.hpp"
#include "../../model/settings/support.hpp"
#include "settingwidget.hpp"
#include <QDebug>
CSVSettings::UserSettingsDialog::UserSettingsDialog(QMainWindow *parent) :
QMainWindow (parent), mStackedWidget (0)
{
setWindowTitle(QString::fromUtf8 ("User Settings"));
buildPages();
setWidgetStates (loadSettings());
setWidgetStates (CSMSettings::UserSettings::instance().getSettingsMap());
positionWindow ();
connect (mListWidget,
@ -76,9 +77,10 @@ void CSVSettings::UserSettingsDialog::buildPages()
setDockOptions (QMainWindow::AllowNestedDocks);
//uncomment to test with sample editor page.
//createSamplePage();
createPage<BlankPage>("Page1");
/*createPage<BlankPage>("Page1");
createPage<BlankPage>("Page2");
createPage<BlankPage>("Page3");
createPage<BlankPage>("Page3");*/
createWindowPage();
}
void CSVSettings::UserSettingsDialog::createSamplePage()
@ -95,55 +97,29 @@ void CSVSettings::UserSettingsDialog::createSamplePage()
&(CSMSettings::UserSettings::instance()), SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)));
}
void CSVSettings::UserSettingsDialog::positionWindow ()
void CSVSettings::UserSettingsDialog::createWindowPage()
{
QRect scr = QApplication::desktop()->screenGeometry();
//add pages to stackedwidget and items to listwidget
CSVSettings::AbstractPage *page
= new CSVSettings::WindowPage(this);
move(scr.center().x() - (width() / 2), scr.center().y() - (height() / 2));
mStackedWidget->addWidget (page);
new QListWidgetItem (page->objectName(), mListWidget);
connect ( page, SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)),
&(CSMSettings::UserSettings::instance()), SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)));
}
CSMSettings::SectionMap CSVSettings::UserSettingsDialog::loadSettings ()
void CSVSettings::UserSettingsDialog::positionWindow ()
{
QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string());
mPaths.append(QString("opencs.cfg"));
mPaths.append(userPath + QString("opencs.cfg"));
CSMSettings::SectionMap settingsMap;
foreach (const QString &path, mPaths)
{
qDebug() << "Loading config file:" << qPrintable(path);
QFile file(path);
if (file.exists())
{
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error opening OpenCS configuration file"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(QObject::tr("<br><b>Could not open %0 for reading</b><br><br> \
Please make sure you have the right permissions \
and try again.<br>").arg(file.fileName()));
msgBox.exec();
return settingsMap;
}
QTextStream stream(&file);
stream.setCodec(QTextCodec::codecForName("UTF-8"));
CSMSettings::UserSettings::instance().getSettings(stream, settingsMap);
}
QRect scr = QApplication::desktop()->screenGeometry();
file.close();
}
move(scr.center().x() - (width() / 2), scr.center().y() - (height() / 2));
return settingsMap;
}
void CSVSettings::UserSettingsDialog::writeSettings()
{
QMap<QString, CSMSettings::SettingList *> settings;
@ -154,7 +130,9 @@ void CSVSettings::UserSettingsDialog::writeSettings()
settings [page->objectName()] = page->getSettings();
}
CSMSettings::UserSettings::instance().writeFile(CSMSettings::UserSettings::instance().openFile(mPaths.back()), settings);
QStringList paths = CSMSettings::UserSettings::instance().getSettingsFiles();
CSMSettings::UserSettings::instance().writeFile(CSMSettings::UserSettings::instance().openFile(paths.back()), settings);
}

@ -25,7 +25,6 @@ namespace CSVSettings {
{
Q_OBJECT
QStringList mPaths;
QListWidget *mListWidget;
QStackedWidget *mStackedWidget;
Files::ConfigurationManager mCfgMgr;
@ -41,10 +40,12 @@ namespace CSVSettings {
void setWidgetStates (CSMSettings::SectionMap settingsMap);
void buildPages();
void positionWindow ();
CSMSettings::SectionMap loadSettings();
void writeSettings();
void createSamplePage();
//Pages
void createWindowPage();
template <typename T>
void createPage (const QString &title)
{

@ -0,0 +1,114 @@
#include "windowpage.hpp"
#include <QList>
#include <QListView>
#include <QGroupBox>
#include <QRadioButton>
#include <QDockWidget>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QStyle>
#ifdef Q_OS_MAC
#include <QPlastiqueStyle>
#endif
#include "../../model/settings/usersettings.hpp"
#include "groupblock.hpp"
#include "toggleblock.hpp"
CSVSettings::WindowPage::WindowPage(QWidget *parent):
AbstractPage("Window Size", parent)
{
// Hacks to get the stylesheet look properly
#ifdef Q_OS_MAC
QPlastiqueStyle *style = new QPlastiqueStyle;
//profilesComboBox->setStyle(style);
#endif
setupUi();
}
void CSVSettings::WindowPage::setupUi()
{
GroupBlockDef customWindowSize (QString ("Custom Window Size"));
GroupBlockDef definedWindowSize (QString ("Pre-Defined Window Size"));
GroupBlockDef windowSizeToggle (QString ("Window Size"));
CustomBlockDef windowSize (QString ("Window Size"));
///////////////////////////////
//custom window size properties
///////////////////////////////
//custom width
SettingsItemDef *widthItem = new SettingsItemDef ("Width", "640");
widthItem->widget = WidgetDef (Widget_LineEdit);
widthItem->widget.widgetWidth = 45;
//custom height
SettingsItemDef *heightItem = new SettingsItemDef ("Height", "480");
heightItem->widget = WidgetDef (Widget_LineEdit);
heightItem->widget.widgetWidth = 45;
heightItem->widget.caption = "x";
customWindowSize.properties << widthItem << heightItem;
customWindowSize.widgetOrientation = Orient_Horizontal;
customWindowSize.isVisible = false;
//pre-defined
SettingsItemDef *widthByHeightItem = new SettingsItemDef ("Window Size", "640x480");
WidgetDef widthByHeightWidget = WidgetDef (Widget_ComboBox);
widthByHeightWidget.widgetWidth = 90;
*(widthByHeightItem->valueList) << "640x480" << "800x600" << "1024x768" << "1440x900";
QStringList *widthProxy = new QStringList;
QStringList *heightProxy = new QStringList;
(*widthProxy) << "Width" << "640" << "800" << "1024" << "1440";
(*heightProxy) << "Height" << "480" << "600" << "768" << "900";
*(widthByHeightItem->proxyList) << widthProxy << heightProxy;
widthByHeightItem->widget = widthByHeightWidget;
definedWindowSize.properties << widthByHeightItem;
definedWindowSize.isProxy = true;
definedWindowSize.isVisible = false;
// window size toggle
windowSizeToggle.captions << "Pre-Defined" << "Custom";
windowSizeToggle.widgetOrientation = Orient_Vertical;
windowSizeToggle.isVisible = false;
//define a widget for each group in the toggle
for (int i = 0; i < 2; i++)
windowSizeToggle.widgets << new WidgetDef (Widget_RadioButton);
windowSizeToggle.widgets.at(0)->isDefault = false;
windowSize.blockDefList << &windowSizeToggle << &definedWindowSize << &customWindowSize;
windowSize.defaultValue = "Custom";
QGridLayout *pageLayout = new QGridLayout(this);
setLayout (pageLayout);
mAbstractBlocks << buildBlock<ToggleBlock> (windowSize);
foreach (AbstractBlock *block, mAbstractBlocks)
{
connect (block, SIGNAL (signalUpdateSetting (const QString &, const QString &)),
this, SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)) );
}
}
void CSVSettings::WindowPage::initializeWidgets (const CSMSettings::SettingMap &settings)
{
//iterate each item in each blocks in this section
//validate the corresponding setting against the defined valuelist if any.
for (AbstractBlockList::Iterator it_block = mAbstractBlocks.begin();
it_block != mAbstractBlocks.end(); ++it_block)
(*it_block)->updateSettings (settings);
}

@ -0,0 +1,28 @@
#ifndef WINDOWPAGE_H
#define WINDOWPAGE_H
#include "abstractpage.hpp"
class QGroupBox;
namespace CSVSettings {
class UserSettings;
class AbstractBlock;
class WindowPage : public AbstractPage
{
Q_OBJECT
public:
WindowPage(QWidget *parent = 0);
void setupUi();
void initializeWidgets (const CSMSettings::SettingMap &settings);
signals:
void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue);
};
}
#endif //WINDOWPAGE_H
Loading…
Cancel
Save