commit c1945d27dfd19ef698ae7506c1311ce94091207a
Author: Guillaume Munch <[email protected]>
Date: Thu Oct 4 19:52:21 2018 -0400
Make tab movement visible (#10733)
The nice hand-made solution for moving tabs has made its time. Use Qt's
feature
instead from now on.
(cherry picked from commit 19794963990f13aaae2cd575b2f445585ec82910)
---
src/frontends/qt4/GuiWorkArea.cpp | 96 ++++---------------------------------
src/frontends/qt4/GuiWorkArea.h | 27 ----------
status.23x | 1 +
3 files changed, 10 insertions(+), 114 deletions(-)
diff --git a/src/frontends/qt4/GuiWorkArea.cpp
b/src/frontends/qt4/GuiWorkArea.cpp
index 1296564..18c25ca 100644
--- a/src/frontends/qt4/GuiWorkArea.cpp
+++ b/src/frontends/qt4/GuiWorkArea.cpp
@@ -1553,19 +1553,19 @@ TabWorkArea::TabWorkArea(QWidget * parent)
this, SLOT(closeCurrentBuffer()));
setCornerWidget(closeBufferButton, Qt::TopRightCorner);
- // setup drag'n'drop
- QTabBar* tb = new DragTabBar;
- connect(tb, SIGNAL(tabMoveRequested(int, int)),
- this, SLOT(moveTab(int, int)));
+ // set TabBar behaviour
+ QTabBar * tb = tabBar();
+ tb->setTabsClosable(!lyxrc.single_close_tab_button);
+ tb->setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab);
tb->setElideMode(Qt::ElideNone);
- setTabBar(tb);
-
+ // allow dragging tabs
+ tb->setMovable(true);
// make us responsible for the context menu of the tabbar
tb->setContextMenuPolicy(Qt::CustomContextMenu);
connect(tb, SIGNAL(customContextMenuRequested(const QPoint &)),
- this, SLOT(showContextMenu(const QPoint &)));
+ this, SLOT(showContextMenu(const QPoint &)));
connect(tb, SIGNAL(tabCloseRequested(int)),
- this, SLOT(closeTab(int)));
+ this, SLOT(closeTab(int)));
setUsesScrollButtons(true);
}
@@ -2080,7 +2080,7 @@ void TabWorkArea::updateTabTexts()
void TabWorkArea::showContextMenu(const QPoint & pos)
{
// which tab?
- clicked_tab_ = static_cast<DragTabBar *>(tabBar())->tabAt(pos);
+ clicked_tab_ = tabBar()->tabAt(pos);
if (clicked_tab_ == -1)
return;
@@ -2109,84 +2109,6 @@ void TabWorkArea::moveTab(int fromIndex, int toIndex)
}
-DragTabBar::DragTabBar(QWidget* parent)
- : QTabBar(parent)
-{
- setAcceptDrops(true);
- setTabsClosable(!lyxrc.single_close_tab_button);
-}
-
-
-void DragTabBar::mousePressEvent(QMouseEvent * event)
-{
- if (event->button() == Qt::LeftButton)
- dragStartPos_ = event->pos();
- QTabBar::mousePressEvent(event);
-}
-
-
-void DragTabBar::mouseMoveEvent(QMouseEvent * event)
-{
- // If the left button isn't pressed anymore then return
- if (!(event->buttons() & Qt::LeftButton))
- return;
-
- // If the distance is too small then return
- if ((event->pos() - dragStartPos_).manhattanLength()
- < QApplication::startDragDistance())
- return;
-
- // did we hit something after all?
- int tab = tabAt(dragStartPos_);
- if (tab == -1)
- return;
-
- // simulate button release to remove highlight from button
- int i = currentIndex();
- QMouseEvent me(QEvent::MouseButtonRelease, dragStartPos_,
- event->button(), event->buttons(), 0);
- QTabBar::mouseReleaseEvent(&me);
- setCurrentIndex(i);
-
- // initiate Drag
- QDrag * drag = new QDrag(this);
- QMimeData * mimeData = new QMimeData;
- // a crude way to distinguish tab-reodering drops from other ones
- mimeData->setData("action", "tab-reordering") ;
- drag->setMimeData(mimeData);
-
- // get tab pixmap as cursor
- QRect r = tabRect(tab);
- QPixmap pixmap(r.size());
- render(&pixmap, - r.topLeft());
- drag->setPixmap(pixmap);
- drag->exec();
-}
-
-
-void DragTabBar::dragEnterEvent(QDragEnterEvent * event)
-{
- // Only accept if it's an tab-reordering request
- QMimeData const * m = event->mimeData();
- QStringList formats = m->formats();
- if (formats.contains("action")
- && m->data("action") == "tab-reordering")
- event->acceptProposedAction();
-}
-
-
-void DragTabBar::dropEvent(QDropEvent * event)
-{
- int fromIndex = tabAt(dragStartPos_);
- int toIndex = tabAt(event->pos());
-
- // Tell interested objects that
- if (fromIndex != toIndex)
- tabMoveRequested(fromIndex, toIndex);
- event->acceptProposedAction();
-}
-
-
GuiWorkAreaContainer::GuiWorkAreaContainer(GuiWorkArea * wa, QWidget * parent)
: QWidget(parent), wa_(wa)
{
diff --git a/src/frontends/qt4/GuiWorkArea.h b/src/frontends/qt4/GuiWorkArea.h
index 39d2054..22e8bfd 100644
--- a/src/frontends/qt4/GuiWorkArea.h
+++ b/src/frontends/qt4/GuiWorkArea.h
@@ -276,33 +276,6 @@ private:
}; // TabWorkArea
-class DragTabBar : public QTabBar
-{
- Q_OBJECT
-public:
- ///
- DragTabBar(QWidget * parent = 0);
-
-protected:
- ///
- void mousePressEvent(QMouseEvent * event);
- ///
- void mouseMoveEvent(QMouseEvent * event);
- ///
- void dragEnterEvent(QDragEnterEvent * event);
- ///
- void dropEvent(QDropEvent * event);
-
-private:
- ///
- QPoint dragStartPos_;
-
-Q_SIGNALS:
- ///
- void tabMoveRequested(int fromIndex, int toIndex);
-};
-
-
class GuiWorkAreaContainer : public QWidget, public Ui::WorkAreaUi
{
Q_OBJECT
diff --git a/status.23x b/status.23x
index 348128f..ba917af 100644
--- a/status.23x
+++ b/status.23x
@@ -31,6 +31,7 @@ What's new
- Allow nameref in math references (bug 9798).
+- Make tab movement visible (bug 10733).
* DOCUMENTATION AND LOCALIZATION