From 2735ff4068f0a72233b2a837d4bed0ec726b5371 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Fri, 10 Oct 2014 10:05:59 +0200 Subject: Help: Make it possible to create multiple content views Change-Id: I77ccbd1b48e9611f263716a248a6193dcbad8823 Reviewed-by: Eike Ziller --- src/shared/help/contentwindow.cpp | 67 ++++++++++++++------------------------- src/shared/help/contentwindow.h | 21 ++++++------ 2 files changed, 34 insertions(+), 54 deletions(-) (limited to 'src/shared/help') diff --git a/src/shared/help/contentwindow.cpp b/src/shared/help/contentwindow.cpp index 7b5504896bf..13cf0907a9f 100644 --- a/src/shared/help/contentwindow.cpp +++ b/src/shared/help/contentwindow.cpp @@ -34,12 +34,14 @@ #include #include +#include + #include #include #include #include -#include +#include using namespace Help::Internal; @@ -47,7 +49,10 @@ ContentWindow::ContentWindow() : m_contentWidget(0) , m_expandDepth(-2) { - m_contentWidget = (&LocalHelpManager::helpEngine())->contentWidget(); + m_contentModel = (&LocalHelpManager::helpEngine())->contentModel(); + m_contentWidget = new Utils::NavigationTreeView; + m_contentWidget->setModel(m_contentModel); + m_contentWidget->setActivationMode(Utils::SingleClickActivation); m_contentWidget->installEventFilter(this); m_contentWidget->viewport()->installEventFilter(this); m_contentWidget->setContextMenuPolicy(Qt::CustomContextMenu); @@ -57,31 +62,19 @@ ContentWindow::ContentWindow() layout->setMargin(0); layout->addWidget(m_contentWidget); - connect(m_contentWidget, SIGNAL(customContextMenuRequested(QPoint)), this, - SLOT(showContextMenu(QPoint))); - connect(m_contentWidget, SIGNAL(linkActivated(QUrl)), this, - SIGNAL(linkActivated(QUrl))); - - QHelpContentModel *contentModel = - qobject_cast(m_contentWidget->model()); - connect(contentModel, SIGNAL(contentsCreated()), this, SLOT(expandTOC())); + connect(m_contentWidget, &QWidget::customContextMenuRequested, + this, &ContentWindow::showContextMenu); + connect(m_contentWidget, &QTreeView::activated, + this, &ContentWindow::itemActivated); - m_contentWidget->setFrameStyle(QFrame::NoFrame); + connect(m_contentModel, &QHelpContentModel::contentsCreated, + this, &ContentWindow::expandTOC); } ContentWindow::~ContentWindow() { } -bool ContentWindow::syncToContent(const QUrl& url) -{ - QModelIndex idx = m_contentWidget->indexOf(url); - if (!idx.isValid()) - return false; - m_contentWidget->setCurrentIndex(idx); - return true; -} - void ContentWindow::expandTOC() { if (m_expandDepth > -2) { @@ -105,7 +98,7 @@ bool ContentWindow::eventFilter(QObject *o, QEvent *e) && e->type() == QEvent::MouseButtonRelease) { QMouseEvent *me = static_cast(e); QItemSelectionModel *sm = m_contentWidget->selectionModel(); - if (!me || !sm) + if (!sm) return QWidget::eventFilter(o, e); Qt::MouseButtons button = me->button(); @@ -113,16 +106,10 @@ bool ContentWindow::eventFilter(QObject *o, QEvent *e) if (index.isValid() && sm->isSelected(index)) { if ((button == Qt::LeftButton && (me->modifiers() & Qt::ControlModifier)) - || (button == Qt::MidButton)) { - QHelpContentModel *contentModel = - qobject_cast(m_contentWidget->model()); - if (contentModel) { - QHelpContentItem *itm = contentModel->contentItemAt(index); - if (itm && HelpViewer::canOpenPage(itm->url().path())) - OpenPagesManager::instance().createPage(itm->url()); - } - } else if (button == Qt::LeftButton) { - itemClicked(index); + || (button == Qt::MidButton)) { + QHelpContentItem *itm = m_contentModel->contentItemAt(index); + if (itm) + emit linkActivated(itm->url(), true/*newPage*/); } } } @@ -149,21 +136,13 @@ void ContentWindow::showContextMenu(const QPoint &pos) QAction *action = menu.exec(); if (curTab == action) - emit linkActivated(itm->url()); + emit linkActivated(itm->url(), false/*newPage*/); else if (newTab == action) - OpenPagesManager::instance().createPage(itm->url()); + emit linkActivated(itm->url(), true/*newPage*/); } -void ContentWindow::itemClicked(const QModelIndex &index) +void ContentWindow::itemActivated(const QModelIndex &index) { - QHelpContentModel *contentModel = - qobject_cast(m_contentWidget->model()); - - if (contentModel) { - if (QHelpContentItem *itm = contentModel->contentItemAt(index)) { - const QUrl &url = itm->url(); - if (url != CentralWidget::instance()->currentViewer()->source()) - emit linkActivated(itm->url()); - } - } + if (QHelpContentItem *itm = m_contentModel->contentItemAt(index)) + emit linkActivated(itm->url(), false/*newPage*/); } diff --git a/src/shared/help/contentwindow.h b/src/shared/help/contentwindow.h index 659dfc26346..ee054157293 100644 --- a/src/shared/help/contentwindow.h +++ b/src/shared/help/contentwindow.h @@ -37,10 +37,14 @@ QT_BEGIN_NAMESPACE class QHelpContentItem; -class QHelpContentWidget; +class QHelpContentModel; QT_END_NAMESPACE +namespace Utils { +class NavigationTreeView; +} + class ContentWindow : public QWidget { Q_OBJECT @@ -49,21 +53,18 @@ public: ContentWindow(); ~ContentWindow(); - bool syncToContent(const QUrl &url); - void expandToDepth(int depth); - signals: - void linkActivated(const QUrl &link); + void linkActivated(const QUrl &link, bool newPage); -private slots: +private: void showContextMenu(const QPoint &pos); void expandTOC(); - void itemClicked(const QModelIndex &index); - -private: + void itemActivated(const QModelIndex &index); + void expandToDepth(int depth); bool eventFilter(QObject *o, QEvent *e); - QHelpContentWidget *m_contentWidget; + Utils::NavigationTreeView *m_contentWidget; + QHelpContentModel *m_contentModel; int m_expandDepth; }; -- cgit v1.2.3