COntinued implementation of new advanced docking system, added stylesheet

This commit is contained in:
Uwe Kindler 2017-02-27 14:15:20 +01:00
parent 4a0c176327
commit f0584ff0c5
18 changed files with 806 additions and 35 deletions

View File

@ -3,5 +3,6 @@
<file>stylesheets/default-windows.css</file> <file>stylesheets/default-windows.css</file>
<file>stylesheets/vendor-partsolutions.css</file> <file>stylesheets/vendor-partsolutions.css</file>
<file>stylesheets/modern-windows.css</file> <file>stylesheets/modern-windows.css</file>
<file>stylesheets/default-windows2.css</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -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;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================ //============================================================================
/// \file DockAreaWidget.cpp /// \file DockAreaWidget.cpp
/// \author Uwe Kindler /// \author Uwe Kindler
@ -5,33 +24,90 @@
/// \brief Implementation of CDockAreaWidget class /// \brief Implementation of CDockAreaWidget class
//============================================================================ //============================================================================
//============================================================================ //============================================================================
// INCLUDES // INCLUDES
//============================================================================ //============================================================================
#include "DockAreaWidget.h" #include "DockAreaWidget.h"
#include <QStackedLayout> #include <QStackedLayout>
#include <QScrollBar>
#include <QScrollArea>
#include <QWheelEvent>
#include <QStyle>
#include <QPushButton>
#include <QDebug>
#include "DockContainerWidget.h" #include "DockContainerWidget.h"
#include "DockWidget.h" #include "DockWidget.h"
#include "DockWidgetTitleBar.h"
#include <iostream>
namespace ads 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) * Private data class of CDockAreaWidget class (pimpl)
*/ */
struct DockAreaWidgetPrivate struct DockAreaWidgetPrivate
{ {
CDockAreaWidget* _this; 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 * Private data constructor
*/ */
DockAreaWidgetPrivate(CDockAreaWidget* _public); DockAreaWidgetPrivate(CDockAreaWidget* _public);
/**
* Creates the layout for top area with tabs and close button
*/
void createTabBar();
}; };
// struct DockAreaWidgetPrivate // struct DockAreaWidgetPrivate
//============================================================================ //============================================================================
DockAreaWidgetPrivate::DockAreaWidgetPrivate(CDockAreaWidget* _public) : DockAreaWidgetPrivate::DockAreaWidgetPrivate(CDockAreaWidget* _public) :
_this(_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) : CDockAreaWidget::CDockAreaWidget(CDockManager* DockManager, CDockContainerWidget* parent) :
QFrame(parent), QFrame(parent),
d(new DockAreaWidgetPrivate(this)) d(new DockAreaWidgetPrivate(this))
{ {
setStyleSheet("background: yellow;"); setStyleSheet("ads--CDockAreaWidget {border: 1px solid white;}");
d->StackedLayout = new QStackedLayout(); d->Layout = new QBoxLayout(QBoxLayout::TopToBottom);
d->StackedLayout->setContentsMargins(0, 0, 0, 0); d->Layout->setContentsMargins(0, 0, 0, 0);
d->StackedLayout->setSpacing(0); d->Layout->setSpacing(0);
setLayout(d->StackedLayout); 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) 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<CDockWidgetTitleBar*>(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<CDockWidgetTitleBar*>(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 } // namespace ads

View File

@ -1,5 +1,24 @@
#ifndef DockAreaWidgetH #ifndef DockAreaWidgetH
#define 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 <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================ //============================================================================
/// \file DockAreaWidget.h /// \file DockAreaWidget.h
/// \author Uwe Kindler /// \author Uwe Kindler
@ -7,6 +26,7 @@
/// \brief Declaration of CDockAreaWidget class /// \brief Declaration of CDockAreaWidget class
//============================================================================ //============================================================================
//============================================================================ //============================================================================
// INCLUDES // INCLUDES
//============================================================================ //============================================================================
@ -30,7 +50,10 @@ class CDockAreaWidget : public QFrame
private: private:
DockAreaWidgetPrivate* d; ///< private data (pimpl) DockAreaWidgetPrivate* d; ///< private data (pimpl)
friend class DockAreaWidgetPrivate; friend class DockAreaWidgetPrivate;
protected:
private slots:
void onDockWidgetTitleClicked();
public: public:
/** /**
* Default Constructor * Default Constructor
@ -53,6 +76,12 @@ public:
* All dockwidgets in the dock area tabified in a stacked layout with tabs * All dockwidgets in the dock area tabified in a stacked layout with tabs
*/ */
void addDockWidget(CDockWidget* DockWidget); void addDockWidget(CDockWidget* DockWidget);
public slots:
/**
* This sets the index position of the current tab page.
*/
void setCurrentIndex(int index);
}; // class DockAreaWidget }; // class DockAreaWidget
} }
// namespace ads // namespace ads

