Commit 75e4505f authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Tabbar: DND improvements

- Fix crash, always ensure we drag the current document that has a view
- Allow to start drag when we have passed 1/4th of the viewspace-rect
height

BUG: 456844
parent 7a83673a
Pipeline #207538 passed with stage
in 6 minutes and 5 seconds
......@@ -167,8 +167,11 @@ void KateTabBar::mousePressEvent(QMouseEvent *event)
Q_EMIT activateViewSpaceRequested();
}
if (event->button() == Qt::LeftButton && tabAt(event->pos()) != -1) {
int tab = tabAt(event->pos());
if (event->button() == Qt::LeftButton && tab != -1) {
dragStartPos = event->pos();
auto r = tabRect(tab);
dragHotspotPos = {dragStartPos.x() - r.x(), dragStartPos.y() - r.y()};
} else {
dragStartPos = {};
}
......@@ -197,7 +200,10 @@ void KateTabBar::mouseMoveEvent(QMouseEvent *event)
// might not know that kate's tabs can be dragged to other
// places, unless they drag it really far away
auto viewSpace = qobject_cast<KateViewSpace *>(parentWidget());
if (!viewSpace || viewSpace->rect().contains(event->pos())) {
const auto viewspaceRect = viewSpace->rect();
QRect viewspaceRectTopArea = viewspaceRect;
viewspaceRectTopArea.setBottom(viewspaceRect.height() / 4);
if (!viewSpace || viewspaceRectTopArea.contains(event->pos())) {
QTabBar::mouseMoveEvent(event);
return;
}
......@@ -211,9 +217,11 @@ void KateTabBar::mouseMoveEvent(QMouseEvent *event)
return QTabBar::mouseMoveEvent(event);
}
QDrag *drag = new QDrag(this);
int tab = currentIndex();
if (tab < 0) {
return;
}
int tab = tabAt(dragStartPos);
QRect rect = tabRect(tab);
QPixmap p(rect.size() * this->devicePixelRatioF());
......@@ -255,18 +263,17 @@ void KateTabBar::mouseMoveEvent(QMouseEvent *event)
auto mime = new TabMimeData(viewSpace, tabDocument(tab));
mime->setData(QStringLiteral("application/kate.tab.mimedata"), data);
QDrag *drag = new QDrag(this);
drag->setMimeData(mime);
drag->setPixmap(p);
QPoint hp;
hp.setX(dragStartPos.x() - rect.x());
hp.setY(dragStartPos.y() - rect.y());
drag->setHotSpot(hp);
drag->setHotSpot(dragHotspotPos);
dragStartPos = {};
dragHotspotPos = {};
drag->exec(Qt::CopyAction);
// We send this even to ensure the "moveable tab" is properly reset and we have no dislocated tabs
QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, dragStartPos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
qApp->postEvent(this, e);
}
......
......@@ -168,6 +168,7 @@ private:
std::unordered_map<KTextEditor::Document *, std::pair<quint64, bool>> m_docToLruCounterAndHasTab;
QPoint dragStartPos;
QPoint dragHotspotPos;
};
#endif // KATE_TAB_BAR_H
......@@ -820,6 +820,11 @@ void KateViewManager::moveViewToViewSpace(KateViewSpace *dest, KateViewSpace *sr
}
auto view = src->takeView(doc);
if (!view) {
qWarning() << Q_FUNC_INFO << "Unexpected null view when trying to drag the view to a different viewspace" << doc;
return;
}
dest->addView(view);
setActiveSpace(dest);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment