summaryrefslogtreecommitdiff
path: root/src/bookmarks
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 /src/bookmarks
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
Diffstat (limited to 'src/bookmarks')
-rw-r--r--src/bookmarks/bookmarkprovider.cpp3
-rw-r--r--src/bookmarks/bookmarkstoolbar.cpp60
2 files changed, 40 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()));