Improved source code documentation, removed empty main.qrc to silence qmake warning

This commit is contained in:
Uwe Kindler 2019-08-26 07:58:56 +02:00
parent a2b07fd97f
commit c8d4487a95
17 changed files with 397 additions and 375 deletions

View File

@ -21,7 +21,6 @@ HEADERS += \
FORMS += \
mainwindow.ui
RESOURCES += main.qrc
LIBS += -L$${ADS_OUT_ROOT}/lib

View File

@ -1,3 +0,0 @@
<RCC>
<qresource prefix="/main"/>
</RCC>

View File

@ -44,6 +44,10 @@ class CFloatingDockContainer;
* Custom tabbar implementation for tab area that is shown on top of a
* dock area widget.
* The tabbar displays the tab widgets of the contained dock widgets.
* We cannot use QTabBar here because it does a lot of fancy animations
* that will crash the application if a tab is removed while the animation
* has not finished. And we need to remove a tab, if the user drags a
* a dock widget out of a group of tabbed widgets
*/
class CDockAreaTabBar : public QScrollArea
{
@ -61,6 +65,7 @@ private slots:
protected:
virtual void wheelEvent(QWheelEvent* Event) override;
/**
* Stores mouse position to detect dragging
*/
@ -96,6 +101,7 @@ protected:
public:
using Super = QScrollArea;
/**
* Default Constructor
*/

View File

@ -99,8 +99,9 @@ struct DockAreaTitleBarPrivate
}
/**
* Helper class to set title bar button icons depending on operating system
* and to avoid duplicated code
* Helper function to set title bar button icons depending on operating
* system and to avoid duplicated code. On windows the standard icons
* are blurry since Qt 5.11 so we need to do some additional steps
*/
void setTitleBarButtonIcon(tTileBarButton* Button, QStyle::StandardPixmap StandarPixmap)
{
@ -136,14 +137,14 @@ void DockAreaTitleBarPrivate::createButtons()
TabsMenuButton->setPopupMode(QToolButton::InstantPopup);
setTitleBarButtonIcon(TabsMenuButton, QStyle::SP_TitleBarUnshadeButton);
QMenu* TabsMenu = new QMenu(TabsMenuButton);
#ifndef QT_NO_TOOLTIP
#ifndef QT_NO_TOOLTIP
TabsMenu->setToolTipsVisible(true);
#endif
#endif
_this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow()));
TabsMenuButton->setMenu(TabsMenu);
#ifndef QT_NO_TOOLTIP
#ifndef QT_NO_TOOLTIP
TabsMenuButton->setToolTip(QObject::tr("List all tabs"));
#endif
#endif
TabsMenuButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
TopLayout->addWidget(TabsMenuButton, 0);
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
@ -154,9 +155,9 @@ void DockAreaTitleBarPrivate::createButtons()
UndockButton = new tTileBarButton();
UndockButton->setObjectName("undockButton");
UndockButton->setAutoRaise(true);
#ifndef QT_NO_TOOLTIP
#ifndef QT_NO_TOOLTIP
UndockButton->setToolTip(QObject::tr("Detach Group"));
#endif
#endif
setTitleBarButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton);
UndockButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
TopLayout->addWidget(UndockButton, 0);
@ -168,7 +169,7 @@ void DockAreaTitleBarPrivate::createButtons()
CloseButton->setObjectName("closeButton");
CloseButton->setAutoRaise(true);
setTitleBarButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton);
#ifndef QT_NO_TOOLTIP
#ifndef QT_NO_TOOLTIP
if (testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
{
CloseButton->setToolTip(QObject::tr("Close Active Tab"));
@ -177,7 +178,7 @@ void DockAreaTitleBarPrivate::createButtons()
{
CloseButton->setToolTip(QObject::tr("Close Group"));
}
#endif
#endif
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
CloseButton->setIconSize(QSize(16, 16));
TopLayout->addWidget(CloseButton, 0);

View File

@ -43,7 +43,9 @@ class CDockAreaWidget;
struct DockAreaTitleBarPrivate;
/**
* Title bar of a dock area
* Title bar of a dock area.
* The title bar contains a tabbar with all tabs for a dock widget group and
* with a tabs menu button, a undock button and a close button.
*/
class CDockAreaTitleBar : public QFrame
{
@ -61,6 +63,10 @@ private slots:
void showContextMenu(const QPoint& pos);
public slots:
/**
* Call this slot to tell the title bar that it should update the tabs menu
* the next time it is shown.
*/
void markTabsMenuOutdated();
@ -87,7 +93,8 @@ public:
QAbstractButton* button(TitleBarButton which) const;
/**
* This function is here for debug reasons
* Marks the tabs menu outdated before it calls its base class
* implementation
*/
virtual void setVisible(bool Visible) override;

View File

@ -63,8 +63,11 @@ static const char* const INDEX_PROPERTY = "index";
static const char* const ACTION_PROPERTY = "action";
/**
* New dock area layout mimics stack layout but only inserts the current
* widget into the internal QLayout object
* Internal dock area layout mimics stack layout but only inserts the current
* widget into the internal QLayout object.
* \warning Only the current widget has a parent. All other widgets
* do not have a parent. That means, a widget that is in this layout may
* return nullptr for its parent() function if it is not the current widget.
*/
class CDockAreaLayout
{
@ -118,7 +121,7 @@ public:
}
/**
* Removes the given widget from the lyout
* Removes the given widget from the layout
*/
void removeWidget(QWidget* Widget)
{

View File

@ -185,12 +185,12 @@ public:
QList<CDockWidget*> dockWidgets() const;
/**
* Returns the number of dock widgets in this area
* Returns the number of open dock widgets in this area
*/
int openDockWidgetsCount() const;
/**
* Returns a list of dock widgets that are not closed
* Returns a list of dock widgets that are not closed.
*/
QList<CDockWidget*> openedDockWidgets() const;
@ -236,8 +236,10 @@ public:
* This functions returns the dock widget features of all dock widget in
* this area.
* A bitwise and is used to combine the flags of all dock widgets. That
* means, if only dock widget does not support a certain flag, the whole
* dock are does not support the flag.
* means, if only one single dock widget does not support a certain flag,
* the whole dock are does not support the flag. I.e. if one single
* dock widget in this area is not closabe, the whole dock are is not
* closable.
*/
CDockWidget::DockWidgetFeatures features() const;

View File

@ -50,7 +50,10 @@ struct FloatingDockContainerPrivate;
/**
* Container that manages a number of dock areas with single dock widgets
* or tabyfied dock widgets in each area
* or tabyfied dock widgets in each area.
* Each window that support docking has a DockContainerWidget. That means
* the main application window and all floating windows are ore contain
* an DockContainerWidget.
*/
class ADS_EXPORT CDockContainerWidget : public QFrame
{

View File

@ -131,7 +131,7 @@ public:
* If the given parent is a QMainWindow, the dock manager sets itself as the
* central widget.
* Before you create any dock widgets, you should properly setup the
* configuration flags via setConfigFlags()
* configuration flags via setConfigFlags().
*/
CDockManager(QWidget* parent = 0);

View File

@ -245,9 +245,6 @@ public:
protected:
virtual void showEvent(QShowEvent* e) override;
void setAreaWidgets(const QHash<DockWidgetArea, QWidget*>& widgets);
private:
}; // CDockOverlayCross
} // namespace ads

View File

@ -38,7 +38,8 @@ namespace ads
struct DockSplitterPrivate;
/**
* Splitter used internally instead of QSplitter
* Splitter used internally instead of QSplitter with some additional
* fuctionality.
*/
class ADS_EXPORT CDockSplitter : public QSplitter
{

View File

@ -143,7 +143,6 @@ public:
virtual bool event(QEvent *e) override;
public slots:
virtual void setVisible(bool visible) override;

View File

@ -1,21 +1,20 @@
/*******************************************************************************
** Qt Advanced Docking System
** Copyright (C) 2017 Uwe Kindler
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this library; If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
** Qt Advanced Docking System
** Copyright (C) 2017 Uwe Kindler
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this library; If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================
/// \file FloatingDockContainer.cpp
@ -24,7 +23,6 @@
/// \brief Implementation of CFloatingDockContainer class
//============================================================================
//============================================================================
// INCLUDES
//============================================================================
@ -50,7 +48,6 @@
#include <xcb/xcb.h>
#endif
namespace ads
{
static unsigned int zOrderCounter = 0;
@ -59,14 +56,14 @@ static unsigned int zOrderCounter = 0;
*/
struct FloatingDockContainerPrivate
{
CFloatingDockContainer* _this;
CDockContainerWidget* DockContainer;
CFloatingDockContainer *_this;
CDockContainerWidget *DockContainer;
unsigned int zOrderIndex = ++zOrderCounter;
QPointer<CDockManager> DockManager;
eDragState DraggingState = DraggingInactive;
QPoint DragStartMousePosition;
CDockContainerWidget* DropContainer = nullptr;
CDockAreaWidget* SingleDockArea = nullptr;
CDockContainerWidget *DropContainer = nullptr;
CDockAreaWidget *SingleDockArea = nullptr;
#ifdef Q_OS_LINUX
QWidget* MouseEventHandler = nullptr;
CFloatingWidgetTitleBar* TitleBar = nullptr;
@ -75,10 +72,10 @@ struct FloatingDockContainerPrivate
/**
* Private data constructor
*/
FloatingDockContainerPrivate(CFloatingDockContainer* _public);
FloatingDockContainerPrivate(CFloatingDockContainer *_public);
void titleMouseReleaseEvent();
void updateDropOverlays(const QPoint& GlobalPos);
void updateDropOverlays(const QPoint &GlobalPos);
/**
* Tests is a certain state is active
@ -93,7 +90,7 @@ struct FloatingDockContainerPrivate
DraggingState = StateId;
}
void setWindowTitle(const QString& Text)
void setWindowTitle(const QString &Text)
{
#ifdef Q_OS_LINUX
TitleBar->setTitle(Text);
@ -104,17 +101,14 @@ struct FloatingDockContainerPrivate
};
// struct FloatingDockContainerPrivate
//============================================================================
FloatingDockContainerPrivate::FloatingDockContainerPrivate(CFloatingDockContainer* _public) :
FloatingDockContainerPrivate::FloatingDockContainerPrivate(
CFloatingDockContainer *_public) :
_this(_public)
{
}
//============================================================================
void FloatingDockContainerPrivate::titleMouseReleaseEvent()
{
@ -124,25 +118,31 @@ void FloatingDockContainerPrivate::titleMouseReleaseEvent()
return;
}
if (DockManager->dockAreaOverlay()->dropAreaUnderCursor() != InvalidDockWidgetArea
|| DockManager->containerOverlay()->dropAreaUnderCursor() != InvalidDockWidgetArea)
if (DockManager->dockAreaOverlay()->dropAreaUnderCursor()
!= InvalidDockWidgetArea
|| DockManager->containerOverlay()->dropAreaUnderCursor()
!= InvalidDockWidgetArea)
{
// Resize the floating widget to the size of the highlighted drop area
// rectangle
CDockOverlay* Overlay = DockManager->containerOverlay();
CDockOverlay *Overlay = DockManager->containerOverlay();
if (!Overlay->dropOverlayRect().isValid())
{
Overlay = DockManager->dockAreaOverlay();
}
QRect Rect = Overlay->dropOverlayRect();
int FrameWidth = (_this->frameSize().width() - _this->rect().width()) / 2;
int TitleBarHeight = _this->frameSize().height() - _this->rect().height() - FrameWidth;
int FrameWidth = (_this->frameSize().width() - _this->rect().width())
/ 2;
int TitleBarHeight = _this->frameSize().height()
- _this->rect().height() - FrameWidth;
if (Rect.isValid())
{
QPoint TopLeft = Overlay->mapToGlobal(Rect.topLeft());
TopLeft.ry() += TitleBarHeight;
_this->setGeometry(QRect(TopLeft, QSize(Rect.width(), Rect.height() - TitleBarHeight)));
_this->setGeometry(
QRect(TopLeft,
QSize(Rect.width(), Rect.height() - TitleBarHeight)));
QApplication::processEvents();
}
DropContainer->dropFloatingWidget(_this, QCursor::pos());
@ -152,10 +152,8 @@ void FloatingDockContainerPrivate::titleMouseReleaseEvent()
DockManager->dockAreaOverlay()->hideOverlay();
}
//============================================================================
void FloatingDockContainerPrivate::updateDropOverlays(const QPoint& GlobalPos)
void FloatingDockContainerPrivate::updateDropOverlays(const QPoint &GlobalPos)
{
if (!_this->isVisible() || !DockManager)
{
@ -163,7 +161,7 @@ void FloatingDockContainerPrivate::updateDropOverlays(const QPoint& GlobalPos)
}
auto Containers = DockManager->dockContainers();
CDockContainerWidget* TopContainer = nullptr;
CDockContainerWidget *TopContainer = nullptr;
for (auto ContainerWidget : Containers)
{
if (!ContainerWidget->isVisible())
@ -198,23 +196,24 @@ void FloatingDockContainerPrivate::updateDropOverlays(const QPoint& GlobalPos)
}
int VisibleDockAreas = TopContainer->visibleDockAreaCount();
ContainerOverlay->setAllowedAreas(VisibleDockAreas > 1 ?
OuterDockAreas : AllDockAreas);
ContainerOverlay->setAllowedAreas(
VisibleDockAreas > 1 ? OuterDockAreas : AllDockAreas);
DockWidgetArea ContainerArea = ContainerOverlay->showOverlay(TopContainer);
ContainerOverlay->enableDropPreview(ContainerArea != InvalidDockWidgetArea);
auto DockArea = TopContainer->dockAreaAt(GlobalPos);
if (DockArea && DockArea->isVisible() && VisibleDockAreas > 0)
{
DockAreaOverlay->enableDropPreview(true);
DockAreaOverlay->setAllowedAreas((VisibleDockAreas == 1) ?
NoDockWidgetArea : AllDockAreas);
DockAreaOverlay->setAllowedAreas(
(VisibleDockAreas == 1) ? NoDockWidgetArea : AllDockAreas);
DockWidgetArea Area = DockAreaOverlay->showOverlay(DockArea);
// A CenterDockWidgetArea for the dockAreaOverlay() indicates that
// the mouse is in the title bar. If the ContainerArea is valid
// then we ignore the dock area of the dockAreaOverlay() and disable
// the drop preview
if ((Area == CenterDockWidgetArea) && (ContainerArea != InvalidDockWidgetArea))
if ((Area == CenterDockWidgetArea)
&& (ContainerArea != InvalidDockWidgetArea))
{
DockAreaOverlay->enableDropPreview(false);
ContainerOverlay->enableDropPreview(true);
@ -230,16 +229,17 @@ void FloatingDockContainerPrivate::updateDropOverlays(const QPoint& GlobalPos)
}
}
//============================================================================
CFloatingDockContainer::CFloatingDockContainer(CDockManager* DockManager) :
CFloatingDockContainer::CFloatingDockContainer(CDockManager *DockManager) :
tFloatingWidgetBase(DockManager),
d(new FloatingDockContainerPrivate(this))
{
d->DockManager = DockManager;
d->DockContainer = new CDockContainerWidget(DockManager, this);
connect(d->DockContainer, SIGNAL(dockAreasAdded()), this, SLOT(onDockAreasAddedOrRemoved()));
connect(d->DockContainer, SIGNAL(dockAreasRemoved()), this, SLOT(onDockAreasAddedOrRemoved()));
connect(d->DockContainer, SIGNAL(dockAreasAdded()), this,
SLOT(onDockAreasAddedOrRemoved()));
connect(d->DockContainer, SIGNAL(dockAreasRemoved()), this,
SLOT(onDockAreasAddedOrRemoved()));
#ifdef Q_OS_LINUX
d->TitleBar = new CFloatingWidgetTitleBar(this);
@ -250,8 +250,9 @@ CFloatingDockContainer::CFloatingDockContainer(CDockManager* DockManager) :
setTitleBarWidget(d->TitleBar);
connect(d->TitleBar, SIGNAL(closeRequested()), SLOT(close()));
#else
setWindowFlags(Qt::Window | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom);
setWindowFlags(
Qt::Window | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
QBoxLayout *l = new QBoxLayout(QBoxLayout::TopToBottom);
l->setContentsMargins(0, 0, 0, 0);
l->setSpacing(0);
setLayout(l);
@ -260,16 +261,14 @@ CFloatingDockContainer::CFloatingDockContainer(CDockManager* DockManager) :
DockManager->registerFloatingWidget(this);
// We install an event filter to detect mouse release events because we
// do not receive mouse release event if the floating widget is behind
// the drop overlay cross
qApp->installEventFilter(this);
}
//============================================================================
CFloatingDockContainer::CFloatingDockContainer(CDockAreaWidget* DockArea) :
CFloatingDockContainer::CFloatingDockContainer(CDockAreaWidget *DockArea) :
CFloatingDockContainer(DockArea->dockManager())
{
d->DockContainer->addDockArea(DockArea);
@ -278,9 +277,8 @@ CFloatingDockContainer::CFloatingDockContainer(CDockAreaWidget* DockArea) :
#endif
}
//============================================================================
CFloatingDockContainer::CFloatingDockContainer(CDockWidget* DockWidget) :
CFloatingDockContainer::CFloatingDockContainer(CDockWidget *DockWidget) :
CFloatingDockContainer(DockWidget->dockManager())
{
d->DockContainer->addDockWidget(CenterDockWidgetArea, DockWidget);
@ -300,14 +298,12 @@ CFloatingDockContainer::~CFloatingDockContainer()
delete d;
}
//============================================================================
CDockContainerWidget* CFloatingDockContainer::dockContainer() const
{
return d->DockContainer;
}
//============================================================================
void CFloatingDockContainer::changeEvent(QEvent *event)
{
@ -320,7 +316,6 @@ void CFloatingDockContainer::changeEvent(QEvent *event)
}
}
//============================================================================
void CFloatingDockContainer::moveEvent(QMoveEvent *event)
{
@ -340,7 +335,6 @@ void CFloatingDockContainer::moveEvent(QMoveEvent *event)
}
}
//============================================================================
void CFloatingDockContainer::closeEvent(QCloseEvent *event)
{
@ -375,7 +369,6 @@ void CFloatingDockContainer::closeEvent(QCloseEvent *event)
}
}
//============================================================================
void CFloatingDockContainer::hideEvent(QHideEvent *event)
{
@ -389,14 +382,12 @@ void CFloatingDockContainer::hideEvent(QHideEvent *event)
}
}
//============================================================================
void CFloatingDockContainer::showEvent(QShowEvent *event)
{
Super::showEvent(event);
}
//============================================================================
bool CFloatingDockContainer::event(QEvent *e)
{
@ -412,7 +403,8 @@ bool CFloatingDockContainer::event(QEvent *e)
// It is really great to work around the whole NonClientMouseArea
// bugs
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 2))
if (e->type() == QEvent::NonClientAreaMouseButtonPress /*&& QGuiApplication::mouseButtons().testFlag(Qt::LeftButton)*/)
if (e->type()
== QEvent::NonClientAreaMouseButtonPress /*&& QGuiApplication::mouseButtons().testFlag(Qt::LeftButton)*/)
{
ADS_PRINT("FloatingWidget::event Event::NonClientAreaMouseButtonPress" << e->type());
d->setState(DraggingMousePressed);
@ -473,12 +465,12 @@ bool CFloatingDockContainer::event(QEvent *e)
return QWidget::event(e);
}
//============================================================================
bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event)
{
Q_UNUSED(watched);
if (event->type() == QEvent::MouseButtonRelease && d->isState(DraggingFloatingWidget))
if (event->type() == QEvent::MouseButtonRelease
&& d->isState(DraggingFloatingWidget))
{
ADS_PRINT("FloatingWidget::eventFilter QEvent::MouseButtonRelease");
finishDragging();
@ -488,10 +480,9 @@ bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event)
return false;
}
//============================================================================
void CFloatingDockContainer::startFloating(const QPoint& DragStartMousePos, const QSize& Size,
eDragState DragState, QWidget* MouseEventHandler)
void CFloatingDockContainer::startFloating(const QPoint &DragStartMousePos,
const QSize &Size, eDragState DragState, QWidget *MouseEventHandler)
{
#ifndef Q_OS_LINUX
Q_UNUSED(MouseEventHandler)
@ -500,6 +491,13 @@ void CFloatingDockContainer::startFloating(const QPoint& DragStartMousePos, cons
d->setState(DragState);
d->DragStartMousePosition = DragStartMousePos;
#ifdef Q_OS_LINUX
// I have not found a way on Linux to display the floating widget behind the
// dock overlay. That means if the user drags this floating widget around,
// it is always painted in front of the dock overlay and dock overlay cross.
// and the user will not see the dock overlay. To work around this issue,
// the window opacity is set to 0.6 to make the dock overlay visible
// again. If someone has an idea, how to place the dragged floating widget
// behind the dock overlay, then a pull request would be welcome.
if (DraggingFloatingWidget == DragState)
{
setAttribute(Qt::WA_X11NetWmWindowTypeDock, true);
@ -516,23 +514,22 @@ void CFloatingDockContainer::startFloating(const QPoint& DragStartMousePos, cons
}
//============================================================================
void CFloatingDockContainer::moveFloating()
{
int BorderSize = (frameSize().width() - size().width()) / 2;
const QPoint moveToPos = QCursor::pos() - d->DragStartMousePosition - QPoint(BorderSize, 0);
const QPoint moveToPos = QCursor::pos() - d->DragStartMousePosition
- QPoint(BorderSize, 0);
move(moveToPos);
}
//============================================================================
bool CFloatingDockContainer::isClosable() const
{
return d->DockContainer->features().testFlag(CDockWidget::DockWidgetClosable);
return d->DockContainer->features().testFlag(
CDockWidget::DockWidgetClosable);
}
//============================================================================
void CFloatingDockContainer::onDockAreasAddedOrRemoved()
{
@ -541,7 +538,8 @@ void CFloatingDockContainer::onDockAreasAddedOrRemoved()
if (TopLevelDockArea)
{
d->SingleDockArea = TopLevelDockArea;
d->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle());
d->setWindowTitle(
d->SingleDockArea->currentDockWidget()->windowTitle());
connect(d->SingleDockArea, SIGNAL(currentChanged(int)), this,
SLOT(onDockAreaCurrentChanged(int)));
}
@ -557,7 +555,6 @@ void CFloatingDockContainer::onDockAreasAddedOrRemoved()
}
}
//============================================================================
void CFloatingDockContainer::updateWindowTitle()
{
@ -572,7 +569,6 @@ void CFloatingDockContainer::updateWindowTitle()
}
}
//============================================================================
void CFloatingDockContainer::onDockAreaCurrentChanged(int Index)
{
@ -580,9 +576,9 @@ void CFloatingDockContainer::onDockAreaCurrentChanged(int Index)
d->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle());
}
//============================================================================
bool CFloatingDockContainer::restoreState(QXmlStreamReader& Stream, bool Testing)
bool CFloatingDockContainer::restoreState(QXmlStreamReader &Stream,
bool Testing)
{
if (!d->DockContainer->restoreState(Stream, Testing))
{
@ -593,29 +589,24 @@ bool CFloatingDockContainer::restoreState(QXmlStreamReader& Stream, bool Testing
return true;
}
//============================================================================
bool CFloatingDockContainer::hasTopLevelDockWidget() const
{
return d->DockContainer->hasTopLevelDockWidget();
}
//============================================================================
CDockWidget* CFloatingDockContainer::topLevelDockWidget() const
{
return d->DockContainer->topLevelDockWidget();
}
//============================================================================
QList<CDockWidget*> CFloatingDockContainer::dockWidgets() const
{
return d->DockContainer->dockWidgets();
}
//============================================================================
void CFloatingDockContainer::finishDragging()
{
@ -632,7 +623,6 @@ void CFloatingDockContainer::finishDragging()
#endif
}
} // namespace ads
//---------------------------------------------------------------------------

View File

@ -60,7 +60,8 @@ class CFloatingWidgetTitleBar;
/**
* This implements a floating widget that is a dock container that accepts
* docking of dock widgets like the main window and that can be docked into
* another dock container
* another dock container.
* Every floating window of the docking system is a FloatingDockContainer.
*/
class ADS_EXPORT CFloatingDockContainer : public tFloatingWidgetBase
{

View File

@ -45,12 +45,15 @@
#define ADS_EXPORT
#endif
// Define ADS_DEBUG_PRINT to enable a lot of debug output
#ifdef ADS_DEBUG_PRINT
#define ADS_PRINT(s) qDebug() << s
#else
#define ADS_PRINT(s)
#endif
// Set ADS_DEBUG_LEVEL to enable additional debug output and to enable layout
// dumps to qDebug and std::cout after layout changes
#define ADS_DEBUG_LEVEL 0
class QSplitter;

View File

@ -1,21 +1,20 @@
/*******************************************************************************
** Qt Advanced Docking System
** Copyright (C) 2017 Uwe Kindler
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this library; If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
** Qt Advanced Docking System
** Copyright (C) 2017 Uwe Kindler
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this library; If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================
/// \file FloatingWidgetTitleBar.cpp
@ -48,20 +47,22 @@ namespace ads
using tTabLabel = CElidingLabel;
using tCloseButton = QPushButton;
/**
* @brief Private data class of public interface CFloatingWidgetTitleBar
*/
struct FloatingWidgetTitleBarPrivate
{
CFloatingWidgetTitleBar* _this; ///< public interface class
QLabel* IconLabel = nullptr;
tTabLabel* TitleLabel;
tCloseButton* CloseButton = nullptr;
CFloatingDockContainer* FloatingWidget = nullptr;
CFloatingWidgetTitleBar *_this; ///< public interface class
QLabel *IconLabel = nullptr;
tTabLabel *TitleLabel;
tCloseButton *CloseButton = nullptr;
CFloatingDockContainer *FloatingWidget = nullptr;
eDragState DragState = DraggingInactive;
FloatingWidgetTitleBarPrivate(CFloatingWidgetTitleBar* _public) : _this(_public) {}
FloatingWidgetTitleBarPrivate(CFloatingWidgetTitleBar *_public) :
_this(_public)
{
}
/**
* Creates the complete layout including all controls
@ -69,7 +70,6 @@ struct FloatingWidgetTitleBarPrivate
void createLayout();
};
//============================================================================
void FloatingWidgetTitleBarPrivate::createLayout()
{
@ -82,13 +82,16 @@ void FloatingWidgetTitleBarPrivate::createLayout()
CloseButton = new tCloseButton();
CloseButton->setObjectName("floatingTitleCloseButton");
CloseButton->setFlat(true);
//CloseButton->setAutoRaise(true);
// The standard icons do does not look good on high DPI screens
QIcon CloseIcon;
QPixmap normalPixmap = _this->style()->standardPixmap(QStyle::SP_TitleBarCloseButton, 0, CloseButton);
QPixmap normalPixmap = _this->style()->standardPixmap(
QStyle::SP_TitleBarCloseButton, 0, CloseButton);
CloseIcon.addPixmap(normalPixmap, QIcon::Normal);
CloseIcon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
CloseButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
CloseIcon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25),
QIcon::Disabled);
CloseButton->setIcon(
_this->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
CloseButton->setVisible(true);
CloseButton->setFocusPolicy(Qt::NoFocus);
@ -98,8 +101,8 @@ void FloatingWidgetTitleBarPrivate::createLayout()
int Spacing = qRound(fm.height() / 4.0);
// Fill the layout
QBoxLayout* Layout = new QBoxLayout(QBoxLayout::LeftToRight);
Layout->setContentsMargins(6,0,0,0);
QBoxLayout *Layout = new QBoxLayout(QBoxLayout::LeftToRight);
Layout->setContentsMargins(6, 0, 0, 0);
Layout->setSpacing(0);
_this->setLayout(Layout);
Layout->addWidget(TitleLabel, 1);
@ -110,47 +113,43 @@ void FloatingWidgetTitleBarPrivate::createLayout()
TitleLabel->setVisible(true);
}
//============================================================================
CFloatingWidgetTitleBar::CFloatingWidgetTitleBar(CFloatingDockContainer *parent)
: QWidget(parent),
CFloatingWidgetTitleBar::CFloatingWidgetTitleBar(CFloatingDockContainer *parent) :
QWidget(parent),
d(new FloatingWidgetTitleBarPrivate(this))
{
d->FloatingWidget = parent;
d->createLayout();
}
//============================================================================
CFloatingWidgetTitleBar::~CFloatingWidgetTitleBar()
{
delete d;
}
//============================================================================
void CFloatingWidgetTitleBar::mousePressEvent(QMouseEvent* ev)
void CFloatingWidgetTitleBar::mousePressEvent(QMouseEvent *ev)
{
if (ev->button() == Qt::LeftButton)
{
d->DragState = DraggingFloatingWidget;
d->FloatingWidget->startDragging(ev->pos(), d->FloatingWidget->size(), this);
d->FloatingWidget->startDragging(ev->pos(), d->FloatingWidget->size(),
this);
return;
}
Super::mousePressEvent(ev);
}
//============================================================================
void CFloatingWidgetTitleBar::mouseReleaseEvent(QMouseEvent* ev)
void CFloatingWidgetTitleBar::mouseReleaseEvent(QMouseEvent *ev)
{
d->DragState = DraggingInactive;
Super::mouseReleaseEvent(ev);
}
//============================================================================
void CFloatingWidgetTitleBar::mouseMoveEvent(QMouseEvent* ev)
void CFloatingWidgetTitleBar::mouseMoveEvent(QMouseEvent *ev)
{
if (!(ev->buttons() & Qt::LeftButton) || DraggingInactive == d->DragState)
{
@ -169,19 +168,16 @@ void CFloatingWidgetTitleBar::mouseMoveEvent(QMouseEvent* ev)
Super::mouseMoveEvent(ev);
}
//============================================================================
void CFloatingWidgetTitleBar::enableCloseButton(bool Enable)
{
d->CloseButton->setEnabled(Enable);
}
//============================================================================
void CFloatingWidgetTitleBar::setTitle(const QString& Text)
void CFloatingWidgetTitleBar::setTitle(const QString &Text)
{
d->TitleLabel->setText(Text);
}
} // namespace ads

View File

@ -37,31 +37,48 @@ class CFloatingDockContainer;
struct FloatingWidgetTitleBarPrivate;
/**
* Titlebar for floating widgets to capture non client are mouse events.
* Linux does not support NonClieantArea mouse events like
* QEvent::NonClientAreaMouseButtonPress. Because these events are required
* for the docking system to work properly, we use our own titlebar here to
* capture the required mouse events.
*/
class CFloatingWidgetTitleBar : public QWidget
{
Q_OBJECT
private:
FloatingWidgetTitleBarPrivate* d; ///< private data (pimpl)
FloatingWidgetTitleBarPrivate *d; ///< private data (pimpl)
protected:
virtual void mousePressEvent(QMouseEvent* ev) override;
virtual void mouseReleaseEvent(QMouseEvent* ev) override;
virtual void mouseMoveEvent(QMouseEvent* ev) override;
virtual void mousePressEvent(QMouseEvent *ev) override;
virtual void mouseReleaseEvent(QMouseEvent *ev) override;
virtual void mouseMoveEvent(QMouseEvent *ev) override;
public:
using Super = QWidget;
explicit CFloatingWidgetTitleBar (CFloatingDockContainer *parent = nullptr);
explicit CFloatingWidgetTitleBar(CFloatingDockContainer *parent = nullptr);
/**
* Virtual Destructor
*/
virtual ~CFloatingWidgetTitleBar();
/**
* Enables / disables the window close button.
*/
void enableCloseButton(bool Enable);
void setTitle(const QString& Text);
/**
* Sets the window title, that means, the text of the internal tile label.
*/
void setTitle(const QString &Text);
signals:
/**
* This signal is emitted, if the close button is clicked.
*/
void closeRequested();
};
} // namespace ads