diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2013-03-10 19:02:12 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2013-03-10 19:02:12 +0100 |
commit | 9461c52f07a2bf8b9bc25f037b17805cda51b2b0 (patch) | |
tree | b599e6eff700e65a864bb275c94adc9a6da7e529 /src/panels | |
parent | Add toggle ability to bk folder in bk page (diff) | |
download | rekonq-9461c52f07a2bf8b9bc25f037b17805cda51b2b0.tar.xz |
Supporting panel (again) :)
- Move to a pure QWidget base window (instead of TabWidget one)
(this to properly store panels position)
- Restoring && rewamping panels code
- Restoring actions to activate/deactivate them
BUG: 312354
Diffstat (limited to 'src/panels')
-rw-r--r-- | src/panels/bookmarkspanel.cpp | 170 | ||||
-rw-r--r-- | src/panels/bookmarkspanel.h | 93 | ||||
-rw-r--r-- | src/panels/historypanel.cpp | 214 | ||||
-rw-r--r-- | src/panels/historypanel.h | 63 | ||||
-rw-r--r-- | src/panels/paneltreeview.cpp | 186 | ||||
-rw-r--r-- | src/panels/paneltreeview.h | 69 | ||||
-rw-r--r-- | src/panels/urlfilterproxymodel.cpp | 59 | ||||
-rw-r--r-- | src/panels/urlfilterproxymodel.h | 59 | ||||
-rw-r--r-- | src/panels/urlpanel.cpp | 111 | ||||
-rw-r--r-- | src/panels/urlpanel.h | 81 |
10 files changed, 1105 insertions, 0 deletions
diff --git a/src/panels/bookmarkspanel.cpp b/src/panels/bookmarkspanel.cpp new file mode 100644 index 00000000..57796a23 --- /dev/null +++ b/src/panels/bookmarkspanel.cpp @@ -0,0 +1,170 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Nils Weigel <nehlsen at gmail dot com> +* Copyright (C) 2010-2013 by Andrea Diamantini <adjam7 at gmail dot com> +* Copyright (C) 2010 by Yoann Laissus <yoann dot laissus 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/>. +* +* ============================================================ */ + + +// Self Includes +#include "bookmarkspanel.h" +#include "bookmarkspanel.moc" + +// Auto Includes +#include "rekonq.h" + +// Local Includes +#include "bookmarkmanager.h" +#include "bookmarkstreemodel.h" +#include "bookmarkscontextmenu.h" +#include "bookmarkowner.h" + +#include "paneltreeview.h" +#include "urlfilterproxymodel.h" + + +BookmarksPanel::BookmarksPanel(const QString &title, QWidget *parent, Qt::WindowFlags flags) + : UrlPanel(title, parent, flags) + , _bkTreeModel(new BookmarksTreeModel(this)) + , _loadingState(false) +{ + setObjectName("bookmarksPanel"); + setVisible(ReKonfig::showBookmarksPanel()); + + panelTreeView()->setDragEnabled(true); + panelTreeView()->setAcceptDrops(true); + connect(_bkTreeModel, SIGNAL(bookmarksUpdated()), this, SLOT(loadFoldedState())); +} + + +BookmarksPanel::~BookmarksPanel() +{ + ReKonfig::setShowBookmarksPanel(!isHidden()); +} + + +void BookmarksPanel::loadFoldedState() +{ + _loadingState = true; + loadFoldedState(QModelIndex()); + _loadingState = false; +} + + +void BookmarksPanel::contextMenu(const QPoint &pos) +{ + if (_loadingState) + return; + + BookmarksContextMenu menu(bookmarkForIndex(panelTreeView()->indexAt(pos)), + BookmarkManager::self()->manager(), + BookmarkManager::self()->owner() + ); + + menu.exec(panelTreeView()->mapToGlobal(pos)); +} + + +void BookmarksPanel::deleteBookmark() +{ + QModelIndex index = panelTreeView()->currentIndex(); + if (_loadingState || !index.isValid()) + return; + + BookmarkManager::self()->owner()->deleteBookmark(bookmarkForIndex(index)); +} + + +void BookmarksPanel::onCollapse(const QModelIndex &index) +{ + if (_loadingState) + return; + + bookmarkForIndex(index).internalElement().setAttribute("folded", "yes"); + emit expansionChanged(); +} + + +void BookmarksPanel::onExpand(const QModelIndex &index) +{ + if (_loadingState) + return; + + bookmarkForIndex(index).internalElement().setAttribute("folded", "no"); + emit expansionChanged(); +} + + +void BookmarksPanel::setup() +{ + UrlPanel::setup(); + + connect(panelTreeView(), SIGNAL(delKeyPressed()), this, SLOT(deleteBookmark())); + connect(panelTreeView(), SIGNAL(collapsed(QModelIndex)), this, SLOT(onCollapse(QModelIndex))); + connect(panelTreeView(), SIGNAL(expanded(QModelIndex)), this, SLOT(onExpand(QModelIndex))); + + loadFoldedState(); +} + + +void BookmarksPanel::loadFoldedState(const QModelIndex &root) +{ + QAbstractItemModel *model = panelTreeView()->model(); + if (!model) + return; + + int count = model->rowCount(root); + QModelIndex index; + + for (int i = 0; i < count; ++i) + { + index = model->index(i, 0, root); + if (index.isValid()) + { + KBookmark bm = bookmarkForIndex(index); + if (bm.isGroup()) + { + panelTreeView()->setExpanded(index, bm.toGroup().isOpen()); + loadFoldedState(index); + } + } + } +} + + +KBookmark BookmarksPanel::bookmarkForIndex(const QModelIndex &index) +{ + if (!index.isValid()) + return KBookmark(); + + const UrlFilterProxyModel *proxyModel = static_cast<const UrlFilterProxyModel*>(index.model()); + QModelIndex originalIndex = proxyModel->mapToSource(index); + + BtmItem *node = static_cast<BtmItem*>(originalIndex.internalPointer()); + return node->getBkm(); +} + + +QAbstractItemModel* BookmarksPanel::model() +{ + return _bkTreeModel; +} diff --git a/src/panels/bookmarkspanel.h b/src/panels/bookmarkspanel.h new file mode 100644 index 00000000..8c827c65 --- /dev/null +++ b/src/panels/bookmarkspanel.h @@ -0,0 +1,93 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Nils Weigel <nehlsen at gmail dot com> +* Copyright (C) 2010-2013 by Andrea Diamantini <adjam7 at gmail dot com> +* Copyright (C) 2010 by Yoann Laissus <yoann dot laissus 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 BOOKMARKS_PANEL_H +#define BOOKMARKS_PANEL_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// Local Includes +#include "urlpanel.h" + +// Forward Declarations +class BookmarksTreeModel; + +class KBookmark; +class QModelIndex; + + +class REKONQ_TESTS_EXPORT BookmarksPanel : public UrlPanel +{ + Q_OBJECT + +public: + explicit BookmarksPanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0); + ~BookmarksPanel(); + +public Q_SLOTS: + void loadFoldedState(); + +Q_SIGNALS: + void expansionChanged(); + +private Q_SLOTS: + void contextMenu(const QPoint &pos); + + virtual void contextMenuItem(const QPoint &pos) + { + contextMenu(pos); + } + virtual void contextMenuGroup(const QPoint &pos) + { + contextMenu(pos); + } + virtual void contextMenuEmpty(const QPoint &pos) + { + contextMenu(pos); + } + + void deleteBookmark(); + void onCollapse(const QModelIndex &index); + void onExpand(const QModelIndex &index); + +private: + virtual void setup(); + + void loadFoldedState(const QModelIndex &root); + + KBookmark bookmarkForIndex(const QModelIndex &index); + + virtual QAbstractItemModel* model(); + + BookmarksTreeModel *_bkTreeModel; + bool _loadingState; +}; + +#endif // BOOKMARKS_PANEL_H diff --git a/src/panels/historypanel.cpp b/src/panels/historypanel.cpp new file mode 100644 index 00000000..30d2cb6b --- /dev/null +++ b/src/panels/historypanel.cpp @@ -0,0 +1,214 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Domrachev Alexandr <alexandr.domrachev@gmail.com> +* Copyright (C) 2009-2011 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/>. +* +* ============================================================ */ + + +// Self Includes +#include "historypanel.h" +#include "historypanel.moc" + +// Auto Includes +#include "rekonq.h" + +// Local Includes +#include "paneltreeview.h" + +#include "historymanager.h" +#include "historymodels.h" +#include "urlfilterproxymodel.h" + +// KDE Includes +#include <KLocalizedString> +#include <KMenu> +#include <KAction> +#include <KMessageBox> + +// Qt Includes +#include <QHeaderView> + + +HistoryPanel::HistoryPanel(const QString &title, QWidget *parent, Qt::WindowFlags flags) + : UrlPanel(title, parent, flags) +{ + setObjectName("historyPanel"); + setVisible(ReKonfig::showHistoryPanel()); +} + + +HistoryPanel::~HistoryPanel() +{ + ReKonfig::setShowHistoryPanel(!isHidden()); +} + + +void HistoryPanel::contextMenuItem(const QPoint &pos) +{ + KMenu menu; + KAction* action; + + action = new KAction(KIcon("tab-new"), i18n("Open"), this); + connect(action, SIGNAL(triggered()), panelTreeView(), SLOT(openInCurrentTab())); + menu.addAction(action); + + action = new KAction(KIcon("tab-new"), i18n("Open in New Tab"), this); + connect(action, SIGNAL(triggered()), panelTreeView(), SLOT(openInNewTab())); + menu.addAction(action); + + action = new KAction(KIcon("window-new"), i18n("Open in New Window"), this); + connect(action, SIGNAL(triggered()), panelTreeView(), SLOT(openInNewWindow())); + menu.addAction(action); + + action = new KAction(KIcon("edit-copy"), i18n("Copy Link Address"), this); + connect(action, SIGNAL(triggered()), panelTreeView(), SLOT(copyToClipboard())); + menu.addAction(action); + + action = new KAction(KIcon("edit-clear"), i18n("Remove Entry"), this); + connect(action, SIGNAL(triggered()), this, SLOT(deleteEntry())); + menu.addAction(action); + + action = new KAction(KIcon("edit-clear"), i18n("Remove all occurrences"), this); + connect(action, SIGNAL(triggered()), this, SLOT(forgetSite())); + menu.addAction(action); + + menu.exec(panelTreeView()->mapToGlobal(pos)); +} + + +void HistoryPanel::contextMenuGroup(const QPoint &pos) +{ + KMenu menu; + KAction* action; + + action = new KAction(KIcon("tab-new"), i18n("Open Folder in Tabs"), this); + connect(action, SIGNAL(triggered()), this, SLOT(openAll())); + menu.addAction(action); + + action = new KAction(KIcon("edit-clear"), i18n("Remove Folder"), this); + connect(action, SIGNAL(triggered()), this, SLOT(deleteGroup())); + menu.addAction(action); + + menu.exec(panelTreeView()->mapToGlobal(pos)); +} + + +void HistoryPanel::contextMenuEmpty(const QPoint& /*pos*/) +{ +} + + +void HistoryPanel::openAll() +{ + QModelIndex index = panelTreeView()->currentIndex(); + if (!index.isValid()) + return; + + QList<KUrl> allChild; + + for (int i = 0; i < index.model()->rowCount(index); i++) + allChild << qVariantValue<KUrl>(index.child(i, 0).data(Qt::UserRole)); + + if (allChild.length() > 8) + { + if (!(KMessageBox::warningContinueCancel(this, + i18ncp("%1=Number of tabs. Value is always >=8", + "You are about to open %1 tabs.\nAre you sure?", + "You are about to open %1 tabs.\nAre you sure?", + allChild.length())) == KMessageBox::Continue) + ) + return; + } + + for (int i = 0; i < allChild.length(); i++) + emit openUrl(allChild.at(i).url(), Rekonq::NewTab); +} + + +void HistoryPanel::deleteGroup() +{ + QModelIndex index = panelTreeView()->currentIndex(); + if (!index.isValid()) + return; + + //Getting all URLs of sub items. + QList<KUrl> allChild; + for (int i = 0; i < index.model()->rowCount(index); i++) + allChild << qVariantValue<KUrl>(index.child(i, 0).data(Qt::UserRole)); + + for (int i = 0; i < allChild.length(); i++) + HistoryManager::self()->removeHistoryEntry(allChild.at(i)); + +} + + +void HistoryPanel::setup() +{ + UrlPanel::setup(); + + panelTreeView()->header()->hideSection(1); + + const UrlFilterProxyModel *proxy = static_cast<const UrlFilterProxyModel*>(panelTreeView()->model()); + panelTreeView()->expand(proxy->index(0, 0)); +} + + +void HistoryPanel::deleteEntry() +{ + QModelIndex index = panelTreeView()->currentIndex(); + if (!index.isValid()) + return; + removedFolderIndex = index.parent().row(); + + HistoryManager::self()->removeHistoryEntry(qVariantValue< KUrl >(index.data(Qt::UserRole))); + + QModelIndex expandItem = panelTreeView()->model()->index(removedFolderIndex, 0); + if (expandItem.isValid()) + panelTreeView()->expand(expandItem); +} + + +void HistoryPanel::forgetSite() +{ + QModelIndex index = panelTreeView()->currentIndex(); + if (!index.isValid()) + return; + removedFolderIndex = index.row(); + + QString site = qVariantValue< KUrl >(index.data(Qt::UserRole)).host(); + QList<HistoryItem> toRemove = HistoryManager::self()->find(site); + for (int i = 0; i < toRemove.length(); i++) + { + HistoryManager::self()->removeHistoryEntry(KUrl(toRemove.at(i).url)); + } + + QModelIndex expandItem = panelTreeView()->model()->index(removedFolderIndex, 0); + if (expandItem.isValid()) + panelTreeView()->expand(expandItem); +} + + +QAbstractItemModel* HistoryPanel::model() +{ + return HistoryManager::self()->historyTreeModel(); +} diff --git a/src/panels/historypanel.h b/src/panels/historypanel.h new file mode 100644 index 00000000..bae55d76 --- /dev/null +++ b/src/panels/historypanel.h @@ -0,0 +1,63 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Domrachev Alexandr <alexandr.domrachev@gmail.com> +* Copyright (C) 2009-2013 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 HISTORYPANEL_H +#define HISTORYPANEL_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// Local Includes +#include "urlpanel.h" + + +class REKONQ_TESTS_EXPORT HistoryPanel : public UrlPanel +{ + Q_OBJECT + +public: + explicit HistoryPanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0); + virtual ~HistoryPanel(); + +private Q_SLOTS: + virtual void contextMenuItem(const QPoint &pos); + virtual void contextMenuGroup(const QPoint &pos); + virtual void contextMenuEmpty(const QPoint &pos); + + void openAll(); + void deleteEntry(); + void deleteGroup(); + void forgetSite(); + +private: + virtual void setup(); + virtual QAbstractItemModel* model(); + int removedFolderIndex; +}; + +#endif // HISTORYPANEL_H diff --git a/src/panels/paneltreeview.cpp b/src/panels/paneltreeview.cpp new file mode 100644 index 00000000..722ba8a9 --- /dev/null +++ b/src/panels/paneltreeview.cpp @@ -0,0 +1,186 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2010 by Yoann Laissus <yoann dot laissus at gmail dot com> +* Copyright (C) 2012-2013 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/>. +* +* ============================================================ */ + + +// Self Includes +#include "paneltreeview.h" +#include "paneltreeview.moc" + +// Local Includes +#include "application.h" + +// KDE Includes +#include <KUrl> + +// Qt Includes +#include <QClipboard> +#include <QMouseEvent> + + +PanelTreeView::PanelTreeView(QWidget *parent) + : QTreeView(parent) +{ + connect(this, SIGNAL(itemHovered(QString)), parent, SIGNAL(itemHovered(QString))); + connect(this, SIGNAL(openUrl(KUrl, Rekonq::OpenType)), parent, SIGNAL(openUrl(KUrl, Rekonq::OpenType))); + + setMouseTracking(true); + setExpandsOnDoubleClick(false); +} + + +void PanelTreeView::mousePressEvent(QMouseEvent *event) +{ + const QModelIndex index = indexAt(event->pos()); + bool expanded = isExpanded(index); + + QTreeView::mousePressEvent(event); + + // A change of an item expansion is handle by mouseReleaseEvent() + // So toggle again the item + if (expanded != isExpanded(index)) + setExpanded(index, !isExpanded(index)); + + if (!index.isValid()) + { + clearSelection(); + setCurrentIndex(QModelIndex()); + + if (event->button() == Qt::RightButton) + emit contextMenuEmptyRequested(event->pos()); + return; + } + + if (event->button() == Qt::RightButton) + { + if (model()->rowCount(index) == 0) + { + // An empty group needs to be handle by the panels + emit contextMenuItemRequested(event->pos()); + } + else + { + emit contextMenuGroupRequested(event->pos()); + } + } +} + + +void PanelTreeView::mouseReleaseEvent(QMouseEvent *event) +{ + QTreeView::mouseReleaseEvent(event); + + const QModelIndex index = indexAt(event->pos()); + if (!index.isValid()) + return; + + if (event->button() == Qt::MidButton || event->modifiers() == Qt::ControlModifier) + emit openUrl(qVariantValue< KUrl >(index.data(Qt::UserRole)), Rekonq::NewTab); + + else if (event->button() == Qt::LeftButton) + { + if (model()->rowCount(index) == 0) + emit openUrl(qVariantValue< KUrl >(index.data(Qt::UserRole))); + else + setExpanded(index, !isExpanded(index)); + } +} + + +void PanelTreeView::keyPressEvent(QKeyEvent *event) +{ + QTreeView::keyPressEvent(event); + QModelIndex index = currentIndex(); + + if (!index.isValid()) + return; + + if (event->key() == Qt::Key_Return) + { + if (model()->rowCount(index) == 0) + openUrl(qVariantValue< KUrl >(index.data(Qt::UserRole))); + else + setExpanded(index, !isExpanded(index)); + } + + else if (event->key() == Qt::Key_Delete) + { + emit delKeyPressed(); + } +} + + +void PanelTreeView::mouseMoveEvent(QMouseEvent *event) +{ + QTreeView::mouseMoveEvent(event); + const QModelIndex index = indexAt(event->pos()); + if (!index.isValid()) + { + emit itemHovered(""); + return; + } + emit itemHovered(qVariantValue< KUrl >(index.data(Qt::UserRole)).url()); +} + + +void PanelTreeView::openInCurrentTab() +{ + QModelIndex index = currentIndex(); + if (!index.isValid()) + return; + + emit openUrl(qVariantValue< KUrl >(index.data(Qt::UserRole))); +} + + +void PanelTreeView::copyToClipboard() +{ + QModelIndex index = currentIndex(); + if (!index.isValid()) + return; + + QClipboard *cb = QApplication::clipboard(); + cb->setText(qVariantValue< KUrl >(index.data(Qt::UserRole)).url()); +} + + +void PanelTreeView::openInNewTab() +{ + QModelIndex index = currentIndex(); + if (!index.isValid()) + return; + + emit openUrl(qVariantValue< KUrl >(index.data(Qt::UserRole)), Rekonq::NewTab); +} + + +void PanelTreeView::openInNewWindow() +{ + QModelIndex index = currentIndex(); + if (!index.isValid()) + return; + + emit openUrl(qVariantValue< KUrl >(index.data(Qt::UserRole)), Rekonq::NewWindow); +} diff --git a/src/panels/paneltreeview.h b/src/panels/paneltreeview.h new file mode 100644 index 00000000..ee8c51d0 --- /dev/null +++ b/src/panels/paneltreeview.h @@ -0,0 +1,69 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2010-2011 by Yoann Laissus <yoann dot laissus at gmail dot com> +* Copyright (C) 2012-2013 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 PANELTREEVIEW_H +#define PANELTREEVIEW_H + +// Rekonq Includes +#include "rekonq_defines.h" + +// Qt Includes +#include <QTreeView> + +// Forward Declarations +class KUrl; + + +class REKONQ_TESTS_EXPORT PanelTreeView : public QTreeView +{ + Q_OBJECT + +public: + PanelTreeView(QWidget *parent = 0); + +Q_SIGNALS: + void openUrl(const KUrl &, const Rekonq::OpenType & = Rekonq::CurrentTab); + void itemHovered(const QString &); + void delKeyPressed(); + void contextMenuItemRequested(const QPoint &pos); + void contextMenuGroupRequested(const QPoint &pos); + void contextMenuEmptyRequested(const QPoint &pos); + +public Q_SLOTS: + void copyToClipboard(); + void openInCurrentTab(); + void openInNewTab(); + void openInNewWindow(); + +protected: + void mouseReleaseEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void keyPressEvent(QKeyEvent *event); +}; + +#endif // PANELTREEVIEW_H diff --git a/src/panels/urlfilterproxymodel.cpp b/src/panels/urlfilterproxymodel.cpp new file mode 100644 index 00000000..aa9ac7a6 --- /dev/null +++ b/src/panels/urlfilterproxymodel.cpp @@ -0,0 +1,59 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Nils Weigel <nehlsen at gmail dot com> +* Copyright (C) 2010-2011 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/>. +* +* ============================================================ */ + + +// Self Includes +#include "urlfilterproxymodel.h" +#include "urlfilterproxymodel.moc" + + +UrlFilterProxyModel::UrlFilterProxyModel(QObject *parent) + : QSortFilterProxyModel(parent) +{ + setFilterCaseSensitivity(Qt::CaseInsensitive); +} + + +bool UrlFilterProxyModel::filterAcceptsRow(const int source_row, const QModelIndex &source_parent) const +{ + return recursiveMatch(sourceModel()->index(source_row, 0, source_parent)); +} + + +bool UrlFilterProxyModel::recursiveMatch(const QModelIndex &index) const +{ + if (index.data().toString().contains(filterRegExp())) + return true; + + int numChildren = sourceModel()->rowCount(index); + for (int childRow = 0; childRow < numChildren; ++childRow) + { + if (recursiveMatch(sourceModel()->index(childRow, 0, index))) + return true; + } + + return false; +} diff --git a/src/panels/urlfilterproxymodel.h b/src/panels/urlfilterproxymodel.h new file mode 100644 index 00000000..6cb8574e --- /dev/null +++ b/src/panels/urlfilterproxymodel.h @@ -0,0 +1,59 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Nils Weigel <nehlsen at gmail dot com> +* Copyright (C) 2010-2011 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 URLFILTERPROXYMODEL_H +#define URLFILTERPROXYMODEL_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// Qt Includes +#include <QSortFilterProxyModel> + + +/** + * QSortFilterProxyModel hides all children which parent doesn't + * match the filter. This class is used to change this behavior. + * If a url matches the filter it'll be shown, + * even if it's parent doesn't match it. + */ +class REKONQ_TESTS_EXPORT UrlFilterProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + explicit UrlFilterProxyModel(QObject *parent = 0); + +protected: + virtual bool filterAcceptsRow(const int source_row, const QModelIndex &source_parent) const; + + // returns true if index or any of his children match the filter + bool recursiveMatch(const QModelIndex &index) const; +}; + +#endif // URLFILTERPROXYMODEL_H diff --git a/src/panels/urlpanel.cpp b/src/panels/urlpanel.cpp new file mode 100644 index 00000000..7fb75087 --- /dev/null +++ b/src/panels/urlpanel.cpp @@ -0,0 +1,111 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Domrachev Alexandr <alexandr.domrachev@gmail.com> +* Copyright (C) 2009-2013 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/>. +* +* ============================================================ */ + + +// Self Includes +#include "urlpanel.h" +#include "urlpanel.moc" + +// Local Includes +#include "paneltreeview.h" +#include "urlfilterproxymodel.h" + +// KDE Includes +#include <KLineEdit> +#include <KLocalizedString> + +// Qt Includes +#include <QLabel> +#include <QHBoxLayout> +#include <QHeaderView> + + +UrlPanel::UrlPanel(const QString &title, QWidget *parent, Qt::WindowFlags flags) + : QDockWidget(title, parent, flags) + , _treeView(new PanelTreeView(this)) + , _loaded(false) +{ + setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + + connect(this, SIGNAL(visibilityChanged(bool)), this, SLOT(showing(bool))); +} + + +void UrlPanel::showing(bool b) +{ + if (!_loaded && b) + { + setup(); + _loaded = true; + } +} + + +void UrlPanel::setup() +{ + QWidget *ui = new QWidget(this); + + // setup search bar + QHBoxLayout *searchLayout = new QHBoxLayout; + searchLayout->setContentsMargins(5, 0, 0, 0); + QLabel *searchLabel = new QLabel(i18n("&Search:")); + searchLayout->addWidget(searchLabel); + KLineEdit *search = new KLineEdit; + search->setClearButtonShown(true); + searchLayout->addWidget(search); + searchLabel->setBuddy(search); + + // setup tree view + _treeView->setUniformRowHeights(true); + _treeView->header()->hide(); + + // put everything together + QVBoxLayout *vBoxLayout = new QVBoxLayout; + vBoxLayout->setContentsMargins(0, 0, 0, 0); + vBoxLayout->addLayout(searchLayout); + vBoxLayout->addWidget(_treeView); + + // add it to the UI + ui->setLayout(vBoxLayout); + setWidget(ui); + + UrlFilterProxyModel *proxy = new UrlFilterProxyModel(this); + proxy->setSourceModel(model()); + _treeView->setModel(proxy); + + connect(search, SIGNAL(textChanged(QString)), proxy, SLOT(setFilterFixedString(QString))); + connect(search, SIGNAL(textChanged(QString)), this, SLOT(expandTreeView())); + + connect(_treeView, SIGNAL(contextMenuItemRequested(QPoint)), this, SLOT(contextMenuItem(QPoint))); + connect(_treeView, SIGNAL(contextMenuGroupRequested(QPoint)), this, SLOT(contextMenuGroup(QPoint))); + connect(_treeView, SIGNAL(contextMenuEmptyRequested(QPoint)), this, SLOT(contextMenuEmpty(QPoint))); +} + + +void UrlPanel::expandTreeView() +{ + _treeView->expandAll(); +} diff --git a/src/panels/urlpanel.h b/src/panels/urlpanel.h new file mode 100644 index 00000000..72393c9e --- /dev/null +++ b/src/panels/urlpanel.h @@ -0,0 +1,81 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Domrachev Alexandr <alexandr.domrachev@gmail.com> +* Copyright (C) 2009-2013 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 URLPANEL_H +#define URLPANEL_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// Qt Includes +#include <QDockWidget> + +// Forward Declarations +class PanelTreeView; + +class QAbstractItemModel; + + +class REKONQ_TESTS_EXPORT UrlPanel : public QDockWidget +{ + Q_OBJECT + +public: + explicit UrlPanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0); + +Q_SIGNALS: + void openUrl(const KUrl &, const Rekonq::OpenType &); + void itemHovered(const QString &); + +public Q_SLOTS: + void showing(bool); + +protected: + virtual void setup(); + virtual QAbstractItemModel* model() = 0; + + PanelTreeView* panelTreeView() const + { + return _treeView; + } + +protected Q_SLOTS: + virtual void contextMenuItem(const QPoint &pos) = 0; + virtual void contextMenuGroup(const QPoint &pos) = 0; + virtual void contextMenuEmpty(const QPoint &pos) = 0; + +private Q_SLOTS: + void expandTreeView(); + +private: + PanelTreeView *_treeView; + bool _loaded; +}; + + +#endif // URLPANEL_H |