diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index ee3bb5b..4404053 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -578,6 +578,14 @@ void MainWindowPrivate::createActions() _this->connect(a, SIGNAL(triggered()), SLOT(createEditor())); ui.menuTests->addAction(a); + a = ui.toolBar->addAction("Create Editor Tab"); + a->setProperty("Floating", false); + a->setToolTip("Creates a editor tab and inserts it as second tab into an area"); + a->setIcon(svgIcon(":/adsdemo/images/tab.svg")); + a->setProperty("Tabbed", true); + _this->connect(a, SIGNAL(triggered()), SLOT(createEditor())); + ui.menuTests->addAction(a); + a = ui.toolBar->addAction("Create Floating Table"); a->setToolTip("Creates floating dynamic dockable table with millions of entries"); a->setIcon(svgIcon(":/adsdemo/images/grid_on.svg")); @@ -829,6 +837,8 @@ void CMainWindow::createEditor() QObject* Sender = sender(); QVariant vFloating = Sender->property("Floating"); bool Floating = vFloating.isValid() ? vFloating.toBool() : true; + QVariant vTabbed = Sender->property("Tabbed"); + bool Tabbed = vTabbed.isValid() ? vTabbed.toBool() : true; auto DockWidget = d->createEditorWidget(); DockWidget->setFeature(ads::CDockWidget::DockWidgetDeleteOnClose, true); DockWidget->setFeature(ads::CDockWidget::DockWidgetForceCloseWithArea, true); @@ -840,28 +850,38 @@ void CMainWindow::createEditor() FloatingWidget->move(QPoint(20, 20)); d->LastCreatedFloatingEditor = DockWidget; d->LastDockedEditor.clear(); + return; } - else - { - ads::CDockAreaWidget* EditorArea = d->LastDockedEditor ? d->LastDockedEditor->dockAreaWidget() : nullptr; - if (EditorArea) - { - d->DockManager->setConfigFlag(ads::CDockManager::EqualSplitOnInsertion, true); - d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, EditorArea); - } - else - { - if (d->LastCreatedFloatingEditor) - { - d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, d->LastCreatedFloatingEditor->dockAreaWidget()); - } - else - { - d->DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget); - } - } - d->LastDockedEditor = DockWidget; - } + + + ads::CDockAreaWidget* EditorArea = d->LastDockedEditor ? d->LastDockedEditor->dockAreaWidget() : nullptr; + if (EditorArea) + { + if (Tabbed) + { + // Test inserting the dock widget tab at a given position instead + // of appending it. This function inserts the new dock widget as + // first tab + d->DockManager->addDockWidgetTabToArea(DockWidget, EditorArea, 0); + } + else + { + d->DockManager->setConfigFlag(ads::CDockManager::EqualSplitOnInsertion, true); + d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, EditorArea); + } + } + else + { + if (d->LastCreatedFloatingEditor) + { + d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, d->LastCreatedFloatingEditor->dockAreaWidget()); + } + else + { + d->DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget); + } + } + d->LastDockedEditor = DockWidget; } diff --git a/demo/demo.qrc b/demo/demo.qrc index a182763..6fadba2 100644 --- a/demo/demo.qrc +++ b/demo/demo.qrc @@ -17,6 +17,7 @@ images/create_floating_editor.svg images/create_floating_table.svg images/docked_editor.svg + images/tab.svg res/visual_studio_light.css images/color_lens.svg images/ads_icon.svg diff --git a/demo/images/tab.svg b/demo/images/tab.svg new file mode 100644 index 0000000..df5fd7c --- /dev/null +++ b/demo/images/tab.svg @@ -0,0 +1,6 @@ + + tab icon - Licensed under Apache License v2.0 (http://www.apache.org/licenses/LICENSE-2.0) - Created with Iconfu.com - Derivative work of Material icons (Copyright Google Inc.) + + + + \ No newline at end of file diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 93c816b..2df00c5 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -480,6 +480,10 @@ void CDockAreaWidget::addDockWidget(CDockWidget* DockWidget) void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget, bool Activate) { + if (index < 0 || index > d->ContentsLayout->count()) + { + index = d->ContentsLayout->count(); + } d->ContentsLayout->insertWidget(index, DockWidget); DockWidget->setDockArea(this); DockWidget->tabWidget()->setDockAreaWidget(this); diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index d3ece1e..c29acc1 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -169,7 +169,7 @@ public: * Adds dock widget to a existing DockWidgetArea */ CDockAreaWidget* addDockWidgetToDockArea(DockWidgetArea area, CDockWidget* Dockwidget, - CDockAreaWidget* TargetDockArea); + CDockAreaWidget* TargetDockArea, int Index = -1); /** * Add dock area to this container @@ -1278,11 +1278,11 @@ void DockContainerWidgetPrivate::dumpRecursive(int level, QWidget* widget) //============================================================================ CDockAreaWidget* DockContainerWidgetPrivate::addDockWidgetToDockArea(DockWidgetArea area, - CDockWidget* Dockwidget, CDockAreaWidget* TargetDockArea) + CDockWidget* Dockwidget, CDockAreaWidget* TargetDockArea, int Index) { if (CenterDockWidgetArea == area) { - TargetDockArea->addDockWidget(Dockwidget); + TargetDockArea->insertDockWidget(Index, Dockwidget); TargetDockArea->updateTitleBarVisibility(); return TargetDockArea; } @@ -1370,7 +1370,7 @@ CDockContainerWidget::~CDockContainerWidget() //============================================================================ CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, - CDockAreaWidget* DockAreaWidget) + CDockAreaWidget* DockAreaWidget, int Index) { auto TopLevelDockWidget = topLevelDockWidget(); CDockAreaWidget* OldDockArea = Dockwidget->dockAreaWidget(); @@ -1383,7 +1383,7 @@ CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockW CDockAreaWidget* DockArea; if (DockAreaWidget) { - DockArea = d->addDockWidgetToDockArea(area, Dockwidget, DockAreaWidget); + DockArea = d->addDockWidgetToDockArea(area, Dockwidget, DockAreaWidget, Index); } else { diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index dd73e50..852615a 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -221,7 +221,7 @@ public: * \return Returns the dock area widget that contains the new DockWidget */ CDockAreaWidget* addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, - CDockAreaWidget* DockAreaWidget = nullptr); + CDockAreaWidget* DockAreaWidget = nullptr, int Index = -1); /** * Removes dockwidget diff --git a/src/DockManager.cpp b/src/DockManager.cpp index febd495..54a6194 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -851,11 +851,11 @@ void CDockManager::restoreHiddenFloatingWidgets() //============================================================================ CDockAreaWidget* CDockManager::addDockWidget(DockWidgetArea area, - CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget) + CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget, int Index) { d->DockWidgetsMap.insert(Dockwidget->objectName(), Dockwidget); auto Container = DockAreaWidget ? DockAreaWidget->dockContainer() : this; - auto AreaOfAddedDockWidget = Container->addDockWidget(area, Dockwidget, DockAreaWidget); + auto AreaOfAddedDockWidget = Container->addDockWidget(area, Dockwidget, DockAreaWidget, Index); Q_EMIT dockWidgetAdded(Dockwidget); return AreaOfAddedDockWidget; } @@ -907,9 +907,9 @@ CDockAreaWidget* CDockManager::addDockWidgetTab(DockWidgetArea area, //============================================================================ CDockAreaWidget* CDockManager::addDockWidgetTabToArea(CDockWidget* Dockwidget, - CDockAreaWidget* DockAreaWidget) + CDockAreaWidget* DockAreaWidget, int Index) { - return addDockWidget(ads::CenterDockWidgetArea, Dockwidget, DockAreaWidget); + return addDockWidget(ads::CenterDockWidgetArea, Dockwidget, DockAreaWidget, Index); } diff --git a/src/DockManager.h b/src/DockManager.h index 7a2bfc3..d4b27f8 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -328,7 +328,7 @@ public: * \return Returns the dock area widget that contains the new DockWidget */ CDockAreaWidget* addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, - CDockAreaWidget* DockAreaWidget = nullptr); + CDockAreaWidget* DockAreaWidget = nullptr, int Index = -1); /** * Adds dockwidget into the given container. @@ -366,9 +366,11 @@ public: /** * This function will add the given Dockwidget to the given DockAreaWidget * as a new tab. + * If index is out of range, the tab is simply appended. Otherwise it is + * inserted at the specified position. */ CDockAreaWidget* addDockWidgetTabToArea(CDockWidget* Dockwidget, - CDockAreaWidget* DockAreaWidget); + CDockAreaWidget* DockAreaWidget, int Index = -1); /** * Adds the given DockWidget floating and returns the created