Commit 2d8de46a authored by Andrea Diamantini's avatar Andrea Diamantini
Browse files

Reimplement (in 2.x way) the ability to edit toolbar

BUG: 312340
parent d9d2c0c1
......@@ -100,6 +100,7 @@ set(rekonq_KDEINIT_SRCS
webtab/webtab.cpp
#----------------------------------------
webwindow/findbar.cpp
webwindow/maintoolbar.cpp
webwindow/rekonqfactory.cpp
webwindow/rekonqmenu.cpp
webwindow/webwindow.cpp
......
/* ============================================================
*
* This file is a part of the rekonq project
*
* Copyright (C) 2003 by Andrea Diamantini <adjam7 at gmail dot com>
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ============================================================ */
#include "maintoolbar.h"
#include "maintoolbar.moc"
#include <KAction>
#include <KActionCollection>
#include <KMenu>
#include <QPoint>
MainToolBar::MainToolBar(QWidget *parent)
: KToolBar (parent, true, true)
{
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showCustomContextMenu(QPoint)));
}
void MainToolBar::showCustomContextMenu(QPoint p)
{
KMenu menu(this);
QList<KActionCollection *> lac = KActionCollection::allCollections();
int lac_count = lac.count();
for (int i = lac_count - 1; i >= 0; i--)
{
KActionCollection *ac = lac.at(i);
QAction *a = ac->action("show_bookmarks_toolbar");
if (a)
{
menu.addAction(a);
}
QAction *b = ac->action("configure_main_toolbar");
if (b)
{
menu.addAction(b);
}
}
// finally launch the menu...
menu.exec(mapToGlobal(p));
}
/* ============================================================
*
* This file is a part of the rekonq project
*
* Copyright (C) 2003 by Andrea Diamantini <adjam7 at gmail dot com>
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ============================================================ */
#ifndef MAIN_TOOLBAR_H
#define MAIN_TOOLBAR_H
// Rekonq Includes
#include "rekonq_defines.h"
// KDE Includes
#include <KToolBar>
// Forward Declarations
class QPoint;
class MainToolBar : public KToolBar
{
Q_OBJECT
public:
explicit MainToolBar(QWidget *parent = 0);
private Q_SLOTS:
void showCustomContextMenu(QPoint);
};
#endif // MAIN_TOOLBAR_H
......@@ -27,6 +27,7 @@
#include "rekonqfactory.h"
#include "bookmarkstoolbar.h"
#include "maintoolbar.h"
#include "rekonqmenu.h"
#include <KActionCollection>
......@@ -129,7 +130,7 @@ QWidget *RekonqFactory::createWidget(const QString &name, QWidget *parent)
}
else
{
KToolBar *b = new KToolBar(parent, false , false);
MainToolBar *b = new MainToolBar(parent);
fillToolbar(b, node);
return b;
}
......@@ -181,8 +182,51 @@ QWidget *RekonqFactory::createWidget(const QString &name, QWidget *parent)
}
void RekonqFactory::updateWidget(QWidget *widg, const QString &name)
{
QDomDocument document("rekonqui.rc");
QString xmlFilePath = KStandardDirs::locate("data", "rekonq/rekonqui.rc");
if (!readDocument(document, xmlFilePath))
return;
// Toolbars ----------------------------------------------------------------------
QDomNodeList elementToolbarList = document.elementsByTagName(QL1S("ToolBar"));
if (elementToolbarList.isEmpty())
{
kDebug() << "ELEMENT TOOLBAR LIST EMPTY. RETURNING NULL";
return;
}
for (unsigned int i = 0; i < elementToolbarList.length(); ++i)
{
QDomNode node = elementToolbarList.at(i);
QDomElement element = node.toElement();
if (element.attribute("name") != name)
continue;
if (element.attribute("deleted").toLower() == "true")
{
return;
}
if (name == QL1S("mainToolBar"))
{
fillToolbar(qobject_cast<MainToolBar *>(widg), node);
return;
}
}
kDebug() << "NO WIDGET RETURNED";
return;
}
void RekonqFactory::fillToolbar(KToolBar *b, QDomNode node)
{
b->clear();
QDomElement element = node.toElement();
if (element.hasAttribute("iconSize"))
......
......@@ -42,6 +42,8 @@ namespace RekonqFactory
{
QWidget *createWidget(const QString &name, QWidget *parent);
void updateWidget(QWidget *widg, const QString &name);
void fillToolbar(KToolBar *, QDomNode);
void fillMenu(KMenu *, QDomNode);
......
......@@ -53,6 +53,7 @@
// KDE Includes
#include <KIO/Job>
#include <KEditToolBar>
#include <KFileDialog>
#include <KJobUiDelegate>
#include <KMimeTypeTrader>
......@@ -76,7 +77,6 @@ WebWindow::WebWindow(QWidget *parent, bool isPrivateBrowsing, WebPage *pg)
: QWidget(parent)
, _tab(new WebTab(this, isPrivateBrowsing))
, _bar(new UrlBar(_tab))
, _mainToolBar(0)
, m_findBar(new FindBar(this))
, m_loadStopReloadAction(0)
, m_rekonqMenu(0)
......@@ -101,7 +101,7 @@ WebWindow::WebWindow(QWidget *parent, bool isPrivateBrowsing, WebPage *pg)
// main toolbar
_mainToolBar = qobject_cast<KToolBar *>(RekonqFactory::createWidget(QL1S("mainToolBar"), this));
l->addWidget(_mainToolBar);
l->addWidget(_mainToolBar.data());
if (ReKonfig::showBookmarksToolbar())
{
......@@ -212,6 +212,11 @@ void WebWindow::setupActions()
KStandardAction::keyBindings(this, SLOT(keyBindings()), actionCollection());
KStandardAction::quit(rApp, SLOT(queryQuit()), actionCollection());
// Configure Main Toolbar
a = new KAction(KIcon("configure-toolbars"), i18n("Configure Main ToolBar"), this);
actionCollection()->addAction(QL1S("configure_main_toolbar"), a);
connect(a, SIGNAL(triggered(bool)), this, SLOT(showToolbarEditor()));
// Bookmark Toolbar
a = new KAction(KIcon("bookmark-toolbar"), i18n("Bookmarks Toolbar"), this);
a->setCheckable(true);
......@@ -821,12 +826,12 @@ void WebWindow::setWidgetsHidden(bool hide)
}
// hide main toolbar
_mainToolBar->hide();
_mainToolBar.data()->hide();
}
else
{
// show main toolbar
_mainToolBar->show();
_mainToolBar.data()->show();
// restore state of windowed mode
if (!_bookmarksBar.isNull() && bookmarksToolBarFlag)
......@@ -1000,3 +1005,23 @@ void WebWindow::keyBindings()
dialog->deleteLater();
}
// Main Toolbar methods ----------
void WebWindow::setupMainToolBar()
{
RekonqFactory::updateWidget(_mainToolBar.data(), QL1S("mainToolBar"));
}
void WebWindow::showToolbarEditor()
{
QPointer<KEditToolBar> ed = new KEditToolBar(actionCollection(), this);
ed->setResourceFile( "rekonqui.rc" );
connect(ed, SIGNAL(newToolBarConfig()),this, SLOT(setupMainToolBar()));
ed->exec();
ed->deleteLater();
}
......@@ -139,6 +139,10 @@ private Q_SLOTS:
void preferences();
void keyBindings();
// Main ToolBar Settings slots
void setupMainToolBar();
void showToolbarEditor();
Q_SIGNALS:
void titleChanged(QString);
......@@ -159,7 +163,7 @@ private:
WebTab *_tab;
UrlBar *_bar;
KToolBar *_mainToolBar;
QWeakPointer<KToolBar> _mainToolBar;
QWeakPointer<BookmarkToolBar> _bookmarksBar;
FindBar *m_findBar;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment