Merged the two draging state enumerations into a single one and reused it in FloatingDockContainer

This commit is contained in:
Uwe Kindler 2018-12-20 16:25:30 +01:00
parent e37e4fdf57
commit 48382ccd82
9 changed files with 62 additions and 43 deletions

View File

@ -228,16 +228,17 @@ void CDockAreaTabBar::mouseDoubleClickEvent(QMouseEvent *event)
{
return;
}
startFloating(event->pos());
makeAreaFloating(event->pos(), DraggingInactive);
}
//============================================================================
CFloatingDockContainer* CDockAreaTabBar::makeAreaFloating(const QPoint& Offset)
CFloatingDockContainer* CDockAreaTabBar::makeAreaFloating(const QPoint& Offset,
eDragState DragState)
{
QSize Size = d->DockArea->size();
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(d->DockArea);
FloatingWidget->startFloating(Offset, Size);
FloatingWidget->startFloating(Offset, Size, DragState);
auto TopLevelDockWidget = FloatingWidget->topLevelDockWidget();
if (TopLevelDockWidget)
{
@ -251,7 +252,7 @@ CFloatingDockContainer* CDockAreaTabBar::makeAreaFloating(const QPoint& Offset)
//============================================================================
void CDockAreaTabBar::startFloating(const QPoint& Offset)
{
d->FloatingWidget = makeAreaFloating(Offset);
d->FloatingWidget = makeAreaFloating(Offset, DraggingFloatingWidget);
}

View File

@ -30,6 +30,7 @@
// INCLUDES
//============================================================================
#include <QScrollArea>
#include "ads_globals.h"
namespace ads
{
@ -89,7 +90,8 @@ protected:
/**
* Makes the dock area floating
*/
CFloatingDockContainer* makeAreaFloating(const QPoint& Offset);
CFloatingDockContainer* makeAreaFloating(const QPoint& Offset,
eDragState DragState);
public:

View File

@ -265,7 +265,7 @@ void CDockAreaTitleBar::onCloseButtonClicked()
//============================================================================
void CDockAreaTitleBar::onUndockButtonClicked()
{
d->TabBar->makeAreaFloating(mapFromGlobal(QCursor::pos()));
d->TabBar->makeAreaFloating(mapFromGlobal(QCursor::pos()), DraggingInactive);
}

View File

@ -671,6 +671,7 @@ QSize CDockWidget::minimumSizeHint() const
return QSize(60, 40);
}
} // namespace ads
//---------------------------------------------------------------------------

View File

@ -45,6 +45,7 @@ class CDockManager;
class CDockContainerWidget;
class CDockAreaWidget;
class DockContainerWidgetPrivate;
class CFloatingDockContainer;
/**
* The QDockWidget class provides a widget that can be docked inside a

View File

@ -53,16 +53,6 @@
namespace ads
{
/**
* The different dragging states
*/
enum eDragState
{
DraggingInactive, //!< DraggingInactive
DraggingMousePressed, //!< DraggingMousePressed
DraggingTab, //!< DraggingTab
DraggingFloatingWidget//!< DraggingFloatingWidget
};
using tTabLabel = CElidingLabel;
using tCloseButton = QPushButton;
@ -229,13 +219,17 @@ bool DockWidgetTabPrivate::startFloating(eDragState DraggingState)
FloatingWidget = new CFloatingDockContainer(DockArea);
}
FloatingWidget->startFloating(DragStartMousePosition, Size);
if (DraggingFloatingWidget == DraggingState)
{
FloatingWidget->startDragging(DragStartMousePosition, Size);
auto Overlay = DockWidget->dockManager()->containerOverlay();
Overlay->setAllowedAreas(OuterDockAreas);
this->FloatingWidget = FloatingWidget;
}
else
{
FloatingWidget->initFloatingGeometry(DragStartMousePosition, Size);
}
DockWidget->emitTopLevelChanged(true);
return true;
}

View File

