diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2012-11-11 09:40:36 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2012-12-10 02:48:06 +0100 |
commit | 4f1dae7834becb7d7105a0cc9945d9a0c04383b8 (patch) | |
tree | be823d81fe7ab1cc199b11bc5b32823d3cc9bdf7 /src/webwindow | |
parent | Clean up previous commit about adblock and fix enable/disable feature (diff) | |
download | rekonq-4f1dae7834becb7d7105a0cc9945d9a0c04383b8.tar.xz |
WARNING: BIG COMMIT
This commit reviews and partially fix the Q/K action mess
in rekonq code.
We now store actions in different actioncollections
(one for each tab && one for each window).
Related to this code review, you can find also fixes for
some triggered actions NOT working (well) before:
- fullscreen
- bookmark all tabs
- new (clean) tab
Diffstat (limited to 'src/webwindow')
-rw-r--r-- | src/webwindow/rekonqfactory.cpp | 41 | ||||
-rw-r--r-- | src/webwindow/rekonqfactory.h | 8 | ||||
-rw-r--r-- | src/webwindow/webwindow.cpp | 34 |
3 files changed, 47 insertions, 36 deletions
diff --git a/src/webwindow/rekonqfactory.cpp b/src/webwindow/rekonqfactory.cpp index 163935a3..9de9e367 100644 --- a/src/webwindow/rekonqfactory.cpp +++ b/src/webwindow/rekonqfactory.cpp @@ -68,10 +68,30 @@ bool readDocument(QDomDocument & document, const QString & filePath) } +// Only used internally +QAction *actionByName(const QString &name) +{ + QList<KActionCollection *> lac = KActionCollection::allCollections(); + + // NOTE: last action collection created is surely the one interests us more! + // So let's start from the end... + int lac_count = lac.count(); + for(int i = lac_count - 1; i>=0; i--) + { + KActionCollection *ac = lac.at(i); + QAction *a = ac->action(name); + if (a) + return a; + } + + kDebug() << "NO ACTION FOUND: " << name; + return 0; +} + // --------------------------------------------------------------------------------------------------------- -QWidget *RekonqFactory::createWidget(const QString &name, QWidget *parent, KActionCollection *ac) +QWidget *RekonqFactory::createWidget(const QString &name, QWidget *parent) { QDomDocument document("rekonqui.rc"); QString xmlFilePath = KStandardDirs::locate("data", "rekonq/rekonqui.rc"); @@ -104,13 +124,13 @@ QWidget *RekonqFactory::createWidget(const QString &name, QWidget *parent, KActi if (name == QL1S("bookmarkToolBar")) { BookmarkToolBar *b = new BookmarkToolBar(parent); - fillToolbar(b, node, ac); + fillToolbar(b, node); return b; } else { KToolBar *b = new KToolBar(parent, false , false); - fillToolbar(b, node, ac); + fillToolbar(b, node); return b; } } @@ -139,7 +159,7 @@ QWidget *RekonqFactory::createWidget(const QString &name, QWidget *parent, KActi if (name == QL1S("rekonqMenu")) { RekonqMenu *m = new RekonqMenu(parent); - fillMenu(m, node, ac); + fillMenu(m, node); return m; } else if (name == QL1S("help")) @@ -150,7 +170,7 @@ QWidget *RekonqFactory::createWidget(const QString &name, QWidget *parent, KActi else { KMenu *m = new KMenu(parent); - fillMenu(m, node, ac); + fillMenu(m, node); return m; } @@ -161,7 +181,7 @@ QWidget *RekonqFactory::createWidget(const QString &name, QWidget *parent, KActi } -void RekonqFactory::fillToolbar(KToolBar *b, QDomNode node, KActionCollection *ac) +void RekonqFactory::fillToolbar(KToolBar *b, QDomNode node) { QDomElement element = node.toElement(); @@ -208,7 +228,7 @@ void RekonqFactory::fillToolbar(KToolBar *b, QDomNode node, KActionCollection *a if (el.tagName() == QL1S("Action")) { const QString actionName = el.attribute("name"); - QAction *a = ac->action(actionName); + QAction *a = actionByName(actionName); if (a) { b->addAction(a); @@ -225,7 +245,7 @@ void RekonqFactory::fillToolbar(KToolBar *b, QDomNode node, KActionCollection *a } -void RekonqFactory::fillMenu(KMenu *m, QDomNode node, KActionCollection *ac) +void RekonqFactory::fillMenu(KMenu *m, QDomNode node) { QDomNodeList childrenList = node.childNodes(); @@ -236,7 +256,7 @@ void RekonqFactory::fillMenu(KMenu *m, QDomNode node, KActionCollection *ac) if (el.tagName() == QL1S("Action")) { const QString actionName = el.attribute("name"); - QAction *a = ac->action(actionName); + QAction *a = actionByName(actionName); if (a) { m->addAction(a); @@ -252,7 +272,7 @@ void RekonqFactory::fillMenu(KMenu *m, QDomNode node, KActionCollection *ac) if (el.tagName() == QL1S("Menu")) { const QString menuName = el.attribute("name"); - KMenu *subm = qobject_cast<KMenu *>(createWidget(menuName, m, ac)); + KMenu *subm = qobject_cast<KMenu *>(createWidget(menuName, m)); m->addMenu(subm); } @@ -264,4 +284,3 @@ void RekonqFactory::fillMenu(KMenu *m, QDomNode node, KActionCollection *ac) } } - diff --git a/src/webwindow/rekonqfactory.h b/src/webwindow/rekonqfactory.h index a0bf956d..4a4f46dd 100644 --- a/src/webwindow/rekonqfactory.h +++ b/src/webwindow/rekonqfactory.h @@ -30,7 +30,6 @@ // Rekonq Includes #include "rekonq_defines.h" -class KActionCollection; class KMenu; class KToolBar; @@ -41,10 +40,11 @@ class QWidget; namespace RekonqFactory { -QWidget *createWidget(const QString &name, QWidget *parent, KActionCollection *); +QWidget *createWidget(const QString &name, QWidget *parent); + +void fillToolbar(KToolBar *, QDomNode); +void fillMenu(KMenu *, QDomNode); -void fillToolbar(KToolBar *, QDomNode, KActionCollection *); -void fillMenu(KMenu *, QDomNode, KActionCollection *); }; #endif diff --git a/src/webwindow/webwindow.cpp b/src/webwindow/webwindow.cpp index 06f0ffac..df38c969 100644 --- a/src/webwindow/webwindow.cpp +++ b/src/webwindow/webwindow.cpp @@ -99,13 +99,12 @@ WebWindow::WebWindow(QWidget *parent, WebPage *pg) QVBoxLayout *l = new QVBoxLayout(this); // main toolbar - _mainToolBar = qobject_cast<KToolBar *>(RekonqFactory::createWidget(QL1S("mainToolBar"), this, actionCollection())); + _mainToolBar = qobject_cast<KToolBar *>(RekonqFactory::createWidget(QL1S("mainToolBar"), this)); l->addWidget(_mainToolBar); if (ReKonfig::showBookmarksToolbar()) { - _bookmarksBar = qobject_cast<BookmarkToolBar *>(RekonqFactory::createWidget(QL1S("bookmarkToolBar"), - this, actionCollection())); + _bookmarksBar = qobject_cast<BookmarkToolBar *>(RekonqFactory::createWidget(QL1S("bookmarkToolBar"), this)); BookmarkManager::self()->registerBookmarkBar(_bookmarksBar.data()); l->addWidget(_bookmarksBar.data()); @@ -143,6 +142,9 @@ WebWindow::WebWindow(QWidget *parent, WebPage *pg) connect(_tab, SIGNAL(infoToShow(QString)), this, SLOT(notifyMessage(QString))); updateHistoryActions(); + + if (parent && parent->isFullScreen()) + setWidgetsHidden(true); } @@ -215,24 +217,23 @@ void WebWindow::setupActions() actionCollection()->addAction(QL1S("show_bookmarks_toolbar"), a); connect(a, SIGNAL(toggled(bool)), this, SLOT(toggleBookmarksToolbar(bool))); - // Open special pages - // Home + // Open Home page a = actionCollection()->addAction(KStandardAction::Home); connect(a, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(openHomePage(Qt::MouseButtons, Qt::KeyboardModifiers))); - // Downloads + // Open Downloads page a = new KAction(KIcon("download"), i18n("Downloads page"), this); a->setShortcut(KShortcut(Qt::CTRL + Qt::Key_J)); actionCollection()->addAction(QL1S("open_downloads_page"), a); connect(a, SIGNAL(triggered(bool)), this, SLOT(openDownloadsPage())); - // History + // Open History page a = new KAction(KIcon("view-history"), i18n("History page"), this); a->setShortcut(KShortcut(Qt::CTRL + Qt::Key_H)); actionCollection()->addAction(QL1S("open_history_page"), a); connect(a, SIGNAL(triggered(bool)), this, SLOT(openHistoryPage())); - // Bookmarks + // Open Bookmarks page a = new KAction(KIcon("bookmarks"), i18n("Bookmarks page"), this); a->setShortcut(KShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_B)); actionCollection()->addAction(QL1S("open_bookmarks_page"), a); @@ -246,11 +247,10 @@ void WebWindow::setupActions() KStandardAction::findNext(m_findBar, SLOT(findNext()), actionCollection()); KStandardAction::findPrev(m_findBar, SLOT(findPrevious()), actionCollection()); - a = KStandardAction::fullScreen(this, SLOT(setWidgetsHidden(bool)), this, actionCollection()); + a = KStandardAction::fullScreen(this, SIGNAL(setFullScreen(bool)), this, actionCollection()); KShortcut fullScreenShortcut = KStandardShortcut::fullScreen(); fullScreenShortcut.setAlternate(Qt::Key_F11); a->setShortcut(fullScreenShortcut); - connect(a, SIGNAL(toggled(bool)), this, SIGNAL(setFullScreen(bool))); a = KStandardAction::redisplay(_tab->view(), SLOT(reload()), actionCollection()); a->setText(i18n("Reload")); @@ -328,12 +328,6 @@ void WebWindow::setupActions() a = new KAction(KIcon("tools-wizard"), i18n("Sync"), this); // FIXME sync icon!! actionCollection()->addAction(QL1S("sync"), a); connect(a, SIGNAL(triggered(bool)), SyncManager::self(), SLOT(showSettings())); - - // ============================== General Tab Actions ==================================== - a = new KAction(KIcon("tab-new"), i18n("New &Tab"), this); - a->setShortcut(KShortcut(Qt::CTRL + Qt::Key_T)); - actionCollection()->addAction(QL1S("new_tab"), a); - connect(a, SIGNAL(triggered(bool)), rApp, SLOT(newTab())); } @@ -343,7 +337,7 @@ void WebWindow::setupTools() toolsAction->setDelayed(false); toolsAction->setShortcutConfigurable(true); toolsAction->setShortcut(KShortcut(Qt::ALT + Qt::Key_T)); - m_rekonqMenu = qobject_cast<RekonqMenu *>(RekonqFactory::createWidget(QL1S("rekonqMenu"), this, actionCollection())); + m_rekonqMenu = qobject_cast<RekonqMenu *>(RekonqFactory::createWidget(QL1S("rekonqMenu"), this)); toolsAction->setMenu(m_rekonqMenu); // dummy menu to have the dropdown arrow // adding rekonq_tools to rekonq actionCollection @@ -412,7 +406,7 @@ void WebWindow::webLoadFinished(bool b) connect(m_loadStopReloadAction, SIGNAL(triggered(bool)), _tab->view(), SLOT(reload())); } - updateHistoryActions(); + updateHistoryActions(); } @@ -833,8 +827,6 @@ void WebWindow::setWidgetsHidden(bool hide) if (!_bookmarksBar.isNull() && bookmarksToolBarFlag) _bookmarksBar.data()->show(); } - - emit setFullScreen(hide); } @@ -883,7 +875,7 @@ void WebWindow::toggleBookmarksToolbar(bool b) if (b) { - _bookmarksBar = qobject_cast<BookmarkToolBar *>(RekonqFactory::createWidget(QL1S("bookmarkToolBar"), this, actionCollection())); + _bookmarksBar = qobject_cast<BookmarkToolBar *>(RekonqFactory::createWidget(QL1S("bookmarkToolBar"), this)); BookmarkManager::self()->registerBookmarkBar(_bookmarksBar.data()); qobject_cast<QVBoxLayout *>(layout())->insertWidget(1, _bookmarksBar.data()); |