From 79ad6230fd3a99e13ed5ee18cba10c90cff3ee5c Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Fri, 20 Aug 2010 15:30:03 +0200 Subject: - The bookmark toolbar is now a real toolbar, not an action. It fixes the problem of the submenu if there are too much items to fit on the bar - Improve a bit the new redesign of BookmarkOwner - Reenable the bookmark menu by default (because the icon in the bar is on the left) --- src/bookmarks/bookmarkowner.cpp | 48 +++-- src/bookmarks/bookmarkowner.h | 28 +-- src/bookmarks/bookmarkscontextmenu.cpp | 2 +- src/bookmarks/bookmarksmanager.cpp | 27 +-- src/bookmarks/bookmarksmanager.h | 4 +- src/bookmarks/bookmarkspanel.cpp | 3 +- src/bookmarks/bookmarkstoolbar.cpp | 336 ++++++++++++++++----------------- src/bookmarks/bookmarkstoolbar.h | 30 +-- src/mainwindow.cpp | 40 +++- src/mainwindow.h | 5 +- src/rekonqui.rc | 6 +- src/urlbar/bookmarkwidget.cpp | 3 +- 12 files changed, 270 insertions(+), 262 deletions(-) (limited to 'src') diff --git a/src/bookmarks/bookmarkowner.cpp b/src/bookmarks/bookmarkowner.cpp index fb7c737e..f47b978d 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(NUM_ACTIONS)) + , m_actions(QVector(NUM_ACTIONS)) { setupActions(); } @@ -57,7 +57,7 @@ BookmarkOwner::BookmarkOwner(KBookmarkManager *manager, QObject *parent) KAction* BookmarkOwner::action(const BookmarkAction &bmAction) { - return static_cast(actions.at(bmAction)); + return static_cast(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 actions; - KBookmark selected; + QVector 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 0c3284bb..dc545698 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 +#include BookmarkMenu::BookmarkMenu(KBookmarkManager *manager, @@ -156,23 +157,24 @@ void BookmarkMenu::actionHovered() // ------------------------------------------------------------------------------------------------------ -#include -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(this->actionAt(this->mapFromGlobal(QCursor::pos()))); + KBookmarkActionMenu* act = dynamic_cast(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(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(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(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(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(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(event); + delete m_dropAction; + m_dropAction = 0; + dragEvent->accept(); + } + else if (event->type() == QEvent::Drop) + { + QDropEvent *dropEvent = static_cast(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(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(actionAt(pos)); + {//QMessageBox::information(NULL, "", ""); + QPoint pos = toolBar()->mapFromGlobal(QCursor::pos()); + KBookmarkActionInterface* action = dynamic_cast(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(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(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(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 cf7b62cc..5991a032 100644 --- a/src/bookmarks/bookmarkstoolbar.h +++ b/src/bookmarks/bookmarkstoolbar.h @@ -27,18 +27,12 @@ #ifndef BOOKMARKSTOOLBAR_H #define BOOKMARKSTOOLBAR_H -// Local Includes - - -// Qt Includes - // KDE Includes #include #include - /** * This class represent the rekonq bookmarks menu. * It's just a simple class inherited from KBookmarkMenu @@ -75,30 +69,23 @@ private: // ------------------------------------------------------------------------------ -#include +/** + * This class manage the bookmark toolbar. + * Some events from the toolbar are handled to allow the drag and drop + */ -class BookmarkToolBar : public KToolBar +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(); @@ -110,11 +97,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 diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1479e477..f0cb5e61 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -106,7 +107,7 @@ MainWindow::MainWindow() , m_analyzerPanel(0) , m_historyBackMenu(0) , m_encodingMenu(new KMenu(this)) - , m_bookmarksBar(new BookmarkToolBar(QString("BookmarkToolBar"), this, Qt::TopToolBarArea, true, false, true)) + , m_bookmarksBar(0) , m_popup(new KPassivePopup(this)) , m_hidePopup(new QTimer(this)) { @@ -198,15 +199,35 @@ void MainWindow::setupToolbars() KToolBar *mainBar = toolBar("mainToolBar"); - // bookmarks bar - KAction *bookmarkBarAction = Application::bookmarkProvider()->bookmarkToolBarAction(m_bookmarksBar); - a = actionCollection()->addAction( QL1S("bookmarks_bar"), bookmarkBarAction); - mainBar->show(); // this just to fix reopening rekonq after fullscreen close +} + + +void MainWindow::initBookmarkBar() +{ + KToolBar *XMLGUIBkBar = toolBar("bookmarkToolBar"); + if (!XMLGUIBkBar) + return; + + if (m_bookmarksBar) + { + Application::bookmarkProvider()->removeToolBar(m_bookmarksBar); + delete m_bookmarksBar; + } + m_bookmarksBar = new BookmarkToolBar(XMLGUIBkBar, this); + Application::bookmarkProvider()->registerBookmarkBar(m_bookmarksBar); +} + - // =========== Bookmarks ToolBar ================================ - m_bookmarksBar->setAcceptDrops(true); - Application::bookmarkProvider()->setupBookmarkBar(m_bookmarksBar); +void MainWindow::configureToolbars() +{ + if (autoSaveSettings()) + saveAutoSaveSettings(); + + KEditToolBar dlg(factory(), this); + // The bookmark bar needs to be refill after the UI changes are finished + connect(&dlg, SIGNAL(newToolBarConfig()), this, SLOT(initBookmarkBar())); + dlg.exec(); } @@ -253,6 +274,9 @@ void MainWindow::postLaunch() // accept d'n'd setAcceptDrops(true); + + // Bookmark ToolBar (needs to be setup after the call to setupGUI()) + initBookmarkBar(); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 50c73b4b..6ae99b5e 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -104,6 +104,8 @@ public slots: void updateActions(); + virtual void configureToolbars(); + signals: // switching tabs void ctrlTabPressed(); @@ -163,6 +165,8 @@ private slots: void populateEncodingMenu(); void enableNetworkAnalysis(bool); + + void initBookmarkBar(); private: MainView *m_view; @@ -187,4 +191,3 @@ private: }; #endif // MAINWINDOW_H - \ No newline at end of file diff --git a/src/rekonqui.rc b/src/rekonqui.rc index e89e3b15..8b9a51cb 100644 --- a/src/rekonqui.rc +++ b/src/rekonqui.rc @@ -88,13 +88,13 @@ + -