From 14c29f695c205868745bf2e0a107fa86e34a7847 Mon Sep 17 00:00:00 2001 From: hulswit Date: Fri, 21 Aug 2020 13:30:59 +0200 Subject: [PATCH] Central widget update Updated the setting of central widget with option to set where the possible old central widget will be placed. Fixed option of "unsetting" central widget by setting it to nullptr. --- .gitignore | 1 + examples/centralWidget/centralWidget.pro | 2 -- examples/centralWidget/digitalclock.cpp | 27 ------------------------ examples/centralWidget/digitalclock.h | 17 --------------- examples/centralWidget/mainwindow.cpp | 15 ++----------- src/DockContainerWidget.cpp | 10 +++++---- src/DockManager.cpp | 21 +++++++++++++----- src/DockManager.h | 4 +++- 8 files changed, 28 insertions(+), 69 deletions(-) delete mode 100644 examples/centralWidget/digitalclock.cpp delete mode 100644 examples/centralWidget/digitalclock.h diff --git a/.gitignore b/.gitignore index f9e79be..05aa783 100644 --- a/.gitignore +++ b/.gitignore @@ -382,3 +382,4 @@ MigrationBackup/ FodyWeavers.xsd / build /Settings.ini +.vscode/settings.json diff --git a/examples/centralWidget/centralWidget.pro b/examples/centralWidget/centralWidget.pro index f39896d..9c00fd6 100644 --- a/examples/centralWidget/centralWidget.pro +++ b/examples/centralWidget/centralWidget.pro @@ -22,12 +22,10 @@ DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ - digitalclock.cpp \ main.cpp \ mainwindow.cpp HEADERS += \ - digitalclock.h \ mainwindow.h FORMS += \ diff --git a/examples/centralWidget/digitalclock.cpp b/examples/centralWidget/digitalclock.cpp deleted file mode 100644 index 2752d6b..0000000 --- a/examples/centralWidget/digitalclock.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "digitalclock.h" - -#include -#include - -CDigitalClock::CDigitalClock(QWidget *parent) - : QLCDNumber(parent) -{ - setDigitCount(8); - setSegmentStyle(Filled); - - QTimer *timer = new QTimer(this); - connect(timer, &QTimer::timeout, this, &CDigitalClock::showTime); - timer->start(1000); - - showTime(); - - setWindowTitle(tr("Digital Clock")); - resize(150, 60); -} - -void CDigitalClock::showTime() -{ - QTime time = QTime::currentTime(); - QString text = time.toString("hh:mm:ss"); - display(text); -} diff --git a/examples/centralWidget/digitalclock.h b/examples/centralWidget/digitalclock.h deleted file mode 100644 index 4c155d3..0000000 --- a/examples/centralWidget/digitalclock.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef DIGITALCLOCK_H -#define DIGITALCLOCK_H - -#include - -class CDigitalClock : public QLCDNumber -{ - Q_OBJECT - -public: - CDigitalClock(QWidget *parent = nullptr); - -private slots: - void showTime(); -}; - -#endif // DIGITALCLOCK_H diff --git a/examples/centralWidget/mainwindow.cpp b/examples/centralWidget/mainwindow.cpp index cc4a8d9..285de5b 100644 --- a/examples/centralWidget/mainwindow.cpp +++ b/examples/centralWidget/mainwindow.cpp @@ -1,6 +1,5 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include "digitalclock.h" #include #include @@ -96,12 +95,8 @@ CMainWindow::CMainWindow(QWidget *parent) QCalendarWidget* calendar = new QCalendarWidget(); CDockWidget* CentralDockWidget = new CDockWidget("CentralWidget"); CentralDockWidget->setWidget(calendar); - CentralDockWidget->setFeature(CDockWidget::DockWidgetClosable, false); - CentralDockWidget->setFeature(CDockWidget::DockWidgetMovable, false); - CentralDockWidget->setFeature(CDockWidget::DockWidgetFloatable, false); auto* CentralDockArea = DockManager->setCentralWidget(CentralDockWidget); CentralDockArea->setAllowedAreas(DockWidgetArea::OuterDockAreas); - CentralDockArea->setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true); QTreeView* fileTree = new QTreeView(); fileTree->setFrameShape(QFrame::NoFrame); @@ -139,20 +134,18 @@ CMainWindow::CMainWindow(QWidget *parent) QRadioButton* radioDockTop = new QRadioButton("Top", timeLineWidget); QRadioButton* radioDockBottom = new QRadioButton("Bottom", timeLineWidget); radioDockTop->setChecked(true); - timelineLayout->addWidget(new QLabel("Fixed height Dock widget.")); + timelineLayout->addWidget(new QLabel("Test Widget.")); timelineLayout->addStretch(1); timelineLayout->addWidget(new QLabel("Apply predefined perspective: ", this)); timelineLayout->addWidget(radioDockTop); timelineLayout->addWidget(radioDockBottom); TimelineDockWidget = new CDockWidget("Timeline"); TimelineDockWidget->setWidget(timeLineWidget); -// TimelineDockWidget->setResizeMode(CDockWidget::eResizeMode::ResizeHorizontal); TimelineDockWidget->setFeature(CDockWidget::DockWidgetClosable, false); TimelineDockWidget->setFeature(CDockWidget::DockWidgetMovable, false); TimelineDockWidget->setFeature(CDockWidget::DockWidgetFloatable, false); TimelineDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget); TimelineDockWidget->setMinimumSize(QSize(50, 50)); - TimelineDockWidget->setFixedHeight(50); auto *TimelineDockArea = DockManager->addDockWidget(DockWidgetArea::TopDockWidgetArea, TimelineDockWidget); TimelineDockArea->setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true); TimelineDockArea->setAllowedAreas(DockWidgetArea::OuterDockAreas); @@ -177,7 +170,6 @@ CMainWindow::CMainWindow(QWidget *parent) QWidget* statusWidget = new QWidget(); QHBoxLayout* statusLayout = new QHBoxLayout(statusWidget); statusLayout->setSpacing(10); - CDigitalClock* clock = new CDigitalClock(statusWidget); statusLayout->addWidget(new QLabel("Status Bar")); QPushButton* OpenPerspectiveButton = new QPushButton("Open Perspective", statusWidget); connect(OpenPerspectiveButton, &QPushButton::clicked, [this](){ @@ -215,19 +207,16 @@ CMainWindow::CMainWindow(QWidget *parent) statusLayout->addWidget(OpenPerspectiveButton); statusLayout->addWidget(SavePerspectiveButton); statusLayout->addStretch(1); - statusLayout->addWidget(clock); CDockWidget* StatusDockWidget = new CDockWidget("Status"); StatusDockWidget->setWidget(statusWidget); -// StatusDockWidget->setResizeMode(CDockWidget::eResizeMode::ResizeHorizontal); StatusDockWidget->setFeature(CDockWidget::DockWidgetClosable, false); StatusDockWidget->setFeature(CDockWidget::DockWidgetMovable, false); StatusDockWidget->setFeature(CDockWidget::DockWidgetFloatable, false); StatusDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget); StatusDockWidget->setMinimumSize(QSize(50, 50)); - StatusDockWidget->setFixedHeight(50); StatusDockArea = DockManager->addDockWidget(DockWidgetArea::BottomDockWidgetArea, StatusDockWidget); StatusDockArea->setAllowedAreas(DockWidgetArea::OuterDockAreas); - StatusDockArea->setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true); + StatusDockArea->setDockAreaFlag(ads::CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true); } CMainWindow::~CMainWindow() diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 56aef07..171a8e0 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -711,11 +711,14 @@ void DockContainerWidgetPrivate::moveToNewSection(QWidget* Widget, CDockAreaWidg //============================================================================ void DockContainerWidgetPrivate::updateSplitterHandles( QSplitter* splitter ) { - if( splitter ) + if(DockManager->centralWidget()) { - for( int index = 0; index < splitter->count(); index++ ) + if( splitter ) { - splitter->setStretchFactor(index, widgetResizesWithContainer(splitter->widget(index)) ? 1 : 0); + for( int index = 0; index < splitter->count(); index++ ) + { + splitter->setStretchFactor(index, widgetResizesWithContainer(splitter->widget(index)) ? 1 : 0); + } } } } @@ -1256,7 +1259,6 @@ CDockAreaWidget* DockContainerWidgetPrivate::addDockWidgetToDockArea(DockWidgetA auto TargetAreaSizes = TargetAreaSplitter->sizes(); QSplitter* NewSplitter = newSplitter(InsertParam.orientation()); NewSplitter->addWidget(TargetDockArea); -// updateSplitterHandles(NewSplitter); insertWidgetIntoSplitter(NewSplitter, NewDockArea, InsertParam.append()); updateSplitterHandles(NewSplitter); diff --git a/src/DockManager.cpp b/src/DockManager.cpp index d04cc50..145501f 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -407,6 +407,7 @@ bool DockManagerPrivate::restoreState(const QByteArray& State, int version) return false; } + CentralWidget = nullptr; // Hide updates of floating widgets from use hideFloatingWidgets(); markDockWidgetsDirty(); @@ -830,15 +831,25 @@ CDockWidget* CDockManager::centralWidget() } //============================================================================ -CDockAreaWidget* CDockManager::setCentralWidget(CDockWidget* widget) +CDockAreaWidget* CDockManager::setCentralWidget(CDockWidget* widget, CDockWidget* oldCentralWidget, DockWidgetArea oldCentralWidgetArea) { - if(d->CentralWidget) + oldCentralWidget = d->CentralWidget; + if(oldCentralWidget) { - addDockWidget(RightDockWidgetArea, d->CentralWidget); + addDockWidget(oldCentralWidgetArea, oldCentralWidget); } - d->CentralWidget = widget; - return addDockWidget(CenterDockWidgetArea, widget); + if(widget) + { + widget->setFeature(CDockWidget::DockWidgetClosable, false); + widget->setFeature(CDockWidget::DockWidgetMovable, false); + widget->setFeature(CDockWidget::DockWidgetFloatable, false); + d->CentralWidget = widget; + CDockAreaWidget* CentralArea = addDockWidget(CenterDockWidgetArea, widget); + CentralArea->setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true); + return CentralArea; + } + return nullptr; } //============================================================================ diff --git a/src/DockManager.h b/src/DockManager.h index 7808a43..07f735c 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -387,8 +387,10 @@ public: * Adds dockwidget into the central area and marks it as central widget. * If central widget is set, it will be the only dock widget * that will resize with the dock container. + * If a central widget does exist, it will be docked to oldCentralWidgetArea + * and returned in oldCentralWidget. */ - CDockAreaWidget* setCentralWidget(CDockWidget* widget); + CDockAreaWidget* setCentralWidget(CDockWidget* widget, CDockWidget* oldCentralWidget = nullptr, DockWidgetArea oldCentralWidgetArea = DockWidgetArea::RightDockWidgetArea); /** * Adds a toggle view action to the the internal view menu.