summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoann Laissus <yoann.laissus@gmail.com>2010-12-20 20:48:18 +0100
committerYoann Laissus <yoann.laissus@gmail.com>2010-12-20 20:51:10 +0100
commit03c624f2b2e718ca6164402d55b5dca8c3a819dd (patch)
tree426bdbdacdbb79ba59b983cccad74af2cffccabd
parentCtrl+Shift+P shortcut for Private browsing (diff)
downloadrekonq-03c624f2b2e718ca6164402d55b5dca8c3a819dd.tar.xz
- Bookmark folders can now be dragged and dropped in the toolbar.
- Drop a bookmark folder in the WebView no longer crash rekonq but open this folder in new tabs - Fix some crash when a single bookmark is dropped in the WebView (incorrect URL) - Port the drag icon to IconManager CCBUG: 226479
-rw-r--r--src/bookmarks/bookmarkprovider.cpp3
-rw-r--r--src/bookmarks/bookmarkstoolbar.cpp60
-rw-r--r--src/webview.cpp22
-rw-r--r--src/webview.h1
4 files changed, 63 insertions, 23 deletions
diff --git a/src/bookmarks/bookmarkprovider.cpp b/src/bookmarks/bookmarkprovider.cpp
index fe038b2a..2a9dbe2e 100644
--- a/src/bookmarks/bookmarkprovider.cpp
+++ b/src/bookmarks/bookmarkprovider.cpp
@@ -231,6 +231,7 @@ void BookmarkProvider::fillBookmarkBar(BookmarkToolBar *toolBar)
connect(menuAction->menu(), SIGNAL(aboutToHide()), toolBar, SLOT(menuHidden()));
toolBar->toolBar()->addAction(menuAction);
+ toolBar->toolBar()->widgetForAction(menuAction)->installEventFilter(toolBar);
}
else if (bookmark.isSeparator())
{
@@ -239,8 +240,6 @@ void BookmarkProvider::fillBookmarkBar(BookmarkToolBar *toolBar)
else
{
KBookmarkAction *action = new KBookmarkAction(bookmark, m_owner, this);
- //action->s
- //action->setIconText(action->iconText().replace('&', "&&&"));
action->setIcon(Application::iconManager()->iconForUrl( KUrl(bookmark.url()) ));
connect(action, SIGNAL(hovered()), toolBar, SLOT(actionHovered()));
toolBar->toolBar()->addAction(action);
diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp
index 63092b8d..e239e235 100644
--- a/src/bookmarks/bookmarkstoolbar.cpp
+++ b/src/bookmarks/bookmarkstoolbar.cpp
@@ -328,27 +328,24 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event)
{
QDropEvent *dropEvent = static_cast<QDropEvent*>(event);
KBookmark bookmark;
- QUrl url;
- QString title;
+ KBookmarkGroup root = Application::bookmarkProvider()->rootGroup();
if (dropEvent->mimeData()->hasFormat("application/rekonq-bookmark"))
{
QByteArray addresses = dropEvent->mimeData()->data("application/rekonq-bookmark");
bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data()));
if (bookmark.isNull())
- return QObject::eventFilter(watched, event);
-
- url = bookmark.url();
- title = bookmark.fullText();
+ return false;
}
else if (dropEvent->mimeData()->hasFormat("text/uri-list"))
{
- title = dropEvent->mimeData()->text();
- url = dropEvent->mimeData()->urls().at(0).toString();
+ QString title = dropEvent->mimeData()->text();
+ QString url = dropEvent->mimeData()->urls().at(0).toString();
+ bookmark = root.addBookmark(title, url);
}
else
{
- return QObject::eventFilter(watched, event);
+ return false;
}
QAction *destAction = toolBar()->actionAt(dropEvent->pos());
@@ -364,8 +361,6 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event)
}
}
- KBookmarkGroup root = Application::bookmarkProvider()->rootGroup();
-
if (destAction)
{
KBookmarkActionInterface *destBookmarkAction = dynamic_cast<KBookmarkActionInterface *>(destAction);
@@ -375,8 +370,6 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event)
&& bookmark.address() != destBookmarkAction->bookmark().address())
{
KBookmark destBookmark = destBookmarkAction->bookmark();
- root.deleteBookmark(bookmark);
- bookmark = root.addBookmark(title, url);
if ((dropEvent->pos().x() - widgetAction->pos().x()) > (widgetAction->width() / 2))
{
@@ -393,7 +386,7 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event)
else
{
root.deleteBookmark(bookmark);
- bookmark = root.addBookmark(title, url);
+ bookmark = root.addBookmark(bookmark);
if (dropEvent->pos().x() < toolBar()->widgetForAction(toolBar()->actions().first())->pos().x())
{
root.moveBookmark(bookmark, KBookmark());
@@ -410,22 +403,38 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event)
if (event->type() == QEvent::MouseButtonPress)
{
QPoint pos = toolBar()->mapFromGlobal(QCursor::pos());
- KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(toolBar()->actionAt(pos));
+ KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(toolBar()->actionAt(pos));
- if (action && !action->bookmark().isGroup())
+ if (action)
{
m_dragAction = toolBar()->actionAt(pos);
m_startDragPos = pos;
+
+ // The menu is displayed only when the mouse button is released
+ if (action->bookmark().isGroup())
+ return true;
}
}
else if (event->type() == QEvent::MouseMove)
{
int distance = (toolBar()->mapFromGlobal(QCursor::pos()) - m_startDragPos).manhattanLength();
- if (distance >= QApplication::startDragDistance())
+ if (!m_currentMenu && distance >= QApplication::startDragDistance())
{
startDrag();
}
}
+ else if (event->type() == QEvent::MouseButtonRelease)
+ {
+ int distance = (toolBar()->mapFromGlobal(QCursor::pos()) - m_startDragPos).manhattanLength();
+ KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(toolBar()->actionAt(m_startDragPos));
+
+ if (action && action->bookmark().isGroup() && distance < QApplication::startDragDistance())
+ {
+ KBookmarkActionMenu *menu = dynamic_cast<KBookmarkActionMenu *>(toolBar()->actionAt(m_startDragPos));
+ QPoint actionPos = toolBar()->mapToGlobal(toolBar()->widgetForAction(menu)->pos());
+ menu->menu()->popup(QPoint(actionPos.x(), actionPos.y() + toolBar()->widgetForAction(menu)->height()));
+ }
+ }
}
return QObject::eventFilter(watched, event);
@@ -443,17 +452,26 @@ void BookmarkToolBar::actionHovered()
void BookmarkToolBar::startDrag()
{
KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(m_dragAction);
- if (action && !action->bookmark().isGroup())
+ if (action)
{
QMimeData *mimeData = new QMimeData;
+ KBookmark bookmark = action->bookmark();
- QByteArray address = action->bookmark().address().toLatin1();
+ QByteArray address = bookmark.address().toLatin1();
mimeData->setData("application/rekonq-bookmark", address);
- action->bookmark().populateMimeData(mimeData);
+ bookmark.populateMimeData(mimeData);
QDrag *drag = new QDrag(toolBar());
drag->setMimeData(mimeData);
- drag->setPixmap(KIcon(action->bookmark().icon()).pixmap(24, 24));
+
+ if (bookmark.isGroup())
+ {
+ drag->setPixmap(KIcon(bookmark.icon()).pixmap(24, 24));
+ }
+ else
+ {
+ drag->setPixmap(Application::iconManager()->iconForUrl(action->bookmark().url()).pixmap(24, 24));
+ }
drag->start(Qt::MoveAction);
connect(drag, SIGNAL(destroyed()), this, SLOT(dragDestroyed()));
diff --git a/src/webview.cpp b/src/webview.cpp
index aeaf92b7..2c0b59ea 100644
--- a/src/webview.cpp
+++ b/src/webview.cpp
@@ -35,6 +35,7 @@
// Local Includes
#include "application.h"
#include "bookmarkprovider.h"
+#include "bookmarkowner.h"
#include "iconmanager.h"
#include "mainview.h"
#include "mainwindow.h"
@@ -453,6 +454,27 @@ void WebView::mouseMoveEvent(QMouseEvent *event)
}
+void WebView::dropEvent(QDropEvent *event)
+{
+ if (event->mimeData()->hasFormat("application/rekonq-bookmark"))
+ {
+ QByteArray addresses = event->mimeData()->data("application/rekonq-bookmark");
+ KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data()));
+ if (bookmark.isGroup())
+ {
+ Application::bookmarkProvider()->bookmarkOwner()->openFolderinTabs(bookmark.toGroup());
+ }
+ else
+ {
+ emit loadUrl(bookmark.url(), Rekonq::CurrentTab);
+ }
+ }
+ else
+ {
+ KWebView::dropEvent(event);
+ }
+}
+
void WebView::search()
{
KAction *a = qobject_cast<KAction*>(sender());
diff --git a/src/webview.h b/src/webview.h
index 9518b74d..acd7eae2 100644
--- a/src/webview.h
+++ b/src/webview.h
@@ -60,6 +60,7 @@ protected:
void mouseMoveEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
void wheelEvent(QWheelEvent *event);
+ void dropEvent(QDropEvent *event);
private slots:
void search();