Commit 2735ff40 authored by Eike Ziller's avatar Eike Ziller Committed by Eike Ziller

Help: Make it possible to create multiple content views

Change-Id: I77ccbd1b48e9611f263716a248a6193dcbad8823
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 5cf29723
......@@ -305,8 +305,7 @@ void HelpPlugin::setupUi()
ContentWindow *contentWindow = new ContentWindow();
contentWindow->setWindowTitle(tr(Constants::SB_CONTENTS));
auto contentItem = new SideBarItem(contentWindow, QLatin1String(Constants::HELP_CONTENTS));
connect(contentWindow, SIGNAL(linkActivated(QUrl)), m_centralWidget,
SLOT(setSource(QUrl)));
connect(contentWindow, &ContentWindow::linkActivated, m_centralWidget, &HelpWidget::open);
action = new QAction(tr("Activate Help Contents View"), m_splitter);
cmd = ActionManager::registerAction(action, Constants::HELP_CONTENTS, modecontext);
......
......@@ -34,12 +34,14 @@
#include <localhelpmanager.h>
#include <openpagesmanager.h>
#include <utils/navigationtreeview.h>
#include <QLayout>
#include <QFocusEvent>
#include <QMenu>
#include <QHelpEngine>
#include <QHelpContentWidget>
#include <QHelpContentModel>
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<QHelpContentModel*>(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<QMouseEvent*>(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<QHelpContentModel*>(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<QHelpContentModel*>(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*/);
}
......@@ -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;
};
......
Markdown is supported
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