Changeset View
Changeset View
Standalone View
Standalone View
src/DetachableTabBar.cpp
Show All 25 Lines | |||||
26 | namespace Konsole { | 26 | namespace Konsole { | ||
27 | 27 | | |||
28 | DetachableTabBar::DetachableTabBar(QWidget *parent) : | 28 | DetachableTabBar::DetachableTabBar(QWidget *parent) : | ||
29 | QTabBar(parent), | 29 | QTabBar(parent), | ||
30 | dragType(DragType::NONE), | 30 | dragType(DragType::NONE), | ||
31 | _originalCursor(cursor()) | 31 | _originalCursor(cursor()) | ||
32 | {} | 32 | {} | ||
33 | 33 | | |||
34 | bool DetachableTabBar::droppedContainerIsNotThis(const QPoint& currentPos) const | | |||
35 | { | | |||
36 | for(const auto dropWidget : _containers) { | | |||
37 | if (dropWidget->rect().contains(dropWidget->mapFromGlobal(currentPos))) { | | |||
38 | if (dropWidget != parent()) { | | |||
39 | return true; | | |||
40 | } | | |||
41 | } | | |||
42 | } | | |||
43 | return false; | | |||
44 | } | | |||
45 | | ||||
46 | void DetachableTabBar::mousePressEvent(QMouseEvent *event) | 34 | void DetachableTabBar::mousePressEvent(QMouseEvent *event) | ||
47 | { | 35 | { | ||
48 | QTabBar::mousePressEvent(event); | 36 | QTabBar::mousePressEvent(event); | ||
49 | _containers = window()->findChildren<Konsole::TabbedViewContainer*>(); | 37 | _containers = window()->findChildren<Konsole::TabbedViewContainer*>(); | ||
50 | } | 38 | } | ||
51 | 39 | | |||
52 | void DetachableTabBar::mouseMoveEvent(QMouseEvent *event) | 40 | void DetachableTabBar::mouseMoveEvent(QMouseEvent *event) | ||
53 | { | 41 | { | ||
54 | QTabBar::mouseMoveEvent(event); | 42 | QTabBar::mouseMoveEvent(event); | ||
55 | auto widgetAtPos = qApp->topLevelAt(event->globalPos()); | 43 | auto widgetAtPos = qApp->topLevelAt(event->globalPos()); | ||
56 | if (widgetAtPos != nullptr) { | 44 | if (widgetAtPos != nullptr) { | ||
57 | if (window() == widgetAtPos->window()) { | 45 | if (window() == widgetAtPos->window()) { | ||
58 | if (droppedContainerIsNotThis(event->globalPos())) { | | |||
59 | if (dragType != DragType::WINDOW) { | | |||
60 | dragType = DragType::WINDOW; | | |||
61 | setCursor(QCursor(Qt::DragMoveCursor)); | | |||
62 | } | | |||
63 | } else { | | |||
64 | if (dragType != DragType::NONE) { | 46 | if (dragType != DragType::NONE) { | ||
65 | dragType = DragType::NONE; | 47 | dragType = DragType::NONE; | ||
66 | setCursor(_originalCursor); | 48 | setCursor(_originalCursor); | ||
67 | } | 49 | } | ||
68 | } | | |||
69 | } else { | 50 | } else { | ||
70 | if (dragType != DragType::WINDOW) { | 51 | if (dragType != DragType::WINDOW) { | ||
71 | dragType = DragType::WINDOW; | 52 | dragType = DragType::WINDOW; | ||
72 | setCursor(QCursor(Qt::DragMoveCursor)); | 53 | setCursor(QCursor(Qt::DragMoveCursor)); | ||
73 | } | 54 | } | ||
74 | } | 55 | } | ||
75 | } else if (!contentsRect().adjusted(-30,-30,30,30).contains(event->pos())) { | 56 | } else if (!contentsRect().adjusted(-30,-30,30,30).contains(event->pos())) { | ||
76 | // Don't let it detach the last tab. | 57 | // Don't let it detach the last tab. | ||
Show All 17 Lines | 69 | { | |||
94 | } | 75 | } | ||
95 | 76 | | |||
96 | auto widgetAtPos = qApp->topLevelAt(event->globalPos()); | 77 | auto widgetAtPos = qApp->topLevelAt(event->globalPos()); | ||
97 | if (widgetAtPos == nullptr) { | 78 | if (widgetAtPos == nullptr) { | ||
98 | if (count() != 1) { | 79 | if (count() != 1) { | ||
99 | emit detachTab(currentIndex()); | 80 | emit detachTab(currentIndex()); | ||
100 | } | 81 | } | ||
101 | } else if (window() != widgetAtPos->window()) { | 82 | } else if (window() != widgetAtPos->window()) { | ||
102 | // splits have a tendency to break, forbid to detach if split and it's the last tab. | | |||
103 | if (_containers.size() == 1 || count() > 1) { | 83 | if (_containers.size() == 1 || count() > 1) { | ||
104 | emit moveTabToWindow(currentIndex(), widgetAtPos); | 84 | emit moveTabToWindow(currentIndex(), widgetAtPos); | ||
105 | } | 85 | } | ||
106 | } else if (droppedContainerIsNotThis(event->globalPos())){ | | |||
107 | if (count() != 1) { | | |||
108 | emit moveTabToWindow(currentIndex(), widgetAtPos); | | |||
109 | } | | |||
110 | } | 86 | } | ||
111 | } | 87 | } | ||
112 | 88 | | |||
113 | } | 89 | } |