Skip to content

Commit ffd35cb

Browse files
Added support for canceling non opaque docking with escape key, fixed state of non opaque docking when switching applications (if application becomes inactive)
1 parent 8c1f065 commit ffd35cb

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

src/DockAreaTabBar.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,9 @@ void CDockAreaTabBar::mouseReleaseEvent(QMouseEvent* ev)
201201
void CDockAreaTabBar::mouseMoveEvent(QMouseEvent* ev)
202202
{
203203
QScrollArea::mouseMoveEvent(ev);
204-
if (ev->buttons() != Qt::LeftButton)
204+
if (!(ev->buttons() & Qt::LeftButton) || d->isDraggingState(DraggingInactive))
205205
{
206+
d->DragState = DraggingInactive;
206207
return;
207208
}
208209

@@ -276,7 +277,12 @@ IFloatingWidget* CDockAreaTabBar::makeAreaFloating(const QPoint& Offset, eDragSt
276277
}
277278
else
278279
{
279-
FloatingWidget = new CFloatingOverlay(d->DockArea);
280+
auto w = new CFloatingOverlay(d->DockArea);
281+
connect(w, &CFloatingOverlay::draggingCanceled, [=]()
282+
{
283+
d->DragState = DraggingInactive;
284+
});
285+
FloatingWidget = w;
280286
}
281287

282288
FloatingWidget->startFloating(Offset, Size, DragState, nullptr);

src/DockWidgetTab.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,12 @@ struct DockWidgetTabPrivate
151151
}
152152
else
153153
{
154-
return new CFloatingOverlay(Widget);
154+
auto w = new CFloatingOverlay(Widget);
155+
_this->connect(w, &CFloatingOverlay::draggingCanceled, [=]()
156+
{
157+
DragState = DraggingInactive;
158+
});
159+
return w;
155160
}
156161
}
157162
};
@@ -246,6 +251,7 @@ bool DockWidgetTabPrivate::startFloating(eDragState DraggingState)
246251
IFloatingWidget* FloatingWidget = nullptr;
247252
bool OpaqueUndocking = CDockManager::configFlags().testFlag(CDockManager::OpaqueUndocking) ||
248253
(DraggingFloatingWidget != DraggingState);
254+
249255
// If section widget has multiple tabs, we take only one tab
250256
// If it has only one single tab, we can move the complete
251257
// dock area into floating widget

src/FloatingOverlay.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <QEvent>
1616
#include <QApplication>
1717
#include <QPainter>
18+
#include <QKeyEvent>
1819

1920
#include "DockWidget.h"
2021
#include "DockAreaWidget.h"
@@ -53,6 +54,17 @@ struct FloatingOverlayPrivate
5354
Hidden = Value;
5455
_this->update();
5556
}
57+
58+
/**
59+
* Cancel dragging and emit the draggingCanceled event
60+
*/
61+
void cancelDragging()
62+
{
63+
emit _this->draggingCanceled();
64+
DockManager->containerOverlay()->hideOverlay();
65+
DockManager->dockAreaOverlay()->hideOverlay();
66+
_this->close();
67+
}
5668
};
5769
// struct LedArrayPanelPrivate
5870

@@ -192,6 +204,9 @@ CFloatingOverlay::CFloatingOverlay(QWidget* Content, QWidget* parent) :
192204
d->ContentPreviewPixmap = QPixmap(Content->size());
193205
Content->render(&d->ContentPreviewPixmap);
194206
}
207+
208+
connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
209+
SLOT(onApplicationStateChanged(Qt::ApplicationState)));
195210
}
196211

197212

@@ -335,6 +350,30 @@ void CFloatingOverlay::paintEvent(QPaintEvent* event)
335350
}
336351

337352

353+
//============================================================================
354+
void CFloatingOverlay::keyPressEvent(QKeyEvent *event)
355+
{
356+
Super::keyPressEvent(event);
357+
if (event->key() == Qt::Key_Escape)
358+
{
359+
d->cancelDragging();
360+
}
361+
}
362+
363+
364+
//============================================================================
365+
void CFloatingOverlay::onApplicationStateChanged(Qt::ApplicationState state)
366+
{
367+
if (state != Qt::ApplicationActive)
368+
{
369+
disconnect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
370+
this, SLOT(onApplicationStateChanged(Qt::ApplicationState)));
371+
d->cancelDragging();
372+
}
373+
}
374+
375+
376+
338377

339378
} // namespace ads
340379

src/FloatingOverlay.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class CFloatingOverlay : public QWidget, public IFloatingWidget
3232
FloatingOverlayPrivate* d;
3333
friend class FloatingOverlayPrivate;
3434

35+
private slots:
36+
void onApplicationStateChanged(Qt::ApplicationState state);
37+
3538
protected:
3639
/**
3740
* Updates the drop overlays
@@ -43,6 +46,8 @@ class CFloatingOverlay : public QWidget, public IFloatingWidget
4346
*/
4447
virtual void paintEvent(QPaintEvent *e) override;
4548

49+
virtual void keyPressEvent(QKeyEvent *event) override;
50+
4651
/**
4752
* The content is a DockArea or a DockWidget
4853
*/
@@ -84,6 +89,13 @@ class CFloatingOverlay : public QWidget, public IFloatingWidget
8489
* of the assigned Content widget
8590
*/
8691
virtual void finishDragging() override;
92+
93+
signals:
94+
/**
95+
* This signal is emitted, if dragging has been canceled by escape key
96+
* or by active application switching via task manager
97+
*/
98+
void draggingCanceled();
8799
};
88100

89101

0 commit comments

Comments
 (0)