Compare commits
85 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9af6622466 | ||
|
|
4fa89374c4 | ||
|
|
1aaa56ef29 | ||
|
|
d298a47bda | ||
|
|
146b65206a | ||
|
|
616ad9f86e | ||
|
|
aa9762718c | ||
|
|
f26bee6677 | ||
|
|
fb18de4868 | ||
|
|
e204e10113 | ||
|
|
a06a14d6cd | ||
|
|
88d4bea2c1 | ||
|
|
b8ad2f7577 | ||
|
|
32e5d599f7 | ||
|
|
48382ccd82 | ||
|
|
e37e4fdf57 | ||
|
|
c9a97534a8 | ||
|
|
8f54dd2a82 | ||
|
|
c0d6f959ec | ||
|
|
8570139cd1 | ||
|
|
b38919e909 | ||
|
|
b19cc98c84 | ||
|
|
f3f5b668e5 | ||
|
|
82d15fbe29 | ||
|
|
01533a9f85 | ||
|
|
fb9f1d851b | ||
|
|
6fb80fdeb7 | ||
|
|
e94cf9bcb7 | ||
|
|
da0ec6dd4b | ||
|
|
80efed693e | ||
|
|
653f475e72 | ||
|
|
87e3777e37 | ||
|
|
71f66ea6dc | ||
|
|
0b3f419c80 | ||
|
|
f69af82a49 | ||
|
|
854f542164 | ||
|
|
b9265fccec | ||
|
|
b3a272110a | ||
|
|
316e5324ad | ||
|
|
6843703484 | ||
|
|
115a9a5b3d | ||
|
|
a4838a41ac | ||
|
|
74b9d35c7b | ||
|
|
c973482b2b | ||
|
|
188624440b | ||
|
|
72ec61a043 | ||
|
|
0ac19ebdfb | ||
|
|
bc6ffcc02c | ||
|
|
a9246f7ce4 | ||
|
|
3f5697554a | ||
|
|
5e6c82b68d | ||
|
|
268f8655a1 | ||
|
|
1dfabb3bef | ||
|
|
6617cf6f19 | ||
|
|
81523b0346 | ||
|
|
927be9a7d9 | ||
|
|
ada3d6b3b5 | ||
|
|
30bbd26d0a | ||
|
|
8637c89a6b | ||
|
|
11e5f9c95a | ||
|
|
9bfb3fbea1 | ||
|
|
9c95e34df5 | ||
|
|
ceebda7431 | ||
|
|
75288af88c | ||
|
|
7c67d71f68 | ||
|
|
548dfb363a | ||
|
|
9fec2bd515 | ||
|
|
fc04aa2411 | ||
|
|
c3a5e3ef21 | ||
|
|
0e85431405 | ||
|
|
b3b6d20d96 | ||
|
|
272bbe275e | ||
|
|
496aec211e | ||
|
|
b9b72df9d4 | ||
|
|
fcb1846bf5 | ||
|
|
9f1b2c122a | ||
|
|
6ec38b48ef | ||
|
|
b93e723a83 | ||
|
|
1a47918bdb | ||
|
|
ff9d965726 | ||
|
|
77d2cebe39 | ||
|
|
5d380708e1 | ||
|
|
aa7b36dbd1 | ||
|
|
c9123c3640 | ||
|
|
67199a81f4 |
68
.cproject
@@ -71,6 +71,15 @@
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
<storageModule moduleId="refreshScope"/>
|
||||
<storageModule moduleId="scannerConfiguration">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1119687795;cdt.managedbuild.toolchain.gnu.mingw.base.1119687795.1949777584;cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base.1947822681;cdt.managedbuild.tool.gnu.cpp.compiler.input.1318830536">
|
||||
<autodiscovery enabled="false" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"/>
|
||||
</scannerConfigBuildInfo>
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1119687795;cdt.managedbuild.toolchain.gnu.mingw.base.1119687795.1949777584;cdt.managedbuild.tool.gnu.c.compiler.mingw.base.389117097;cdt.managedbuild.tool.gnu.c.compiler.input.1568363924">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
</scannerConfigBuildInfo>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
|
||||
<buildTargets>
|
||||
<target name="Build all" path=" build" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
@@ -83,6 +92,7 @@
|
||||
</target>
|
||||
<target name="Clean" path=" build" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>clean</buildTarget>
|
||||
<stopOnError>false</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
@@ -99,7 +109,6 @@
|
||||
<target name="qmake" path=" build" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>qmake</buildCommand>
|
||||
<buildArguments>-recursive ../ads.pro</buildArguments>
|
||||
<buildTarget/>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
<runAllBuilders>false</runAllBuilders>
|
||||
@@ -122,7 +131,6 @@
|
||||
</target>
|
||||
<target name="Clean" path=" build/src" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>clean</buildTarget>
|
||||
<stopOnError>false</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
@@ -139,7 +147,6 @@
|
||||
<target name="qmake" path=" build/src" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>qmake</buildCommand>
|
||||
<buildArguments>-recursive ../../src/src.pro</buildArguments>
|
||||
<buildTarget/>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
<runAllBuilders>false</runAllBuilders>
|
||||
@@ -152,6 +159,46 @@
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
<runAllBuilders>false</runAllBuilders>
|
||||
</target>
|
||||
<target name="Build all" path=" build/example" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>mingw32-make</buildCommand>
|
||||
<buildArguments>-j</buildArguments>
|
||||
<buildTarget>all</buildTarget>
|
||||
<stopOnError>false</stopOnError>
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
<runAllBuilders>false</runAllBuilders>
|
||||
</target>
|
||||
<target name="Clean" path=" build/example" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>clean</buildTarget>
|
||||
<stopOnError>false</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>false</runAllBuilders>
|
||||
</target>
|
||||
<target name="Debug Build" path=" build/example" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>mingw32-make</buildCommand>
|
||||
<buildArguments>-j6</buildArguments>
|
||||
<buildTarget>debug</buildTarget>
|
||||
<stopOnError>false</stopOnError>
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
<runAllBuilders>false</runAllBuilders>
|
||||
</target>
|
||||
<target name="qmake" path=" build/example" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>qmake</buildCommand>
|
||||
<buildArguments>-recursive ../../example/example.pro</buildArguments>
|
||||
<buildTarget/>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
<runAllBuilders>false</runAllBuilders>
|
||||
</target>
|
||||
<target name="Release Build" path=" build/example" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>mingw32-make</buildCommand>
|
||||
<buildArguments>-j4</buildArguments>
|
||||
<buildTarget>release</buildTarget>
|
||||
<stopOnError>false</stopOnError>
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
<runAllBuilders>false</runAllBuilders>
|
||||
</target>
|
||||
<target name="Build all" path=" build/demo" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>mingw32-make</buildCommand>
|
||||
<buildArguments>-j</buildArguments>
|
||||
@@ -162,7 +209,6 @@
|
||||
</target>
|
||||
<target name="Clean" path=" build/demo" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>clean</buildTarget>
|
||||
<stopOnError>false</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
@@ -179,7 +225,6 @@
|
||||
<target name="qmake" path=" build/demo" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>qmake</buildCommand>
|
||||
<buildArguments>-recursive ../../demo/demo.pro</buildArguments>
|
||||
<buildTarget/>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
<runAllBuilders>false</runAllBuilders>
|
||||
@@ -202,6 +247,7 @@
|
||||
</target>
|
||||
<target name="Clean" path=" build/AdvancedDockingSystemDemo" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>clean</buildTarget>
|
||||
<stopOnError>false</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
@@ -240,6 +286,7 @@
|
||||
</target>
|
||||
<target name="Clean" path=" build/AdvancedDockingSystemDemo_v2" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>clean</buildTarget>
|
||||
<stopOnError>false</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
@@ -278,6 +325,7 @@
|
||||
</target>
|
||||
<target name="Clean" path=" build/AdvancedDockingSystem" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>clean</buildTarget>
|
||||
<stopOnError>false</stopOnError>
|
||||
<useDefaultCommand>true</useDefaultCommand>
|
||||
@@ -294,7 +342,6 @@
|
||||
<target name="qmake" path=" build/AdvancedDockingSystem" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>qmake</buildCommand>
|
||||
<buildArguments>-recursive ../../AdvancedDockingSystem/src.pro</buildArguments>
|
||||
<buildTarget/>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
<runAllBuilders>false</runAllBuilders>
|
||||
@@ -309,13 +356,4 @@
|
||||
</target>
|
||||
</buildTargets>
|
||||
</storageModule>
|
||||
<storageModule moduleId="scannerConfiguration">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1119687795;cdt.managedbuild.toolchain.gnu.mingw.base.1119687795.1949777584;cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base.1947822681;cdt.managedbuild.tool.gnu.cpp.compiler.input.1318830536">
|
||||
<autodiscovery enabled="false" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"/>
|
||||
</scannerConfigBuildInfo>
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1119687795;cdt.managedbuild.toolchain.gnu.mingw.base.1119687795.1949777584;cdt.managedbuild.tool.gnu.c.compiler.mingw.base.389117097;cdt.managedbuild.tool.gnu.c.compiler.input.1568363924">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
</scannerConfigBuildInfo>
|
||||
</storageModule>
|
||||
</cproject>
|
||||
|
||||
8
.gitignore
vendored
@@ -1,2 +1,10 @@
|
||||
*.pro.user
|
||||
/ build
|
||||
*.o
|
||||
*.dylib
|
||||
*.app
|
||||
qrc_*
|
||||
moc_*
|
||||
ui_*
|
||||
Makefile
|
||||
|
||||
|
||||
93
README.md
@@ -13,28 +13,36 @@ from Manuel Freiholz. I did an almost complete rewrite of his code to improve
|
||||
code quality, readibility and to fix all issues from the issue tracker
|
||||
of his docking system project.
|
||||
|
||||
The following video gives a first impression what is possible with the Advanced Docking System for Qt.
|
||||
|
||||
[](https://www.youtube.com/watch?v=7pdNfafg3Qc)
|
||||
|
||||
## Features
|
||||
### Docking everywhere - no central widget
|
||||
There is no central widget like in the Qt docking system. You can dock on every
|
||||
border of the main window or you can dock into each dock area - so you are
|
||||
free to dock almost everywhere.
|
||||
|
||||

|
||||
|
||||

|
||||
\
|
||||
\
|
||||

|
||||
|
||||
### Docking inside floating windows
|
||||
There is no difference between the main window and a floating window. Docking
|
||||
into floating windows is supported.
|
||||
|
||||

|
||||
\
|
||||
\
|
||||

|
||||
|
||||
### Grouped dragging
|
||||
When dragging the titlebar of a dock, all the tabs that are tabbed with it are
|
||||
going to be dragged. So you can move complete groups of tabbed widgets into
|
||||
a floating widget or from one dock area to another one.
|
||||
|
||||

|
||||
\
|
||||
\
|
||||

|
||||
|
||||
### Perspectives for fast switching of the complete main window layout
|
||||
A perspective defines the set and layout of dock windows in the main
|
||||
@@ -43,7 +51,9 @@ perspective to make your own custom perspective. Later you can simply
|
||||
select a perspective from the perspective list to quickly switch the complete
|
||||
main window layout.
|
||||
|
||||

|
||||
\
|
||||
\
|
||||

|
||||
|
||||
## Tested Compatible Environments
|
||||
- Windows 10
|
||||
@@ -52,6 +62,77 @@ main window layout.
|
||||
Open the `ads.pro` with QtCreator and start the build, that's it.
|
||||
You can run the demo project and test it yourself.
|
||||
|
||||
## Getting started / Example
|
||||
The following example shows the minimum code required to use the advanced Qt docking system.
|
||||
|
||||
*MainWindow.h*
|
||||
|
||||
```cpp
|
||||
#include <QMainWindow>
|
||||
#include "DockManager.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
// The main container for docking
|
||||
ads::CDockManager* m_DockManager;
|
||||
};
|
||||
```
|
||||
*MainWindow.cpp*
|
||||
```cpp
|
||||
#include "MainWindow.h"
|
||||
#include "ui_MainWindow.h"
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
// Create the dock manager. Because the parent parameter is a QMainWindow
|
||||
// the dock manager registers itself as the central widget.
|
||||
m_DockManager = new ads::CDockManager(this);
|
||||
|
||||
// Create example content label - this can be any application specific
|
||||
// widget
|
||||
QLabel* l = new QLabel();
|
||||
l->setWordWrap(true);
|
||||
l->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
l->setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. ");
|
||||
|
||||
// Create a dock widget with the title Label 1 and set the created label
|
||||
// as the dock widget content
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget("Label 1");
|
||||
DockWidget->setWidget(l);
|
||||
|
||||
// Add the toggleViewAction of the dock widget to the menu to give
|
||||
// the user the possibility to show the dock widget if it has been closed
|
||||
ui->menuView->addAction(DockWidget->toggleViewAction());
|
||||
|
||||
// Add the dock widget to the top dock widget area
|
||||
m_DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
```
|
||||
|
||||
## Developers
|
||||
- Uwe Kindler, Project Maintainer
|
||||
- Manuel Freiholz
|
||||
|
||||
6
ads.pro
@@ -2,4 +2,8 @@ TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS = \
|
||||
src \
|
||||
demo
|
||||
demo \
|
||||
example
|
||||
|
||||
demo.depends = src
|
||||
example.depends = src
|
||||
|
||||
@@ -174,9 +174,16 @@ void MainWindowPrivate::createContent()
|
||||
DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false);
|
||||
DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
|
||||
DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu));
|
||||
DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
|
||||
|
||||
auto FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
|
||||
auto ToolBar = FileSystemWidget->createDefaultToolBar();
|
||||
ToolBar->addAction(ui.actionSaveState);
|
||||
ToolBar->addAction(ui.actionRestoreState);
|
||||
DockManager->addDockWidget(ads::BottomDockWidgetArea, FileSystemWidget);
|
||||
|
||||
FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
|
||||
ToolBar = FileSystemWidget->createDefaultToolBar();
|
||||
ToolBar->addAction(ui.actionSaveState);
|
||||
ToolBar->addAction(ui.actionRestoreState);
|
||||
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetMovable, false);
|
||||
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
|
||||
DockWidget = createCalendarDockWidget(ViewMenu);
|
||||
@@ -258,11 +265,17 @@ CMainWindow::CMainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
d(new MainWindowPrivate(this))
|
||||
{
|
||||
using namespace ads;
|
||||
d->ui.setupUi(this);
|
||||
d->createActions();
|
||||
|
||||
// Now create the dock manager and its content
|
||||
d->DockManager = new ads::CDockManager(this);
|
||||
d->DockManager = new CDockManager(this);
|
||||
|
||||
// Uncomment the following line to have the old style where the dock
|
||||
// area close button closes the active tab
|
||||
//d->DockManager->setConfigFlags({
|
||||
// CDockManager::DockAreaHasCloseButton | CDockManager::DockAreaCloseButtonClosesTab});
|
||||
connect(d->PerspectiveComboBox, SIGNAL(activated(const QString&)),
|
||||
d->DockManager, SLOT(openPerspective(const QString&)));
|
||||
|
||||
@@ -309,7 +322,6 @@ void CMainWindow::on_actionRestoreState_triggered(bool)
|
||||
//============================================================================
|
||||
void CMainWindow::savePerspective()
|
||||
{
|
||||
std::cout << "savePerspective" << std::endl;
|
||||
QString PerspectiveName = QInputDialog::getText(this, "Save Perspective", "Enter unique name:");
|
||||
if (PerspectiveName.isEmpty())
|
||||
{
|
||||
|
||||
@@ -17,13 +17,15 @@ HEADERS += \
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
|
||||
RESOURCES += main.qrc
|
||||
|
||||
LIBS += -L$${ADS_OUT_ROOT}/lib
|
||||
|
||||
# Dependency: AdvancedDockingSystem (shared)
|
||||
win32:CONFIG(release, debug|release): LIBS += -lAdvancedDockingSystem
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -lAdvancedDockingSystemd
|
||||
else:unix: LIBS += -lAdvancedDockingSystem
|
||||
win32:CONFIG(release, debug|release): LIBS += -lqtadvanceddocking
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -lqtadvanceddockingd
|
||||
else:unix: LIBS += -lqtadvanceddocking
|
||||
|
||||
INCLUDEPATH += ../src
|
||||
DEPENDPATH += ../src
|
||||
|
||||
@@ -35,6 +35,10 @@ void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QS
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
#if QT_VERSION >= 0x050600
|
||||
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
#endif
|
||||
std::shared_ptr<int> b;
|
||||
QApplication a(argc, argv);
|
||||
a.setQuitOnLastWindowClosed(true);
|
||||
|
||||
3
demo/main.qrc
Normal file
@@ -0,0 +1,3 @@
|
||||
<RCC>
|
||||
<qresource prefix="/main"/>
|
||||
</RCC>
|
||||
BIN
doc/TabMenu.png
Normal file
|
After Width: | Height: | Size: 44 KiB |
BIN
doc/TabMenu_dark.png
Normal file
|
After Width: | Height: | Size: 44 KiB |
BIN
doc/advanced-docking_video.png
Normal file
|
After Width: | Height: | Size: 276 KiB |
BIN
doc/floating-widget-dragndrop.png
Normal file
|
After Width: | Height: | Size: 103 KiB |
BIN
doc/floating-widget-dragndrop_dark.png
Normal file
|
After Width: | Height: | Size: 123 KiB |
BIN
doc/grouped-dragging.png
Normal file
|
After Width: | Height: | Size: 68 KiB |
BIN
doc/grouped-dragging_dark.png
Normal file
|
After Width: | Height: | Size: 53 KiB |
BIN
doc/perspectives.png
Normal file
|
After Width: | Height: | Size: 61 KiB |
BIN
doc/perspectives_dark.png
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
doc/preview-dragndrop.png
Normal file
|
After Width: | Height: | Size: 92 KiB |
BIN
doc/preview-dragndrop_dark.png
Normal file
|
After Width: | Height: | Size: 194 KiB |
BIN
doc/preview_dark.png
Normal file
|
After Width: | Height: | Size: 136 KiB |
39
example/MainWindow.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "MainWindow.h"
|
||||
#include "ui_MainWindow.h"
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
// Create the dock manager. Because the parent parameter is a QMainWindow
|
||||
// the dock manager registers itself as the central widget.
|
||||
m_DockManager = new ads::CDockManager(this);
|
||||
|
||||
// Create example content label - this can be any application specific
|
||||
// widget
|
||||
QLabel* l = new QLabel();
|
||||
l->setWordWrap(true);
|
||||
l->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
l->setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. ");
|
||||
|
||||
// Create a dock widget with the title Label 1 and set the created label
|
||||
// as the dock widget content
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget("Label 1");
|
||||
DockWidget->setWidget(l);
|
||||
|
||||
// Add the toggleViewAction of the dock widget to the menu to give
|
||||
// the user the possibility to show the dock widget if it has been closed
|
||||
ui->menuView->addAction(DockWidget->toggleViewAction());
|
||||
|
||||
// Add the dock widget to the top dock widget area
|
||||
m_DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
24
example/MainWindow.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include "DockManager.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
ads::CDockManager* m_DockManager;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
38
example/MainWindow.ui
Normal file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget"/>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuView">
|
||||
<property name="title">
|
||||
<string>View</string>
|
||||
</property>
|
||||
</widget>
|
||||
<addaction name="menuView"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
51
example/example.pro
Normal file
@@ -0,0 +1,51 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2018-12-14T22:42:14
|
||||
#
|
||||
#-------------------------------------------------
|
||||
ADS_ROOT = $${PWD}/..
|
||||
ADS_OUT_ROOT = $${OUT_PWD}/..
|
||||
|
||||
QT += core gui widgets
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = Example1
|
||||
DESTDIR = $${ADS_OUT_ROOT}/lib
|
||||
TEMPLATE = app
|
||||
CONFIG *= c++14
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which has been marked as deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if you use deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
MainWindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
MainWindow.h
|
||||
|
||||
FORMS += \
|
||||
MainWindow.ui
|
||||
|
||||
#RESOURCES += main.qrc
|
||||
|
||||
LIBS += -L$${ADS_OUT_ROOT}/lib
|
||||
|
||||
# Dependency: AdvancedDockingSystem (shared)
|
||||
win32:CONFIG(release, debug|release): LIBS += -lqtadvanceddocking
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -lqtadvanceddockingd
|
||||
else:unix: LIBS += -lqtadvanceddocking
|
||||
|
||||
INCLUDEPATH += ../src
|
||||
DEPENDPATH += ../src
|
||||
|
||||
11
example/main.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "MainWindow.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
Before Width: | Height: | Size: 222 KiB |
|
Before Width: | Height: | Size: 41 KiB |
BIN
perspectives.png
|
Before Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 82 KiB |
BIN
preview.png
|
Before Width: | Height: | Size: 57 KiB |
@@ -1,3 +1,22 @@
|
||||
/*******************************************************************************
|
||||
** 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 DockAreaTabBar.cpp
|
||||
/// \author Uwe Kindler
|
||||
@@ -13,11 +32,18 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QScrollBar>
|
||||
#include <QDebug>
|
||||
#include <QBoxLayout>
|
||||
#include <QApplication>
|
||||
|
||||
#include "FloatingDockContainer.h"
|
||||
#include "DockAreaWidget.h"
|
||||
#include "DockOverlay.h"
|
||||
#include "DockManager.h"
|
||||
#include "DockWidget.h"
|
||||
#include "DockWidgetTab.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace ads
|
||||
{
|
||||
@@ -30,11 +56,20 @@ struct DockAreaTabBarPrivate
|
||||
QPoint DragStartMousePos;
|
||||
CDockAreaWidget* DockArea;
|
||||
CFloatingDockContainer* FloatingWidget = nullptr;
|
||||
QWidget* TabsContainerWidget;
|
||||
QBoxLayout* TabsLayout;
|
||||
int CurrentIndex = -1;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
*/
|
||||
DockAreaTabBarPrivate(CDockAreaTabBar* _public);
|
||||
|
||||
/**
|
||||
* Update tabs after current index changed or when tabs are removed.
|
||||
* The function reassigns the stylesheet to update the tabs
|
||||
*/
|
||||
void updateTabs();
|
||||
};
|
||||
// struct DockAreaTabBarPrivate
|
||||
|
||||
@@ -45,6 +80,33 @@ DockAreaTabBarPrivate::DockAreaTabBarPrivate(CDockAreaTabBar* _public) :
|
||||
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockAreaTabBarPrivate::updateTabs()
|
||||
{
|
||||
// Set active TAB and update all other tabs to be inactive
|
||||
for (int i = 0; i < _this->count(); ++i)
|
||||
{
|
||||
auto TabWidget = _this->tab(i);
|
||||
if (!TabWidget)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i == CurrentIndex)
|
||||
{
|
||||
TabWidget->show();
|
||||
TabWidget->setActiveTab(true);
|
||||
_this->ensureWidgetVisible(TabWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
TabWidget->setActiveTab(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockAreaTabBar::CDockAreaTabBar(CDockAreaWidget* parent) :
|
||||
QScrollArea(parent),
|
||||
@@ -56,6 +118,16 @@ CDockAreaTabBar::CDockAreaTabBar(CDockAreaWidget* parent) :
|
||||
setWidgetResizable(true);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
d->TabsContainerWidget = new QWidget();
|
||||
d->TabsContainerWidget->setObjectName("tabsContainerWidget");
|
||||
setWidget(d->TabsContainerWidget);
|
||||
|
||||
d->TabsLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
d->TabsLayout->setContentsMargins(0, 0, 0, 0);
|
||||
d->TabsLayout->setSpacing(0);
|
||||
d->TabsLayout->addStretch(1);
|
||||
d->TabsContainerWidget->setLayout(d->TabsLayout);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
@@ -133,7 +205,8 @@ void CDockAreaTabBar::mouseMoveEvent(QMouseEvent* ev)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->geometry().contains(ev->pos()))
|
||||
int DragDistance = (d->DragStartMousePos - ev->pos()).manhattanLength();
|
||||
if (DragDistance >= CDockManager::startDragDistance())
|
||||
{
|
||||
qDebug() << "CTabsScrollArea::startFloating";
|
||||
startFloating(d->DragStartMousePos);
|
||||
@@ -155,18 +228,331 @@ void CDockAreaTabBar::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
return;
|
||||
}
|
||||
startFloating(event->pos());
|
||||
makeAreaFloating(event->pos(), DraggingInactive);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTabBar::startFloating(const QPoint& Pos)
|
||||
CFloatingDockContainer* CDockAreaTabBar::makeAreaFloating(const QPoint& Offset,
|
||||
eDragState DragState)
|
||||
{
|
||||
QSize Size = d->DockArea->size();
|
||||
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(d->DockArea);
|
||||
FloatingWidget->startFloating(Pos, Size);
|
||||
d->FloatingWidget = FloatingWidget;
|
||||
FloatingWidget->startFloating(Offset, Size, DragState);
|
||||
auto TopLevelDockWidget = FloatingWidget->topLevelDockWidget();
|
||||
if (TopLevelDockWidget)
|
||||
{
|
||||
TopLevelDockWidget->emitTopLevelChanged(true);
|
||||
}
|
||||
|
||||
return FloatingWidget;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTabBar::startFloating(const QPoint& Offset)
|
||||
{
|
||||
d->FloatingWidget = makeAreaFloating(Offset, DraggingFloatingWidget);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTabBar::setCurrentIndex(int index)
|
||||
{
|
||||
if (index == d->CurrentIndex)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (index < -1 || index > (count() - 1))
|
||||
{
|
||||
qWarning() << Q_FUNC_INFO << "Invalid index" << index;
|
||||
return;
|
||||
}
|
||||
|
||||
emit currentChanging(index);
|
||||
d->CurrentIndex = index;
|
||||
d->updateTabs();
|
||||
emit currentChanged(index);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
int CDockAreaTabBar::count() const
|
||||
{
|
||||
// The tab bar contains a stretch item as last item
|
||||
return d->TabsLayout->count() - 1;
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
void CDockAreaTabBar::insertTab(int Index, CDockWidgetTab* Tab)
|
||||
{
|
||||
d->TabsLayout->insertWidget(Index, Tab);
|
||||
connect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked()));
|
||||
connect(Tab, SIGNAL(closeRequested()), this, SLOT(onTabCloseRequested()));
|
||||
connect(Tab, SIGNAL(closeOtherTabsRequested()), this, SLOT(onCloseOtherTabsRequested()));
|
||||
connect(Tab, SIGNAL(moved(const QPoint&)), this, SLOT(onTabWidgetMoved(const QPoint&)));
|
||||
Tab->installEventFilter(this);
|
||||
emit tabInserted(Index);
|
||||
if (Index <= d->CurrentIndex)
|
||||
{
|
||||
setCurrentIndex(d->CurrentIndex + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
void CDockAreaTabBar::removeTab(CDockWidgetTab* Tab)
|
||||
{
|
||||
if (!count())
|
||||
{
|
||||
return;
|
||||
}
|
||||
qDebug() << "CDockAreaTabBar::removeTab ";
|
||||
int NewCurrentIndex = currentIndex();
|
||||
int RemoveIndex = d->TabsLayout->indexOf(Tab);
|
||||
if (count() == 1)
|
||||
{
|
||||
NewCurrentIndex = -1;
|
||||
}
|
||||
if (NewCurrentIndex > RemoveIndex)
|
||||
{
|
||||
NewCurrentIndex--;
|
||||
}
|
||||
else if (NewCurrentIndex == RemoveIndex)
|
||||
{
|
||||
NewCurrentIndex = -1;
|
||||
// First we walk to the right to search for the next visible tab
|
||||
for (int i = (RemoveIndex + 1); i < count(); ++i)
|
||||
{
|
||||
if (tab(i)->isVisibleTo(this))
|
||||
{
|
||||
NewCurrentIndex = i - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If there is no visible tab right to this tab then we walk to
|
||||
// the left to find a visible tab
|
||||
if (NewCurrentIndex < 0)
|
||||
{
|
||||
for (int i = (RemoveIndex - 1); i >= 0; --i)
|
||||
{
|
||||
if (tab(i)->isVisibleTo(this))
|
||||
{
|
||||
NewCurrentIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
emit removingTab(RemoveIndex);
|
||||
d->TabsLayout->removeWidget(Tab);
|
||||
Tab->disconnect(this);
|
||||
Tab->removeEventFilter(this);
|
||||
qDebug() << "NewCurrentIndex " << NewCurrentIndex;
|
||||
if (NewCurrentIndex != d->CurrentIndex)
|
||||
{
|
||||
setCurrentIndex(NewCurrentIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
d->updateTabs();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
int CDockAreaTabBar::currentIndex() const
|
||||
{
|
||||
return d->CurrentIndex;
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
CDockWidgetTab* CDockAreaTabBar::currentTab() const
|
||||
{
|
||||
if (d->CurrentIndex < 0)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return qobject_cast<CDockWidgetTab*>(d->TabsLayout->itemAt(d->CurrentIndex)->widget());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
void CDockAreaTabBar::onTabClicked()
|
||||
{
|
||||
CDockWidgetTab* Tab = qobject_cast<CDockWidgetTab*>(sender());
|
||||
if (!Tab)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int index = d->TabsLayout->indexOf(Tab);
|
||||
if (index < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
setCurrentIndex(index);
|
||||
emit tabBarClicked(index);
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
void CDockAreaTabBar::onTabCloseRequested()
|
||||
{
|
||||
CDockWidgetTab* Tab = qobject_cast<CDockWidgetTab*>(sender());
|
||||
int Index = d->TabsLayout->indexOf(Tab);
|
||||
closeTab(Index);
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
void CDockAreaTabBar::onCloseOtherTabsRequested()
|
||||
{
|
||||
auto Sender = qobject_cast<CDockWidgetTab*>(sender());
|
||||
for (int i = 0; i < count(); ++i)
|
||||
{
|
||||
auto Tab = tab(i);
|
||||
if (Tab->isClosable() && !Tab->isHidden() && Tab != Sender)
|
||||
{
|
||||
closeTab(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
CDockWidgetTab* CDockAreaTabBar::tab(int Index) const
|
||||
{
|
||||
if (Index >= count() || Index < 0)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
return qobject_cast<CDockWidgetTab*>(d->TabsLayout->itemAt(Index)->widget());
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
void CDockAreaTabBar::onTabWidgetMoved(const QPoint& GlobalPos)
|
||||
{
|
||||
CDockWidgetTab* MovingTab = qobject_cast<CDockWidgetTab*>(sender());
|
||||
if (!MovingTab)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int fromIndex = d->TabsLayout->indexOf(MovingTab);
|
||||
auto MousePos = mapFromGlobal(GlobalPos);
|
||||
int toIndex = -1;
|
||||
// Find tab under mouse
|
||||
for (int i = 0; i < count(); ++i)
|
||||
{
|
||||
CDockWidgetTab* DropTab = tab(i);
|
||||
if (DropTab == MovingTab || !DropTab->isVisibleTo(this)
|
||||
|| !DropTab->geometry().contains(MousePos))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
toIndex = d->TabsLayout->indexOf(DropTab);
|
||||
if (toIndex == fromIndex)
|
||||
{
|
||||
toIndex = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (toIndex < 0)
|
||||
{
|
||||
toIndex = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Now check if the mouse is behind the last tab
|
||||
if (toIndex < 0)
|
||||
{
|
||||
if (MousePos.x() > tab(count() - 1)->geometry().right())
|
||||
{
|
||||
qDebug() << "after all tabs";
|
||||
toIndex = count() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
toIndex = fromIndex;
|
||||
}
|
||||
}
|
||||
|
||||
d->TabsLayout->removeWidget(MovingTab);
|
||||
d->TabsLayout->insertWidget(toIndex, MovingTab);
|
||||
if (toIndex >= 0)
|
||||
{
|
||||
qDebug() << "tabMoved from " << fromIndex << " to " << toIndex;
|
||||
emit tabMoved(fromIndex, toIndex);
|
||||
setCurrentIndex(toIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
void CDockAreaTabBar::closeTab(int Index)
|
||||
{
|
||||
if (Index < 0 || Index >= count())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto Tab = tab(Index);
|
||||
if (Tab->isHidden())
|
||||
{
|
||||
return;
|
||||
}
|
||||
emit tabCloseRequested(Index);
|
||||
Tab->hide();
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
bool CDockAreaTabBar::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
bool Result = Super::eventFilter(watched, event);
|
||||
CDockWidgetTab* Tab = qobject_cast<CDockWidgetTab*>(watched);
|
||||
if (!Tab)
|
||||
{
|
||||
return Result;
|
||||
}
|
||||
|
||||
switch (event->type())
|
||||
{
|
||||
case QEvent::Hide:
|
||||
emit tabClosed(d->TabsLayout->indexOf(Tab)); break;
|
||||
case QEvent::Show:
|
||||
emit tabOpened(d->TabsLayout->indexOf(Tab)); break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
bool CDockAreaTabBar::isTabOpen(int Index) const
|
||||
{
|
||||
if (Index < 0 || Index >= count())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return !tab(Index)->isHidden();
|
||||
}
|
||||
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
#ifndef DockAreaTabBarH
|
||||
#define DockAreaTabBarH
|
||||
/*******************************************************************************
|
||||
** 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 DockAreaTabBar.h
|
||||
/// \author Uwe Kindler
|
||||
@@ -11,11 +30,15 @@
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <QScrollArea>
|
||||
#include "ads_globals.h"
|
||||
|
||||
namespace ads
|
||||
{
|
||||
class CDockAreaWidget;
|
||||
class CDockWidgetTab;
|
||||
struct DockAreaTabBarPrivate;
|
||||
class CDockAreaTitleBar;
|
||||
class CFloatingDockContainer;
|
||||
|
||||
/**
|
||||
* Custom tabbar implementation for tab area that is shown on top of a
|
||||
@@ -27,7 +50,14 @@ class CDockAreaTabBar : public QScrollArea
|
||||
Q_OBJECT
|
||||
private:
|
||||
DockAreaTabBarPrivate* d; ///< private data (pimpl)
|
||||
friend class DockAreaTabBarPrivate;
|
||||
friend struct DockAreaTabBarPrivate;
|
||||
friend class CDockAreaTitleBar;
|
||||
|
||||
private slots:
|
||||
void onTabClicked();
|
||||
void onTabCloseRequested();
|
||||
void onCloseOtherTabsRequested();
|
||||
void onTabWidgetMoved(const QPoint& GlobalPos);
|
||||
|
||||
protected:
|
||||
virtual void wheelEvent(QWheelEvent* Event) override;
|
||||
@@ -55,9 +85,17 @@ protected:
|
||||
/**
|
||||
* Starts floating
|
||||
*/
|
||||
void startFloating(const QPoint& Pos);
|
||||
void startFloating(const QPoint& Offset);
|
||||
|
||||
/**
|
||||
* Makes the dock area floating
|
||||
*/
|
||||
CFloatingDockContainer* makeAreaFloating(const QPoint& Offset,
|
||||
eDragState DragState);
|
||||
|
||||
|
||||
public:
|
||||
using Super = QScrollArea;
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
@@ -67,6 +105,114 @@ public:
|
||||
* Virtual Destructor
|
||||
*/
|
||||
virtual ~CDockAreaTabBar();
|
||||
|
||||
/**
|
||||
* Inserts the given dock widget tab at the given position.
|
||||
* Inserting a new tab at an index less than or equal to the current index
|
||||
* will increment the current index, but keep the current tab.
|
||||
*/
|
||||
void insertTab(int Index, CDockWidgetTab* Tab);
|
||||
|
||||
/**
|
||||
* Removes the given DockWidgetTab from the tabbar
|
||||
*/
|
||||
void removeTab(CDockWidgetTab* Tab);
|
||||
|
||||
/**
|
||||
* Returns the number of tabs in this tabbar
|
||||
*/
|
||||
int count() const;
|
||||
|
||||
/**
|
||||
* Returns the current index or -1 if no tab is selected
|
||||
*/
|
||||
int currentIndex() const;
|
||||
|
||||
/**
|
||||
* Returns the current tab or a nullptr if no tab is selected.
|
||||
*/
|
||||
CDockWidgetTab* currentTab() const;
|
||||
|
||||
/**
|
||||
* Returns the tab with the given index
|
||||
*/
|
||||
CDockWidgetTab* tab(int Index) const;
|
||||
|
||||
/**
|
||||
* Filters the tab widget events
|
||||
*/
|
||||
virtual bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
/**
|
||||
* This function returns true if the tab is open, that means if it is
|
||||
* visible to the user. If the function returns false, the tab is
|
||||
* closed
|
||||
*/
|
||||
bool isTabOpen(int Index) const;
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* This property sets the index of the tab bar's visible tab
|
||||
*/
|
||||
void setCurrentIndex(int Index);
|
||||
|
||||
/**
|
||||
* This function will close the tab given in Index param.
|
||||
* Closing a tab means, the tab will be hidden, it will not be removed
|
||||
*/
|
||||
void closeTab(int Index);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* This signal is emitted when the tab bar's current tab is about to be changed. The new
|
||||
* current has the given index, or -1 if there isn't a new one.
|
||||
*/
|
||||
void currentChanging(int Index);
|
||||
|
||||
/**
|
||||
* This signal is emitted when the tab bar's current tab changes. The new
|
||||
* current has the given index, or -1 if there isn't a new one
|
||||
*/
|
||||
void currentChanged(int Index);
|
||||
|
||||
/**
|
||||
* This signal is emitted when user clicks on a tab
|
||||
*/
|
||||
void tabBarClicked(int index);
|
||||
|
||||
/**
|
||||
* This signal is emitted when the close button on a tab is clicked.
|
||||
* The index is the index that should be closed.
|
||||
*/
|
||||
void tabCloseRequested(int index);
|
||||
|
||||
/**
|
||||
* This signal is emitted if a tab has been closed
|
||||
*/
|
||||
void tabClosed(int index);
|
||||
|
||||
/**
|
||||
* This signal is emitted if a tab has been opened.
|
||||
* A tab is opened if it has been made visible
|
||||
*/
|
||||
void tabOpened(int index);
|
||||
|
||||
/**
|
||||
* This signal is emitted when the tab has moved the tab at index position
|
||||
* from to index position to.
|
||||
*/
|
||||
void tabMoved(int from, int to);
|
||||
|
||||
/**
|
||||
* This signal is emitted, just before the tab with the given index is
|
||||
* removed
|
||||
*/
|
||||
void removingTab(int index);
|
||||
|
||||
/**
|
||||
* This signal is emitted if a tab has been inserted
|
||||
*/
|
||||
void tabInserted(int index);
|
||||
}; // class CDockAreaTabBar
|
||||
} // namespace ads
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
334
src/DockAreaTitleBar.cpp
Normal file
@@ -0,0 +1,334 @@
|
||||
/*******************************************************************************
|
||||
** 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 DockAreaTitleBar.cpp
|
||||
/// \author Uwe Kindler
|
||||
/// \date 12.10.2018
|
||||
/// \brief Implementation of CDockAreaTitleBar class
|
||||
//============================================================================
|
||||
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include "DockAreaTitleBar.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QToolButton>
|
||||
#include <QBoxLayout>
|
||||
#include <QStyle>
|
||||
#include <QMenu>
|
||||
#include <QScrollArea>
|
||||
#include <QMouseEvent>
|
||||
#include <QDebug>
|
||||
|
||||
#include "ads_globals.h"
|
||||
#include "FloatingDockContainer.h"
|
||||
#include "DockAreaWidget.h"
|
||||
#include "DockOverlay.h"
|
||||
#include "DockManager.h"
|
||||
#include "DockWidget.h"
|
||||
#include "DockWidgetTab.h"
|
||||
#include "DockAreaTabBar.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace ads
|
||||
{
|
||||
using tTileBarButton = QToolButton;
|
||||
/**
|
||||
* Private data class of CDockAreaTitleBar class (pimpl)
|
||||
*/
|
||||
struct DockAreaTitleBarPrivate
|
||||
{
|
||||
CDockAreaTitleBar* _this;
|
||||
tTileBarButton* TabsMenuButton;
|
||||
tTileBarButton* UndockButton;
|
||||
tTileBarButton* CloseButton;
|
||||
QBoxLayout* TopLayout;
|
||||
CDockAreaWidget* DockArea;
|
||||
CDockAreaTabBar* TabBar;
|
||||
bool MenuOutdated = true;
|
||||
QMenu* TabsMenu;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
*/
|
||||
DockAreaTitleBarPrivate(CDockAreaTitleBar* _public);
|
||||
|
||||
/**
|
||||
* Creates the title bar close and menu buttons
|
||||
*/
|
||||
void createButtons();
|
||||
|
||||
/**
|
||||
* Creates the internal TabBar
|
||||
*/
|
||||
void createTabBar();
|
||||
|
||||
/**
|
||||
* Convenience function for DockManager access
|
||||
*/
|
||||
CDockManager* dockManager() const
|
||||
{
|
||||
return DockArea->dockManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given config flag is set
|
||||
*/
|
||||
bool testConfigFlag(CDockManager::eConfigFlag Flag) const
|
||||
{
|
||||
return DockArea->dockManager()->configFlags().testFlag(Flag);
|
||||
}
|
||||
};// struct DockAreaTitleBarPrivate
|
||||
|
||||
|
||||
|
||||
//============================================================================
|
||||
DockAreaTitleBarPrivate::DockAreaTitleBarPrivate(CDockAreaTitleBar* _public) :
|
||||
_this(_public)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockAreaTitleBarPrivate::createButtons()
|
||||
{
|
||||
TabsMenuButton = new tTileBarButton();
|
||||
TabsMenuButton->setObjectName("tabsMenuButton");
|
||||
TabsMenuButton->setAutoRaise(true);
|
||||
TabsMenuButton->setPopupMode(QToolButton::InstantPopup);
|
||||
TabsMenuButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarUnshadeButton));
|
||||
|
||||
QMenu* TabsMenu = new QMenu(TabsMenuButton);
|
||||
_this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow()));
|
||||
TabsMenuButton->setMenu(TabsMenu);
|
||||
TabsMenuButton->setToolTip(QObject::tr("List all tabs"));
|
||||
TabsMenuButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
TopLayout->addWidget(TabsMenuButton, 0);
|
||||
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
|
||||
SLOT(onTabsMenuActionTriggered(QAction*)));
|
||||
|
||||
// Undock button
|
||||
UndockButton = new tTileBarButton();
|
||||
UndockButton->setObjectName("undockButton");
|
||||
UndockButton->setAutoRaise(true);
|
||||
UndockButton->setToolTip(QObject::tr("Detach Group"));
|
||||
UndockButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarNormalButton));
|
||||
UndockButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
TopLayout->addWidget(UndockButton, 0);
|
||||
_this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked()));
|
||||
|
||||
CloseButton = new tTileBarButton();
|
||||
CloseButton->setObjectName("closeButton");
|
||||
CloseButton->setAutoRaise(true);
|
||||
|
||||
// The standard icons do not look good on high DPI screens
|
||||
QIcon CloseIcon = _this->style()->standardIcon(QStyle::SP_TitleBarCloseButton);
|
||||
QPixmap normalPixmap = _this->style()->standardPixmap(QStyle::SP_TitleBarCloseButton, 0, CloseButton);
|
||||
QPixmap disabledPixmap = internal::createTransparentPixmap(normalPixmap, 0.25);
|
||||
CloseIcon.addPixmap(disabledPixmap, QIcon::Disabled);
|
||||
|
||||
CloseButton->setIcon(CloseIcon);
|
||||
if (testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
|
||||
{
|
||||
CloseButton->setToolTip(QObject::tr("Close Active Tab"));
|
||||
}
|
||||
else
|
||||
{
|
||||
CloseButton->setToolTip(QObject::tr("Close Group"));
|
||||
}
|
||||
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
TopLayout->addWidget(CloseButton, 0);
|
||||
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockAreaTitleBarPrivate::createTabBar()
|
||||
{
|
||||
TabBar = new CDockAreaTabBar(DockArea);
|
||||
TopLayout->addWidget(TabBar);
|
||||
_this->connect(TabBar, SIGNAL(tabClosed(int)), SLOT(markTabsMenuOutdated()));
|
||||
_this->connect(TabBar, SIGNAL(tabOpened(int)), SLOT(markTabsMenuOutdated()));
|
||||
_this->connect(TabBar, SIGNAL(tabInserted(int)), SLOT(markTabsMenuOutdated()));
|
||||
_this->connect(TabBar, SIGNAL(removingTab(int)), SLOT(markTabsMenuOutdated()));
|
||||
_this->connect(TabBar, SIGNAL(tabMoved(int, int)), SLOT(markTabsMenuOutdated()));
|
||||
_this->connect(TabBar, SIGNAL(currentChanged(int)), SLOT(onCurrentTabChanged(int)));
|
||||
_this->connect(TabBar, SIGNAL(tabBarClicked(int)), SIGNAL(tabBarClicked(int)));
|
||||
|
||||
TabBar->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
_this->connect(TabBar, SIGNAL(customContextMenuRequested(const QPoint&)),
|
||||
SLOT(showContextMenu(const QPoint&)));
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) :
|
||||
QFrame(parent),
|
||||
d(new DockAreaTitleBarPrivate(this))
|
||||
{
|
||||
d->DockArea = parent;
|
||||
|
||||
setObjectName("dockAreaTitleBar");
|
||||
d->TopLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
d->TopLayout->setContentsMargins(0, 0, 0, 0);
|
||||
d->TopLayout->setSpacing(0);
|
||||
setLayout(d->TopLayout);
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
|
||||
d->createTabBar();
|
||||
d->createButtons();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockAreaTitleBar::~CDockAreaTitleBar()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockAreaTabBar* CDockAreaTitleBar::tabBar() const
|
||||
{
|
||||
return d->TabBar;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTitleBar::markTabsMenuOutdated()
|
||||
{
|
||||
d->MenuOutdated = true;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTitleBar::onTabsMenuAboutToShow()
|
||||
{
|
||||
if (!d->MenuOutdated)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QMenu* menu = d->TabsMenuButton->menu();
|
||||
menu->clear();
|
||||
for (int i = 0; i < d->TabBar->count(); ++i)
|
||||
{
|
||||
if (!d->TabBar->isTabOpen(i))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
auto Tab = d->TabBar->tab(i);
|
||||
QAction* Action = menu->addAction(Tab->icon(), Tab->text());
|
||||
Action->setData(i);
|
||||
}
|
||||
|
||||
d->MenuOutdated = false;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTitleBar::onCloseButtonClicked()
|
||||
{
|
||||
qDebug() << "CDockAreaTitleBar::onCloseButtonClicked";
|
||||
if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
|
||||
{
|
||||
d->TabBar->closeTab(d->TabBar->currentIndex());
|
||||
}
|
||||
else
|
||||
{
|
||||
d->DockArea->closeArea();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTitleBar::onUndockButtonClicked()
|
||||
{
|
||||
d->TabBar->makeAreaFloating(mapFromGlobal(QCursor::pos()), DraggingInactive);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTitleBar::onTabsMenuActionTriggered(QAction* Action)
|
||||
{
|
||||
int Index = Action->data().toInt();
|
||||
d->TabBar->setCurrentIndex(Index);
|
||||
emit tabBarClicked(Index);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTitleBar::onCurrentTabChanged(int Index)
|
||||
{
|
||||
if (Index < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
|
||||
{
|
||||
CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
|
||||
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QAbstractButton* CDockAreaTitleBar::button(TitleBarButton which) const
|
||||
{
|
||||
switch (which)
|
||||
{
|
||||
case TitleBarButtonTabsMenu: return d->TabsMenuButton;
|
||||
case TitleBarButtonUndock: return d->UndockButton;
|
||||
case TitleBarButtonClose: return d->CloseButton;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTitleBar::setVisible(bool Visible)
|
||||
{
|
||||
Super::setVisible(Visible);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTitleBar::showContextMenu(const QPoint& pos)
|
||||
{
|
||||
QMenu Menu(this);
|
||||
Menu.addAction(tr("Detach Area"), this, SLOT(onUndockButtonClicked()));
|
||||
Menu.addSeparator();
|
||||
auto Action = Menu.addAction(tr("Close Area"), this, SLOT(onCloseButtonClicked()));
|
||||
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable));
|
||||
Menu.addAction(tr("Close Other Areas"), d->DockArea, SLOT(closeOtherAreas()));
|
||||
Menu.exec(mapToGlobal(pos));
|
||||
}
|
||||
|
||||
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// EOF DockAreaTitleBar.cpp
|
||||
101
src/DockAreaTitleBar.h
Normal file
@@ -0,0 +1,101 @@
|
||||
#ifndef DockAreaTitleBarH
|
||||
#define DockAreaTitleBarH
|
||||
/*******************************************************************************
|
||||
** 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 DockAreaTitleBar.h
|
||||
/// \author Uwe Kindler
|
||||
/// \date 12.10.2018
|
||||
/// \brief Declaration of CDockAreaTitleBar class
|
||||
//============================================================================
|
||||
|
||||
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <QFrame>
|
||||
|
||||
#include "ads_globals.h"
|
||||
|
||||
class QAbstractButton;
|
||||
|
||||
namespace ads
|
||||
{
|
||||
class CDockAreaTabBar;
|
||||
class CDockAreaWidget;
|
||||
struct DockAreaTitleBarPrivate;
|
||||
|
||||
/**
|
||||
* Title bar of a dock area
|
||||
*/
|
||||
class CDockAreaTitleBar : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
DockAreaTitleBarPrivate* d; ///< private data (pimpl)
|
||||
friend struct DockAreaTitleBarPrivate;
|
||||
|
||||
private slots:
|
||||
void markTabsMenuOutdated();
|
||||
void onTabsMenuAboutToShow();
|
||||
void onCloseButtonClicked();
|
||||
void onUndockButtonClicked();
|
||||
void onTabsMenuActionTriggered(QAction* Action);
|
||||
void onCurrentTabChanged(int Index);
|
||||
void showContextMenu(const QPoint& pos);
|
||||
|
||||
public:
|
||||
using Super = QFrame;
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
CDockAreaTitleBar(CDockAreaWidget* parent);
|
||||
|
||||
/**
|
||||
* Virtual Destructor
|
||||
*/
|
||||
virtual ~CDockAreaTitleBar();
|
||||
|
||||
/**
|
||||
* Returns the pointer to the tabBar()
|
||||
*/
|
||||
CDockAreaTabBar* tabBar() const;
|
||||
|
||||
/**
|
||||
* Returns the button corresponding to the given title bar button identifier
|
||||
*/
|
||||
QAbstractButton* button(TitleBarButton which) const;
|
||||
|
||||
/**
|
||||
* This function is here for debug reasons
|
||||
*/
|
||||
virtual void setVisible(bool Visible) override;
|
||||
|
||||
signals:
|
||||
/**
|
||||
* This signal is emitted if a tab in the tab bar is clicked by the user
|
||||
* or if the user clicks on a tab item in the title bar tab menu.
|
||||
*/
|
||||
void tabBarClicked(int index);
|
||||
}; // class name
|
||||
}
|
||||
// namespace ads
|
||||
//-----------------------------------------------------------------------------
|
||||
#endif // DockAreaTitleBarH
|
||||
@@ -1,17 +1,17 @@
|
||||
/*******************************************************************************
|
||||
** 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/>.
|
||||
******************************************************************************/
|
||||
@@ -41,6 +41,8 @@
|
||||
#include <QMenu>
|
||||
#include <QSplitter>
|
||||
#include <QXmlStreamWriter>
|
||||
#include <QVector>
|
||||
#include <QList>
|
||||
|
||||
|
||||
#include "DockContainerWidget.h"
|
||||
@@ -49,13 +51,184 @@
|
||||
#include "DockManager.h"
|
||||
#include "DockOverlay.h"
|
||||
#include "DockAreaTabBar.h"
|
||||
#include "DockSplitter.h"
|
||||
#include "DockAreaTitleBar.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace ads
|
||||
{
|
||||
static const char* const INDEX_PROPERTY = "index";
|
||||
static const char* const ACTION_PROPERTY = "action";
|
||||
static const int APPEND = -1;
|
||||
|
||||
/**
|
||||
* New dock area layout mimics stack layout but only inserts the current
|
||||
* widget into the internal QLayout object
|
||||
*/
|
||||
class CDockAreaLayout
|
||||
{
|
||||
private:
|
||||
QBoxLayout* m_ParentLayout;
|
||||
QList<QWidget*> m_Widgets;
|
||||
int m_CurrentIndex = -1;
|
||||
QWidget* m_CurrentWidget = nullptr;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Creates an instance with the given parent layout
|
||||
*/
|
||||
CDockAreaLayout(QBoxLayout* ParentLayout)
|
||||
: m_ParentLayout(ParentLayout)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of widgets in this layout
|
||||
*/
|
||||
int count() const
|
||||
{
|
||||
return m_Widgets.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the widget at the given index position into the internal widget
|
||||
* list
|
||||
*/
|
||||
void insertWidget(int index, QWidget* Widget)
|
||||
{
|
||||
Widget->setParent(0);
|
||||
if (index < 0)
|
||||
{
|
||||
index = m_Widgets.count();
|
||||
}
|
||||
m_Widgets.insert(index, Widget);
|
||||
if (m_CurrentIndex < 0)
|
||||
{
|
||||
setCurrentIndex(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (index <= m_CurrentIndex )
|
||||
{
|
||||
++m_CurrentIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given widget from the lyout
|
||||
*/
|
||||
void removeWidget(QWidget* Widget)
|
||||
{
|
||||
if (currentWidget() == Widget)
|
||||
{
|
||||
auto LayoutItem = m_ParentLayout->takeAt(1);
|
||||
if (LayoutItem)
|
||||
{
|
||||
LayoutItem->widget()->setParent(0);
|
||||
}
|
||||
m_CurrentWidget = nullptr;
|
||||
m_CurrentIndex = -1;
|
||||
}
|
||||
m_Widgets.removeOne(Widget);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current selected widget
|
||||
*/
|
||||
QWidget* currentWidget() const
|
||||
{
|
||||
return m_CurrentWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates the widget with the give index.
|
||||
*/
|
||||
void setCurrentIndex(int index)
|
||||
{
|
||||
QWidget *prev = currentWidget();
|
||||
QWidget *next = widget(index);
|
||||
if (!next || (next == prev && !m_CurrentWidget))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool reenableUpdates = false;
|
||||
QWidget *parent = m_ParentLayout->parentWidget();
|
||||
|
||||
if (parent && parent->updatesEnabled())
|
||||
{
|
||||
reenableUpdates = true;
|
||||
parent->setUpdatesEnabled(false);
|
||||
}
|
||||
|
||||
auto LayoutItem = m_ParentLayout->takeAt(1);
|
||||
if (LayoutItem)
|
||||
{
|
||||
LayoutItem->widget()->setParent(0);
|
||||
}
|
||||
|
||||
m_ParentLayout->addWidget(next);
|
||||
if (prev)
|
||||
{
|
||||
prev->hide();
|
||||
}
|
||||
m_CurrentIndex = index;
|
||||
m_CurrentWidget = next;
|
||||
|
||||
|
||||
if (reenableUpdates)
|
||||
{
|
||||
parent->setUpdatesEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the current active widget
|
||||
*/
|
||||
int currentIndex() const
|
||||
{
|
||||
return m_CurrentIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there are no widgets in the layout
|
||||
*/
|
||||
bool isEmpty() const
|
||||
{
|
||||
return m_Widgets.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the given widget
|
||||
*/
|
||||
int indexOf(QWidget* w) const
|
||||
{
|
||||
return m_Widgets.indexOf(w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the widget for the given index
|
||||
*/
|
||||
QWidget* widget(int index) const
|
||||
{
|
||||
return (index < m_Widgets.size()) ? m_Widgets.at(index) : nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the geometry of the current active widget
|
||||
*/
|
||||
QRect geometry() const
|
||||
{
|
||||
return m_Widgets.empty() ? QRect() : currentWidget()->geometry();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
using DockAreaLayout = CDockAreaLayout;
|
||||
|
||||
|
||||
/**
|
||||
@@ -65,16 +238,10 @@ struct DockAreaWidgetPrivate
|
||||
{
|
||||
CDockAreaWidget* _this;
|
||||
QBoxLayout* Layout;
|
||||
QFrame* TitleBar;
|
||||
QBoxLayout* TopLayout;
|
||||
QStackedLayout* ContentsLayout;
|
||||
CDockAreaTabBar* TabBar;
|
||||
QWidget* TabsContainerWidget;
|
||||
QBoxLayout* TabsLayout;
|
||||
QPushButton* TabsMenuButton;
|
||||
QPushButton* CloseButton;
|
||||
int TabsLayoutInitCount;
|
||||
DockAreaLayout* ContentsLayout;
|
||||
CDockAreaTitleBar* TitleBar;
|
||||
CDockManager* DockManager = nullptr;
|
||||
bool UpdateCloseButton = false;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@@ -84,7 +251,7 @@ struct DockAreaWidgetPrivate
|
||||
/**
|
||||
* Creates the layout for top area with tabs and close button
|
||||
*/
|
||||
void createTabBar();
|
||||
void createTitleBar();
|
||||
|
||||
/**
|
||||
* Returns the dock widget with the given index
|
||||
@@ -97,18 +264,11 @@ struct DockAreaWidgetPrivate
|
||||
/**
|
||||
* Convenience function to ease title widget access by index
|
||||
*/
|
||||
CDockWidgetTab* titleWidgetAt(int index)
|
||||
CDockWidgetTab* tabWidgetAt(int index)
|
||||
{
|
||||
return dockWidgetAt(index)->titleBar();
|
||||
return dockWidgetAt(index)->tabWidget();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a tabs menu entry for the given dock widget
|
||||
* If menu is 0, a menu entry is added to the menu of the TabsMenuButton
|
||||
* member. If menu is a valid menu pointer, the entry will be added to
|
||||
* the given menu
|
||||
*/
|
||||
void addTabsMenuEntry(CDockWidget* DockWidget, int Index = -1, QMenu* menu = 0);
|
||||
|
||||
/**
|
||||
* Returns the tab action of the given dock widget
|
||||
@@ -127,16 +287,17 @@ struct DockAreaWidgetPrivate
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the tabs menu if dock widget order changed or if dock widget has
|
||||
* been removed
|
||||
* Convenience function for tabbar access
|
||||
*/
|
||||
void updateTabsMenu();
|
||||
CDockAreaTabBar* tabBar() const
|
||||
{
|
||||
return TitleBar->tabBar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the tab bar visibility depending on the number of dock widgets
|
||||
* in this area
|
||||
* Udpates the enable state of the close button
|
||||
*/
|
||||
void updateTabBar();
|
||||
void updateCloseButtonState();
|
||||
};
|
||||
// struct DockAreaWidgetPrivate
|
||||
|
||||
@@ -150,102 +311,31 @@ DockAreaWidgetPrivate::DockAreaWidgetPrivate(CDockAreaWidget* _public) :
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockAreaWidgetPrivate::createTabBar()
|
||||
void DockAreaWidgetPrivate::createTitleBar()
|
||||
{
|
||||
TitleBar = new QFrame(_this);
|
||||
TitleBar->setObjectName("dockAreaTitleBar");
|
||||
TopLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
TopLayout->setContentsMargins(0, 0, 0, 0);
|
||||
TopLayout->setSpacing(0);
|
||||
TitleBar->setLayout(TopLayout);
|
||||
TitleBar = new CDockAreaTitleBar(_this);
|
||||
Layout->addWidget(TitleBar);
|
||||
|
||||
TabBar = new CDockAreaTabBar(_this);
|
||||
TopLayout->addWidget(TabBar, 1);
|
||||
|
||||
TabsContainerWidget = new QWidget();
|
||||
TabsContainerWidget->setObjectName("tabsContainerWidget");
|
||||
TabBar->setWidget(TabsContainerWidget);
|
||||
|
||||
TabsLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
TabsLayout->setContentsMargins(0, 0, 0, 0);
|
||||
TabsLayout->setSpacing(0);
|
||||
TabsLayout->addStretch(1);
|
||||
TabsContainerWidget->setLayout(TabsLayout);
|
||||
|
||||
TabsMenuButton = new QPushButton();
|
||||
TabsMenuButton->setObjectName("tabsMenuButton");
|
||||
TabsMenuButton->setFlat(true);
|
||||
TabsMenuButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarUnshadeButton));
|
||||
TabsMenuButton->setMaximumWidth(TabsMenuButton->iconSize().width());
|
||||
TabsMenuButton->setMenu(new QMenu(TabsMenuButton));
|
||||
TopLayout->addWidget(TabsMenuButton, 0);
|
||||
TabsMenuButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
|
||||
SLOT(onTabsMenuActionTriggered(QAction*)));
|
||||
|
||||
CloseButton = new QPushButton();
|
||||
CloseButton->setObjectName("closeButton");
|
||||
CloseButton->setFlat(true);
|
||||
CloseButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
|
||||
CloseButton->setToolTip(_this->tr("Close"));
|
||||
CloseButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
TopLayout->addWidget(CloseButton, 0);
|
||||
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
|
||||
|
||||
TabsLayoutInitCount = TabsLayout->count();
|
||||
_this->connect(tabBar(), SIGNAL(tabCloseRequested(int)),
|
||||
SLOT(onTabCloseRequested(int)));
|
||||
_this->connect(TitleBar, SIGNAL(tabBarClicked(int)),
|
||||
SLOT(setCurrentIndex(int)));
|
||||
_this->connect(tabBar(), SIGNAL(tabMoved(int, int)),
|
||||
SLOT(reorderDockWidget(int, int)));
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockAreaWidgetPrivate::updateTabBar()
|
||||
void DockAreaWidgetPrivate::updateCloseButtonState()
|
||||
{
|
||||
CDockContainerWidget* Container = _this->dockContainer();
|
||||
if (!Container)
|
||||
if (_this->isHidden())
|
||||
{
|
||||
UpdateCloseButton = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Container->isFloating() && (Container->dockAreaCount() == 1) && (_this->count() == 1))
|
||||
{
|
||||
TitleBar->setVisible(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
TitleBar->setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockAreaWidgetPrivate::addTabsMenuEntry(CDockWidget* DockWidget,
|
||||
int Index, QMenu* menu)
|
||||
{
|
||||
menu = menu ? menu : TabsMenuButton->menu();
|
||||
QAction* Action;
|
||||
if (Index >= 0 && Index < menu->actions().count())
|
||||
{
|
||||
Action = new QAction(DockWidget->icon(), DockWidget->windowTitle());
|
||||
menu->insertAction(menu->actions().at(Index), Action);
|
||||
}
|
||||
else
|
||||
{
|
||||
Action = menu->addAction(DockWidget->icon(), DockWidget->windowTitle());
|
||||
}
|
||||
QVariant vAction = QVariant::fromValue(Action);
|
||||
DockWidget->setProperty(ACTION_PROPERTY, vAction);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockAreaWidgetPrivate::updateTabsMenu()
|
||||
{
|
||||
QMenu* menu = TabsMenuButton->menu();
|
||||
menu->clear();
|
||||
for (int i = 0; i < ContentsLayout->count(); ++i)
|
||||
{
|
||||
addTabsMenuEntry(dockWidgetAt(i), APPEND, menu);
|
||||
}
|
||||
TitleBar->button(TitleBarButtonClose)->setEnabled(
|
||||
_this->features().testFlag(CDockWidget::DockWidgetClosable));
|
||||
UpdateCloseButton = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -260,18 +350,15 @@ CDockAreaWidget::CDockAreaWidget(CDockManager* DockManager, CDockContainerWidget
|
||||
d->Layout->setSpacing(0);
|
||||
setLayout(d->Layout);
|
||||
|
||||
d->createTabBar();
|
||||
|
||||
d->ContentsLayout = new QStackedLayout();
|
||||
d->ContentsLayout->setContentsMargins(0, 0, 0, 0);
|
||||
d->ContentsLayout->setSpacing(0);
|
||||
d->Layout->addLayout(d->ContentsLayout, 1);
|
||||
d->createTitleBar();
|
||||
d->ContentsLayout = new DockAreaLayout(d->Layout);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
CDockAreaWidget::~CDockAreaWidget()
|
||||
{
|
||||
qDebug() << "~CDockAreaWidget()";
|
||||
delete d->ContentsLayout;
|
||||
delete d;
|
||||
}
|
||||
|
||||
@@ -286,18 +373,7 @@ CDockManager* CDockAreaWidget::dockManager() const
|
||||
//============================================================================
|
||||
CDockContainerWidget* CDockAreaWidget::dockContainer() const
|
||||
{
|
||||
QWidget* Parent = parentWidget();
|
||||
while (Parent)
|
||||
{
|
||||
CDockContainerWidget* Container = dynamic_cast<CDockContainerWidget*>(Parent);
|
||||
if (Container)
|
||||
{
|
||||
return Container;
|
||||
}
|
||||
Parent = Parent->parentWidget();
|
||||
}
|
||||
|
||||
return 0;
|
||||
return internal::findParent<CDockContainerWidget*>(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -313,18 +389,21 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
|
||||
bool Activate)
|
||||
{
|
||||
d->ContentsLayout->insertWidget(index, DockWidget);
|
||||
DockWidget->titleBar()->setDockAreaWidget(this);
|
||||
auto TitleBar = DockWidget->titleBar();
|
||||
d->TabsLayout->insertWidget(index, TitleBar);
|
||||
TitleBar->show();
|
||||
connect(TitleBar, SIGNAL(clicked()), this, SLOT(onDockWidgetTitleClicked()));
|
||||
DockWidget->tabWidget()->setDockAreaWidget(this);
|
||||
auto TabWidget = DockWidget->tabWidget();
|
||||
// Inserting the tab will change the current index which in turn will
|
||||
// make the tab widget visible in the slot
|
||||
d->tabBar()->blockSignals(true);
|
||||
d->tabBar()->insertTab(index, TabWidget);
|
||||
d->tabBar()->blockSignals(false);
|
||||
TabWidget->setVisible(!DockWidget->isClosed());
|
||||
DockWidget->setProperty(INDEX_PROPERTY, index);
|
||||
if (Activate)
|
||||
{
|
||||
setCurrentIndex(index);
|
||||
}
|
||||
d->addTabsMenuEntry(DockWidget, index);
|
||||
DockWidget->setDockArea(this);
|
||||
d->updateCloseButtonState();
|
||||
}
|
||||
|
||||
|
||||
@@ -332,64 +411,118 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
|
||||
void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
|
||||
{
|
||||
qDebug() << "CDockAreaWidget::removeDockWidget";
|
||||
d->ContentsLayout->removeWidget(DockWidget);
|
||||
auto TitleBar = DockWidget->titleBar();
|
||||
TitleBar->hide();
|
||||
d->TabsLayout->removeWidget(TitleBar);
|
||||
disconnect(TitleBar, SIGNAL(clicked()), this, SLOT(onDockWidgetTitleClicked()));
|
||||
setCurrentIndex(d->ContentsLayout->currentIndex());
|
||||
d->updateTabsMenu();
|
||||
auto NextOpenDockWidget = nextOpenDockWidget(DockWidget);
|
||||
|
||||
CDockContainerWidget* DockContainer = dockContainer();
|
||||
if (d->ContentsLayout->isEmpty())
|
||||
d->ContentsLayout->removeWidget(DockWidget);
|
||||
auto TabWidget = DockWidget->tabWidget();
|
||||
TabWidget->hide();
|
||||
d->tabBar()->removeTab(TabWidget);
|
||||
if (NextOpenDockWidget)
|
||||
{
|
||||
setCurrentDockWidget(NextOpenDockWidget);
|
||||
}
|
||||
else if (d->ContentsLayout->isEmpty())
|
||||
{
|
||||
qDebug() << "Dock Area empty";
|
||||
dockContainer()->removeDockArea(this);
|
||||
this->deleteLater();;
|
||||
this->deleteLater();
|
||||
}
|
||||
else
|
||||
{
|
||||
// if contents layout is not empty but there are no more open dock
|
||||
// widgets, then we need to hide the dock area because it does not
|
||||
// contain any visible content
|
||||
hideAreaWithNoVisibleContent();
|
||||
}
|
||||
|
||||
d->updateTabBar();
|
||||
DockWidget->setDockArea(nullptr);
|
||||
d->updateCloseButtonState();
|
||||
updateTitleBarVisibility();
|
||||
auto TopLevelDockWidget = dockContainer()->topLevelDockWidget();
|
||||
if (TopLevelDockWidget)
|
||||
{
|
||||
TopLevelDockWidget->emitTopLevelChanged(true);
|
||||
}
|
||||
|
||||
#if (ADS_DEBUG_LEVEL > 0)
|
||||
CDockContainerWidget* DockContainer = dockContainer();
|
||||
DockContainer->dumpLayout();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::onDockWidgetTitleClicked()
|
||||
void CDockAreaWidget::hideAreaWithNoVisibleContent()
|
||||
{
|
||||
CDockWidgetTab* TitleWidget = qobject_cast<CDockWidgetTab*>(sender());
|
||||
if (!TitleWidget)
|
||||
this->toggleView(false);
|
||||
|
||||
// Hide empty parent splitters
|
||||
auto Splitter = internal::findParent<CDockSplitter*>(this);
|
||||
internal::hideEmptyParentSplitters(Splitter);
|
||||
|
||||
//Hide empty floating widget
|
||||
CDockContainerWidget* Container = this->dockContainer();
|
||||
if (!Container->isFloating())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int index = d->TabsLayout->indexOf(TitleWidget);
|
||||
setCurrentIndex(index);
|
||||
updateTitleBarVisibility();
|
||||
auto TopLevelWidget = Container->topLevelDockWidget();
|
||||
auto FloatingWidget = Container->floatingWidget();
|
||||
if (TopLevelWidget)
|
||||
{
|
||||
FloatingWidget->updateWindowTitle();
|
||||
CDockWidget::emitTopLevelEventForWidget(TopLevelWidget, true);
|
||||
}
|
||||
else if (Container->openedDockAreas().isEmpty())
|
||||
{
|
||||
FloatingWidget->hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::onCloseButtonClicked()
|
||||
void CDockAreaWidget::onTabCloseRequested(int Index)
|
||||
{
|
||||
currentDockWidget()->toggleView(false);
|
||||
qDebug() << "CDockAreaWidget::onTabCloseRequested " << Index;
|
||||
dockWidget(Index)->toggleView(false);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockWidget* CDockAreaWidget::currentDockWidget() const
|
||||
{
|
||||
return dockWidget(currentIndex());
|
||||
int CurrentIndex = currentIndex();
|
||||
if (CurrentIndex < 0)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return dockWidget(CurrentIndex);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::setCurrentDockWidget(CDockWidget* DockWidget)
|
||||
{
|
||||
int Index = tabIndex(DockWidget);
|
||||
if (dockManager()->isRestoringState())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
internalSetCurrentDockWidget(DockWidget);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::internalSetCurrentDockWidget(CDockWidget* DockWidget)
|
||||
{
|
||||
int Index = index(DockWidget);
|
||||
if (Index < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
setCurrentIndex(Index);
|
||||
}
|
||||
|
||||
@@ -397,43 +530,15 @@ void CDockAreaWidget::setCurrentDockWidget(CDockWidget* DockWidget)
|
||||
//============================================================================
|
||||
void CDockAreaWidget::setCurrentIndex(int index)
|
||||
{
|
||||
if (index < 0 || index > (d->TabsLayout->count() - 1))
|
||||
auto TabBar = d->tabBar();
|
||||
if (index < 0 || index > (TabBar->count() - 1))
|
||||
{
|
||||
qWarning() << Q_FUNC_INFO << "Invalid index" << index;
|
||||
return;
|
||||
}
|
||||
|
||||
emit currentChanging(index);
|
||||
|
||||
// Set active TAB and update all other tabs to be inactive
|
||||
for (int i = 0; i < d->TabsLayout->count(); ++i)
|
||||
{
|
||||
QLayoutItem* item = d->TabsLayout->itemAt(i);
|
||||
if (!item->widget())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto TitleWidget = dynamic_cast<CDockWidgetTab*>(item->widget());
|
||||
if (!TitleWidget)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i == index)
|
||||
{
|
||||
TitleWidget->show();
|
||||
TitleWidget->setActiveTab(true);
|
||||
d->TabBar->ensureWidgetVisible(TitleWidget);
|
||||
auto Features = TitleWidget->dockWidget()->features();
|
||||
d->CloseButton->setVisible(Features.testFlag(CDockWidget::DockWidgetClosable));
|
||||
}
|
||||
else
|
||||
{
|
||||
TitleWidget->setActiveTab(false);
|
||||
}
|
||||
}
|
||||
|
||||
TabBar->setCurrentIndex(index);
|
||||
d->ContentsLayout->setCurrentIndex(index);
|
||||
d->ContentsLayout->currentWidget()->show();
|
||||
emit currentChanged(index);
|
||||
@@ -448,9 +553,9 @@ int CDockAreaWidget::currentIndex() const
|
||||
|
||||
|
||||
//============================================================================
|
||||
QRect CDockAreaWidget::titleAreaGeometry() const
|
||||
QRect CDockAreaWidget::titleBarGeometry() const
|
||||
{
|
||||
return d->TopLayout->geometry();
|
||||
return d->TitleBar->geometry();
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
@@ -461,7 +566,7 @@ QRect CDockAreaWidget::contentAreaGeometry() const
|
||||
|
||||
|
||||
//============================================================================
|
||||
int CDockAreaWidget::tabIndex(CDockWidget* DockWidget)
|
||||
int CDockAreaWidget::index(CDockWidget* DockWidget)
|
||||
{
|
||||
return d->ContentsLayout->indexOf(DockWidget);
|
||||
}
|
||||
@@ -479,6 +584,21 @@ QList<CDockWidget*> CDockAreaWidget::dockWidgets() const
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
int CDockAreaWidget::openDockWidgetsCount() const
|
||||
{
|
||||
int Count = 0;
|
||||
for (int i = 0; i < d->ContentsLayout->count(); ++i)
|
||||
{
|
||||
if (!dockWidget(i)->isClosed())
|
||||
{
|
||||
++Count;
|
||||
}
|
||||
}
|
||||
return Count;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QList<CDockWidget*> CDockAreaWidget::openedDockWidgets() const
|
||||
{
|
||||
@@ -496,22 +616,22 @@ QList<CDockWidget*> CDockAreaWidget::openedDockWidgets() const
|
||||
|
||||
|
||||
//============================================================================
|
||||
int CDockAreaWidget::indexOfContentByTitlePos(const QPoint& p, QWidget* exclude) const
|
||||
int CDockAreaWidget::indexOfFirstOpenDockWidget() const
|
||||
{
|
||||
for (int i = 0; i < d->ContentsLayout->count(); ++i)
|
||||
{
|
||||
auto TitleWidget = d->titleWidgetAt(i);
|
||||
if (TitleWidget->geometry().contains(p) && (!exclude || TitleWidget != exclude))
|
||||
if (!dockWidget(i)->isClosed())
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
int CDockAreaWidget::count() const
|
||||
int CDockAreaWidget::dockWidgetsCount() const
|
||||
{
|
||||
return d->ContentsLayout->count();
|
||||
}
|
||||
@@ -520,70 +640,60 @@ int CDockAreaWidget::count() const
|
||||
//============================================================================
|
||||
CDockWidget* CDockAreaWidget::dockWidget(int Index) const
|
||||
{
|
||||
return dynamic_cast<CDockWidget*>(d->ContentsLayout->widget(Index));
|
||||
return qobject_cast<CDockWidget*>(d->ContentsLayout->widget(Index));
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::reorderDockWidget(int fromIndex, int toIndex)
|
||||
{
|
||||
qDebug() << "CDockAreaWidget::reorderDockWidget";
|
||||
if (fromIndex >= d->ContentsLayout->count() || fromIndex < 0
|
||||
|| toIndex >= d->ContentsLayout->count() || toIndex < 0 || fromIndex == toIndex)
|
||||
{
|
||||
qDebug() << "Invalid index for tab movement" << fromIndex << toIndex;
|
||||
d->TabsLayout->update();
|
||||
return;
|
||||
}
|
||||
|
||||
CDockWidget* DockWidget = dockWidget(fromIndex);
|
||||
|
||||
// reorder tabs menu action to match new order of contents
|
||||
auto Menu = d->TabsMenuButton->menu();
|
||||
auto TabsAction = d->dockWidgetTabAction(DockWidget);
|
||||
Menu->removeAction(TabsAction);
|
||||
if (toIndex >= Menu->actions().count())
|
||||
{
|
||||
Menu->addAction(TabsAction);
|
||||
}
|
||||
else
|
||||
{
|
||||
Menu->insertAction(Menu->actions().at(toIndex), TabsAction);
|
||||
}
|
||||
|
||||
|
||||
// now reorder contents and title bars
|
||||
QLayoutItem* liFrom = nullptr;
|
||||
liFrom = d->TabsLayout->takeAt(fromIndex);
|
||||
d->TabsLayout->insertItem(toIndex, liFrom);
|
||||
liFrom = d->ContentsLayout->takeAt(fromIndex);
|
||||
d->ContentsLayout->insertWidget(toIndex, liFrom->widget());
|
||||
delete liFrom;
|
||||
auto Widget = d->ContentsLayout->widget(fromIndex);
|
||||
d->ContentsLayout->removeWidget(Widget);
|
||||
d->ContentsLayout->insertWidget(toIndex, Widget);
|
||||
setCurrentIndex(toIndex);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::onTabsMenuActionTriggered(QAction* Action)
|
||||
void CDockAreaWidget::toggleDockWidgetView(CDockWidget* DockWidget, bool Open)
|
||||
{
|
||||
int Index = d->TabsMenuButton->menu()->actions().indexOf(Action);
|
||||
setCurrentIndex(Index);
|
||||
Q_UNUSED(DockWidget);
|
||||
Q_UNUSED(Open);
|
||||
updateTitleBarVisibility();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::updateDockArea()
|
||||
void CDockAreaWidget::updateTitleBarVisibility()
|
||||
{
|
||||
d->updateTabBar();
|
||||
CDockContainerWidget* Container = dockContainer();
|
||||
if (!Container)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
d->TitleBar->setVisible(!Container->isFloating() || !Container->hasTopLevelDockWidget());
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::saveState(QXmlStreamWriter& s) const
|
||||
{
|
||||
s.writeStartElement("DockAreaWidget");
|
||||
s.writeStartElement("Area");
|
||||
s.writeAttribute("Tabs", QString::number(d->ContentsLayout->count()));
|
||||
s.writeAttribute("CurrentIndex", QString::number(d->ContentsLayout->currentIndex()));
|
||||
auto CurrentDockWidget = currentDockWidget();
|
||||
QString Name = CurrentDockWidget ? CurrentDockWidget->objectName() : "";
|
||||
s.writeAttribute("Current", Name);
|
||||
qDebug() << "CDockAreaWidget::saveState TabCount: " << d->ContentsLayout->count()
|
||||
<< " CurrentIndex: " << d->ContentsLayout->currentIndex();
|
||||
<< " Current: " << Name;
|
||||
for (int i = 0; i < d->ContentsLayout->count(); ++i)
|
||||
{
|
||||
dockWidget(i)->saveState(s);
|
||||
@@ -591,6 +701,88 @@ void CDockAreaWidget::saveState(QXmlStreamWriter& s) const
|
||||
s.writeEndElement();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockWidget* CDockAreaWidget::nextOpenDockWidget(CDockWidget* DockWidget) const
|
||||
{
|
||||
auto OpenDockWidgets = openedDockWidgets();
|
||||
if (OpenDockWidgets.count() > 1 || (OpenDockWidgets.count() == 1 && OpenDockWidgets[0] != DockWidget))
|
||||
{
|
||||
CDockWidget* NextDockWidget;
|
||||
if (OpenDockWidgets.last() == DockWidget)
|
||||
{
|
||||
NextDockWidget = OpenDockWidgets[OpenDockWidgets.count() - 2];
|
||||
}
|
||||
else
|
||||
{
|
||||
int NextIndex = OpenDockWidgets.indexOf(DockWidget) + 1;
|
||||
NextDockWidget = OpenDockWidgets[NextIndex];
|
||||
}
|
||||
|
||||
return NextDockWidget;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockWidget::DockWidgetFeatures CDockAreaWidget::features() const
|
||||
{
|
||||
CDockWidget::DockWidgetFeatures Features(CDockWidget::AllDockWidgetFeatures);
|
||||
for (const auto DockWidget : dockWidgets())
|
||||
{
|
||||
Features &= DockWidget->features();
|
||||
}
|
||||
|
||||
return Features;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::toggleView(bool Open)
|
||||
{
|
||||
setVisible(Open);
|
||||
|
||||
emit viewToggled(Open);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::setVisible(bool Visible)
|
||||
{
|
||||
Super::setVisible(Visible);
|
||||
if (d->UpdateCloseButton)
|
||||
{
|
||||
d->updateCloseButtonState();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QAbstractButton* CDockAreaWidget::titleBarButton(TitleBarButton which) const
|
||||
{
|
||||
return d->TitleBar->button(which);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::closeArea()
|
||||
{
|
||||
for (auto DockWidget : openedDockWidgets())
|
||||
{
|
||||
DockWidget->toggleView(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::closeOtherAreas()
|
||||
{
|
||||
dockContainer()->closeOtherAreas(this);
|
||||
}
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -33,16 +33,17 @@
|
||||
#include <QFrame>
|
||||
|
||||
#include "ads_globals.h"
|
||||
#include "DockWidget.h"
|
||||
|
||||
class QXmlStreamWriter;
|
||||
class QAbstractButton;
|
||||
|
||||
namespace ads
|
||||
{
|
||||
struct DockAreaWidgetPrivate;
|
||||
class CDockManager;
|
||||
class CDockContainerWidget;
|
||||
struct DockContainerWidgetPrivate;
|
||||
class CDockWidget;
|
||||
class DockContainerWidgetPrivate;
|
||||
|
||||
|
||||
/**
|
||||
@@ -59,11 +60,18 @@ private:
|
||||
friend class CDockContainerWidget;
|
||||
friend class DockContainerWidgetPrivate;
|
||||
friend class CDockWidgetTab;
|
||||
friend struct DockWidgetPrivate;
|
||||
friend class CDockWidget;
|
||||
friend struct DockManagerPrivate;
|
||||
|
||||
private slots:
|
||||
void onDockWidgetTitleClicked();
|
||||
void onTabsMenuActionTriggered(QAction* Action);
|
||||
void onCloseButtonClicked();
|
||||
void onTabCloseRequested(int Index);
|
||||
|
||||
/**
|
||||
* Reorder the index position of DockWidget at fromIndx to toIndex
|
||||
* if a tab in the tabbar is dragged from one index to another one
|
||||
*/
|
||||
void reorderDockWidget(int fromIndex, int toIndex);
|
||||
|
||||
protected:
|
||||
/**
|
||||
@@ -87,18 +95,47 @@ protected:
|
||||
void removeDockWidget(CDockWidget* DockWidget);
|
||||
|
||||
/**
|
||||
* Returns the index of contents of the title widget that is located at
|
||||
* mouse position pos
|
||||
* Called from dock widget if it is opened or closed
|
||||
*/
|
||||
int indexOfContentByTitlePos(const QPoint& pos, QWidget* exclude = nullptr) const;
|
||||
void toggleDockWidgetView(CDockWidget* DockWidget, bool Open);
|
||||
|
||||
/**
|
||||
* Reorder the index position of DockWidget at fromIndx to toIndex.
|
||||
* This is a helper function to get the next open dock widget to activate
|
||||
* if the given DockWidget will be closed or removed.
|
||||
* The function returns the next widget that should be activated or
|
||||
* nullptr in case there are no more open widgets in this area.
|
||||
*/
|
||||
void reorderDockWidget(int fromIndex, int toIndex);
|
||||
CDockWidget* nextOpenDockWidget(CDockWidget* DockWidget) const;
|
||||
|
||||
/**
|
||||
* Returns the index of the given DockWidget in the internal layout
|
||||
*/
|
||||
int index(CDockWidget* DockWidget);
|
||||
|
||||
/**
|
||||
* Call this function, if you already know, that the dock does not
|
||||
* contain any visible content (any open dock widgets).
|
||||
*/
|
||||
void hideAreaWithNoVisibleContent();
|
||||
|
||||
/**
|
||||
* Updates the dock area layout and components visibility
|
||||
*/
|
||||
void updateTitleBarVisibility();
|
||||
|
||||
/**
|
||||
* This is the internal private function for setting the current widget.
|
||||
* This function is called by the public setCurrentDockWidget() function
|
||||
* and by the dock manager when restoring the state
|
||||
*/
|
||||
void internalSetCurrentDockWidget(CDockWidget* DockWidget);
|
||||
|
||||
protected slots:
|
||||
void toggleView(bool Open);
|
||||
|
||||
public:
|
||||
using Super = QFrame;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
@@ -123,7 +160,7 @@ public:
|
||||
/**
|
||||
* Returns the rectangle of the title area
|
||||
*/
|
||||
QRect titleAreaGeometry() const;
|
||||
QRect titleBarGeometry() const;
|
||||
|
||||
/**
|
||||
* Returns the rectangle of the content
|
||||
@@ -131,9 +168,9 @@ public:
|
||||
QRect contentAreaGeometry() const;
|
||||
|
||||
/**
|
||||
* Returns the tab index of the given DockWidget
|
||||
* Returns the number of dock widgets in this area
|
||||
*/
|
||||
int tabIndex(CDockWidget* DockWidget);
|
||||
int dockWidgetsCount() const;
|
||||
|
||||
/**
|
||||
* Returns a list of all dock widgets in this dock area.
|
||||
@@ -141,28 +178,41 @@ public:
|
||||
*/
|
||||
QList<CDockWidget*> dockWidgets() const;
|
||||
|
||||
/**
|
||||
* Returns the number of dock widgets in this area
|
||||
*/
|
||||
int openDockWidgetsCount() const;
|
||||
|
||||
/**
|
||||
* Returns a list of dock widgets that are not closed
|
||||
*/
|
||||
QList<CDockWidget*> openedDockWidgets() const;
|
||||
|
||||
/**
|
||||
* Returns the number of dock widgets in this area
|
||||
*/
|
||||
int count() const;
|
||||
|
||||
/**
|
||||
* Returns a dock widget by its index
|
||||
*/
|
||||
CDockWidget* dockWidget(int Index) const;
|
||||
|
||||
/**
|
||||
* Returns the index of the current active dock widget
|
||||
* Returns the index of the current active dock widget or -1 if there
|
||||
* are is no active dock widget (ie.e if all dock widgets are closed)
|
||||
*/
|
||||
int currentIndex() const;
|
||||
|
||||
/**
|
||||
* Returns the current active dock widget
|
||||
* Returns the index of the first open dock widgets in the list of
|
||||
* dock widgets.
|
||||
* This function is here for performance reasons. Normally it would
|
||||
* be possible to take the first dock widget from the list returned by
|
||||
* openedDockWidgets() function. But that function enumerates all
|
||||
* dock widgets while this functions stops after the first open dock widget.
|
||||
* If there are no open dock widgets, the function returns -1.
|
||||
*/
|
||||
int indexOfFirstOpenDockWidget() const;
|
||||
|
||||
/**
|
||||
* Returns the current active dock widget or a nullptr if there is no
|
||||
* active dock widget (i.e. if all dock widgets are closed)
|
||||
*/
|
||||
CDockWidget* currentDockWidget() const;
|
||||
|
||||
@@ -176,16 +226,43 @@ public:
|
||||
*/
|
||||
void saveState(QXmlStreamWriter& Stream) const;
|
||||
|
||||
/**
|
||||
* This functions returns the dock widget features of all dock widget in
|
||||
* this area.
|
||||
* A bitwise and is used to combine the flags of all dock widgets. That
|
||||
* means, if only dock widget does not support a certain flag, the whole
|
||||
* dock are does not support the flag.
|
||||
*/
|
||||
CDockWidget::DockWidgetFeatures features() const;
|
||||
|
||||
/**
|
||||
* Returns the title bar button corresponding to the given title bar
|
||||
* button identifier
|
||||
*/
|
||||
QAbstractButton* titleBarButton(TitleBarButton which) const;
|
||||
|
||||
/**
|
||||
* Update the close button if visibility changed
|
||||
*/
|
||||
virtual void setVisible(bool Visible) override;
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* This sets the index position of the current tab page.
|
||||
* This activates the tab for the given tab index.
|
||||
* If the dock widget for the given tab is not visible, the this function
|
||||
* call will make it visible.
|
||||
*/
|
||||
void setCurrentIndex(int index);
|
||||
|
||||
/**
|
||||
* Updates the dock area layout and components visibility
|
||||
* Closes the dock area and all dock widgets in this area
|
||||
*/
|
||||
void updateDockArea();
|
||||
void closeArea();
|
||||
|
||||
/**
|
||||
* This function closes all other areas except of this area
|
||||
*/
|
||||
void closeOtherAreas();
|
||||
|
||||
signals:
|
||||
/**
|
||||
@@ -206,6 +283,12 @@ signals:
|
||||
* @param index
|
||||
*/
|
||||
void currentChanged(int index);
|
||||
|
||||
/**
|
||||
* This signal is emitted if the visibility of this dock area is toggled
|
||||
* via toggle view function
|
||||
*/
|
||||
void viewToggled(bool Open);
|
||||
}; // class DockAreaWidget
|
||||
}
|
||||
// namespace ads
|
||||
|
||||
@@ -30,8 +30,6 @@
|
||||
//============================================================================
|
||||
#include "DockContainerWidget.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <QEvent>
|
||||
#include <QList>
|
||||
#include <QGridLayout>
|
||||
@@ -39,21 +37,69 @@
|
||||
#include <QVariant>
|
||||
#include <QDebug>
|
||||
#include <QXmlStreamWriter>
|
||||
#include <QAbstractButton>
|
||||
|
||||
#include "DockManager.h"
|
||||
#include "DockAreaWidget.h"
|
||||
#include "DockWidget.h"
|
||||
#include "FloatingDockContainer.h"
|
||||
#include "DockOverlay.h"
|
||||
#include "DockStateSerialization.h"
|
||||
#include "ads_globals.h"
|
||||
#include "DockSplitter.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#if QT_VERSION < 0x050900
|
||||
|
||||
inline char toHexLower(uint value)
|
||||
{
|
||||
return "0123456789abcdef"[value & 0xF];
|
||||
}
|
||||
|
||||
QByteArray qByteArrayToHex(const QByteArray& src, char separator)
|
||||
{
|
||||
if(src.size() == 0)
|
||||
return QByteArray();
|
||||
|
||||
const int length = separator ? (src.size() * 3 - 1) : (src.size() * 2);
|
||||
QByteArray hex(length, Qt::Uninitialized);
|
||||
char *hexData = hex.data();
|
||||
const uchar *data = (const uchar *)src.data();
|
||||
for (int i = 0, o = 0; i < src.size(); ++i) {
|
||||
hexData[o++] = toHexLower(data[i] >> 4);
|
||||
hexData[o++] = toHexLower(data[i] & 0xf);
|
||||
|
||||
if ((separator) && (o < length))
|
||||
hexData[o++] = separator;
|
||||
}
|
||||
return hex;
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace ads
|
||||
{
|
||||
static unsigned int zOrderCounter = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Converts dock area ID to an index for array access
|
||||
*/
|
||||
static int areaIdToIndex(DockWidgetArea area)
|
||||
{
|
||||
switch (area)
|
||||
{
|
||||
case LeftDockWidgetArea: return 0;
|
||||
case RightDockWidgetArea: return 1;
|
||||
case TopDockWidgetArea: return 2;
|
||||
case BottomDockWidgetArea: return 3;
|
||||
case CenterDockWidgetArea: return 4;
|
||||
default:
|
||||
return 4;
|
||||
}
|
||||
|
||||
return 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to ease insertion of dock area into splitter
|
||||
*/
|
||||
@@ -72,15 +118,19 @@ static void insertWidgetIntoSplitter(QSplitter* Splitter, QWidget* widget, bool
|
||||
/**
|
||||
* Private data class of CDockContainerWidget class (pimpl)
|
||||
*/
|
||||
struct DockContainerWidgetPrivate
|
||||
class DockContainerWidgetPrivate
|
||||
{
|
||||
public:
|
||||
CDockContainerWidget* _this;
|
||||
QPointer<CDockManager> DockManager;
|
||||
unsigned int zOrderIndex = 0;
|
||||
QList<CDockAreaWidget*> DockAreas;
|
||||
QGridLayout* Layout = nullptr;
|
||||
QSplitter* RootSplitter;
|
||||
QSplitter* RootSplitter = nullptr;
|
||||
bool isFloating = false;
|
||||
CDockAreaWidget* LastAddedAreaCache[5]{0, 0, 0, 0, 0};
|
||||
int VisibleDockAreaCount = -1;
|
||||
CDockAreaWidget* TopLevelDockArea = nullptr;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@@ -115,11 +165,23 @@ struct DockContainerWidgetPrivate
|
||||
void dropIntoSection(CFloatingDockContainer* FloatingWidget,
|
||||
CDockAreaWidget* TargetArea, DockWidgetArea area);
|
||||
|
||||
/**
|
||||
* Creates a new tab for a widget dropped into the center of a section
|
||||
*/
|
||||
void dropIntoCenterOfSection(CFloatingDockContainer* FloatingWidget,
|
||||
CDockAreaWidget* TargetArea);
|
||||
|
||||
/**
|
||||
* Adds new dock areas to the internal dock area list
|
||||
*/
|
||||
void addDockAreasToList(const QList<CDockAreaWidget*> NewDockAreas);
|
||||
|
||||
/**
|
||||
* Wrapper function for DockAreas append, that ensures that dock area signals
|
||||
* are properly connected to dock container slots
|
||||
*/
|
||||
void appendDockAreas(const QList<CDockAreaWidget*> NewDockAreas);
|
||||
|
||||
/**
|
||||
* Save state of child nodes
|
||||
*/
|
||||
@@ -154,6 +216,74 @@ struct DockContainerWidgetPrivate
|
||||
* Helper function for recursive dumping of layout
|
||||
*/
|
||||
void dumpRecursive(int level, QWidget* widget);
|
||||
|
||||
/**
|
||||
* Initializes the visible dock area count variable if it is not initialized
|
||||
* yet
|
||||
*/
|
||||
void initVisibleDockAreaCount()
|
||||
{
|
||||
if (VisibleDockAreaCount > -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
VisibleDockAreaCount = 0;
|
||||
for (auto DockArea : DockAreas)
|
||||
{
|
||||
VisibleDockAreaCount += DockArea->isHidden() ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Access function for the visible dock area counter
|
||||
*/
|
||||
int& visibleDockAreaCount()
|
||||
{
|
||||
// Lazy initialisation - we initialize the VisibleDockAreaCount variable
|
||||
// on first use
|
||||
initVisibleDockAreaCount();
|
||||
return VisibleDockAreaCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* The visible dock area count changes, if dock areas are remove, added or
|
||||
* when its view is toggled
|
||||
*/
|
||||
void onVisibleDockAreaCountChanged();
|
||||
|
||||
void emitDockAreasRemoved()
|
||||
{
|
||||
onVisibleDockAreaCountChanged();
|
||||
emit _this->dockAreasRemoved();
|
||||
}
|
||||
|
||||
void emitDockAreasAdded()
|
||||
{
|
||||
onVisibleDockAreaCountChanged();
|
||||
emit _this->dockAreasAdded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for creation of new splitter
|
||||
*/
|
||||
CDockSplitter* newSplitter(Qt::Orientation orientation, QWidget* parent = 0)
|
||||
{
|
||||
CDockSplitter* s = new CDockSplitter(orientation, parent);
|
||||
s->setOpaqueResize(DockManager->configFlags().testFlag(CDockManager::OpaqueSplitterResize));
|
||||
s->setChildrenCollapsible(false);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
// private slots: ------------------------------------------------------------
|
||||
void onDockAreaViewToggled(bool Visible)
|
||||
{
|
||||
CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(_this->sender());
|
||||
VisibleDockAreaCount += Visible ? 1 : -1;
|
||||
onVisibleDockAreaCountChanged();
|
||||
emit _this->dockAreaViewToggled(DockArea, Visible);
|
||||
}
|
||||
}; // struct DockContainerWidgetPrivate
|
||||
|
||||
|
||||
@@ -165,14 +295,36 @@ DockContainerWidgetPrivate::DockContainerWidgetPrivate(CDockContainerWidget* _pu
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockContainerWidgetPrivate::onVisibleDockAreaCountChanged()
|
||||
{
|
||||
auto TopLevelDockArea = _this->topLevelDockArea();
|
||||
|
||||
if (TopLevelDockArea)
|
||||
{
|
||||
this->TopLevelDockArea = TopLevelDockArea;
|
||||
TopLevelDockArea->titleBarButton(TitleBarButtonUndock)->setVisible(false || !_this->isFloating());
|
||||
TopLevelDockArea->titleBarButton(TitleBarButtonClose)->setVisible(false || !_this->isFloating());
|
||||
}
|
||||
else if (this->TopLevelDockArea)
|
||||
{
|
||||
this->TopLevelDockArea->titleBarButton(TitleBarButtonUndock)->setVisible(true);
|
||||
this->TopLevelDockArea->titleBarButton(TitleBarButtonClose)->setVisible(true);
|
||||
this->TopLevelDockArea = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* FloatingWidget,
|
||||
DockWidgetArea area)
|
||||
{
|
||||
auto InsertParam = internal::dockAreaInsertParameters(area);
|
||||
auto NewDockAreas = FloatingWidget->dockContainer()->findChildren<CDockAreaWidget*>(
|
||||
CDockContainerWidget* FloatingDockContainer = FloatingWidget->dockContainer();
|
||||
auto NewDockAreas = FloatingDockContainer->findChildren<CDockAreaWidget*>(
|
||||
QString(), Qt::FindChildrenRecursively);
|
||||
CDockWidget* DockWidget = FloatingWidget->dockContainer()->findChild<CDockWidget*>();
|
||||
CDockWidget* SingleDroppedDockWidget = FloatingDockContainer->topLevelDockWidget();
|
||||
CDockWidget* SingleDockWidget = _this->topLevelDockWidget();
|
||||
QSplitter* Splitter = RootSplitter;
|
||||
|
||||
if (DockAreas.count() <= 1)
|
||||
@@ -181,7 +333,7 @@ void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* Float
|
||||
}
|
||||
else if (Splitter->orientation() != InsertParam.orientation())
|
||||
{
|
||||
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
||||
QSplitter* NewSplitter = newSplitter(InsertParam.orientation());
|
||||
QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter);
|
||||
NewSplitter->addWidget(Splitter);
|
||||
Splitter = NewSplitter;
|
||||
@@ -189,7 +341,7 @@ void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* Float
|
||||
}
|
||||
|
||||
// Now we can insert the floating widget content into this container
|
||||
auto FloatingSplitter = FloatingWidget->dockContainer()->rootSplitter();
|
||||
auto FloatingSplitter = FloatingDockContainer->rootSplitter();
|
||||
if (FloatingSplitter->count() == 1)
|
||||
{
|
||||
insertWidgetIntoSplitter(Splitter, FloatingSplitter->widget(0), InsertParam.append());
|
||||
@@ -209,30 +361,65 @@ void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* Float
|
||||
RootSplitter = Splitter;
|
||||
addDockAreasToList(NewDockAreas);
|
||||
FloatingWidget->deleteLater();
|
||||
if (DockWidget)
|
||||
CDockWidget::emitTopLevelEventForWidget(SingleDroppedDockWidget, false);
|
||||
CDockWidget::emitTopLevelEventForWidget(SingleDockWidget, false);
|
||||
|
||||
// If we dropped the floating widget into the main dock container that does
|
||||
// not contain any dock widgets, then splitter is invisible and we need to
|
||||
// show it to display the docked widgets
|
||||
if (!Splitter->isVisible())
|
||||
{
|
||||
DockWidget->toggleView(true);
|
||||
Splitter->show();
|
||||
}
|
||||
_this->dumpLayout();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockContainerWidgetPrivate::dropIntoCenterOfSection(
|
||||
CFloatingDockContainer* FloatingWidget, CDockAreaWidget* TargetArea)
|
||||
{
|
||||
CDockContainerWidget* FloatingContainer = FloatingWidget->dockContainer();
|
||||
auto NewDockWidgets = FloatingContainer->dockWidgets();
|
||||
auto TopLevelDockArea = FloatingContainer->topLevelDockArea();
|
||||
int NewCurrentIndex = -1;
|
||||
|
||||
// If the floating widget contains only one single dock are, then the
|
||||
// current dock widget of the dock area will also be the future current
|
||||
// dock widget in the drop area.
|
||||
if (TopLevelDockArea)
|
||||
{
|
||||
NewCurrentIndex = TopLevelDockArea->currentIndex();
|
||||
}
|
||||
|
||||
for (int i = 0; i < NewDockWidgets.count(); ++i)
|
||||
{
|
||||
CDockWidget* DockWidget = NewDockWidgets[i];
|
||||
TargetArea->insertDockWidget(i, DockWidget, false);
|
||||
// If the floating widget contains multiple visible dock areas, then we
|
||||
// simply pick the first visible open dock widget and make it
|
||||
// the current one.
|
||||
if (NewCurrentIndex < 0 && !DockWidget->isClosed())
|
||||
{
|
||||
NewCurrentIndex = i;
|
||||
}
|
||||
}
|
||||
TargetArea->setCurrentIndex(NewCurrentIndex);
|
||||
FloatingWidget->deleteLater();
|
||||
TargetArea->updateTitleBarVisibility();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* FloatingWidget,
|
||||
CDockAreaWidget* TargetArea, DockWidgetArea area)
|
||||
{
|
||||
CDockContainerWidget* FloatingContainer = FloatingWidget->dockContainer();
|
||||
if (area == CenterDockWidgetArea)
|
||||
// Dropping into center means all dock widgets in the dropped floating
|
||||
// widget will become tabs of the drop area
|
||||
if (CenterDockWidgetArea == area)
|
||||
{
|
||||
auto NewDockWidgets = FloatingContainer->findChildren<CDockWidget*>(
|
||||
QString(), Qt::FindChildrenRecursively);
|
||||
for (auto DockWidget : NewDockWidgets)
|
||||
{
|
||||
TargetArea->insertDockWidget(0, DockWidget, false);
|
||||
}
|
||||
TargetArea->setCurrentIndex(0); // make the topmost widget active
|
||||
FloatingWidget->deleteLater();
|
||||
TargetArea->updateDockArea();
|
||||
dropIntoCenterOfSection(FloatingWidget, TargetArea);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -243,48 +430,72 @@ void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* Floatin
|
||||
|
||||
if (!TargetAreaSplitter)
|
||||
{
|
||||
QSplitter* Splitter = internal::newSplitter(InsertParam.orientation());
|
||||
QSplitter* Splitter = newSplitter(InsertParam.orientation());
|
||||
Layout->replaceWidget(TargetArea, Splitter);
|
||||
Splitter->addWidget(TargetArea);
|
||||
TargetAreaSplitter = Splitter;
|
||||
}
|
||||
|
||||
int AreaIndex = TargetAreaSplitter->indexOf(TargetArea);
|
||||
auto Widget = FloatingWidget->dockContainer()->findChild<QWidget*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
auto FloatingSplitter = dynamic_cast<QSplitter*>(Widget);
|
||||
auto FloatingSplitter = qobject_cast<QSplitter*>(Widget);
|
||||
|
||||
if (TargetAreaSplitter->orientation() == InsertParam.orientation())
|
||||
{
|
||||
auto Sizes = TargetAreaSplitter->sizes();
|
||||
int TargetAreaSize = (InsertParam.orientation() == Qt::Horizontal) ? TargetArea->width() : TargetArea->height();
|
||||
bool AdjustSplitterSizes = true;
|
||||
if ((FloatingSplitter->orientation() != InsertParam.orientation()) && FloatingSplitter->count() > 1)
|
||||
{
|
||||
TargetAreaSplitter->insertWidget(AreaIndex + InsertParam.insertOffset(), Widget);
|
||||
}
|
||||
else
|
||||
{
|
||||
AdjustSplitterSizes = (FloatingSplitter->count() == 1);
|
||||
int InsertIndex = AreaIndex + InsertParam.insertOffset();
|
||||
while (FloatingSplitter->count())
|
||||
{
|
||||
TargetAreaSplitter->insertWidget(InsertIndex++, FloatingSplitter->widget(0));
|
||||
}
|
||||
}
|
||||
|
||||
if (AdjustSplitterSizes)
|
||||
{
|
||||
int Size = (TargetAreaSize - TargetAreaSplitter->handleWidth()) / 2;
|
||||
Sizes[AreaIndex] = Size;
|
||||
Sizes.insert(AreaIndex, Size);
|
||||
TargetAreaSplitter->setSizes(Sizes);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
||||
QList<int> NewSplitterSizes;
|
||||
QSplitter* NewSplitter = newSplitter(InsertParam.orientation());
|
||||
int TargetAreaSize = (InsertParam.orientation() == Qt::Horizontal) ? TargetArea->width() : TargetArea->height();
|
||||
bool AdjustSplitterSizes = true;
|
||||
if ((FloatingSplitter->orientation() != InsertParam.orientation()) && FloatingSplitter->count() > 1)
|
||||
{
|
||||
NewSplitter->addWidget(Widget);
|
||||
}
|
||||
else
|
||||
{
|
||||
AdjustSplitterSizes = (FloatingSplitter->count() == 1);
|
||||
while (FloatingSplitter->count())
|
||||
{
|
||||
NewSplitter->addWidget(FloatingSplitter->widget(0));
|
||||
}
|
||||
}
|
||||
|
||||
// Save the sizes before insertion and restore it later to prevent
|
||||
// shrinking of existing area
|
||||
auto Sizes = TargetAreaSplitter->sizes();
|
||||
insertWidgetIntoSplitter(NewSplitter, TargetArea, !InsertParam.append());
|
||||
if (AdjustSplitterSizes)
|
||||
{
|
||||
int Size = TargetAreaSize / 2;
|
||||
NewSplitter->setSizes({Size, Size});
|
||||
}
|
||||
TargetAreaSplitter->insertWidget(AreaIndex, NewSplitter);
|
||||
TargetAreaSplitter->setSizes(Sizes);
|
||||
}
|
||||
|
||||
FloatingWidget->deleteLater();
|
||||
@@ -298,21 +509,40 @@ void DockContainerWidgetPrivate::addDockAreasToList(const QList<CDockAreaWidget*
|
||||
{
|
||||
int CountBefore = DockAreas.count();
|
||||
int NewAreaCount = NewDockAreas.count();
|
||||
DockAreas.append(NewDockAreas);
|
||||
appendDockAreas(NewDockAreas);
|
||||
// If the user dropped a floating widget that contains only one single
|
||||
// visible dock area, then its title bar button TitleBarButtonUndock is
|
||||
// likely hidden. We need to ensure, that it is visible
|
||||
for (auto DockArea : NewDockAreas)
|
||||
{
|
||||
DockArea->titleBarButton(TitleBarButtonUndock)->setVisible(true);
|
||||
DockArea->titleBarButton(TitleBarButtonClose)->setVisible(true);
|
||||
}
|
||||
|
||||
// We need to ensure, that the dock area title bar is visible. The title bar
|
||||
// is invisible, if the dock are is a single dock area in a floating widget.
|
||||
if (1 == CountBefore)
|
||||
{
|
||||
DockAreas.at(0)->updateDockArea();
|
||||
DockAreas.at(0)->updateTitleBarVisibility();
|
||||
}
|
||||
|
||||
if (1 == NewAreaCount)
|
||||
{
|
||||
DockAreas.last()->updateDockArea();
|
||||
DockAreas.last()->updateTitleBarVisibility();
|
||||
}
|
||||
|
||||
emit _this->dockAreasAdded();
|
||||
emitDockAreasAdded();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockContainerWidgetPrivate::appendDockAreas(const QList<CDockAreaWidget*> NewDockAreas)
|
||||
{
|
||||
DockAreas.append(NewDockAreas);
|
||||
for (auto DockArea : NewDockAreas)
|
||||
{
|
||||
_this->connect(DockArea, SIGNAL(viewToggled(bool)), SLOT(onDockAreaViewToggled(bool)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -323,7 +553,7 @@ void DockContainerWidgetPrivate::saveChildNodesState(QXmlStreamWriter& s, QWidge
|
||||
if (Splitter)
|
||||
{
|
||||
s.writeStartElement("Splitter");
|
||||
s.writeAttribute("Orientation", QString::number(Splitter->orientation()));
|
||||
s.writeAttribute("Orientation", (Splitter->orientation() == Qt::Horizontal) ? "-" : "|");
|
||||
s.writeAttribute("Count", QString::number(Splitter->count()));
|
||||
qDebug() << "NodeSplitter orient: " << Splitter->orientation()
|
||||
<< " WidgetCont: " << Splitter->count();
|
||||
@@ -356,8 +586,17 @@ bool DockContainerWidgetPrivate::restoreSplitter(QXmlStreamReader& s,
|
||||
QWidget*& CreatedWidget, bool Testing)
|
||||
{
|
||||
bool Ok;
|
||||
int Orientation = s.attributes().value("Orientation").toInt(&Ok);
|
||||
if (!Ok)
|
||||
QString OrientationStr = s.attributes().value("Orientation").toString();
|
||||
int Orientation;
|
||||
if (OrientationStr.startsWith("-"))
|
||||
{
|
||||
Orientation = Qt::Horizontal;
|
||||
}
|
||||
else if (OrientationStr.startsWith("|"))
|
||||
{
|
||||
Orientation = Qt::Vertical;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -372,7 +611,7 @@ bool DockContainerWidgetPrivate::restoreSplitter(QXmlStreamReader& s,
|
||||
QSplitter* Splitter = nullptr;
|
||||
if (!Testing)
|
||||
{
|
||||
Splitter = internal::newSplitter((Qt::Orientation)Orientation);
|
||||
Splitter = newSplitter((Qt::Orientation)Orientation);
|
||||
}
|
||||
bool Visible = false;
|
||||
QList<int> Sizes;
|
||||
@@ -384,7 +623,7 @@ bool DockContainerWidgetPrivate::restoreSplitter(QXmlStreamReader& s,
|
||||
{
|
||||
Result = restoreSplitter(s, ChildNode, Testing);
|
||||
}
|
||||
else if (s.name() == "DockAreaWidget")
|
||||
else if (s.name() == "Area")
|
||||
{
|
||||
Result = restoreDockArea(s, ChildNode, Testing);
|
||||
}
|
||||
@@ -460,13 +699,10 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
|
||||
return false;
|
||||
}
|
||||
|
||||
int CurrentIndex = s.attributes().value("CurrentIndex").toInt(&Ok);
|
||||
if (!Ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
qDebug() << "Restore NodeDockArea Tabs: " << Tabs << " CurrentIndex: "
|
||||
<< CurrentIndex;
|
||||
|
||||
QString CurrentDockWidget = s.attributes().value("Current").toString();
|
||||
qDebug() << "Restore NodeDockArea Tabs: " << Tabs << " Current: "
|
||||
<< CurrentDockWidget;
|
||||
|
||||
CDockAreaWidget* DockArea = nullptr;
|
||||
if (!Testing)
|
||||
@@ -476,12 +712,12 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
|
||||
|
||||
while (s.readNextStartElement())
|
||||
{
|
||||
if (s.name() != "DockWidget")
|
||||
if (s.name() != "Widget")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto ObjectName = s.attributes().value("ObjectName");
|
||||
auto ObjectName = s.attributes().value("Name");
|
||||
if (ObjectName.isEmpty())
|
||||
{
|
||||
return false;
|
||||
@@ -501,10 +737,12 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
|
||||
}
|
||||
|
||||
qDebug() << "Dock Widget found - parent " << DockWidget->parent();
|
||||
DockArea->addDockWidget(DockWidget);
|
||||
|
||||
// We hide the DockArea here to prevent the short display (the flashing)
|
||||
// of the dock areas during application startup
|
||||
DockArea->hide();
|
||||
DockArea->addDockWidget(DockWidget);
|
||||
DockWidget->setToggleViewActionChecked(!Closed);
|
||||
DockWidget->setClosedState(Closed);
|
||||
DockWidget->setProperty("closed", Closed);
|
||||
DockWidget->setProperty("dirty", false);
|
||||
}
|
||||
@@ -514,15 +752,15 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!DockArea->count())
|
||||
if (!DockArea->dockWidgetsCount())
|
||||
{
|
||||
delete DockArea;
|
||||
DockArea = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
DockArea->setProperty("currentIndex", CurrentIndex);
|
||||
DockAreas.append(DockArea);
|
||||
DockArea->setProperty("currentDockWidget", CurrentDockWidget);
|
||||
appendDockAreas({DockArea});
|
||||
}
|
||||
|
||||
CreatedWidget = DockArea;
|
||||
@@ -542,7 +780,7 @@ bool DockContainerWidgetPrivate::restoreChildNodes(QXmlStreamReader& s,
|
||||
Result = restoreSplitter(s, CreatedWidget, Testing);
|
||||
qDebug() << "Splitter";
|
||||
}
|
||||
else if (s.name() == "DockAreaWidget")
|
||||
else if (s.name() == "Area")
|
||||
{
|
||||
Result = restoreDockArea(s, CreatedWidget, Testing);
|
||||
qDebug() << "DockAreaWidget";
|
||||
@@ -565,6 +803,8 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetA
|
||||
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
|
||||
NewDockArea->addDockWidget(Dockwidget);
|
||||
addDockArea(NewDockArea, area);
|
||||
NewDockArea->updateTitleBarVisibility();
|
||||
LastAddedAreaCache[areaIdToIndex(area)] = NewDockArea;
|
||||
return NewDockArea;
|
||||
}
|
||||
|
||||
@@ -587,7 +827,7 @@ void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockW
|
||||
}
|
||||
else
|
||||
{
|
||||
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
||||
QSplitter* NewSplitter = newSplitter(InsertParam.orientation());
|
||||
if (InsertParam.append())
|
||||
{
|
||||
QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter);
|
||||
@@ -605,9 +845,9 @@ void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockW
|
||||
RootSplitter = NewSplitter;
|
||||
}
|
||||
|
||||
DockAreas.append(NewDockArea);
|
||||
NewDockArea->updateDockArea();
|
||||
emit _this->dockAreasAdded();
|
||||
appendDockAreas({NewDockArea});
|
||||
NewDockArea->updateTitleBarVisibility();
|
||||
emitDockAreasAdded();
|
||||
}
|
||||
|
||||
|
||||
@@ -622,9 +862,13 @@ void DockContainerWidgetPrivate::dumpRecursive(int level, QWidget* widget)
|
||||
{
|
||||
qDebug("%sSplitter %s v: %s c: %s",
|
||||
(const char*)buf,
|
||||
(Splitter->orientation() == Qt::Vertical) ? "-" : "|",
|
||||
Splitter->isVisibleTo(Splitter->parentWidget()) ? "1" : "0",
|
||||
(Splitter->orientation() == Qt::Vertical) ? "--" : "|",
|
||||
Splitter->isHidden() ? " " : "v",
|
||||
QString::number(Splitter->count()).toStdString().c_str());
|
||||
std::cout << (const char*)buf << "Splitter "
|
||||
<< ((Splitter->orientation() == Qt::Vertical) ? "--" : "|") << " "
|
||||
<< (Splitter->isHidden() ? " " : "v") << " "
|
||||
<< QString::number(Splitter->count()).toStdString() << std::endl;
|
||||
for (int i = 0; i < Splitter->count(); ++i)
|
||||
{
|
||||
dumpRecursive(level + 1, Splitter->widget(i));
|
||||
@@ -638,6 +882,19 @@ void DockContainerWidgetPrivate::dumpRecursive(int level, QWidget* widget)
|
||||
return;
|
||||
}
|
||||
qDebug("%sDockArea", (const char*)buf);
|
||||
std::cout << (const char*)buf
|
||||
<< (DockArea->isHidden() ? " " : "v")
|
||||
<< (DockArea->openDockWidgetsCount() > 0 ? " " : "c")
|
||||
<< " DockArea" << std::endl;
|
||||
buf.fill(' ', (level + 1) * 4);
|
||||
for (int i = 0; i < DockArea->dockWidgetsCount(); ++i)
|
||||
{
|
||||
std::cout << (const char*)buf << (i == DockArea->currentIndex() ? "*" : " ");
|
||||
CDockWidget* DockWidget = DockArea->dockWidget(i);
|
||||
std::cout << (DockWidget->isHidden() ? " " : "v");
|
||||
std::cout << (DockWidget->isClosed() ? "c" : " ") << " ";
|
||||
std::cout << DockWidget->windowTitle().toStdString() << std::endl;
|
||||
}
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(level);
|
||||
@@ -670,14 +927,14 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetAr
|
||||
else
|
||||
{
|
||||
qDebug() << "TargetAreaSplitter->orientation() != InsertParam.orientation()";
|
||||
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
||||
QSplitter* NewSplitter = newSplitter(InsertParam.orientation());
|
||||
NewSplitter->addWidget(TargetDockArea);
|
||||
insertWidgetIntoSplitter(NewSplitter, NewDockArea, InsertParam.append());
|
||||
TargetAreaSplitter->insertWidget(index, NewSplitter);
|
||||
}
|
||||
|
||||
DockAreas.append(NewDockArea);
|
||||
emit _this->dockAreasAdded();
|
||||
appendDockAreas({NewDockArea});
|
||||
emitDockAreasAdded();
|
||||
return NewDockArea;
|
||||
}
|
||||
|
||||
@@ -687,22 +944,24 @@ CDockContainerWidget::CDockContainerWidget(CDockManager* DockManager, QWidget *p
|
||||
QFrame(parent),
|
||||
d(new DockContainerWidgetPrivate(this))
|
||||
{
|
||||
d->isFloating = dynamic_cast<CFloatingDockContainer*>(parent) != 0;
|
||||
|
||||
//setStyleSheet("background: green;");
|
||||
d->DockManager = DockManager;
|
||||
if (DockManager != this)
|
||||
{
|
||||
d->DockManager->registerDockContainer(this);
|
||||
}
|
||||
d->isFloating = floatingWidget() != nullptr;
|
||||
|
||||
d->Layout = new QGridLayout();
|
||||
d->Layout->setContentsMargins(0, 1, 0, 1);
|
||||
d->Layout->setSpacing(0);
|
||||
setLayout(d->Layout);
|
||||
|
||||
d->RootSplitter = internal::newSplitter(Qt::Horizontal);
|
||||
d->Layout->addWidget(d->RootSplitter);
|
||||
// The function d->newSplitter() accesses the config flags from dock
|
||||
// manager which in turn requires a properly constructed dock manager.
|
||||
// If this dock container is the dock manager, then it is not properly
|
||||
// constructed yet because this base class constructor is called before
|
||||
// the constructor of the DockManager private class
|
||||
if (DockManager != this)
|
||||
{
|
||||
d->DockManager->registerDockContainer(this);
|
||||
createRootSplitter();
|
||||
}
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
@@ -787,13 +1046,14 @@ void CDockContainerWidget::addDockArea(CDockAreaWidget* DockAreaWidget,
|
||||
void CDockContainerWidget::removeDockArea(CDockAreaWidget* area)
|
||||
{
|
||||
qDebug() << "CDockContainerWidget::removeDockArea";
|
||||
area->disconnect(this);
|
||||
d->DockAreas.removeAll(area);
|
||||
CDockSplitter* Splitter = internal::findParent<CDockSplitter*>(area);
|
||||
|
||||
// Remove are from parent splitter and hide splitter if it has no visible
|
||||
// content
|
||||
// Remove are from parent splitter and recursively hide tree of parent
|
||||
// splitters if it has no visible content
|
||||
area->setParent(0);
|
||||
Splitter->setVisible(Splitter->hasVisibleContent());
|
||||
internal::hideEmptyParentSplitters(Splitter);
|
||||
|
||||
// If splitter has more than 1 widgets, we are finished and can leave
|
||||
if (Splitter->count() > 1)
|
||||
@@ -832,17 +1092,24 @@ void CDockContainerWidget::removeDockArea(CDockAreaWidget* area)
|
||||
else if (Splitter->count() == 1)
|
||||
{
|
||||
qDebug() << "Replacing splitter with content";
|
||||
QSplitter* ParentSplitter = internal::findParent<QSplitter*>(Splitter);
|
||||
auto Sizes = ParentSplitter->sizes();
|
||||
QWidget* widget = Splitter->widget(0);
|
||||
widget->setParent(this);
|
||||
QSplitter* ParentSplitter = internal::findParent<QSplitter*>(Splitter);
|
||||
internal::replaceSplitterWidget(ParentSplitter, Splitter, widget);
|
||||
ParentSplitter->setSizes(Sizes);
|
||||
}
|
||||
|
||||
delete Splitter;
|
||||
|
||||
emitAndExit:
|
||||
CDockWidget* TopLevelWidget = topLevelDockWidget();
|
||||
|
||||
// Updated the title bar visibility of the dock widget if there is only
|
||||
// one single visible dock widget
|
||||
CDockWidget::emitTopLevelEventForWidget(TopLevelWidget, true);
|
||||
dumpLayout();
|
||||
emit dockAreasRemoved();
|
||||
d->emitDockAreasRemoved();
|
||||
}
|
||||
|
||||
|
||||
@@ -885,15 +1152,17 @@ int CDockContainerWidget::dockAreaCount() const
|
||||
//============================================================================
|
||||
int CDockContainerWidget::visibleDockAreaCount() const
|
||||
{
|
||||
// TODO Cache or precalculate this to speed it up because it is used during
|
||||
// movement of floating widget
|
||||
int Result = 0;
|
||||
for (auto DockArea : d->DockAreas)
|
||||
{
|
||||
Result += DockArea->isVisible() ? 1 : 0;
|
||||
Result += DockArea->isHidden() ? 0 : 1;
|
||||
}
|
||||
|
||||
return Result;
|
||||
|
||||
// TODO Cache or precalculate this to speed it up because it is used during
|
||||
// movement of floating widget
|
||||
//return d->visibleDockAreaCount();
|
||||
}
|
||||
|
||||
|
||||
@@ -905,6 +1174,9 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
|
||||
CDockAreaWidget* DockArea = dockAreaAt(TargetPos);
|
||||
auto dropArea = InvalidDockWidgetArea;
|
||||
auto ContainerDropArea = d->DockManager->containerOverlay()->dropAreaUnderCursor();
|
||||
CDockWidget* FloatingTopLevelDockWidget = FloatingWidget->topLevelDockWidget();
|
||||
CDockWidget* TopLevelDockWidget = topLevelDockWidget();
|
||||
|
||||
if (DockArea)
|
||||
{
|
||||
auto dropOverlay = d->DockManager->dockAreaOverlay();
|
||||
@@ -933,6 +1205,20 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
|
||||
d->dropIntoContainer(FloatingWidget, dropArea);
|
||||
}
|
||||
}
|
||||
|
||||
// If there was a top level widget before the drop, then it is not top
|
||||
// level widget anymore
|
||||
if (TopLevelDockWidget)
|
||||
{
|
||||
TopLevelDockWidget->emitTopLevelChanged(false);
|
||||
}
|
||||
|
||||
// If we drop a floating widget with only one single dock widget, then we
|
||||
// drop a top level widget that changes from floating to docked now
|
||||
if (FloatingTopLevelDockWidget)
|
||||
{
|
||||
FloatingTopLevelDockWidget->emitTopLevelChanged(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -942,7 +1228,7 @@ QList<CDockAreaWidget*> CDockContainerWidget::openedDockAreas() const
|
||||
QList<CDockAreaWidget*> Result;
|
||||
for (auto DockArea : d->DockAreas)
|
||||
{
|
||||
if (DockArea->isVisible())
|
||||
if (!DockArea->isHidden())
|
||||
{
|
||||
Result.append(DockArea);
|
||||
}
|
||||
@@ -958,13 +1244,17 @@ void CDockContainerWidget::saveState(QXmlStreamWriter& s) const
|
||||
qDebug() << "CDockContainerWidget::saveState isFloating "
|
||||
<< isFloating();
|
||||
|
||||
s.writeStartElement("DockContainerWidget");
|
||||
s.writeStartElement("Container");
|
||||
s.writeAttribute("Floating", QString::number(isFloating() ? 1 : 0));
|
||||
if (isFloating())
|
||||
{
|
||||
CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(this);
|
||||
CFloatingDockContainer* FloatingWidget = floatingWidget();
|
||||
QByteArray Geometry = FloatingWidget->saveGeometry();
|
||||
#if QT_VERSION < 0x050900
|
||||
s.writeTextElement("Geometry", qByteArrayToHex(Geometry, ' '));
|
||||
#else
|
||||
s.writeTextElement("Geometry", Geometry.toHex(' '));
|
||||
#endif
|
||||
}
|
||||
d->saveChildNodesState(s, d->RootSplitter);
|
||||
s.writeEndElement();
|
||||
@@ -980,6 +1270,7 @@ bool CDockContainerWidget::restoreState(QXmlStreamReader& s, bool Testing)
|
||||
QWidget*NewRootSplitter {};
|
||||
if (!Testing)
|
||||
{
|
||||
d->VisibleDockAreaCount = -1;// invalidate the dock area count
|
||||
d->DockAreas.clear();
|
||||
}
|
||||
|
||||
@@ -1000,7 +1291,7 @@ bool CDockContainerWidget::restoreState(QXmlStreamReader& s, bool Testing)
|
||||
|
||||
if (!Testing)
|
||||
{
|
||||
CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(this);
|
||||
CFloatingDockContainer* FloatingWidget = floatingWidget();
|
||||
FloatingWidget->restoreGeometry(Geometry);
|
||||
}
|
||||
}
|
||||
@@ -1019,7 +1310,7 @@ bool CDockContainerWidget::restoreState(QXmlStreamReader& s, bool Testing)
|
||||
// and we need to create a new empty root splitter
|
||||
if (!NewRootSplitter)
|
||||
{
|
||||
NewRootSplitter = internal::newSplitter(Qt::Horizontal);
|
||||
NewRootSplitter = d->newSplitter(Qt::Horizontal);
|
||||
}
|
||||
|
||||
d->Layout->replaceWidget(d->RootSplitter, NewRootSplitter);
|
||||
@@ -1038,16 +1329,142 @@ QSplitter* CDockContainerWidget::rootSplitter() const
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockContainerWidget::createRootSplitter()
|
||||
{
|
||||
if (d->RootSplitter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
d->RootSplitter = d->newSplitter(Qt::Horizontal);
|
||||
d->Layout->addWidget(d->RootSplitter);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockContainerWidget::dumpLayout()
|
||||
{
|
||||
#if (ADS_DEBUG_LEVEL > 0)
|
||||
qDebug("\n\nDumping layout --------------------------");
|
||||
std::cout << "\n\nDumping layout --------------------------" << std::endl;
|
||||
d->dumpRecursive(0, d->RootSplitter);
|
||||
qDebug("--------------------------\n\n");
|
||||
std::cout << "--------------------------\n\n" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockAreaWidget* CDockContainerWidget::lastAddedDockAreaWidget(DockWidgetArea area) const
|
||||
{
|
||||
return d->LastAddedAreaCache[areaIdToIndex(area)];
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
bool CDockContainerWidget::hasTopLevelDockWidget() const
|
||||
{
|
||||
if (!isFloating())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto DockAreas = openedDockAreas();
|
||||
if (DockAreas.count() != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return DockAreas[0]->openDockWidgetsCount() == 1;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockWidget* CDockContainerWidget::topLevelDockWidget() const
|
||||
{
|
||||
auto TopLevelDockArea = topLevelDockArea();
|
||||
if (!TopLevelDockArea)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto DockWidgets = TopLevelDockArea->openedDockWidgets();
|
||||
if (DockWidgets.count() != 1)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return DockWidgets[0];
|
||||
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockAreaWidget* CDockContainerWidget::topLevelDockArea() const
|
||||
{
|
||||
if (!isFloating())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto DockAreas = openedDockAreas();
|
||||
if (DockAreas.count() != 1)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return DockAreas[0];
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QList<CDockWidget*> CDockContainerWidget::dockWidgets() const
|
||||
{
|
||||
QList<CDockWidget*> Result;
|
||||
for (const auto DockArea : d->DockAreas)
|
||||
{
|
||||
Result.append(DockArea->dockWidgets());
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockWidget::DockWidgetFeatures CDockContainerWidget::features() const
|
||||
{
|
||||
CDockWidget::DockWidgetFeatures Features(CDockWidget::AllDockWidgetFeatures);
|
||||
for (const auto DockArea : d->DockAreas)
|
||||
{
|
||||
Features &= DockArea->features();
|
||||
}
|
||||
|
||||
return Features;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CFloatingDockContainer* CDockContainerWidget::floatingWidget() const
|
||||
{
|
||||
return internal::findParent<CFloatingDockContainer*>(this);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockContainerWidget::closeOtherAreas(CDockAreaWidget* KeepOpenArea)
|
||||
{
|
||||
for (const auto DockArea : d->DockAreas)
|
||||
{
|
||||
if (DockArea != KeepOpenArea && DockArea->features().testFlag(CDockWidget::DockWidgetClosable))
|
||||
{
|
||||
DockArea->closeArea();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace ads
|
||||
|
||||
#include "moc_DockContainerWidget.cpp"
|
||||
//---------------------------------------------------------------------------
|
||||
// EOF DockContainerWidget.cpp
|
||||
|
||||
@@ -33,14 +33,14 @@
|
||||
#include <QFrame>
|
||||
|
||||
#include "ads_globals.h"
|
||||
|
||||
#include "DockWidget.h"
|
||||
|
||||
class QXmlStreamWriter;
|
||||
class QXmlStreamReader;
|
||||
|
||||
namespace ads
|
||||
{
|
||||
struct DockContainerWidgetPrivate;
|
||||
class DockContainerWidgetPrivate;
|
||||
class CDockAreaWidget;
|
||||
class CDockWidget;
|
||||
class CDockManager;
|
||||
@@ -57,12 +57,15 @@ class ADS_EXPORT CDockContainerWidget : public QFrame
|
||||
Q_OBJECT
|
||||
private:
|
||||
DockContainerWidgetPrivate* d; ///< private data (pimpl)
|
||||
friend struct DockContainerWidgetPrivate;
|
||||
friend class DockContainerWidgetPrivate;
|
||||
friend class CDockManager;
|
||||
friend struct DockManagerPrivate;
|
||||
friend class CDockAreaWidget;
|
||||
friend struct DockAreaWidgetPrivate;
|
||||
friend class CFloatingDockContainer;
|
||||
friend struct FloatingDockContainerPrivate;
|
||||
friend class CDockWidget;
|
||||
Q_PRIVATE_SLOT(d, void onDockAreaViewToggled(bool Visible))
|
||||
|
||||
protected:
|
||||
/**
|
||||
@@ -75,6 +78,11 @@ protected:
|
||||
*/
|
||||
QSplitter* rootSplitter() const;
|
||||
|
||||
/**
|
||||
* Helper function for creation of the root splitter
|
||||
*/
|
||||
void createRootSplitter();
|
||||
|
||||
/**
|
||||
* Drop floating widget into the container
|
||||
*/
|
||||
@@ -103,6 +111,42 @@ protected:
|
||||
*/
|
||||
bool restoreState(QXmlStreamReader& Stream, bool Testing);
|
||||
|
||||
/**
|
||||
* This function returns the last added dock area widget for the given
|
||||
* area identifier or 0 if no dock area widget has been added for the given
|
||||
* area
|
||||
*/
|
||||
CDockAreaWidget* lastAddedDockAreaWidget(DockWidgetArea area) const;
|
||||
|
||||
/**
|
||||
* This function returns true if this dock area has only one single
|
||||
* visible dock widget.
|
||||
* A top level widget is a real floating widget. Only the isFloating()
|
||||
* function of top level widgets may returns true.
|
||||
*/
|
||||
bool hasTopLevelDockWidget() const;
|
||||
|
||||
/**
|
||||
* If hasSingleVisibleDockWidget() returns true, this function returns the
|
||||
* one and only visible dock widget. Otherwise it returns a nullptr.
|
||||
*/
|
||||
CDockWidget* topLevelDockWidget() const;
|
||||
|
||||
/**
|
||||
* Returns the top level dock area.
|
||||
*/
|
||||
CDockAreaWidget* topLevelDockArea() const;
|
||||
|
||||
/**
|
||||
* This function returns a list of all dock widgets in this floating widget.
|
||||
* It may be possible, depending on the implementation, that dock widgets,
|
||||
* that are not visible to the user have no parent widget. Therefore simply
|
||||
* calling findChildren() would not work here. Therefore this function
|
||||
* iterates over all dock areas and creates a list that contains all
|
||||
* dock widgets returned from all dock areas.
|
||||
*/
|
||||
QList<CDockWidget*> dockWidgets() const;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default Constructor
|
||||
@@ -173,6 +217,27 @@ public:
|
||||
*/
|
||||
void dumpLayout();
|
||||
|
||||
/**
|
||||
* This functions returns the dock widget features of all dock widget in
|
||||
* this container.
|
||||
* A bitwise and is used to combine the flags of all dock widgets. That
|
||||
* means, if only dock widget does not support a certain flag, the whole
|
||||
* dock are does not support the flag.
|
||||
*/
|
||||
CDockWidget::DockWidgetFeatures features() const;
|
||||
|
||||
/**
|
||||
* If this dock container is in a floating widget, this function returns
|
||||
* the floating widget.
|
||||
* Else, it returns a nullptr.
|
||||
*/
|
||||
CFloatingDockContainer* floatingWidget() const;
|
||||
|
||||
/**
|
||||
* Call this function to close all dock areas except the KeepOpenArea
|
||||
*/
|
||||
void closeOtherAreas(CDockAreaWidget* KeepOpenArea);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* This signal is emitted if one or multiple dock areas has been added to
|
||||
@@ -185,6 +250,12 @@ signals:
|
||||
* This signal is emitted if one or multiple dock areas has been removed
|
||||
*/
|
||||
void dockAreasRemoved();
|
||||
|
||||
/**
|
||||
* This signal is emitted if a dock area is opened or closed via
|
||||
* toggleView() function
|
||||
*/
|
||||
void dockAreaViewToggled(CDockAreaWidget* DockArea, bool Open);
|
||||
}; // class DockContainerWidget
|
||||
} // namespace ads
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <DockWidgetTab.h>
|
||||
#include "DockManager.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
#include <QMainWindow>
|
||||
@@ -39,19 +40,20 @@
|
||||
#include <QVariant>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QApplication>
|
||||
#include <QAction>
|
||||
#include <QXmlStreamWriter>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QSettings>
|
||||
#include <QMenu>
|
||||
#include <QApplication>
|
||||
|
||||
#include "FloatingDockContainer.h"
|
||||
#include "DockOverlay.h"
|
||||
#include "DockWidget.h"
|
||||
#include "ads_globals.h"
|
||||
#include "DockStateSerialization.h"
|
||||
#include "DockAreaWidget.h"
|
||||
|
||||
|
||||
namespace ads
|
||||
{
|
||||
/**
|
||||
@@ -66,6 +68,11 @@ struct DockManagerPrivate
|
||||
CDockOverlay* DockAreaOverlay;
|
||||
QMap<QString, CDockWidget*> DockWidgetsMap;
|
||||
QMap<QString, QByteArray> Perspectives;
|
||||
QMap<QString, QMenu*> ViewMenuGroups;
|
||||
QMenu* ViewMenu;
|
||||
CDockManager::eViewMenuInsertionOrder MenuInsertionOrder = CDockManager::MenuAlphabeticallySorted;
|
||||
bool RestoringState = false;
|
||||
CDockManager::ConfigFlags ConfigFlags{CDockManager::DefaultConfig};
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@@ -81,7 +88,33 @@ struct DockManagerPrivate
|
||||
/**
|
||||
* Restores the state
|
||||
*/
|
||||
bool restoreState(const QByteArray &state, int version, bool Testing = internal::Restore);
|
||||
bool restoreStateFromXml(const QByteArray &state, int version, bool Testing = internal::Restore);
|
||||
|
||||
/**
|
||||
* Restore state
|
||||
*/
|
||||
bool restoreState(const QByteArray &state, int version);
|
||||
|
||||
void restoreDockWidgetsOpenState();
|
||||
void restoreDockAreasIndices();
|
||||
void emitTopLevelEvents();
|
||||
|
||||
void hideFloatingWidgets()
|
||||
{
|
||||
// Hide updates of floating widgets from use
|
||||
for (auto FloatingWidget : FloatingWidgets)
|
||||
{
|
||||
FloatingWidget->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void markDockWidgetsDirty()
|
||||
{
|
||||
for (auto DockWidget : DockWidgetsMap)
|
||||
{
|
||||
DockWidget->setProperty("dirty", true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the container with the given index
|
||||
@@ -92,6 +125,11 @@ struct DockManagerPrivate
|
||||
* Loads the stylesheet
|
||||
*/
|
||||
void loadStylesheet();
|
||||
|
||||
/**
|
||||
* Adds action to menu - optionally in sorted order
|
||||
*/
|
||||
void addActionToMenu(QAction* Action, QMenu* Menu, bool InsertSorted);
|
||||
};
|
||||
// struct DockManagerPrivate
|
||||
|
||||
@@ -124,28 +162,39 @@ bool DockManagerPrivate::restoreContainer(int Index, QXmlStreamReader& stream, b
|
||||
Index = 0;
|
||||
}
|
||||
|
||||
bool Result = false;
|
||||
if (Index >= Containers.count())
|
||||
{
|
||||
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(_this);
|
||||
return FloatingWidget->restoreState(stream, Testing);
|
||||
Result = FloatingWidget->restoreState(stream, Testing);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "d->Containers[i]->restoreState ";
|
||||
return Containers[Index]->restoreState(stream, Testing);
|
||||
auto Container = Containers[Index];
|
||||
if (Container->isFloating())
|
||||
{
|
||||
Result = Container->floatingWidget()->restoreState(stream, Testing);
|
||||
}
|
||||
else
|
||||
{
|
||||
Result = Container->restoreState(stream, Testing);
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
bool DockManagerPrivate::checkFormat(const QByteArray &state, int version)
|
||||
{
|
||||
return restoreState(state, version, internal::RestoreTesting);
|
||||
return restoreStateFromXml(state, version, internal::RestoreTesting);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
bool DockManagerPrivate::restoreState(const QByteArray &state, int version,
|
||||
bool DockManagerPrivate::restoreStateFromXml(const QByteArray &state, int version,
|
||||
bool Testing)
|
||||
{
|
||||
if (state.isEmpty())
|
||||
@@ -167,12 +216,12 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version,
|
||||
}
|
||||
|
||||
bool Result = true;
|
||||
int DockContainers = s.attributes().value("DockContainers").toInt();
|
||||
int DockContainers = s.attributes().value("Containers").toInt();
|
||||
qDebug() << DockContainers;
|
||||
int DockContainerCount = 0;
|
||||
while (s.readNextStartElement())
|
||||
{
|
||||
if (s.name() == "DockContainerWidget")
|
||||
if (s.name() == "Container")
|
||||
{
|
||||
Result = restoreContainer(DockContainerCount, s, Testing);
|
||||
if (!Result)
|
||||
@@ -191,6 +240,7 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version,
|
||||
for (int i = 0; i < DeleteCount; ++i)
|
||||
{
|
||||
FloatingWidgets[FloatingWidgetIndex + i]->deleteLater();
|
||||
_this->removeDockContainer(FloatingWidgets[FloatingWidgetIndex + i]->dockContainer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,17 +248,161 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version,
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockManagerPrivate::restoreDockWidgetsOpenState()
|
||||
{
|
||||
// All dock widgets, that have not been processed in the restore state
|
||||
// function are invisible to the user now and have no assigned dock area
|
||||
// They do not belong to any dock container, until the user toggles the
|
||||
// toggle view action the next time
|
||||
for (auto DockWidget : DockWidgetsMap)
|
||||
{
|
||||
if (DockWidget->property("dirty").toBool())
|
||||
{
|
||||
DockWidget->flagAsUnassigned();
|
||||
}
|
||||
else
|
||||
{
|
||||
DockWidget->toggleViewInternal(!DockWidget->property("closed").toBool());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockManagerPrivate::restoreDockAreasIndices()
|
||||
{
|
||||
// Now all dock areas are properly restored and we setup the index of
|
||||
// The dock areas because the previous toggleView() action has changed
|
||||
// the dock area index
|
||||
int Count = 0;
|
||||
for (auto DockContainer : Containers)
|
||||
{
|
||||
Count++;
|
||||
for (int i = 0; i < DockContainer->dockAreaCount(); ++i)
|
||||
{
|
||||
CDockAreaWidget* DockArea = DockContainer->dockArea(i);
|
||||
QString DockWidgetName = DockArea->property("currentDockWidget").toString();
|
||||
CDockWidget* DockWidget = nullptr;
|
||||
if (!DockWidgetName.isEmpty())
|
||||
{
|
||||
DockWidget = _this->findDockWidget(DockWidgetName);
|
||||
}
|
||||
|
||||
if (!DockWidget || DockWidget->isClosed())
|
||||
{
|
||||
int Index = DockArea->indexOfFirstOpenDockWidget();
|
||||
if (Index < 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
DockArea->setCurrentIndex(Index);
|
||||
}
|
||||
else
|
||||
{
|
||||
DockArea->internalSetCurrentDockWidget(DockWidget);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockManagerPrivate::emitTopLevelEvents()
|
||||
{
|
||||
// Finally we need to send the topLevelChanged() signals for all dock
|
||||
// widgets if top level changed
|
||||
for (auto DockContainer : Containers)
|
||||
{
|
||||
CDockWidget* TopLevelDockWidget = DockContainer->topLevelDockWidget();
|
||||
if (TopLevelDockWidget)
|
||||
{
|
||||
TopLevelDockWidget->emitTopLevelChanged(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < DockContainer->dockAreaCount(); ++i)
|
||||
{
|
||||
auto DockArea = DockContainer->dockArea(i);
|
||||
for (auto DockWidget : DockArea->dockWidgets())
|
||||
{
|
||||
DockWidget->emitTopLevelChanged(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
|
||||
{
|
||||
if (!checkFormat(state, version))
|
||||
{
|
||||
qDebug() << "checkFormat: Error checking format!!!!!!!";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Hide updates of floating widgets from use
|
||||
hideFloatingWidgets();
|
||||
markDockWidgetsDirty();
|
||||
|
||||
if (!restoreStateFromXml(state, version))
|
||||
{
|
||||
qDebug() << "restoreState: Error restoring state!!!!!!!";
|
||||
return false;
|
||||
}
|
||||
|
||||
restoreDockWidgetsOpenState();
|
||||
restoreDockAreasIndices();
|
||||
emitTopLevelEvents();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockManagerPrivate::addActionToMenu(QAction* Action, QMenu* Menu, bool InsertSorted)
|
||||
{
|
||||
if (InsertSorted)
|
||||
{
|
||||
auto Actions = Menu->actions();
|
||||
auto it = std::find_if(Actions.begin(), Actions.end(),
|
||||
[&Action](const QAction* a)
|
||||
{
|
||||
return a->text().compare(Action->text(), Qt::CaseInsensitive) > 0;
|
||||
});
|
||||
|
||||
if (it == Actions.end())
|
||||
{
|
||||
Menu->addAction(Action);
|
||||
}
|
||||
else
|
||||
{
|
||||
Menu->insertAction(*it, Action);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Menu->addAction(Action);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockManager::CDockManager(QWidget *parent) :
|
||||
CDockContainerWidget(this, parent),
|
||||
d(new DockManagerPrivate(this))
|
||||
{
|
||||
createRootSplitter();
|
||||
QMainWindow* MainWindow = dynamic_cast<QMainWindow*>(parent);
|
||||
if (MainWindow)
|
||||
{
|
||||
MainWindow->setCentralWidget(this);
|
||||
}
|
||||
|
||||
d->ViewMenu = new QMenu(tr("Show View"), this);
|
||||
d->DockAreaOverlay = new CDockOverlay(this, CDockOverlay::ModeDockAreaOverlay);
|
||||
d->ContainerOverlay = new CDockOverlay(this, CDockOverlay::ModeContainerOverlay);
|
||||
d->Containers.append(this);
|
||||
@@ -295,15 +489,15 @@ unsigned int CDockManager::zOrderIndex() const
|
||||
|
||||
|
||||
//============================================================================
|
||||
QByteArray CDockManager::saveState(int version) const
|
||||
QByteArray CDockManager::saveState(eXmlMode XmlMode, int version) const
|
||||
{
|
||||
QByteArray xmldata;
|
||||
QXmlStreamWriter s(&xmldata);
|
||||
s.setAutoFormatting(true);
|
||||
s.setAutoFormatting(XmlAutoFormattingEnabled == XmlMode);
|
||||
s.writeStartDocument();
|
||||
s.writeStartElement("QtAdvancedDockingSystem");
|
||||
s.writeAttribute("Version", QString::number(version));
|
||||
s.writeAttribute("DockContainers", QString::number(d->Containers.count()));
|
||||
s.writeAttribute("Containers", QString::number(d->Containers.count()));
|
||||
for (auto Container : d->Containers)
|
||||
{
|
||||
Container->saveState(s);
|
||||
@@ -319,57 +513,37 @@ QByteArray CDockManager::saveState(int version) const
|
||||
//============================================================================
|
||||
bool CDockManager::restoreState(const QByteArray &state, int version)
|
||||
{
|
||||
if (!d->checkFormat(state, version))
|
||||
{
|
||||
qDebug() << "checkFormat: Error checking format!!!!!!!";
|
||||
return false;
|
||||
}
|
||||
// Prevent multiple calls as long as state is not restore. This may
|
||||
// happen, if QApplication::processEvents() is called somewhere
|
||||
if (d->RestoringState)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto DockWidget : d->DockWidgetsMap)
|
||||
{
|
||||
DockWidget->setProperty("dirty", true);
|
||||
}
|
||||
// We hide the complete dock manager here. Restoring the state means
|
||||
// that DockWidgets are removed from the DockArea internal stack layout
|
||||
// which in turn means, that each time a widget is removed the stack
|
||||
// will show and raise the next available widget which in turn
|
||||
// triggers show events for the dock widgets. To avoid this we hide the
|
||||
// dock manager. Because there will be no processing of application
|
||||
// events until this function is finished, the user will not see this
|
||||
// hiding
|
||||
bool IsHidden = this->isHidden();
|
||||
if (!IsHidden)
|
||||
{
|
||||
hide();
|
||||
}
|
||||
d->RestoringState = true;
|
||||
emit restoringState();
|
||||
bool Result = d->restoreState(state, version);
|
||||
d->RestoringState = false;
|
||||
emit stateRestored();
|
||||
if (!IsHidden)
|
||||
{
|
||||
show();
|
||||
}
|
||||
|
||||
if (!d->restoreState(state, version))
|
||||
{
|
||||
qDebug() << "restoreState: Error restoring state!!!!!!!";
|
||||
return false;
|
||||
}
|
||||
|
||||
// All dock widgets, that have not been processed in the restore state
|
||||
// function are invisible to the user now and have no assigned dock area
|
||||
// They do not belong to any dock container, until the user toggles the
|
||||
// toggle view action the next time
|
||||
for (auto DockWidget : d->DockWidgetsMap)
|
||||
{
|
||||
if (DockWidget->property("dirty").toBool())
|
||||
{
|
||||
DockWidget->flagAsUnassigned();
|
||||
}
|
||||
else
|
||||
{
|
||||
DockWidget->toggleView(!DockWidget->property("closed").toBool());
|
||||
}
|
||||
}
|
||||
|
||||
// Now all dock areas are properly restored and we setup the index of
|
||||
// The dock areas because the previous toggleView() action has changed
|
||||
// the dock area index
|
||||
for (auto DockContainer : d->Containers)
|
||||
{
|
||||
for (int i = 0; i < DockContainer->dockAreaCount(); ++i)
|
||||
{
|
||||
CDockAreaWidget* DockArea = DockContainer->dockArea(i);
|
||||
int CurrentIndex = DockArea->property("currentIndex").toInt();
|
||||
if (CurrentIndex < DockArea->count() && DockArea->count() > 1 && CurrentIndex > -1)
|
||||
{
|
||||
DockArea->setCurrentIndex(CurrentIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
emit stateChanged();
|
||||
return true;
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
||||
@@ -383,12 +557,43 @@ CDockAreaWidget* CDockManager::addDockWidget(DockWidgetArea area,
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockWidget* CDockManager::findDockWidget(const QString& ObjectName)
|
||||
CDockAreaWidget* CDockManager::addDockWidgetTab(DockWidgetArea area,
|
||||
CDockWidget* Dockwidget)
|
||||
{
|
||||
CDockAreaWidget* AreaWidget = lastAddedDockAreaWidget(area);
|
||||
if (AreaWidget)
|
||||
{
|
||||
return addDockWidget(ads::CenterDockWidgetArea, Dockwidget, AreaWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
return addDockWidget(area, Dockwidget, AreaWidget);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockAreaWidget* CDockManager::addDockWidgetTabToArea(CDockWidget* Dockwidget,
|
||||
CDockAreaWidget* DockAreaWidget)
|
||||
{
|
||||
return addDockWidget(ads::CenterDockWidgetArea, Dockwidget, DockAreaWidget);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockWidget* CDockManager::findDockWidget(const QString& ObjectName) const
|
||||
{
|
||||
return d->DockWidgetsMap.value(ObjectName, nullptr);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QMap<QString, CDockWidget*> CDockManager::dockWidgetsMap() const
|
||||
{
|
||||
return d->DockWidgetsMap;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockManager::addPerspective(const QString& UniquePrespectiveName)
|
||||
{
|
||||
@@ -397,6 +602,30 @@ void CDockManager::addPerspective(const QString& UniquePrespectiveName)
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockManager::removePerspective(const QString& Name)
|
||||
{
|
||||
removePerspectives({Name});
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockManager::removePerspectives(const QStringList& Names)
|
||||
{
|
||||
int Count = 0;
|
||||
for (auto Name : Names)
|
||||
{
|
||||
Count += d->Perspectives.remove(Name);
|
||||
}
|
||||
|
||||
if (Count)
|
||||
{
|
||||
emit perspectivesRemoved();
|
||||
emit perspectiveListChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QStringList CDockManager::perspectiveNames() const
|
||||
{
|
||||
@@ -413,7 +642,9 @@ void CDockManager::openPerspective(const QString& PerspectiveName)
|
||||
return;
|
||||
}
|
||||
|
||||
emit openingPerspective(PerspectiveName);
|
||||
restoreState(Iterator.value());
|
||||
emit perspectiveOpened(PerspectiveName);
|
||||
}
|
||||
|
||||
|
||||
@@ -459,6 +690,76 @@ void CDockManager::loadPerspectives(QSettings& Settings)
|
||||
|
||||
Settings.endArray();
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
QAction* CDockManager::addToggleViewActionToMenu(QAction* ToggleViewAction,
|
||||
const QString& Group, const QIcon& GroupIcon)
|
||||
{
|
||||
bool AlphabeticallySorted = (MenuAlphabeticallySorted == d->MenuInsertionOrder);
|
||||
if (!Group.isEmpty())
|
||||
{
|
||||
QMenu* GroupMenu = d->ViewMenuGroups.value(Group, 0);
|
||||
if (!GroupMenu)
|
||||
{
|
||||
GroupMenu = new QMenu(Group, this);
|
||||
GroupMenu->setIcon(GroupIcon);
|
||||
d->addActionToMenu(GroupMenu->menuAction(), d->ViewMenu, AlphabeticallySorted);
|
||||
d->ViewMenuGroups.insert(Group, GroupMenu);
|
||||
}
|
||||
|
||||
d->addActionToMenu(ToggleViewAction, GroupMenu, AlphabeticallySorted);
|
||||
return GroupMenu->menuAction();
|
||||
}
|
||||
else
|
||||
{
|
||||
d->addActionToMenu(ToggleViewAction, d->ViewMenu, AlphabeticallySorted);
|
||||
return ToggleViewAction;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QMenu* CDockManager::viewMenu() const
|
||||
{
|
||||
return d->ViewMenu;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockManager::setViewMenuInsertionOrder(eViewMenuInsertionOrder Order)
|
||||
{
|
||||
d->MenuInsertionOrder = Order;
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
bool CDockManager::isRestoringState() const
|
||||
{
|
||||
return d->RestoringState;
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
int CDockManager::startDragDistance()
|
||||
{
|
||||
return QApplication::startDragDistance() * 1.5;
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
CDockManager::ConfigFlags CDockManager::configFlags() const
|
||||
{
|
||||
return d->ConfigFlags;
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
void CDockManager::setConfigFlags(const ConfigFlags Flags)
|
||||
{
|
||||
d->ConfigFlags = Flags;
|
||||
}
|
||||
|
||||
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -31,10 +31,12 @@
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include "DockContainerWidget.h"
|
||||
#include <QIcon>
|
||||
|
||||
#include "ads_globals.h"
|
||||
|
||||
class QSettings;
|
||||
class QMenu;
|
||||
|
||||
namespace ads
|
||||
{
|
||||
@@ -100,10 +102,38 @@ protected:
|
||||
CDockOverlay* dockAreaOverlay() const;
|
||||
|
||||
public:
|
||||
enum eViewMenuInsertionOrder
|
||||
{
|
||||
MenuSortedByInsertion,
|
||||
MenuAlphabeticallySorted
|
||||
};
|
||||
|
||||
enum eXmlMode
|
||||
{
|
||||
XmlAutoFormattingDisabled,
|
||||
XmlAutoFormattingEnabled
|
||||
};
|
||||
|
||||
/**
|
||||
* These global configuration flags configure some global dock manager
|
||||
* settings.
|
||||
*/
|
||||
enum eConfigFlag
|
||||
{
|
||||
ActiveTabHasCloseButton = 0x01, //!< If this flag is set, the active tab in a tab area has a close button
|
||||
DockAreaHasCloseButton = 0x02, //!< If the flag is set each dock area has a close button
|
||||
DockAreaCloseButtonClosesTab = 0x04,//!< If the flag is set, the dock area close button closes the active tab, if not set, it closes the complete cock area
|
||||
OpaqueSplitterResize = 0x08, //!< See QSplitter::setOpaqueResize() documentation
|
||||
DefaultConfig = ActiveTabHasCloseButton | DockAreaHasCloseButton | OpaqueSplitterResize, ///< the default configuration
|
||||
};
|
||||
Q_DECLARE_FLAGS(ConfigFlags, eConfigFlag)
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
* If the given parent is a QMainWindow, the dock manager sets itself as the
|
||||
* central widget
|
||||
* central widget.
|
||||
* Before you create any dock widgets, you should properly setup the
|
||||
* configuration flags via setConfigFlags()
|
||||
*/
|
||||
CDockManager(QWidget* parent = 0);
|
||||
|
||||
@@ -112,6 +142,17 @@ public:
|
||||
*/
|
||||
virtual ~CDockManager();
|
||||
|
||||
/**
|
||||
* This function returns the global configuration flags
|
||||
*/
|
||||
ConfigFlags configFlags() const;
|
||||
|
||||
/**
|
||||
* Sets the global configuration flags for the whole docking system.
|
||||
* Call this function before you create your first dock widget.
|
||||
*/
|
||||
void setConfigFlags(const ConfigFlags Flags);
|
||||
|
||||
/**
|
||||
* Adds dockwidget into the given area.
|
||||
* If DockAreaWidget is not null, then the area parameter indicates the area
|
||||
@@ -128,12 +169,34 @@ public:
|
||||
CDockAreaWidget* addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget,
|
||||
CDockAreaWidget* DockAreaWidget = nullptr);
|
||||
|
||||
/**
|
||||
* This function will add the given Dockwidget to the given dock area as
|
||||
* a new tab.
|
||||
* If no dock area widget exists for the given area identifier, a new
|
||||
* dock area widget is created.
|
||||
*/
|
||||
CDockAreaWidget* addDockWidgetTab(DockWidgetArea area,
|
||||
CDockWidget* Dockwidget);
|
||||
|
||||
/**
|
||||
* This function will add the given Dockwidget to the given DockAreaWidget
|
||||
* as a new tab.
|
||||
*/
|
||||
CDockAreaWidget* addDockWidgetTabToArea(CDockWidget* Dockwidget,
|
||||
CDockAreaWidget* DockAreaWidget);
|
||||
|
||||
/**
|
||||
* Searches for a registered doc widget with the given ObjectName
|
||||
* \return Return the found dock widget or nullptr if a dock widget with the
|
||||
* given name is not registered
|
||||
*/
|
||||
CDockWidget* findDockWidget(const QString& ObjectName);
|
||||
CDockWidget* findDockWidget(const QString& ObjectName) const;
|
||||
|
||||
/**
|
||||
* This function returns a readable reference to the internal dock
|
||||
* widgets map so that it is possible to iterate over all dock widgets
|
||||
*/
|
||||
QMap<QString, CDockWidget*> dockWidgetsMap() const;
|
||||
|
||||
/**
|
||||
* Returns the list of all active and visible dock containers
|
||||
@@ -154,9 +217,13 @@ public:
|
||||
|
||||
/**
|
||||
* Saves the current state of the dockmanger and all its dock widgets
|
||||
* into the returned QByteArray
|
||||
* into the returned QByteArray.
|
||||
* The XmlMode enables / disables the auto formatting for the XmlStreamWriter.
|
||||
* If auto formatting is enabled, the output is intended and line wrapped.
|
||||
* The XmlMode XmlAutoFormattingDisabled is better if you would like to have
|
||||
* a more compact XML output - i.e. for storage in ini files.
|
||||
*/
|
||||
QByteArray saveState(int version = 0) const;
|
||||
QByteArray saveState(eXmlMode XmlMode = XmlAutoFormattingDisabled, int version = 0) const;
|
||||
|
||||
/**
|
||||
* Restores the state of this dockmanagers dockwidgets.
|
||||
@@ -177,6 +244,16 @@ public:
|
||||
*/
|
||||
void addPerspective(const QString& UniquePrespectiveName);
|
||||
|
||||
/**
|
||||
* Removes the perspective with the given name from the list of perspectives
|
||||
*/
|
||||
void removePerspective(const QString& Name);
|
||||
|
||||
/**
|
||||
* Removes the given perspectives from the dock manager
|
||||
*/
|
||||
void removePerspectives(const QStringList& Names);
|
||||
|
||||
/**
|
||||
* Returns the names of all available perspectives
|
||||
*/
|
||||
@@ -192,6 +269,56 @@ public:
|
||||
*/
|
||||
void loadPerspectives(QSettings& Settings);
|
||||
|
||||
/**
|
||||
* Adds a toggle view action to the the internal view menu.
|
||||
* You can either manage the insertion of the toggle view actions in your
|
||||
* application or you can add the actions to the internal view menu and
|
||||
* then simply insert the menu object into your.
|
||||
* \param[in] ToggleViewAction The action to insert. If no group is provided
|
||||
* the action is directly inserted into the menu. If a group
|
||||
* is provided, the action is inserted into the group and the
|
||||
* group is inserted into the menu if it is not existing yet.
|
||||
* \param[in] Group This is the text used for the group menu item
|
||||
* \param[in] GroupIcon The icon used for grouping the workbenches in the
|
||||
* view menu. I.e. if there is a workbench for each device
|
||||
* like for spectrometer devices, it is good to group all these
|
||||
* workbenches under a menu item
|
||||
* \return If Group is not empty, this function returns the GroupAction
|
||||
* for this group. If the group is empty, the function returns
|
||||
* the given ToggleViewAction.
|
||||
*/
|
||||
QAction* addToggleViewActionToMenu(QAction* ToggleViewAction,
|
||||
const QString& Group = QString(), const QIcon& GroupIcon = QIcon());
|
||||
|
||||
/**
|
||||
* This function returns the internal view menu.
|
||||
* To fill the view menu, you can use the addToggleViewActionToMenu()
|
||||
* function.
|
||||
*/
|
||||
QMenu* viewMenu() const;
|
||||
|
||||
/**
|
||||
* Define the insertion order for toggle view menu items.
|
||||
* The order defines how the actions are added to the view menu.
|
||||
* The default insertion order is MenuAlphabeticallySorted to make it
|
||||
* easier for users to find the menu entry for a certain dock widget.
|
||||
* You need to call this function befor you insert the first menu item
|
||||
* into the view menu.
|
||||
*/
|
||||
void setViewMenuInsertionOrder(eViewMenuInsertionOrder Order);
|
||||
|
||||
/**
|
||||
* This function returns true between the restoringState() and
|
||||
* stateRestored() signals.
|
||||
*/
|
||||
bool isRestoringState() const;
|
||||
|
||||
/**
|
||||
* The distance the user needs to move the mouse with the left button
|
||||
* hold down before a dock widget start floating
|
||||
*/
|
||||
static int startDragDistance();
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* Opens the perspective with the given name.
|
||||
@@ -204,12 +331,40 @@ signals:
|
||||
*/
|
||||
void perspectiveListChanged();
|
||||
|
||||
/**
|
||||
* This signal is emitted if perspectives have been removed
|
||||
*/
|
||||
void perspectivesRemoved();
|
||||
|
||||
/**
|
||||
* This signal is emitted, if the restore function is called, just before
|
||||
* the dock manager starts restoring the state.
|
||||
* If this function is called, nothing has changed yet
|
||||
*/
|
||||
void restoringState();
|
||||
|
||||
/**
|
||||
* This signal is emitted if the state changed in restoreState.
|
||||
* The signal is emitted if the restoreState() function is called or
|
||||
* if the openPerspective() function is called
|
||||
*/
|
||||
void stateChanged();
|
||||
void stateRestored();
|
||||
|
||||
/**
|
||||
* This signal is emitted, if the dock manager starts opening a
|
||||
* perspective.
|
||||
* Opening a perspective may take more than a second if there are
|
||||
* many complex widgets. The application may use this signal
|
||||
* to show some progress indicator or to change the mouse cursor
|
||||
* into a busy cursor.
|
||||
*/
|
||||
void openingPerspective(const QString& PerspectiveName);
|
||||
|
||||
/**
|
||||
* This signal is emitted if the dock manager finished opening a
|
||||
* perspective
|
||||
*/
|
||||
void perspectiveOpened(const QString& PerspectiveName);
|
||||
}; // class DockManager
|
||||
} // namespace ads
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <QtGlobal>
|
||||
#include <QDebug>
|
||||
#include <QMap>
|
||||
#include <QWindow>
|
||||
|
||||
#include "DockAreaWidget.h"
|
||||
|
||||
@@ -75,6 +76,7 @@ struct DockOverlayCrossPrivate
|
||||
QGridLayout* GridLayout;
|
||||
QColor IconColors[5];
|
||||
bool UpdateRequired = false;
|
||||
double LastDevicePixelRatio = 0.1;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@@ -141,21 +143,38 @@ struct DockOverlayCrossPrivate
|
||||
const qreal metric = static_cast<qreal>(l->fontMetrics().height()) * 3.f;
|
||||
const QSizeF size(metric, metric);
|
||||
|
||||
l->setPixmap(createDropIndicatorPixmap(size, DockWidgetArea, Mode));
|
||||
l->setPixmap(createHighDpiDropIndicatorPixmap(size, DockWidgetArea, Mode));
|
||||
l->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
|
||||
l->setAttribute(Qt::WA_TranslucentBackground);
|
||||
l->setProperty("dockWidgetArea", DockWidgetArea);
|
||||
return l;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void updateDropIndicatorIcon(QWidget* DropIndicatorWidget)
|
||||
{
|
||||
QLabel* l = qobject_cast<QLabel*>(DropIndicatorWidget);
|
||||
const qreal metric = static_cast<qreal>(l->fontMetrics().height()) * 3.f;
|
||||
const QSizeF size(metric, metric);
|
||||
|
||||
int Area = l->property("dockWidgetArea").toInt();
|
||||
l->setPixmap(createHighDpiDropIndicatorPixmap(size, (DockWidgetArea)Area, Mode));
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
QPixmap createDropIndicatorPixmap(const QSizeF& size, DockWidgetArea DockWidgetArea,
|
||||
QPixmap createHighDpiDropIndicatorPixmap(const QSizeF& size, DockWidgetArea DockWidgetArea,
|
||||
CDockOverlay::eMode Mode)
|
||||
{
|
||||
QColor borderColor = iconColor(CDockOverlayCross::FrameColor);
|
||||
QColor backgroundColor = iconColor(CDockOverlayCross::WindowBackgroundColor);
|
||||
|
||||
QPixmap pm(size.width(), size.height());
|
||||
#if QT_VERSION >= 0x050600
|
||||
double DevicePixelRatio = _this->window()->devicePixelRatioF();
|
||||
#else
|
||||
double DevicePixelRatio = _this->window()->devicePixelRatio();
|
||||
#endif
|
||||
QSizeF PixmapSize = size * DevicePixelRatio;
|
||||
QPixmap pm(PixmapSize.toSize());
|
||||
pm.fill(QColor(0, 0, 0, 0));
|
||||
|
||||
QPainter p(&pm);
|
||||
@@ -225,6 +244,7 @@ struct DockOverlayCrossPrivate
|
||||
p.drawRect(areaRect);
|
||||
|
||||
pen = p.pen();
|
||||
pen.setWidth(1);
|
||||
pen.setColor(borderColor);
|
||||
pen.setStyle(Qt::DashLine);
|
||||
p.setPen(pen);
|
||||
@@ -284,6 +304,7 @@ struct DockOverlayCrossPrivate
|
||||
p.drawPolygon(Arrow);
|
||||
}
|
||||
|
||||
pm.setDevicePixelRatio(DevicePixelRatio);
|
||||
return pm;
|
||||
}
|
||||
|
||||
@@ -347,7 +368,7 @@ DockWidgetArea CDockOverlay::dropAreaUnderCursor() const
|
||||
return Result;
|
||||
}
|
||||
|
||||
if (DockArea->titleAreaGeometry().contains(DockArea->mapFromGlobal(QCursor::pos())))
|
||||
if (DockArea->titleBarGeometry().contains(DockArea->mapFromGlobal(QCursor::pos())))
|
||||
{
|
||||
return CenterDockWidgetArea;
|
||||
}
|
||||
@@ -381,6 +402,7 @@ DockWidgetArea CDockOverlay::showOverlay(QWidget* target)
|
||||
move(TopLeft);
|
||||
show();
|
||||
d->Cross->updatePosition();
|
||||
d->Cross->updateOverlayIcons();
|
||||
return dropAreaUnderCursor();
|
||||
}
|
||||
|
||||
@@ -430,9 +452,16 @@ void CDockOverlay::paintEvent(QPaintEvent* event)
|
||||
}
|
||||
QPainter painter(this);
|
||||
QColor Color = palette().color(QPalette::Active, QPalette::Highlight);
|
||||
QPen Pen = painter.pen();
|
||||
Pen.setColor(Color.darker(120));
|
||||
Pen.setStyle(Qt::SolidLine);
|
||||
Pen.setWidth(1);
|
||||
Pen.setCosmetic(true);
|
||||
painter.setPen(Pen);
|
||||
Color = Color.lighter(130);
|
||||
Color.setAlpha(64);
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.fillRect(r, Color);
|
||||
painter.setBrush(Color);
|
||||
painter.drawRect(r.adjusted(0, 0, -1, -1));
|
||||
d->DropAreaRect = r;
|
||||
}
|
||||
|
||||
@@ -552,12 +581,36 @@ void CDockOverlayCross::setupOverlayCross(CDockOverlay::eMode Mode)
|
||||
areaWidgets.insert(BottomDockWidgetArea, d->createDropIndicatorWidget(BottomDockWidgetArea, Mode));
|
||||
areaWidgets.insert(LeftDockWidgetArea, d->createDropIndicatorWidget(LeftDockWidgetArea, Mode));
|
||||
areaWidgets.insert(CenterDockWidgetArea, d->createDropIndicatorWidget(CenterDockWidgetArea, Mode));
|
||||
|
||||
#if QT_VERSION >= 0x050600
|
||||
d->LastDevicePixelRatio = devicePixelRatioF();
|
||||
#else
|
||||
d->LastDevicePixelRatio = devicePixelRatio();
|
||||
#endif
|
||||
setAreaWidgets(areaWidgets);
|
||||
d->UpdateRequired = false;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockOverlayCross::updateOverlayIcons()
|
||||
{
|
||||
if (windowHandle()->devicePixelRatio() == d->LastDevicePixelRatio)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto Widget : d->DropIndicatorWidgets)
|
||||
{
|
||||
d->updateDropIndicatorIcon(Widget);
|
||||
}
|
||||
#if QT_VESION >= 0x050600
|
||||
d->LastDevicePixelRatio = devicePixelRatioF();
|
||||
#else
|
||||
d->LastDevicePixelRatio = devicePixelRatio();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockOverlayCross::setIconColor(eIconColor ColorIndex, const QColor& Color)
|
||||
{
|
||||
|
||||
@@ -214,6 +214,11 @@ public:
|
||||
*/
|
||||
void setupOverlayCross(CDockOverlay::eMode Mode);
|
||||
|
||||
/**
|
||||
* Recreates the overlay icons.
|
||||
*/
|
||||
void updateOverlayIcons();
|
||||
|
||||
/**
|
||||
* Resets and updates the
|
||||
*/
|
||||
|
||||
@@ -52,7 +52,8 @@ CDockSplitter::CDockSplitter(QWidget *parent)
|
||||
: QSplitter(parent),
|
||||
d(new DockSplitterPrivate(this))
|
||||
{
|
||||
|
||||
setProperty("ads-splitter", true);
|
||||
setChildrenCollapsible(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +79,7 @@ bool CDockSplitter::hasVisibleContent() const
|
||||
// TODO Cache or precalculate this to speed up
|
||||
for (int i = 0; i < count(); ++i)
|
||||
{
|
||||
if (widget(i)->isVisibleTo(this))
|
||||
if (!widget(i)->isHidden())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/*******************************************************************************
|
||||
** 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 DockStateSerialization.cpp
|
||||
/// \author Uwe Kindler
|
||||
/// \date 26.02.2017
|
||||
/// \brief Serialization related data, constants and stuff
|
||||
//============================================================================
|
||||
|
||||
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include "DockStateSerialization.h"
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
#ifndef DockStateSerializationH
|
||||
#define DockStateSerializationH
|
||||
/*******************************************************************************
|
||||
** 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 DockStateSerialization.h
|
||||
/// \author Uwe Kindler
|
||||
/// \date 26.02.2017
|
||||
/// \brief Declaration of serialization related data, constants and stuff
|
||||
//============================================================================
|
||||
|
||||
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
|
||||
|
||||
namespace ads
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
// sentinel values used to validate state data
|
||||
enum VersionMarkers
|
||||
{
|
||||
VersionMarker = 0xff,
|
||||
ContainerMarker = 0xfe,
|
||||
SplitterMarker = 0xfd,
|
||||
DockAreaMarker = 0xfc,
|
||||
DockWidgetMarker = 0xfb
|
||||
};
|
||||
|
||||
static const bool RestoreTesting = true;
|
||||
static const bool Restore = false;
|
||||
} // internal
|
||||
} // namespace ads
|
||||
//-----------------------------------------------------------------------------
|
||||
#endif // DockManagerH
|
||||
@@ -35,20 +35,22 @@
|
||||
#include <QAction>
|
||||
#include <QSplitter>
|
||||
#include <QStack>
|
||||
#include <QScrollArea>
|
||||
#include <QTextStream>
|
||||
#include <QPointer>
|
||||
#include <QEvent>
|
||||
#include <QDebug>
|
||||
#include <QToolBar>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#include "DockContainerWidget.h"
|
||||
#include "DockAreaWidget.h"
|
||||
#include "DockManager.h"
|
||||
#include "FloatingDockContainer.h"
|
||||
#include "DockStateSerialization.h"
|
||||
#include "DockSplitter.h"
|
||||
#include "ads_globals.h"
|
||||
|
||||
|
||||
namespace ads
|
||||
{
|
||||
/**
|
||||
@@ -59,12 +61,19 @@ struct DockWidgetPrivate
|
||||
CDockWidget* _this;
|
||||
QBoxLayout* Layout;
|
||||
QWidget* Widget = nullptr;
|
||||
CDockWidgetTab* TitleWidget;
|
||||
CDockWidgetTab* TabWidget;
|
||||
CDockWidget::DockWidgetFeatures Features = CDockWidget::AllDockWidgetFeatures;
|
||||
CDockManager* DockManager = nullptr;
|
||||
CDockAreaWidget* DockArea = nullptr;
|
||||
QAction* ToggleViewAction;
|
||||
bool Closed = false;
|
||||
QScrollArea* ScrollArea = nullptr;
|
||||
QToolBar* ToolBar = nullptr;
|
||||
Qt::ToolButtonStyle ToolBarStyleDocked = Qt::ToolButtonIconOnly;
|
||||
Qt::ToolButtonStyle ToolBarStyleFloating = Qt::ToolButtonTextUnderIcon;
|
||||
QSize ToolBarIconSizeDocked = QSize(16, 16);
|
||||
QSize ToolBarIconSizeFloating = QSize(24, 24);
|
||||
bool IsFloatingTopLevel = false;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@@ -82,20 +91,21 @@ struct DockWidgetPrivate
|
||||
void hideDockWidget();
|
||||
|
||||
/**
|
||||
* Hides a parent splitter if all dock widgets in the splitter are closed
|
||||
* Hides a dock area if all dock widgets in the area are closed.
|
||||
* This function updates the current selected tab and hides the parent
|
||||
* dock area if it is empty
|
||||
*/
|
||||
void hideEmptyParentSplitters();
|
||||
void updateParentDockArea();
|
||||
|
||||
/**
|
||||
* Hides a dock area if all dock widgets in the area are closed
|
||||
* Setup the top tool bar
|
||||
*/
|
||||
void hideEmptyParentDockArea();
|
||||
void setupToolBar();
|
||||
|
||||
/**
|
||||
* Hides a floating widget if all dock areas are empty - that means,
|
||||
* if all dock widgets in all dock areas are closed
|
||||
* Setup the main scroll area
|
||||
*/
|
||||
void hideEmptyFloatingWidget();
|
||||
void setupScrollArea();
|
||||
};
|
||||
// struct DockWidgetPrivate
|
||||
|
||||
@@ -118,9 +128,10 @@ void DockWidgetPrivate::showDockWidget()
|
||||
}
|
||||
else
|
||||
{
|
||||
DockArea->show();
|
||||
DockArea->setCurrentIndex(DockArea->tabIndex(_this));
|
||||
QSplitter* Splitter = internal::findParent<QSplitter*>(_this);
|
||||
DockArea->toggleView(true);
|
||||
DockArea->setCurrentDockWidget(_this);
|
||||
TabWidget->show();
|
||||
QSplitter* Splitter = internal::findParent<QSplitter*>(DockArea);
|
||||
while (Splitter && !Splitter->isVisible())
|
||||
{
|
||||
Splitter->show();
|
||||
@@ -141,63 +152,52 @@ void DockWidgetPrivate::showDockWidget()
|
||||
//============================================================================
|
||||
void DockWidgetPrivate::hideDockWidget()
|
||||
{
|
||||
TitleWidget->hide();
|
||||
hideEmptyParentDockArea();
|
||||
hideEmptyParentSplitters();
|
||||
hideEmptyFloatingWidget();
|
||||
TabWidget->hide();
|
||||
updateParentDockArea();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockWidgetPrivate::hideEmptyParentSplitters()
|
||||
void DockWidgetPrivate::updateParentDockArea()
|
||||
{
|
||||
auto Splitter = internal::findParent<CDockSplitter*>(_this);
|
||||
while (Splitter && Splitter->isVisible())
|
||||
if (!DockArea)
|
||||
{
|
||||
if (!Splitter->hasVisibleContent())
|
||||
{
|
||||
Splitter->hide();
|
||||
}
|
||||
Splitter = internal::findParent<CDockSplitter*>(Splitter);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockWidgetPrivate::hideEmptyParentDockArea()
|
||||
{
|
||||
auto OpenDockWidgets = DockArea->openedDockWidgets();
|
||||
if (OpenDockWidgets.count() > 1)
|
||||
auto NextDockWidget = DockArea->nextOpenDockWidget(_this);
|
||||
if (NextDockWidget)
|
||||
{
|
||||
CDockWidget* NextDockWidget;
|
||||
if (OpenDockWidgets.last() == _this)
|
||||
{
|
||||
NextDockWidget = OpenDockWidgets[OpenDockWidgets.count() - 2];
|
||||
}
|
||||
else
|
||||
{
|
||||
int NextIndex = OpenDockWidgets.indexOf(_this) + 1;
|
||||
NextDockWidget = OpenDockWidgets[NextIndex];
|
||||
}
|
||||
|
||||
DockArea->setCurrentDockWidget(NextDockWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
DockArea->hide();
|
||||
DockArea->hideAreaWithNoVisibleContent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockWidgetPrivate::hideEmptyFloatingWidget()
|
||||
void DockWidgetPrivate::setupToolBar()
|
||||
{
|
||||
CDockContainerWidget* Container = _this->dockContainer();
|
||||
if (Container->isFloating() && Container->openedDockAreas().isEmpty())
|
||||
{
|
||||
CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(Container);
|
||||
FloatingWidget->hide();
|
||||
}
|
||||
ToolBar = new QToolBar(_this);
|
||||
ToolBar->setObjectName("dockWidgetToolBar");
|
||||
Layout->insertWidget(0, ToolBar);
|
||||
ToolBar->setIconSize(QSize(16, 16));
|
||||
ToolBar->toggleViewAction()->setEnabled(false);
|
||||
ToolBar->toggleViewAction()->setVisible(false);
|
||||
_this->connect(_this, SIGNAL(topLevelChanged(bool)), SLOT(setToolbarFloatingStyle(bool)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockWidgetPrivate::setupScrollArea()
|
||||
{
|
||||
ScrollArea = new QScrollArea(_this);
|
||||
ScrollArea->setObjectName("dockWidgetScrollArea");
|
||||
ScrollArea->setWidgetResizable(true);
|
||||
Layout->addWidget(ScrollArea);
|
||||
}
|
||||
|
||||
|
||||
@@ -213,11 +213,12 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
|
||||
setWindowTitle(title);
|
||||
setObjectName(title);
|
||||
|
||||
d->TitleWidget = new CDockWidgetTab(this);
|
||||
d->ToggleViewAction = new QAction(title);
|
||||
d->TabWidget = new CDockWidgetTab(this);
|
||||
d->ToggleViewAction = new QAction(title, nullptr);
|
||||
d->ToggleViewAction->setCheckable(true);
|
||||
connect(d->ToggleViewAction, SIGNAL(triggered(bool)), this,
|
||||
SLOT(toggleView(bool)));
|
||||
setToolbarFloatingStyle(false);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
@@ -239,11 +240,13 @@ void CDockWidget::setToggleViewActionChecked(bool Checked)
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidget::setWidget(QWidget* widget)
|
||||
void CDockWidget::setWidget(QWidget* widget, eInsertMode InsertMode)
|
||||
{
|
||||
if (d->Widget)
|
||||
QScrollArea* ScrollAreaWidget = qobject_cast<QScrollArea*>(widget);
|
||||
if (ScrollAreaWidget || ForceNoScrollArea != InsertMode)
|
||||
{
|
||||
d->Layout->replaceWidget(d->Widget, widget);
|
||||
d->setupScrollArea();
|
||||
d->ScrollArea->setWidget(widget);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -251,6 +254,7 @@ void CDockWidget::setWidget(QWidget* widget)
|
||||
}
|
||||
|
||||
d->Widget = widget;
|
||||
d->Widget->setProperty("dockWidgetContent", true);
|
||||
}
|
||||
|
||||
|
||||
@@ -262,9 +266,9 @@ QWidget* CDockWidget::widget() const
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockWidgetTab* CDockWidget::titleBar() const
|
||||
CDockWidgetTab* CDockWidget::tabWidget() const
|
||||
{
|
||||
return d->TitleWidget;
|
||||
return d->TabWidget;
|
||||
}
|
||||
|
||||
|
||||
@@ -278,7 +282,18 @@ void CDockWidget::setFeatures(DockWidgetFeatures features)
|
||||
//============================================================================
|
||||
void CDockWidget::setFeature(DockWidgetFeature flag, bool on)
|
||||
{
|
||||
#if QT_VERSION >= 0x050700
|
||||
d->Features.setFlag(flag, on);
|
||||
#else
|
||||
if(on)
|
||||
{
|
||||
d->Features |= flag;
|
||||
}
|
||||
else
|
||||
{
|
||||
d->Features &= ~flag;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -306,21 +321,51 @@ void CDockWidget::setDockManager(CDockManager* DockManager)
|
||||
//============================================================================
|
||||
CDockContainerWidget* CDockWidget::dockContainer() const
|
||||
{
|
||||
return internal::findParent<CDockContainerWidget*>(this);
|
||||
if (d->DockArea)
|
||||
{
|
||||
return d->DockArea->dockContainer();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockAreaWidget* CDockWidget::dockAreaWidget() const
|
||||
{
|
||||
return internal::findParent<CDockAreaWidget*>(this);
|
||||
return d->DockArea;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
bool CDockWidget::isFloating() const
|
||||
{
|
||||
return dockContainer() ? dockContainer()->isFloating() : false;
|
||||
if (!isInFloatingContainer())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return dockContainer()->topLevelDockWidget() == this;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
bool CDockWidget::isInFloatingContainer() const
|
||||
{
|
||||
auto Container = dockContainer();
|
||||
if (!Container)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Container->isFloating())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -349,7 +394,7 @@ void CDockWidget::setToggleViewActionMode(eToggleViewActionMode Mode)
|
||||
else
|
||||
{
|
||||
d->ToggleViewAction->setCheckable(false);
|
||||
d->ToggleViewAction->setIcon(d->TitleWidget->icon());
|
||||
d->ToggleViewAction->setIcon(d->TabWidget->icon());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,11 +402,33 @@ void CDockWidget::setToggleViewActionMode(eToggleViewActionMode Mode)
|
||||
//============================================================================
|
||||
void CDockWidget::toggleView(bool Open)
|
||||
{
|
||||
// If the toggle view action mode is ActionModeShow, then Open is always
|
||||
// true if the sender is the toggle view action
|
||||
QAction* Sender = qobject_cast<QAction*>(sender());
|
||||
if (Sender == d->ToggleViewAction && !d->ToggleViewAction->isCheckable())
|
||||
{
|
||||
Open = true;
|
||||
}
|
||||
// If the dock widget state is different, then we really need to toggle
|
||||
// the state. If we are in the right state, then we simply make this
|
||||
// dock widget the current dock widget
|
||||
if (d->Closed != !Open)
|
||||
{
|
||||
toggleViewInternal(Open);
|
||||
}
|
||||
else if (Open && d->DockArea)
|
||||
{
|
||||
d->DockArea->setCurrentDockWidget(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidget::toggleViewInternal(bool Open)
|
||||
{
|
||||
CDockContainerWidget* DockContainer = dockContainer();
|
||||
CDockWidget* TopLevelDockWidgetBefore = DockContainer
|
||||
? DockContainer->topLevelDockWidget() : nullptr;
|
||||
|
||||
if (Open)
|
||||
{
|
||||
@@ -375,6 +442,29 @@ void CDockWidget::toggleView(bool Open)
|
||||
d->ToggleViewAction->blockSignals(true);
|
||||
d->ToggleViewAction->setChecked(Open);
|
||||
d->ToggleViewAction->blockSignals(false);
|
||||
if (d->DockArea)
|
||||
{
|
||||
d->DockArea->toggleDockWidgetView(this, Open);
|
||||
}
|
||||
|
||||
if (Open && TopLevelDockWidgetBefore)
|
||||
{
|
||||
CDockWidget::emitTopLevelEventForWidget(TopLevelDockWidgetBefore, false);
|
||||
}
|
||||
|
||||
// Here we need to call the dockContainer() function again, because if
|
||||
// this dock widget was unassigned before the call to showDockWidget() then
|
||||
// it has a dock container now
|
||||
DockContainer = dockContainer();
|
||||
CDockWidget* TopLevelDockWidgetAfter = DockContainer
|
||||
? DockContainer->topLevelDockWidget() : nullptr;
|
||||
CDockWidget::emitTopLevelEventForWidget(TopLevelDockWidgetAfter, true);
|
||||
CFloatingDockContainer* FloatingContainer = DockContainer->floatingWidget();
|
||||
if (FloatingContainer)
|
||||
{
|
||||
FloatingContainer->updateWindowTitle();
|
||||
}
|
||||
|
||||
if (!Open)
|
||||
{
|
||||
emit closed();
|
||||
@@ -387,15 +477,15 @@ void CDockWidget::toggleView(bool Open)
|
||||
void CDockWidget::setDockArea(CDockAreaWidget* DockArea)
|
||||
{
|
||||
d->DockArea = DockArea;
|
||||
d->ToggleViewAction->setChecked(DockArea != nullptr);
|
||||
d->ToggleViewAction->setChecked(DockArea != nullptr && !this->isClosed());
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidget::saveState(QXmlStreamWriter& s) const
|
||||
{
|
||||
s.writeStartElement("DockWidget");
|
||||
s.writeAttribute("ObjectName", objectName());
|
||||
s.writeStartElement("Widget");
|
||||
s.writeAttribute("Name", objectName());
|
||||
s.writeAttribute("Closed", QString::number(d->Closed ? 1 : 0));
|
||||
s.writeEndElement();
|
||||
}
|
||||
@@ -404,9 +494,11 @@ void CDockWidget::saveState(QXmlStreamWriter& s) const
|
||||
//============================================================================
|
||||
void CDockWidget::flagAsUnassigned()
|
||||
{
|
||||
d->Closed = true;
|
||||
setParent(d->DockManager);
|
||||
setVisible(false);
|
||||
setDockArea(nullptr);
|
||||
titleBar()->setParent(this);
|
||||
tabWidget()->setParent(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -424,7 +516,7 @@ bool CDockWidget::event(QEvent *e)
|
||||
//============================================================================
|
||||
void CDockWidget::setIcon(const QIcon& Icon)
|
||||
{
|
||||
d->TitleWidget->setIcon(Icon);
|
||||
d->TabWidget->setIcon(Icon);
|
||||
if (!d->ToggleViewAction->isCheckable())
|
||||
{
|
||||
d->ToggleViewAction->setIcon(Icon);
|
||||
@@ -435,10 +527,161 @@ void CDockWidget::setIcon(const QIcon& Icon)
|
||||
//============================================================================
|
||||
QIcon CDockWidget::icon() const
|
||||
{
|
||||
return d->TitleWidget->icon();
|
||||
return d->TabWidget->icon();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QToolBar* CDockWidget::toolBar() const
|
||||
{
|
||||
return d->ToolBar;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QToolBar* CDockWidget::createDefaultToolBar()
|
||||
{
|
||||
if (!d->ToolBar)
|
||||
{
|
||||
d->setupToolBar();
|
||||
}
|
||||
|
||||
return d->ToolBar;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidget::setToolBar(QToolBar* ToolBar)
|
||||
{
|
||||
if (d->ToolBar)
|
||||
{
|
||||
delete d->ToolBar;
|
||||
}
|
||||
|
||||
d->ToolBar = ToolBar;
|
||||
d->Layout->insertWidget(0, d->ToolBar);
|
||||
this->connect(this, SIGNAL(topLevelChanged(bool)), SLOT(setToolbarFloatingStyle(bool)));
|
||||
setToolbarFloatingStyle(isFloating());
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidget::setToolBarStyle(Qt::ToolButtonStyle Style, eState State)
|
||||
{
|
||||
if (StateFloating == State)
|
||||
{
|
||||
d->ToolBarStyleFloating = Style;
|
||||
}
|
||||
else
|
||||
{
|
||||
d->ToolBarStyleDocked = Style;
|
||||
}
|
||||
|
||||
setToolbarFloatingStyle(isFloating());
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
Qt::ToolButtonStyle CDockWidget::toolBarStyle(eState State) const
|
||||
{
|
||||
if (StateFloating == State)
|
||||
{
|
||||
return d->ToolBarStyleFloating;
|
||||
}
|
||||
else
|
||||
{
|
||||
return d->ToolBarStyleDocked;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidget::setToolBarIconSize(const QSize& IconSize, eState State)
|
||||
{
|
||||
if (StateFloating == State)
|
||||
{
|
||||
d->ToolBarIconSizeFloating = IconSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
d->ToolBarIconSizeDocked = IconSize;
|
||||
}
|
||||
|
||||
setToolbarFloatingStyle(isFloating());
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QSize CDockWidget::toolBarIconSize(eState State) const
|
||||
{
|
||||
if (StateFloating == State)
|
||||
{
|
||||
return d->ToolBarIconSizeFloating;
|
||||
}
|
||||
else
|
||||
{
|
||||
return d->ToolBarIconSizeDocked;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidget::setToolbarFloatingStyle(bool Floating)
|
||||
{
|
||||
if (!d->ToolBar)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto IconSize = Floating ? d->ToolBarIconSizeFloating : d->ToolBarIconSizeDocked;
|
||||
if (IconSize != d->ToolBar->iconSize())
|
||||
{
|
||||
d->ToolBar->setIconSize(IconSize);
|
||||
}
|
||||
|
||||
auto ButtonStyle = Floating ? d->ToolBarStyleFloating : d->ToolBarStyleDocked;
|
||||
if (ButtonStyle != d->ToolBar->toolButtonStyle())
|
||||
{
|
||||
d->ToolBar->setToolButtonStyle(ButtonStyle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidget::emitTopLevelEventForWidget(CDockWidget* TopLevelDockWidget, bool Floating)
|
||||
{
|
||||
if (TopLevelDockWidget)
|
||||
{
|
||||
TopLevelDockWidget->dockAreaWidget()->updateTitleBarVisibility();
|
||||
TopLevelDockWidget->emitTopLevelChanged(Floating);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidget::emitTopLevelChanged(bool Floating)
|
||||
{
|
||||
if (Floating != d->IsFloatingTopLevel)
|
||||
{
|
||||
d->IsFloatingTopLevel = Floating;
|
||||
emit topLevelChanged(d->IsFloatingTopLevel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidget::setClosedState(bool Closed)
|
||||
{
|
||||
d->Closed = Closed;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QSize CDockWidget::minimumSizeHint() const
|
||||
{
|
||||
return QSize(60, 40);
|
||||
}
|
||||
|
||||
|
||||
} // namespace ads
|
||||
|
||||
|
||||
171
src/DockWidget.h
@@ -34,6 +34,7 @@
|
||||
|
||||
#include "ads_globals.h"
|
||||
|
||||
class QToolBar;
|
||||
class QXmlStreamWriter;
|
||||
|
||||
namespace ads
|
||||
@@ -43,7 +44,8 @@ class CDockWidgetTab;
|
||||
class CDockManager;
|
||||
class CDockContainerWidget;
|
||||
class CDockAreaWidget;
|
||||
struct DockContainerWidgetPrivate;
|
||||
class DockContainerWidgetPrivate;
|
||||
class CFloatingDockContainer;
|
||||
|
||||
/**
|
||||
* The QDockWidget class provides a widget that can be docked inside a
|
||||
@@ -56,12 +58,22 @@ private:
|
||||
DockWidgetPrivate* d; ///< private data (pimpl)
|
||||
friend struct DockWidgetPrivate;
|
||||
|
||||
private slots:
|
||||
/**
|
||||
* Adjusts the toolbar icon sizes according to the floating state
|
||||
*/
|
||||
void setToolbarFloatingStyle(bool topLevel);
|
||||
|
||||
protected:
|
||||
friend class CDockContainerWidget;
|
||||
friend class CDockAreaWidget;
|
||||
friend class CFloatingDockContainer;
|
||||
friend class CDockManager;
|
||||
friend struct DockContainerWidgetPrivate;
|
||||
friend struct DockManagerPrivate;
|
||||
friend class DockContainerWidgetPrivate;
|
||||
friend class CDockAreaTabBar;
|
||||
friend class CDockWidgetTab;
|
||||
friend struct DockWidgetTabPrivate;
|
||||
|
||||
/**
|
||||
* Assigns the dock manager that manages this dock widget
|
||||
@@ -98,6 +110,31 @@ protected:
|
||||
*/
|
||||
void flagAsUnassigned();
|
||||
|
||||
/**
|
||||
* Call this function to emit a topLevelChanged() signal and to update
|
||||
* the dock area tool bar visibility
|
||||
*/
|
||||
static void emitTopLevelEventForWidget(CDockWidget* TopLevelDockWidget, bool Floating);
|
||||
|
||||
/**
|
||||
* Use this function to emit a top level changed event.
|
||||
* Do never use emit topLevelChanged(). Always use this function because
|
||||
* it only emits a signal if the floating state has really changed
|
||||
*/
|
||||
void emitTopLevelChanged(bool Floating);
|
||||
|
||||
/**
|
||||
* Internal function for modifying the closed state when restoring
|
||||
* a saved docking state
|
||||
*/
|
||||
void setClosedState(bool Closed);
|
||||
|
||||
/**
|
||||
* Internal toggle view function that does not check if the widget
|
||||
* already is in the given state
|
||||
*/
|
||||
void toggleViewInternal(bool Open);
|
||||
|
||||
public:
|
||||
enum DockWidgetFeature
|
||||
{
|
||||
@@ -109,7 +146,6 @@ public:
|
||||
};
|
||||
Q_DECLARE_FLAGS(DockWidgetFeatures, DockWidgetFeature)
|
||||
|
||||
|
||||
enum eState
|
||||
{
|
||||
StateHidden,
|
||||
@@ -117,6 +153,30 @@ public:
|
||||
StateFloating
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the widget for the dock widget to widget.
|
||||
* The InsertMode defines how the widget is inserted into the dock widget.
|
||||
* The content of a dock widget should be resizable do a very small size to
|
||||
* prevent the dock widget from blocking the resizing. To ensure, that a
|
||||
* dock widget can be resized very well, it is better to insert the content+
|
||||
* widget into a scroll area or to provide a widget that is already a scroll
|
||||
* area or that contains a scroll area.
|
||||
* If the InsertMode is AutoScrollArea, the DockWidget tries to automatically
|
||||
* detect how to insert the given widget. If the widget is derived from
|
||||
* QScrollArea (i.e. an QAbstractItemView), then the widget is inserted
|
||||
* directly. If the given widget is not a scroll area, the widget will be
|
||||
* inserted into a scroll area.
|
||||
* To force insertion into a scroll area, you can also provide the InsertMode
|
||||
* ForceScrollArea. To prevent insertion into a scroll area, you can
|
||||
* provide the InsertMode ForceNoScrollArea
|
||||
*/
|
||||
enum eInsertMode
|
||||
{
|
||||
AutoScrollArea,
|
||||
ForceScrollArea,
|
||||
ForceNoScrollArea
|
||||
};
|
||||
|
||||
/**
|
||||
* This mode configures the behavior of the toggle view action.
|
||||
* If the mode if ActionModeToggle, then the toggle view action is
|
||||
@@ -131,6 +191,7 @@ public:
|
||||
ActionModeShow //!< ActionModeShow
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* This constructor creates a dock widget with the given title.
|
||||
* The title is the text that is shown in the window title when the dock
|
||||
@@ -142,6 +203,7 @@ public:
|
||||
* If your title is not unique or if you would like to change the title
|
||||
* during runtime, you need to set a unique object name explicitely
|
||||
* by calling setObjectName() after construction.
|
||||
* Use the layoutFlags to configure the layout of the dock widget.
|
||||
*/
|
||||
CDockWidget(const QString &title, QWidget* parent = 0);
|
||||
|
||||
@@ -151,9 +213,28 @@ public:
|
||||
virtual ~CDockWidget();
|
||||
|
||||
/**
|
||||
* Sets the widget for the dock widget to widget.
|
||||
* We return a fixed minimum size hint for all dock widgets
|
||||
*/
|
||||
void setWidget(QWidget* widget);
|
||||
virtual QSize minimumSizeHint() const override;
|
||||
|
||||
/**
|
||||
* Sets the widget for the dock widget to widget.
|
||||
* The InsertMode defines how the widget is inserted into the dock widget.
|
||||
* The content of a dock widget should be resizable do a very small size to
|
||||
* prevent the dock widget from blocking the resizing. To ensure, that a
|
||||
* dock widget can be resized very well, it is better to insert the content+
|
||||
* widget into a scroll area or to provide a widget that is already a scroll
|
||||
* area or that contains a scroll area.
|
||||
* If the InsertMode is AutoScrollArea, the DockWidget tries to automatically
|
||||
* detect how to insert the given widget. If the widget is derived from
|
||||
* QScrollArea (i.e. an QAbstractItemView), then the widget is inserted
|
||||
* directly. If the given widget is not a scroll area, the widget will be
|
||||
* inserted into a scroll area.
|
||||
* To force insertion into a scroll area, you can also provide the InsertMode
|
||||
* ForceScrollArea. To prevent insertion into a scroll area, you can
|
||||
* provide the InsertMode ForceNoScrollArea
|
||||
*/
|
||||
void setWidget(QWidget* widget, eInsertMode InsertMode = AutoScrollArea);
|
||||
|
||||
/**
|
||||
* Returns the widget for the dock widget. This function returns zero if
|
||||
@@ -164,7 +245,7 @@ public:
|
||||
/**
|
||||
* Returns the title bar widget of this dock widget
|
||||
*/
|
||||
CDockWidgetTab* titleBar() const;
|
||||
CDockWidgetTab* tabWidget() const;
|
||||
|
||||
/**
|
||||
* Sets, whether the dock widget is movable, closable, and floatable.
|
||||
@@ -193,7 +274,7 @@ public:
|
||||
|
||||
/**
|
||||
* Returns the dock container widget this dock area widget belongs to or 0
|
||||
* if this dock widget has nt been docked yet
|
||||
* if this dock widget has not been docked yet
|
||||
*/
|
||||
CDockContainerWidget* dockContainer() const;
|
||||
|
||||
@@ -205,9 +286,19 @@ public:
|
||||
|
||||
/**
|
||||
* This property holds whether the dock widget is floating.
|
||||
* A dock widget is only floating, if it is the one and only widget inside
|
||||
* of a floating container. If there are more than one dock widget in a
|
||||
* floating container, the all dock widgets are docked and not floating.
|
||||
*/
|
||||
bool isFloating() const;
|
||||
|
||||
/**
|
||||
* This function returns true, if this dock widget is in a floating.
|
||||
* The function returns true, if the dock widget is floating and it also
|
||||
* returns true if it is docked inside of a floating container.
|
||||
*/
|
||||
bool isInFloatingContainer() const;
|
||||
|
||||
/**
|
||||
* Returns true, if this dock widget is closed.
|
||||
*/
|
||||
@@ -232,10 +323,67 @@ public:
|
||||
void setIcon(const QIcon& Icon);
|
||||
|
||||
/**
|
||||
* Returns tzhe icon that has been assigned to the dock widget
|
||||
* Returns the icon that has been assigned to the dock widget
|
||||
*/
|
||||
QIcon icon() const;
|
||||
|
||||
/**
|
||||
* If the WithToolBar layout flag is enabled, then this function returns
|
||||
* the dock widget toolbar. If the flag is disabled, the function returns
|
||||
* a nullptr.
|
||||
* This function returns the dock widget top tool bar.
|
||||
* If no toolbar is assigned, this function returns nullptr. To get a vaild
|
||||
* toolbar you either need to create a default empty toolbar via
|
||||
* createDefaultToolBar() function or you need to assign you custom
|
||||
* toolbar via setToolBar().
|
||||
*/
|
||||
QToolBar* toolBar() const;
|
||||
|
||||
/**
|
||||
* If you would like to use the default top tool bar, then call this
|
||||
* function to create the default tool bar.
|
||||
* After this function the toolBar() function will return a valid toolBar()
|
||||
* object.
|
||||
*/
|
||||
QToolBar* createDefaultToolBar();
|
||||
|
||||
/**
|
||||
* Assign a new tool bar that is shown above the content widget.
|
||||
* The dock widget will become the owner of the tool bar and deletes it
|
||||
* on destruction
|
||||
*/
|
||||
void setToolBar(QToolBar* ToolBar);
|
||||
|
||||
/**
|
||||
* This function sets the tool button style for the given dock widget state.
|
||||
* It is possible to switch the tool button style depending on the state.
|
||||
* If a dock widget is floating, then here are more space and it is
|
||||
* possible to select a style that requires more space like
|
||||
* Qt::ToolButtonTextUnderIcon. For the docked state Qt::ToolButtonIconOnly
|
||||
* might be better.
|
||||
*/
|
||||
void setToolBarStyle(Qt::ToolButtonStyle Style, eState State);
|
||||
|
||||
/**
|
||||
* Returns the tool button style for the given docking state.
|
||||
* \see setToolBarStyle()
|
||||
*/
|
||||
Qt::ToolButtonStyle toolBarStyle(eState State) const;
|
||||
|
||||
/**
|
||||
* This function sets the tool button icon size for the given state.
|
||||
* If a dock widget is floating, there is more space an increasing the
|
||||
* icon size is possible. For docked widgets, small icon sizes, eg. 16 x 16
|
||||
* might be better.
|
||||
*/
|
||||
void setToolBarIconSize(const QSize& IconSize, eState State);
|
||||
|
||||
/**
|
||||
* Returns the icon size for a given docking state.
|
||||
* \see setToolBarIconSize()
|
||||
*/
|
||||
QSize toolBarIconSize(eState State) const;
|
||||
|
||||
|
||||
public: // reimplements QFrame -----------------------------------------------
|
||||
/**
|
||||
@@ -266,6 +414,13 @@ signals:
|
||||
* changed
|
||||
*/
|
||||
void titleChanged(const QString& Title);
|
||||
|
||||
/**
|
||||
* This signal is emitted when the floating property changes.
|
||||
* The topLevel parameter is true if the dock widget is now floating;
|
||||
* otherwise it is false.
|
||||
*/
|
||||
void topLevelChanged(bool topLevel);
|
||||
}; // class DockWidget
|
||||
}
|
||||
// namespace ads
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <ElidingLabel.h>
|
||||
#include "DockWidgetTab.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
@@ -37,6 +38,9 @@
|
||||
#include <QApplication>
|
||||
#include <QSplitter>
|
||||
#include <QDebug>
|
||||
#include <QToolButton>
|
||||
#include <QPushButton>
|
||||
#include <QMenu>
|
||||
|
||||
#include "ads_globals.h"
|
||||
#include "DockWidget.h"
|
||||
@@ -45,19 +49,13 @@
|
||||
#include "DockOverlay.h"
|
||||
#include "DockManager.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace ads
|
||||
{
|
||||
/**
|
||||
* The different dragging states
|
||||
*/
|
||||
enum eDragState
|
||||
{
|
||||
DraggingInactive, //!< DraggingInactive
|
||||
DraggingMousePressed, //!< DraggingMousePressed
|
||||
DraggingTab, //!< DraggingTab
|
||||
DraggingFloatingWidget//!< DraggingFloatingWidget
|
||||
};
|
||||
|
||||
using tTabLabel = CElidingLabel;
|
||||
using tCloseButton = QPushButton;
|
||||
|
||||
/**
|
||||
* Private data class of CDockWidgetTab class (pimpl)
|
||||
@@ -66,14 +64,16 @@ struct DockWidgetTabPrivate
|
||||
{
|
||||
CDockWidgetTab* _this;
|
||||
CDockWidget* DockWidget;
|
||||
QLabel* IconLabel;
|
||||
QLabel* TitleLabel;
|
||||
QLabel* IconLabel = nullptr;
|
||||
tTabLabel* TitleLabel;
|
||||
QPoint DragStartMousePosition;
|
||||
bool IsActiveTab = false;
|
||||
CDockAreaWidget* DockArea = nullptr;
|
||||
eDragState DragState = DraggingInactive;
|
||||
CFloatingDockContainer* FloatingWidget = nullptr;
|
||||
QIcon Icon;
|
||||
tCloseButton* CloseButton = nullptr;
|
||||
QSpacerItem* IconTextSpacer;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@@ -105,7 +105,7 @@ struct DockWidgetTabPrivate
|
||||
*/
|
||||
bool titleAreaGeometryContains(const QPoint& GlobalPos) const
|
||||
{
|
||||
return DockArea->titleAreaGeometry().contains(DockArea->mapFromGlobal(GlobalPos));
|
||||
return DockArea->titleBarGeometry().contains(DockArea->mapFromGlobal(GlobalPos));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,7 +113,15 @@ struct DockWidgetTabPrivate
|
||||
* Returns true, if floating has been started and false if floating
|
||||
* is not possible for any reason
|
||||
*/
|
||||
bool startFloating();
|
||||
bool startFloating(eDragState DraggingState = DraggingFloatingWidget);
|
||||
|
||||
/**
|
||||
* Returns true if the given config flag is set
|
||||
*/
|
||||
bool testConfigFlag(CDockManager::eConfigFlag Flag) const
|
||||
{
|
||||
return DockArea->dockManager()->configFlags().testFlag(Flag);
|
||||
}
|
||||
};
|
||||
// struct DockWidgetTabPrivate
|
||||
|
||||
@@ -129,21 +137,40 @@ DockWidgetTabPrivate::DockWidgetTabPrivate(CDockWidgetTab* _public) :
|
||||
//============================================================================
|
||||
void DockWidgetTabPrivate::createLayout()
|
||||
{
|
||||
QBoxLayout* l = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
l->setContentsMargins(0, 0, 0, 0);
|
||||
_this->setLayout(l);
|
||||
|
||||
IconLabel = new QLabel();
|
||||
IconLabel->setAlignment(Qt::AlignVCenter);
|
||||
l->addWidget(IconLabel, Qt::AlignVCenter);
|
||||
|
||||
TitleLabel = new QLabel();
|
||||
TitleLabel->setObjectName("dockWidgetTabLabel");
|
||||
l->addWidget(TitleLabel, 1);
|
||||
|
||||
IconLabel->setVisible(false);
|
||||
TitleLabel->setVisible(true);
|
||||
TitleLabel = new tTabLabel();
|
||||
TitleLabel->setElideMode(Qt::ElideRight);
|
||||
TitleLabel->setText(DockWidget->windowTitle());
|
||||
TitleLabel->setObjectName("dockWidgetTabLabel");
|
||||
TitleLabel->setAlignment(Qt::AlignCenter);
|
||||
|
||||
CloseButton = new tCloseButton();
|
||||
CloseButton->setObjectName("tabCloseButton");
|
||||
// The standard icons do does not look good on high DPI screens
|
||||
QIcon CloseIcon = _this->style()->standardIcon(QStyle::SP_TitleBarCloseButton);
|
||||
QPixmap normalPixmap = _this->style()->standardPixmap(QStyle::SP_TitleBarCloseButton, 0, CloseButton);
|
||||
QPixmap disabledPixmap = internal::createTransparentPixmap(normalPixmap, 0.25);
|
||||
CloseIcon.addPixmap(disabledPixmap, QIcon::Disabled);
|
||||
CloseButton->setIcon(CloseIcon);
|
||||
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
CloseButton->setVisible(false);
|
||||
CloseButton->setToolTip(QObject::tr("Close Tab"));
|
||||
_this->connect(CloseButton, SIGNAL(clicked()), SIGNAL(closeRequested()));
|
||||
|
||||
QFontMetrics fm(TitleLabel->font());
|
||||
int Spacing = qRound(fm.height() / 4.0);
|
||||
|
||||
// Fill the layout
|
||||
QBoxLayout* Layout = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
Layout->setContentsMargins(2 * Spacing,0,0,0);
|
||||
Layout->setSpacing(0);
|
||||
_this->setLayout(Layout);
|
||||
Layout->addWidget(TitleLabel, 1);
|
||||
Layout->addSpacing(Spacing);
|
||||
Layout->addWidget(CloseButton);
|
||||
Layout->addSpacing(qRound(Spacing * 4.0 / 3.0));
|
||||
Layout->setAlignment(Qt::AlignCenter);
|
||||
|
||||
TitleLabel->setVisible(true);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
@@ -160,42 +187,50 @@ void DockWidgetTabPrivate::moveTab(QMouseEvent* ev)
|
||||
|
||||
|
||||
//============================================================================
|
||||
bool DockWidgetTabPrivate::startFloating()
|
||||
bool DockWidgetTabPrivate::startFloating(eDragState DraggingState)
|
||||
{
|
||||
qDebug() << "isFloating " << DockWidget->dockContainer()->isFloating();
|
||||
qDebug() << "areaCount " << DockWidget->dockContainer()->dockAreaCount();
|
||||
qDebug() << "widgetCount " << DockWidget->dockAreaWidget()->count();
|
||||
auto dockContainer = DockWidget->dockContainer();
|
||||
qDebug() << "isFloating " << dockContainer->isFloating();
|
||||
qDebug() << "areaCount " << dockContainer->dockAreaCount();
|
||||
qDebug() << "widgetCount " << DockWidget->dockAreaWidget()->dockWidgetsCount();
|
||||
// if this is the last dock widget inside of this floating widget,
|
||||
// then it does not make any sense, to make it floating because
|
||||
// it is already floating
|
||||
if (DockWidget->dockContainer()->isFloating()
|
||||
&& (DockWidget->dockContainer()->visibleDockAreaCount() == 1)
|
||||
&& (DockWidget->dockAreaWidget()->count() == 1))
|
||||
if (dockContainer->isFloating()
|
||||
&& (dockContainer->visibleDockAreaCount() == 1)
|
||||
&& (DockWidget->dockAreaWidget()->dockWidgetsCount() == 1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
qDebug() << "startFloating";
|
||||
DragState = DraggingFloatingWidget;
|
||||
DragState = DraggingState;
|
||||
QSize Size = DockArea->size();
|
||||
CFloatingDockContainer* FloatingWidget = nullptr;
|
||||
if (DockArea->count() > 1)
|
||||
if (DockArea->dockWidgetsCount() > 1)
|
||||
{
|
||||
// If section widget has multiple tabs, we take only one tab
|
||||
FloatingWidget = new CFloatingDockContainer(DockWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "DockWidgetTabPrivate::startFloating DockArea";
|
||||
// If section widget has only one content widget, we can move the complete
|
||||
// dock area into floating widget
|
||||
FloatingWidget = new CFloatingDockContainer(DockArea);
|
||||
}
|
||||
|
||||
FloatingWidget->startFloating(DragStartMousePosition, Size);
|
||||
auto Overlay = DockWidget->dockManager()->containerOverlay();
|
||||
Overlay->setAllowedAreas(OuterDockAreas);
|
||||
this->FloatingWidget = FloatingWidget;
|
||||
if (DraggingFloatingWidget == DraggingState)
|
||||
{
|
||||
FloatingWidget->startDragging(DragStartMousePosition, Size);
|
||||
auto Overlay = DockWidget->dockManager()->containerOverlay();
|
||||
Overlay->setAllowedAreas(OuterDockAreas);
|
||||
this->FloatingWidget = FloatingWidget;
|
||||
}
|
||||
else
|
||||
{
|
||||
FloatingWidget->initFloatingGeometry(DragStartMousePosition, Size);
|
||||
}
|
||||
DockWidget->emitTopLevelChanged(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -223,10 +258,10 @@ void CDockWidgetTab::mousePressEvent(QMouseEvent* ev)
|
||||
{
|
||||
if (ev->button() == Qt::LeftButton)
|
||||
{
|
||||
qDebug() << "CDockWidgetTab::mousePressEvent";
|
||||
ev->accept();
|
||||
d->DragStartMousePosition = ev->pos();
|
||||
d->DragState = DraggingMousePressed;
|
||||
emit clicked();
|
||||
return;
|
||||
}
|
||||
QFrame::mousePressEvent(ev);
|
||||
@@ -237,27 +272,12 @@ void CDockWidgetTab::mousePressEvent(QMouseEvent* ev)
|
||||
//============================================================================
|
||||
void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev)
|
||||
{
|
||||
qDebug() << "CDockWidgetTab::mouseReleaseEvent";
|
||||
// End of tab moving, change order now
|
||||
// End of tab moving, emit signal
|
||||
if (d->isDraggingState(DraggingTab) && d->DockArea)
|
||||
{
|
||||
// Find tab under mouse
|
||||
QPoint pos = d->DockArea->mapFromGlobal(ev->globalPos());
|
||||
int fromIndex = d->DockArea->tabIndex(d->DockWidget);
|
||||
int toIndex = d->DockArea->indexOfContentByTitlePos(pos, this);
|
||||
if (-1 == toIndex)
|
||||
{
|
||||
toIndex = d->DockArea->count() - 1;
|
||||
}
|
||||
qDebug() << "Move tab from " << fromIndex << " to " << toIndex;
|
||||
d->DockArea->reorderDockWidget(fromIndex, toIndex);
|
||||
emit moved(ev->globalPos());
|
||||
}
|
||||
|
||||
if (!d->DragStartMousePosition.isNull())
|
||||
{
|
||||
emit clicked();
|
||||
}
|
||||
|
||||
d->DragStartMousePosition = QPoint();
|
||||
d->DragState = DraggingInactive;
|
||||
QFrame::mouseReleaseEvent(ev);
|
||||
@@ -274,7 +294,7 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
|
||||
return;
|
||||
}
|
||||
|
||||
// move floating winwdow
|
||||
// move floating window
|
||||
if (d->isDraggingState(DraggingFloatingWidget))
|
||||
{
|
||||
d->FloatingWidget->moveFloating();
|
||||
@@ -290,9 +310,20 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
|
||||
d->moveTab(ev);
|
||||
}
|
||||
|
||||
bool MouseInsideTitleArea = d->titleAreaGeometryContains(ev->globalPos());
|
||||
if (!MouseInsideTitleArea)
|
||||
// Maybe a fixed drag distance is better here ?
|
||||
int DragDistanceY = qAbs(d->DragStartMousePosition.y() - ev->pos().y());
|
||||
if (DragDistanceY >= CDockManager::startDragDistance())
|
||||
{
|
||||
// If this is the last dock area in a dock container with only
|
||||
// one single dock widget it does not make sense to move it to a new
|
||||
// floating widget and leave this one empty
|
||||
if (d->DockArea->dockContainer()->isFloating()
|
||||
&& d->DockArea->openDockWidgetsCount() == 1
|
||||
&& d->DockArea->dockContainer()->visibleDockAreaCount() == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Floating is only allowed for widgets that are movable
|
||||
if (d->DockWidget->features().testFlag(CDockWidget::DockWidgetMovable))
|
||||
{
|
||||
@@ -300,7 +331,7 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (d->DockArea->count() > 1
|
||||
else if (d->DockArea->openDockWidgetsCount() > 1
|
||||
&& (ev->pos() - d->DragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving
|
||||
{
|
||||
d->DragState = DraggingTab;
|
||||
@@ -311,6 +342,22 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidgetTab::contextMenuEvent(QContextMenuEvent* ev)
|
||||
{
|
||||
ev->accept();
|
||||
|
||||
d->DragStartMousePosition = ev->pos();
|
||||
QMenu Menu(this);
|
||||
Menu.addAction(tr("Detach"), this, SLOT(onDetachActionTriggered()));
|
||||
Menu.addSeparator();
|
||||
auto Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested()));
|
||||
Action->setEnabled(isClosable());
|
||||
Menu.addAction(tr("Close Others"), this, SIGNAL(closeOtherTabsRequested()));
|
||||
Menu.exec(mapToGlobal(ev->pos()));
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
bool CDockWidgetTab::isActiveTab() const
|
||||
{
|
||||
@@ -321,6 +368,9 @@ bool CDockWidgetTab::isActiveTab() const
|
||||
//============================================================================
|
||||
void CDockWidgetTab::setActiveTab(bool active)
|
||||
{
|
||||
bool DockWidgetClosable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetClosable);
|
||||
bool TabHasCloseButton = d->testConfigFlag(CDockManager::ActiveTabHasCloseButton);
|
||||
d->CloseButton->setVisible(active && DockWidgetClosable && TabHasCloseButton);
|
||||
if (d->IsActiveTab == active)
|
||||
{
|
||||
return;
|
||||
@@ -361,9 +411,36 @@ CDockAreaWidget* CDockWidgetTab::dockAreaWidget() const
|
||||
//============================================================================
|
||||
void CDockWidgetTab::setIcon(const QIcon& Icon)
|
||||
{
|
||||
QBoxLayout* Layout = qobject_cast<QBoxLayout*>(layout());
|
||||
if (!d->IconLabel && Icon.isNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!d->IconLabel)
|
||||
{
|
||||
d->IconLabel = new QLabel();
|
||||
d->IconLabel->setAlignment(Qt::AlignVCenter);
|
||||
d->IconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
d->IconLabel->setToolTip(d->TitleLabel->toolTip());
|
||||
Layout->insertWidget(0, d->IconLabel, Qt::AlignVCenter);
|
||||
Layout->insertSpacing(1, qRound(1.5 * Layout->contentsMargins().left() / 2.0));
|
||||
}
|
||||
else if (Icon.isNull())
|
||||
{
|
||||
// Remove icon label and spacer item
|
||||
Layout->removeWidget(d->IconLabel);
|
||||
Layout->removeItem(Layout->itemAt(0));
|
||||
delete d->IconLabel;
|
||||
d->IconLabel = nullptr;
|
||||
}
|
||||
|
||||
d->Icon = Icon;
|
||||
d->IconLabel->setPixmap(Icon.pixmap(this->windowHandle(), QSize(16, 16)));
|
||||
d->IconLabel->setVisible(true);
|
||||
if (d->IconLabel)
|
||||
{
|
||||
d->IconLabel->setPixmap(Icon.pixmap(this->windowHandle(), QSize(16, 16)));
|
||||
d->IconLabel->setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -372,6 +449,53 @@ const QIcon& CDockWidgetTab::icon() const
|
||||
{
|
||||
return d->Icon;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QString CDockWidgetTab::text() const
|
||||
{
|
||||
return d->TitleLabel->text();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
// If this is the last dock area in a dock container it does not make
|
||||
// sense to move it to a new floating widget and leave this one
|
||||
// empty
|
||||
if (!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1)
|
||||
{
|
||||
d->DragStartMousePosition = event->pos();
|
||||
d->startFloating(DraggingInactive);
|
||||
}
|
||||
|
||||
Super::mouseDoubleClickEvent(event);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidgetTab::setVisible(bool visible)
|
||||
{
|
||||
// Just here for debugging to insert debug output
|
||||
Super::setVisible(visible);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
bool CDockWidgetTab::isClosable() const
|
||||
{
|
||||
return d->DockWidget && d->DockWidget->features().testFlag(CDockWidget::DockWidgetClosable);
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
void CDockWidgetTab::onDetachActionTriggered()
|
||||
{
|
||||
d->DragStartMousePosition = mapFromGlobal(QCursor::pos());
|
||||
d->startFloating(DraggingInactive);
|
||||
}
|
||||
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -54,12 +54,22 @@ private:
|
||||
DockWidgetTabPrivate* d; ///< private data (pimpl)
|
||||
friend struct DockWidgetTabPrivate;
|
||||
|
||||
private slots:
|
||||
void onDetachActionTriggered();
|
||||
|
||||
protected:
|
||||
virtual void mousePressEvent(QMouseEvent* ev) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent* ev) override;
|
||||
virtual void mouseMoveEvent(QMouseEvent* ev) override;
|
||||
virtual void contextMenuEvent(QContextMenuEvent* ev) override;
|
||||
|
||||
/**
|
||||
* Double clicking the tab widget makes the assigned dock widget floating
|
||||
*/
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
public:
|
||||
using Super = QFrame;
|
||||
/**
|
||||
* Default Constructor
|
||||
* param[in] DockWidget The dock widget this title bar belongs to
|
||||
@@ -110,9 +120,25 @@ public:
|
||||
*/
|
||||
const QIcon& icon() const;
|
||||
|
||||
/**
|
||||
* Returns the tab text
|
||||
*/
|
||||
QString text() const;
|
||||
|
||||
/**
|
||||
* This function returns true if the assigned dock widget is closeable
|
||||
*/
|
||||
bool isClosable() const;
|
||||
|
||||
public slots:
|
||||
virtual void setVisible(bool visible) override;
|
||||
|
||||
signals:
|
||||
void activeTabChanged();
|
||||
void clicked();
|
||||
void closeRequested();
|
||||
void closeOtherTabsRequested();
|
||||
void moved(const QPoint& GlobalPos);
|
||||
}; // class DockWidgetTab
|
||||
}
|
||||
// namespace ads
|
||||
|
||||
200
src/ElidingLabel.cpp
Normal file
@@ -0,0 +1,200 @@
|
||||
/*******************************************************************************
|
||||
** 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 ElidingLabel.cpp
|
||||
/// \author Uwe Kindler
|
||||
/// \date 05.11.2018
|
||||
/// \brief Implementation of CElidingLabel
|
||||
//============================================================================
|
||||
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <ElidingLabel.h>
|
||||
#include <QMouseEvent>
|
||||
|
||||
|
||||
namespace ads
|
||||
{
|
||||
/**
|
||||
* Private data of public CClickableLabel
|
||||
*/
|
||||
struct ElidingLabelPrivate
|
||||
{
|
||||
CElidingLabel* _this;
|
||||
Qt::TextElideMode ElideMode = Qt::ElideNone;
|
||||
QString Text;
|
||||
|
||||
ElidingLabelPrivate(CElidingLabel* _public) : _this(_public) {}
|
||||
|
||||
void elideText(int Width);
|
||||
|
||||
/**
|
||||
* Convenience function to check if the
|
||||
*/
|
||||
bool isModeElideNone() const
|
||||
{
|
||||
return Qt::ElideNone == ElideMode;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//============================================================================
|
||||
void ElidingLabelPrivate::elideText(int Width)
|
||||
{
|
||||
if (isModeElideNone())
|
||||
{
|
||||
return;
|
||||
}
|
||||
QFontMetrics fm = _this->fontMetrics();
|
||||
QString str = fm.elidedText(Text, ElideMode, Width - _this->margin() * 2 - _this->indent());
|
||||
if (str == "…")
|
||||
{
|
||||
str = Text.at(0);
|
||||
}
|
||||
_this->QLabel::setText(str);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CElidingLabel::CElidingLabel(QWidget* parent, Qt::WindowFlags f)
|
||||
: QLabel(parent, f),
|
||||
d(new ElidingLabelPrivate(this))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CElidingLabel::CElidingLabel(const QString& text, QWidget* parent, Qt::WindowFlags f)
|
||||
: QLabel(text, parent,f),
|
||||
d(new ElidingLabelPrivate(this))
|
||||
{
|
||||
d->Text = text;
|
||||
setToolTip(text);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CElidingLabel::~CElidingLabel()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
Qt::TextElideMode CElidingLabel::elideMode() const
|
||||
{
|
||||
return d->ElideMode;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CElidingLabel::setElideMode(Qt::TextElideMode mode)
|
||||
{
|
||||
d->ElideMode = mode;
|
||||
d->elideText(size().width());
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CElidingLabel::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
Super::mouseReleaseEvent(event);
|
||||
if (event->button() != Qt::LeftButton)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
emit clicked();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CElidingLabel::mouseDoubleClickEvent( QMouseEvent *ev )
|
||||
{
|
||||
Q_UNUSED(ev)
|
||||
emit doubleClicked();
|
||||
Super::mouseDoubleClickEvent(ev);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CElidingLabel::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
if (!d->isModeElideNone())
|
||||
{
|
||||
d->elideText(event->size().width());
|
||||
}
|
||||
Super::resizeEvent(event);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QSize CElidingLabel::minimumSizeHint() const
|
||||
{
|
||||
if (pixmap() != nullptr || d->isModeElideNone())
|
||||
{
|
||||
return QLabel::minimumSizeHint();
|
||||
}
|
||||
const QFontMetrics &fm = fontMetrics();
|
||||
QSize size(fm.width(d->Text.left(2) + "…"), fm.height());
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QSize CElidingLabel::sizeHint() const
|
||||
{
|
||||
if (pixmap() != nullptr || d->isModeElideNone())
|
||||
{
|
||||
return QLabel::sizeHint();
|
||||
}
|
||||
const QFontMetrics& fm = fontMetrics();
|
||||
QSize size(fm.width(d->Text), QLabel::sizeHint().height());
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CElidingLabel::setText(const QString &text)
|
||||
{
|
||||
if (d->isModeElideNone())
|
||||
{
|
||||
Super::setText(text);
|
||||
}
|
||||
else
|
||||
{
|
||||
d->Text = text;
|
||||
setToolTip( text );
|
||||
d->elideText(this->size().width());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QString CElidingLabel::text() const
|
||||
{
|
||||
return d->Text;
|
||||
}
|
||||
} // namespace QtLabb
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// EOF ClickableLabel.cpp
|
||||
97
src/ElidingLabel.h
Normal file
@@ -0,0 +1,97 @@
|
||||
#ifndef ElidingLabelH
|
||||
#define ElidingLabelH
|
||||
/*******************************************************************************
|
||||
** 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 ElidingLabel.h
|
||||
/// \author Uwe Kindler
|
||||
/// \date 05.11.2018
|
||||
/// \brief Declaration of CElidingLabel
|
||||
//============================================================================
|
||||
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <QLabel>
|
||||
|
||||
namespace ads
|
||||
{
|
||||
struct ElidingLabelPrivate;
|
||||
|
||||
/**
|
||||
* A QLabel that supports eliding text.
|
||||
* Because the functions setText() and text() are no virtual functions setting
|
||||
* and reading the text via a pointer to the base class QLabel does not work
|
||||
* properly
|
||||
*/
|
||||
class CElidingLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
ElidingLabelPrivate* d;
|
||||
friend struct ElidingLabelPrivate;
|
||||
|
||||
protected:
|
||||
virtual void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
virtual void resizeEvent( QResizeEvent *event ) override;
|
||||
virtual void mouseDoubleClickEvent( QMouseEvent *ev ) override;
|
||||
|
||||
public:
|
||||
using Super = QLabel;
|
||||
|
||||
CElidingLabel(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
CElidingLabel(const QString& text, QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
virtual ~CElidingLabel();
|
||||
|
||||
/**
|
||||
* Returns the text elide mode.
|
||||
* The default mode is ElideNone
|
||||
*/
|
||||
Qt::TextElideMode elideMode() const;
|
||||
|
||||
/**
|
||||
* Sets the text elide mode
|
||||
*/
|
||||
void setElideMode(Qt::TextElideMode mode);
|
||||
|
||||
|
||||
public: // reimplements QLabel ----------------------------------------------
|
||||
virtual QSize minimumSizeHint() const override;
|
||||
virtual QSize sizeHint() const override;
|
||||
void setText(const QString &text);
|
||||
QString text() const;
|
||||
|
||||
signals:
|
||||
/**
|
||||
* This signal is emitted if the user clicks on the label (i.e. pressed
|
||||
* down then released while the mouse cursor is inside the label)
|
||||
*/
|
||||
void clicked();
|
||||
|
||||
/**
|
||||
* This signal is emitted if the user does a double click on the label
|
||||
*/
|
||||
void doubleClicked();
|
||||
}; //class CElidingLabel
|
||||
|
||||
} // namespace QtLabb
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
#endif // ElidingLabelH
|
||||
@@ -36,6 +36,8 @@
|
||||
#include <QPointer>
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
#include <QAbstractButton>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#include "DockContainerWidget.h"
|
||||
#include "DockAreaWidget.h"
|
||||
@@ -48,7 +50,6 @@
|
||||
namespace ads
|
||||
{
|
||||
static unsigned int zOrderCounter = 0;
|
||||
|
||||
/**
|
||||
* Private data class of CFloatingDockContainer class (pimpl)
|
||||
*/
|
||||
@@ -58,8 +59,7 @@ struct FloatingDockContainerPrivate
|
||||
CDockContainerWidget* DockContainer;
|
||||
unsigned int zOrderIndex = ++zOrderCounter;
|
||||
QPointer<CDockManager> DockManager;
|
||||
bool DraggingActive = false;
|
||||
bool NonClientAreaMouseButtonPress = false;
|
||||
eDragState DraggingState = DraggingInactive;
|
||||
QPoint DragStartMousePosition;
|
||||
CDockContainerWidget* DropContainer = nullptr;
|
||||
CDockAreaWidget* SingleDockArea = nullptr;
|
||||
@@ -71,10 +71,24 @@ struct FloatingDockContainerPrivate
|
||||
|
||||
void titleMouseReleaseEvent();
|
||||
void updateDropOverlays(const QPoint& GlobalPos);
|
||||
void setDraggingActive(bool Active);
|
||||
|
||||
/**
|
||||
* Tests is a certain state is active
|
||||
*/
|
||||
bool isState(eDragState StateId) const
|
||||
{
|
||||
return StateId == DraggingState;
|
||||
}
|
||||
|
||||
void setState(eDragState StateId)
|
||||
{
|
||||
DraggingState = StateId;
|
||||
}
|
||||
};
|
||||
// struct FloatingDockContainerPrivate
|
||||
|
||||
|
||||
|
||||
//============================================================================
|
||||
FloatingDockContainerPrivate::FloatingDockContainerPrivate(CFloatingDockContainer* _public) :
|
||||
_this(_public)
|
||||
@@ -87,7 +101,7 @@ FloatingDockContainerPrivate::FloatingDockContainerPrivate(CFloatingDockContaine
|
||||
//============================================================================
|
||||
void FloatingDockContainerPrivate::titleMouseReleaseEvent()
|
||||
{
|
||||
setDraggingActive(false);
|
||||
setState(DraggingInactive);
|
||||
if (!DropContainer)
|
||||
{
|
||||
return;
|
||||
@@ -98,15 +112,21 @@ void FloatingDockContainerPrivate::titleMouseReleaseEvent()
|
||||
{
|
||||
// Resize the floating widget to the size of the highlighted drop area
|
||||
// rectangle
|
||||
QRect Rect = DockManager->containerOverlay()->dropOverlayRect();
|
||||
if (!Rect.isValid())
|
||||
CDockOverlay* Overlay = DockManager->containerOverlay();
|
||||
if (!Overlay->dropOverlayRect().isValid())
|
||||
{
|
||||
Rect = DockManager->dockAreaOverlay()->rect();
|
||||
Overlay = DockManager->dockAreaOverlay();
|
||||
}
|
||||
|
||||
QRect Rect = Overlay->dropOverlayRect();
|
||||
int FrameWidth = (_this->frameSize().width() - _this->rect().width()) / 2;
|
||||
int TitleBarHeight = _this->frameSize().height() - _this->rect().height() - FrameWidth;
|
||||
if (Rect.isValid())
|
||||
{
|
||||
_this->resize(Rect.size());
|
||||
QPoint TopLeft = Overlay->mapToGlobal(Rect.topLeft());
|
||||
TopLeft.ry() += TitleBarHeight;
|
||||
_this->setGeometry(QRect(TopLeft, QSize(Rect.width(), Rect.height() - TitleBarHeight)));
|
||||
QApplication::processEvents();
|
||||
}
|
||||
DropContainer->dropFloatingWidget(_this, QCursor::pos());
|
||||
}
|
||||
@@ -164,7 +184,7 @@ void FloatingDockContainerPrivate::updateDropOverlays(const QPoint& GlobalPos)
|
||||
ContainerOverlay->setAllowedAreas(VisibleDockAreas > 1 ?
|
||||
OuterDockAreas : AllDockAreas);
|
||||
DockWidgetArea ContainerArea = ContainerOverlay->showOverlay(TopContainer);
|
||||
|
||||
ContainerOverlay->enableDropPreview(ContainerArea != InvalidDockWidgetArea);
|
||||
auto DockArea = TopContainer->dockAreaAt(GlobalPos);
|
||||
if (DockArea && DockArea->isVisible() && VisibleDockAreas > 0)
|
||||
{
|
||||
@@ -194,17 +214,6 @@ void FloatingDockContainerPrivate::updateDropOverlays(const QPoint& GlobalPos)
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void FloatingDockContainerPrivate::setDraggingActive(bool Active)
|
||||
{
|
||||
DraggingActive = Active;
|
||||
if (!DraggingActive)
|
||||
{
|
||||
NonClientAreaMouseButtonPress = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CFloatingDockContainer::CFloatingDockContainer(CDockManager* DockManager) :
|
||||
QWidget(DockManager, Qt::Window),
|
||||
@@ -280,18 +289,18 @@ void CFloatingDockContainer::changeEvent(QEvent *event)
|
||||
void CFloatingDockContainer::moveEvent(QMoveEvent *event)
|
||||
{
|
||||
QWidget::moveEvent(event);
|
||||
if (!qApp->mouseButtons().testFlag(Qt::LeftButton))
|
||||
switch (d->DraggingState)
|
||||
{
|
||||
if (d->DraggingActive)
|
||||
{
|
||||
d->setDraggingActive(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
case DraggingMousePressed:
|
||||
d->setState(DraggingFloatingWidget);
|
||||
d->updateDropOverlays(QCursor::pos());
|
||||
break;
|
||||
|
||||
if (d->DraggingActive)
|
||||
{
|
||||
d->updateDropOverlays(QCursor::pos());
|
||||
case DraggingFloatingWidget:
|
||||
d->updateDropOverlays(QCursor::pos());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,25 +309,26 @@ void CFloatingDockContainer::moveEvent(QMoveEvent *event)
|
||||
void CFloatingDockContainer::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
qDebug() << "CFloatingDockContainer closeEvent";
|
||||
d->setDraggingActive(false);
|
||||
d->setState(DraggingInactive);
|
||||
|
||||
if (isClosable())
|
||||
QWidget::closeEvent(event);
|
||||
{
|
||||
QWidget::closeEvent(event);
|
||||
}
|
||||
else
|
||||
{
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CFloatingDockContainer::hideEvent(QHideEvent *event)
|
||||
{
|
||||
qDebug() << "CFloatingDockContainer hideEvent";
|
||||
QWidget::hideEvent(event);
|
||||
auto OpenDockAreas = d->DockContainer->openedDockAreas();
|
||||
for (auto DockArea : OpenDockAreas)
|
||||
Super::hideEvent(event);
|
||||
for (auto DockArea : d->DockContainer->openedDockAreas())
|
||||
{
|
||||
auto OpenDockWidgets = DockArea->openedDockWidgets();
|
||||
for (auto DockWidget : OpenDockWidgets)
|
||||
for (auto DockWidget : DockArea->openedDockWidgets())
|
||||
{
|
||||
DockWidget->toggleView(false);
|
||||
}
|
||||
@@ -329,56 +339,73 @@ void CFloatingDockContainer::hideEvent(QHideEvent *event)
|
||||
//============================================================================
|
||||
void CFloatingDockContainer::showEvent(QShowEvent *event)
|
||||
{
|
||||
QWidget::showEvent(event);
|
||||
CDockContainerWidget* DockContainer = dockContainer();
|
||||
for (int i = 0; i < DockContainer->dockAreaCount(); ++i)
|
||||
Super::showEvent(event);
|
||||
/*for (auto DockArea : d->DockContainer->openedDockAreas())
|
||||
{
|
||||
auto DockArea = DockContainer->dockArea(i);
|
||||
for (auto DockWidget : DockArea->openedDockWidgets())
|
||||
{
|
||||
DockWidget->setToggleViewActionChecked(true);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
bool CFloatingDockContainer::event(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::NonClientAreaMouseButtonPress)
|
||||
switch (d->DraggingState)
|
||||
{
|
||||
if (QGuiApplication::mouseButtons() == Qt::LeftButton)
|
||||
case DraggingInactive:
|
||||
if (e->type() == QEvent::NonClientAreaMouseButtonPress && QGuiApplication::mouseButtons() == Qt::LeftButton)
|
||||
{
|
||||
qDebug() << "FloatingWidget::event Event::NonClientAreaMouseButtonPress" << e->type();
|
||||
d->setDraggingActive(true);
|
||||
d->NonClientAreaMouseButtonPress = true;
|
||||
d->setState(DraggingMousePressed);
|
||||
}
|
||||
}
|
||||
else if (e->type() == QEvent::NonClientAreaMouseButtonDblClick)
|
||||
{
|
||||
qDebug() << "FloatingWidget::event QEvent::NonClientAreaMouseButtonDblClick";
|
||||
d->setDraggingActive(false);
|
||||
}
|
||||
else if ((e->type() == QEvent::NonClientAreaMouseButtonRelease) && d->DraggingActive)
|
||||
{
|
||||
qDebug() << "FloatingWidget::event QEvent::NonClientAreaMouseButtonRelease";
|
||||
d->titleMouseReleaseEvent();
|
||||
}
|
||||
else if (d->NonClientAreaMouseButtonPress && (e->type() == QEvent::Resize))
|
||||
{
|
||||
// If user resizes the floating widget, we do not want to show any
|
||||
// drop overlays or drop overlay icons. If the window is maximized,
|
||||
// then dragging the window via title bar will cause the widget to
|
||||
// leave the maximized state. This in turn will trigger a resize event.
|
||||
// To know, if the resize event was triggered by user via moving a
|
||||
// corner of the window frame or if it was caused by a windows state
|
||||
// change, we check, if we are not in maximized state.
|
||||
if (!isMaximized())
|
||||
break;
|
||||
|
||||
case DraggingMousePressed:
|
||||
switch (e->type())
|
||||
{
|
||||
d->setDraggingActive(false);
|
||||
case QEvent::NonClientAreaMouseButtonDblClick:
|
||||
qDebug() << "FloatingWidget::event QEvent::NonClientAreaMouseButtonDblClick";
|
||||
d->setState(DraggingInactive);
|
||||
break;
|
||||
|
||||
case QEvent::Resize:
|
||||
// If the first event after the mouse press is a resize event, then
|
||||
// the user resizes the window instead of dragging it around.
|
||||
// But there is one exception. If the window is maximized,
|
||||
// then dragging the window via title bar will cause the widget to
|
||||
// leave the maximized state. This in turn will trigger a resize event.
|
||||
// To know, if the resize event was triggered by user via moving a
|
||||
// corner of the window frame or if it was caused by a windows state
|
||||
// change, we check, if we are not in maximized state.
|
||||
if (!isMaximized())
|
||||
{
|
||||
d->setState(DraggingInactive);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case DraggingFloatingWidget:
|
||||
if (e->type() == QEvent::NonClientAreaMouseButtonRelease)
|
||||
{
|
||||
qDebug() << "FloatingWidget::event QEvent::NonClientAreaMouseButtonRelease";
|
||||
d->titleMouseReleaseEvent();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#if (ADS_DEBUG_LEVEL > 0)
|
||||
qDebug() << "CFloatingDockContainer::event " << e->type();
|
||||
#endif
|
||||
return QWidget::event(e);
|
||||
}
|
||||
|
||||
@@ -387,7 +414,7 @@ bool CFloatingDockContainer::event(QEvent *e)
|
||||
bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
Q_UNUSED(watched);
|
||||
if (event->type() == QEvent::MouseButtonRelease && d->DraggingActive)
|
||||
if (event->type() == QEvent::MouseButtonRelease && d->isState(DraggingFloatingWidget))
|
||||
{
|
||||
qDebug() << "FloatingWidget::eventFilter QEvent::MouseButtonRelease";
|
||||
d->titleMouseReleaseEvent();
|
||||
@@ -398,14 +425,15 @@ bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event)
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CFloatingDockContainer::startFloating(const QPoint& Pos, const QSize& Size)
|
||||
void CFloatingDockContainer::startFloating(const QPoint& DragStartMousePos, const QSize& Size,
|
||||
eDragState DragState)
|
||||
{
|
||||
resize(Size);
|
||||
d->setDraggingActive(true);
|
||||
QPoint TargetPos = QCursor::pos() - Pos;
|
||||
move(TargetPos);
|
||||
d->setState(DragState);
|
||||
d->DragStartMousePosition = DragStartMousePos;
|
||||
moveFloating();
|
||||
show();
|
||||
d->DragStartMousePosition = Pos;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -421,19 +449,7 @@ void CFloatingDockContainer::moveFloating()
|
||||
//============================================================================
|
||||
bool CFloatingDockContainer::isClosable() const
|
||||
{
|
||||
auto OpenDockAreas = d->DockContainer->openedDockAreas();
|
||||
for (auto DockArea : OpenDockAreas)
|
||||
{
|
||||
auto OpenDockWidgets = DockArea->openedDockWidgets();
|
||||
for (auto DockWidget : OpenDockWidgets)
|
||||
{
|
||||
if (!DockWidget->features().testFlag(CDockWidget::DockWidgetClosable))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return d->DockContainer->features().testFlag(CDockWidget::DockWidgetClosable);
|
||||
}
|
||||
|
||||
|
||||
@@ -441,9 +457,10 @@ bool CFloatingDockContainer::isClosable() const
|
||||
void CFloatingDockContainer::onDockAreasAddedOrRemoved()
|
||||
{
|
||||
qDebug() << "CFloatingDockContainer::onDockAreasAddedOrRemoved()";
|
||||
if (d->DockContainer->dockAreaCount() == 1)
|
||||
auto TopLevelDockArea = d->DockContainer->topLevelDockArea();
|
||||
if (TopLevelDockArea)
|
||||
{
|
||||
d->SingleDockArea = d->DockContainer->dockArea(0);
|
||||
d->SingleDockArea = TopLevelDockArea;
|
||||
this->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle());
|
||||
connect(d->SingleDockArea, SIGNAL(currentChanged(int)), this,
|
||||
SLOT(onDockAreaCurrentChanged(int)));
|
||||
@@ -461,6 +478,21 @@ void CFloatingDockContainer::onDockAreasAddedOrRemoved()
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CFloatingDockContainer::updateWindowTitle()
|
||||
{
|
||||
auto TopLevelDockArea = d->DockContainer->topLevelDockArea();
|
||||
if (TopLevelDockArea)
|
||||
{
|
||||
this->setWindowTitle(TopLevelDockArea->currentDockWidget()->windowTitle());
|
||||
}
|
||||
else
|
||||
{
|
||||
this->setWindowTitle(qApp->applicationDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CFloatingDockContainer::onDockAreaCurrentChanged(int Index)
|
||||
{
|
||||
@@ -476,11 +508,33 @@ bool CFloatingDockContainer::restoreState(QXmlStreamReader& Stream, bool Testing
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
onDockAreasAddedOrRemoved();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
bool CFloatingDockContainer::hasTopLevelDockWidget() const
|
||||
{
|
||||
return d->DockContainer->hasTopLevelDockWidget();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockWidget* CFloatingDockContainer::topLevelDockWidget() const
|
||||
{
|
||||
return d->DockContainer->topLevelDockWidget();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QList<CDockWidget*> CFloatingDockContainer::dockWidgets() const
|
||||
{
|
||||
return d->DockContainer->dockWidgets();
|
||||
}
|
||||
|
||||
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -47,6 +47,8 @@ class CDockManager;
|
||||
class CDockAreaTabBar;
|
||||
class CDockWidgetTab;
|
||||
struct DockWidgetTabPrivate;
|
||||
class CDockAreaTitleBar;
|
||||
struct DockAreaTitleBarPrivate;
|
||||
|
||||
/**
|
||||
* This implements a floating widget that is a dock container that accepts
|
||||
@@ -64,6 +66,10 @@ private:
|
||||
friend class CDockAreaTabBar;
|
||||
friend struct DockWidgetTabPrivate;
|
||||
friend class CDockWidgetTab;
|
||||
friend class CDockAreaTitleBar;
|
||||
friend struct DockAreaTitleBarPrivate;
|
||||
friend class CDockWidget;
|
||||
friend class CDockAreaWidget;
|
||||
|
||||
private slots:
|
||||
void onDockAreasAddedOrRemoved();
|
||||
@@ -75,7 +81,25 @@ protected:
|
||||
* Use moveToGlobalPos() to move the widget to a new position
|
||||
* depending on the start position given in Pos parameter
|
||||
*/
|
||||
void startFloating(const QPoint& Pos, const QSize& Size = QSize());
|
||||
void startFloating(const QPoint& DragStartMousePos, const QSize& Size,
|
||||
eDragState DragState);
|
||||
|
||||
/**
|
||||
* Call this function to start dragging the floating widget
|
||||
*/
|
||||
void startDragging(const QPoint& DragStartMousePos, const QSize& Size)
|
||||
{
|
||||
startFloating(DragStartMousePos, Size, DraggingFloatingWidget);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this function if you just want to initialize the position
|
||||
* and size of the floating widget
|
||||
*/
|
||||
void initFloatingGeometry(const QPoint& DragStartMousePos, const QSize& Size)
|
||||
{
|
||||
startFloating(DragStartMousePos, Size, DraggingInactive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the widget to a new position relative to the position given when
|
||||
@@ -91,6 +115,11 @@ protected:
|
||||
*/
|
||||
bool restoreState(QXmlStreamReader& Stream, bool Testing);
|
||||
|
||||
/**
|
||||
* Call this function to update the window title
|
||||
*/
|
||||
void updateWindowTitle();
|
||||
|
||||
|
||||
protected: // reimplements QWidget
|
||||
virtual void changeEvent(QEvent *event) override;
|
||||
@@ -102,6 +131,8 @@ protected: // reimplements QWidget
|
||||
virtual bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
public:
|
||||
using Super = QWidget;
|
||||
|
||||
/**
|
||||
* Create empty flatingb widget - required for restore state
|
||||
*/
|
||||
@@ -132,6 +163,28 @@ public:
|
||||
* It can be closed, if all dock widgets in all dock areas can be closed
|
||||
*/
|
||||
bool isClosable() const;
|
||||
|
||||
/**
|
||||
* This function returns true, if this floating widget has only one single
|
||||
* visible dock widget in a single visible dock area.
|
||||
* The single dock widget is a real top level floating widget because no
|
||||
* other widgets are docked.
|
||||
*/
|
||||
bool hasTopLevelDockWidget() const;
|
||||
|
||||
/**
|
||||
* This function returns the first dock widget in the first dock area.
|
||||
* If the function hasSingleDockWidget() returns true, then this function
|
||||
* returns this single dock widget.
|
||||
*/
|
||||
CDockWidget* topLevelDockWidget() const;
|
||||
|
||||
/**
|
||||
* This function returns a list of all dock widget in this floating widget.
|
||||
* This is a simple convenience function that simply calls the dockWidgets()
|
||||
* function of the internal container widget.
|
||||
*/
|
||||
QList<CDockWidget*> dockWidgets() const;
|
||||
}; // class FloatingDockContainer
|
||||
}
|
||||
// namespace ads
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/ads">
|
||||
<file>stylesheets/default.css</file>
|
||||
<file>images/close-button.svg</file>
|
||||
<file>images/close-button-disabled.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <QVariant>
|
||||
#include <QPainter>
|
||||
|
||||
#include "DockSplitter.h"
|
||||
#include "ads_globals.h"
|
||||
@@ -39,16 +40,6 @@ namespace ads
|
||||
|
||||
namespace internal
|
||||
{
|
||||
//============================================================================
|
||||
QSplitter* newSplitter(Qt::Orientation orientation, QWidget* parent)
|
||||
{
|
||||
QSplitter* s = new CDockSplitter(orientation, parent);
|
||||
s->setProperty("ads-splitter", QVariant(true));
|
||||
s->setChildrenCollapsible(false);
|
||||
s->setOpaqueResize(false);
|
||||
return s;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void replaceSplitterWidget(QSplitter* Splitter, QWidget* From, QWidget* To)
|
||||
{
|
||||
@@ -73,6 +64,33 @@ CDockInsertParam dockAreaInsertParameters(DockWidgetArea Area)
|
||||
return CDockInsertParam(Qt::Vertical, false);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QPixmap createTransparentPixmap(const QPixmap& Source, qreal Opacity)
|
||||
{
|
||||
QPixmap TransparentPixmap(Source.size());
|
||||
TransparentPixmap.fill(Qt::transparent);
|
||||
QPainter p(&TransparentPixmap);
|
||||
p.setOpacity(Opacity);
|
||||
p.drawPixmap(0, 0, Source);
|
||||
return TransparentPixmap;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void hideEmptyParentSplitters(CDockSplitter* Splitter)
|
||||
{
|
||||
while (Splitter && Splitter->isVisible())
|
||||
{
|
||||
if (!Splitter->hasVisibleContent())
|
||||
{
|
||||
Splitter->hide();
|
||||
}
|
||||
Splitter = internal::findParent<CDockSplitter*>(Splitter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace internal
|
||||
} // namespace ads
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
//============================================================================
|
||||
#include <QPair>
|
||||
#include <QtCore/QtGlobal>
|
||||
#include <QPixmap>
|
||||
#include <QWidget>
|
||||
|
||||
#ifdef ADS_SHARED_EXPORT
|
||||
#define ADS_EXPORT Q_DECL_EXPORT
|
||||
@@ -39,10 +41,14 @@
|
||||
#define ADS_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#define ADS_DEBUG_LEVEL 0
|
||||
|
||||
class QSplitter;
|
||||
|
||||
namespace ads
|
||||
{
|
||||
class CDockSplitter;
|
||||
|
||||
enum DockWidgetArea
|
||||
{
|
||||
NoDockWidgetArea = 0x00,
|
||||
@@ -59,20 +65,40 @@ enum DockWidgetArea
|
||||
Q_DECLARE_FLAGS(DockWidgetAreas, DockWidgetArea)
|
||||
|
||||
|
||||
namespace internal
|
||||
enum TitleBarButton
|
||||
{
|
||||
|
||||
TitleBarButtonTabsMenu,
|
||||
TitleBarButtonUndock,
|
||||
TitleBarButtonClose
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function to create new splitter widgets
|
||||
* The different dragging states
|
||||
*/
|
||||
QSplitter* newSplitter(Qt::Orientation orientation, QWidget* parent = 0);
|
||||
enum eDragState
|
||||
{
|
||||
DraggingInactive, //!< DraggingInactive
|
||||
DraggingMousePressed, //!< DraggingMousePressed
|
||||
DraggingTab, //!< DraggingTab
|
||||
DraggingFloatingWidget//!< DraggingFloatingWidget
|
||||
};
|
||||
|
||||
namespace internal
|
||||
{
|
||||
static const bool RestoreTesting = true;
|
||||
static const bool Restore = false;
|
||||
|
||||
/**
|
||||
* Replace the from widget in the given splitter with the To widget
|
||||
*/
|
||||
void replaceSplitterWidget(QSplitter* Splitter, QWidget* From, QWidget* To);
|
||||
|
||||
/**
|
||||
* This function walks the splitter tree upwards to hides all splitters
|
||||
* that do not have visible content
|
||||
*/
|
||||
void hideEmptyParentSplitters(CDockSplitter* FirstParentSplitter);
|
||||
|
||||
/**
|
||||
* Convenience class for QPair to provide better naming than first and
|
||||
* second
|
||||
@@ -95,6 +121,10 @@ CDockInsertParam dockAreaInsertParameters(DockWidgetArea Area);
|
||||
* Searches for the parent widget of the given type.
|
||||
* Returns the parent widget of the given widget or 0 if the widget is not
|
||||
* child of any widget of type T
|
||||
*
|
||||
* It is not safe to use this function in in CDockWidget because only
|
||||
* the current dock widget has a parent. All dock widgets that are not the
|
||||
* current dock widget in a dock area have no parent.
|
||||
*/
|
||||
template <class T>
|
||||
T findParent(const QWidget* w)
|
||||
@@ -102,7 +132,7 @@ T findParent(const QWidget* w)
|
||||
QWidget* parentWidget = w->parentWidget();
|
||||
while (parentWidget)
|
||||
{
|
||||
T ParentImpl = dynamic_cast<T>(parentWidget);
|
||||
T ParentImpl = qobject_cast<T>(parentWidget);
|
||||
if (ParentImpl)
|
||||
{
|
||||
return ParentImpl;
|
||||
@@ -112,6 +142,13 @@ T findParent(const QWidget* w)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a semi transparent pixmap from the given pixmap Source.
|
||||
* The Opacity parameter defines the opacity from completely transparent (0.0)
|
||||
* to completely opaque (1.0)
|
||||
*/
|
||||
QPixmap createTransparentPixmap(const QPixmap& Source, qreal Opacity);
|
||||
|
||||
} // namespace internal
|
||||
} // namespace ads
|
||||
|
||||
|
||||
122
src/images/close-button-disabled.svg
Normal file
@@ -0,0 +1,122 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
version="1.1"
|
||||
id="Capa_1"
|
||||
x="0px"
|
||||
y="0px"
|
||||
width="512"
|
||||
height="512"
|
||||
viewBox="0 0 512 512"
|
||||
xml:space="preserve"
|
||||
sodipodi:docname="close-button-disabled.svg"
|
||||
inkscape:version="0.92.3 (2405546, 2018-03-11)"><metadata
|
||||
id="metadata897"><rdf:RDF><cc:Work
|
||||
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
|
||||
id="defs895" /><sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1017"
|
||||
id="namedview893"
|
||||
showgrid="false"
|
||||
fit-margin-top="0"
|
||||
fit-margin-left="0"
|
||||
fit-margin-right="0"
|
||||
fit-margin-bottom="0"
|
||||
inkscape:zoom="0.85862966"
|
||||
inkscape:cx="345.29142"
|
||||
inkscape:cy="32.731258"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="Capa_1" />
|
||||
<g
|
||||
id="g860"
|
||||
transform="matrix(0.71708683,0,0,0.71708683,128,128)"
|
||||
style="stroke:none;stroke-opacity:1;fill:#000000;fill-opacity:0.50196081">
|
||||
<g
|
||||
id="close"
|
||||
style="stroke:none;stroke-opacity:1;fill:#000000;fill-opacity:0.50196081">
|
||||
<polygon
|
||||
points="357,321.3 214.2,178.5 357,35.7 321.3,0 178.5,142.8 35.7,0 0,35.7 142.8,178.5 0,321.3 35.7,357 178.5,214.2 321.3,357 "
|
||||
id="polygon857"
|
||||
style="stroke:none;stroke-opacity:1;fill:#000000;fill-opacity:0.50196081" />
|
||||
</g>
|
||||
</g>
|
||||
<g
|
||||
id="g862"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g864"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g866"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g868"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g870"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g872"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g874"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g876"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g878"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g880"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g882"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g884"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g886"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g888"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g890"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.9 KiB |
119
src/images/close-button.svg
Normal file
@@ -0,0 +1,119 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
version="1.1"
|
||||
id="Capa_1"
|
||||
x="0px"
|
||||
y="0px"
|
||||
width="512"
|
||||
height="512"
|
||||
viewBox="0 0 512 512"
|
||||
xml:space="preserve"
|
||||
sodipodi:docname="close-button.svg"
|
||||
inkscape:version="0.92.3 (2405546, 2018-03-11)"><metadata
|
||||
id="metadata897"><rdf:RDF><cc:Work
|
||||
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
|
||||
id="defs895" /><sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1017"
|
||||
id="namedview893"
|
||||
showgrid="false"
|
||||
fit-margin-top="0"
|
||||
fit-margin-left="0"
|
||||
fit-margin-right="0"
|
||||
fit-margin-bottom="0"
|
||||
inkscape:zoom="0.85862966"
|
||||
inkscape:cx="345.29142"
|
||||
inkscape:cy="32.731258"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="Capa_1" />
|
||||
<g
|
||||
id="g860"
|
||||
transform="matrix(0.71708683,0,0,0.71708683,128,128)">
|
||||
<g
|
||||
id="close">
|
||||
<polygon
|
||||
points="357,321.3 214.2,178.5 357,35.7 321.3,0 178.5,142.8 35.7,0 0,35.7 142.8,178.5 0,321.3 35.7,357 178.5,214.2 321.3,357 "
|
||||
id="polygon857" />
|
||||
</g>
|
||||
</g>
|
||||
<g
|
||||
id="g862"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g864"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g866"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g868"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g870"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g872"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g874"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g876"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g878"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g880"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g882"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g884"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g886"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g888"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
<g
|
||||
id="g890"
|
||||
transform="translate(0,155)">
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.6 KiB |
14
src/src.pro
@@ -1,7 +1,7 @@
|
||||
ADS_ROOT = $${PWD}/..
|
||||
ADS_OUT_ROOT = $${OUT_PWD}/..
|
||||
|
||||
TARGET = $$qtLibraryTarget(AdvancedDockingSystem)
|
||||
TARGET = $$qtLibraryTarget(qtadvanceddocking)
|
||||
TEMPLATE = lib
|
||||
DESTDIR = $${ADS_OUT_ROOT}/lib
|
||||
QT += core gui widgets
|
||||
@@ -28,6 +28,10 @@ windows {
|
||||
}
|
||||
}
|
||||
|
||||
unix {
|
||||
CONFIG += c++11
|
||||
}
|
||||
|
||||
RESOURCES += ads.qrc
|
||||
|
||||
HEADERS += \
|
||||
@@ -40,7 +44,9 @@ HEADERS += \
|
||||
DockWidgetTab.h \
|
||||
FloatingDockContainer.h \
|
||||
DockOverlay.h \
|
||||
DockSplitter.h
|
||||
DockSplitter.h \
|
||||
DockAreaTitleBar.h \
|
||||
ElidingLabel.h
|
||||
|
||||
|
||||
|
||||
@@ -54,4 +60,6 @@ SOURCES += \
|
||||
DockWidgetTab.cpp \
|
||||
FloatingDockContainer.cpp \
|
||||
DockOverlay.cpp \
|
||||
DockSplitter.cpp
|
||||
DockSplitter.cpp \
|
||||
DockAreaTitleBar.cpp \
|
||||
ElidingLabel.cpp
|
||||
|
||||
@@ -25,18 +25,20 @@ ads--CDockAreaWidget #tabsMenuButton::menu-indicator
|
||||
image: none;
|
||||
}
|
||||
|
||||
|
||||
ads--CDockWidgetTab
|
||||
{
|
||||
background: palette(window);
|
||||
border-color: palette(light);
|
||||
border-style: solid;
|
||||
border-width: 0 1px 0 0;
|
||||
padding: 0 9px;
|
||||
padding: 0 0px;
|
||||
}
|
||||
|
||||
ads--CDockWidgetTab[activeTab="true"]
|
||||
{
|
||||
background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:0.5, stop:0 palette(window), stop:1 palette(light));
|
||||
/*background: palette(highlight);*/
|
||||
}
|
||||
|
||||
ads--CDockWidgetTab QLabel
|
||||
@@ -57,10 +59,38 @@ ads--CDockWidget
|
||||
border-width: 1px 0 0 0;
|
||||
}
|
||||
|
||||
QPushButton#closeButton,
|
||||
QPushButton#tabsMenuButton
|
||||
#tabsMenuButton,
|
||||
#closeButton,
|
||||
#undockButton
|
||||
{
|
||||
padding: 2px;
|
||||
padding: 0 -2px;
|
||||
}
|
||||
|
||||
|
||||
QScrollArea#dockWidgetScrollArea
|
||||
{
|
||||
padding: 0px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
|
||||
#tabCloseButton
|
||||
{
|
||||
margin-top: 2px;
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0px -2px;
|
||||
}
|
||||
|
||||
#tabCloseButton:hover
|
||||
{
|
||||
border: 1px solid rgba(0, 0, 0, 32);
|
||||
background: rgba(0, 0, 0, 16);
|
||||
}
|
||||
|
||||
#tabCloseButton:pressed
|
||||
{
|
||||
background: rgba(0, 0, 0, 32);
|
||||
}
|
||||
|
||||
|
||||
|
||||