mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-25 07:31:33 +08:00
Added support for perspectives to centralwidget example to test save and restore state functionality with central widget
This commit is contained in:
parent
f645fe725a
commit
f5759716b4
@ -109,7 +109,7 @@ static void appendFeaturStringToWindowTitle(ads::CDockWidget* DockWidget)
|
|||||||
static QIcon svgIcon(const QString& File)
|
static QIcon svgIcon(const QString& File)
|
||||||
{
|
{
|
||||||
// This is a workaround, because in item views SVG icons are not
|
// 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);
|
QIcon SvgIcon(File);
|
||||||
SvgIcon.addPixmap(SvgIcon.pixmap(92));
|
SvgIcon.addPixmap(SvgIcon.pixmap(92));
|
||||||
return SvgIcon;
|
return SvgIcon;
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
|
#include <QToolBar>
|
||||||
|
|
||||||
#include "DockAreaWidget.h"
|
#include "DockAreaWidget.h"
|
||||||
#include "DockAreaTitleBar.h"
|
#include "DockAreaTitleBar.h"
|
||||||
@ -25,6 +26,18 @@
|
|||||||
|
|
||||||
using namespace ads;
|
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)
|
CMainWindow::CMainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(new Ui::CMainWindow)
|
, ui(new Ui::CMainWindow)
|
||||||
@ -77,6 +90,8 @@ CMainWindow::CMainWindow(QWidget *parent)
|
|||||||
PropertiesDockWidget->setMinimumSize(200,150);
|
PropertiesDockWidget->setMinimumSize(200,150);
|
||||||
DockManager->addDockWidget(DockWidgetArea::RightDockWidgetArea, PropertiesDockWidget, CentralDockArea);
|
DockManager->addDockWidget(DockWidgetArea::RightDockWidgetArea, PropertiesDockWidget, CentralDockArea);
|
||||||
ui->menuView->addAction(PropertiesDockWidget->toggleViewAction());
|
ui->menuView->addAction(PropertiesDockWidget->toggleViewAction());
|
||||||
|
|
||||||
|
createPerspectiveUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
CMainWindow::~CMainWindow()
|
CMainWindow::~CMainWindow()
|
||||||
@ -84,3 +99,37 @@ CMainWindow::~CMainWindow()
|
|||||||
delete ui;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QWidgetAction>
|
||||||
|
|
||||||
#include "DockManager.h"
|
#include "DockManager.h"
|
||||||
#include "DockAreaWidget.h"
|
#include "DockAreaWidget.h"
|
||||||
@ -20,13 +22,19 @@ public:
|
|||||||
~CMainWindow();
|
~CMainWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const QString kTableTopLayout;
|
QAction* SavePerspectiveAction = nullptr;
|
||||||
static const QString kTableBottomLayout;
|
QWidgetAction* PerspectiveListAction = nullptr;
|
||||||
|
QComboBox* PerspectiveComboBox = nullptr;
|
||||||
|
|
||||||
Ui::CMainWindow *ui;
|
Ui::CMainWindow *ui;
|
||||||
|
|
||||||
ads::CDockManager* DockManager;
|
ads::CDockManager* DockManager;
|
||||||
ads::CDockAreaWidget* StatusDockArea;
|
ads::CDockAreaWidget* StatusDockArea;
|
||||||
ads::CDockWidget* TimelineDockWidget;
|
ads::CDockWidget* TimelineDockWidget;
|
||||||
|
|
||||||
|
void createPerspectiveUi();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void savePerspective();
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
@ -30,6 +30,17 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<addaction name="menuView"/>
|
<addaction name="menuView"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QToolBar" name="toolBar">
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>toolBar</string>
|
||||||
|
</property>
|
||||||
|
<attribute name="toolBarArea">
|
||||||
|
<enum>TopToolBarArea</enum>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="toolBarBreak">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
Loading…
Reference in New Issue
Block a user