summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <aleixpol@kde.org>2016-01-30 18:28:41 (GMT)
committerAleix Pol <aleixpol@kde.org>2016-01-30 18:28:41 (GMT)
commitcbf47d1bb8540a3e2007ff2dacdb04bd91c97714 (patch)
treec4b657dc95b83eac3317d6e6a23b900d5f867953
parentb6d3854e66717e7d73edb8e12120f5afe5aa3ab8 (diff)
Fix KTabWidget porting issue
Restore drop on tabs Reviewed by Albert
-rw-r--r--shell/shell.cpp36
-rw-r--r--shell/shell.h4
2 files changed, 25 insertions, 15 deletions
diff --git a/shell/shell.cpp b/shell/shell.cpp
index 1c4c8e9..e75a32e 100644
--- a/shell/shell.cpp
+++ b/shell/shell.cpp
@@ -96,10 +96,12 @@ Shell::Shell( const QString &serializedOptions )
m_tabWidget->tabBar()->hide();
m_tabWidget->setDocumentMode( true );
m_tabWidget->setMovable( true );
+
+ m_tabWidget->setAcceptDrops(true);
+ m_tabWidget->installEventFilter(this);
+
connect( m_tabWidget, &QTabWidget::currentChanged, this, &Shell::setActiveTab );
connect( m_tabWidget, &QTabWidget::tabCloseRequested, this, &Shell::closeTab );
- connect( m_tabWidget, SIGNAL(testCanDecode(const QDragMoveEvent*,bool&)), SLOT(testTabDrop(const QDragMoveEvent*,bool&)) ); // kf5 FIXME DnD
- connect( m_tabWidget, SIGNAL(receivedDropEvent(QDropEvent*)), SLOT(handleTabDrop(QDropEvent*)) ); // kf5 FIXME DnD
connect( m_tabWidget->tabBar(), &QTabBar::tabMoved, this, &Shell::moveTabData );
setCentralWidget( m_tabWidget );
@@ -138,6 +140,25 @@ Shell::Shell( const QString &serializedOptions )
}
}
+bool Shell::eventFilter(QObject *obj, QEvent *event)
+{
+ QDragMoveEvent* dmEvent = dynamic_cast<QDragMoveEvent*>(event);
+ if (dmEvent) {
+ bool accept = dmEvent->mimeData()->hasUrls();
+ event->setAccepted(accept);
+ return accept;
+ }
+
+ QDropEvent* dEvent = dynamic_cast<QDropEvent*>(event);
+ if (dEvent) {
+ const QList<QUrl> list = KUrlMimeData::urlsFromMimeData(dEvent->mimeData());
+ handleDroppedUrls(list);
+ dEvent->setAccepted(true);
+ return true;
+ }
+ return false;
+}
+
bool Shell::isValid() const
{
return m_isValid;
@@ -652,17 +673,6 @@ void Shell::handleDroppedUrls( const QList<QUrl>& urls )
}
}
-void Shell::testTabDrop( const QDragMoveEvent* event, bool& accept )
-{
- accept = event->mimeData()->hasUrls();
-}
-
-void Shell::handleTabDrop( QDropEvent* event )
-{
- const QList<QUrl> list = KUrlMimeData::urlsFromMimeData( event->mimeData() );
- handleDroppedUrls( list );
-}
-
void Shell::moveTabData( int from, int to )
{
m_tabs.move( from, to );
diff --git a/shell/shell.h b/shell/shell.h
index d1bb51b..c7c155b 100644
--- a/shell/shell.h
+++ b/shell/shell.h
@@ -119,8 +119,6 @@ private slots:
void closeTab( int tab );
void activateNextTab();
void activatePrevTab();
- void testTabDrop( const QDragMoveEvent* event, bool& accept );
- void handleTabDrop( QDropEvent* event );
void moveTabData( int from, int to );
void slotFitWindowToPage( const QSize& pageViewSize, const QSize& pageSize );
@@ -138,6 +136,8 @@ private:
int findTabIndex( QObject* sender );
private:
+ bool eventFilter(QObject *obj, QEvent *event) override;
+
KPluginFactory* m_partFactory;
KRecentFilesAction* m_recent;
QStringList m_fileformats;