forked from teamnwah/openmw-tes3coop
Feature #468
This commit is contained in:
parent
48496a644f
commit
10165d3c6b
8 changed files with 229 additions and 4 deletions
|
@ -79,6 +79,7 @@ opencs_units (view/settings
|
||||||
abstractwidget
|
abstractwidget
|
||||||
usersettingsdialog
|
usersettingsdialog
|
||||||
editorpage
|
editorpage
|
||||||
|
windowpage
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_units_noqt (view/settings
|
opencs_units_noqt (view/settings
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include <components/files/configurationmanager.hpp>
|
#include <components/files/configurationmanager.hpp>
|
||||||
|
|
||||||
|
@ -135,3 +136,58 @@ void CSMSettings::UserSettings::getSettings(QTextStream &stream, SectionMap &sec
|
||||||
}
|
}
|
||||||
sections.insert(section, settings);
|
sections.insert(section, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CSMSettings::UserSettings::getSettingValue(QString section, QString setting)
|
||||||
|
{
|
||||||
|
Files::ConfigurationManager configMgr;
|
||||||
|
QString userPath = QString::fromStdString(configMgr.getUserPath().string());
|
||||||
|
QStringList list;
|
||||||
|
|
||||||
|
list.append(QString("opencs.cfg"));
|
||||||
|
list.append(userPath + QString("opencs.cfg"));
|
||||||
|
|
||||||
|
|
||||||
|
CSMSettings::SectionMap sectionMap;
|
||||||
|
|
||||||
|
foreach (const QString &path, list)
|
||||||
|
{
|
||||||
|
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 QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QTextStream stream(&file);
|
||||||
|
stream.setCodec(QTextCodec::codecForName("UTF-8"));
|
||||||
|
|
||||||
|
getSettings(stream, sectionMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sectionMap.find(section) == sectionMap.end())
|
||||||
|
return QString();
|
||||||
|
|
||||||
|
CSMSettings::SettingMap *settings = sectionMap.value(section);
|
||||||
|
|
||||||
|
if(settings->find(setting) == settings->end())
|
||||||
|
return QString();
|
||||||
|
|
||||||
|
CSMSettings::SettingContainer *settingContainer = settings->value(setting);
|
||||||
|
|
||||||
|
return settingContainer->getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ namespace CSMSettings {
|
||||||
QFile *openFile (const QString &);
|
QFile *openFile (const QString &);
|
||||||
bool writeFile(QFile *file, QMap<QString, SettingList *> §ions);
|
bool writeFile(QFile *file, QMap<QString, SettingList *> §ions);
|
||||||
void getSettings (QTextStream &stream, SectionMap &settings);
|
void getSettings (QTextStream &stream, SectionMap &settings);
|
||||||
|
QString getSettingValue(QString section, QString setting);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <QMdiArea>
|
#include <QMdiArea>
|
||||||
#include <QDockWidget>
|
#include <QDockWidget>
|
||||||
#include <QtGui/QApplication>
|
#include <QtGui/QApplication>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include "../../model/doc/document.hpp"
|
#include "../../model/doc/document.hpp"
|
||||||
#include "../world/subviews.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),
|
: mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1),
|
||||||
mViewTotal (totalViews)
|
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);
|
mSubViewWindow.setDockOptions (QMainWindow::AllowNestedDocks);
|
||||||
|
|
||||||
|
|
|
@ -9,13 +9,14 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QDockWidget>
|
#include <QDockWidget>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include "blankpage.hpp"
|
#include "blankpage.hpp"
|
||||||
#include "editorpage.hpp"
|
#include "editorpage.hpp"
|
||||||
|
#include "windowpage.hpp"
|
||||||
#include "../../model/settings/support.hpp"
|
#include "../../model/settings/support.hpp"
|
||||||
|
|
||||||
#include "settingwidget.hpp"
|
#include "settingwidget.hpp"
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
CSVSettings::UserSettingsDialog::UserSettingsDialog(QMainWindow *parent) :
|
CSVSettings::UserSettingsDialog::UserSettingsDialog(QMainWindow *parent) :
|
||||||
QMainWindow (parent), mStackedWidget (0)
|
QMainWindow (parent), mStackedWidget (0)
|
||||||
|
@ -76,9 +77,10 @@ void CSVSettings::UserSettingsDialog::buildPages()
|
||||||
setDockOptions (QMainWindow::AllowNestedDocks);
|
setDockOptions (QMainWindow::AllowNestedDocks);
|
||||||
//uncomment to test with sample editor page.
|
//uncomment to test with sample editor page.
|
||||||
//createSamplePage();
|
//createSamplePage();
|
||||||
createPage<BlankPage>("Page1");
|
/*createPage<BlankPage>("Page1");
|
||||||
createPage<BlankPage>("Page2");
|
createPage<BlankPage>("Page2");
|
||||||
createPage<BlankPage>("Page3");
|
createPage<BlankPage>("Page3");*/
|
||||||
|
createWindowPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVSettings::UserSettingsDialog::createSamplePage()
|
void CSVSettings::UserSettingsDialog::createSamplePage()
|
||||||
|
@ -95,6 +97,20 @@ void CSVSettings::UserSettingsDialog::createSamplePage()
|
||||||
&(CSMSettings::UserSettings::instance()), SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)));
|
&(CSMSettings::UserSettings::instance()), SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVSettings::UserSettingsDialog::createWindowPage()
|
||||||
|
{
|
||||||
|
//add pages to stackedwidget and items to listwidget
|
||||||
|
CSVSettings::AbstractPage *page
|
||||||
|
= new CSVSettings::WindowPage(this);
|
||||||
|
|
||||||
|
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 &)));
|
||||||
|
}
|
||||||
|
|
||||||
void CSVSettings::UserSettingsDialog::positionWindow ()
|
void CSVSettings::UserSettingsDialog::positionWindow ()
|
||||||
{
|
{
|
||||||
QRect scr = QApplication::desktop()->screenGeometry();
|
QRect scr = QApplication::desktop()->screenGeometry();
|
||||||
|
|
|
@ -45,6 +45,9 @@ namespace CSVSettings {
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
void createSamplePage();
|
void createSamplePage();
|
||||||
|
|
||||||
|
//Pages
|
||||||
|
void createWindowPage();
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void createPage (const QString &title)
|
void createPage (const QString &title)
|
||||||
{
|
{
|
||||||
|
|
114
apps/opencs/view/settings/windowpage.cpp
Normal file
114
apps/opencs/view/settings/windowpage.cpp
Normal file
|
@ -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);
|
||||||
|
}
|
28
apps/opencs/view/settings/windowpage.hpp
Normal file
28
apps/opencs/view/settings/windowpage.hpp
Normal file
|
@ -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…
Reference in a new issue