From f0584ff0c53805f65f77db0475c4e444746b65be Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 27 Feb 2017 14:15:20 +0100 Subject: [PATCH] COntinued implementation of new advanced docking system, added stylesheet --- AdvancedDockingSystem/res/ads.qrc | 1 + .../res/stylesheets/default-windows2.css | 58 +++++ .../src/v2/DockAreaWidget.cpp | 202 +++++++++++++++++- AdvancedDockingSystem/src/v2/DockAreaWidget.h | 31 ++- .../src/v2/DockContainerWidget.cpp | 47 +++- .../src/v2/DockContainerWidget.h | 24 ++- AdvancedDockingSystem/src/v2/DockManager.cpp | 19 ++ AdvancedDockingSystem/src/v2/DockManager.h | 20 ++ AdvancedDockingSystem/src/v2/DockWidget.cpp | 47 ++++ AdvancedDockingSystem/src/v2/DockWidget.h | 49 +++++ .../src/v2/DockWidgetTitleBar.cpp | 162 +++++++++++++- .../src/v2/DockWidgetTitleBar.h | 80 ++++++- .../src/v2/FloatingDockContainer.cpp | 20 ++ .../src/v2/FloatingDockContainer.h | 20 ++ AdvancedDockingSystem/src/v2/ads_globals.cpp | 21 +- AdvancedDockingSystem/src/v2/ads_globals.h | 21 +- AdvancedDockingSystemDemo_v2/src/main.cpp | 2 +- .../src/mainwindow.cpp | 17 +- 18 files changed, 806 insertions(+), 35 deletions(-) create mode 100644 AdvancedDockingSystem/res/stylesheets/default-windows2.css diff --git a/AdvancedDockingSystem/res/ads.qrc b/AdvancedDockingSystem/res/ads.qrc index ce64016..32ef0d3 100644 --- a/AdvancedDockingSystem/res/ads.qrc +++ b/AdvancedDockingSystem/res/ads.qrc @@ -3,5 +3,6 @@ stylesheets/default-windows.css stylesheets/vendor-partsolutions.css stylesheets/modern-windows.css + stylesheets/default-windows2.css diff --git a/AdvancedDockingSystem/res/stylesheets/default-windows2.css b/AdvancedDockingSystem/res/stylesheets/default-windows2.css new file mode 100644 index 0000000..15fde86 --- /dev/null +++ b/AdvancedDockingSystem/res/stylesheets/default-windows2.css @@ -0,0 +1,58 @@ + +/* + * Default style sheet on Windows Platforms + * Note: Always use CSS-classes with and without "ads--" namespace to support Qt4 & Qt5 + */ + +ads--CDockContainerWidget +{ + background: palette(dark); +} + +ads--CDockContainerWidget QSplitter::handle +{ + background: palette(dark); +} + +ads--CDockAreaWidget +{ + background: palette(window); + border: 1px solid palette(light); +} + +ads--CDockAreaWidget #tabsMenuButton::menu-indicator +{ + image: none; +} + +ads--CDockWidgetTitleBar +{ + background: palette(window); + border-color: palette(light); + border-style: solid; + border-width: 0 1px 0 0; + padding: 0 9px; +} + +ads--CDockWidgetTitleBar[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 +{ + color: palette(dark); +} + +ads--CDockWidgetTitleBar[activeTab="true"] QLabel +{ + color: palette(foreground); +} + +ads--CDockWidget +{ + background: palette(light); + border-color: palette(light); + border-style: solid; + border-width: 1px 0 0 0; +} diff --git a/AdvancedDockingSystem/src/v2/DockAreaWidget.cpp b/AdvancedDockingSystem/src/v2/DockAreaWidget.cpp index 2428992..2508336 100644 --- a/AdvancedDockingSystem/src/v2/DockAreaWidget.cpp +++ b/AdvancedDockingSystem/src/v2/DockAreaWidget.cpp @@ -1,3 +1,22 @@ +/******************************************************************************* +** QtAdcancedDockingSystem +** Copyright (C) 2017 Uwe Kindler +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +******************************************************************************/ + + //============================================================================ /// \file DockAreaWidget.cpp /// \author Uwe Kindler @@ -5,33 +24,90 @@ /// \brief Implementation of CDockAreaWidget class //============================================================================ + //============================================================================ // INCLUDES //============================================================================ #include "DockAreaWidget.h" #include +#include +#include +#include +#include +#include +#include #include "DockContainerWidget.h" #include "DockWidget.h" +#include "DockWidgetTitleBar.h" + +#include namespace ads { +/** + * Custom scroll bar implementation for dock area tab bar + */ +class CTabsScrollArea : public QScrollArea +{ +public: + CTabsScrollArea(QWidget* parent = nullptr) + : QScrollArea(parent) + { + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored); + setFrameStyle(QFrame::NoFrame); + setWidgetResizable(true); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + } + +protected: + virtual void 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); + } + } +}; // class CTabsScrollArea + + /** * Private data class of CDockAreaWidget class (pimpl) */ struct DockAreaWidgetPrivate { CDockAreaWidget* _this; - QStackedLayout* StackedLayout; + QBoxLayout* Layout; + QBoxLayout* TopLayout; + QStackedLayout* ContentsLayout; + QScrollArea* TabsScrollArea; + QWidget* TabsContainerWidget; + QBoxLayout* TabsLayout; + QPushButton* TabsMenuButton; + QPushButton* CloseButton; + int TabsLayoutInitCount; /** * Private data constructor */ DockAreaWidgetPrivate(CDockAreaWidget* _public); + + /** + * Creates the layout for top area with tabs and close button + */ + void createTabBar(); }; // struct DockAreaWidgetPrivate + //============================================================================ DockAreaWidgetPrivate::DockAreaWidgetPrivate(CDockAreaWidget* _public) : _this(_public) @@ -39,16 +115,64 @@ DockAreaWidgetPrivate::DockAreaWidgetPrivate(CDockAreaWidget* _public) : } + +//============================================================================ +void DockAreaWidgetPrivate::createTabBar() +{ + TopLayout = new QBoxLayout(QBoxLayout::LeftToRight); + TopLayout->setContentsMargins(0, 0, 0, 0); + TopLayout->setSpacing(0); + Layout->addLayout(TopLayout); + + TabsScrollArea = new CTabsScrollArea(_this); + TopLayout->addWidget(TabsScrollArea, 1); + + TabsContainerWidget = new QWidget(); + TabsContainerWidget->setObjectName("tabsContainerWidget"); + TabsScrollArea->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()); + TopLayout->addWidget(TabsMenuButton, 0); + + 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); + //connect(_closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked())); + + TabsLayoutInitCount = TabsLayout->count(); +} + //============================================================================ CDockAreaWidget::CDockAreaWidget(CDockManager* DockManager, CDockContainerWidget* parent) : QFrame(parent), d(new DockAreaWidgetPrivate(this)) { - setStyleSheet("background: yellow;"); - d->StackedLayout = new QStackedLayout(); - d->StackedLayout->setContentsMargins(0, 0, 0, 0); - d->StackedLayout->setSpacing(0); - setLayout(d->StackedLayout); + setStyleSheet("ads--CDockAreaWidget {border: 1px solid white;}"); + d->Layout = new QBoxLayout(QBoxLayout::TopToBottom); + d->Layout->setContentsMargins(0, 0, 0, 0); + 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); } //============================================================================ @@ -79,7 +203,71 @@ CDockContainerWidget* CDockAreaWidget::dockContainerWidget() const //============================================================================ void CDockAreaWidget::addDockWidget(CDockWidget* DockWidget) { - d->StackedLayout->addWidget(DockWidget); + d->ContentsLayout->addWidget(DockWidget); + auto TitleBar = DockWidget->titleBar(); + d->TabsLayout->insertWidget(d->TabsLayout->count() - d->TabsLayoutInitCount, + TitleBar); + connect(TitleBar, SIGNAL(clicked()), this, SLOT(onDockWidgetTitleClicked())); + // if this is the first tab, then activate it + if (d->ContentsLayout->count() == 1) + { + setCurrentIndex(0); + } +} + + +//============================================================================ +void CDockAreaWidget::onDockWidgetTitleClicked() +{ + CDockWidgetTitleBar* TitleWidget = qobject_cast(sender()); + if (!TitleWidget) + { + return; + } + + int index = d->TabsLayout->indexOf(TitleWidget); + setCurrentIndex(index); +} + + +//============================================================================ +void CDockAreaWidget::setCurrentIndex(int index) +{ + if (index < 0 || index > (d->TabsLayout->count() - 1)) + { + qWarning() << Q_FUNC_INFO << "Invalid index" << index; + return; + } + + // 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(item->widget()); + if (!TitleWidget) + { + continue; + } + + if (i == index) + { + TitleWidget->setActiveTab(true); + d->TabsScrollArea->ensureWidgetVisible(TitleWidget); + auto Features = TitleWidget->dockWidget()->features(); + d->CloseButton->setEnabled(Features.testFlag(CDockWidget::DockWidgetClosable)); + } + else + { + TitleWidget->setActiveTab(false); + } + } + + d->ContentsLayout->setCurrentIndex(index); } } // namespace ads diff --git a/AdvancedDockingSystem/src/v2/DockAreaWidget.h b/AdvancedDockingSystem/src/v2/DockAreaWidget.h index 274e201..cbf7cd9 100644 --- a/AdvancedDockingSystem/src/v2/DockAreaWidget.h +++ b/AdvancedDockingSystem/src/v2/DockAreaWidget.h @@ -1,5 +1,24 @@ #ifndef DockAreaWidgetH #define DockAreaWidgetH +/******************************************************************************* +** QtAdcancedDockingSystem +** Copyright (C) 2017 Uwe Kindler +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +******************************************************************************/ + + //============================================================================ /// \file DockAreaWidget.h /// \author Uwe Kindler @@ -7,6 +26,7 @@ /// \brief Declaration of CDockAreaWidget class //============================================================================ + //============================================================================ // INCLUDES //============================================================================ @@ -30,7 +50,10 @@ class CDockAreaWidget : public QFrame private: DockAreaWidgetPrivate* d; ///< private data (pimpl) friend class DockAreaWidgetPrivate; -protected: + +private slots: + void onDockWidgetTitleClicked(); + public: /** * Default Constructor @@ -53,6 +76,12 @@ public: * All dockwidgets in the dock area tabified in a stacked layout with tabs */ void addDockWidget(CDockWidget* DockWidget); + +public slots: + /** + * This sets the index position of the current tab page. + */ + void setCurrentIndex(int index); }; // class DockAreaWidget } // namespace ads diff --git a/AdvancedDockingSystem/src/v2/DockContainerWidget.cpp b/AdvancedDockingSystem/src/v2/DockContainerWidget.cpp index 67de3d4..e4434aa 100644 --- a/AdvancedDockingSystem/src/v2/DockContainerWidget.cpp +++ b/AdvancedDockingSystem/src/v2/DockContainerWidget.cpp @@ -1,3 +1,22 @@ +/******************************************************************************* +** QtAdcancedDockingSystem +** Copyright (C) 2017 Uwe Kindler +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +******************************************************************************/ + + //============================================================================ /// \file DockContainerWidget.cpp /// \author Uwe Kindler @@ -5,6 +24,7 @@ /// \brief Implementation of CDockContainerWidget class //============================================================================ + //============================================================================ // INCLUDES //============================================================================ @@ -65,14 +85,15 @@ struct DockContainerWidgetPrivate } /** - * Adds dock widget to container + * Adds dock widget to container and returns the dock area that contains + * the inserted dock widget */ - void dockWidgetIntoContainer(DockWidgetArea area, CDockWidget* Dockwidget); + CDockAreaWidget* dockWidgetIntoContainer(DockWidgetArea area, CDockWidget* Dockwidget); /** * Adds dock widget to a existing DockWidgetArea */ - void dockWidgetIntoDockArea(DockWidgetArea area, CDockWidget* Dockwidget, + CDockAreaWidget* dockWidgetIntoDockArea(DockWidgetArea area, CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget); }; // struct DockContainerWidgetPrivate @@ -86,7 +107,7 @@ DockContainerWidgetPrivate::DockContainerWidgetPrivate(CDockContainerWidget* _pu //============================================================================ -void DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetArea area, +CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetArea area, CDockWidget* Dockwidget) { CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this); @@ -133,14 +154,22 @@ void DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetArea area, } DockAreas.append(NewDockArea); + return NewDockArea; } //============================================================================ -void DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetArea area, +CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetArea area, CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget) { + if (CenterDockWidgetArea == area) + { + DockAreaWidget->addDockWidget(Dockwidget); + return DockAreaWidget; + } + auto InsertParam = internal::dockAreaInsertParameters(area); + return 0; } @@ -149,7 +178,7 @@ CDockContainerWidget::CDockContainerWidget(CDockManager* DockManager, QWidget *p QFrame(parent), d(new DockContainerWidgetPrivate(this)) { - setStyleSheet("background: green;"); + //setStyleSheet("background: green;"); d->DockManager = DockManager; d->Layout = new QGridLayout(); @@ -166,16 +195,16 @@ CDockContainerWidget::~CDockContainerWidget() //============================================================================ -void CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, +CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget) { if (DockAreaWidget) { - d->dockWidgetIntoDockArea(area, Dockwidget, DockAreaWidget); + return d->dockWidgetIntoDockArea(area, Dockwidget, DockAreaWidget); } else { - d->dockWidgetIntoContainer(area, Dockwidget); + return d->dockWidgetIntoContainer(area, Dockwidget); } } diff --git a/AdvancedDockingSystem/src/v2/DockContainerWidget.h b/AdvancedDockingSystem/src/v2/DockContainerWidget.h index f2fa97b..b28a57d 100644 --- a/AdvancedDockingSystem/src/v2/DockContainerWidget.h +++ b/AdvancedDockingSystem/src/v2/DockContainerWidget.h @@ -1,5 +1,24 @@ #ifndef DockContainerWidgetH #define DockContainerWidgetH +/******************************************************************************* +** QtAdcancedDockingSystem +** Copyright (C) 2017 Uwe Kindler +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +******************************************************************************/ + + //============================================================================ /// \file DockContainerWidget.h /// \author Uwe Kindler @@ -7,6 +26,7 @@ /// \brief Declaration of CDockContainerWidget class //============================================================================ + //============================================================================ // INCLUDES //============================================================================ @@ -53,8 +73,10 @@ public: * If DockAreaWidget is not null, then the area parameter indicates the area * into the DockAreaWidget. If DockAreaWidget is null, the Dockwidget will * be dropped into the container. + * \return Returns the dock area widget that contains the new DockWidget */ - void addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget = nullptr); + CDockAreaWidget* addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, + CDockAreaWidget* DockAreaWidget = nullptr); /** * Returns the current zOrderIndex diff --git a/AdvancedDockingSystem/src/v2/DockManager.cpp b/AdvancedDockingSystem/src/v2/DockManager.cpp index 555304e..0c0dae5 100644 --- a/AdvancedDockingSystem/src/v2/DockManager.cpp +++ b/AdvancedDockingSystem/src/v2/DockManager.cpp @@ -1,3 +1,21 @@ +/******************************************************************************* +** QtAdcancedDockingSystem +** Copyright (C) 2017 Uwe Kindler +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +******************************************************************************/ + //============================================================================ /// \file DockManager.cpp @@ -6,6 +24,7 @@ /// \brief Implementation of CDockManager class //============================================================================ + //============================================================================ // INCLUDES //============================================================================ diff --git a/AdvancedDockingSystem/src/v2/DockManager.h b/AdvancedDockingSystem/src/v2/DockManager.h index e6d818f..5b87bc3 100644 --- a/AdvancedDockingSystem/src/v2/DockManager.h +++ b/AdvancedDockingSystem/src/v2/DockManager.h @@ -1,5 +1,24 @@ #ifndef DockManagerH #define DockManagerH +/******************************************************************************* +** QtAdcancedDockingSystem +** Copyright (C) 2017 Uwe Kindler +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +******************************************************************************/ + + //============================================================================ /// \file DockManager.h /// \author Uwe Kindler @@ -7,6 +26,7 @@ /// \brief Declaration of CDockManager class //============================================================================ + //============================================================================ // INCLUDES //============================================================================ diff --git a/AdvancedDockingSystem/src/v2/DockWidget.cpp b/AdvancedDockingSystem/src/v2/DockWidget.cpp index 251520a..db46657 100644 --- a/AdvancedDockingSystem/src/v2/DockWidget.cpp +++ b/AdvancedDockingSystem/src/v2/DockWidget.cpp @@ -1,3 +1,21 @@ +/******************************************************************************* +** QtAdcancedDockingSystem +** Copyright (C) 2017 Uwe Kindler +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +******************************************************************************/ + //============================================================================ /// \file DockWidget.cpp @@ -6,6 +24,7 @@ /// \brief Implementation of CDockWidget class //============================================================================ + //============================================================================ // INCLUDES //============================================================================ @@ -13,6 +32,8 @@ #include +#include "DockWidgetTitleBar.h" + namespace ads { /** @@ -23,6 +44,8 @@ struct DockWidgetPrivate CDockWidget* _this; QBoxLayout* Layout; QWidget* Widget = nullptr; + CDockWidgetTitleBar* TitleWidget; + CDockWidget::DockWidgetFeatures Features = CDockWidget::AllDockWidgetFeatures; /** * Private data constructor @@ -47,6 +70,9 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) : d->Layout->setContentsMargins(0, 0, 0, 0); d->Layout->setSpacing(0); setLayout(d->Layout); + setWindowTitle(title); + + d->TitleWidget = new CDockWidgetTitleBar(this); } //============================================================================ @@ -77,6 +103,27 @@ QWidget* CDockWidget::widget() const { return d->Widget; } + + +//============================================================================ +CDockWidgetTitleBar* CDockWidget::titleBar() const +{ + return d->TitleWidget; +} + + +//============================================================================ +void CDockWidget::setFeatures(DockWidgetFeatures features) +{ + d->Features = features; +} + + +//============================================================================ +CDockWidget::DockWidgetFeatures CDockWidget::features() const +{ + return d->Features; +} } // namespace ads //--------------------------------------------------------------------------- diff --git a/AdvancedDockingSystem/src/v2/DockWidget.h b/AdvancedDockingSystem/src/v2/DockWidget.h index d7018c9..8905fa8 100644 --- a/AdvancedDockingSystem/src/v2/DockWidget.h +++ b/AdvancedDockingSystem/src/v2/DockWidget.h @@ -1,5 +1,24 @@ #ifndef DockWidgetH #define DockWidgetH +/******************************************************************************* +** QtAdcancedDockingSystem +** Copyright (C) 2017 Uwe Kindler +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +******************************************************************************/ + + //============================================================================ /// \file DockWidget.h /// \author Uwe Kindler @@ -7,6 +26,7 @@ /// \brief Declaration of CDockWidget class //============================================================================ + //============================================================================ // INCLUDES //============================================================================ @@ -15,6 +35,7 @@ namespace ads { struct DockWidgetPrivate; +class CDockWidgetTitleBar; /** * The QDockWidget class provides a widget that can be docked inside a @@ -28,6 +49,16 @@ private: friend class DockWidgetPrivate; protected: public: + enum DockWidgetFeature + { + DockWidgetClosable = 0x01, + DockWidgetMovable = 0x02, + DockWidgetFloatable = 0x04, + AllDockWidgetFeatures = DockWidgetClosable | DockWidgetMovable | DockWidgetFloatable, + NoDockWidgetFeatures = 0x00 + }; + Q_DECLARE_FLAGS(DockWidgetFeatures, DockWidgetFeature) + /** * Default Constructor */ @@ -48,6 +79,24 @@ public: * the widget has not been set. */ QWidget* widget() const; + + /** + * Returns the title bar widget of this dock widget + */ + CDockWidgetTitleBar* titleBar() const; + + /** + * Sets, whether the dock widget is movable, closable, and floatable. + */ + void setFeatures(DockWidgetFeatures features); + + /** + * This property holds whether the dock widget is movable, closable, and + * floatable. + * By default, this property is set to a combination of DockWidgetClosable, + * DockWidgetMovable and DockWidgetFloatable. + */ + DockWidgetFeatures features() const; }; // class DockWidget } // namespace ads diff --git a/AdvancedDockingSystem/src/v2/DockWidgetTitleBar.cpp b/AdvancedDockingSystem/src/v2/DockWidgetTitleBar.cpp index cb0eb3a..88ea940 100644 --- a/AdvancedDockingSystem/src/v2/DockWidgetTitleBar.cpp +++ b/AdvancedDockingSystem/src/v2/DockWidgetTitleBar.cpp @@ -1,18 +1,176 @@ +/******************************************************************************* +** QtAdcancedDockingSystem +** Copyright (C) 2017 Uwe Kindler +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +******************************************************************************/ + + //============================================================================ /// \file DockWidgetTitleBar.cpp /// \author Uwe Kindler -/// \date 23.02.2017 -/// \brief Implementation of DockWidgetTitleBar +/// \date 27.02.2017 +/// \brief Implementation of CDockWidgetTitleBar class //============================================================================ + //============================================================================ // INCLUDES //============================================================================ #include "DockWidgetTitleBar.h" +#include +#include +#include +#include + +#include "DockWidget.h" + namespace ads { +/** + * Private data class of CDockWidgetTitleBar class (pimpl) + */ +struct DockWidgetTitleBarPrivate +{ + CDockWidgetTitleBar* _this; + CDockWidget* DockWidget; + QLabel* IconLabel; + QLabel* TitleLabel; + QPoint DragStartMousePosition; + bool IsActiveTab = false; + /** + * Private data constructor + */ + DockWidgetTitleBarPrivate(CDockWidgetTitleBar* _public); + + /** + * Creates the complete layout including all controls + */ + void createLayout(); +}; +// struct DockWidgetTitleBarPrivate + +//============================================================================ +DockWidgetTitleBarPrivate::DockWidgetTitleBarPrivate(CDockWidgetTitleBar* _public) : + _this(_public) +{ + +} + + +//============================================================================ +void DockWidgetTitleBarPrivate::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(); + l->addWidget(TitleLabel, 1); + + IconLabel->setVisible(false); + TitleLabel->setVisible(true); + TitleLabel->setText(DockWidget->windowTitle()); +} + + +//============================================================================ +CDockWidgetTitleBar::CDockWidgetTitleBar(CDockWidget* DockWidget, QWidget *parent) : + QFrame(parent), + d(new DockWidgetTitleBarPrivate(this)) +{ + d->DockWidget = DockWidget; + d->createLayout(); +} + +//============================================================================ +CDockWidgetTitleBar::~CDockWidgetTitleBar() +{ + delete d; +} + + +//============================================================================ +void CDockWidgetTitleBar::mousePressEvent(QMouseEvent* ev) +{ + if (ev->button() == Qt::LeftButton) + { + ev->accept(); + d->DragStartMousePosition = ev->pos(); + return; + } + QFrame::mousePressEvent(ev); +} + + + +//============================================================================ +void CDockWidgetTitleBar::mouseReleaseEvent(QMouseEvent* ev) +{ + if (!d->DragStartMousePosition.isNull()) + { + emit clicked(); + } + + d->DragStartMousePosition = QPoint(); +} + + +//============================================================================ +void CDockWidgetTitleBar::mouseMoveEvent(QMouseEvent* ev) +{ + +} + + +//============================================================================ +bool CDockWidgetTitleBar::isActiveTab() const +{ + return d->IsActiveTab; +} + + +//============================================================================ +void CDockWidgetTitleBar::setActiveTab(bool active) +{ + if (d->IsActiveTab == active) + { + return; + } + + d->IsActiveTab = active; + style()->unpolish(this); + style()->polish(this); + d->TitleLabel->style()->unpolish(d->TitleLabel); + d->TitleLabel->style()->polish(d->TitleLabel); + update(); + + emit activeTabChanged(); +} + + +//============================================================================ +CDockWidget* CDockWidgetTitleBar::dockWidget() const +{ + return d->DockWidget; +} } // namespace ads //--------------------------------------------------------------------------- diff --git a/AdvancedDockingSystem/src/v2/DockWidgetTitleBar.h b/AdvancedDockingSystem/src/v2/DockWidgetTitleBar.h index b04c764..9afc673 100644 --- a/AdvancedDockingSystem/src/v2/DockWidgetTitleBar.h +++ b/AdvancedDockingSystem/src/v2/DockWidgetTitleBar.h @@ -1,26 +1,92 @@ #ifndef DockWidgetTitleBarH #define DockWidgetTitleBarH +/******************************************************************************* +** QtAdcancedDockingSystem +** Copyright (C) 2017 Uwe Kindler +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +******************************************************************************/ + + //============================================================================ /// \file DockWidgetTitleBar.h /// \author Uwe Kindler -/// \date 23.02.2017 -/// \brief Declaration of DockWidgetTitleBar +/// \date 27.02.2017 +/// \brief Declaration of CDockWidgetTitleBar class //============================================================================ + //============================================================================ // INCLUDES //============================================================================ +#include + namespace ads { +class CDockWidget; +struct DockWidgetTitleBarPrivate; /** - * @brief + * A dock widget title bar that shows a title and an icon */ -class CDockWidgetTitleBar +class CDockWidgetTitleBar : public QFrame { -}; + Q_OBJECT + Q_PROPERTY(bool activeTab READ isActiveTab WRITE setActiveTab NOTIFY activeTabChanged) -} // namespace ads +private: + DockWidgetTitleBarPrivate* d; ///< private data (pimpl) + friend class DockWidgetTitleBarPrivate; -//--------------------------------------------------------------------------- +protected: + virtual void mousePressEvent(QMouseEvent* ev) override; + virtual void mouseReleaseEvent(QMouseEvent* ev) override; + virtual void mouseMoveEvent(QMouseEvent* ev) override; + +public: + /** + * Default Constructor + * 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); + + /** + * Virtual Destructor + */ + virtual ~CDockWidgetTitleBar(); + + /** + * Returns true, if this is the active tab + */ + bool isActiveTab() const; + + /** + * Set this true to make this tab the active tab + */ + void setActiveTab(bool active); + + /** + * Returns the dock widget this title widget belongs to + */ + CDockWidget* dockWidget() const; + +signals: + void activeTabChanged(); + void clicked(); +}; // class DockWidgetTitleBar +} + // namespace ads +//----------------------------------------------------------------------------- #endif // DockWidgetTitleBarH diff --git a/AdvancedDockingSystem/src/v2/FloatingDockContainer.cpp b/AdvancedDockingSystem/src/v2/FloatingDockContainer.cpp index 1c28a22..686098f 100644 --- a/AdvancedDockingSystem/src/v2/FloatingDockContainer.cpp +++ b/AdvancedDockingSystem/src/v2/FloatingDockContainer.cpp @@ -1,3 +1,22 @@ +/******************************************************************************* +** QtAdcancedDockingSystem +** Copyright (C) 2017 Uwe Kindler +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +******************************************************************************/ + + //============================================================================ /// \file FloatingDockContainer.cpp /// \author Uwe Kindler @@ -5,6 +24,7 @@ /// \brief Implementation of CFloatingDockContainer //============================================================================ + //============================================================================ // INCLUDES //============================================================================ diff --git a/AdvancedDockingSystem/src/v2/FloatingDockContainer.h b/AdvancedDockingSystem/src/v2/FloatingDockContainer.h index ea8791d..17a8537 100644 --- a/AdvancedDockingSystem/src/v2/FloatingDockContainer.h +++ b/AdvancedDockingSystem/src/v2/FloatingDockContainer.h @@ -1,5 +1,24 @@ #ifndef FloatingDockContainerH #define FloatingDockContainerH +/******************************************************************************* +** QtAdcancedDockingSystem +** Copyright (C) 2017 Uwe Kindler +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +******************************************************************************/ + + //============================================================================ /// \file FloatingDockContainer.h /// \author Uwe Kindler @@ -7,6 +26,7 @@ /// \brief Declaration of CFloatingDockContainer //============================================================================ + //============================================================================ // INCLUDES //============================================================================ diff --git a/AdvancedDockingSystem/src/v2/ads_globals.cpp b/AdvancedDockingSystem/src/v2/ads_globals.cpp index 61fd2af..eccbe23 100644 --- a/AdvancedDockingSystem/src/v2/ads_globals.cpp +++ b/AdvancedDockingSystem/src/v2/ads_globals.cpp @@ -1,8 +1,27 @@ +/******************************************************************************* +** QtAdcancedDockingSystem +** Copyright (C) 2017 Uwe Kindler +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +******************************************************************************/ + + //============================================================================ /// \file ads_globals.cpp /// \author Uwe Kindler /// \date 24.02.2017 -/// \brief Implementation of +/// \brief Implementation of //============================================================================ diff --git a/AdvancedDockingSystem/src/v2/ads_globals.h b/AdvancedDockingSystem/src/v2/ads_globals.h index a8ea2e5..d0ad5e1 100644 --- a/AdvancedDockingSystem/src/v2/ads_globals.h +++ b/AdvancedDockingSystem/src/v2/ads_globals.h @@ -1,10 +1,29 @@ #ifndef ads_globalsH #define ads_globalsH +/******************************************************************************* +** QtAdcancedDockingSystem +** Copyright (C) 2017 Uwe Kindler +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +******************************************************************************/ + + //============================================================================ /// \file ads_globals.h /// \author Uwe Kindler /// \date 24.02.2017 -/// \brief Declaration of +/// \brief Declaration of //============================================================================ diff --git a/AdvancedDockingSystemDemo_v2/src/main.cpp b/AdvancedDockingSystemDemo_v2/src/main.cpp index cf61070..488b2e0 100644 --- a/AdvancedDockingSystemDemo_v2/src/main.cpp +++ b/AdvancedDockingSystemDemo_v2/src/main.cpp @@ -7,7 +7,7 @@ static void initStyleSheet(QApplication& a) { //Q_INIT_RESOURCE(ads); // If static linked. - QFile f(":ads/stylesheets/default-windows.css"); + QFile f(":ads/stylesheets/default-windows2.css"); if (f.open(QFile::ReadOnly)) { const QByteArray ba = f.readAll(); diff --git a/AdvancedDockingSystemDemo_v2/src/mainwindow.cpp b/AdvancedDockingSystemDemo_v2/src/mainwindow.cpp index 51a4c36..c1292a7 100644 --- a/AdvancedDockingSystemDemo_v2/src/mainwindow.cpp +++ b/AdvancedDockingSystemDemo_v2/src/mainwindow.cpp @@ -12,6 +12,7 @@ #include "DockManager.h" #include "DockWidget.h" +#include "DockAreaWidget.h" /////////////////////////////////////////////////////////////////////// @@ -20,6 +21,7 @@ static int CONTENT_COUNT = 0; static ads::CDockWidget* createLongTextLabelDockWidget(ads::CDockManager* DockManager) { + static int LabelCount = 0; QLabel* l = new QLabel(); l->setWordWrap(true); l->setAlignment(Qt::AlignTop | Qt::AlignLeft); @@ -33,27 +35,29 @@ static ads::CDockWidget* createLongTextLabelDockWidget(ads::CDockManager* DockMa "welches Passagen von Lorem Ipsum enhielt, so wie Desktop Software wie " "Aldus PageMaker - ebenfalls mit Lorem Ipsum.")); - ads::CDockWidget* DockWidget = new ads::CDockWidget("DockWidget1"); + ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Label %1").arg(LabelCount++)); DockWidget->setWidget(l); return DockWidget; } static ads::CDockWidget* createCalendarDockWidget(ads::CDockManager* DockManager) { + static int CalendarCount = 0; QCalendarWidget* w = new QCalendarWidget(); - ads::CDockWidget* DockWidget = new ads::CDockWidget("DockWidget1"); + ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Calendar %1").arg(CalendarCount++)); DockWidget->setWidget(w); return DockWidget; } static ads::CDockWidget* createFileSystemTreeDockWidget(ads::CDockManager* DockManager) { + static int FileSystemCount = 0; QTreeView* w = new QTreeView(); w->setFrameShape(QFrame::NoFrame); QFileSystemModel* m = new QFileSystemModel(w); m->setRootPath(QDir::currentPath()); w->setModel(m); - ads::CDockWidget* DockWidget = new ads::CDockWidget("DockWidget1"); + ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Filesystem %1").arg(FileSystemCount++)); DockWidget->setWidget(w); return DockWidget; } @@ -82,10 +86,13 @@ MainWindow::~MainWindow() void MainWindow::createContent() { - m_DockManager->addDockWidget(ads::LeftDockWidgetArea, createCalendarDockWidget(m_DockManager)); + auto DockWidget = createCalendarDockWidget(m_DockManager); + DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false)); + m_DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget); m_DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(m_DockManager)); m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(m_DockManager)); - m_DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(m_DockManager)); + auto DockArea = m_DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(m_DockManager)); + m_DockManager->addDockWidget(ads::CenterDockWidgetArea, createCalendarDockWidget(m_DockManager), DockArea); }