From e9ca02216201fdb64e1dcd59a6a385d8a4c067d5 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Sun, 17 May 2015 20:45:13 +1000 Subject: [PATCH 1/2] Add an optional horizontal scrollbar to the main view window. Should resolve Feature #2549. - TableSubviews and DialogueSubviews now provide size hints - Option to stop the growth of the window at the screen boundary for multi-monitor setup with different resolution. - Three options: Grow Only: No change to current, except the use of size hints Scrollbar Only: Simple addition of a scrollbar, the view window does not grow Grow then Scroll: Window grows as per current behaviour. The scrollbar appears once it cannot grow any further. --- apps/opencs/model/settings/usersettings.cpp | 14 ++ apps/opencs/view/doc/subview.cpp | 16 +++ apps/opencs/view/doc/subview.hpp | 13 ++ apps/opencs/view/doc/view.cpp | 145 +++++++++++++++++++- apps/opencs/view/doc/view.hpp | 5 + apps/opencs/view/world/dialoguesubview.cpp | 12 +- apps/opencs/view/world/tablesubview.cpp | 12 +- 7 files changed, 213 insertions(+), 4 deletions(-) diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index 41ce593b7..bd31b6e38 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -143,6 +143,20 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() minWidth->setDefaultValue (325); minWidth->setRange (50, 10000); minWidth->setToolTip ("Minimum width of subviews."); + + QString defaultScroll = "Scrollbar Only"; + QStringList scrollValues = QStringList() << defaultScroll << "Grow Only" << "Grow then Scroll"; + + Setting *mainwinScroll = createSetting (Type_RadioButton, "mainwindow-scrollbar", + "Add a horizontal scrollbar to the main view window."); + mainwinScroll->setDefaultValue (defaultScroll); + mainwinScroll->setDeclaredValues (scrollValues); + + Setting *grow = createSetting (Type_CheckBox, "grow-limit", "Grow Limit Screen"); + grow->setDefaultValue ("false"); + grow->setToolTip ("When \"Grow then Scroll\" option is selected, the window size grows to" + " the width of the virtual desktop. \nIf this option is selected the the window growth" + "is limited to the current screen."); } declareSection ("records", "Records"); diff --git a/apps/opencs/view/doc/subview.cpp b/apps/opencs/view/doc/subview.cpp index df1e7ee49..09128d919 100644 --- a/apps/opencs/view/doc/subview.cpp +++ b/apps/opencs/view/doc/subview.cpp @@ -43,3 +43,19 @@ void CSVDoc::SubView::closeRequest() { emit closeRequest (this); } + +CSVDoc::SizeHintWidget::SizeHintWidget(QWidget *parent) : QWidget(parent) +{} + +CSVDoc::SizeHintWidget::~SizeHintWidget() +{} + +QSize CSVDoc::SizeHintWidget::sizeHint() const +{ + return mSize; +} + +void CSVDoc::SizeHintWidget::setSizeHint(const QSize &size) +{ + mSize = size; +} diff --git a/apps/opencs/view/doc/subview.hpp b/apps/opencs/view/doc/subview.hpp index a8aa3cda1..f327107c2 100644 --- a/apps/opencs/view/doc/subview.hpp +++ b/apps/opencs/view/doc/subview.hpp @@ -8,6 +8,7 @@ #include "subviewfactory.hpp" #include +#include class QUndoStack; @@ -70,6 +71,18 @@ namespace CSVDoc void closeRequest(); }; + + class SizeHintWidget : public QWidget + { + QSize mSize; + + public: + SizeHintWidget(QWidget *parent = 0); + ~SizeHintWidget(); + + virtual QSize sizeHint() const; + void setSizeHint(const QSize &size); + }; } #endif diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 5636fff94..16b96ed4d 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -9,6 +9,10 @@ #include #include #include +#include +#include +#include +#include #include "../../model/doc/document.hpp" #include "../../model/settings/usersettings.hpp" @@ -16,6 +20,7 @@ #include "../../model/world/idtable.hpp" #include "../world/subviews.hpp" +#include "../world/tablesubview.hpp" #include "../tools/subviews.hpp" @@ -334,8 +339,15 @@ void CSVDoc::View::updateTitle() void CSVDoc::View::updateSubViewIndicies(SubView *view) { if(view && mSubViews.contains(view)) + { mSubViews.removeOne(view); + // adjust (reduce) the scroll area (even floating), except when it is "Scrollbar Only" + CSMSettings::UserSettings &settings = CSMSettings::UserSettings::instance(); + if(settings.settingValue ("window/mainwindow-scrollbar") == "Grow then Scroll") + updateScrollbar(); + } + CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); bool hideTitle = userSettings.setting ("window/hide-subview", QString ("false"))=="true" && @@ -381,7 +393,7 @@ void CSVDoc::View::updateActions() CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews) : mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1), - mViewTotal (totalViews) + mViewTotal (totalViews), mScroll(0), mScrollbarOnly(false) { int width = CSMSettings::UserSettings::instance().settingValue ("window/default-width").toInt(); @@ -400,7 +412,18 @@ CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int to mSubViewWindow.setDockOptions (QMainWindow::AllowNestedDocks); - setCentralWidget (&mSubViewWindow); + CSMSettings::UserSettings &settings = CSMSettings::UserSettings::instance(); + if(settings.settingValue ("window/mainwindow-scrollbar") == "Grow Only") + { + setCentralWidget (&mSubViewWindow); + } + else + { + mScroll = new QScrollArea(this); + mScroll->setWidgetResizable(true); + mScroll->setWidget(&mSubViewWindow); + setCentralWidget(mScroll); + } mOperations = new Operations; addDockWidget (Qt::BottomDockWidgetArea, mOperations); @@ -527,6 +550,59 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id, const std::strin view->setStatusBar (mShowStatusBar->isChecked()); + // Work out how to deal with additional subviews + // + // Policy for "Grow then Scroll": + // + // - Increase the horizontal width of the mainwindow until it becomes greater than or equal + // to the screen (monitor) width. + // - Move the mainwindow position sideways if necessary to fit within the screen. + // - Any more additions increases the size of the mSubViewWindow (horizontal scrollbar + // should become visible) + // - Move the scroll bar to the newly added subview + // + CSMSettings::UserSettings &settings = CSMSettings::UserSettings::instance(); + QString mainwinScroll = settings.settingValue ("window/mainwindow-scrollbar"); + if (mainwinScroll.isEmpty() || mainwinScroll == "Scrollbar Only") + mScrollbarOnly = true; + else if(mainwinScroll == "Grow Only") + mScrollbarOnly = false; + else + mScrollbarOnly = false; + + QDesktopWidget *dw = QApplication::desktop(); + QRect rect; + if(settings.settingValue ("window/grow-limit") == "true") + rect = dw->screenGeometry(this); + else + rect = dw->screenGeometry(dw->screen(dw->screenNumber(this))); + + if (!mScrollbarOnly && mScroll && mSubViews.size() > 1) + { + int newWidth = width()+minWidth; + int frameWidth = frameGeometry().width() - width(); + if (newWidth+frameWidth <= rect.width()) + { + resize(newWidth, height()); + // WARNING: below code assumes that new subviews are added to the right + if (x() > rect.width()-(newWidth+frameWidth)) + move(rect.width()-(newWidth+frameWidth), y()); // shift left to stay within the screen + } + else + { + // full width + resize(rect.width()-frameWidth, height()); + mSubViewWindow.setMinimumWidth(mSubViewWindow.width()+minWidth); + move(0, y()); + } + + // Make the new subview visible, setFocus() or raise() don't seem to work + // On Ubuntu the scrollbar does not go right to the end, even if using + // mScroll->horizontalScrollBar()->setValue(mScroll->horizontalScrollBar()->maximum()); + if (mSubViewWindow.width() > rect.width()) + mScroll->horizontalScrollBar()->setValue(mSubViewWindow.width()); + } + mSubViewWindow.addDockWidget (Qt::TopDockWidgetArea, view); updateSubViewIndicies(); @@ -774,6 +850,48 @@ void CSVDoc::View::updateUserSetting (const QString &name, const QStringList &li { subView->updateUserSetting (name, list); } + + if (name=="window/mainwindow-scrollbar") + { + if(list.at(0) != "Grow Only") + { + if (mScroll) + { + if (list.at(0).isEmpty() || list.at(0) == "Scrollbar Only") + { + mScrollbarOnly = true; + mSubViewWindow.setMinimumWidth(0); + } + else + { + if(!mScrollbarOnly) + return; + + mScrollbarOnly = false; + updateScrollbar(); + } + } + else + { + mScroll = new QScrollArea(this); + mScroll->setWidgetResizable(true); + mScroll->setWidget(&mSubViewWindow); + setCentralWidget(mScroll); + } + } + else + { + if (mScroll) + { + mScroll->takeWidget(); + setCentralWidget (&mSubViewWindow); + mScroll->deleteLater(); + mScroll = 0; + } + else + return; + } + } } void CSVDoc::View::toggleShowStatusBar (bool show) @@ -815,3 +933,26 @@ void CSVDoc::View::closeRequest (SubView *subView) else if (mViewManager.closeRequest (this)) mViewManager.removeDocAndView (mDocument); } + +void CSVDoc::View::updateScrollbar() +{ + QRect rect; + QWidget *topLevel = QApplication::topLevelAt(pos()); + if (topLevel) + rect = topLevel->rect(); + else + rect = this->rect(); + + int newWidth = 0; + for (int i = 0; i < mSubViews.size(); ++i) + { + newWidth += mSubViews[i]->width(); + } + + int frameWidth = frameGeometry().width() - width(); + + if ((newWidth+frameWidth) >= rect.width()) + mSubViewWindow.setMinimumWidth(newWidth); + else + mSubViewWindow.setMinimumWidth(0); +} diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index 32d7159c2..1d44cb7f5 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -10,6 +10,7 @@ class QAction; class QDockWidget; +class QScrollArea; namespace CSMDoc { @@ -47,6 +48,8 @@ namespace CSVDoc SubViewFactoryManager mSubViewFactory; QMainWindow mSubViewWindow; GlobalDebugProfileMenu *mGlobalDebugProfileMenu; + QScrollArea *mScroll; + bool mScrollbarOnly; // not implemented @@ -87,6 +90,8 @@ namespace CSVDoc /// User preference function void resizeViewHeight (int height); + void updateScrollbar(); + public: View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews); diff --git a/apps/opencs/view/world/dialoguesubview.cpp b/apps/opencs/view/world/dialoguesubview.cpp index 0d0e82dbf..ccab576fa 100644 --- a/apps/opencs/view/world/dialoguesubview.cpp +++ b/apps/opencs/view/world/dialoguesubview.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include "../../model/world/nestedtableproxymodel.hpp" #include "../../model/world/columnbase.hpp" @@ -581,7 +583,15 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM changeCurrentId(id.getId()); - QWidget *mainWidget = new QWidget(this); + //QWidget *mainWidget = new QWidget(this); + CSVDoc::SizeHintWidget *mainWidget = new CSVDoc::SizeHintWidget; + + const QRect rect = QApplication::desktop()->screenGeometry(this); + int frameHeight = 40; // set a reasonable default + QWidget *topLevel = QApplication::topLevelAt(pos()); + if (topLevel) + frameHeight = topLevel->frameGeometry().height() - topLevel->height(); + mainWidget->setSizeHint(QSize(400, rect.height()-frameHeight)); // FIXME: 400 QHBoxLayout *buttonsLayout = new QHBoxLayout; QToolButton* prevButton = new QToolButton(mainWidget); diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 729b6b8d7..dde04fb3f 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -3,6 +3,9 @@ #include #include +#include +#include +#include #include "../../model/doc/document.hpp" #include "../../model/world/tablemimedata.hpp" @@ -30,11 +33,18 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D layout->insertWidget (0, mFilterBox); - QWidget *widget = new QWidget; + CSVDoc::SizeHintWidget *widget = new CSVDoc::SizeHintWidget; widget->setLayout (layout); setWidget (widget); + // prefer height of the screen and full width of the table + const QRect rect = QApplication::desktop()->screenGeometry(this); + int frameHeight = 40; // set a reasonable default + QWidget *topLevel = QApplication::topLevelAt(pos()); + if (topLevel) + frameHeight = topLevel->frameGeometry().height() - topLevel->height(); + widget->setSizeHint(QSize(mTable->horizontalHeader()->length(), rect.height()-frameHeight)); connect (mTable, SIGNAL (editRequest (const CSMWorld::UniversalId&, const std::string&)), this, SLOT (editRequest (const CSMWorld::UniversalId&, const std::string&))); From cfcfb173205bb1148b7b40f20b3eb75eb6791295 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Mon, 18 May 2015 07:12:02 +1000 Subject: [PATCH 2/2] Updates to optional horizontal scrollbar. - move SizeHintWidget out to separate files - remove redundant logic in view.cpp - remove sizehint from dialogue subview - add tooltip hints in user preferences --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/model/settings/usersettings.cpp | 4 ++++ apps/opencs/view/doc/sizehint.cpp | 17 ++++++++++++++++ apps/opencs/view/doc/sizehint.hpp | 22 +++++++++++++++++++++ apps/opencs/view/doc/subview.cpp | 16 --------------- apps/opencs/view/doc/subview.hpp | 13 ------------ apps/opencs/view/doc/view.cpp | 7 +------ apps/opencs/view/world/dialoguesubview.cpp | 12 +---------- apps/opencs/view/world/tablesubview.cpp | 1 + 9 files changed, 47 insertions(+), 47 deletions(-) create mode 100644 apps/opencs/view/doc/sizehint.cpp create mode 100644 apps/opencs/view/doc/sizehint.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 9fb80324e..438f3c694 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -46,7 +46,7 @@ opencs_units_noqt (model/tools opencs_units (view/doc viewmanager view operations operation subview startup filedialog newgame - filewidget adjusterwidget loader globaldebugprofilemenu runlogsubview + filewidget adjusterwidget loader globaldebugprofilemenu runlogsubview sizehint ) diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index bd31b6e38..ea002c5ed 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -151,6 +151,10 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() "Add a horizontal scrollbar to the main view window."); mainwinScroll->setDefaultValue (defaultScroll); mainwinScroll->setDeclaredValues (scrollValues); + mainwinScroll->setToolTip ("Scrollbar Only: Simple addition of scrollbars, the view window does not grow" + " automatically.\n" + "Grow Only: Original Editor behaviour. The view window grows as subviews are added. No scrollbars.\n" + "Grow then Scroll: The view window grows. The scrollbar appears once it cannot grow any further."); Setting *grow = createSetting (Type_CheckBox, "grow-limit", "Grow Limit Screen"); grow->setDefaultValue ("false"); diff --git a/apps/opencs/view/doc/sizehint.cpp b/apps/opencs/view/doc/sizehint.cpp new file mode 100644 index 000000000..038bd9e4d --- /dev/null +++ b/apps/opencs/view/doc/sizehint.cpp @@ -0,0 +1,17 @@ +#include "sizehint.hpp" + +CSVDoc::SizeHintWidget::SizeHintWidget(QWidget *parent) : QWidget(parent) +{} + +CSVDoc::SizeHintWidget::~SizeHintWidget() +{} + +QSize CSVDoc::SizeHintWidget::sizeHint() const +{ + return mSize; +} + +void CSVDoc::SizeHintWidget::setSizeHint(const QSize &size) +{ + mSize = size; +} diff --git a/apps/opencs/view/doc/sizehint.hpp b/apps/opencs/view/doc/sizehint.hpp new file mode 100644 index 000000000..cf5a02580 --- /dev/null +++ b/apps/opencs/view/doc/sizehint.hpp @@ -0,0 +1,22 @@ +#ifndef CSV_DOC_SIZEHINT_H +#define CSV_DOC_SIZEHINT_H + +#include +#include + +namespace CSVDoc +{ + class SizeHintWidget : public QWidget + { + QSize mSize; + + public: + SizeHintWidget(QWidget *parent = 0); + ~SizeHintWidget(); + + virtual QSize sizeHint() const; + void setSizeHint(const QSize &size); + }; +} + +#endif // CSV_DOC_SIZEHINT_H diff --git a/apps/opencs/view/doc/subview.cpp b/apps/opencs/view/doc/subview.cpp index 09128d919..df1e7ee49 100644 --- a/apps/opencs/view/doc/subview.cpp +++ b/apps/opencs/view/doc/subview.cpp @@ -43,19 +43,3 @@ void CSVDoc::SubView::closeRequest() { emit closeRequest (this); } - -CSVDoc::SizeHintWidget::SizeHintWidget(QWidget *parent) : QWidget(parent) -{} - -CSVDoc::SizeHintWidget::~SizeHintWidget() -{} - -QSize CSVDoc::SizeHintWidget::sizeHint() const -{ - return mSize; -} - -void CSVDoc::SizeHintWidget::setSizeHint(const QSize &size) -{ - mSize = size; -} diff --git a/apps/opencs/view/doc/subview.hpp b/apps/opencs/view/doc/subview.hpp index f327107c2..a8aa3cda1 100644 --- a/apps/opencs/view/doc/subview.hpp +++ b/apps/opencs/view/doc/subview.hpp @@ -8,7 +8,6 @@ #include "subviewfactory.hpp" #include -#include class QUndoStack; @@ -71,18 +70,6 @@ namespace CSVDoc void closeRequest(); }; - - class SizeHintWidget : public QWidget - { - QSize mSize; - - public: - SizeHintWidget(QWidget *parent = 0); - ~SizeHintWidget(); - - virtual QSize sizeHint() const; - void setSizeHint(const QSize &size); - }; } #endif diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 16b96ed4d..47810a115 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -563,12 +563,7 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id, const std::strin // CSMSettings::UserSettings &settings = CSMSettings::UserSettings::instance(); QString mainwinScroll = settings.settingValue ("window/mainwindow-scrollbar"); - if (mainwinScroll.isEmpty() || mainwinScroll == "Scrollbar Only") - mScrollbarOnly = true; - else if(mainwinScroll == "Grow Only") - mScrollbarOnly = false; - else - mScrollbarOnly = false; + mScrollbarOnly = mainwinScroll.isEmpty() || mainwinScroll == "Scrollbar Only"; QDesktopWidget *dw = QApplication::desktop(); QRect rect; diff --git a/apps/opencs/view/world/dialoguesubview.cpp b/apps/opencs/view/world/dialoguesubview.cpp index ccab576fa..0d0e82dbf 100644 --- a/apps/opencs/view/world/dialoguesubview.cpp +++ b/apps/opencs/view/world/dialoguesubview.cpp @@ -20,8 +20,6 @@ #include #include #include -#include -#include #include "../../model/world/nestedtableproxymodel.hpp" #include "../../model/world/columnbase.hpp" @@ -583,15 +581,7 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM changeCurrentId(id.getId()); - //QWidget *mainWidget = new QWidget(this); - CSVDoc::SizeHintWidget *mainWidget = new CSVDoc::SizeHintWidget; - - const QRect rect = QApplication::desktop()->screenGeometry(this); - int frameHeight = 40; // set a reasonable default - QWidget *topLevel = QApplication::topLevelAt(pos()); - if (topLevel) - frameHeight = topLevel->frameGeometry().height() - topLevel->height(); - mainWidget->setSizeHint(QSize(400, rect.height()-frameHeight)); // FIXME: 400 + QWidget *mainWidget = new QWidget(this); QHBoxLayout *buttonsLayout = new QHBoxLayout; QToolButton* prevButton = new QToolButton(mainWidget); diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index dde04fb3f..af0b64447 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -10,6 +10,7 @@ #include "../../model/doc/document.hpp" #include "../../model/world/tablemimedata.hpp" +#include "../doc/sizehint.hpp" #include "../filter/filterbox.hpp" #include "table.hpp" #include "tablebottombox.hpp"