Help: Make it possible to create multiple content views

Change-Id: I77ccbd1b48e9611f263716a248a6193dcbad8823
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
Eike Ziller
2014-10-10 10:05:59 +02:00
committed by Eike Ziller
parent 5cf2972345
commit 2735ff4068
3 changed files with 36 additions and 57 deletions

View File

@@ -305,8 +305,7 @@ void HelpPlugin::setupUi()
ContentWindow *contentWindow = new ContentWindow(); ContentWindow *contentWindow = new ContentWindow();
contentWindow->setWindowTitle(tr(Constants::SB_CONTENTS)); contentWindow->setWindowTitle(tr(Constants::SB_CONTENTS));
auto contentItem = new SideBarItem(contentWindow, QLatin1String(Constants::HELP_CONTENTS)); auto contentItem = new SideBarItem(contentWindow, QLatin1String(Constants::HELP_CONTENTS));
connect(contentWindow, SIGNAL(linkActivated(QUrl)), m_centralWidget, connect(contentWindow, &ContentWindow::linkActivated, m_centralWidget, &HelpWidget::open);
SLOT(setSource(QUrl)));
action = new QAction(tr("Activate Help Contents View"), m_splitter); action = new QAction(tr("Activate Help Contents View"), m_splitter);
cmd = ActionManager::registerAction(action, Constants::HELP_CONTENTS, modecontext); cmd = ActionManager::registerAction(action, Constants::HELP_CONTENTS, modecontext);

View File

@@ -34,12 +34,14 @@
#include <localhelpmanager.h> #include <localhelpmanager.h>
#include <openpagesmanager.h> #include <openpagesmanager.h>
#include <utils/navigationtreeview.h>
#include <QLayout> #include <QLayout>
#include <QFocusEvent> #include <QFocusEvent>
#include <QMenu> #include <QMenu>
#include <QHelpEngine> #include <QHelpEngine>
#include <QHelpContentWidget> #include <QHelpContentModel>
using namespace Help::Internal; using namespace Help::Internal;
@@ -47,7 +49,10 @@ ContentWindow::ContentWindow()
: m_contentWidget(0) : m_contentWidget(0)
, m_expandDepth(-2) , 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->installEventFilter(this);
m_contentWidget->viewport()->installEventFilter(this); m_contentWidget->viewport()->installEventFilter(this);
m_contentWidget->setContextMenuPolicy(Qt::CustomContextMenu); m_contentWidget->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -57,31 +62,19 @@ ContentWindow::ContentWindow()
layout->setMargin(0); layout->setMargin(0);
layout->addWidget(m_contentWidget); layout->addWidget(m_contentWidget);
connect(m_contentWidget, SIGNAL(customContextMenuRequested(QPoint)), this, connect(m_contentWidget, &QWidget::customContextMenuRequested,
SLOT(showContextMenu(QPoint))); this, &ContentWindow::showContextMenu);
connect(m_contentWidget, SIGNAL(linkActivated(QUrl)), this, connect(m_contentWidget, &QTreeView::activated,
SIGNAL(linkActivated(QUrl))); this, &ContentWindow::itemActivated);
QHelpContentModel *contentModel = connect(m_contentModel, &QHelpContentModel::contentsCreated,
qobject_cast<QHelpContentModel*>(m_contentWidget->model()); this, &ContentWindow::expandTOC);
connect(contentModel, SIGNAL(contentsCreated()), this, SLOT(expandTOC()));
m_contentWidget->setFrameStyle(QFrame::NoFrame);
} }
ContentWindow::~ContentWindow() 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() void ContentWindow::expandTOC()
{ {
if (m_expandDepth > -2) { if (m_expandDepth > -2) {
@@ -105,7 +98,7 @@ bool ContentWindow::eventFilter(QObject *o, QEvent *e)
&& e->type() == QEvent::MouseButtonRelease) { && e->type() == QEvent::MouseButtonRelease) {
QMouseEvent *me = static_cast<QMouseEvent*>(e); QMouseEvent *me = static_cast<QMouseEvent*>(e);
QItemSelectionModel *sm = m_contentWidget->selectionModel(); QItemSelectionModel *sm = m_contentWidget->selectionModel();
if (!me || !sm) if (!sm)
return QWidget::eventFilter(o, e); return QWidget::eventFilter(o, e);
Qt::MouseButtons button = me->button(); Qt::MouseButtons button = me->button();
@@ -113,16 +106,10 @@ bool ContentWindow::eventFilter(QObject *o, QEvent *e)
if (index.isValid() && sm->isSelected(index)) { if (index.isValid() && sm->isSelected(index)) {
if ((button == Qt::LeftButton && (me->modifiers() & Qt::ControlModifier)) if ((button == Qt::LeftButton && (me->modifiers() & Qt::ControlModifier))
|| (button == Qt::MidButton)) { || (button == Qt::MidButton)) {
QHelpContentModel *contentModel = QHelpContentItem *itm = m_contentModel->contentItemAt(index);
qobject_cast<QHelpContentModel*>(m_contentWidget->model()); if (itm)
if (contentModel) { emit linkActivated(itm->url(), true/*newPage*/);
QHelpContentItem *itm = contentModel->contentItemAt(index);
if (itm && HelpViewer::canOpenPage(itm->url().path()))
OpenPagesManager::instance().createPage(itm->url());
}
} else if (button == Qt::LeftButton) {
itemClicked(index);
} }
} }
} }
@@ -149,21 +136,13 @@ void ContentWindow::showContextMenu(const QPoint &pos)
QAction *action = menu.exec(); QAction *action = menu.exec();
if (curTab == action) if (curTab == action)
emit linkActivated(itm->url()); emit linkActivated(itm->url(), false/*newPage*/);
else if (newTab == action) 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 = if (QHelpContentItem *itm = m_contentModel->contentItemAt(index))
qobject_cast<QHelpContentModel*>(m_contentWidget->model()); emit linkActivated(itm->url(), false/*newPage*/);
if (contentModel) {
if (QHelpContentItem *itm = contentModel->contentItemAt(index)) {
const QUrl &url = itm->url();
if (url != CentralWidget::instance()->currentViewer()->source())
emit linkActivated(itm->url());
}
}
} }

View File

@@ -37,10 +37,14 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QHelpContentItem; class QHelpContentItem;
class QHelpContentWidget; class QHelpContentModel;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Utils {
class NavigationTreeView;
}
class ContentWindow : public QWidget class ContentWindow : public QWidget
{ {
Q_OBJECT Q_OBJECT
@@ -49,21 +53,18 @@ public:
ContentWindow(); ContentWindow();
~ContentWindow(); ~ContentWindow();
bool syncToContent(const QUrl &url);
void expandToDepth(int depth);
signals: signals:
void linkActivated(const QUrl &link); void linkActivated(const QUrl &link, bool newPage);
private slots:
void showContextMenu(const QPoint &pos);
void expandTOC();
void itemClicked(const QModelIndex &index);
private: private:
void showContextMenu(const QPoint &pos);
void expandTOC();
void itemActivated(const QModelIndex &index);
void expandToDepth(int depth);
bool eventFilter(QObject *o, QEvent *e); bool eventFilter(QObject *o, QEvent *e);
QHelpContentWidget *m_contentWidget; Utils::NavigationTreeView *m_contentWidget;
QHelpContentModel *m_contentModel;
int m_expandDepth; int m_expandDepth;
}; };