View File

@ -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 <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================ //============================================================================
/// \file DockContainerWidget.cpp /// \file DockContainerWidget.cpp
/// \author Uwe Kindler /// \author Uwe Kindler
@ -5,6 +24,7 @@
/// \brief Implementation of CDockContainerWidget class /// \brief Implementation of CDockContainerWidget class
//============================================================================ //============================================================================
//============================================================================ //============================================================================
// INCLUDES // 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 * Adds dock widget to a existing DockWidgetArea
*/ */
void dockWidgetIntoDockArea(DockWidgetArea area, CDockWidget* Dockwidget, CDockAreaWidget* dockWidgetIntoDockArea(DockWidgetArea area, CDockWidget* Dockwidget,
CDockAreaWidget* DockAreaWidget); CDockAreaWidget* DockAreaWidget);
}; // struct DockContainerWidgetPrivate }; // struct DockContainerWidgetPrivate
@ -86,7 +107,7 @@ DockContainerWidgetPrivate::DockContainerWidgetPrivate(CDockContainerWidget* _pu
//============================================================================ //============================================================================
void DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetArea area, CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetArea area,
CDockWidget* Dockwidget) CDockWidget* Dockwidget)
{ {
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this); CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
@ -133,14 +154,22 @@ void DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetArea area,
} }
DockAreas.append(NewDockArea); DockAreas.append(NewDockArea);
return NewDockArea;
} }
//============================================================================ //============================================================================
void DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetArea area, CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetArea area,
CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget) 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), QFrame(parent),
d(new DockContainerWidgetPrivate(this)) d(new DockContainerWidgetPrivate(this))
{ {
setStyleSheet("background: green;"); //setStyleSheet("background: green;");
d->DockManager = DockManager; d->DockManager = DockManager;
d->Layout = new QGridLayout(); 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) CDockAreaWidget* DockAreaWidget)
{ {
if (DockAreaWidget) if (DockAreaWidget)
{ {
d->dockWidgetIntoDockArea(area, Dockwidget, DockAreaWidget); return d->dockWidgetIntoDockArea(area, Dockwidget, DockAreaWidget);
} }
else else
{ {
d->dockWidgetIntoContainer(area, Dockwidget); return d->dockWidgetIntoContainer(area, Dockwidget);
} }
} }

View File

@ -1,5 +1,24 @@
#ifndef DockContainerWidgetH #ifndef DockContainerWidgetH
#define 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 <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================ //============================================================================
/// \file DockContainerWidget.h /// \file DockContainerWidget.h
/// \author Uwe Kindler /// \author Uwe Kindler
@ -7,6 +26,7 @@
/// \brief Declaration of CDockContainerWidget class /// \brief Declaration of CDockContainerWidget class
//============================================================================ //============================================================================
//============================================================================ //============================================================================
// INCLUDES // INCLUDES
//============================================================================ //============================================================================
@ -53,8 +73,10 @@ public:
* If DockAreaWidget is not null, then the area parameter indicates the area * If DockAreaWidget is not null, then the area parameter indicates the area
* into the DockAreaWidget. If DockAreaWidget is null, the Dockwidget will * into the DockAreaWidget. If DockAreaWidget is null, the Dockwidget will
* be dropped into the container. * 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 * Returns the current zOrderIndex

View File

@ -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 <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================ //============================================================================
/// \file DockManager.cpp /// \file DockManager.cpp
@ -6,6 +24,7 @@
/// \brief Implementation of CDockManager class /// \brief Implementation of CDockManager class
//============================================================================ //============================================================================
//============================================================================ //============================================================================
// INCLUDES // INCLUDES
//============================================================================ //============================================================================

View File

@ -1,5 +1,24 @@
#ifndef DockManagerH #ifndef DockManagerH
#define 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 <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================ //============================================================================
/// \file DockManager.h /// \file DockManager.h
/// \author Uwe Kindler /// \author Uwe Kindler
@ -7,6 +26,7 @@
/// \brief Declaration of CDockManager class /// \brief Declaration of CDockManager class
//============================================================================ //============================================================================
//============================================================================ //============================================================================
// INCLUDES // INCLUDES
//============================================================================ //============================================================================

View File

