From 1f995299f056ea6bd621d17392fb974015975544 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Thu, 9 Apr 2020 23:16:50 +0200 Subject: [PATCH] Added setFullScreen(), setNormal() and isFullScreen() function to CDockWidget to be more compatible to QDockWidget --- demo/MainWindow.cpp | 20 ++++++++++++++++++ demo/MainWindow.h | 1 + demo/demo.qrc | 1 + demo/images/fullscreen.svg | 6 ++++++ src/DockWidget.cpp | 42 ++++++++++++++++++++++++++++++++++++++ src/DockWidget.h | 20 ++++++++++++++++++ 6 files changed, 90 insertions(+) create mode 100644 demo/images/fullscreen.svg diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index 5650540..212d2ad 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -266,6 +266,19 @@ static ads::CDockWidget* createTableWidget(QMenu* ViewMenu) DockWidget->setWidget(w); DockWidget->setIcon(svgIcon(":/adsdemo/images/grid_on.svg")); DockWidget->setMinimumSizeHintMode(ads::CDockWidget::MinimumSizeHintFromContent); + auto ToolBar = DockWidget->createDefaultToolBar(); + auto Action = ToolBar->addAction(svgIcon(":/adsdemo/images/fullscreen.svg"), "Toggle Fullscreen"); + QObject::connect(Action, &QAction::triggered, [=]() + { + if (DockWidget->isFullScreen()) + { + DockWidget->showNormal(); + } + else + { + DockWidget->showFullScreen(); + } + }); ViewMenu->addAction(DockWidget->toggleViewAction()); return DockWidget; } @@ -670,3 +683,10 @@ void CMainWindow::createTable() FloatingWidget->move(QPoint(40, 40)); } + +//============================================================================ +void CMainWindow::onFullscreenActionTriggered() +{ + std::cout << "CMainWindow::onFullscreenActionTriggered()" << std::endl; +} + diff --git a/demo/MainWindow.h b/demo/MainWindow.h index f2fe937..06961a8 100644 --- a/demo/MainWindow.h +++ b/demo/MainWindow.h @@ -63,6 +63,7 @@ private slots: void createEditor(); void createTable(); void onEditorCloseRequested(); + void onFullscreenActionTriggered(); }; #endif // MAINWINDOW_H diff --git a/demo/demo.qrc b/demo/demo.qrc index ddd49d8..d92ca79 100644 --- a/demo/demo.qrc +++ b/demo/demo.qrc @@ -13,5 +13,6 @@ app.css images/plus.svg images/help_outline.svg + images/fullscreen.svg diff --git a/demo/images/fullscreen.svg b/demo/images/fullscreen.svg new file mode 100644 index 0000000..2cf89e3 --- /dev/null +++ b/demo/images/fullscreen.svg @@ -0,0 +1,6 @@ + + settings_overscan icon - Licensed under Apache License v2.0 (http://www.apache.org/licenses/LICENSE-2.0) - Created with Iconfu.com - Derivative work of Material icons (Copyright Google Inc.) + + + + \ No newline at end of file diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 8099f21..4185b89 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -876,6 +876,48 @@ QList CDockWidget::titleBarActions() const } +//============================================================================ +void CDockWidget::showFullScreen() +{ + if (isFloating()) + { + dockContainer()->floatingWidget()->showFullScreen(); + } + else + { + Super::showFullScreen(); + } +} + + +//============================================================================ +void CDockWidget::showNormal() +{ + if (isFloating()) + { + dockContainer()->floatingWidget()->showNormal(); + } + else + { + Super::showFullScreen(); + } +} + + +//============================================================================ +bool CDockWidget::isFullScreen() const +{ + if (isFloating()) + { + return dockContainer()->floatingWidget()->isFullScreen(); + } + else + { + return Super::isFullScreen(); + } +} + + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockWidget.h b/src/DockWidget.h index 9d2e2ee..57e121f 100644 --- a/src/DockWidget.h +++ b/src/DockWidget.h @@ -449,6 +449,12 @@ public: void setTabToolTip(const QString &text); #endif + /** + * Returns true if the dock widget is floating and if the floating dock + * container is full screen + */ + bool isFullScreen() const; + public: // reimplements QFrame ----------------------------------------------- /** * Emits titleChanged signal if title change event occurs @@ -478,6 +484,20 @@ public slots: */ void closeDockWidget(); + /** + * Shows the widget in full-screen mode. + * Normally this function only affects windows. To make the interface + * compatible to QDockWidget, this function also maximizes a floating + * dock widget. + */ + void showFullScreen(); + + /** + * This function complements showFullScreen() to restore the widget + * after it has been in full screen mode. + */ + void showNormal(); + signals: /**