mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-03-16 02:59:51 +08:00
Merged the two draging state enumerations into a single one and reused it in FloatingDockContainer
This commit is contained in:
parent
e37e4fdf57
commit
48382ccd82
@ -228,16 +228,17 @@ void CDockAreaTabBar::mouseDoubleClickEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
return;
|
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();
|
QSize Size = d->DockArea->size();
|
||||||
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(d->DockArea);
|
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(d->DockArea);
|
||||||
FloatingWidget->startFloating(Offset, Size);
|
FloatingWidget->startFloating(Offset, Size, DragState);
|
||||||
auto TopLevelDockWidget = FloatingWidget->topLevelDockWidget();
|
auto TopLevelDockWidget = FloatingWidget->topLevelDockWidget();
|
||||||
if (TopLevelDockWidget)
|
if (TopLevelDockWidget)
|
||||||
{
|
{
|
||||||
@ -251,7 +252,7 @@ CFloatingDockContainer* CDockAreaTabBar::makeAreaFloating(const QPoint& Offset)
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
void CDockAreaTabBar::startFloating(const QPoint& Offset)
|
void CDockAreaTabBar::startFloating(const QPoint& Offset)
|
||||||
{
|
{
|
||||||
d->FloatingWidget = makeAreaFloating(Offset);
|
d->FloatingWidget = makeAreaFloating(Offset, DraggingFloatingWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
// INCLUDES
|
// INCLUDES
|
||||||
//============================================================================
|
//============================================================================
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
|
#include "ads_globals.h"
|
||||||
|
|
||||||
namespace ads
|
namespace ads
|
||||||
{
|
{
|
||||||
@ -89,7 +90,8 @@ protected:
|
|||||||
/**
|
/**
|
||||||
* Makes the dock area floating
|
* Makes the dock area floating
|
||||||
*/
|
*/
|
||||||
CFloatingDockContainer* makeAreaFloating(const QPoint& Offset);
|
CFloatingDockContainer* makeAreaFloating(const QPoint& Offset,
|
||||||
|
eDragState DragState);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -265,7 +265,7 @@ void CDockAreaTitleBar::onCloseButtonClicked()
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
void CDockAreaTitleBar::onUndockButtonClicked()
|
void CDockAreaTitleBar::onUndockButtonClicked()
|
||||||
{
|
{
|
||||||
d->TabBar->makeAreaFloating(mapFromGlobal(QCursor::pos()));
|
d->TabBar->makeAreaFloating(mapFromGlobal(QCursor::pos()), DraggingInactive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -671,6 +671,7 @@ QSize CDockWidget::minimumSizeHint() const
|
|||||||
return QSize(60, 40);
|
return QSize(60, 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace ads
|
} // namespace ads
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -45,6 +45,7 @@ class CDockManager;
|
|||||||
class CDockContainerWidget;
|
class CDockContainerWidget;
|
||||||
class CDockAreaWidget;
|
class CDockAreaWidget;
|
||||||
class DockContainerWidgetPrivate;
|
class DockContainerWidgetPrivate;
|
||||||
|
class CFloatingDockContainer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The QDockWidget class provides a widget that can be docked inside a
|
* The QDockWidget class provides a widget that can be docked inside a
|
||||||
|
@ -53,16 +53,6 @@
|
|||||||
|
|
||||||
namespace ads
|
namespace ads
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The different dragging states
|
|
||||||
*/
|
|
||||||
enum eDragState
|
|
||||||
{
|
|
||||||
DraggingInactive, //!< DraggingInactive
|
|
||||||
DraggingMousePressed, //!< DraggingMousePressed
|
|
||||||
DraggingTab, //!< DraggingTab
|
|
||||||
DraggingFloatingWidget//!< DraggingFloatingWidget
|
|
||||||
};
|
|
||||||
|
|
||||||
using tTabLabel = CElidingLabel;
|
using tTabLabel = CElidingLabel;
|
||||||
using tCloseButton = QPushButton;
|
using tCloseButton = QPushButton;
|
||||||
@ -229,13 +219,17 @@ bool DockWidgetTabPrivate::startFloating(eDragState DraggingState)
|
|||||||
FloatingWidget = new CFloatingDockContainer(DockArea);
|
FloatingWidget = new CFloatingDockContainer(DockArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatingWidget->startFloating(DragStartMousePosition, Size);
|
|
||||||
if (DraggingFloatingWidget == DraggingState)
|
if (DraggingFloatingWidget == DraggingState)
|
||||||
{
|
{
|
||||||
|
FloatingWidget->startDragging(DragStartMousePosition, Size);
|
||||||
auto Overlay = DockWidget->dockManager()->containerOverlay();
|
auto Overlay = DockWidget->dockManager()->containerOverlay();
|
||||||
Overlay->setAllowedAreas(OuterDockAreas);
|
Overlay->setAllowedAreas(OuterDockAreas);
|
||||||
this->FloatingWidget = FloatingWidget;
|
this->FloatingWidget = FloatingWidget;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FloatingWidget->initFloatingGeometry(DragStartMousePosition, Size);
|
||||||
|
}
|
||||||
DockWidget->emitTopLevelChanged(true);
|
DockWidget->emitTopLevelChanged(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -50,16 +50,6 @@
|
|||||||
namespace ads
|
namespace ads
|
||||||
{
|
{
|
||||||
static unsigned int zOrderCounter = 0;
|
static unsigned int zOrderCounter = 0;
|
||||||
/**
|
|
||||||
* The different dragging states
|
|
||||||
*/
|
|
||||||
enum eDragState
|
|
||||||
{
|
|
||||||
StateInactive, //!< DraggingInactive
|
|
||||||
StateMousePressed, //!< DraggingMousePressed
|
|
||||||
StateDraggingActive//!< DraggingFloatingWidget
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private data class of CFloatingDockContainer class (pimpl)
|
* Private data class of CFloatingDockContainer class (pimpl)
|
||||||
*/
|
*/
|
||||||
@ -69,7 +59,7 @@ struct FloatingDockContainerPrivate
|
|||||||
CDockContainerWidget* DockContainer;
|
CDockContainerWidget* DockContainer;
|
||||||
unsigned int zOrderIndex = ++zOrderCounter;
|
unsigned int zOrderIndex = ++zOrderCounter;
|
||||||
QPointer<CDockManager> DockManager;
|
QPointer<CDockManager> DockManager;
|
||||||
eDragState DraggingState = StateInactive;
|
eDragState DraggingState = DraggingInactive;
|
||||||
QPoint DragStartMousePosition;
|
QPoint DragStartMousePosition;
|
||||||
CDockContainerWidget* DropContainer = nullptr;
|
CDockContainerWidget* DropContainer = nullptr;
|
||||||
CDockAreaWidget* SingleDockArea = nullptr;
|
CDockAreaWidget* SingleDockArea = nullptr;
|
||||||
@ -111,7 +101,7 @@ FloatingDockContainerPrivate::FloatingDockContainerPrivate(CFloatingDockContaine
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
void FloatingDockContainerPrivate::titleMouseReleaseEvent()
|
void FloatingDockContainerPrivate::titleMouseReleaseEvent()
|
||||||
{
|
{
|
||||||
setState(StateInactive);
|
setState(DraggingInactive);
|
||||||
if (!DropContainer)
|
if (!DropContainer)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -301,12 +291,12 @@ void CFloatingDockContainer::moveEvent(QMoveEvent *event)
|
|||||||
QWidget::moveEvent(event);
|
QWidget::moveEvent(event);
|
||||||
switch (d->DraggingState)
|
switch (d->DraggingState)
|
||||||
{
|
{
|
||||||
case StateMousePressed:
|
case DraggingMousePressed:
|
||||||
d->setState(StateDraggingActive);
|
d->setState(DraggingFloatingWidget);
|
||||||
d->updateDropOverlays(QCursor::pos());
|
d->updateDropOverlays(QCursor::pos());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case StateDraggingActive:
|
case DraggingFloatingWidget:
|
||||||
d->updateDropOverlays(QCursor::pos());
|
d->updateDropOverlays(QCursor::pos());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -319,7 +309,7 @@ void CFloatingDockContainer::moveEvent(QMoveEvent *event)
|
|||||||
void CFloatingDockContainer::closeEvent(QCloseEvent *event)
|
void CFloatingDockContainer::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
qDebug() << "CFloatingDockContainer closeEvent";
|
qDebug() << "CFloatingDockContainer closeEvent";
|
||||||
d->setState(StateInactive);
|
d->setState(DraggingInactive);
|
||||||
|
|
||||||
if (isClosable())
|
if (isClosable())
|
||||||
{
|
{
|
||||||
@ -365,20 +355,20 @@ bool CFloatingDockContainer::event(QEvent *e)
|
|||||||
{
|
{
|
||||||
switch (d->DraggingState)
|
switch (d->DraggingState)
|
||||||
{
|
{
|
||||||
case StateInactive:
|
case DraggingInactive:
|
||||||
if (e->type() == QEvent::NonClientAreaMouseButtonPress && QGuiApplication::mouseButtons() == Qt::LeftButton)
|
if (e->type() == QEvent::NonClientAreaMouseButtonPress && QGuiApplication::mouseButtons() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
qDebug() << "FloatingWidget::event Event::NonClientAreaMouseButtonPress" << e->type();
|
qDebug() << "FloatingWidget::event Event::NonClientAreaMouseButtonPress" << e->type();
|
||||||
d->setState(StateMousePressed);
|
d->setState(DraggingMousePressed);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case StateMousePressed:
|
case DraggingMousePressed:
|
||||||
switch (e->type())
|
switch (e->type())
|
||||||
{
|
{
|
||||||
case QEvent::NonClientAreaMouseButtonDblClick:
|
case QEvent::NonClientAreaMouseButtonDblClick:
|
||||||
qDebug() << "FloatingWidget::event QEvent::NonClientAreaMouseButtonDblClick";
|
qDebug() << "FloatingWidget::event QEvent::NonClientAreaMouseButtonDblClick";
|
||||||
d->setState(StateInactive);
|
d->setState(DraggingInactive);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QEvent::Resize:
|
case QEvent::Resize:
|
||||||
@ -392,7 +382,7 @@ bool CFloatingDockContainer::event(QEvent *e)
|
|||||||
// change, we check, if we are not in maximized state.
|
// change, we check, if we are not in maximized state.
|
||||||
if (!isMaximized())
|
if (!isMaximized())
|
||||||
{
|
{
|
||||||
d->setState(StateInactive);
|
d->setState(DraggingInactive);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -401,7 +391,7 @@ bool CFloatingDockContainer::event(QEvent *e)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case StateDraggingActive:
|
case DraggingFloatingWidget:
|
||||||
if (e->type() == QEvent::NonClientAreaMouseButtonRelease)
|
if (e->type() == QEvent::NonClientAreaMouseButtonRelease)
|
||||||
{
|
{
|
||||||
qDebug() << "FloatingWidget::event QEvent::NonClientAreaMouseButtonRelease";
|
qDebug() << "FloatingWidget::event QEvent::NonClientAreaMouseButtonRelease";
|
||||||
@ -424,7 +414,7 @@ bool CFloatingDockContainer::event(QEvent *e)
|
|||||||
bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event)
|
bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(watched);
|
Q_UNUSED(watched);
|
||||||
if (event->type() == QEvent::MouseButtonRelease && d->isState(StateDraggingActive))
|
if (event->type() == QEvent::MouseButtonRelease && d->isState(DraggingFloatingWidget))
|
||||||
{
|
{
|
||||||
qDebug() << "FloatingWidget::eventFilter QEvent::MouseButtonRelease";
|
qDebug() << "FloatingWidget::eventFilter QEvent::MouseButtonRelease";
|
||||||
d->titleMouseReleaseEvent();
|
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);
|
resize(Size);
|
||||||
d->setState(StateDraggingActive);
|
d->setState(DragState);
|
||||||
d->DragStartMousePosition = DragStartMousePos;
|
d->DragStartMousePosition = DragStartMousePos;
|
||||||
moveFloating();
|
moveFloating();
|
||||||
show();
|
show();
|
||||||
|
@ -81,7 +81,25 @@ protected:
|
|||||||
* Use moveToGlobalPos() to move the widget to a new position
|
* Use moveToGlobalPos() to move the widget to a new position
|
||||||
* depending on the start position given in Pos parameter
|
* 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
|
* Moves the widget to a new position relative to the position given when
|
||||||
|
@ -72,6 +72,17 @@ enum TitleBarButton
|
|||||||
TitleBarButtonClose
|
TitleBarButtonClose
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The different dragging states
|
||||||
|
*/
|
||||||
|
enum eDragState
|
||||||
|
{
|
||||||
|
DraggingInactive, //!< DraggingInactive
|
||||||
|
DraggingMousePressed, //!< DraggingMousePressed
|
||||||
|
DraggingTab, //!< DraggingTab
|
||||||
|
DraggingFloatingWidget//!< DraggingFloatingWidget
|
||||||
|
};
|
||||||
|
|
||||||
namespace internal
|
namespace internal
|
||||||
{
|
{
|
||||||
static const bool RestoreTesting = true;
|
static const bool RestoreTesting = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user