diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index 3fcf083d1..82f4bc750 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -202,18 +202,8 @@ void UserSettings::buildSettingModelDefaults() spaceText2->setViewLocation(3, 7); #if 0 - sh::Factory::getInstance().setGlobalSetting ("shadows_pssm", "false"); - - sh::Factory::getInstance ().setGlobalSetting ("render_refraction", "false"); - - sh::Factory::getInstance ().setGlobalSetting ("viewproj_fix", "false"); - - - sh::Factory::getInstance ().setSharedParameter ("windDir_windSpeed", sh::makeProperty(new sh::Vector3(0.5, -0.8, 0.2))); sh::Factory::getInstance ().setSharedParameter ("waterSunFade_sunHeight", sh::makeProperty(new sh::Vector2(1, 0.6))); -sh::Factory::getInstance ().setGlobalSetting ("refraction", Settings::Manager::getBool("refraction", "Water") ? "true" : "false"); -sh::Factory::getInstance ().setGlobalSetting ("viewproj_fix", "false"); sh::Factory::getInstance ().setSharedParameter ("vpRow2Fix", sh::makeProperty (new sh::Vector4(0,0,0,0))); #endif } diff --git a/apps/opencs/view/doc/subview.cpp b/apps/opencs/view/doc/subview.cpp index 9c3c4e5e9..be03f91a5 100644 --- a/apps/opencs/view/doc/subview.cpp +++ b/apps/opencs/view/doc/subview.cpp @@ -1,5 +1,7 @@ #include "subview.hpp" +#include "view.hpp" + CSVDoc::SubView::SubView (const CSMWorld::UniversalId& id) : mUniversalId (id) { /// \todo add a button to the title bar that clones this sub view @@ -25,3 +27,10 @@ void CSVDoc::SubView::setUniversalId (const CSMWorld::UniversalId& id) mUniversalId = id; setWindowTitle (mUniversalId.toString().c_str()); } + +void CSVDoc::SubView::closeEvent (QCloseEvent *event) +{ + // update title bars of view and subviews + if(mParent) + mParent->updateSubViewIndicies(this); +} diff --git a/apps/opencs/view/doc/subview.hpp b/apps/opencs/view/doc/subview.hpp index 733a75bb0..6a3ddd8bd 100644 --- a/apps/opencs/view/doc/subview.hpp +++ b/apps/opencs/view/doc/subview.hpp @@ -18,11 +18,14 @@ namespace CSMWorld namespace CSVDoc { + class View; + class SubView : public QDockWidget { Q_OBJECT CSMWorld::UniversalId mUniversalId; + View *mParent; // not implemented SubView (const SubView&); @@ -44,6 +47,12 @@ namespace CSVDoc virtual void useHint (const std::string& hint); ///< Default implementation: ignored + void setParent(View *parent) { mParent = parent; } + + private: + + void closeEvent (QCloseEvent *event); + signals: void focusId (const CSMWorld::UniversalId& universalId, const std::string& hint); diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index e77b995fc..b2317d77b 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -297,7 +297,7 @@ void CSVDoc::View::setupUi() setupDebugMenu(); } -void CSVDoc::View::updateTitle() +void CSVDoc::View::updateTitle(const std::string subview) { std::ostringstream stream; @@ -309,9 +309,37 @@ void CSVDoc::View::updateTitle() if (mViewTotal>1) stream << " [" << (mViewIndex+1) << "/" << mViewTotal << "]"; + if (subview != "") + stream << " - " << subview; + setWindowTitle (stream.str().c_str()); } +void CSVDoc::View::updateSubViewIndicies(SubView *view) +{ + if(view && mSubViews.contains(view)) + mSubViews.removeOne(view); + + if(mSubViews.size() == 1) + { + mSubViews.at(0)->setTitleBarWidget(new QWidget(this)); + updateTitle(mSubViews.at(0)->getUniversalId().getTypeName().c_str()); + } + else + { + updateTitle(); + if(mSubViews.size() > 1) + { + foreach(SubView * sb, mSubViews) + { + QWidget * tb = sb->titleBarWidget(); + if(tb) delete tb; + sb->setTitleBarWidget(0); + } + } + } +} + void CSVDoc::View::updateActions() { bool editing = !(mDocument->getState() & CSMDoc::State_Locked); @@ -421,11 +449,20 @@ void CSVDoc::View::updateProgress (int current, int max, int type, int threads) void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id, const std::string& hint) { - /// \todo add an user setting for limiting the number of sub views per top level view. Automatically open a new top level view if this - /// number is exceeded + CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); - /// \todo if the sub view limit setting is one, the sub view title bar should be hidden and the text in the main title bar adjusted - /// accordingly + int maxSubView = 3; + if(userSettings.hasSettingDefinitions("SubView/max subviews")) + maxSubView = userSettings.settingValue("SubView/max subviews").toInt(); + else + userSettings.setDefinitions("SubView/max subviews", (QStringList() << QString(maxSubView))); + + if(mSubViews.size() >= maxSubView) // create a new top level view + { + mViewManager.addView(mDocument, id, hint); + + return; + } /// \todo add an user setting to reuse sub views (on a per document basis or on a per top level view basis) @@ -439,16 +476,29 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id, const std::strin view = mSubViewFactory.makeSubView (id, *mDocument); } assert(view); + view->setParent(this); + mSubViews.append(view); // only after assert if (!hint.empty()) view->useHint (hint); - int minWidth = 325; // default value if none found - if(CSMSettings::UserSettings::instance().hasSettingDefinitions("SubView/minimum width")) - minWidth = CSMSettings::UserSettings::instance().settingValue("SubView/minimum width").toInt(); + int minWidth = 325; // default value to use if none found + if(userSettings.hasSettingDefinitions("SubView/minimum width")) + minWidth = userSettings.settingValue("SubView/minimum width").toInt(); else - CSMSettings::UserSettings::instance().setDefinitions("SubView/minimum width", (QStringList() << "minWidth")); + userSettings.setDefinitions("SubView/minimum width", (QStringList() << QString(minWidth))); view->setMinimumWidth(minWidth); +#if 0 + if(mSubViews.size() == 1) // remove subview title and add to the main window + { + updateTitle(id.getTypeName().c_str()); + // FIXME: search area broken + view->setTitleBarWidget(new QWidget(this)); + } + else +#endif + updateSubViewIndicies(); + view->setStatusBar (mShowStatusBar->isChecked()); // NOTE: only required if show status bar setting should be applied to existing // window diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index e7c813c5c..eab274a59 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -35,6 +35,7 @@ namespace CSVDoc CSMDoc::Document *mDocument; int mViewIndex; int mViewTotal; + QList mSubViews; QAction *mUndo; QAction *mRedo; QAction *mSave; @@ -74,7 +75,7 @@ namespace CSVDoc void setupUi(); - void updateTitle(); + void updateTitle(const std::string subview = ""); void updateActions(); @@ -113,6 +114,9 @@ namespace CSVDoc /// Function called by view manager when user preferences are updated void updateEditorSetting (const QString &, const QString &); + // called when subviews are added or removed + void updateSubViewIndicies(SubView *view = 0); + signals: void newGameRequest(); diff --git a/apps/opencs/view/doc/viewmanager.cpp b/apps/opencs/view/doc/viewmanager.cpp index d5e5e7027..39cd7eeda 100644 --- a/apps/opencs/view/doc/viewmanager.cpp +++ b/apps/opencs/view/doc/viewmanager.cpp @@ -9,6 +9,7 @@ #include "../../model/doc/documentmanager.hpp" #include "../../model/doc/document.hpp" #include "../../model/world/columns.hpp" +#include "../../model/world/universalid.hpp" #include "../world/util.hpp" #include "../world/enumdelegate.hpp" @@ -161,6 +162,14 @@ CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document) return view; } +CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document, const CSMWorld::UniversalId& id, const std::string& hint) +{ + View* view = addView(document); + view->addSubView(id, hint); + + return view; +} + int CSVDoc::ViewManager::countViews (const CSMDoc::Document *document) const { int count = 0; diff --git a/apps/opencs/view/doc/viewmanager.hpp b/apps/opencs/view/doc/viewmanager.hpp index 61b807960..d703b430a 100644 --- a/apps/opencs/view/doc/viewmanager.hpp +++ b/apps/opencs/view/doc/viewmanager.hpp @@ -18,6 +18,11 @@ namespace CSVWorld class CommandDelegateFactoryCollection; } +namespace CSMWorld +{ + class UniversalId; +} + namespace CSVDoc { class View; @@ -52,6 +57,8 @@ namespace CSVDoc View *addView (CSMDoc::Document *document); ///< The ownership of the returned view is not transferred. + View *addView (CSMDoc::Document *document, const CSMWorld::UniversalId& id, const std::string& hint); + int countViews (const CSMDoc::Document *document) const; ///< Return number of views for \a document. diff --git a/apps/opencs/view/settings/dialog.cpp b/apps/opencs/view/settings/dialog.cpp index 561eccc5c..e328384e8 100644 --- a/apps/opencs/view/settings/dialog.cpp +++ b/apps/opencs/view/settings/dialog.cpp @@ -305,6 +305,11 @@ void CSVSettings::Dialog::buildPages() else sbMinSubViewWidth->setValue(325); + if(model()->hasSettingDefinitions("SubView/max subviews")) + sbMaxSubViews->setValue(model()->settingValue("SubView/max subview").toInt()); + else + sbMaxSubViews->setValue(3); + SettingWindow::createPages (); foreach (Page *page, SettingWindow::pages()) @@ -385,6 +390,8 @@ void CSVSettings::Dialog::closeEvent (QCloseEvent *event) // subview model()->setDefinitions("SubView/minimum width", QStringList(QString::number(sbMinSubViewWidth->value()))); + model()->setDefinitions("SubView/max subviews", + QStringList(QString::number(sbMaxSubViews->value()))); saveSettings(); } diff --git a/files/ui/settingstab.ui b/files/ui/settingstab.ui index 2aafdeb00..95c10367a 100644 --- a/files/ui/settingstab.ui +++ b/files/ui/settingstab.ui @@ -128,10 +128,13 @@ - + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + 1 + @@ -386,7 +389,7 @@ sbWidth sbHeight cbStatusBar - spinBox_max_subviews + sbMaxSubViews sbMinSubViewWidth checkBox_reuse_subview cbOverride