mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 13:15:43 +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 "DockWidget.h"
|
||||
#include "DockWidgetTitleBar.h"
|
||||
#include "FloatingDockContainer.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@ -52,12 +53,19 @@ static const char* const ACTION_PROPERTY = "action";
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
private:
|
||||
QPoint m_DragStartMousePos;
|
||||
CDockAreaWidget* DockArea;
|
||||
|
||||
public:
|
||||
CTabsScrollArea(QWidget* parent = nullptr)
|
||||
: QScrollArea(parent)
|
||||
CTabsScrollArea(CDockAreaWidget* parent)
|
||||
: QScrollArea(parent),
|
||||
DockArea(parent)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
|
||||
setFrameStyle(QFrame::NoFrame);
|
||||
@ -80,6 +88,40 @@ protected:
|
||||
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
|
||||
|
||||
|
||||
|
@ -172,9 +172,7 @@ void DockWidgetTitleBarPrivate::startFloating(const QPoint& GlobalPos)
|
||||
FloatingWidget = new CFloatingDockContainer(DockArea);
|
||||
}
|
||||
|
||||
FloatingWidget->resize(Size);
|
||||
FloatingWidget->setObjectName("FloatingWidget");
|
||||
FloatingWidget->startFloating(DragStartMousePosition);
|
||||
FloatingWidget->startFloating(DragStartMousePosition, Size);
|
||||
|
||||
/*
|
||||
* DropOverlay* ContainerDropOverlay = cw->dropOverlay();
|
||||
|
@ -279,6 +279,7 @@ bool CFloatingDockContainer::event(QEvent *e)
|
||||
std::cout << "FloatingWidget::event QEvent::NonClientAreaMouseButtonRelease" << std::endl;
|
||||
d->titleMouseReleaseEvent();
|
||||
}
|
||||
|
||||
return QWidget::event(e);
|
||||
}
|
||||
|
||||
@ -286,7 +287,7 @@ bool CFloatingDockContainer::event(QEvent *e)
|
||||
//============================================================================
|
||||
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;
|
||||
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);
|
||||
QPoint TargetPos = QCursor::pos() - Pos;
|
||||
move(TargetPos);
|
||||
|
@ -86,7 +86,7 @@ public:
|
||||
/**
|
||||
* Starts floating at the given global position
|
||||
*/
|
||||
void startFloating(const QPoint& Pos);
|
||||
void startFloating(const QPoint& Pos, const QSize& Size = QSize());
|
||||
}; // class FloatingDockContainer
|
||||
}
|
||||
// namespace ads
|
||||
|
Loading…
Reference in New Issue
Block a user