From 6b93ae9c3985a5408a2d77282d1e44ac60cb0db8 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Fri, 24 Aug 2018 13:41:58 +0200 Subject: [PATCH] Some refactoring to improve code clarity, renamed DockWidgetTitleBar into DockWidgetTab because in the GUI it is a tab, created new class CDockAreaTabBar for the tabbar of a dock area --- demo/MainWindow.cpp | 8 +- src/DockAreaTabBar.cpp | 173 ++++++++++++++++++ src/DockAreaTabBar.h | 74 ++++++++ src/DockAreaWidget.cpp | 153 +--------------- src/DockManager.cpp | 3 +- src/DockManager.h | 4 +- src/DockWidget.cpp | 15 +- src/DockWidget.h | 10 +- ...ckWidgetTitleBar.cpp => DockWidgetTab.cpp} | 60 +++--- src/{DockWidgetTitleBar.h => DockWidgetTab.h} | 28 +-- src/FloatingDockContainer.cpp | 9 +- src/FloatingDockContainer.h | 8 +- src/src.pro | 6 +- src/stylesheets/default.css | 8 +- 14 files changed, 350 insertions(+), 209 deletions(-) create mode 100644 src/DockAreaTabBar.cpp create mode 100644 src/DockAreaTabBar.h rename src/{DockWidgetTitleBar.cpp => DockWidgetTab.cpp} (85%) rename src/{DockWidgetTitleBar.h => DockWidgetTab.h} (83%) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index e6f8d1f..72e7cf4 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -174,13 +174,15 @@ void MainWindowPrivate::createContent() QMenu* ViewMenu = ui.menuView; auto DockWidget = createCalendarDockWidget(ViewMenu); DockWidget->setIcon(_this->style()->standardIcon(QStyle::SP_DialogOpenButton)); - DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false)); + DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false); DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget); DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu)); DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu)); - auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu)); + auto FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu); + FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetMovable, false); + auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget); DockWidget = createCalendarDockWidget(ViewMenu); - DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false)); + DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false); DockManager->addDockWidget(ads::CenterDockWidgetArea, DockWidget, TopDockArea); // Test dock area docking diff --git a/src/DockAreaTabBar.cpp b/src/DockAreaTabBar.cpp new file mode 100644 index 0000000..8dbaec2 --- /dev/null +++ b/src/DockAreaTabBar.cpp @@ -0,0 +1,173 @@ +//============================================================================ +/// \file DockAreaTabBar.cpp +/// \author Uwe Kindler +/// \date 24.08.2018 +/// \brief Implementation of CDockAreaTabBar class +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include "DockAreaTabBar.h" + +#include +#include +#include + +#include "FloatingDockContainer.h" +#include "DockAreaWidget.h" +#include "DockOverlay.h" +#include "DockManager.h" + +namespace ads +{ +/** + * Private data class of CDockAreaTabBar class (pimpl) + */ +struct DockAreaTabBarPrivate +{ + CDockAreaTabBar* _this; + QPoint DragStartMousePos; + CDockAreaWidget* DockArea; + CFloatingDockContainer* FloatingWidget = nullptr; + + /** + * Private data constructor + */ + DockAreaTabBarPrivate(CDockAreaTabBar* _public); +}; +// struct DockAreaTabBarPrivate + +//============================================================================ +DockAreaTabBarPrivate::DockAreaTabBarPrivate(CDockAreaTabBar* _public) : + _this(_public) +{ + +} + +//============================================================================ +CDockAreaTabBar::CDockAreaTabBar(CDockAreaWidget* parent) : + QScrollArea(parent), + d(new DockAreaTabBarPrivate(this)) +{ + d->DockArea = parent; + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored); + setFrameStyle(QFrame::NoFrame); + setWidgetResizable(true); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); +} + +//============================================================================ +CDockAreaTabBar::~CDockAreaTabBar() +{ + delete d; +} + + +//============================================================================ +void CDockAreaTabBar::wheelEvent(QWheelEvent* Event) +{ + Event->accept(); + const int direction = Event->angleDelta().y(); + if (direction < 0) + { + horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 20); + } + else + { + horizontalScrollBar()->setValue(horizontalScrollBar()->value() - 20); + } +} + + +//============================================================================ +void CDockAreaTabBar::mousePressEvent(QMouseEvent* ev) +{ + if (ev->button() == Qt::LeftButton) + { + ev->accept(); + d->DragStartMousePos = ev->pos(); + return; + } + QScrollArea::mousePressEvent(ev); +} + + +//============================================================================ +void CDockAreaTabBar::mouseReleaseEvent(QMouseEvent* ev) +{ + if (ev->button() == Qt::LeftButton) + { + qDebug() << "CTabsScrollArea::mouseReleaseEvent"; + ev->accept(); + d->FloatingWidget = nullptr; + d->DragStartMousePos = QPoint(); + return; + } + QScrollArea::mouseReleaseEvent(ev); +} + + +//============================================================================ +void CDockAreaTabBar::mouseMoveEvent(QMouseEvent* ev) +{ + QScrollArea::mouseMoveEvent(ev); + if (ev->buttons() != Qt::LeftButton) + { + return; + } + + if (d->FloatingWidget) + { + d->FloatingWidget->moveFloating(); + return; + } + + // 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->dockContainer()->visibleDockAreaCount() == 1) + { + return; + } + + if (!this->geometry().contains(ev->pos())) + { + qDebug() << "CTabsScrollArea::startFloating"; + startFloating(d->DragStartMousePos); + auto Overlay = d->DockArea->dockManager()->containerOverlay(); + Overlay->setAllowedAreas(OuterDockAreas); + } + + return; +} + + +//============================================================================ +void CDockAreaTabBar::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->dockContainer()->dockAreaCount() == 1) + { + return; + } + startFloating(event->pos()); +} + + +//============================================================================ +void CDockAreaTabBar::startFloating(const QPoint& Pos) +{ + QSize Size = d->DockArea->size(); + CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(d->DockArea); + FloatingWidget->startFloating(Pos, Size); + d->FloatingWidget = FloatingWidget; +} +} // namespace ads + +//--------------------------------------------------------------------------- +// EOF DockAreaTabBar.cpp diff --git a/src/DockAreaTabBar.h b/src/DockAreaTabBar.h new file mode 100644 index 0000000..aa2c76e --- /dev/null +++ b/src/DockAreaTabBar.h @@ -0,0 +1,74 @@ +#ifndef DockAreaTabBarH +#define DockAreaTabBarH +//============================================================================ +/// \file DockAreaTabBar.h +/// \author Uwe Kindler +/// \date 24.08.2018 +/// \brief Declaration of CDockAreaTabBar class +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include + +namespace ads +{ +class CDockAreaWidget; +struct DockAreaTabBarPrivate; + +/** + * Custom scroll bar implementation for dock area tab bar + * This scroll area enables floating of a whole dock area including all + * dock widgets + */ +class CDockAreaTabBar : public QScrollArea +{ + Q_OBJECT +private: + DockAreaTabBarPrivate* d; ///< private data (pimpl) + friend class DockAreaTabBarPrivate; + +protected: + virtual void wheelEvent(QWheelEvent* Event) override; + /** + * Stores mouse position to detect dragging + */ + virtual void mousePressEvent(QMouseEvent* ev) override; + + /** + * Stores mouse position to detect dragging + */ + virtual void mouseReleaseEvent(QMouseEvent* ev) override; + + /** + * Starts floating the complete docking area including all dock widgets, + * if it is not the last dock area in a floating widget + */ + virtual void mouseMoveEvent(QMouseEvent* ev) override; + + /** + * Double clicking the title bar also starts floating of the complete area + */ + virtual void mouseDoubleClickEvent(QMouseEvent *event) override; + + /** + * Starts floating + */ + void startFloating(const QPoint& Pos); + +public: + /** + * Default Constructor + */ + CDockAreaTabBar(CDockAreaWidget* parent); + + /** + * Virtual Destructor + */ + virtual ~CDockAreaTabBar(); +}; // class CDockAreaTabBar +} // namespace ads +//----------------------------------------------------------------------------- +#endif // DockAreaTabBarH + diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index dbbf144..c2611bf 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -28,6 +28,7 @@ //============================================================================ // INCLUDES //============================================================================ +#include #include "DockAreaWidget.h" #include @@ -44,10 +45,10 @@ #include "DockContainerWidget.h" #include "DockWidget.h" -#include "DockWidgetTitleBar.h" #include "FloatingDockContainer.h" #include "DockManager.h" #include "DockOverlay.h" +#include "DockAreaTabBar.h" namespace ads @@ -56,140 +57,6 @@ static const char* const INDEX_PROPERTY = "index"; static const char* const ACTION_PROPERTY = "action"; static const int APPEND = -1; -/** - * Custom scroll bar implementation for dock area tab bar - * This scroll area enables floating of a whole dock area including all - * dock widgets - */ -class CTabsScrollArea : public QScrollArea -{ -private: - QPoint m_DragStartMousePos; - CDockAreaWidget* m_DockArea; - CFloatingDockContainer* m_FloatingWidget = nullptr; - -public: - CTabsScrollArea(CDockAreaWidget* parent) - : QScrollArea(parent), - m_DockArea(parent) - { - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored); - setFrameStyle(QFrame::NoFrame); - setWidgetResizable(true); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - } - -protected: - virtual void wheelEvent(QWheelEvent* Event) override - { - Event->accept(); - const int direction = Event->angleDelta().y(); - if (direction < 0) - { - horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 20); - } - else - { - horizontalScrollBar()->setValue(horizontalScrollBar()->value() - 20); - } - } - - /** - * Stores mouse position to detect dragging - */ - virtual void mousePressEvent(QMouseEvent* ev) override - { - if (ev->button() == Qt::LeftButton) - { - ev->accept(); - m_DragStartMousePos = ev->pos(); - return; - } - QScrollArea::mousePressEvent(ev); - } - - /** - * Stores mouse position to detect dragging - */ - virtual void mouseReleaseEvent(QMouseEvent* ev) override - { - if (ev->button() == Qt::LeftButton) - { - qDebug() << "CTabsScrollArea::mouseReleaseEvent"; - ev->accept(); - m_FloatingWidget = nullptr; - m_DragStartMousePos = QPoint(); - return; - } - QScrollArea::mouseReleaseEvent(ev); - } - - /** - * Starts floating the complete docking area including all dock widgets, - * if it is not the last dock area in a floating widget - */ - virtual void mouseMoveEvent(QMouseEvent* ev) override - { - QScrollArea::mouseMoveEvent(ev); - if (ev->buttons() != Qt::LeftButton) - { - return; - } - - if (m_FloatingWidget) - { - m_FloatingWidget->moveFloating(); - return; - } - - // 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 (m_DockArea->dockContainer()->isFloating() - && m_DockArea->dockContainer()->visibleDockAreaCount() == 1) - { - return; - } - - if (!this->geometry().contains(ev->pos())) - { - qDebug() << "CTabsScrollArea::startFloating"; - startFloating(m_DragStartMousePos); - auto Overlay = m_DockArea->dockManager()->containerOverlay(); - Overlay->setAllowedAreas(OuterDockAreas); - } - - return; - } - - /** - * Double clicking the title bar also starts floating of the complete area - */ - virtual void mouseDoubleClickEvent(QMouseEvent *event) override - { - // 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 (m_DockArea->dockContainer()->isFloating() && m_DockArea->dockContainer()->dockAreaCount() == 1) - { - return; - } - startFloating(event->pos()); - } - - /** - * Starts floating - */ - void startFloating(const QPoint& Pos) - { - QSize Size = m_DockArea->size(); - CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(m_DockArea); - FloatingWidget->startFloating(Pos, Size); - m_FloatingWidget = FloatingWidget; - } -}; // class CTabsScrollArea - /** * Private data class of CDockAreaWidget class (pimpl) @@ -201,7 +68,7 @@ struct DockAreaWidgetPrivate QFrame* TitleBar; QBoxLayout* TopLayout; QStackedLayout* ContentsLayout; - QScrollArea* TabsScrollArea; + CDockAreaTabBar* TabBar; QWidget* TabsContainerWidget; QBoxLayout* TabsLayout; QPushButton* TabsMenuButton; @@ -230,7 +97,7 @@ struct DockAreaWidgetPrivate /** * Convenience function to ease title widget access by index */ - CDockWidgetTitleBar* titleWidgetAt(int index) + CDockWidgetTab* titleWidgetAt(int index) { return dockWidgetAt(index)->titleBar(); } @@ -293,12 +160,12 @@ void DockAreaWidgetPrivate::createTabBar() TitleBar->setLayout(TopLayout); Layout->addWidget(TitleBar); - TabsScrollArea = new CTabsScrollArea(_this); - TopLayout->addWidget(TabsScrollArea, 1); + TabBar = new CDockAreaTabBar(_this); + TopLayout->addWidget(TabBar, 1); TabsContainerWidget = new QWidget(); TabsContainerWidget->setObjectName("tabsContainerWidget"); - TabsScrollArea->setWidget(TabsContainerWidget); + TabBar->setWidget(TabsContainerWidget); TabsLayout = new QBoxLayout(QBoxLayout::LeftToRight); TabsLayout->setContentsMargins(0, 0, 0, 0); @@ -489,7 +356,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget) //============================================================================ void CDockAreaWidget::onDockWidgetTitleClicked() { - CDockWidgetTitleBar* TitleWidget = qobject_cast(sender()); + CDockWidgetTab* TitleWidget = qobject_cast(sender()); if (!TitleWidget) { return; @@ -546,7 +413,7 @@ void CDockAreaWidget::setCurrentIndex(int index) continue; } - auto TitleWidget = dynamic_cast(item->widget()); + auto TitleWidget = dynamic_cast(item->widget()); if (!TitleWidget) { continue; @@ -556,7 +423,7 @@ void CDockAreaWidget::setCurrentIndex(int index) { TitleWidget->show(); TitleWidget->setActiveTab(true); - d->TabsScrollArea->ensureWidgetVisible(TitleWidget); + d->TabBar->ensureWidgetVisible(TitleWidget); auto Features = TitleWidget->dockWidget()->features(); d->CloseButton->setVisible(Features.testFlag(CDockWidget::DockWidgetClosable)); } diff --git a/src/DockManager.cpp b/src/DockManager.cpp index df34055..6c476d0 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -28,6 +28,7 @@ //============================================================================ // INCLUDES //============================================================================ +#include #include "DockManager.h" #include @@ -49,7 +50,6 @@ #include "DockWidget.h" #include "ads_globals.h" #include "DockStateSerialization.h" -#include "DockWidgetTitleBar.h" #include "DockAreaWidget.h" namespace ads @@ -370,7 +370,6 @@ bool CDockManager::restoreState(const QByteArray &state, int version) } emit stateChanged(); - return true; } diff --git a/src/DockManager.h b/src/DockManager.h index d6e19c7..d485c33 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -189,7 +189,9 @@ signals: void perspectiveListChanged(); /** - * This signal is emitted if the state changed in restoreState + * 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(); }; // class DockManager diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 8269377..24d10af 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -28,6 +28,7 @@ //============================================================================ // INCLUDES //============================================================================ +#include #include "DockWidget.h" #include @@ -40,7 +41,6 @@ #include #include -#include "DockWidgetTitleBar.h" #include "DockContainerWidget.h" #include "DockAreaWidget.h" #include "DockManager.h" @@ -59,7 +59,7 @@ struct DockWidgetPrivate CDockWidget* _this; QBoxLayout* Layout; QWidget* Widget = nullptr; - CDockWidgetTitleBar* TitleWidget; + CDockWidgetTab* TitleWidget; CDockWidget::DockWidgetFeatures Features = CDockWidget::AllDockWidgetFeatures; CDockManager* DockManager = nullptr; CDockAreaWidget* DockArea = nullptr; @@ -212,7 +212,7 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) : setLayout(d->Layout); setWindowTitle(title); - d->TitleWidget = new CDockWidgetTitleBar(this); + d->TitleWidget = new CDockWidgetTab(this); d->ToggleViewAction = new QAction(title); d->ToggleViewAction->setCheckable(true); connect(d->ToggleViewAction, SIGNAL(triggered(bool)), this, @@ -261,7 +261,7 @@ QWidget* CDockWidget::widget() const //============================================================================ -CDockWidgetTitleBar* CDockWidget::titleBar() const +CDockWidgetTab* CDockWidget::titleBar() const { return d->TitleWidget; } @@ -274,6 +274,13 @@ void CDockWidget::setFeatures(DockWidgetFeatures features) } +//============================================================================ +void CDockWidget::setFeature(DockWidgetFeature flag, bool on) +{ + d->Features.setFlag(flag, on); +} + + //============================================================================ CDockWidget::DockWidgetFeatures CDockWidget::features() const { diff --git a/src/DockWidget.h b/src/DockWidget.h index 407f2da..7f75176 100644 --- a/src/DockWidget.h +++ b/src/DockWidget.h @@ -39,7 +39,7 @@ class QXmlStreamWriter; namespace ads { struct DockWidgetPrivate; -class CDockWidgetTitleBar; +class CDockWidgetTab; class CDockManager; class CDockContainerWidget; class CDockAreaWidget; @@ -155,13 +155,19 @@ public: /** * Returns the title bar widget of this dock widget */ - CDockWidgetTitleBar* titleBar() const; + CDockWidgetTab* titleBar() const; /** * Sets, whether the dock widget is movable, closable, and floatable. */ void setFeatures(DockWidgetFeatures features); + /** + * Sets the feature flag for this dock widget if on is true; otherwise + * clears the flag. + */ + void setFeature(DockWidgetFeature flag, bool on); + /** * This property holds whether the dock widget is movable, closable, and * floatable. diff --git a/src/DockWidgetTitleBar.cpp b/src/DockWidgetTab.cpp similarity index 85% rename from src/DockWidgetTitleBar.cpp rename to src/DockWidgetTab.cpp index b9f5be9..6c629ff 100644 --- a/src/DockWidgetTitleBar.cpp +++ b/src/DockWidgetTab.cpp @@ -18,17 +18,17 @@ //============================================================================ -/// \file DockWidgetTitleBar.cpp +/// \file DockWidgetTab.cpp /// \author Uwe Kindler /// \date 27.02.2017 -/// \brief Implementation of CDockWidgetTitleBar class +/// \brief Implementation of CDockWidgetTab class //============================================================================ //============================================================================ // INCLUDES //============================================================================ -#include "DockWidgetTitleBar.h" +#include "DockWidgetTab.h" #include #include @@ -60,11 +60,11 @@ enum eDragState /** - * Private data class of CDockWidgetTitleBar class (pimpl) + * Private data class of CDockWidgetTab class (pimpl) */ -struct DockWidgetTitleBarPrivate +struct DockWidgetTabPrivate { - CDockWidgetTitleBar* _this; + CDockWidgetTab* _this; CDockWidget* DockWidget; QLabel* IconLabel; QLabel* TitleLabel; @@ -78,7 +78,7 @@ struct DockWidgetTitleBarPrivate /** * Private data constructor */ - DockWidgetTitleBarPrivate(CDockWidgetTitleBar* _public); + DockWidgetTabPrivate(CDockWidgetTab* _public); /** * Creates the complete layout including all controls @@ -115,11 +115,11 @@ struct DockWidgetTitleBarPrivate */ bool startFloating(); }; -// struct DockWidgetTitleBarPrivate +// struct DockWidgetTabPrivate //============================================================================ -DockWidgetTitleBarPrivate::DockWidgetTitleBarPrivate(CDockWidgetTitleBar* _public) : +DockWidgetTabPrivate::DockWidgetTabPrivate(CDockWidgetTab* _public) : _this(_public) { @@ -127,7 +127,7 @@ DockWidgetTitleBarPrivate::DockWidgetTitleBarPrivate(CDockWidgetTitleBar* _publi //============================================================================ -void DockWidgetTitleBarPrivate::createLayout() +void DockWidgetTabPrivate::createLayout() { QBoxLayout* l = new QBoxLayout(QBoxLayout::LeftToRight); l->setContentsMargins(0, 0, 0, 0); @@ -146,7 +146,7 @@ void DockWidgetTitleBarPrivate::createLayout() } //============================================================================ -void DockWidgetTitleBarPrivate::moveTab(QMouseEvent* ev) +void DockWidgetTabPrivate::moveTab(QMouseEvent* ev) { ev->accept(); int left, top, right, bottom; @@ -159,7 +159,7 @@ void DockWidgetTitleBarPrivate::moveTab(QMouseEvent* ev) //============================================================================ -bool DockWidgetTitleBarPrivate::startFloating() +bool DockWidgetTabPrivate::startFloating() { qDebug() << "isFloating " << DockWidget->dockContainer()->isFloating(); qDebug() << "areaCount " << DockWidget->dockContainer()->dockAreaCount(); @@ -185,7 +185,7 @@ bool DockWidgetTitleBarPrivate::startFloating() } else { - qDebug() << "DockWidgetTitleBarPrivate::startFloating DockArea"; + 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); @@ -200,9 +200,9 @@ bool DockWidgetTitleBarPrivate::startFloating() //============================================================================ -CDockWidgetTitleBar::CDockWidgetTitleBar(CDockWidget* DockWidget, QWidget *parent) : +CDockWidgetTab::CDockWidgetTab(CDockWidget* DockWidget, QWidget *parent) : QFrame(parent), - d(new DockWidgetTitleBarPrivate(this)) + d(new DockWidgetTabPrivate(this)) { setAttribute(Qt::WA_NoMousePropagation, true); d->DockWidget = DockWidget; @@ -210,19 +210,19 @@ CDockWidgetTitleBar::CDockWidgetTitleBar(CDockWidget* DockWidget, QWidget *paren } //============================================================================ -CDockWidgetTitleBar::~CDockWidgetTitleBar() +CDockWidgetTab::~CDockWidgetTab() { - qDebug() << "~CDockWidgetTitleBar()"; + qDebug() << "~CDockWidgetTab()"; delete d; } //============================================================================ -void CDockWidgetTitleBar::mousePressEvent(QMouseEvent* ev) +void CDockWidgetTab::mousePressEvent(QMouseEvent* ev) { if (ev->button() == Qt::LeftButton) { - qDebug() << "CDockWidgetTitleBar::mousePressEvent"; + qDebug() << "CDockWidgetTab::mousePressEvent"; ev->accept(); d->DragStartMousePosition = ev->pos(); d->DragState = DraggingMousePressed; @@ -234,9 +234,9 @@ void CDockWidgetTitleBar::mousePressEvent(QMouseEvent* ev) //============================================================================ -void CDockWidgetTitleBar::mouseReleaseEvent(QMouseEvent* ev) +void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev) { - qDebug() << "CDockWidgetTitleBar::mouseReleaseEvent"; + qDebug() << "CDockWidgetTab::mouseReleaseEvent"; // End of tab moving, change order now if (d->isDraggingState(DraggingTab) && d->DockArea) { @@ -267,7 +267,7 @@ void CDockWidgetTitleBar::mouseReleaseEvent(QMouseEvent* ev) //============================================================================ -void CDockWidgetTitleBar::mouseMoveEvent(QMouseEvent* ev) +void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev) { if (!(ev->buttons() & Qt::LeftButton) || d->isDraggingState(DraggingInactive)) { @@ -315,14 +315,14 @@ void CDockWidgetTitleBar::mouseMoveEvent(QMouseEvent* ev) //============================================================================ -bool CDockWidgetTitleBar::isActiveTab() const +bool CDockWidgetTab::isActiveTab() const { return d->IsActiveTab; } //============================================================================ -void CDockWidgetTitleBar::setActiveTab(bool active) +void CDockWidgetTab::setActiveTab(bool active) { if (d->IsActiveTab == active) { @@ -341,28 +341,28 @@ void CDockWidgetTitleBar::setActiveTab(bool active) //============================================================================ -CDockWidget* CDockWidgetTitleBar::dockWidget() const +CDockWidget* CDockWidgetTab::dockWidget() const { return d->DockWidget; } //============================================================================ -void CDockWidgetTitleBar::setDockAreaWidget(CDockAreaWidget* DockArea) +void CDockWidgetTab::setDockAreaWidget(CDockAreaWidget* DockArea) { d->DockArea = DockArea; } //============================================================================ -CDockAreaWidget* CDockWidgetTitleBar::dockAreaWidget() const +CDockAreaWidget* CDockWidgetTab::dockAreaWidget() const { return d->DockArea; } //============================================================================ -void CDockWidgetTitleBar::setIcon(const QIcon& Icon) +void CDockWidgetTab::setIcon(const QIcon& Icon) { d->Icon = Icon; d->IconLabel->setPixmap(Icon.pixmap(this->windowHandle(), QSize(16, 16))); @@ -371,11 +371,11 @@ void CDockWidgetTitleBar::setIcon(const QIcon& Icon) //============================================================================ -const QIcon& CDockWidgetTitleBar::icon() const +const QIcon& CDockWidgetTab::icon() const { return d->Icon; } } // namespace ads //--------------------------------------------------------------------------- -// EOF DockWidgetTitleBar.cpp +// EOF DockWidgetTab.cpp diff --git a/src/DockWidgetTitleBar.h b/src/DockWidgetTab.h similarity index 83% rename from src/DockWidgetTitleBar.h rename to src/DockWidgetTab.h index 6e88d9c..b81d85d 100644 --- a/src/DockWidgetTitleBar.h +++ b/src/DockWidgetTab.h @@ -1,5 +1,5 @@ -#ifndef DockWidgetTitleBarH -#define DockWidgetTitleBarH +#ifndef DockWidgetTabH +#define DockWidgetTabH /******************************************************************************* ** Qt Advanced Docking System ** Copyright (C) 2017 Uwe Kindler @@ -20,10 +20,10 @@ //============================================================================ -/// \file DockWidgetTitleBar.h +/// \file DockWidgetTab.h /// \author Uwe Kindler /// \date 27.02.2017 -/// \brief Declaration of CDockWidgetTitleBar class +/// \brief Declaration of CDockWidgetTab class //============================================================================ @@ -38,19 +38,21 @@ namespace ads { class CDockWidget; class CDockAreaWidget; -struct DockWidgetTitleBarPrivate; +struct DockWidgetTabPrivate; /** - * A dock widget title bar that shows a title and an icon + * A dock widget tab that shows a title and an icon. + * The dock widget tab is shown in the dock area title bar to switch between + * tabbed dock widgets */ -class ADS_EXPORT CDockWidgetTitleBar : public QFrame +class ADS_EXPORT CDockWidgetTab : public QFrame { Q_OBJECT Q_PROPERTY(bool activeTab READ isActiveTab WRITE setActiveTab NOTIFY activeTabChanged) private: - DockWidgetTitleBarPrivate* d; ///< private data (pimpl) - friend struct DockWidgetTitleBarPrivate; + DockWidgetTabPrivate* d; ///< private data (pimpl) + friend struct DockWidgetTabPrivate; protected: virtual void mousePressEvent(QMouseEvent* ev) override; @@ -63,12 +65,12 @@ public: * param[in] DockWidget The dock widget this title bar belongs to * param[in] parent The parent widget of this title bar */ - CDockWidgetTitleBar(CDockWidget* DockWidget, QWidget* parent = 0); + CDockWidgetTab(CDockWidget* DockWidget, QWidget* parent = 0); /** * Virtual Destructor */ - virtual ~CDockWidgetTitleBar(); + virtual ~CDockWidgetTab(); /** * Returns true, if this is the active tab @@ -111,8 +113,8 @@ public: signals: void activeTabChanged(); void clicked(); -}; // class DockWidgetTitleBar +}; // class DockWidgetTab } // namespace ads //----------------------------------------------------------------------------- -#endif // DockWidgetTitleBarH +#endif // DockWidgetTabH diff --git a/src/FloatingDockContainer.cpp b/src/FloatingDockContainer.cpp index 49b54d4..6c2f5a9 100644 --- a/src/FloatingDockContainer.cpp +++ b/src/FloatingDockContainer.cpp @@ -210,7 +210,6 @@ CFloatingDockContainer::CFloatingDockContainer(CDockManager* DockManager) : QWidget(DockManager, Qt::Window), d(new FloatingDockContainerPrivate(this)) { - //setAttribute(Qt::WA_DeleteOnClose); d->DockManager = DockManager; QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom); l->setContentsMargins(0, 0, 0, 0); @@ -412,7 +411,7 @@ void CFloatingDockContainer::moveFloating() //============================================================================ -bool CFloatingDockContainer::isClosable() +bool CFloatingDockContainer::isClosable() const { auto OpenDockAreas = d->DockContainer->openedDockAreas(); for (auto DockArea : OpenDockAreas) @@ -420,13 +419,17 @@ bool CFloatingDockContainer::isClosable() auto OpenDockWidgets = DockArea->openedDockWidgets(); for (auto DockWidget : OpenDockWidgets) { - if (!(DockWidget->features() & CDockWidget::DockWidgetClosable)) + if (!DockWidget->features().testFlag(CDockWidget::DockWidgetClosable)) + { return false; + } } } return true; } + +//============================================================================ void CFloatingDockContainer::onDockAreasAddedOrRemoved() { qDebug() << "CFloatingDockContainer::onDockAreasAddedOrRemoved()"; diff --git a/src/FloatingDockContainer.h b/src/FloatingDockContainer.h index 2c743d5..fe6f557 100644 --- a/src/FloatingDockContainer.h +++ b/src/FloatingDockContainer.h @@ -55,8 +55,6 @@ private: FloatingDockContainerPrivate* d; ///< private data (pimpl) friend struct FloatingDockContainerPrivate; - bool isClosable(); - private slots: void onDockAreasAddedOrRemoved(); void onDockAreaCurrentChanged(int Index); @@ -117,6 +115,12 @@ public: * faulty files before you start restoring the state */ bool restoreState(QXmlStreamReader& Stream, bool Testing); + + /** + * This function returns true, if it can be closed. + * It can be closed, if all dock widgets in all dock areas can be closed + */ + bool isClosable() const; }; // class FloatingDockContainer } // namespace ads diff --git a/src/src.pro b/src/src.pro index 33d3d88..6033707 100644 --- a/src/src.pro +++ b/src/src.pro @@ -33,10 +33,11 @@ RESOURCES += ads.qrc HEADERS += \ ads_globals.h \ DockAreaWidget.h \ + DockAreaTabBar.h \ DockContainerWidget.h \ DockManager.h \ DockWidget.h \ - DockWidgetTitleBar.h \ + DockWidgetTab.h \ FloatingDockContainer.h \ DockOverlay.h \ DockSplitter.h @@ -46,10 +47,11 @@ HEADERS += \ SOURCES += \ ads_globals.cpp \ DockAreaWidget.cpp \ + DockAreaTabBar.cpp \ DockContainerWidget.cpp \ DockManager.cpp \ DockWidget.cpp \ - DockWidgetTitleBar.cpp \ + DockWidgetTab.cpp \ FloatingDockContainer.cpp \ DockOverlay.cpp \ DockSplitter.cpp diff --git a/src/stylesheets/default.css b/src/stylesheets/default.css index ba8b91a..1df7741 100644 --- a/src/stylesheets/default.css +++ b/src/stylesheets/default.css @@ -25,7 +25,7 @@ ads--CDockAreaWidget #tabsMenuButton::menu-indicator image: none; } -ads--CDockWidgetTitleBar +ads--CDockWidgetTab { background: palette(window); border-color: palette(light); @@ -34,17 +34,17 @@ ads--CDockWidgetTitleBar padding: 0 9px; } -ads--CDockWidgetTitleBar[activeTab="true"] +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)); } -ads--CDockWidgetTitleBar QLabel +ads--CDockWidgetTab QLabel { color: palette(dark); } -ads--CDockWidgetTitleBar[activeTab="true"] QLabel +ads--CDockWidgetTab[activeTab="true"] QLabel { color: palette(foreground); }