@ -50,16 +50,6 @@
namespace ads
{
static unsigned int zOrderCounter = 0;
/**
* The different dragging states
*/
enum eDragState
{
StateInactive, //!< DraggingInactive
StateMousePressed, //!< DraggingMousePressed
StateDraggingActive//!< DraggingFloatingWidget
};
/**
* Private data class of CFloatingDockContainer class (pimpl)
*/
@ -69,7 +59,7 @@ struct FloatingDockContainerPrivate
CDockContainerWidget* DockContainer;
unsigned int zOrderIndex = ++zOrderCounter;
QPointer<CDockManager> DockManager;
eDragState DraggingState = StateInactive;
eDragState DraggingState = DraggingInactive;
QPoint DragStartMousePosition;
CDockContainerWidget* DropContainer = nullptr;
CDockAreaWidget* SingleDockArea = nullptr;
@ -111,7 +101,7 @@ FloatingDockContainerPrivate::FloatingDockContainerPrivate(CFloatingDockContaine
//============================================================================
void FloatingDockContainerPrivate::titleMouseReleaseEvent()
{
setState(StateInactive);
setState(DraggingInactive);
if (!DropContainer)
{
return;
@ -301,12 +291,12 @@ void CFloatingDockContainer::moveEvent(QMoveEvent *event)
QWidget::moveEvent(event);
switch (d->DraggingState)
{
case StateMousePressed:
d->setState(StateDraggingActive);
case DraggingMousePressed:
d->setState(DraggingFloatingWidget);
d->updateDropOverlays(QCursor::pos());
break;
case StateDraggingActive:
case DraggingFloatingWidget:
d->updateDropOverlays(QCursor::pos());
break;
default:
@ -319,7 +309,7 @@ void CFloatingDockContainer::moveEvent(QMoveEvent *event)
void CFloatingDockContainer::closeEvent(QCloseEvent *event)
{
qDebug() << "CFloatingDockContainer closeEvent";
d->setState(StateInactive);
d->setState(DraggingInactive);
if (isClosable())
{
@ -365,20 +355,20 @@ bool CFloatingDockContainer::event(QEvent *e)
{
switch (d->DraggingState)
{
case StateInactive:
case DraggingInactive:
if (e->type() == QEvent::NonClientAreaMouseButtonPress && QGuiApplication::mouseButtons() == Qt::LeftButton)
{
qDebug() << "FloatingWidget::event Event::NonClientAreaMouseButtonPress" << e->type();
d->setState(StateMousePressed);
d->setState(DraggingMousePressed);
}
break;
case StateMousePressed:
case DraggingMousePressed:
switch (e->type())
{
case QEvent::NonClientAreaMouseButtonDblClick:
qDebug() << "FloatingWidget::event QEvent::NonClientAreaMouseButtonDblClick";
d->setState(StateInactive);
d->setState(DraggingInactive);
break;
case QEvent::Resize:
@ -392,7 +382,7 @@ bool CFloatingDockContainer::event(QEvent *e)
// change, we check, if we are not in maximized state.
if (!isMaximized())
{
d->setState(StateInactive);
d->setState(DraggingInactive);
}
break;
@ -401,7 +391,7 @@ bool CFloatingDockContainer::event(QEvent *e)
}
break;
case StateDraggingActive:
case DraggingFloatingWidget:
if (e->type() == QEvent::NonClientAreaMouseButtonRelease)
{
qDebug() << "FloatingWidget::event QEvent::NonClientAreaMouseButtonRelease";
@ -424,7 +414,7 @@ bool CFloatingDockContainer::event(QEvent *e)
bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event)
{
Q_UNUSED(watched);
if (event->type() == QEvent::MouseButtonRelease && d->isState(StateDraggingActive))
if (event->type() == QEvent::MouseButtonRelease && d->isState(DraggingFloatingWidget))
{
qDebug() << "FloatingWidget::eventFilter QEvent::MouseButtonRelease";
d->titleMouseReleaseEvent();
@ -435,10 +425,11 @@ bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event)
//============================================================================
void CFloatingDockContainer::startFloating(const QPoint& DragStartMousePos, const QSize& Size)
void CFloatingDockContainer::startFloating(const QPoint& DragStartMousePos, const QSize& Size,
eDragState DragState)
{
resize(Size);
d->setState(StateDraggingActive);
d->setState(DragState);
d->DragStartMousePosition = DragStartMousePos;
moveFloating();
show();

View File

@ -81,7 +81,25 @@ protected:
* Use moveToGlobalPos() to move the widget to a new position
* depending on the start position given in Pos parameter
*/
void startFloating(const QPoint& DragStartMousePos, const QSize& Size = QSize());
void startFloating(const QPoint& DragStartMousePos, const QSize& Size,
eDragState DragState);
/**
* Call this function to start dragging the floating widget
*/
void startDragging(const QPoint& DragStartMousePos, const QSize& Size)
{
startFloating(DragStartMousePos, Size, DraggingFloatingWidget);
}
/**
* Call this function if you just want to initialize the position
* and size of the floating widget
*/
void initFloatingGeometry(const QPoint& DragStartMousePos, const QSize& Size)
{
startFloating(DragStartMousePos, Size, DraggingInactive);
}
/**
* Moves the widget to a new position relative to the position given when

View File

@ -72,6 +72,17 @@ enum TitleBarButton
TitleBarButtonClose
};
/**
* The different dragging states
*/
enum eDragState
{
DraggingInactive, //!< DraggingInactive
DraggingMousePressed, //!< DraggingMousePressed
DraggingTab, //!< DraggingTab
DraggingFloatingWidget//!< DraggingFloatingWidget
};
namespace internal
{
static const bool RestoreTesting = true;