Skip to content

Commit 8c1f065

Browse files
CHanged DockAreaTabBar to handle the dragging state via DragState member variable instead of testing for FloatingWidget nullptr
1 parent 5af6b4e commit 8c1f065

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

demo/MainWindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
385385
// uncomment the follwing line if you want to use non opaque undocking and splitter
386386
// moevements
387387
CDockManager::setConfigFlags(CDockManager::DefaultNonOpaqueConfig);
388+
CDockManager::setConfigFlag(CDockManager::DragPreviewHasWindowFrame, true);
388389

389390
// Now create the dock manager and its content
390391
d->DockManager = new CDockManager(this);

src/DockAreaTabBar.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct DockAreaTabBarPrivate
6060
QWidget* TabsContainerWidget;
6161
QBoxLayout* TabsLayout;
6262
int CurrentIndex = -1;
63+
eDragState DragState = DraggingInactive;
6364

6465
/**
6566
* Private data constructor
@@ -71,6 +72,14 @@ struct DockAreaTabBarPrivate
7172
* The function reassigns the stylesheet to update the tabs
7273
*/
7374
void updateTabs();
75+
76+
/**
77+
* Test function for current drag state
78+
*/
79+
bool isDraggingState(eDragState dragState) const
80+
{
81+
return this->DragState == dragState;
82+
}
7483
};
7584
// struct DockAreaTabBarPrivate
7685

@@ -161,6 +170,7 @@ void CDockAreaTabBar::mousePressEvent(QMouseEvent* ev)
161170
{
162171
ev->accept();
163172
d->DragStartMousePos = ev->pos();
173+
d->DragState = DraggingMousePressed;
164174
return;
165175
}
166176
QScrollArea::mousePressEvent(ev);
@@ -174,12 +184,12 @@ void CDockAreaTabBar::mouseReleaseEvent(QMouseEvent* ev)
174184
{
175185
ADS_PRINT("CDockAreaTabBar::mouseReleaseEvent");
176186
ev->accept();
187+
auto CurrentDragState = d->DragState;
177188
d->DragStartMousePos = QPoint();
178-
if (d->FloatingWidget)
189+
d->DragState = DraggingInactive;
190+
if (DraggingFloatingWidget == CurrentDragState)
179191
{
180-
auto FloatingWidget = d->FloatingWidget;
181-
d->FloatingWidget = nullptr;
182-
FloatingWidget->finishDragging();
192+
d->FloatingWidget->finishDragging();
183193
}
184194
return;
185195
}
@@ -196,11 +206,12 @@ void CDockAreaTabBar::mouseMoveEvent(QMouseEvent* ev)
196206
return;
197207
}
198208

199-
if (d->FloatingWidget)
200-
{
201-
d->FloatingWidget->moveFloating();
202-
return;
203-
}
209+
// move floating window
210+
if (d->isDraggingState(DraggingFloatingWidget))
211+
{
212+
d->FloatingWidget->moveFloating();
213+
return;
214+
}
204215

205216
// If this is the last dock area in a dock container it does not make
206217
// sense to move it to a new floating widget and leave this one
@@ -254,6 +265,7 @@ void CDockAreaTabBar::mouseDoubleClickEvent(QMouseEvent *event)
254265
IFloatingWidget* CDockAreaTabBar::makeAreaFloating(const QPoint& Offset, eDragState DragState)
255266
{
256267
QSize Size = d->DockArea->size();
268+
d->DragState = DragState;
257269
bool OpaqueUndocking = CDockManager::configFlags().testFlag(CDockManager::OpaqueUndocking) ||
258270
(DraggingFloatingWidget != DragState);
259271
CFloatingDockContainer* FloatingDockContainer = nullptr;

src/DockWidgetTab.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct DockWidgetTabPrivate
9595
/**
9696
* Test function for current drag state
9797
*/
98-
bool isDraggingState(eDragState dragState)
98+
bool isDraggingState(eDragState dragState) const
9999
{
100100
return this->DragState == dragState;
101101
}

src/FloatingOverlay.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct FloatingOverlayPrivate;
2727
*/
2828
class CFloatingOverlay : public QWidget, public IFloatingWidget
2929
{
30+
Q_OBJECT
3031
private:
3132
FloatingOverlayPrivate* d;
3233
friend class FloatingOverlayPrivate;

0 commit comments

Comments
 (0)