From 3b4cc236b5e597499b4bebc6829693df710d3656 Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Sat, 21 Aug 2010 22:16:23 +0200 Subject: - Fix BK toolbar drops at the extremities of the bar - A little cleanup --- src/bookmarks/bookmarkstoolbar.cpp | 61 ++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 22 deletions(-) (limited to 'src/bookmarks') diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp index 64e9c3b9..1a712939 100644 --- a/src/bookmarks/bookmarkstoolbar.cpp +++ b/src/bookmarks/bookmarkstoolbar.cpp @@ -38,7 +38,7 @@ // Qt Includes #include -#include +#include BookmarkMenu::BookmarkMenu(KBookmarkManager *manager, @@ -320,33 +320,37 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) else if (event->type() == QEvent::Drop) { QDropEvent *dropEvent = static_cast(event); - if (dropEvent->mimeData()->hasFormat("application/rekonq-bookmark")) + QByteArray addresses = dropEvent->mimeData()->data("application/rekonq-bookmark"); + KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data())); + + if (!dropEvent->mimeData()->hasFormat("application/rekonq-bookmark") && !bookmark.isNull()) { - QByteArray addresses = dropEvent->mimeData()->data("application/rekonq-bookmark"); - KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data())); + return QObject::eventFilter(watched, event); + } - QAction *destAction = toolBar()->actionAt(dropEvent->pos()); - if (destAction && destAction == m_dropAction) + QAction *destAction = toolBar()->actionAt(dropEvent->pos()); + if (destAction && destAction == m_dropAction) + { + if (toolBar()->actions().indexOf(m_dropAction) > 0) { - if (toolBar()->actions().indexOf(m_dropAction) > 0) - { - destAction = toolBar()->actions().at(toolBar()->actions().indexOf(m_dropAction) - 1); - } - else - { - destAction = toolBar()->actions().at(1); - } + destAction = toolBar()->actions().at(toolBar()->actions().indexOf(m_dropAction) - 1); + } + else + { + destAction = toolBar()->actions().at(1); } + } - KBookmarkActionInterface *destBookmarkAction = dynamic_cast(destAction); - QWidget *widgetAction = toolBar()->widgetForAction(destAction); + KBookmarkGroup root = Application::bookmarkProvider()->rootGroup(); + KBookmarkActionInterface *destBookmarkAction = dynamic_cast(destAction); + QWidget *widgetAction = toolBar()->widgetForAction(destAction); - if (!bookmark.isNull() && destBookmarkAction && !destBookmarkAction->bookmark().isNull() + if (destAction) + { + if (destBookmarkAction && !destBookmarkAction->bookmark().isNull() && widgetAction && bookmark.address() != destBookmarkAction->bookmark().address()) { - KBookmarkGroup root = Application::bookmarkProvider()->rootGroup(); KBookmark destBookmark = destBookmarkAction->bookmark(); - // To fix an issue with panel's drags root.deleteBookmark(bookmark); if ((dropEvent->pos().x() - widgetAction->pos().x()) > (widgetAction->width() / 2)) @@ -357,18 +361,31 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) { root.moveBookmark(bookmark, destBookmark.parentGroup().previous(destBookmark)); } - Application::bookmarkProvider()->bookmarkManager()->emitChanged(); - dropEvent->accept(); } } + else + { + root.deleteBookmark(bookmark); + if (QCursor::pos().x() <= toolBar()->pos().x()) + { + root.moveBookmark(bookmark, KBookmark()); + } + else + { + root.addBookmark(bookmark); + } + + Application::bookmarkProvider()->bookmarkManager()->emitChanged(); + } + dropEvent->accept(); } } else { // Drag handling if (event->type() == QEvent::MouseButtonPress) - {//QMessageBox::information(NULL, "", ""); + { QPoint pos = toolBar()->mapFromGlobal(QCursor::pos()); KBookmarkActionInterface* action = dynamic_cast(toolBar()->actionAt(pos)); -- cgit v1.2.1