@ -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 <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================ //============================================================================
/// \file DockWidget.cpp /// \file DockWidget.cpp
@ -6,6 +24,7 @@
/// \brief Implementation of CDockWidget class /// \brief Implementation of CDockWidget class
//============================================================================ //============================================================================
//============================================================================ //============================================================================
// INCLUDES // INCLUDES
//============================================================================ //============================================================================
@ -13,6 +32,8 @@
#include <QBoxLayout> #include <QBoxLayout>
#include "DockWidgetTitleBar.h"
namespace ads namespace ads
{ {
/** /**
@ -23,6 +44,8 @@ struct DockWidgetPrivate
CDockWidget* _this; CDockWidget* _this;
QBoxLayout* Layout; QBoxLayout* Layout;
QWidget* Widget = nullptr; QWidget* Widget = nullptr;
CDockWidgetTitleBar* TitleWidget;
CDockWidget::DockWidgetFeatures Features = CDockWidget::AllDockWidgetFeatures;
/** /**
* Private data constructor * Private data constructor
@ -47,6 +70,9 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
d->Layout->setContentsMargins(0, 0, 0, 0); d->Layout->setContentsMargins(0, 0, 0, 0);
d->Layout->setSpacing(0); d->Layout->setSpacing(0);
setLayout(d->Layout); setLayout(d->Layout);
setWindowTitle(title);
d->TitleWidget = new CDockWidgetTitleBar(this);
} }
//============================================================================ //============================================================================
@ -77,6 +103,27 @@ QWidget* CDockWidget::widget() const
{ {
return d->Widget; 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 } // namespace ads
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -1,5 +1,24 @@
#ifndef DockWidgetH #ifndef DockWidgetH
#define 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 <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================ //============================================================================
/// \file DockWidget.h /// \file DockWidget.h
/// \author Uwe Kindler /// \author Uwe Kindler
@ -7,6 +26,7 @@
/// \brief Declaration of CDockWidget class /// \brief Declaration of CDockWidget class
//============================================================================ //============================================================================
//============================================================================ //============================================================================
// INCLUDES // INCLUDES
//============================================================================ //============================================================================
@ -15,6 +35,7 @@
namespace ads namespace ads
{ {
struct DockWidgetPrivate; struct DockWidgetPrivate;
class CDockWidgetTitleBar;
/** /**
* The QDockWidget class provides a widget that can be docked inside a * The QDockWidget class provides a widget that can be docked inside a
@ -28,6 +49,16 @@ private:
friend class DockWidgetPrivate; friend class DockWidgetPrivate;
protected: protected:
public: public:
enum DockWidgetFeature
{
DockWidgetClosable = 0x01,
DockWidgetMovable = 0x02,
DockWidgetFloatable = 0x04,
AllDockWidgetFeatures = DockWidgetClosable | DockWidgetMovable | DockWidgetFloatable,
NoDockWidgetFeatures = 0x00
};
Q_DECLARE_FLAGS(DockWidgetFeatures, DockWidgetFeature)
/** /**
* Default Constructor * Default Constructor
*/ */
@ -48,6 +79,24 @@ public:
* the widget has not been set. * the widget has not been set.
*/ */
QWidget* widget() const; 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 }; // class DockWidget
} }
// namespace ads // namespace ads

View File

@ -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 <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================ //============================================================================
/// \file DockWidgetTitleBar.cpp /// \file DockWidgetTitleBar.cpp
/// \author Uwe Kindler /// \author Uwe Kindler
/// \date 23.02.2017 /// \date 27.02.2017
/// \brief Implementation of DockWidgetTitleBar /// \brief Implementation of CDockWidgetTitleBar class
//============================================================================ //============================================================================
//============================================================================ //============================================================================
// INCLUDES // INCLUDES
//============================================================================ //============================================================================
#include "DockWidgetTitleBar.h" #include "DockWidgetTitleBar.h"
#include <QBoxLayout>
#include <QLabel>
#include <QMouseEvent>
#include <QStyle>
#include "DockWidget.h"
namespace ads 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 } // namespace ads
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -1,26 +1,92 @@
#ifndef DockWidgetTitleBarH #ifndef DockWidgetTitleBarH
#define 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 <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================ //============================================================================
/// \file DockWidgetTitleBar.h /// \file DockWidgetTitleBar.h
/// \author Uwe Kindler /// \author Uwe Kindler
/// \date 23.02.2017 /// \date 27.02.2017
/// \brief Declaration of DockWidgetTitleBar /// \brief Declaration of CDockWidgetTitleBar class
//============================================================================ //============================================================================
//============================================================================ //============================================================================
// INCLUDES // INCLUDES
//============================================================================ //============================================================================
#include <QFrame>
namespace ads 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 #endif // DockWidgetTitleBarH

