summaryrefslogtreecommitdiff
path: root/src/bookmarks/bookmarkstoolbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bookmarks/bookmarkstoolbar.cpp')
-rw-r--r--src/bookmarks/bookmarkstoolbar.cpp336
1 files changed, 167 insertions, 169 deletions
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