mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 07:21:32 +08:00
Fixed a bug in restore functionality that caused application crash, added initial support for perspectives
This commit is contained in:
parent
805e97946e
commit
8a401ebd68
@ -25,6 +25,7 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/QtAdvancedDockingSystem/src}""/>
|
||||
<listOptionValue builtIn="false" value=""${QTDIR}/include""/>
|
||||
<listOptionValue builtIn="false" value=""${QTDIR}/include/QtCore""/>
|
||||
<listOptionValue builtIn="false" value=""${QTDIR}/include/QtWidgets""/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1249325593" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
|
||||
</tool>
|
||||
@ -35,6 +36,7 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/QtAdvancedDockingSystem/demo}""/>
|
||||
<listOptionValue builtIn="false" value=""${QTDIR}/include""/>
|
||||
<listOptionValue builtIn="false" value=""${QTDIR}/include/QtCore""/>
|
||||
<listOptionValue builtIn="false" value=""${QTDIR}/include/QtWidgets""/>
|
||||
</option>
|
||||
<option id="gnu.cpp.compiler.option.preprocessor.def.56223209" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" useByScannerDiscovery="false"/>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1318830536" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
||||
@ -45,6 +47,7 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/QtAdvancedDockingSystem/src}""/>
|
||||
<listOptionValue builtIn="false" value=""${QTDIR}/include""/>
|
||||
<listOptionValue builtIn="false" value=""${QTDIR}/include/QtCore""/>
|
||||
<listOptionValue builtIn="false" value=""${QTDIR}/include/QtWidgets""/>
|
||||
</option>
|
||||
<option id="gnu.c.compiler.option.preprocessor.def.symbols.806805509" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" useByScannerDiscovery="false"/>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1568363924" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
|
||||
|
@ -2,10 +2,7 @@
|
||||
<project>
|
||||
<configuration id="cdt.managedbuild.toolchain.gnu.mingw.base.1119687795" name="Default">
|
||||
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||
<provider class="org.eclipse.cdt.managedbuilder.internal.language.settings.providers.GCCBuiltinSpecsDetectorMinGW" console="false" env-hash="-1519829723851667984" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetectorMinGW" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings MinGW" parameter="${COMMAND} ${FLAGS} -E -P -v -dD -std=c++14 "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetectorMinGW" ref="shared-provider"/>
|
||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(g?cc)|([gc]\+\+)|(clang)" prefer-non-shared="true"/>
|
||||
|
327
demo/MainWindow.cpp
Normal file
327
demo/MainWindow.cpp
Normal file
@ -0,0 +1,327 @@
|
||||
|
||||
/*******************************************************************************
|
||||
** Qt Advanced Docking System
|
||||
** Copyright (C) 2017 Uwe Kindler
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or
|
||||
** modify it under the terms of the GNU Lesser General Public
|
||||
** License as published by the Free Software Foundation; either
|
||||
** version 2.1 of the License, or (at your option) any later version.
|
||||
**
|
||||
** This library is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
** Lesser General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU Lesser General Public
|
||||
** License along with this library; If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
//============================================================================
|
||||
/// \file MainWindow.cpp
|
||||
/// \author Uwe Kindler
|
||||
/// \date 13.02.2018
|
||||
/// \brief Implementation of CMainWindow demo class
|
||||
//============================================================================
|
||||
|
||||
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <MainWindow.h>
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <QTime>
|
||||
#include <QLabel>
|
||||
#include <QTextEdit>
|
||||
#include <QCalendarWidget>
|
||||
#include <QFrame>
|
||||
#include <QTreeView>
|
||||
#include <QFileSystemModel>
|
||||
#include <QBoxLayout>
|
||||
#include <QSettings>
|
||||
#include <QDockWidget>
|
||||
#include <QDebug>
|
||||
#include <QResizeEvent>
|
||||
#include <QAction>
|
||||
#include <QWidgetAction>
|
||||
#include <QComboBox>
|
||||
#include <QInputDialog>
|
||||
|
||||
#include <QMap>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#include "DockManager.h"
|
||||
#include "DockWidget.h"
|
||||
#include "DockAreaWidget.h"
|
||||
|
||||
|
||||
//============================================================================
|
||||
static ads::CDockWidget* createLongTextLabelDockWidget(QMenu* ViewMenu)
|
||||
{
|
||||
static int LabelCount = 0;
|
||||
QLabel* l = new QLabel();
|
||||
l->setWordWrap(true);
|
||||
l->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
l->setText(QString("Label %1 %2 - Lorem ipsum dolor sit amet, consectetuer adipiscing elit. "
|
||||
"Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque "
|
||||
"penatibus et magnis dis parturient montes, nascetur ridiculus mus. "
|
||||
"Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. "
|
||||
"Nulla consequat massa quis enim. Donec pede justo, fringilla vel, "
|
||||
"aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, "
|
||||
"imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede "
|
||||
"mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum "
|
||||
"semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, "
|
||||
"porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, "
|
||||
"dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla "
|
||||
"ut metus varius laoreet.")
|
||||
.arg(LabelCount)
|
||||
.arg(QTime::currentTime().toString("hh:mm:ss:zzz")));
|
||||
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Label %1").arg(LabelCount++));
|
||||
DockWidget->setWidget(l);
|
||||
DockWidget->setObjectName(DockWidget->windowTitle());
|
||||
ViewMenu->addAction(DockWidget->toggleViewAction());
|
||||
return DockWidget;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
static ads::CDockWidget* createCalendarDockWidget(QMenu* ViewMenu)
|
||||
{
|
||||
static int CalendarCount = 0;
|
||||
QCalendarWidget* w = new QCalendarWidget();
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Calendar %1").arg(CalendarCount++));
|
||||
DockWidget->setWidget(w);
|
||||
DockWidget->setObjectName(DockWidget->windowTitle());
|
||||
DockWidget->setToggleViewActionMode(ads::CDockWidget::ActionModeShow);
|
||||
ViewMenu->addAction(DockWidget->toggleViewAction());
|
||||
return DockWidget;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
static ads::CDockWidget* createFileSystemTreeDockWidget(QMenu* ViewMenu)
|
||||
{
|
||||
static int FileSystemCount = 0;
|
||||
QTreeView* w = new QTreeView();
|
||||
w->setFrameShape(QFrame::NoFrame);
|
||||
QFileSystemModel* m = new QFileSystemModel(w);
|
||||
m->setRootPath(QDir::currentPath());
|
||||
w->setModel(m);
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Filesystem %1").arg(FileSystemCount++));
|
||||
DockWidget->setWidget(w);
|
||||
DockWidget->setObjectName(DockWidget->windowTitle());
|
||||
ViewMenu->addAction(DockWidget->toggleViewAction());
|
||||
return DockWidget;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
/**
|
||||
* Private data class pimpl
|
||||
*/
|
||||
struct MainWindowPrivate
|
||||
{
|
||||
CMainWindow* _this;
|
||||
Ui::MainWindow ui;
|
||||
QAction* SavePerspectiveAction = nullptr;
|
||||
QWidgetAction* PerspectiveListAction = nullptr;
|
||||
QComboBox* PerspectiveComboBox = nullptr;;
|
||||
ads::CDockManager* DockManager = nullptr;
|
||||
|
||||
MainWindowPrivate(CMainWindow* _public) : _this(_public) {}
|
||||
|
||||
/**
|
||||
* Creates the toolbar actions
|
||||
*/
|
||||
void createActions();
|
||||
|
||||
/**
|
||||
* Fill the dock manager with dock widgets
|
||||
*/
|
||||
void createContent();
|
||||
|
||||
/**
|
||||
* Saves the dock manager state and the main window geometry
|
||||
*/
|
||||
void saveState();
|
||||
|
||||
/**
|
||||
* Save the list of perspectives
|
||||
*/
|
||||
void savePerspectives();
|
||||
|
||||
/**
|
||||
* Restores the dock manager state
|
||||
*/
|
||||
void restoreState();
|
||||
|
||||
/**
|
||||
* Restore the perspective listo of the dock manager
|
||||
*/
|
||||
void restorePerspectives();
|
||||
};
|
||||
|
||||
|
||||
//============================================================================
|
||||
void MainWindowPrivate::createContent()
|
||||
{
|
||||
// Test container docking
|
||||
QMenu* ViewMenu = ui.menuView;
|
||||
auto DockWidget = createCalendarDockWidget(ViewMenu);
|
||||
DockWidget->setIcon(_this->style()->standardIcon(QStyle::SP_DialogOpenButton));
|
||||
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
|
||||
DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
|
||||
DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu));
|
||||
DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
|
||||
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
|
||||
DockWidget = createCalendarDockWidget(ViewMenu);
|
||||
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
|
||||
DockManager->addDockWidget(ads::CenterDockWidgetArea, DockWidget, TopDockArea);
|
||||
|
||||
// Test dock area docking
|
||||
auto RighDockArea = DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), TopDockArea);
|
||||
DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
|
||||
auto BottomDockArea = DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
|
||||
DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
|
||||
DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void MainWindowPrivate::createActions()
|
||||
{
|
||||
ui.toolBar->addAction(ui.actionSaveState);
|
||||
ui.actionSaveState->setIcon(_this->style()->standardIcon(QStyle::SP_DialogSaveButton));
|
||||
ui.toolBar->addAction(ui.actionRestoreState);
|
||||
ui.actionRestoreState->setIcon(_this->style()->standardIcon(QStyle::SP_DialogOpenButton));
|
||||
|
||||
SavePerspectiveAction = new QAction("Save Perspective", _this);
|
||||
_this->connect(SavePerspectiveAction, SIGNAL(triggered()), SLOT(savePerspective()));
|
||||
PerspectiveListAction = new QWidgetAction(_this);
|
||||
PerspectiveComboBox = new QComboBox(_this);
|
||||
PerspectiveComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||
PerspectiveComboBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
PerspectiveListAction->setDefaultWidget(PerspectiveComboBox);
|
||||
ui.toolBar->addSeparator();
|
||||
ui.toolBar->addAction(PerspectiveListAction);
|
||||
ui.toolBar->addAction(SavePerspectiveAction);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void MainWindowPrivate::saveState()
|
||||
{
|
||||
QSettings Settings("Settings.ini", QSettings::IniFormat);
|
||||
Settings.setValue("mainWindow/Geometry", _this->saveGeometry());
|
||||
Settings.setValue("mainWindow/State", _this->saveState());
|
||||
Settings.setValue("mainWindow/DockingState", DockManager->saveState());
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void MainWindowPrivate::restoreState()
|
||||
{
|
||||
QSettings Settings("Settings.ini", QSettings::IniFormat);
|
||||
_this->restoreGeometry(Settings.value("mainWindow/Geometry").toByteArray());
|
||||
_this->restoreState(Settings.value("mainWindow/State").toByteArray());
|
||||
DockManager->restoreState(Settings.value("mainWindow/DockingState").toByteArray());
|
||||
}
|
||||
|
||||
|
||||
|
||||
//============================================================================
|
||||
void MainWindowPrivate::savePerspectives()
|
||||
{
|
||||
QSettings Settings("Settings.ini", QSettings::IniFormat);
|
||||
DockManager->savePerspectives(Settings);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//============================================================================
|
||||
void MainWindowPrivate::restorePerspectives()
|
||||
{
|
||||
QSettings Settings("Settings.ini", QSettings::IniFormat);
|
||||
DockManager->loadPerspectives(Settings);
|
||||
PerspectiveComboBox->clear();
|
||||
PerspectiveComboBox->addItems(DockManager->perspectiveNames());
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CMainWindow::CMainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
d(new MainWindowPrivate(this))
|
||||
{
|
||||
d->ui.setupUi(this);
|
||||
d->createActions();
|
||||
|
||||
// Now create the dock manager and its content
|
||||
d->DockManager = new ads::CDockManager(this);
|
||||
connect(d->PerspectiveComboBox, SIGNAL(activated(const QString&)),
|
||||
d->DockManager, SLOT(openPerspective(const QString&)));
|
||||
|
||||
d->createContent();
|
||||
// Default window geometry
|
||||
resize(800, 600);
|
||||
|
||||
d->restoreState();
|
||||
d->restorePerspectives();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CMainWindow::~CMainWindow()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CMainWindow::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
d->saveState();
|
||||
QMainWindow::closeEvent(event);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CMainWindow::on_actionSaveState_triggered(bool)
|
||||
{
|
||||
qDebug() << "MainWindow::on_actionSaveState_triggered";
|
||||
d->saveState();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CMainWindow::on_actionRestoreState_triggered(bool)
|
||||
{
|
||||
qDebug() << "MainWindow::on_actionRestoreState_triggered";
|
||||
d->restoreState();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CMainWindow::savePerspective()
|
||||
{
|
||||
std::cout << "savePerspective" << std::endl;
|
||||
QString PerspectiveName = QInputDialog::getText(this, "Save Perspective", "Enter unique name:");
|
||||
if (PerspectiveName.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
d->DockManager->addPerspective(PerspectiveName);
|
||||
QSignalBlocker Blocker(d->PerspectiveComboBox);
|
||||
d->PerspectiveComboBox->clear();
|
||||
d->PerspectiveComboBox->addItems(d->DockManager->perspectiveNames());
|
||||
d->PerspectiveComboBox->setCurrentText(PerspectiveName);
|
||||
|
||||
d->savePerspectives();
|
||||
}
|
||||
|
63
demo/MainWindow.h
Normal file
63
demo/MainWindow.h
Normal file
@ -0,0 +1,63 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
/*******************************************************************************
|
||||
** Qt Advanced Docking System
|
||||
** Copyright (C) 2017 Uwe Kindler
|
||||
**
|
||||
** This library is free software; you can redistribute it and/or
|
||||
** modify it under the terms of the GNU Lesser General Public
|
||||
** License as published by the Free Software Foundation; either
|
||||
** version 2.1 of the License, or (at your option) any later version.
|
||||
**
|
||||
** This library is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
** Lesser General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU Lesser General Public
|
||||
** License along with this library; If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
//============================================================================
|
||||
/// \file MainWindow.h
|
||||
/// \author Uwe Kindler
|
||||
/// \date 13.02.2018
|
||||
/// \brief Declaration of CMainWindow class
|
||||
//============================================================================
|
||||
|
||||
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <QMainWindow>
|
||||
|
||||
|
||||
|
||||
struct MainWindowPrivate;
|
||||
|
||||
|
||||
/**
|
||||
* Simple main window for demo
|
||||
*/
|
||||
class CMainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
MainWindowPrivate* d;///< private data - pimpl
|
||||
friend class MainWindowPrivate;
|
||||
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent* event) override;
|
||||
|
||||
public:
|
||||
explicit CMainWindow(QWidget *parent = 0);
|
||||
virtual ~CMainWindow();
|
||||
|
||||
private slots:
|
||||
void on_actionSaveState_triggered(bool);
|
||||
void on_actionRestoreState_triggered(bool);
|
||||
void savePerspective();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
@ -4,24 +4,16 @@ ADS_OUT_ROOT = $${OUT_PWD}/..
|
||||
TARGET = AdvancedDockingSystemDemo
|
||||
DESTDIR = $${ADS_OUT_ROOT}/lib
|
||||
QT += core gui widgets
|
||||
CONFIG *= c++14
|
||||
|
||||
windows {
|
||||
# MinGW
|
||||
*-g++* {
|
||||
QMAKE_CXXFLAGS += -std=c++11
|
||||
}
|
||||
# MSVC
|
||||
*-msvc* {
|
||||
}
|
||||
}
|
||||
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
mainwindow.cpp
|
||||
MainWindow.cpp
|
||||
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h
|
||||
MainWindow.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <MainWindow.h>
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
#include <QApplication>
|
||||
@ -5,7 +6,6 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
|
||||
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||
@ -41,7 +41,7 @@ int main(int argc, char *argv[])
|
||||
qInstallMessageHandler(myMessageOutput);
|
||||
qDebug() << "Message handler test";
|
||||
|
||||
MainWindow mw;
|
||||
CMainWindow mw;
|
||||
mw.show();
|
||||
return a.exec();
|
||||
}
|
||||
|
@ -1,164 +0,0 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <QTime>
|
||||
#include <QLabel>
|
||||
#include <QTextEdit>
|
||||
#include <QCalendarWidget>
|
||||
#include <QFrame>
|
||||
#include <QTreeView>
|
||||
#include <QFileSystemModel>
|
||||
#include <QBoxLayout>
|
||||
#include <QSettings>
|
||||
#include <QDockWidget>
|
||||
#include <QDebug>
|
||||
#include <QResizeEvent>
|
||||
|
||||
#include "DockManager.h"
|
||||
#include "DockWidget.h"
|
||||
#include "DockAreaWidget.h"
|
||||
|
||||
|
||||
|
||||
|
||||
static ads::CDockWidget* createLongTextLabelDockWidget(QMenu* ViewMenu)
|
||||
{
|
||||
static int LabelCount = 0;
|
||||
QLabel* l = new QLabel();
|
||||
l->setWordWrap(true);
|
||||
l->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
l->setText(QString("Label %1 %2 - Lorem ipsum dolor sit amet, consectetuer adipiscing elit. "
|
||||
"Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque "
|
||||
"penatibus et magnis dis parturient montes, nascetur ridiculus mus. "
|
||||
"Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. "
|
||||
"Nulla consequat massa quis enim. Donec pede justo, fringilla vel, "
|
||||
"aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, "
|
||||
"imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede "
|
||||
"mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum "
|
||||
"semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, "
|
||||
"porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, "
|
||||
"dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla "
|
||||
"ut metus varius laoreet.")
|
||||
.arg(LabelCount)
|
||||
.arg(QTime::currentTime().toString("hh:mm:ss:zzz")));
|
||||
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Label %1").arg(LabelCount++));
|
||||
DockWidget->setWidget(l);
|
||||
DockWidget->setObjectName(DockWidget->windowTitle());
|
||||
ViewMenu->addAction(DockWidget->toggleViewAction());
|
||||
return DockWidget;
|
||||
}
|
||||
|
||||
|
||||
static ads::CDockWidget* createCalendarDockWidget(QMenu* ViewMenu)
|
||||
{
|
||||
static int CalendarCount = 0;
|
||||
QCalendarWidget* w = new QCalendarWidget();
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Calendar %1").arg(CalendarCount++));
|
||||
DockWidget->setWidget(w);
|
||||
DockWidget->setObjectName(DockWidget->windowTitle());
|
||||
DockWidget->setToggleViewActionMode(ads::CDockWidget::ActionModeShow);
|
||||
ViewMenu->addAction(DockWidget->toggleViewAction());
|
||||
return DockWidget;
|
||||
}
|
||||
|
||||
static ads::CDockWidget* createFileSystemTreeDockWidget(QMenu* ViewMenu)
|
||||
{
|
||||
static int FileSystemCount = 0;
|
||||
QTreeView* w = new QTreeView();
|
||||
w->setFrameShape(QFrame::NoFrame);
|
||||
QFileSystemModel* m = new QFileSystemModel(w);
|
||||
m->setRootPath(QDir::currentPath());
|
||||
w->setModel(m);
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Filesystem %1").arg(FileSystemCount++));
|
||||
DockWidget->setWidget(w);
|
||||
DockWidget->setObjectName(DockWidget->windowTitle());
|
||||
ViewMenu->addAction(DockWidget->toggleViewAction());
|
||||
return DockWidget;
|
||||
}
|
||||
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->toolBar->addAction(ui->actionSaveState);
|
||||
ui->actionSaveState->setIcon(style()->standardIcon(QStyle::SP_DialogSaveButton));
|
||||
ui->toolBar->addAction(ui->actionRestoreState);
|
||||
ui->actionRestoreState->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton));
|
||||
|
||||
m_SavePerspectiveAction = new QAction("Save Perspective", this);
|
||||
m_PerspectiveListAction = new QWidgetAction(this);
|
||||
m_PerspectiveComboBox = new QComboBox(this);
|
||||
m_PerspectiveListAction->setDefaultWidget(m_PerspectiveComboBox);
|
||||
ui->toolBar->addSeparator();
|
||||
ui->toolBar->addAction(m_PerspectiveListAction);
|
||||
ui->toolBar->addAction(m_SavePerspectiveAction);
|
||||
|
||||
m_DockManager = new ads::CDockManager(this);
|
||||
createContent();
|
||||
// Default window geometry
|
||||
resize(800, 600);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::createContent()
|
||||
{
|
||||
// Test container docking
|
||||
QMenu* ViewMenu = this->ui->menuView;
|
||||
auto DockWidget = createCalendarDockWidget(ViewMenu);
|
||||
DockWidget->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton));
|
||||
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
|
||||
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
|
||||
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu));
|
||||
m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
|
||||
auto TopDockArea = m_DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
|
||||
DockWidget = createCalendarDockWidget(ViewMenu);
|
||||
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
|
||||
m_DockManager->addDockWidget(ads::CenterDockWidgetArea, DockWidget, TopDockArea);
|
||||
|
||||
// Test dock area docking
|
||||
auto RighDockArea = m_DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), TopDockArea);
|
||||
m_DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
|
||||
auto BottomDockArea = m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
|
||||
m_DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
|
||||
m_DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
/*QSettings Settings("Settings.ini", QSettings::IniFormat);
|
||||
Settings.setValue("mainWindow/Geometry", saveGeometry());
|
||||
Settings.setValue("mainWindow/DockingState", m_DockManager->saveState());*/
|
||||
QMainWindow::closeEvent(event);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionSaveState_triggered(bool)
|
||||
{
|
||||
qDebug() << "MainWindow::on_actionSaveState_triggered";
|
||||
QSettings Settings("Settings.ini", QSettings::IniFormat);
|
||||
Settings.setValue("mainWindow/Geometry", saveGeometry());
|
||||
Settings.setValue("mainWindow/DockingState", m_DockManager->saveState());
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionRestoreState_triggered(bool)
|
||||
{
|
||||
qDebug() << "MainWindow::on_actionRestoreState_triggered";
|
||||
QSettings Settings("Settings.ini", QSettings::IniFormat);
|
||||
restoreGeometry(Settings.value("mainWindow/Geometry").toByteArray());
|
||||
m_DockManager->restoreState(Settings.value("mainWindow/DockingState").toByteArray());
|
||||
}
|
||||
|
@ -1,43 +0,0 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QAction>
|
||||
#include <QWidgetAction>
|
||||
#include <QComboBox>
|
||||
|
||||
#include <QMainWindow>
|
||||
#include "DockManager.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple main window for demo
|
||||
*/
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
QAction* m_SavePerspectiveAction;
|
||||
QWidgetAction* m_PerspectiveListAction;
|
||||
QComboBox* m_PerspectiveComboBox;
|
||||
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent* event) override;
|
||||
;
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
virtual ~MainWindow();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
ads::CDockManager* m_DockManager;
|
||||
void createContent();
|
||||
|
||||
private slots:
|
||||
void on_actionSaveState_triggered(bool);
|
||||
void on_actionRestoreState_triggered(bool);
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
@ -522,9 +522,10 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
|
||||
else
|
||||
{
|
||||
DockArea->setProperty("currentIndex", CurrentIndex);
|
||||
DockAreas.append(DockArea);
|
||||
}
|
||||
|
||||
CreatedWidget = DockArea;
|
||||
DockAreas.append(DockArea);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include <QAction>
|
||||
#include <QXmlStreamWriter>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QSettings>
|
||||
|
||||
#include "FloatingDockContainer.h"
|
||||
#include "DockOverlay.h"
|
||||
@ -53,7 +54,6 @@
|
||||
|
||||
namespace ads
|
||||
{
|
||||
|
||||
/**
|
||||
* Private data class of CDockManager class (pimpl)
|
||||
*/
|
||||
@ -65,6 +65,7 @@ struct DockManagerPrivate
|
||||
CDockOverlay* ContainerOverlay;
|
||||
CDockOverlay* DockAreaOverlay;
|
||||
QMap<QString, CDockWidget*> DockWidgetsMap;
|
||||
QMap<QString, QByteArray> Perspectives;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@ -386,6 +387,80 @@ CDockWidget* CDockManager::findDockWidget(const QString& ObjectName)
|
||||
{
|
||||
return d->DockWidgetsMap.value(ObjectName, nullptr);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockManager::addPerspective(const QString& UniquePrespectiveName)
|
||||
{
|
||||
d->Perspectives.insert(UniquePrespectiveName, saveState());
|
||||
emit perspectiveListChanged();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QStringList CDockManager::perspectiveNames() const
|
||||
{
|
||||
return d->Perspectives.keys();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockManager::openPerspective(const QString& PerspectiveName)
|
||||
{
|
||||
std::cout << "CDockManager::openPerspective " << PerspectiveName.toStdString() << std::endl;
|
||||
const auto Iterator = d->Perspectives.find(PerspectiveName);
|
||||
if (d->Perspectives.end() == Iterator)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << "CDockManager::openPerspective - restoring state" << std::endl;
|
||||
restoreState(Iterator.value());
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockManager::savePerspectives(QSettings& Settings) const
|
||||
{
|
||||
Settings.beginWriteArray("Perspectives", d->Perspectives.size());
|
||||
int i = 0;
|
||||
for (auto it = d->Perspectives.constBegin(); it != d->Perspectives.constEnd(); ++it)
|
||||
{
|
||||
Settings.setArrayIndex(i);
|
||||
Settings.setValue("Name", it.key());
|
||||
Settings.setValue("State", it.value());
|
||||
++i;
|
||||
}
|
||||
Settings.endArray();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockManager::loadPerspectives(QSettings& Settings)
|
||||
{
|
||||
d->Perspectives.clear();
|
||||
int Size = Settings.beginReadArray("Perspectives");
|
||||
if (!Size)
|
||||
{
|
||||
Settings.endArray();
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < Size; ++i)
|
||||
{
|
||||
Settings.setArrayIndex(i);
|
||||
QString Name = Settings.value("Name").toString();
|
||||
QByteArray Data = Settings.value("State").toByteArray();
|
||||
if (Name.isEmpty() || Data.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
d->Perspectives.insert(Name, Data);
|
||||
}
|
||||
|
||||
Settings.endArray();
|
||||
}
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -32,6 +32,8 @@
|
||||
//============================================================================
|
||||
#include "DockContainerWidget.h"
|
||||
|
||||
class QSettings;
|
||||
|
||||
namespace ads
|
||||
{
|
||||
struct DockManagerPrivate;
|
||||
@ -134,6 +136,7 @@ public:
|
||||
|
||||
/**
|
||||
* Saves the current state of the dockmanger and all its dock widgets
|
||||
* into the returned QByteArray
|
||||
*/
|
||||
QByteArray saveState(int version = 0) const;
|
||||
|
||||
@ -145,6 +148,43 @@ public:
|
||||
* returns true.
|
||||
*/
|
||||
bool restoreState(const QByteArray &state, int version = 0);
|
||||
|
||||
/**
|
||||
* Saves the current perspective to the internal list of perspectives.
|
||||
* A perspective is the current state of the dock manager assigned
|
||||
* with a certain name. This makes it possible for the user,
|
||||
* to switch between different perspectives quickly.
|
||||
* If a perspective with the given name already exists, then
|
||||
* it will be overwritten with the new state.
|
||||
*/
|
||||
void addPerspective(const QString& UniquePrespectiveName);
|
||||
|
||||
/**
|
||||
* Returns the names of all available perspectives
|
||||
*/
|
||||
QStringList perspectiveNames() const;
|
||||
|
||||
/**
|
||||
* Saves the perspectives to the given settings file.
|
||||
*/
|
||||
void savePerspectives(QSettings& Settings) const;
|
||||
|
||||
/**
|
||||
* Loads the perspectives from the given settings file
|
||||
*/
|
||||
void loadPerspectives(QSettings& Settings);
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* Opens the perspective with the given name.
|
||||
*/
|
||||
void openPerspective(const QString& PerspectiveName);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* This signal is emitted if the list of perspectives changed
|
||||
*/
|
||||
void perspectiveListChanged();
|
||||
}; // class DockManager
|
||||
} // namespace ads
|
||||
//-----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user