View File

@ -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 <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================ //============================================================================
/// \file FloatingDockContainer.cpp /// \file FloatingDockContainer.cpp
/// \author Uwe Kindler /// \author Uwe Kindler
@ -5,6 +24,7 @@
/// \brief Implementation of CFloatingDockContainer /// \brief Implementation of CFloatingDockContainer
//============================================================================ //============================================================================
//============================================================================ //============================================================================
// INCLUDES // INCLUDES
//============================================================================ //============================================================================

View File

@ -1,5 +1,24 @@
#ifndef FloatingDockContainerH #ifndef FloatingDockContainerH
#define 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 <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================ //============================================================================
/// \file FloatingDockContainer.h /// \file FloatingDockContainer.h
/// \author Uwe Kindler /// \author Uwe Kindler
@ -7,6 +26,7 @@
/// \brief Declaration of CFloatingDockContainer /// \brief Declaration of CFloatingDockContainer
//============================================================================ //============================================================================
//============================================================================ //============================================================================
// INCLUDES // INCLUDES
//============================================================================ //============================================================================

View File

@ -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 <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================ //============================================================================
/// \file ads_globals.cpp /// \file ads_globals.cpp
/// \author Uwe Kindler /// \author Uwe Kindler

View File

@ -1,5 +1,24 @@
#ifndef ads_globalsH #ifndef ads_globalsH
#define 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 <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================ //============================================================================
/// \file ads_globals.h /// \file ads_globals.h
/// \author Uwe Kindler /// \author Uwe Kindler

View File

@ -7,7 +7,7 @@
static void initStyleSheet(QApplication& a) static void initStyleSheet(QApplication& a)
{ {
//Q_INIT_RESOURCE(ads); // If static linked. //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)) if (f.open(QFile::ReadOnly))
{ {
const QByteArray ba = f.readAll(); const QByteArray ba = f.readAll();

View File

@ -12,6 +12,7 @@
#include "DockManager.h" #include "DockManager.h"
#include "DockWidget.h" #include "DockWidget.h"
#include "DockAreaWidget.h"
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
@ -20,6 +21,7 @@ static int CONTENT_COUNT = 0;
static ads::CDockWidget* createLongTextLabelDockWidget(ads::CDockManager* DockManager) static ads::CDockWidget* createLongTextLabelDockWidget(ads::CDockManager* DockManager)
{ {
static int LabelCount = 0;
QLabel* l = new QLabel(); QLabel* l = new QLabel();
l->setWordWrap(true); l->setWordWrap(true);
l->setAlignment(Qt::AlignTop | Qt::AlignLeft); 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 " "welches Passagen von Lorem Ipsum enhielt, so wie Desktop Software wie "
"Aldus PageMaker - ebenfalls mit Lorem Ipsum.")); "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); DockWidget->setWidget(l);
return DockWidget; return DockWidget;
} }
static ads::CDockWidget* createCalendarDockWidget(ads::CDockManager* DockManager) static ads::CDockWidget* createCalendarDockWidget(ads::CDockManager* DockManager)
{ {
static int CalendarCount = 0;
QCalendarWidget* w = new QCalendarWidget(); 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); DockWidget->setWidget(w);
return DockWidget; return DockWidget;
} }
static ads::CDockWidget* createFileSystemTreeDockWidget(ads::CDockManager* DockManager) static ads::CDockWidget* createFileSystemTreeDockWidget(ads::CDockManager* DockManager)
{ {
static int FileSystemCount = 0;
QTreeView* w = new QTreeView(); QTreeView* w = new QTreeView();
w->setFrameShape(QFrame::NoFrame); w->setFrameShape(QFrame::NoFrame);
QFileSystemModel* m = new QFileSystemModel(w); QFileSystemModel* m = new QFileSystemModel(w);
m->setRootPath(QDir::currentPath()); m->setRootPath(QDir::currentPath());
w->setModel(m); w->setModel(m);
ads::CDockWidget* DockWidget = new ads::CDockWidget("DockWidget1"); ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Filesystem %1").arg(FileSystemCount++));
DockWidget->setWidget(w); DockWidget->setWidget(w);
return DockWidget; return DockWidget;
} }
@ -82,10 +86,13 @@ MainWindow::~MainWindow()
void MainWindow::createContent() 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::LeftDockWidgetArea, createLongTextLabelDockWidget(m_DockManager));
m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(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);
} }