From fdf375fb4d21d19373e2be16b4ddba3069804c8f Mon Sep 17 00:00:00 2001 From: cc9cii Date: Wed, 24 Sep 2014 13:49:19 +1000 Subject: [PATCH] Reusing subviews implemented. --- apps/opencs/view/doc/view.cpp | 30 +++++++++++++++++++++++++--- apps/opencs/view/settings/dialog.cpp | 7 +++++++ files/ui/settingstab.ui | 4 ++-- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 6c04ac322..baa3a3608 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -454,6 +454,33 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id, const std::strin { CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); + const std::vector referenceables(CSMWorld::UniversalId::listReferenceableTypes()); + bool isReferenceable = std::find(referenceables.begin(), referenceables.end(), id.getType()) != referenceables.end(); + + // User setting to reuse sub views (on a per top level view basis) + bool reuse = true; + if(userSettings.hasSettingDefinitions("SubView/reuse")) + reuse = userSettings.settingValue("SubView/reuse").toStdString() == "true" ? true : false; + else + userSettings.setDefinitions("SubView/reuse", (QStringList() << QString(reuse ? "true" : "false"))); + if(reuse) + { + foreach(SubView *sb, mSubViews) + { + if((isReferenceable && (CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Referenceable, id.getId()) == CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Referenceable, sb->getUniversalId().getId()))) + || (!isReferenceable && (id == sb->getUniversalId()))) + { + sb->setFocus(Qt::OtherFocusReason); // FIXME: focus not quite working + return; + } + } + } + + // 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 + // + // If the sub view limit setting is one, the sub view title bar is hidden and the + // text in the main title bar is adjusted accordingly int maxSubView = 3; if(userSettings.hasSettingDefinitions("SubView/max subviews")) maxSubView = userSettings.settingValue("SubView/max subviews").toInt(); @@ -467,9 +494,6 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id, const std::strin return; } - /// \todo add an user setting to reuse sub views (on a per document basis or on a per top level view basis) - - const std::vector referenceables(CSMWorld::UniversalId::listReferenceableTypes()); SubView *view = NULL; if(std::find(referenceables.begin(), referenceables.end(), id.getType()) != referenceables.end()) { diff --git a/apps/opencs/view/settings/dialog.cpp b/apps/opencs/view/settings/dialog.cpp index 7d2b8f0a5..f2d38bab9 100644 --- a/apps/opencs/view/settings/dialog.cpp +++ b/apps/opencs/view/settings/dialog.cpp @@ -310,6 +310,8 @@ void CSVSettings::Dialog::buildPages() else sbMaxSubViews->setValue(3); + cbReuseSubView->setChecked(model()->settingValue("SubView/reuse") == "true"); + SettingWindow::createPages (); foreach (Page *page, SettingWindow::pages()) @@ -393,6 +395,11 @@ void CSVSettings::Dialog::closeEvent (QCloseEvent *event) model()->setDefinitions("SubView/max subviews", QStringList(QString::number(sbMaxSubViews->value()))); + if(cbReuseSubView->isChecked()) + model()->setDefinitions("SubView/reuse", QStringList("true")); + else + model()->setDefinitions("SubView/reuse", QStringList("false")); + saveSettings(); } diff --git a/files/ui/settingstab.ui b/files/ui/settingstab.ui index 95c10367a..e44a51f5a 100644 --- a/files/ui/settingstab.ui +++ b/files/ui/settingstab.ui @@ -161,7 +161,7 @@ - + Reuse Subviews @@ -391,7 +391,7 @@ cbStatusBar sbMaxSubViews sbMinSubViewWidth - checkBox_reuse_subview + cbReuseSubView cbOverride cmbRenderSys cbVsync