12#include <QtWidgets/QLayout>
13#include <QtGui/QFocusEvent>
14#include <QtWidgets/QMenu>
16#include <QtHelp/QHelpContentWidget>
20ContentWindow::ContentWindow()
21 : m_contentWidget(HelpEngineWrapper::instance().contentWidget())
25 m_contentWidget->viewport()->installEventFilter(
this);
26 m_contentWidget->setContextMenuPolicy(Qt::CustomContextMenu);
28 QVBoxLayout *layout =
new QVBoxLayout(
this);
29 layout->setContentsMargins(4, 4, 4, 4);
30 layout->addWidget(m_contentWidget);
32 connect(m_contentWidget, &QWidget::customContextMenuRequested,
33 this, &ContentWindow::showContextMenu);
34 connect(m_contentWidget, &QHelpContentWidget::linkActivated,
35 this, &ContentWindow::linkActivated);
37 QHelpContentModel *contentModel =
38 qobject_cast<QHelpContentModel*>(m_contentWidget->model());
39 connect(contentModel, &QHelpContentModel::contentsCreated,
40 this, &ContentWindow::expandTOC);
54 m_contentWidget->setCurrentIndex(idx);
55 m_contentWidget->scrollTo(idx);
62 Q_ASSERT(m_expandDepth >= -2);
63 if (m_expandDepth > -2) {
72 Q_ASSERT(depth >= -2);
73 m_expandDepth = depth;
75 m_contentWidget->expandAll();
77 m_contentWidget->collapseAll();
79 m_contentWidget->expandToDepth(depth - 1);
85 if (e->reason() != Qt::MouseFocusReason)
86 m_contentWidget->setFocus();
92 if (e->key() == Qt::Key_Escape)
99 if (m_contentWidget && o == m_contentWidget->viewport()
100 && e->type() == QEvent::MouseButtonRelease) {
101 QMouseEvent *me =
static_cast<QMouseEvent*>(e);
102 const QModelIndex &index = m_contentWidget->indexAt(me->pos());
103 if (!index.isValid())
104 return QWidget::eventFilter(o, e);
106 const Qt::MouseButtons button = me->button();
107 QItemSelectionModel *sm = m_contentWidget->selectionModel();
108 if (sm->isSelected(index)) {
109 if ((button == Qt::LeftButton && (me->modifiers() & Qt::ControlModifier))
110 || (button == Qt::MiddleButton)) {
111 QHelpContentModel *contentModel =
112 qobject_cast<QHelpContentModel*>(m_contentWidget->model());
114 QHelpContentItem *itm = contentModel->contentItemAt(index);
115 if (itm && HelpViewer::canOpenPage(itm->url().path()))
118 }
else if (button == Qt::LeftButton) {
123 return QWidget::eventFilter(o, e);
130 if (!m_contentWidget->indexAt(pos).isValid())
133 QHelpContentModel *contentModel =
134 qobject_cast<QHelpContentModel*>(m_contentWidget->model());
135 QHelpContentItem *itm =
136 contentModel->contentItemAt(m_contentWidget->currentIndex());
139 QAction *curTab = menu.addAction(tr(
"Open Link"));
140 QAction *newTab = menu.addAction(tr(
"Open Link in New Tab"));
141 if (!HelpViewer::canOpenPage(itm->url().path()))
142 newTab->setEnabled(
false);
144 menu.move(m_contentWidget->mapToGlobal(pos));
146 QAction *action = menu.exec();
147 if (curTab == action)
148 emit linkActivated(itm->url());
149 else if (newTab == action)
156 QHelpContentModel *contentModel =
157 qobject_cast<QHelpContentModel*>(m_contentWidget->model());
160 if (QHelpContentItem *itm = contentModel->contentItemAt(index)) {
161 const QUrl &url = itm->url();
163 emit linkActivated(url);
void focusInEvent(QFocusEvent *e) override
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
void keyPressEvent(QKeyEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
void expandToDepth(int depth)
bool eventFilter(QObject *o, QEvent *e) override
Filters events if this object has been installed as an event filter for the watched object.
~ContentWindow() override
static OpenPagesManager * instance()
Combined button and popup list for selecting options.