From bf9aa2e1317ec2b49ecb84b32924d0a1ba2397b2 Mon Sep 17 00:00:00 2001 From: pi03k Date: Wed, 27 Jan 2016 18:50:53 +0100 Subject: [PATCH] Extracted resizing of window's width to separate method --- apps/opencs/view/doc/view.cpp | 57 +++++++++++++++++++---------------- apps/opencs/view/doc/view.hpp | 2 +- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 3491c9de2..234483744 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -570,32 +570,7 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id, const std::strin // mScrollbarOnly = windows["mainwindow-scrollbar"].toString() == "Scrollbar Only"; - QDesktopWidget *dw = QApplication::desktop(); - QRect rect; - if (windows["grow-limit"].isTrue()) - 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()); - } - } + updateWidth(windows["grow-limit"].isTrue(), minWidth); mSubViewWindow.addDockWidget (Qt::TopDockWidgetArea, view); @@ -959,3 +934,33 @@ void CSVDoc::View::merge() { emit mergeDocument (mDocument); } + +void CSVDoc::View::updateWidth(bool isGrowLimit, int minSubViewWidth) +{ + QDesktopWidget *dw = QApplication::desktop(); + QRect rect; + if (isGrowLimit) + rect = dw->screenGeometry(this); + else + rect = dw->screenGeometry(dw->screen(dw->screenNumber(this))); + + if (!mScrollbarOnly && mScroll && mSubViews.size() > 1) + { + int newWidth = width()+minSubViewWidth; + 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()+minSubViewWidth); + move(0, y()); + } + } +} diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index 7d5304269..4a620121e 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -95,7 +95,7 @@ namespace CSVDoc void resizeViewHeight (int height); void updateScrollbar(); - + void updateWidth(bool isGrowLimit, int minSubViewWidth); public: View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews);