Skip to content

Commit f575971

Browse files
Added support for perspectives to centralwidget example to test save and restore state functionality with central widget
1 parent f645fe7 commit f575971

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

demo/MainWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static void appendFeaturStringToWindowTitle(ads::CDockWidget* DockWidget)
109109
static QIcon svgIcon(const QString& File)
110110
{
111111
// This is a workaround, because in item views SVG icons are not
112-
// properly scaled an look blurry or pixelate
112+
// properly scaled and look blurry or pixelate
113113
QIcon SvgIcon(File);
114114
SvgIcon.addPixmap(SvgIcon.pixmap(92));
115115
return SvgIcon;

examples/centralwidget/mainwindow.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <QSettings>
1717
#include <QMessageBox>
1818
#include <QPlainTextEdit>
19+
#include <QToolBar>
1920

2021
#include "DockAreaWidget.h"
2122
#include "DockAreaTitleBar.h"
@@ -25,6 +26,18 @@
2526

2627
using namespace ads;
2728

29+
/**
30+
* Helper function to create an SVG icon
31+
*/
32+
static QIcon svgIcon(const QString& File)
33+
{
34+
// This is a workaround, because in item views SVG icons are not
35+
// properly scaled and look blurry or pixelate
36+
QIcon SvgIcon(File);
37+
SvgIcon.addPixmap(SvgIcon.pixmap(92));
38+
return SvgIcon;
39+
}
40+
2841
CMainWindow::CMainWindow(QWidget *parent)
2942
: QMainWindow(parent)
3043
, ui(new Ui::CMainWindow)
@@ -77,10 +90,46 @@ CMainWindow::CMainWindow(QWidget *parent)
7790
PropertiesDockWidget->setMinimumSize(200,150);
7891
DockManager->addDockWidget(DockWidgetArea::RightDockWidgetArea, PropertiesDockWidget, CentralDockArea);
7992
ui->menuView->addAction(PropertiesDockWidget->toggleViewAction());
93+
94+
createPerspectiveUi();
8095
}
8196

8297
CMainWindow::~CMainWindow()
8398
{
8499
delete ui;
85100
}
86101

102+
103+
void CMainWindow::createPerspectiveUi()
104+
{
105+
SavePerspectiveAction = new QAction("Create Perspective", this);
106+
SavePerspectiveAction->setIcon(svgIcon(":/adsdemo/images/picture_in_picture.svg"));
107+
connect(SavePerspectiveAction, SIGNAL(triggered()), SLOT(savePerspective()));
108+
PerspectiveListAction = new QWidgetAction(this);
109+
PerspectiveComboBox = new QComboBox(this);
110+
PerspectiveComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
111+
PerspectiveComboBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
112+
connect(PerspectiveComboBox, SIGNAL(activated(const QString&)),
113+
DockManager, SLOT(openPerspective(const QString&)));
114+
PerspectiveListAction->setDefaultWidget(PerspectiveComboBox);
115+
ui->toolBar->addSeparator();
116+
ui->toolBar->addAction(PerspectiveListAction);
117+
ui->toolBar->addAction(SavePerspectiveAction);
118+
}
119+
120+
121+
void CMainWindow::savePerspective()
122+
{
123+
QString PerspectiveName = QInputDialog::getText(this, "Save Perspective", "Enter unique name:");
124+
if (PerspectiveName.isEmpty())
125+
{
126+
return;
127+
}
128+
129+
DockManager->addPerspective(PerspectiveName);
130+
QSignalBlocker Blocker(PerspectiveComboBox);
131+
PerspectiveComboBox->clear();
132+
PerspectiveComboBox->addItems(DockManager->perspectiveNames());
133+
PerspectiveComboBox->setCurrentText(PerspectiveName);
134+
}
135+

examples/centralwidget/mainwindow.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#define MAINWINDOW_H
33

44
#include <QMainWindow>
5+
#include <QComboBox>
6+
#include <QWidgetAction>
57

68
#include "DockManager.h"
79
#include "DockAreaWidget.h"
@@ -20,13 +22,19 @@ class CMainWindow : public QMainWindow
2022
~CMainWindow();
2123

2224
private:
23-
static const QString kTableTopLayout;
24-
static const QString kTableBottomLayout;
25+
QAction* SavePerspectiveAction = nullptr;
26+
QWidgetAction* PerspectiveListAction = nullptr;
27+
QComboBox* PerspectiveComboBox = nullptr;
2528

2629
Ui::CMainWindow *ui;
2730

2831
ads::CDockManager* DockManager;
2932
ads::CDockAreaWidget* StatusDockArea;
3033
ads::CDockWidget* TimelineDockWidget;
34+
35+
void createPerspectiveUi();
36+
37+
private slots:
38+
void savePerspective();
3139
};
3240
#endif // MAINWINDOW_H

examples/centralwidget/mainwindow.ui

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@
3030
</widget>
3131
<addaction name="menuView"/>
3232
</widget>
33+
<widget class="QToolBar" name="toolBar">
34+
<property name="windowTitle">
35+
<string>toolBar</string>
36+
</property>
37+
<attribute name="toolBarArea">
38+
<enum>TopToolBarArea</enum>
39+
</attribute>
40+
<attribute name="toolBarBreak">
41+
<bool>false</bool>
42+
</attribute>
43+
</widget>
3344
</widget>
3445
<resources/>
3546
<connections/>

0 commit comments

Comments
 (0)