mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-04-16 02:14:45 +08:00
Implemented support for dragging a complete dock area including all dock widgets
This commit is contained in:
parent
2c9ceb8645
commit
e0a442263e
@ -42,6 +42,7 @@
|
|||||||
#include "DockContainerWidget.h"
|
#include "DockContainerWidget.h"
|
||||||
#include "DockWidget.h"
|
#include "DockWidget.h"
|
||||||
#include "DockWidgetTitleBar.h"
|
#include "DockWidgetTitleBar.h"
|
||||||
|
#include "FloatingDockContainer.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@ -52,12 +53,19 @@ static const char* const ACTION_PROPERTY = "action";
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom scroll bar implementation for dock area tab bar
|
* Custom scroll bar implementation for dock area tab bar
|
||||||
|
* This scroll area enables floating of a whole dock area including all
|
||||||
|
* dock widgets
|
||||||
*/
|
*/
|
||||||
class CTabsScrollArea : public QScrollArea
|
class CTabsScrollArea : public QScrollArea
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
QPoint m_DragStartMousePos;
|
||||||
|
CDockAreaWidget* DockArea;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CTabsScrollArea(QWidget* parent = nullptr)
|
CTabsScrollArea(CDockAreaWidget* parent)
|
||||||
: QScrollArea(parent)
|
: QScrollArea(parent),
|
||||||
|
DockArea(parent)
|
||||||
{
|
{
|
||||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
|
||||||
setFrameStyle(QFrame::NoFrame);
|
setFrameStyle(QFrame::NoFrame);
|
||||||
@ -80,6 +88,40 @@ protected:
|
|||||||
horizontalScrollBar()->setValue(horizontalScrollBar()->value() - 20);
|
horizontalScrollBar()->setValue(horizontalScrollBar()->value() - 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores mouse position to detect dragging
|
||||||
|
*/
|
||||||
|
void mousePressEvent(QMouseEvent* ev)
|
||||||
|
{
|
||||||
|
if (ev->button() == Qt::LeftButton)
|
||||||
|
{
|
||||||
|
ev->accept();
|
||||||
|
m_DragStartMousePos = ev->pos();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QScrollArea::mousePressEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts floating the complete docking area including all dock widgets
|
||||||
|
*/
|
||||||
|
void mouseMoveEvent(QMouseEvent* ev)
|
||||||
|
{
|
||||||
|
QScrollArea::mouseMoveEvent(ev);
|
||||||
|
if (ev->buttons() != Qt::LeftButton)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this->geometry().contains(ev->pos()))
|
||||||
|
{
|
||||||
|
QSize Size = DockArea->size();
|
||||||
|
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(DockArea);
|
||||||
|
FloatingWidget->startFloating(m_DragStartMousePos, Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
}; // class CTabsScrollArea
|
}; // class CTabsScrollArea
|
||||||
|
|
||||||
|
|
||||||
|
@ -172,9 +172,7 @@ void DockWidgetTitleBarPrivate::startFloating(const QPoint& GlobalPos)
|
|||||||
FloatingWidget = new CFloatingDockContainer(DockArea);
|
FloatingWidget = new CFloatingDockContainer(DockArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatingWidget->resize(Size);
|
FloatingWidget->startFloating(DragStartMousePosition, Size);
|
||||||
FloatingWidget->setObjectName("FloatingWidget");
|
|
||||||
FloatingWidget->startFloating(DragStartMousePosition);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DropOverlay* ContainerDropOverlay = cw->dropOverlay();
|
* DropOverlay* ContainerDropOverlay = cw->dropOverlay();
|
||||||
|
@ -279,6 +279,7 @@ bool CFloatingDockContainer::event(QEvent *e)
|
|||||||
std::cout << "FloatingWidget::event QEvent::NonClientAreaMouseButtonRelease" << std::endl;
|
std::cout << "FloatingWidget::event QEvent::NonClientAreaMouseButtonRelease" << std::endl;
|
||||||
d->titleMouseReleaseEvent();
|
d->titleMouseReleaseEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
return QWidget::event(e);
|
return QWidget::event(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,7 +287,7 @@ bool CFloatingDockContainer::event(QEvent *e)
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event)
|
bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event)
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::MouseButtonRelease)
|
if (event->type() == QEvent::MouseButtonRelease && d->DraggingActive)
|
||||||
{
|
{
|
||||||
std::cout << "FloatingWidget::eventFilter QEvent::MouseButtonRelease" << std::endl;
|
std::cout << "FloatingWidget::eventFilter QEvent::MouseButtonRelease" << std::endl;
|
||||||
d->titleMouseReleaseEvent();
|
d->titleMouseReleaseEvent();
|
||||||
@ -304,8 +305,9 @@ bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event)
|
|||||||
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
void CFloatingDockContainer::startFloating(const QPoint& Pos)
|
void CFloatingDockContainer::startFloating(const QPoint& Pos, const QSize& Size)
|
||||||
{
|
{
|
||||||
|
resize(Size);
|
||||||
d->setDraggingActive(true);
|
d->setDraggingActive(true);
|
||||||
QPoint TargetPos = QCursor::pos() - Pos;
|
QPoint TargetPos = QCursor::pos() - Pos;
|
||||||
move(TargetPos);
|
move(TargetPos);
|
||||||
|
@ -86,7 +86,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Starts floating at the given global position
|
* Starts floating at the given global position
|
||||||
*/
|
*/
|
||||||
void startFloating(const QPoint& Pos);
|
void startFloating(const QPoint& Pos, const QSize& Size = QSize());
|
||||||
}; // class FloatingDockContainer
|
}; // class FloatingDockContainer
|
||||||
}
|
}
|
||||||
// namespace ads
|
// namespace ads
|
||||||
|
Loading…
Reference in New Issue
Block a user