aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/help
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@digia.com>2014-10-10 10:05:59 +0200
committerEike Ziller <eike.ziller@theqtcompany.com>2014-10-13 11:23:29 +0200
commit2735ff4068f0a72233b2a837d4bed0ec726b5371 (patch)
tree69a25033171da9c2d5c973477c42f744cbc3e1c5 /src/shared/help
parent5cf2972345171892aca33c6ad784b9a92aa99936 (diff)
Help: Make it possible to create multiple content views
Change-Id: I77ccbd1b48e9611f263716a248a6193dcbad8823 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Diffstat (limited to 'src/shared/help')
-rw-r--r--src/shared/help/contentwindow.cpp67
-rw-r--r--src/shared/help/contentwindow.h21
2 files changed, 34 insertions, 54 deletions
diff --git a/src/shared/help/contentwindow.cpp b/src/shared/help/contentwindow.cpp
index 7b5504896b..13cf0907a9 100644
--- a/src/shared/help/contentwindow.cpp
+++ b/src/shared/help/contentwindow.cpp
@@ -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*/);
}
diff --git a/src/shared/help/contentwindow.h b/src/shared/help/contentwindow.h
index 659dfc2634..ee05415729 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;
};