From ebc27b8734167c9aad4900d9baffd426556d1376 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 10 Apr 2009 19:38:30 +0200 Subject: Fixed tab moving, thanks to Qt 4.5 magic.. --- src/mainview.cpp | 17 ----------------- src/mainview.h | 3 +-- src/tabbar.cpp | 49 ++----------------------------------------------- src/tabbar.h | 4 ---- 4 files changed, 3 insertions(+), 70 deletions(-) diff --git a/src/mainview.cpp b/src/mainview.cpp index 65400ace..c67d70a6 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -70,7 +70,6 @@ MainView::MainView(QWidget *parent) connect(m_tabBar, SIGNAL(closeOtherTabs(int)), this, SLOT(slotCloseOtherTabs(int))); connect(m_tabBar, SIGNAL(reloadTab(int)), this, SLOT(slotReloadTab(int))); connect(m_tabBar, SIGNAL(reloadAllTabs()), this, SLOT(slotReloadAllTabs())); - connect(m_tabBar, SIGNAL(tabMoveRequested(int, int)), this, SLOT(slotMoveTab(int, int))); // Recently Closed Tab Action m_recentlyClosedTabsMenu = new KMenu(this); @@ -223,22 +222,6 @@ void MainView::clear() } -void MainView::slotMoveTab(int fromIndex, int toIndex) -{ - disconnect(this, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentChanged(int))); - - QWidget *tabWidget = widget(fromIndex); - QIcon icon = tabIcon(fromIndex); - QString text = tabText(fromIndex); - QVariant data = m_tabBar->tabData(fromIndex); - removeTab(fromIndex); - insertTab(toIndex, tabWidget, icon, text); - m_tabBar->setTabData(toIndex, data); - connect(this, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentChanged(int))); - setCurrentIndex(toIndex); -} - - // When index is -1 index chooses the current tab void MainView::slotReloadTab(int index) { diff --git a/src/mainview.h b/src/mainview.h index 4203e272..9085aa46 100644 --- a/src/mainview.h +++ b/src/mainview.h @@ -129,10 +129,9 @@ private slots: void webViewUrlChanged(const QUrl &url); void lineEditReturnPressed(); void windowCloseRequested(); - void slotMoveTab(int fromIndex, int toIndex); -private: +private: KAction *m_recentlyClosedTabsAction; KMenu *m_recentlyClosedTabsMenu; diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 94cda51c..05b386b8 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -47,9 +47,10 @@ TabBar::TabBar(QWidget *parent) { setElideMode(Qt::ElideRight); setContextMenuPolicy(Qt::CustomContextMenu); - setAcceptDrops(true); + setMovable(true); connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &))); + // tabbar font QFont standardFont = KGlobalSettings::generalFont(); QString fontFamily = standardFont.family(); int dim = standardFont.pointSize(); @@ -144,52 +145,6 @@ void TabBar::mousePressEvent(QMouseEvent *event) } -void TabBar::mouseMoveEvent(QMouseEvent *event) -{ - if (event->buttons() == Qt::LeftButton && (event->pos() - m_dragStartPos).manhattanLength() > QApplication::startDragDistance()) - { - QDrag *drag = new QDrag(this); - QMimeData *mimeData = new QMimeData; - QList urls; - int index = tabAt(event->pos()); - QUrl url = tabData(index).toUrl(); - urls.append(url); - mimeData->setUrls(urls); - mimeData->setText(tabText(index)); - mimeData->setData(QLatin1String("action"), "tab-reordering"); - drag->setMimeData(mimeData); - drag->exec(); - } - KTabBar::mouseMoveEvent(event); -} - - -void TabBar::dragEnterEvent(QDragEnterEvent *event) -{ - const QMimeData *mimeData = event->mimeData(); - QStringList formats = mimeData->formats(); - - if (formats.contains(QLatin1String("action")) && (mimeData->data(QLatin1String("action")) == "tab-reordering")) - { - event->acceptProposedAction(); - } - KTabBar::dragEnterEvent(event); -} - - -void TabBar::dropEvent(QDropEvent *event) -{ - int fromIndex = tabAt(m_dragStartPos); - int toIndex = tabAt(event->pos()); - if (fromIndex != toIndex) - { - emit tabMoveRequested(fromIndex, toIndex); - event->acceptProposedAction(); - } - KTabBar::dropEvent(event); -} - - void TabBar::reloadTab() { emit reloadTab(m_actualIndex); diff --git a/src/tabbar.h b/src/tabbar.h index 5ee04305..2703dfe6 100644 --- a/src/tabbar.h +++ b/src/tabbar.h @@ -50,13 +50,9 @@ signals: void closeOtherTabs(int index); void reloadTab(int index); void reloadAllTabs(); - void tabMoveRequested(int fromIndex, int toIndex); protected: void mousePressEvent(QMouseEvent* event); - void mouseMoveEvent(QMouseEvent* event); - void dragEnterEvent(QDragEnterEvent *event); - void dropEvent(QDropEvent *event); /** * Added to fix tab dimension -- cgit v1.2.1