summaryrefslogtreecommitdiff
path: root/src/bookmarks
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-08-18 23:08:59 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-08-18 23:08:59 +0200
commitaa3ddcce01572e968b4abce827d6d21e5604b360 (patch)
tree2e8a8dda71405d5d51e56df4c5b81317a198da5a /src/bookmarks
parentMerge commit 'refs/merge-requests/178' of git://gitorious.org/rekonq/mainline... (diff)
parentFix a strange behaviour if a dragged item is dropped on itself (diff)
downloadrekonq-aa3ddcce01572e968b4abce827d6d21e5604b360.tar.xz
Merge commit 'refs/merge-requests/173' of git://gitorious.org/rekonq/mainline into m173
Diffstat (limited to 'src/bookmarks')
-rw-r--r--src/bookmarks/bookmarkscontextmenu.cpp (renamed from src/bookmarks/bookmarkcontextmenu.cpp)38
-rw-r--r--src/bookmarks/bookmarkscontextmenu.h (renamed from src/bookmarks/bookmarkcontextmenu.h)6
-rw-r--r--src/bookmarks/bookmarksmanager.cpp200
-rw-r--r--src/bookmarks/bookmarksmanager.h74
-rw-r--r--src/bookmarks/bookmarkspanel.cpp4
-rw-r--r--src/bookmarks/bookmarkstoolbar.cpp433
-rw-r--r--src/bookmarks/bookmarkstoolbar.h120
7 files changed, 580 insertions, 295 deletions
diff --git a/src/bookmarks/bookmarkcontextmenu.cpp b/src/bookmarks/bookmarkscontextmenu.cpp
index 714c8b51..c448d293 100644
--- a/src/bookmarks/bookmarkcontextmenu.cpp
+++ b/src/bookmarks/bookmarkscontextmenu.cpp
@@ -25,8 +25,8 @@
// Self Includes
-#include "bookmarkcontextmenu.h"
-#include "bookmarkcontextmenu.moc"
+#include "bookmarkscontextmenu.h"
+#include "bookmarkscontextmenu.moc"
// Local Includes
#include "application.h"
@@ -41,7 +41,7 @@
#include <QClipboard>
-BookmarkContextMenu::BookmarkContextMenu(const KBookmark & bookmark, KBookmarkManager *manager, KBookmarkOwner *owner, QWidget *parent)
+BookmarksContextMenu::BookmarksContextMenu(const KBookmark & bookmark, KBookmarkManager *manager, KBookmarkOwner *owner, QWidget *parent)
: KBookmarkContextMenu(bookmark, manager, owner, parent)
, m_ac(new KActionCollection(this))
{
@@ -49,13 +49,13 @@ BookmarkContextMenu::BookmarkContextMenu(const KBookmark & bookmark, KBookmarkMa
}
-BookmarkContextMenu::~BookmarkContextMenu()
+BookmarksContextMenu::~BookmarksContextMenu()
{
delete m_ac;
}
-void BookmarkContextMenu::setupActions()
+void BookmarksContextMenu::setupActions()
{
KAction* action;
@@ -101,7 +101,7 @@ void BookmarkContextMenu::setupActions()
}
-void BookmarkContextMenu::addBookmarkActions()
+void BookmarksContextMenu::addBookmarkActions()
{
addAction(m_ac->action("open"));
addAction(m_ac->action("open_tab"));
@@ -124,7 +124,7 @@ void BookmarkContextMenu::addBookmarkActions()
}
-void BookmarkContextMenu::addFolderActions()
+void BookmarksContextMenu::addFolderActions()
{
if (!bookmark().toGroup().first().isNull())
{
@@ -143,7 +143,7 @@ void BookmarkContextMenu::addFolderActions()
}
-void BookmarkContextMenu::addSeparatorActions()
+void BookmarksContextMenu::addSeparatorActions()
{
addAction(m_ac->action("bookmark_page"));
addAction(m_ac->action("folder_new"));
@@ -155,7 +155,7 @@ void BookmarkContextMenu::addSeparatorActions()
}
-void BookmarkContextMenu::addActions()
+void BookmarksContextMenu::addActions()
{
if (bookmark().isGroup())
{
@@ -181,25 +181,25 @@ void BookmarkContextMenu::addActions()
}
-void BookmarkContextMenu::openInCurrentTab()
+void BookmarksContextMenu::openInCurrentTab()
{
Application::instance()->loadUrl(bookmark().url());
}
-void BookmarkContextMenu::openInNewTab()
+void BookmarksContextMenu::openInNewTab()
{
Application::instance()->loadUrl(bookmark().url(), Rekonq::NewTab);
}
-void BookmarkContextMenu::openInNewWindow()
+void BookmarksContextMenu::openInNewWindow()
{
Application::instance()->loadUrl(bookmark().url(), Rekonq::NewWindow);
}
-void BookmarkContextMenu::copyToClipboard()
+void BookmarksContextMenu::copyToClipboard()
{
if (bookmark().isNull())
return;
@@ -209,14 +209,14 @@ void BookmarkContextMenu::copyToClipboard()
}
-void BookmarkContextMenu::deleteBookmark()
+void BookmarksContextMenu::deleteBookmark()
{
KBookmark bm = bookmark();
Application::bookmarkProvider()->bookmarkOwner()->deleteBookmark(bm);
}
-void BookmarkContextMenu::editBookmark()
+void BookmarksContextMenu::editBookmark()
{
KBookmark selected = bookmark();
selected.setFullText(selected.fullText().replace("&&", "&"));
@@ -227,14 +227,14 @@ void BookmarkContextMenu::editBookmark()
}
-void BookmarkContextMenu::openFolderInTabs()
+void BookmarksContextMenu::openFolderInTabs()
{
if (bookmark().isGroup())
owner()->openFolderinTabs(bookmark().toGroup());
}
-void BookmarkContextMenu::newBookmarkGroup()
+void BookmarksContextMenu::newBookmarkGroup()
{
KBookmark selected = bookmark();
KBookmarkDialog *dialog = owner()->bookmarkDialog(manager(), QApplication::activeWindow());
@@ -266,7 +266,7 @@ void BookmarkContextMenu::newBookmarkGroup()
}
-void BookmarkContextMenu::newSeparator()
+void BookmarksContextMenu::newSeparator()
{
KBookmark selected = bookmark();
KBookmark newBk;
@@ -295,7 +295,7 @@ void BookmarkContextMenu::newSeparator()
}
-void BookmarkContextMenu::bookmarkCurrentPage()
+void BookmarksContextMenu::bookmarkCurrentPage()
{
KBookmarkGroup parent = Application::bookmarkProvider()->rootGroup();
KBookmark selected = bookmark();
diff --git a/src/bookmarks/bookmarkcontextmenu.h b/src/bookmarks/bookmarkscontextmenu.h
index ebbfd6e8..2ef8e5a7 100644
--- a/src/bookmarks/bookmarkcontextmenu.h
+++ b/src/bookmarks/bookmarkscontextmenu.h
@@ -34,13 +34,13 @@
#include <KBookmarkMenu>
-class BookmarkContextMenu : public KBookmarkContextMenu
+class BookmarksContextMenu : public KBookmarkContextMenu
{
Q_OBJECT
public:
- BookmarkContextMenu(const KBookmark & bk, KBookmarkManager * manager, KBookmarkOwner *owner, QWidget * parent = 0);
- ~BookmarkContextMenu();
+ BookmarksContextMenu(const KBookmark & bk, KBookmarkManager * manager, KBookmarkOwner *owner, QWidget * parent = 0);
+ ~BookmarksContextMenu();
virtual void addActions();
diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarksmanager.cpp
index cade77b4..221a6db1 100644
--- a/src/bookmarks/bookmarksmanager.cpp
+++ b/src/bookmarks/bookmarksmanager.cpp
@@ -36,7 +36,7 @@
#include "webtab.h"
#include "webview.h"
#include "mainview.h"
-#include "bookmarkcontextmenu.h"
+#include "bookmarkscontextmenu.h"
// KDE Includes
#include <KActionCollection>
@@ -179,202 +179,6 @@ QList< QPair<QString, QString> > BookmarkOwner::currentBookmarkList() const
// ------------------------------------------------------------------------------------------------------
-BookmarkMenu::BookmarkMenu(KBookmarkManager *manager,
- KBookmarkOwner *owner,
- KMenu *menu,
- KActionCollection* actionCollection)
- : KBookmarkMenu(manager, owner, menu, actionCollection)
-{
-}
-
-
-BookmarkMenu::BookmarkMenu(KBookmarkManager *manager,
- KBookmarkOwner *owner,
- KMenu *parentMenu,
- const QString &parentAddress)
- : KBookmarkMenu(manager, owner, parentMenu, parentAddress)
-{
-}
-
-
-BookmarkMenu::~BookmarkMenu()
-{
-}
-
-
-KMenu * BookmarkMenu::contextMenu(QAction *act)
-{
-
- KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(act);
- if (!action)
- return 0;
- return new BookmarkContextMenu(action->bookmark(), manager(), owner());
-}
-
-
-QAction * BookmarkMenu::actionForBookmark(const KBookmark &bookmark)
-{
- if (bookmark.isGroup())
- {
- KBookmarkActionMenu *actionMenu = new KBookmarkActionMenu(bookmark, this);
- BookmarkMenu *menu = new BookmarkMenu(manager(), owner(), actionMenu->menu(), bookmark.address());
- connect(actionMenu, SIGNAL(hovered()), menu, SLOT(slotAboutToShow()));
- return actionMenu;
- }
- else if (bookmark.isSeparator())
- {
- return KBookmarkMenu::actionForBookmark(bookmark);
- }
- else
- {
- KBookmarkAction *action = new KBookmarkAction(bookmark, owner(), this);
- connect(action, SIGNAL(hovered()), this, SLOT(actionHovered()));
- return action;
- }
-}
-
-
-void BookmarkMenu::refill()
-{
- clear();
- fillBookmarks();
-
- if (parentMenu()->actions().count() > 0)
- parentMenu()->addSeparator();
-
- if (isRoot())
- {
- addAddBookmark();
- addAddBookmarksList();
- addNewFolder();
- addEditBookmarks();
- }
- else
- {
- addOpenFolderInTabs();
- addAddBookmark();
- addAddBookmarksList();
- addNewFolder();
- }
-}
-
-
-void BookmarkMenu::addOpenFolderInTabs()
-{
- KAction *action;
- KBookmarkGroup group = manager()->findByAddress(parentAddress()).toGroup();
-
- if (!group.first().isNull())
- {
- KBookmark bookmark = group.first();
-
- while (bookmark.isGroup() || bookmark.isSeparator())
- {
- bookmark = group.next(bookmark);
- }
-
- if (!bookmark.isNull())
- {
- action = new KAction(KIcon("tab-new"), i18n("Open Folder in Tabs"), this);
- action->setHelpText(i18n("Open all bookmarks in this folder as new tabs."));
- connect(action, SIGNAL(triggered(bool)), this, SLOT(slotOpenFolderInTabs()));
- parentMenu()->addAction(action);
- }
- }
-}
-
-
-void BookmarkMenu::actionHovered()
-{
- KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(sender());
- if (action)
- Application::instance()->mainWindow()->notifyMessage(action->bookmark().url().url());
-}
-
-
-// ------------------------------------------------------------------------------------------------------
-
-
-BookmarkToolBar::BookmarkToolBar( const QString &objectName,
- QMainWindow *parentWindow,
- Qt::ToolBarArea area,
- bool newLine,
- bool isMainToolBar,
- bool readConfig
- )
- : KToolBar(objectName, parentWindow, area, newLine, isMainToolBar, readConfig)
- , m_filled(false)
- , m_currentMenu(0)
-{
- connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(QString,QString)), this, SLOT(hideMenu()));
-}
-
-
-BookmarkToolBar::~BookmarkToolBar()
-{
-}
-
-
-void BookmarkToolBar::setVisible(bool visible)
-{
- if (visible && !m_filled)
- {
- m_filled = true;
- Application::bookmarkProvider()->fillBookmarkBar(this);
- }
- KToolBar::setVisible(visible);
-}
-
-
-void BookmarkToolBar::menuDisplayed()
-{
- qApp->installEventFilter(this);
- m_currentMenu = qobject_cast<KMenu*>(sender());
-}
-
-
-void BookmarkToolBar::menuHidden()
-{
- qApp->removeEventFilter(this);
- m_currentMenu = 0;
-}
-
-
-void BookmarkToolBar::hideMenu()
-{
- if(m_currentMenu)
- m_currentMenu->hide();
-}
-
-
-bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event)
-{
- // To switch root folders as in a menubar
- if (event->type() == QEvent::MouseMove && m_currentMenu)
- {
- KBookmarkActionMenu* act = dynamic_cast<KBookmarkActionMenu *>(this->actionAt(this->mapFromGlobal(QCursor::pos())));
- if (act && act->menu() != m_currentMenu)
- {
- m_currentMenu->hide();
- QPoint pos = mapToGlobal(widgetForAction(act)->pos());
- act->menu()->popup(QPoint(pos.x(), pos.y() + widgetForAction(act)->height()));
- }
- }
- return KToolBar::eventFilter(watched, event);
-}
-
-
-void BookmarkToolBar::actionHovered()
-{
- KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(sender());
- if (action)
- Application::instance()->mainWindow()->notifyMessage(action->bookmark().url().url());
-}
-
-// ------------------------------------------------------------------------------------------------------
-
-
-
BookmarkProvider::BookmarkProvider(QObject *parent)
: QObject(parent)
, m_manager(0)
@@ -484,7 +288,7 @@ void BookmarkProvider::contextMenu(const QPoint &point)
if (!action)
return;
- BookmarkContextMenu menu(action->bookmark(), bookmarkManager(), bookmarkOwner());
+ BookmarksContextMenu menu(action->bookmark(), bookmarkManager(), bookmarkOwner());
menu.exec(bookmarkToolBar->mapToGlobal(point));
}
diff --git a/src/bookmarks/bookmarksmanager.h b/src/bookmarks/bookmarksmanager.h
index b084b8ee..6f97e4ef 100644
--- a/src/bookmarks/bookmarksmanager.h
+++ b/src/bookmarks/bookmarksmanager.h
@@ -38,6 +38,7 @@
#include "application.h"
#include "urlresolver.h"
#include "bookmarkspanel.h"
+#include "bookmarkstoolbar.h"
// Qt Includes
#include <QWidget>
@@ -137,79 +138,6 @@ signals:
void openUrl(const KUrl &, const Rekonq::OpenType &);
};
-// ------------------------------------------------------------------------------
-
-
-// KDE Includes
-#include <KBookmarkMenu>
-
-/**
- * This class represent the rekonq bookmarks menu.
- * It's just a simple class inherited from KBookmarkMenu
- *
- */
-class BookmarkMenu : public KBookmarkMenu
-{
- Q_OBJECT
-
-public:
- BookmarkMenu(KBookmarkManager* manager,
- KBookmarkOwner* owner,
- KMenu* menu,
- KActionCollection* actionCollection);
- BookmarkMenu(KBookmarkManager *manager,
- KBookmarkOwner *owner,
- KMenu *parentMenu,
- const QString &parentAddress);
- ~BookmarkMenu();
-
-protected:
- virtual KMenu * contextMenu(QAction * act);
- virtual void refill();
- virtual QAction* actionForBookmark(const KBookmark &bookmark);
-
-private slots:
- void actionHovered();
-
-private:
- void addOpenFolderInTabs();
-
-};
-
-
-// ------------------------------------------------------------------------------
-
-#include <KToolBar>
-
-class BookmarkToolBar : public KToolBar
-{
- Q_OBJECT
-
-public:
-BookmarkToolBar(const QString &objectName,
- QMainWindow *parentWindow,
- Qt::ToolBarArea area,
- bool newLine = false,
- bool isMainToolBar = false,
- bool readConfig = true);
-~BookmarkToolBar();
-
-virtual void setVisible(bool visible);
-
-protected:
- bool eventFilter(QObject *watched, QEvent *event);
-
-private slots:
- void actionHovered();
- void menuDisplayed();
- void menuHidden();
- void hideMenu();
-
-private:
- bool m_filled;
- KMenu *m_currentMenu;
-};
-
// ------------------------------------------------------------------------------
diff --git a/src/bookmarks/bookmarkspanel.cpp b/src/bookmarks/bookmarkspanel.cpp
index b49d4f5e..72778f7a 100644
--- a/src/bookmarks/bookmarkspanel.cpp
+++ b/src/bookmarks/bookmarkspanel.cpp
@@ -33,7 +33,7 @@
#include "bookmarksmanager.h"
#include "bookmarkstreemodel.h"
#include "bookmarksproxy.h"
-#include "bookmarkcontextmenu.h"
+#include "bookmarkscontextmenu.h"
// Auto Includes
#include "rekonq.h"
@@ -201,7 +201,7 @@ void BookmarksPanel::contextMenu(const QPoint &pos)
KBookmark selected = bookmarkForIndex(index);
- BookmarkContextMenu menu( selected,
+ BookmarksContextMenu menu( selected,
Application::bookmarkProvider()->bookmarkManager(),
Application::bookmarkProvider()->bookmarkOwner(),
this
diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp
new file mode 100644
index 00000000..1ec1d677
--- /dev/null
+++ b/src/bookmarks/bookmarkstoolbar.cpp
@@ -0,0 +1,433 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2008-2010 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2010 by Yoann Laissus <yoann dot laissus at gmail dot com>
+*
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License as
+* published by the Free Software Foundation; either version 2 of
+* the License or (at your option) version 3 or any later version
+* accepted by the membership of KDE e.V. (or its successor approved
+* by the membership of KDE e.V.), which shall act as a proxy
+* defined in Section 14 of version 3 of the license.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+// Self Includes
+#include "bookmarkstoolbar.h"
+#include "bookmarkstoolbar.moc"
+
+// Local Includes
+#include "bookmarkscontextmenu.h"
+#include "mainwindow.h"
+#include "application.h"
+#include "bookmarksmanager.h"
+
+
+BookmarkMenu::BookmarkMenu(KBookmarkManager *manager,
+ KBookmarkOwner *owner,
+ KMenu *menu,
+ KActionCollection* actionCollection)
+ : KBookmarkMenu(manager, owner, menu, actionCollection)
+{
+}
+
+
+BookmarkMenu::BookmarkMenu(KBookmarkManager *manager,
+ KBookmarkOwner *owner,
+ KMenu *parentMenu,
+ const QString &parentAddress)
+ : KBookmarkMenu(manager, owner, parentMenu, parentAddress)
+{
+}
+
+
+BookmarkMenu::~BookmarkMenu()
+{
+}
+
+
+KMenu * BookmarkMenu::contextMenu(QAction *act)
+{
+
+ KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(act);
+ if (!action)
+ return 0;
+ return new BookmarksContextMenu(action->bookmark(), manager(), owner());
+}
+
+
+QAction * BookmarkMenu::actionForBookmark(const KBookmark &bookmark)
+{
+ if (bookmark.isGroup())
+ {
+ KBookmarkActionMenu *actionMenu = new KBookmarkActionMenu(bookmark, this);
+ BookmarkMenu *menu = new BookmarkMenu(manager(), owner(), actionMenu->menu(), bookmark.address());
+ // An hack to get rid of bug 219274
+ connect(actionMenu, SIGNAL(hovered()), menu, SLOT(slotAboutToShow()));
+ return actionMenu;
+ }
+ else if (bookmark.isSeparator())
+ {
+ return KBookmarkMenu::actionForBookmark(bookmark);
+ }
+ else
+ {
+ KBookmarkAction *action = new KBookmarkAction(bookmark, owner(), this);
+ connect(action, SIGNAL(hovered()), this, SLOT(actionHovered()));
+ return action;
+ }
+}
+
+
+void BookmarkMenu::refill()
+{
+ clear();
+ fillBookmarks();
+
+ if (parentMenu()->actions().count() > 0)
+ parentMenu()->addSeparator();
+
+ if (isRoot())
+ {
+ addAddBookmark();
+ addAddBookmarksList();
+ addNewFolder();
+ addEditBookmarks();
+ }
+ else
+ {
+ addOpenFolderInTabs();
+ addAddBookmark();
+ addAddBookmarksList();
+ addNewFolder();
+ }
+}
+
+
+void BookmarkMenu::addOpenFolderInTabs()
+{
+ KAction *action;
+ KBookmarkGroup group = manager()->findByAddress(parentAddress()).toGroup();
+
+ if (!group.first().isNull())
+ {
+ KBookmark bookmark = group.first();
+
+ while (bookmark.isGroup() || bookmark.isSeparator())
+ {
+ bookmark = group.next(bookmark);
+ }
+
+ if (!bookmark.isNull())
+ {
+ action = new KAction(KIcon("tab-new"), i18n("Open Folder in Tabs"), this);
+ action->setHelpText(i18n("Open all bookmarks in this folder as new tabs."));
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(slotOpenFolderInTabs()));
+ parentMenu()->addAction(action);
+ }
+ }
+}
+
+
+void BookmarkMenu::actionHovered()
+{
+ KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(sender());
+ if (action)
+ Application::instance()->mainWindow()->notifyMessage(action->bookmark().url().url());
+}
+
+
+// ------------------------------------------------------------------------------------------------------
+
+#include <QActionEvent>
+
+BookmarkToolBar::BookmarkToolBar( const QString &objectName,
+ QMainWindow *parentWindow,
+ Qt::ToolBarArea area,
+ bool newLine,
+ bool isMainToolBar,
+ bool readConfig
+ )
+ : KToolBar(objectName, parentWindow, area, newLine, isMainToolBar, readConfig)
+ , m_filled(false)
+ , m_currentMenu(0)
+ , m_dragAction(0)
+ , m_dropAction(0)
+{
+ connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(QString, QString)), this, SLOT(hideMenu()));
+ setAcceptDrops(true);
+}
+
+
+BookmarkToolBar::~BookmarkToolBar()
+{
+}
+
+
+void BookmarkToolBar::setVisible(bool visible)
+{
+ if (visible && !m_filled)
+ {
+ m_filled = true;
+ Application::bookmarkProvider()->fillBookmarkBar(this);
+ }
+ KToolBar::setVisible(visible);
+}
+
+
+void BookmarkToolBar::menuDisplayed()
+{
+ qApp->installEventFilter(this);
+ m_currentMenu = qobject_cast<KMenu*>(sender());
+}
+
+
+void BookmarkToolBar::menuHidden()
+{
+ qApp->removeEventFilter(this);
+ m_currentMenu = 0;
+}
+
+
+void BookmarkToolBar::hideMenu()
+{
+ if(m_currentMenu)
+ m_currentMenu->hide();
+}
+
+
+bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event)
+{
+
+ if (m_currentMenu && m_currentMenu->isVisible())
+ {
+ // To switch root folders as in a menubar
+ KBookmarkActionMenu* act = dynamic_cast<KBookmarkActionMenu *>(this->actionAt(this->mapFromGlobal(QCursor::pos())));
+ if (event->type() == QEvent::MouseMove && act && m_currentMenu && act->menu() != m_currentMenu)
+ {
+ m_currentMenu->hide();
+ QPoint pos = mapToGlobal(widgetForAction(act)->pos());
+ act->menu()->popup(QPoint(pos.x(), pos.y() + widgetForAction(act)->height()));
+ }
+ }
+ else
+ {
+ // Drag handling
+ if (event->type() == QEvent::MouseButtonPress)
+ {
+ QPoint pos = mapFromGlobal(QCursor::pos());
+ KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(actionAt(pos));
+
+ if (action && !action->bookmark().isGroup())
+ {
+ m_dragAction = actionAt(pos);
+ m_startDragPos = pos;
+ }
+ }
+ else if (event->type() == QEvent::MouseMove)
+ {
+ int distance = (mapFromGlobal(QCursor::pos()) - m_startDragPos).manhattanLength();
+ if (distance >= QApplication::startDragDistance())
+ {
+ startDrag();
+ }
+ }
+ }
+ return KToolBar::eventFilter(watched, event);
+}
+
+
+void BookmarkToolBar::actionHovered()
+{
+ KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(sender());
+ if (action)
+ Application::instance()->mainWindow()->notifyMessage(action->bookmark().url().url());
+}
+
+
+void BookmarkToolBar::actionEvent(QActionEvent *event)
+{
+ KToolBar::actionEvent(event);
+
+ QWidget *widget = widgetForAction(event->action());
+ if (!widget || event->action() == m_dropAction)
+ return;
+
+ if (event->type() == QEvent::ActionAdded)
+ {
+ widget->installEventFilter(this);
+ }
+ else if (event->type() == QEvent::ActionRemoved)
+ {
+ widget->removeEventFilter(this);
+ }
+ else if (event->type() == QEvent::ParentChange)
+ {
+ widget->removeEventFilter(this);
+ }
+}
+
+
+void BookmarkToolBar::startDrag()
+{
+ KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(m_dragAction);
+ if (action && !action->bookmark().isGroup())
+ {
+ QMimeData *mimeData = new QMimeData;
+
+ QByteArray address = action->bookmark().address().toLatin1();
+ mimeData->setData("application/rekonq-bookmark", address);
+ action->bookmark().populateMimeData(mimeData);
+
+ QDrag *drag = new QDrag(this);
+ drag->setMimeData(mimeData);
+ drag->setPixmap(KIcon(action->bookmark().icon()).pixmap(24, 24));
+
+ drag->start(Qt::MoveAction);
+ connect(drag, SIGNAL(destroyed()), this, SLOT(dragDestroyed()));
+ }
+}
+
+
+void BookmarkToolBar::dragEnterEvent(QDragEnterEvent *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.isNull())
+ {
+ QFrame* dropIndicatorWidget = new QFrame(this);
+ dropIndicatorWidget->setFrameShape(QFrame::VLine);
+ m_dropAction = insertWidget(actionAt(event->pos()), dropIndicatorWidget);
+
+ event->accept();
+ }
+ }
+
+ KToolBar::dragEnterEvent(event);
+}
+
+
+void BookmarkToolBar::dragMoveEvent(QDragMoveEvent *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()));
+ QAction *overAction = actionAt(event->pos());
+ KBookmarkActionInterface *overActionBK = dynamic_cast<KBookmarkActionInterface*>(overAction);
+ QWidget *widgetAction = widgetForAction(overAction);
+
+ if (!bookmark.isNull() && overAction != m_dropAction && overActionBK && widgetAction && m_dropAction)
+ {
+ removeAction(m_dropAction);
+
+ if ((event->pos().x() - widgetAction->pos().x()) > (widgetAction->width() / 2))
+ {
+ if (actions().count() > actions().indexOf(overAction) + 1)
+ {
+ insertAction(actions().at(actions().indexOf(overAction) + 1), m_dropAction);
+ }
+ else
+ {
+ addAction(m_dropAction);
+ }
+ }
+ else
+ {
+ insertAction(overAction, m_dropAction);
+ }
+
+ event->accept();
+ }
+ }
+
+ KToolBar::dragMoveEvent(event);
+}
+
+
+void BookmarkToolBar::dragLeaveEvent(QDragLeaveEvent *event)
+{
+ delete m_dropAction;
+ m_dropAction = 0;
+ event->accept();
+ KToolBar::dragLeaveEvent(event);
+}
+
+
+void BookmarkToolBar::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()));
+
+ QAction *destAction = actionAt(event->pos());
+ if (destAction && destAction == m_dropAction)
+ {
+ if (actions().indexOf(m_dropAction) > 0)
+ {
+ destAction = actions().at(actions().indexOf(m_dropAction) - 1);
+ }
+ else
+ {
+ destAction = actions().at(1);
+ }
+ }
+
+ KBookmarkActionInterface *destBookmarkAction = dynamic_cast<KBookmarkActionInterface *>(destAction);
+ QWidget *widgetAction = widgetForAction(destAction);
+
+ if (!bookmark.isNull() && 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 ((event->pos().x() - widgetAction->pos().x()) > (widgetAction->width() / 2))
+ {
+ root.moveBookmark(bookmark, destBookmark);
+ }
+ else
+ {
+ root.moveBookmark(bookmark, destBookmark.parentGroup().previous(destBookmark));
+ }
+
+ Application::bookmarkProvider()->bookmarkManager()->emitChanged();
+ event->accept();
+ }
+ }
+
+ KToolBar::dropEvent(event);
+}
+
+
+void BookmarkToolBar::dragDestroyed()
+{
+ // A workaround to get rid of the checked state of the dragged action
+ if (m_dragAction)
+ {
+ m_dragAction->setVisible(false);
+ m_dragAction->setVisible(true);
+ m_dragAction = 0;
+ }
+ delete m_dropAction;
+ m_dropAction = 0;
+}
diff --git a/src/bookmarks/bookmarkstoolbar.h b/src/bookmarks/bookmarkstoolbar.h
new file mode 100644
index 00000000..cf7b62cc
--- /dev/null
+++ b/src/bookmarks/bookmarkstoolbar.h
@@ -0,0 +1,120 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2008-2010 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2010 by Yoann Laissus <yoann dot laissus at gmail dot com>
+*
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License as
+* published by the Free Software Foundation; either version 2 of
+* the License or (at your option) version 3 or any later version
+* accepted by the membership of KDE e.V. (or its successor approved
+* by the membership of KDE e.V.), which shall act as a proxy
+* defined in Section 14 of version 3 of the license.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+#ifndef BOOKMARKSTOOLBAR_H
+#define BOOKMARKSTOOLBAR_H
+
+// Local Includes
+
+
+// Qt Includes
+
+
+// KDE Includes
+#include <KBookmarkMenu>
+#include <KToolBar>
+
+
+
+/**
+ * This class represent the rekonq bookmarks menu.
+ * It's just a simple class inherited from KBookmarkMenu
+ *
+ */
+class BookmarkMenu : public KBookmarkMenu
+{
+ Q_OBJECT
+
+public:
+ BookmarkMenu(KBookmarkManager* manager,
+ KBookmarkOwner* owner,
+ KMenu* menu,
+ KActionCollection* actionCollection);
+ BookmarkMenu(KBookmarkManager *manager,
+ KBookmarkOwner *owner,
+ KMenu *parentMenu,
+ const QString &parentAddress);
+ ~BookmarkMenu();
+
+protected:
+ virtual KMenu * contextMenu(QAction * act);
+ virtual void refill();
+ virtual QAction* actionForBookmark(const KBookmark &bookmark);
+
+private slots:
+ void actionHovered();
+
+private:
+ void addOpenFolderInTabs();
+
+};
+
+
+// ------------------------------------------------------------------------------
+
+#include <KToolBar>
+
+class BookmarkToolBar : public KToolBar
+{
+ Q_OBJECT
+
+public:
+BookmarkToolBar(const QString &objectName,
+ QMainWindow *parentWindow,
+ Qt::ToolBarArea area,
+ bool newLine = false,
+ bool isMainToolBar = false,
+ bool readConfig = true);
+~BookmarkToolBar();
+
+virtual void setVisible(bool visible);
+
+protected:
+ bool eventFilter(QObject *watched, QEvent *event);
+ void dragEnterEvent(QDragEnterEvent *event);
+ void dragMoveEvent(QDragMoveEvent *event);
+ void dragLeaveEvent(QDragLeaveEvent *event);
+ void dropEvent(QDropEvent *event);
+ void actionEvent(QActionEvent *event);
+
+private slots:
+ void actionHovered();
+ void menuDisplayed();
+ void menuHidden();
+ void hideMenu();
+ void dragDestroyed();
+
+private:
+ void startDrag();
+
+ bool m_filled;
+ KMenu *m_currentMenu;
+ QPoint m_startDragPos;
+ QAction *m_dragAction;
+ QAction *m_dropAction;
+};
+
+#endif // BOOKMARKSTOOLBAR_H