From 9461c52f07a2bf8b9bc25f037b17805cda51b2b0 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 10 Mar 2013 19:02:12 +0100 Subject: 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 --- src/panels/paneltreeview.cpp | 186 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 src/panels/paneltreeview.cpp (limited to 'src/panels/paneltreeview.cpp') 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 +* Copyright (C) 2012-2013 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +// Self Includes +#include "paneltreeview.h" +#include "paneltreeview.moc" + +// Local Includes +#include "application.h" + +// KDE Includes +#include + +// Qt Includes +#include +#include + + +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); +} -- cgit v1.2.1