Changeset View
Changeset View
Standalone View
Standalone View
src/DetachableTabBar.cpp
Show All 13 Lines | 1 | /* | |||
---|---|---|---|---|---|
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software | 15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301 USA. | 17 | 02110-1301 USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "DetachableTabBar.h" | 20 | #include "DetachableTabBar.h" | ||
21 | #include <QMouseEvent> | 21 | #include <QMouseEvent> | ||
22 | #include <QDebug> | ||||
23 | #include <QApplication> | ||||
22 | 24 | | |||
23 | DetachableTabBar::DetachableTabBar(QWidget *parent) : | 25 | DetachableTabBar::DetachableTabBar(QWidget *parent) : | ||
24 | QTabBar(parent), | 26 | QTabBar(parent), | ||
25 | _draggingOutside(false) {} | 27 | dragType(DragType::NONE), | ||
28 | _originalCursor(cursor()) | ||||
29 | {} | ||||
26 | 30 | | |||
27 | void DetachableTabBar::mouseMoveEvent(QMouseEvent *event) | 31 | void DetachableTabBar::mouseMoveEvent(QMouseEvent *event) | ||
28 | { | 32 | { | ||
29 | QTabBar::mouseMoveEvent(event); | 33 | QTabBar::mouseMoveEvent(event); | ||
30 | if (!contentsRect().adjusted(-30,-30,30,30).contains(event->pos())) { | 34 | auto widgetAtPos = qApp->topLevelAt(event->globalPos()); | ||
31 | if (!_draggingOutside) { | 35 | if (widgetAtPos){ | ||
32 | _draggingOutside = true; | 36 | if (window() == widgetAtPos->window()) { | ||
33 | _originalCursor = cursor(); | 37 | if (dragType != DragType::NONE) { | ||
38 | dragType = DragType::NONE; | ||||
39 | setCursor(_originalCursor); | ||||
40 | } | ||||
41 | } else { | ||||
42 | if (dragType != DragType::WINDOW) { | ||||
43 | dragType = DragType::WINDOW; | ||||
44 | setCursor(QCursor(Qt::DragMoveCursor)); | ||||
45 | } | ||||
46 | } | ||||
47 | } else if (!contentsRect().adjusted(-30,-30,30,30).contains(event->pos())) { | ||||
48 | if (dragType != DragType::OUTSIDE) { | ||||
49 | dragType = DragType::OUTSIDE; | ||||
34 | setCursor(QCursor(Qt::DragCopyCursor)); | 50 | setCursor(QCursor(Qt::DragCopyCursor)); | ||
35 | } | 51 | } | ||
36 | } else if (_draggingOutside) { | | |||
37 | _draggingOutside = false; | | |||
38 | setCursor(_originalCursor); | | |||
39 | } | 52 | } | ||
40 | } | 53 | } | ||
41 | 54 | | |||
42 | void DetachableTabBar::mouseReleaseEvent(QMouseEvent *event) | 55 | void DetachableTabBar::mouseReleaseEvent(QMouseEvent *event) | ||
43 | { | 56 | { | ||
44 | QTabBar::mouseReleaseEvent(event); | 57 | QTabBar::mouseReleaseEvent(event); | ||
45 | if (!contentsRect().adjusted(-30,-30,30,30).contains(event->pos())) { | 58 | if (contentsRect().adjusted(-30,-30,30,30).contains(event->pos())) { | ||
59 | return; | ||||
60 | } | ||||
61 | | ||||
46 | setCursor(_originalCursor); | 62 | setCursor(_originalCursor); | ||
63 | auto widgetAtPos = qApp->topLevelAt(event->globalPos()); | ||||
64 | if (! widgetAtPos) { | ||||
47 | emit detachTab(currentIndex()); | 65 | emit detachTab(currentIndex()); | ||
66 | } else if (window() != widgetAtPos->window()) { | ||||
67 | emit moveTabToWindow(currentIndex(), widgetAtPos); | ||||
68 | } else { | ||||
69 | qDebug() << "Doing nothing, you dropped at the same widnow."; | ||||
48 | } | 70 | } | ||
49 | } | 71 | } |