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