Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
contentwindow.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4
#
include
"contentwindow.h"
5
6
#
include
"centralwidget.h"
7
#
include
"helpenginewrapper.h"
8
#
include
"helpviewer.h"
9
#
include
"openpagesmanager.h"
10
#
include
"tracer.h"
11
12
#
include
<
QtWidgets
/
QLayout
>
13
#
include
<
QtGui
/
QFocusEvent
>
14
#
include
<
QtWidgets
/
QMenu
>
15
16
#
include
<
QtHelp
/
QHelpContentWidget
>
17
18
QT_BEGIN_NAMESPACE
19
20
ContentWindow::ContentWindow()
21
: m_contentWidget(HelpEngineWrapper::instance().contentWidget())
22
, m_expandDepth(-2)
23
{
24
TRACE_OBJ
25
m_contentWidget->viewport()->installEventFilter(
this
);
26
m_contentWidget->setContextMenuPolicy(Qt::CustomContextMenu);
27
28
QVBoxLayout *layout =
new
QVBoxLayout(
this
);
29
layout->setContentsMargins(4, 4, 4, 4);
30
layout->addWidget(m_contentWidget);
31
32
connect(m_contentWidget, &QWidget::customContextMenuRequested,
33
this
, &ContentWindow::showContextMenu);
34
connect(m_contentWidget, &QHelpContentWidget::linkActivated,
35
this
, &ContentWindow::linkActivated);
36
37
QHelpContentModel *contentModel =
38
qobject_cast<QHelpContentModel*>(m_contentWidget->model());
39
connect(contentModel, &QHelpContentModel::contentsCreated,
40
this
, &ContentWindow::expandTOC);
41
}
42
43
ContentWindow
::~
ContentWindow
()
44
{
45
TRACE_OBJ
46
}
47
48
bool
ContentWindow
::syncToContent(
const
QUrl& url)
49
{
50
TRACE_OBJ
51
QModelIndex
idx = m_contentWidget->indexOf(url);
52
if
(!idx.isValid())
53
return
false
;
54
m_contentWidget->setCurrentIndex(idx);
55
m_contentWidget->scrollTo(idx);
56
return
true
;
57
}
58
59
void
ContentWindow
::expandTOC()
60
{
61
TRACE_OBJ
62
Q_ASSERT(m_expandDepth >= -2);
63
if
(m_expandDepth > -2) {
64
expandToDepth
(
m_expandDepth
)
;
65
m_expandDepth = -2;
66
}
67
}
68
69
void
ContentWindow
::
expandToDepth
(
int
depth)
70
{
71
TRACE_OBJ
72
Q_ASSERT(depth >= -2);
73
m_expandDepth = depth;
74
if
(depth == -1)
75
m_contentWidget->expandAll();
76
else
if
(depth == 0)
77
m_contentWidget->collapseAll();
78
else
79
m_contentWidget->expandToDepth(depth - 1);
80
}
81
82
void
ContentWindow
::
focusInEvent
(QFocusEvent *e)
83
{
84
TRACE_OBJ
85
if
(e->reason() != Qt::MouseFocusReason)
86
m_contentWidget->setFocus();
87
}
88
89
void
ContentWindow
::
keyPressEvent
(QKeyEvent *e)
90
{
91
TRACE_OBJ
92
if
(e->key() == Qt::Key_Escape)
93
emit escapePressed();
94
}
95
96
bool
ContentWindow
::
eventFilter
(QObject *o, QEvent *e)
97
{
98
TRACE_OBJ
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);
105
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());
113
if
(contentModel) {
114
QHelpContentItem *itm = contentModel->contentItemAt(index);
115
if
(itm && HelpViewer::canOpenPage(itm->url().path()))
116
OpenPagesManager
::
instance
(
)
->createPage(itm->url());
117
}
118
}
else
if
(button == Qt::LeftButton) {
119
itemClicked(index);
120
}
121
}
122
}
123
return
QWidget::eventFilter(o, e);
124
}
125
126
127
void
ContentWindow
::showContextMenu(
const
QPoint &pos)
128
{
129
TRACE_OBJ
130
if
(!m_contentWidget->indexAt(pos).isValid())
131
return
;
132
133
QHelpContentModel *contentModel =
134
qobject_cast<QHelpContentModel*>(m_contentWidget->model());
135
QHelpContentItem *itm =
136
contentModel->contentItemAt(m_contentWidget->currentIndex());
137
138
QMenu menu;
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
);
143
144
menu.move(m_contentWidget->mapToGlobal(pos));
145
146
QAction *action = menu.exec();
147
if
(curTab == action)
148
emit linkActivated(itm->url());
149
else
if
(newTab == action)
150
OpenPagesManager
::
instance
(
)
->createPage(itm->url());
151
}
152
153
void
ContentWindow
::itemClicked(
const
QModelIndex
&index)
154
{
155
TRACE_OBJ
156
QHelpContentModel *contentModel =
157
qobject_cast<QHelpContentModel*>(m_contentWidget->model());
158
159
if
(contentModel) {
160
if
(QHelpContentItem *itm = contentModel->contentItemAt(index)) {
161
const
QUrl &url = itm->url();
162
if
(url !=
CentralWidget
::
instance
(
)
->currentSource())
163
emit linkActivated(url);
164
}
165
}
166
}
167
168
QT_END_NAMESPACE
CentralWidget
Definition
centralwidget.h:49
CentralWidget::instance
static CentralWidget * instance()
Definition
centralwidget.cpp:212
ContentWindow
Definition
contentwindow.h:16
ContentWindow::focusInEvent
void focusInEvent(QFocusEvent *e) override
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition
contentwindow.cpp:82
ContentWindow::keyPressEvent
void keyPressEvent(QKeyEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
Definition
contentwindow.cpp:89
ContentWindow::expandToDepth
void expandToDepth(int depth)
Definition
contentwindow.cpp:69
ContentWindow::eventFilter
bool eventFilter(QObject *o, QEvent *e) override
Filters events if this object has been installed as an event filter for the watched object.
Definition
contentwindow.cpp:96
ContentWindow::~ContentWindow
~ContentWindow() override
Definition
contentwindow.cpp:43
OpenPagesManager
Definition
openpagesmanager.h:22
OpenPagesManager::instance
static OpenPagesManager * instance()
Definition
openpagesmanager.cpp:33
QModelIndex
\inmodule QtCore
Definition
qabstractitemmodel.h:128
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
TRACE_OBJ
#define TRACE_OBJ
Definition
tracer.h:34
qttools
src
assistant
assistant
contentwindow.cpp
Generated on
for Qt by
1.18.0