From f5759716b4b4c9654d598087b19ba8ae3ab66a52 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 21 Sep 2020 08:39:39 +0200 Subject: [PATCH] Added support for perspectives to centralwidget example to test save and restore state functionality with central widget --- demo/MainWindow.cpp | 2 +- examples/centralwidget/mainwindow.cpp | 49 +++++++++++++++++++++++++++ examples/centralwidget/mainwindow.h | 12 +++++-- examples/centralwidget/mainwindow.ui | 11 ++++++ 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index 2dbdc59..47add8f 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -109,7 +109,7 @@ static void appendFeaturStringToWindowTitle(ads::CDockWidget* DockWidget) static QIcon svgIcon(const QString& File) { // This is a workaround, because in item views SVG icons are not - // properly scaled an look blurry or pixelate + // properly scaled and look blurry or pixelate QIcon SvgIcon(File); SvgIcon.addPixmap(SvgIcon.pixmap(92)); return SvgIcon; diff --git a/examples/centralwidget/mainwindow.cpp b/examples/centralwidget/mainwindow.cpp index 19c0ea4..9a3caa6 100644 --- a/examples/centralwidget/mainwindow.cpp +++ b/examples/centralwidget/mainwindow.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "DockAreaWidget.h" #include "DockAreaTitleBar.h" @@ -25,6 +26,18 @@ using namespace ads; +/** + * Helper function to create an SVG icon + */ +static QIcon svgIcon(const QString& File) +{ + // This is a workaround, because in item views SVG icons are not + // properly scaled and look blurry or pixelate + QIcon SvgIcon(File); + SvgIcon.addPixmap(SvgIcon.pixmap(92)); + return SvgIcon; +} + CMainWindow::CMainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::CMainWindow) @@ -77,6 +90,8 @@ CMainWindow::CMainWindow(QWidget *parent) PropertiesDockWidget->setMinimumSize(200,150); DockManager->addDockWidget(DockWidgetArea::RightDockWidgetArea, PropertiesDockWidget, CentralDockArea); ui->menuView->addAction(PropertiesDockWidget->toggleViewAction()); + + createPerspectiveUi(); } CMainWindow::~CMainWindow() @@ -84,3 +99,37 @@ CMainWindow::~CMainWindow() delete ui; } + +void CMainWindow::createPerspectiveUi() +{ + SavePerspectiveAction = new QAction("Create Perspective", this); + SavePerspectiveAction->setIcon(svgIcon(":/adsdemo/images/picture_in_picture.svg")); + connect(SavePerspectiveAction, SIGNAL(triggered()), SLOT(savePerspective())); + PerspectiveListAction = new QWidgetAction(this); + PerspectiveComboBox = new QComboBox(this); + PerspectiveComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); + PerspectiveComboBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + connect(PerspectiveComboBox, SIGNAL(activated(const QString&)), + DockManager, SLOT(openPerspective(const QString&))); + PerspectiveListAction->setDefaultWidget(PerspectiveComboBox); + ui->toolBar->addSeparator(); + ui->toolBar->addAction(PerspectiveListAction); + ui->toolBar->addAction(SavePerspectiveAction); +} + + +void CMainWindow::savePerspective() +{ + QString PerspectiveName = QInputDialog::getText(this, "Save Perspective", "Enter unique name:"); + if (PerspectiveName.isEmpty()) + { + return; + } + + DockManager->addPerspective(PerspectiveName); + QSignalBlocker Blocker(PerspectiveComboBox); + PerspectiveComboBox->clear(); + PerspectiveComboBox->addItems(DockManager->perspectiveNames()); + PerspectiveComboBox->setCurrentText(PerspectiveName); +} + diff --git a/examples/centralwidget/mainwindow.h b/examples/centralwidget/mainwindow.h index cbd05b0..b31c91b 100644 --- a/examples/centralwidget/mainwindow.h +++ b/examples/centralwidget/mainwindow.h @@ -2,6 +2,8 @@ #define MAINWINDOW_H #include +#include +#include #include "DockManager.h" #include "DockAreaWidget.h" @@ -20,13 +22,19 @@ public: ~CMainWindow(); private: - static const QString kTableTopLayout; - static const QString kTableBottomLayout; + QAction* SavePerspectiveAction = nullptr; + QWidgetAction* PerspectiveListAction = nullptr; + QComboBox* PerspectiveComboBox = nullptr; Ui::CMainWindow *ui; ads::CDockManager* DockManager; ads::CDockAreaWidget* StatusDockArea; ads::CDockWidget* TimelineDockWidget; + + void createPerspectiveUi(); + +private slots: + void savePerspective(); }; #endif // MAINWINDOW_H diff --git a/examples/centralwidget/mainwindow.ui b/examples/centralwidget/mainwindow.ui index 135fdd1..f7d3b09 100644 --- a/examples/centralwidget/mainwindow.ui +++ b/examples/centralwidget/mainwindow.ui @@ -30,6 +30,17 @@ + + + toolBar + + + TopToolBarArea + + + false + +