diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2012-08-09 15:36:39 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2012-12-10 02:48:05 +0100 |
commit | b3526c84a15e91b05ee1ea0c6052be3fd73a6044 (patch) | |
tree | d587600753d9f22e36670f2ddf7a3808dc26ce94 | |
parent | Restore rekonq settings (diff) | |
download | rekonq-b3526c84a15e91b05ee1ea0c6052be3fd73a6044.tar.xz |
Moved the bookmark toolbar to be a... toolbar!!!
-rw-r--r-- | src/bookmarks/bookmarkmanager.cpp | 12 | ||||
-rw-r--r-- | src/bookmarks/bookmarkstoolbar.cpp | 100 | ||||
-rw-r--r-- | src/bookmarks/bookmarkstoolbar.h | 7 | ||||
-rw-r--r-- | src/webwindow/rekonqfactory.cpp | 105 | ||||
-rw-r--r-- | src/webwindow/rekonqfactory.h | 2 | ||||
-rw-r--r-- | src/webwindow/webwindow.cpp | 13 |
6 files changed, 147 insertions, 92 deletions
diff --git a/src/bookmarks/bookmarkmanager.cpp b/src/bookmarks/bookmarkmanager.cpp index 42a6ae40..7e1b5d90 100644 --- a/src/bookmarks/bookmarkmanager.cpp +++ b/src/bookmarks/bookmarkmanager.cpp @@ -161,7 +161,7 @@ void BookmarkManager::slotBookmarksChanged() { if (bookmarkToolBar) { - bookmarkToolBar->toolBar()->clear(); + bookmarkToolBar->clear(); fillBookmarkBar(bookmarkToolBar); } } @@ -189,19 +189,19 @@ void BookmarkManager::fillBookmarkBar(BookmarkToolBar *toolBar) connect(menuAction->menu(), SIGNAL(aboutToShow()), toolBar, SLOT(menuDisplayed())); connect(menuAction->menu(), SIGNAL(aboutToHide()), toolBar, SLOT(menuHidden())); - toolBar->toolBar()->addAction(menuAction); - toolBar->toolBar()->widgetForAction(menuAction)->installEventFilter(toolBar); + toolBar->addAction(menuAction); + toolBar->widgetForAction(menuAction)->installEventFilter(toolBar); } else if (bookmark.isSeparator()) { - toolBar->toolBar()->addSeparator(); + toolBar->addSeparator(); } else { KBookmarkAction *action = new KBookmarkAction(bookmark, m_owner, this); action->setIcon(IconManager::self()->iconForUrl(KUrl(bookmark.url()))); - toolBar->toolBar()->addAction(action); - toolBar->toolBar()->widgetForAction(action)->installEventFilter(toolBar); + toolBar->addAction(action); + toolBar->widgetForAction(action)->installEventFilter(toolBar); } } } diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp index 019c260e..2ecb0e35 100644 --- a/src/bookmarks/bookmarkstoolbar.cpp +++ b/src/bookmarks/bookmarkstoolbar.cpp @@ -145,23 +145,24 @@ void BookmarkMenu::addOpenFolderInTabs() // ------------------------------------------------------------------------------------------------------ -BookmarkToolBar::BookmarkToolBar(KToolBar *toolBar, QObject *parent) - : QObject(parent) - , m_toolBar(toolBar) +BookmarkToolBar::BookmarkToolBar(QWidget *parent) + : KToolBar(parent, false, false) , m_currentMenu(0) , m_dragAction(0) , m_dropAction(0) , m_checkedAction(0) , m_filled(false) { - toolBar->setContextMenuPolicy(Qt::CustomContextMenu); - connect(toolBar, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenu(QPoint))); + setContextMenuPolicy(Qt::CustomContextMenu); + + connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenu(QPoint))); connect(BookmarkManager::self()->manager(), SIGNAL(changed(QString, QString)), this, SLOT(hideMenu())); - toolBar->setAcceptDrops(true); - toolBar->installEventFilter(this); - toolBar->setShortcutEnabled(false); - if (toolBar->isVisible()) + setAcceptDrops(true); + installEventFilter(this); + setShortcutEnabled(false); + + if (isVisible()) { BookmarkManager::self()->fillBookmarkBar(this); m_filled = true; @@ -169,15 +170,9 @@ BookmarkToolBar::BookmarkToolBar(KToolBar *toolBar, QObject *parent) } -KToolBar* BookmarkToolBar::toolBar() -{ - return m_toolBar; -} - - void BookmarkToolBar::contextMenu(const QPoint &point) { - KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface*>(toolBar()->actionAt(point)); + KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface*>(actionAt(point)); KBookmark bookmark = BookmarkManager::self()->manager()->toolbar(); bool nullAction = true; if (action) @@ -190,7 +185,8 @@ void BookmarkToolBar::contextMenu(const QPoint &point) BookmarkManager::self()->manager(), BookmarkManager::self()->owner(), nullAction); - menu.exec(toolBar()->mapToGlobal(point)); + + menu.exec( mapToGlobal(point) ); } @@ -222,13 +218,13 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) { // To switch root folders as in a menubar - KBookmarkActionMenu* act = dynamic_cast<KBookmarkActionMenu *>(toolBar()->actionAt(toolBar()->mapFromGlobal(QCursor::pos()))); + KBookmarkActionMenu* act = dynamic_cast<KBookmarkActionMenu *>(actionAt(mapFromGlobal(QCursor::pos()))); if (event->type() == QEvent::MouseMove && act && act->menu() != m_currentMenu) { m_currentMenu->hide(); - QPoint pos = toolBar()->mapToGlobal(toolBar()->widgetForAction(act)->pos()); - act->menu()->popup(QPoint(pos.x(), pos.y() + toolBar()->widgetForAction(act)->height())); + QPoint pos = mapToGlobal(widgetForAction(act)->pos()); + act->menu()->popup(QPoint(pos.x(), pos.y() + widgetForAction(act)->height())); } else if (event->type() == QEvent::MouseButtonPress && act) { @@ -255,7 +251,7 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) QActionEvent *actionEvent = static_cast<QActionEvent*>(event); if (actionEvent && actionEvent->action() != m_dropAction) { - QWidget *widget = toolBar()->widgetForAction(actionEvent->action()); + QWidget *widget = widgetForAction(actionEvent->action()); if (widget) { widget->removeEventFilter(this); @@ -269,7 +265,7 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) QActionEvent *actionEvent = static_cast<QActionEvent*>(event); if (actionEvent && actionEvent->action() != m_dropAction) { - QWidget *widget = toolBar()->widgetForAction(actionEvent->action()); + QWidget *widget = widgetForAction(actionEvent->action()); if (widget) { widget->removeEventFilter(this); @@ -285,9 +281,9 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) || dragEvent->mimeData()->hasFormat("text/uri-list") || dragEvent->mimeData()->hasFormat("text/plain")) { - QFrame* dropIndicatorWidget = new QFrame(toolBar()); + QFrame* dropIndicatorWidget = new QFrame(this); dropIndicatorWidget->setFrameShape(QFrame::VLine); - m_dropAction = toolBar()->insertWidget(toolBar()->actionAt(dragEvent->pos()), dropIndicatorWidget); + m_dropAction = insertWidget(actionAt(dragEvent->pos()), dropIndicatorWidget); dragEvent->accept(); } @@ -317,13 +313,13 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) || dragEvent->mimeData()->hasFormat("text/uri-list") || dragEvent->mimeData()->hasFormat("text/plain")) { - QAction *overAction = toolBar()->actionAt(dragEvent->pos()); + QAction *overAction = actionAt(dragEvent->pos()); KBookmarkActionInterface *overActionBK = dynamic_cast<KBookmarkActionInterface*>(overAction); - QWidget *widgetAction = toolBar()->widgetForAction(overAction); + QWidget *widgetAction = widgetForAction(overAction); if (overAction != m_dropAction && overActionBK && widgetAction && m_dropAction) { - toolBar()->removeAction(m_dropAction); + removeAction(m_dropAction); if (m_checkedAction) { m_checkedAction->setCheckable(false); @@ -334,36 +330,36 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) { if ((dragEvent->pos().x() - widgetAction->pos().x()) > (widgetAction->width() / 2)) { - if (toolBar()->actions().count() > toolBar()->actions().indexOf(overAction) + 1) + if (actions().count() > actions().indexOf(overAction) + 1) { - toolBar()->insertAction(toolBar()->actions().at(toolBar()->actions().indexOf(overAction) + 1), m_dropAction); + insertAction(actions().at(actions().indexOf(overAction) + 1), m_dropAction); } else { - toolBar()->addAction(m_dropAction); + addAction(m_dropAction); } } else { - toolBar()->insertAction(overAction, m_dropAction); + insertAction(overAction, m_dropAction); } } else { if ((dragEvent->pos().x() - widgetAction->pos().x()) >= (widgetAction->width() * 0.75)) { - if (toolBar()->actions().count() > toolBar()->actions().indexOf(overAction) + 1) + if (actions().count() > actions().indexOf(overAction) + 1) { - toolBar()->insertAction(toolBar()->actions().at(toolBar()->actions().indexOf(overAction) + 1), m_dropAction); + insertAction(actions().at(actions().indexOf(overAction) + 1), m_dropAction); } else { - toolBar()->addAction(m_dropAction); + addAction(m_dropAction); } } else if ((dragEvent->pos().x() - widgetAction->pos().x()) <= (widgetAction->width() * 0.25)) { - toolBar()->insertAction(overAction, m_dropAction); + insertAction(overAction, m_dropAction); } else { @@ -428,23 +424,23 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) return false; } - QAction *destAction = toolBar()->actionAt(dropEvent->pos()); + QAction *destAction = actionAt(dropEvent->pos()); if (destAction && destAction == m_dropAction) { - if (toolBar()->actions().indexOf(m_dropAction) > 0) + if (actions().indexOf(m_dropAction) > 0) { - destAction = toolBar()->actions().at(toolBar()->actions().indexOf(m_dropAction) - 1); + destAction = actions().at(actions().indexOf(m_dropAction) - 1); } else { - destAction = toolBar()->actions().at(1); + destAction = actions().at(1); } } if (destAction) { KBookmarkActionInterface *destBookmarkAction = dynamic_cast<KBookmarkActionInterface *>(destAction); - QWidget *widgetAction = toolBar()->widgetForAction(destAction); + QWidget *widgetAction = widgetForAction(destAction); if (destBookmarkAction && !destBookmarkAction->bookmark().isNull() && widgetAction && bookmark.address() != destBookmarkAction->bookmark().address()) @@ -486,7 +482,7 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) { root.deleteBookmark(bookmark); bookmark = root.addBookmark(bookmark); - if (dropEvent->pos().x() < toolBar()->widgetForAction(toolBar()->actions().first())->pos().x()) + if (dropEvent->pos().x() < widgetForAction(actions().first())->pos().x()) { root.moveBookmark(bookmark, KBookmark()); } @@ -504,18 +500,18 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); // These events need to be handled only for Bookmark actions and not the bar - if (watched != toolBar() && mouseEvent) + if (watched != this && mouseEvent) { switch (event->type()) { case QEvent::MouseButtonPress: // drag handling { - QPoint pos = toolBar()->mapFromGlobal(QCursor::pos()); - KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(toolBar()->actionAt(pos)); + QPoint pos = mapFromGlobal(QCursor::pos()); + KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(actionAt(pos)); if (action && mouseEvent->button() != Qt::MidButton) { - m_dragAction = toolBar()->actionAt(pos); + m_dragAction = actionAt(pos); m_startDragPos = pos; // The menu is displayed only when the mouse button is released @@ -527,7 +523,7 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) case QEvent::MouseMove: { - int distance = (toolBar()->mapFromGlobal(QCursor::pos()) - m_startDragPos).manhattanLength(); + int distance = (mapFromGlobal(QCursor::pos()) - m_startDragPos).manhattanLength(); if (!m_currentMenu && distance >= QApplication::startDragDistance()) { startDrag(); @@ -537,9 +533,9 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) case QEvent::MouseButtonRelease: { - QPoint destPos = toolBar()->mapFromGlobal(QCursor::pos()); + QPoint destPos = mapFromGlobal(QCursor::pos()); int distance = (destPos - m_startDragPos).manhattanLength(); - KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(toolBar()->actionAt(destPos)); + KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(actionAt(destPos)); if (action && action->bookmark().isGroup()) { @@ -549,9 +545,9 @@ bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) } else if (distance < QApplication::startDragDistance()) { - KBookmarkActionMenu *menu = dynamic_cast<KBookmarkActionMenu *>(toolBar()->actionAt(m_startDragPos)); - QPoint actionPos = toolBar()->mapToGlobal(toolBar()->widgetForAction(menu)->pos()); - menu->menu()->popup(QPoint(actionPos.x(), actionPos.y() + toolBar()->widgetForAction(menu)->height())); + KBookmarkActionMenu *menu = dynamic_cast<KBookmarkActionMenu *>(actionAt(m_startDragPos)); + QPoint actionPos = mapToGlobal(widgetForAction(menu)->pos()); + menu->menu()->popup(QPoint(actionPos.x(), actionPos.y() + widgetForAction(menu)->height())); } } } @@ -578,7 +574,7 @@ void BookmarkToolBar::startDrag() mimeData->setData(BookmarkManager::bookmark_mime_type(), address); bookmark.populateMimeData(mimeData); - QDrag *drag = new QDrag(toolBar()); + QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); if (bookmark.isGroup()) diff --git a/src/bookmarks/bookmarkstoolbar.h b/src/bookmarks/bookmarkstoolbar.h index e2ed6e3a..97fd7a8f 100644 --- a/src/bookmarks/bookmarkstoolbar.h +++ b/src/bookmarks/bookmarkstoolbar.h @@ -77,14 +77,12 @@ private: * Some events from the toolbar are handled to allow the drag and drop */ -class BookmarkToolBar : public QObject +class BookmarkToolBar : public KToolBar { Q_OBJECT public: - BookmarkToolBar(KToolBar *toolBar, QObject *parent); - - KToolBar* toolBar(); + BookmarkToolBar(QWidget *parent); protected: bool eventFilter(QObject *watched, QEvent *event); @@ -99,7 +97,6 @@ private Q_SLOTS: private: void startDrag(); - KToolBar *m_toolBar; KMenu *m_currentMenu; QPoint m_startDragPos; QAction *m_dragAction; diff --git a/src/webwindow/rekonqfactory.cpp b/src/webwindow/rekonqfactory.cpp index e3f62f9f..c8aaeb09 100644 --- a/src/webwindow/rekonqfactory.cpp +++ b/src/webwindow/rekonqfactory.cpp @@ -26,6 +26,7 @@ #include "rekonqfactory.h" +#include "bookmarkstoolbar.h" #include "rekonqmenu.h" #include <KActionCollection> @@ -45,7 +46,6 @@ QWidget *RekonqFactory::createWidget(const QString &name, QWidget *parent, KActi { QString xmlFilePath; xmlFilePath = KStandardDirs::locateLocal( "data", "rekonq/rekonqui.rc"); - kDebug() << "local xmlfile: " << xmlFilePath; if (!QFile::exists(xmlFilePath)) { xmlFilePath = KStandardDirs::locate( "data", "rekonq/rekonqui.rc"); @@ -58,42 +58,46 @@ QWidget *RekonqFactory::createWidget(const QString &name, QWidget *parent, KActi document.setContent(&xmlFile, false); // Toolbars ---------------------------------------------------------------------- - QDomNodeList elementList = document.elementsByTagName(QL1S("ToolBar")); - if (elementList.isEmpty()) + QDomNodeList elementToolbarList = document.elementsByTagName(QL1S("ToolBar")); + if (elementToolbarList.isEmpty()) { + kDebug() << "ELEMENT TOOLBAR LIST EMPTY. RETURNING NULL"; return 0; } - for(unsigned int i = 0; i < elementList.length(); ++i) + for(unsigned int i = 0; i < elementToolbarList.length(); ++i) { - QDomElement element = elementList.at(i).toElement(); + QDomNode node = elementToolbarList.at(i); + QDomElement element = node.toElement(); if (element.attribute("name") != name) continue; if (element.attribute("deleted").toLower() == "true") { + kDebug() << "ELEMENT DELETED. RETURNING NULL"; return 0; } - KToolBar *bar = new KToolBar(parent, false, false); - QDomNodeList actionList = element.elementsByTagName(QL1S("Action")); - - for(unsigned int j = 0; j < actionList.length(); ++j) + + if (name == QL1S("bookmarkToolBar")) { - QDomElement actionElement = actionList.at(j).toElement(); - const QString actionName = actionElement.attribute("name"); - QAction *a = ac->action(actionName); - if (a) - bar->addAction(a); + BookmarkToolBar *b = new BookmarkToolBar(parent); + fillToolbar(b, node, ac); + return b; + } + else + { + KToolBar *b = new KToolBar(parent, false , false); + fillToolbar(b, node, ac); + return b; } - - return bar; } // Rekonq Menu ---------------------------------------------------------------------- QDomNodeList elementMenuList = document.elementsByTagName(QL1S("Menu")); if (elementMenuList.isEmpty()) { + kDebug() << "ELEMENT MENU LIST EMPTY. RETURNING NULL"; return 0; } @@ -106,13 +110,13 @@ QWidget *RekonqFactory::createWidget(const QString &name, QWidget *parent, KActi if (element.attribute("deleted").toLower() == "true") { + kDebug() << "ELEMENT DELETED. RETURNING NULL"; return 0; } if (name == QL1S("rekonqMenu")) { RekonqMenu *m = new RekonqMenu(parent); - kDebug() << "filling menu..."; fillMenu(m, node, ac); return m; } @@ -130,6 +134,70 @@ QWidget *RekonqFactory::createWidget(const QString &name, QWidget *parent, KActi } +void RekonqFactory::fillToolbar(KToolBar *b, QDomNode node, KActionCollection *ac) +{ + QDomElement element = node.toElement(); + + if (element.hasAttribute("iconSize")) + { + int iconSize = element.attribute("iconSize").toInt(); + b->setIconDimensions(iconSize); + } + + if (element.hasAttribute("iconText")) + { + if(element.attribute("iconText").toLower() == QL1S("icononly")) + { + b->setToolButtonStyle(Qt::ToolButtonIconOnly); + } + + if(element.attribute("iconText").toLower() == QL1S("textonly")) + { + b->setToolButtonStyle(Qt::ToolButtonTextOnly); + } + + if(element.attribute("iconText").toLower() == QL1S("icontextright")) + { + b->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + } + + if(element.attribute("iconText").toLower() == QL1S("textundericon")) + { + b->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + } + + if(element.attribute("iconText").toLower() == QL1S("followstyle")) + { + b->setToolButtonStyle(Qt::ToolButtonFollowStyle); + } + } + + QDomNodeList childrenList = node.childNodes(); + + for(unsigned int i = 0; i < childrenList.length(); ++i) + { + QDomElement el = childrenList.at(i).toElement(); + + if (el.tagName() == QL1S("Action")) + { + const QString actionName = el.attribute("name"); + QAction *a = ac->action(actionName); + if (a) + { + b->addAction(a); + } + + } + + if (el.tagName() == QL1S("Separator")) + { + b->addSeparator(); + } + + } +} + + void RekonqFactory::fillMenu(KMenu *m, QDomNode node, KActionCollection *ac) { QDomNodeList childrenList = node.childNodes(); @@ -144,10 +212,9 @@ void RekonqFactory::fillMenu(KMenu *m, QDomNode node, KActionCollection *ac) QAction *a = ac->action(actionName); if (a) { - kDebug() << "ADDING ACTION " << actionName << " to menu " << m; m->addAction(a); } - + } if (el.tagName() == QL1S("Separator")) diff --git a/src/webwindow/rekonqfactory.h b/src/webwindow/rekonqfactory.h index 6a59adcd..cf8bc2ee 100644 --- a/src/webwindow/rekonqfactory.h +++ b/src/webwindow/rekonqfactory.h @@ -32,6 +32,7 @@ class KActionCollection; class KMenu; +class KToolBar; class QDomNode; class QString; @@ -42,6 +43,7 @@ namespace RekonqFactory { QWidget *createWidget(const QString &name, QWidget *parent, KActionCollection *); + void fillToolbar(KToolBar *, QDomNode, KActionCollection *); void fillMenu(KMenu *, QDomNode, KActionCollection *); }; diff --git a/src/webwindow/webwindow.cpp b/src/webwindow/webwindow.cpp index 4d350d71..87006bf8 100644 --- a/src/webwindow/webwindow.cpp +++ b/src/webwindow/webwindow.cpp @@ -92,21 +92,14 @@ WebWindow::WebWindow(QWidget *parent, WebPage *pg) // main toolbar _mainToolBar = qobject_cast<KToolBar *>(RekonqFactory::createWidget(QL1S("mainToolBar"), this, actionCollection())); - - // bookmarks toolbar - if (_bookmarksBar) - { - BookmarkManager::self()->removeBookmarkBar(_bookmarksBar); - delete _bookmarksBar; - } - KToolBar *XMLGUIBkBar = new KToolBar(this); - _bookmarksBar = new BookmarkToolBar(XMLGUIBkBar, this); + + _bookmarksBar = qobject_cast<BookmarkToolBar *>(RekonqFactory::createWidget(QL1S("bookmarkToolBar"), this, actionCollection())); BookmarkManager::self()->registerBookmarkBar(_bookmarksBar); // layout QVBoxLayout *l = new QVBoxLayout(this); l->addWidget(_mainToolBar); - l->addWidget(XMLGUIBkBar); + l->addWidget(_bookmarksBar); l->addWidget(_tab); l->setContentsMargins(0, 0, 0, 0); |