summaryrefslogtreecommitdiff
path: root/src/bookmarks
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-08-20 19:15:23 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-08-20 19:15:23 +0200
commit52bf222bf033f6bbcd15cfe2012a51a194d475d8 (patch)
treed2e839ccbdf38c930d145d4d8dd23897bbc43666 /src/bookmarks
parentKrazy fixes, first bunch (diff)
parent- The bookmark toolbar is now a real toolbar, not an action. (diff)
downloadrekonq-52bf222bf033f6bbcd15cfe2012a51a194d475d8.tar.xz
Merge commit 'refs/merge-requests/181' of git://gitorious.org/rekonq/mainline into m181
Conflicts: src/bookmarks/bookmarkstoolbar.h
Diffstat (limited to 'src/bookmarks')
-rw-r--r--src/bookmarks/bookmarkowner.cpp48
-rw-r--r--src/bookmarks/bookmarkowner.h28
-rw-r--r--src/bookmarks/bookmarkscontextmenu.cpp2
-rw-r--r--src/bookmarks/bookmarksmanager.cpp27
-rw-r--r--src/bookmarks/bookmarksmanager.h4
-rw-r--r--src/bookmarks/bookmarkspanel.cpp3
-rw-r--r--src/bookmarks/bookmarkstoolbar.cpp336
-rw-r--r--src/bookmarks/bookmarkstoolbar.h25
8 files changed, 231 insertions, 242 deletions
diff --git a/src/bookmarks/bookmarkowner.cpp b/src/bookmarks/bookmarkowner.cpp
index 09d615d1..d9df6e82 100644
--- a/src/bookmarks/bookmarkowner.cpp
+++ b/src/bookmarks/bookmarkowner.cpp
@@ -49,7 +49,7 @@ BookmarkOwner::BookmarkOwner(KBookmarkManager *manager, QObject *parent)
: QObject(parent)
, KBookmarkOwner()
, m_manager(manager)
- , actions(QVector<KAction*>(NUM_ACTIONS))
+ , m_actions(QVector<KAction*>(NUM_ACTIONS))
{
setupActions();
}
@@ -57,7 +57,7 @@ BookmarkOwner::BookmarkOwner(KBookmarkManager *manager, QObject *parent)
KAction* BookmarkOwner::action(const BookmarkAction &bmAction)
{
- return static_cast<KAction*>(actions.at(bmAction));
+ return static_cast<KAction*>(m_actions.at(bmAction));
}
@@ -101,51 +101,53 @@ void BookmarkOwner::openBookmark(const KBookmark &bookmark,
Qt::MouseButtons mouseButtons,
Qt::KeyboardModifiers keyboardModifiers)
{
- bookmarkSelected(bookmark);
if (keyboardModifiers & Qt::ControlModifier || mouseButtons & Qt::MidButton)
{
- openBookmarkInNewTab();
+ openBookmarkInNewTab(bookmark);
}
else
{
- openBookmark();
+ openBookmark(bookmark);
}
}
void BookmarkOwner::openFolderinTabs(const KBookmarkGroup &bookmark)
{
- bookmarkSelected(bookmark);
- openBookmarkFolder();
+ openBookmarkFolder(bookmark);
}
-void BookmarkOwner::bookmarkSelected(const KBookmark &bookmark)
+void BookmarkOwner::setCurrentBookmark(const KBookmark &bookmark)
{
- selected = bookmark;
+ m_currentBookmark = bookmark;
}
-void BookmarkOwner::openBookmark()
+void BookmarkOwner::openBookmark(const KBookmark &bookmark)
{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
emit openUrl(selected.url(), Rekonq::CurrentTab);
}
-void BookmarkOwner::openBookmarkInNewTab()
+void BookmarkOwner::openBookmarkInNewTab(const KBookmark &bookmark)
{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
emit openUrl(selected.url(), Rekonq::NewTab);
}
-void BookmarkOwner::openBookmarkInNewWindow()
+void BookmarkOwner::openBookmarkInNewWindow(const KBookmark &bookmark)
{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
emit openUrl(selected.url(), Rekonq::NewWindow);
}
-void BookmarkOwner::openBookmarkFolder()
+void BookmarkOwner::openBookmarkFolder(const KBookmark &bookmark)
{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
if (!selected.isGroup())
return;
@@ -168,8 +170,9 @@ void BookmarkOwner::openBookmarkFolder()
}
-void BookmarkOwner::bookmarkCurrentPage()
+void BookmarkOwner::bookmarkCurrentPage(const KBookmark &bookmark)
{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
KBookmarkGroup parent;
if (!selected.isNull())
@@ -192,8 +195,9 @@ void BookmarkOwner::bookmarkCurrentPage()
}
-void BookmarkOwner::newBookmarkFolder()
+void BookmarkOwner::newBookmarkFolder(const KBookmark &bookmark)
{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
KBookmarkDialog *dialog = bookmarkDialog(m_manager, QApplication::activeWindow());
QString folderName = i18n("New folder");
@@ -223,8 +227,9 @@ void BookmarkOwner::newBookmarkFolder()
}
-void BookmarkOwner::newSeparator()
+void BookmarkOwner::newSeparator(const KBookmark &bookmark)
{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
KBookmark newBk;
if (!selected.isNull())
@@ -250,8 +255,9 @@ void BookmarkOwner::newSeparator()
}
-void BookmarkOwner::copyLink()
+void BookmarkOwner::copyLink(const KBookmark &bookmark)
{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
if (selected.isNull())
return;
@@ -259,8 +265,9 @@ void BookmarkOwner::copyLink()
}
-void BookmarkOwner::editBookmark()
+void BookmarkOwner::editBookmark(KBookmark bookmark)
{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
if (selected.isNull())
return;
@@ -274,8 +281,9 @@ void BookmarkOwner::editBookmark()
}
-bool BookmarkOwner::deleteBookmark()
+bool BookmarkOwner::deleteBookmark(KBookmark bookmark)
{
+ KBookmark selected = bookmark.isNull() ? m_currentBookmark : bookmark;
if (selected.isNull())
return false;
@@ -346,6 +354,6 @@ void BookmarkOwner::createAction(const BookmarkAction &action, const QString &te
{
KAction *act = new KAction(KIcon(icon), text, this);
act->setHelpText(help);
- actions[action] = act;
+ m_actions[action] = act;
connect(act, SIGNAL(triggered()), this, slot);
}
diff --git a/src/bookmarks/bookmarkowner.h b/src/bookmarks/bookmarkowner.h
index abb65c36..e0c2a8ad 100644
--- a/src/bookmarks/bookmarkowner.h
+++ b/src/bookmarks/bookmarkowner.h
@@ -119,24 +119,24 @@ signals:
void openUrl(const KUrl &, const Rekonq::OpenType &);
public slots:
- void bookmarkSelected(const KBookmark &bookmark);
-
- void openBookmark();
- void openBookmarkInNewTab();
- void openBookmarkInNewWindow();
- void openBookmarkFolder();
- void bookmarkCurrentPage();
- void newBookmarkFolder();
- void newSeparator();
- void copyLink();
- void editBookmark();
- bool deleteBookmark();
+ void setCurrentBookmark(const KBookmark &bookmark);
+
+ void openBookmark(const KBookmark &bookmark = KBookmark());
+ void openBookmarkInNewTab(const KBookmark &bookmark = KBookmark());
+ void openBookmarkInNewWindow(const KBookmark &bookmark = KBookmark());
+ void openBookmarkFolder(const KBookmark &bookmark = KBookmark());
+ void bookmarkCurrentPage(const KBookmark &bookmark = KBookmark());
+ void newBookmarkFolder(const KBookmark &bookmark = KBookmark());
+ void newSeparator(const KBookmark &bookmark = KBookmark());
+ void copyLink(const KBookmark &bookmark = KBookmark());
+ void editBookmark(KBookmark bookmark = KBookmark());
+ bool deleteBookmark(KBookmark bookmark = KBookmark());
private:
KBookmarkManager *m_manager;
- QVector<KAction*> actions;
- KBookmark selected;
+ QVector<KAction*> m_actions;
+ KBookmark m_currentBookmark;
void setupActions();
void createAction(const BookmarkAction &action,
diff --git a/src/bookmarks/bookmarkscontextmenu.cpp b/src/bookmarks/bookmarkscontextmenu.cpp
index 45b7f563..a473966a 100644
--- a/src/bookmarks/bookmarkscontextmenu.cpp
+++ b/src/bookmarks/bookmarkscontextmenu.cpp
@@ -35,7 +35,7 @@ BookmarksContextMenu::BookmarksContextMenu(const KBookmark &bookmark, KBookmarkM
: KBookmarkContextMenu(bookmark, manager, owner, parent)
, bmOwner(owner)
{
- bmOwner->bookmarkSelected(bookmark);
+ bmOwner->setCurrentBookmark(bookmark);
}
diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarksmanager.cpp
index e68751c0..ea7b313d 100644
--- a/src/bookmarks/bookmarksmanager.cpp
+++ b/src/bookmarks/bookmarksmanager.cpp
@@ -95,7 +95,7 @@ BookmarkProvider::~BookmarkProvider()
}
-void BookmarkProvider::setupBookmarkBar(BookmarkToolBar *toolbar)
+void BookmarkProvider::registerBookmarkBar(BookmarkToolBar *toolbar)
{
if (m_bookmarkToolBars.contains(toolbar))
return;
@@ -103,8 +103,8 @@ void BookmarkProvider::setupBookmarkBar(BookmarkToolBar *toolbar)
kDebug() << "new bookmark bar...";
m_bookmarkToolBars.append(toolbar);
- toolbar->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(toolbar, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenu(const QPoint &)));
+ toolbar->toolBar()->setContextMenuPolicy(Qt::CustomContextMenu);
+ connect(toolbar->toolBar(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenu(const QPoint &)));
kDebug() << "new bookmark bar... DONE!";
}
@@ -125,7 +125,7 @@ void BookmarkProvider::slotBookmarksChanged(const QString &group, const QString
{
if (bookmarkToolBar)
{
- bookmarkToolBar->clear();
+ bookmarkToolBar->toolBar()->clear();
fillBookmarkBar(bookmarkToolBar);
}
}
@@ -146,7 +146,7 @@ void BookmarkProvider::contextMenu(const QPoint &point)
if (m_bookmarkToolBars.isEmpty())
return;
- KToolBar *bookmarkToolBar = m_bookmarkToolBars.at(0);
+ KToolBar *bookmarkToolBar = m_bookmarkToolBars.at(0)->toolBar();
if (!bookmarkToolBar)
return;
@@ -174,16 +174,6 @@ KActionMenu* BookmarkProvider::bookmarkActionMenu(QWidget *parent)
}
-KAction* BookmarkProvider::bookmarkToolBarAction(KToolBar *t)
-{
- KAction *bookmarkToolBarAction = new KAction(this);
- bookmarkToolBarAction->setDefaultWidget(t); // The ownership is transferred to action
- bookmarkToolBarAction->setText(i18n("Bookmarks Bar"));
- bookmarkToolBarAction->setShortcutConfigurable(false);
- return bookmarkToolBarAction;
-}
-
-
void BookmarkProvider::fillBookmarkBar(BookmarkToolBar *toolBar)
{
KBookmarkGroup root = m_manager->toolbar();
@@ -199,12 +189,12 @@ void BookmarkProvider::fillBookmarkBar(BookmarkToolBar *toolBar)
new BookmarkMenu(bookmarkManager(), bookmarkOwner(), menuAction->menu(), bookmark.address());
connect(menuAction->menu(), SIGNAL(aboutToShow()), toolBar, SLOT(menuDisplayed()));
connect(menuAction->menu(), SIGNAL(aboutToHide()), toolBar, SLOT(menuHidden()));
- toolBar->addAction(menuAction);
+ toolBar->toolBar()->addAction(menuAction);
}
else if (bookmark.isSeparator())
{
- toolBar->addSeparator();
+ toolBar->toolBar()->addSeparator();
}
else
@@ -212,7 +202,8 @@ void BookmarkProvider::fillBookmarkBar(BookmarkToolBar *toolBar)
KBookmarkAction* action = new KBookmarkAction(bookmark, m_owner, this);
action->setIconText(action->iconText().replace('&', "&&"));
connect(action, SIGNAL(hovered()), toolBar, SLOT(actionHovered()));
- toolBar->addAction(action);
+ toolBar->toolBar()->addAction(action);
+ toolBar->toolBar()->widgetForAction(action)->installEventFilter(toolBar);
}
}
}
diff --git a/src/bookmarks/bookmarksmanager.h b/src/bookmarks/bookmarksmanager.h
index 49073b2a..0c2b9ee2 100644
--- a/src/bookmarks/bookmarksmanager.h
+++ b/src/bookmarks/bookmarksmanager.h
@@ -74,12 +74,10 @@ public:
*/
KActionMenu *bookmarkActionMenu(QWidget *parent);
- KAction *bookmarkToolBarAction(KToolBar *t);
-
/**
* @short set the Bookmarks Toolbar Action
*/
- void setupBookmarkBar(BookmarkToolBar *);
+ void registerBookmarkBar(BookmarkToolBar *);
void removeToolBar(BookmarkToolBar *);
diff --git a/src/bookmarks/bookmarkspanel.cpp b/src/bookmarks/bookmarkspanel.cpp
index 22701baa..1b561515 100644
--- a/src/bookmarks/bookmarkspanel.cpp
+++ b/src/bookmarks/bookmarkspanel.cpp
@@ -105,8 +105,7 @@ void BookmarksPanel::deleteBookmark()
if (m_loadingState || !index.isValid())
return;
- Application::bookmarkProvider()->bookmarkOwner()->bookmarkSelected(bookmarkForIndex(index));
- Application::bookmarkProvider()->bookmarkOwner()->deleteBookmark();
+ Application::bookmarkProvider()->bookmarkOwner()->deleteBookmark(bookmarkForIndex(index));
}
diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp
index 3f103104..bce2bd1e 100644
--- a/src/bookmarks/bookmarkstoolbar.cpp
+++ b/src/bookmarks/bookmarkstoolbar.cpp
@@ -38,6 +38,7 @@
// Qt Includes
#include <QtGui/QFrame>
+#include <QActionEvent>
BookmarkMenu::BookmarkMenu(KBookmarkManager *manager,
@@ -156,23 +157,24 @@ void BookmarkMenu::actionHovered()
// ------------------------------------------------------------------------------------------------------
-#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)
+BookmarkToolBar::BookmarkToolBar(KToolBar *toolBar, QObject *parent)
+ : QObject(parent)
+ , m_toolBar(toolBar)
, m_currentMenu(0)
, m_dragAction(0)
, m_dropAction(0)
+ , m_filled(false)
{
connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(QString, QString)), this, SLOT(hideMenu()));
- setAcceptDrops(true);
+ toolBar->setAcceptDrops(true);
+ toolBar->installEventFilter(this);
+
+ if (toolBar->isVisible())
+ {
+ Application::bookmarkProvider()->fillBookmarkBar(this);
+ m_filled = true;
+ }
}
@@ -181,14 +183,9 @@ BookmarkToolBar::~BookmarkToolBar()
}
-void BookmarkToolBar::setVisible(bool visible)
+KToolBar* BookmarkToolBar::toolBar()
{
- if (visible && !m_filled)
- {
- m_filled = true;
- Application::bookmarkProvider()->fillBookmarkBar(this);
- }
- KToolBar::setVisible(visible);
+ return m_toolBar;
}
@@ -215,42 +212,183 @@ void BookmarkToolBar::hideMenu()
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())));
+ KBookmarkActionMenu* act = dynamic_cast<KBookmarkActionMenu *>(toolBar()->actionAt(toolBar()->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()));
+ QPoint pos = toolBar()->mapToGlobal(toolBar()->widgetForAction(act)->pos());
+ act->menu()->popup(QPoint(pos.x(), pos.y() + toolBar()->widgetForAction(act)->height()));
+ }
+ }
+ else if (watched == toolBar())
+ {
+ if (event->type() == QEvent::Show)
+ {
+ if (!m_filled)
+ {
+ Application::bookmarkProvider()->fillBookmarkBar(this);
+ m_filled = true;
+ }
+ }
+ if (event->type() == QEvent::ActionRemoved)
+ {
+ QActionEvent *actionEvent = static_cast<QActionEvent*>(event);
+ if (actionEvent && actionEvent->action() != m_dropAction)
+ {
+ QWidget *widget = toolBar()->widgetForAction(actionEvent->action());
+ if (widget)
+ {
+ widget->removeEventFilter(this);
+ }
+ }
+ }
+ else if (event->type() == QEvent::ParentChange)
+ {
+ QActionEvent *actionEvent = static_cast<QActionEvent*>(event);
+ if (actionEvent && actionEvent->action() != m_dropAction)
+ {
+ QWidget *widget = toolBar()->widgetForAction(actionEvent->action());
+ if (widget)
+ {
+ widget->removeEventFilter(this);
+ }
+ }
+ }
+ else if (event->type() == QEvent::DragEnter)
+ {
+ QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent*>(event);
+ if (dragEvent->mimeData()->hasFormat("application/rekonq-bookmark"))
+ {
+ QByteArray addresses = dragEvent->mimeData()->data("application/rekonq-bookmark");
+ KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data()));
+
+ if (!bookmark.isNull())
+ {
+ QFrame* dropIndicatorWidget = new QFrame(toolBar());
+ dropIndicatorWidget->setFrameShape(QFrame::VLine);
+ m_dropAction = toolBar()->insertWidget(toolBar()->actionAt(dragEvent->pos()), dropIndicatorWidget);
+
+ dragEvent->accept();
+ }
+ }
+ }
+ else if (event->type() == QEvent::DragMove)
+ {
+ QDragMoveEvent *dragEvent = static_cast<QDragMoveEvent*>(event);
+ if (dragEvent->mimeData()->hasFormat("application/rekonq-bookmark"))
+ {
+ QByteArray addresses = dragEvent->mimeData()->data("application/rekonq-bookmark");
+ KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data()));
+ QAction *overAction = toolBar()->actionAt(dragEvent->pos());
+ KBookmarkActionInterface *overActionBK = dynamic_cast<KBookmarkActionInterface*>(overAction);
+ QWidget *widgetAction = toolBar()->widgetForAction(overAction);
+
+ if (!bookmark.isNull() && overAction != m_dropAction && overActionBK && widgetAction && m_dropAction)
+ {
+ toolBar()->removeAction(m_dropAction);
+
+ if ((dragEvent->pos().x() - widgetAction->pos().x()) > (widgetAction->width() / 2))
+ {
+ if (toolBar()->actions().count() > toolBar()->actions().indexOf(overAction) + 1)
+ {
+ toolBar()->insertAction(toolBar()->actions().at(toolBar()->actions().indexOf(overAction) + 1), m_dropAction);
+ }
+ else
+ {
+ toolBar()->addAction(m_dropAction);
+ }
+ }
+ else
+ {
+ toolBar()->insertAction(overAction, m_dropAction);
+ }
+
+ dragEvent->accept();
+ }
+ }
+ }
+ else if (event->type() == QEvent::DragLeave)
+ {
+ QDragLeaveEvent *dragEvent = static_cast<QDragLeaveEvent*>(event);
+ delete m_dropAction;
+ m_dropAction = 0;
+ dragEvent->accept();
+ }
+ else if (event->type() == QEvent::Drop)
+ {
+ QDropEvent *dropEvent = static_cast<QDropEvent*>(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()));
+
+ QAction *destAction = toolBar()->actionAt(dropEvent->pos());
+ if (destAction && destAction == m_dropAction)
+ {
+ if (toolBar()->actions().indexOf(m_dropAction) > 0)
+ {
+ destAction = toolBar()->actions().at(toolBar()->actions().indexOf(m_dropAction) - 1);
+ }
+ else
+ {
+ destAction = toolBar()->actions().at(1);
+ }
+ }
+
+ KBookmarkActionInterface *destBookmarkAction = dynamic_cast<KBookmarkActionInterface *>(destAction);
+ QWidget *widgetAction = toolBar()->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 ((dropEvent->pos().x() - widgetAction->pos().x()) > (widgetAction->width() / 2))
+ {
+ root.moveBookmark(bookmark, destBookmark);
+ }
+ else
+ {
+ root.moveBookmark(bookmark, destBookmark.parentGroup().previous(destBookmark));
+ }
+
+ Application::bookmarkProvider()->bookmarkManager()->emitChanged();
+ dropEvent->accept();
+ }
+ }
}
}
else
{
// Drag handling
if (event->type() == QEvent::MouseButtonPress)
- {
- QPoint pos = mapFromGlobal(QCursor::pos());
- KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(actionAt(pos));
+ {//QMessageBox::information(NULL, "", "");
+ QPoint pos = toolBar()->mapFromGlobal(QCursor::pos());
+ KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(toolBar()->actionAt(pos));
if (action && !action->bookmark().isGroup())
{
- m_dragAction = actionAt(pos);
+ m_dragAction = toolBar()->actionAt(pos);
m_startDragPos = pos;
}
}
else if (event->type() == QEvent::MouseMove)
{
- int distance = (mapFromGlobal(QCursor::pos()) - m_startDragPos).manhattanLength();
+ int distance = (toolBar()->mapFromGlobal(QCursor::pos()) - m_startDragPos).manhattanLength();
if (distance >= QApplication::startDragDistance())
{
startDrag();
}
}
}
- return KToolBar::eventFilter(watched, event);
+
+ return QObject::eventFilter(watched, event);
}
@@ -262,29 +400,6 @@ void BookmarkToolBar::actionHovered()
}
-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);
@@ -296,7 +411,7 @@ void BookmarkToolBar::startDrag()
mimeData->setData("application/rekonq-bookmark", address);
action->bookmark().populateMimeData(mimeData);
- QDrag *drag = new QDrag(this);
+ QDrag *drag = new QDrag(toolBar());
drag->setMimeData(mimeData);
drag->setPixmap(KIcon(action->bookmark().icon()).pixmap(24, 24));
@@ -306,123 +421,6 @@ void BookmarkToolBar::startDrag()
}
-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
diff --git a/src/bookmarks/bookmarkstoolbar.h b/src/bookmarks/bookmarkstoolbar.h
index 92a56749..54a430e3 100644
--- a/src/bookmarks/bookmarkstoolbar.h
+++ b/src/bookmarks/bookmarkstoolbar.h
@@ -31,7 +31,6 @@
// KDE Includes
#include <KBookmarkMenu>
-
/**
* This class represent the rekonq bookmarks menu.
* It's just a simple class inherited from KBookmarkMenu
@@ -73,28 +72,23 @@ private:
#include <KToolBar>
-class BookmarkToolBar : public KToolBar
+/**
+ * This class manage the bookmark toolbar.
+ * Some events from the toolbar are handled to allow the drag and drop
+ */
+
+class BookmarkToolBar : public QObject
{
Q_OBJECT
public:
-BookmarkToolBar(const QString &objectName,
- QMainWindow *parentWindow,
- Qt::ToolBarArea area,
- bool newLine = false,
- bool isMainToolBar = false,
- bool readConfig = true);
+BookmarkToolBar(KToolBar *toolBar, QObject *parent);
~BookmarkToolBar();
-virtual void setVisible(bool visible);
+KToolBar* toolBar();
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();
@@ -106,11 +100,12 @@ private slots:
private:
void startDrag();
- bool m_filled;
+ KToolBar *m_toolBar;
KMenu *m_currentMenu;
QPoint m_startDragPos;
QAction *m_dragAction;
QAction *m_dropAction;
+ bool m_filled;
};
#endif // BOOKMARKSTOOLBAR_H