Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Education
Cantor
Commits
5326340f
Commit
5326340f
authored
Nov 22, 2020
by
Alexander Semke
Browse files
Better variable names in the documentation panel widget.
parent
e8e56192
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/panelplugins/documentationpanel/documentationpanelwidget.cpp
View file @
5326340f
...
...
@@ -16,6 +16,7 @@
---
Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
Copyright (C) 2020 Alexander Semke <alexander.semke@web.de>
*/
#include "cantor_macros.h"
...
...
@@ -33,7 +34,6 @@
#include <QFrame>
#include <QHBoxLayout>
#include <QHelpContentWidget>
#include <QHelpEngine>
#include <QHelpIndexWidget>
#include <QIcon>
#include <QLabel>
...
...
@@ -41,7 +41,6 @@
#include <QModelIndex>
#include <QPushButton>
#include <QShortcut>
#include <QStandardPaths>
#include <QStackedWidget>
#include <QToolButton>
#include <QVBoxLayout>
...
...
@@ -49,16 +48,15 @@
#include <QWebEngineProfile>
#include <QWebEngineUrlScheme>
#include <QWebEngineView>
#include <QDebug>
DocumentationPanelWidget
::
DocumentationPanelWidget
(
QWidget
*
parent
)
:
QWidget
(
parent
)
{
m_
textBrowser
=
new
QWebEngineView
(
this
);
m_
textBrowser
->
page
()
->
action
(
QWebEnginePage
::
ViewSource
)
->
setVisible
(
false
);
m_
textBrowser
->
page
()
->
action
(
QWebEnginePage
::
OpenLinkInNewTab
)
->
setVisible
(
false
);
m_
textBrowser
->
page
()
->
action
(
QWebEnginePage
::
OpenLinkInNewWindow
)
->
setVisible
(
false
);
m_
textBrowser
->
page
()
->
action
(
QWebEnginePage
::
DownloadLinkToDisk
)
->
setVisible
(
false
);
m_
textBrowser
->
page
()
->
action
(
QWebEnginePage
::
Reload
)
->
setVisible
(
false
);
m_
webEngineView
=
new
QWebEngineView
(
this
);
m_
webEngineView
->
page
()
->
action
(
QWebEnginePage
::
ViewSource
)
->
setVisible
(
false
);
m_
webEngineView
->
page
()
->
action
(
QWebEnginePage
::
OpenLinkInNewTab
)
->
setVisible
(
false
);
m_
webEngineView
->
page
()
->
action
(
QWebEnginePage
::
OpenLinkInNewWindow
)
->
setVisible
(
false
);
m_
webEngineView
->
page
()
->
action
(
QWebEnginePage
::
DownloadLinkToDisk
)
->
setVisible
(
false
);
m_
webEngineView
->
page
()
->
action
(
QWebEnginePage
::
Reload
)
->
setVisible
(
false
);
/////////////////////////
// Top toolbar layout //
...
...
@@ -76,7 +74,7 @@ DocumentationPanelWidget::DocumentationPanelWidget(QWidget* parent) : QWidget(pa
m_search
->
setClearButtonEnabled
(
true
);
// Add a seperator
QFrame
*
seperator
=
new
QFrame
(
this
);
QFrame
*
seperator
=
new
QFrame
(
this
);
seperator
->
setFrameShape
(
QFrame
::
VLine
);
seperator
->
setFrameShadow
(
QFrame
::
Sunken
);
...
...
@@ -107,7 +105,7 @@ DocumentationPanelWidget::DocumentationPanelWidget(QWidget* parent) : QWidget(pa
zoomIn
->
setContext
(
Qt
::
WidgetWithChildrenShortcut
);
connect
(
zoomIn
,
&
QShortcut
::
activated
,
this
,
[
=
]{
m_
textBrowser
->
setZoomFactor
(
m_
textBrowser
->
zoomFactor
()
+
0.1
);
m_
webEngineView
->
setZoomFactor
(
m_
webEngineView
->
zoomFactor
()
+
0.1
);
emit
zoomFactorChanged
();
});
...
...
@@ -115,19 +113,19 @@ DocumentationPanelWidget::DocumentationPanelWidget(QWidget* parent) : QWidget(pa
zoomOut
->
setContext
(
Qt
::
WidgetWithChildrenShortcut
);
connect
(
zoomOut
,
&
QShortcut
::
activated
,
this
,
[
=
]{
m_
textBrowser
->
setZoomFactor
(
m_
textBrowser
->
zoomFactor
()
-
0.1
);
m_
webEngineView
->
setZoomFactor
(
m_
webEngineView
->
zoomFactor
()
-
0.1
);
emit
zoomFactorChanged
();
});
connect
(
this
,
&
DocumentationPanelWidget
::
zoomFactorChanged
,
[
=
]{
if
(
m_
textBrowser
->
zoomFactor
()
!=
1.0
)
if
(
m_
webEngineView
->
zoomFactor
()
!=
1.0
)
resetZoom
->
setEnabled
(
true
);
else
resetZoom
->
setEnabled
(
false
);
});
// Later on, add Contents, Browser and Index on this stacked widget whenever setBackend() is called
m_
displayArea
=
new
QStackedWidget
(
this
);
m_
stackedWidget
=
new
QStackedWidget
(
this
);
/////////////////////////////////
// Find in Page widget layout //
...
...
@@ -173,20 +171,14 @@ DocumentationPanelWidget::DocumentationPanelWidget(QWidget* parent) : QWidget(pa
// Add topmost toolbar, display area and find in page widget in a Vertical layout
QVBoxLayout
*
vlayout
=
new
QVBoxLayout
(
this
);
vlayout
->
addWidget
(
toolBarContainer
);
vlayout
->
addWidget
(
m_
displayArea
);
vlayout
->
addWidget
(
m_
stackedWidget
);
vlayout
->
addWidget
(
findPageWidgetContainer
);
connect
(
this
,
&
DocumentationPanelWidget
::
activateBrowser
,
[
=
]{
m_textBrowser
->
hide
();
m_displayArea
->
setCurrentIndex
(
1
);
m_textBrowser
->
show
();
});
connect
(
m_documentationSelector
,
QOverload
<
int
>::
of
(
&
QComboBox
::
currentIndexChanged
),
this
,
&
DocumentationPanelWidget
::
updateDocumentation
);
connect
(
m_
displayArea
,
&
QStackedWidget
::
currentChanged
,
[
=
]{
connect
(
m_
stackedWidget
,
&
QStackedWidget
::
currentChanged
,
[
=
]{
//disable Home and Search in Page buttons when stackwidget shows contents widget, enable when shows web browser
if
(
m_
displayArea
->
currentIndex
()
!=
1
)
//0->contents 1->browser
if
(
m_
stackedWidget
->
currentIndex
()
!=
1
)
//0->contents 1->browser
{
findPage
->
setEnabled
(
false
);
home
->
setEnabled
(
false
);
...
...
@@ -199,12 +191,12 @@ DocumentationPanelWidget::DocumentationPanelWidget(QWidget* parent) : QWidget(pa
});
connect
(
home
,
&
QPushButton
::
clicked
,
[
=
]{
m_
displayArea
->
setCurrentIndex
(
0
);
m_
stackedWidget
->
setCurrentIndex
(
0
);
findPageWidgetContainer
->
hide
();
});
connect
(
resetZoom
,
&
QPushButton
::
clicked
,
[
=
]{
m_
textBrowser
->
setZoomFactor
(
1.0
);
m_
webEngineView
->
setZoomFactor
(
1.0
);
resetZoom
->
setEnabled
(
false
);
});
...
...
@@ -219,7 +211,7 @@ DocumentationPanelWidget::DocumentationPanelWidget(QWidget* parent) : QWidget(pa
connect
(
hideButton
,
&
QToolButton
::
clicked
,
this
,
[
=
]{
findPageWidgetContainer
->
hide
();
m_
textBrowser
->
findText
(
QString
());
// this clears up the selected text
m_
webEngineView
->
findText
(
QString
());
// this clears up the selected text
});
connect
(
m_findText
,
&
QLineEdit
::
returnPressed
,
this
,
&
DocumentationPanelWidget
::
searchForward
);
...
...
@@ -228,21 +220,21 @@ DocumentationPanelWidget::DocumentationPanelWidget(QWidget* parent) : QWidget(pa
connect
(
previous
,
&
QToolButton
::
clicked
,
this
,
&
DocumentationPanelWidget
::
searchBackward
);
connect
(
m_matchCase
,
&
QAbstractButton
::
toggled
,
this
,
&
DocumentationPanelWidget
::
searchForward
);
connect
(
m_matchCase
,
&
QAbstractButton
::
toggled
,
this
,
[
=
]{
m_
textBrowser
->
findText
(
QString
());
m_
webEngineView
->
findText
(
QString
());
searchForward
();
});
// for webenginebrowser for downloading of images or html pages
connect
(
m_
textBrowser
->
page
()
->
profile
(),
&
QWebEngineProfile
::
downloadRequested
,
this
,
&
DocumentationPanelWidget
::
downloadResource
);
connect
(
m_
webEngineView
->
page
()
->
profile
(),
&
QWebEngineProfile
::
downloadRequested
,
this
,
&
DocumentationPanelWidget
::
downloadResource
);
}
DocumentationPanelWidget
::~
DocumentationPanelWidget
()
{
delete
m_index
;
delete
m_content
;
delete
m_index
Widget
;
delete
m_content
Widget
;
delete
m_engine
;
delete
m_
textBrowser
;
delete
m_
displayArea
;
delete
m_
webEngineView
;
delete
m_
stackedWidget
;
delete
m_search
;
delete
m_findText
;
delete
m_matchCase
;
...
...
@@ -295,10 +287,10 @@ void DocumentationPanelWidget::updateDocumentation()
return
;
//remove the currently shown widgets
if
(
m_
displayArea
->
count
())
if
(
m_
stackedWidget
->
count
())
{
for
(
int
i
=
m_
displayArea
->
count
();
i
>=
0
;
i
--
)
m_
displayArea
->
removeWidget
(
m_
displayArea
->
widget
(
i
));
for
(
int
i
=
m_
stackedWidget
->
count
();
i
>=
0
;
i
--
)
m_
stackedWidget
->
removeWidget
(
m_
stackedWidget
->
widget
(
i
));
m_search
->
clear
();
}
...
...
@@ -313,11 +305,11 @@ void DocumentationPanelWidget::updateDocumentation()
if
(
m_docNames
.
isEmpty
())
{
m_
textBrowser
->
hide
();
m_
webEngineView
->
hide
();
return
;
}
else
m_
textBrowser
->
show
();
m_
webEngineView
->
show
();
//initialize the Qt Help engine and provide the proper help collection file for the current backend
//and for the currently selected documentation for this backend
...
...
@@ -330,43 +322,36 @@ void DocumentationPanelWidget::updateDocumentation()
/*if(!m_engine->setupData())
qWarning() << "Couldn't setup QtHelp Engine: " << m_engine->error();*/
if
(
m_backend
!=
QLatin1String
(
"
O
ctave"
))
if
(
m_backend
!=
QLatin1String
(
"
o
ctave"
))
m_engine
->
setProperty
(
"_q_readonly"
,
QVariant
::
fromValue
<
bool
>
(
true
));
//index widget
m_index
=
m_engine
->
indexWidget
();
connect
(
m_index
,
&
QHelpIndexWidget
::
linkActivated
,
this
,
&
DocumentationPanelWidget
::
displayHelp
);
connect
(
m_index
,
&
QHelpIndexWidget
::
linkActivated
,
this
,
&
DocumentationPanelWidget
::
displayHelp
);
m_indexWidget
=
m_engine
->
indexWidget
();
connect
(
m_indexWidget
,
&
QHelpIndexWidget
::
linkActivated
,
this
,
&
DocumentationPanelWidget
::
displayHelp
);
//content widget
m_content
=
m_engine
->
contentWidget
();
connect
(
m_content
,
&
QHelpContentWidget
::
linkActivated
,
this
,
&
DocumentationPanelWidget
::
displayHelp
);
connect
(
m_content
,
&
QHelpContentWidget
::
linkActivated
,
this
,
&
DocumentationPanelWidget
::
displayHelp
);
//TODO QHelpIndexWidget::linkActivated is obsolete, use QHelpIndexWidget::documentActivated instead
// display the documentation browser whenever contents are clicked
connect
(
m_content
,
&
QHelpContentWidget
::
linkActivated
,
[
=
]{
m_displayArea
->
setCurrentIndex
(
1
);
});
m_contentWidget
=
m_engine
->
contentWidget
();
connect
(
m_contentWidget
,
&
QHelpContentWidget
::
linkActivated
,
this
,
&
DocumentationPanelWidget
::
displayHelp
);
connect
(
m_contentWidget
,
&
QHelpContentWidget
::
linkActivated
,
[
=
]{
m_stackedWidget
->
setCurrentIndex
(
1
);
});
//search widget
auto
*
completer
=
new
QCompleter
(
m_index
->
model
(),
m_search
);
auto
*
completer
=
new
QCompleter
(
m_index
Widget
->
model
(),
m_search
);
m_search
->
setCompleter
(
completer
);
completer
->
setCompletionMode
(
QCompleter
::
UnfilteredPopupCompletion
);
completer
->
setCaseSensitivity
(
Qt
::
CaseInsensitive
);
connect
(
completer
,
QOverload
<
const
QModelIndex
&>::
of
(
&
QCompleter
::
activated
),
this
,
&
DocumentationPanelWidget
::
returnPressed
);
//add the widgets to the display area
m_
displayArea
->
addWidget
(
m_content
);
m_
displayArea
->
addWidget
(
m_
textBrowser
);
m_
stackedWidget
->
addWidget
(
m_content
Widget
);
m_
stackedWidget
->
addWidget
(
m_
webEngineView
);
/* Adding the index widget to implement the logic for context sensitive help
* This widget would be NEVER shown*/
m_
displayArea
->
addWidget
(
m_index
);
m_
stackedWidget
->
addWidget
(
m_index
Widget
);
// handle the URL scheme handler
//m_
textBrowser
->page()->profile()->removeUrlScheme("qthelp");
m_
textBrowser
->
page
()
->
profile
()
->
removeAllUrlSchemeHandlers
();
// remove previously installed scheme handler and then install new one
m_
textBrowser
->
page
()
->
profile
()
->
installUrlSchemeHandler
(
"qthelp"
,
new
QtHelpSchemeHandler
(
m_engine
));
//m_
webEngineView
->page()->profile()->removeUrlScheme("qthelp");
m_
webEngineView
->
page
()
->
profile
()
->
removeAllUrlSchemeHandlers
();
// remove previously installed scheme handler and then install new one
m_
webEngineView
->
page
()
->
profile
()
->
installUrlSchemeHandler
(
"qthelp"
,
new
QtHelpSchemeHandler
(
m_engine
));
// register the compressed help file (qch)
const
QString
&
nameSpace
=
QHelpEngineCore
::
namespaceName
(
m_currentQchFileName
);
...
...
@@ -382,8 +367,8 @@ void DocumentationPanelWidget::updateDocumentation()
void
DocumentationPanelWidget
::
displayHelp
(
const
QUrl
&
url
)
{
qDebug
()
<<
url
;
m_
textBrowser
->
load
(
url
);
m_
textBrowser
->
show
();
m_
webEngineView
->
load
(
url
);
m_
webEngineView
->
show
();
}
void
DocumentationPanelWidget
::
returnPressed
()
...
...
@@ -398,38 +383,40 @@ void DocumentationPanelWidget::returnPressed()
void
DocumentationPanelWidget
::
contextSensitiveHelp
(
const
QString
&
keyword
)
{
qDebug
()
<<
keyword
;
qDebug
()
<<
"requested the documentation for the keyword "
<<
keyword
;
// First make sure we have display browser as the current widget on the QStackedWidget
emit
activateBrowser
();
m_webEngineView
->
hide
();
m_stackedWidget
->
setCurrentIndex
(
1
);
m_webEngineView
->
show
();
m_index
->
filterIndices
(
keyword
);
// filter exactly, no wildcards
m_index
->
activateCurrentItem
();
// this internally emitts the QHelpIndexWidget::linkActivated signal
m_index
Widget
->
filterIndices
(
keyword
);
// filter exactly, no wildcards
m_index
Widget
->
activateCurrentItem
();
// this internally emitts the QHelpIndexWidget::linkActivated signal
// called in order to refresh and restore the index widget
// otherwise filterIndices() filters the indices list, and then the index widget only contains the matched keywords
m_index
->
filterIndices
(
QString
());
m_index
Widget
->
filterIndices
(
QString
());
}
void
DocumentationPanelWidget
::
searchForward
()
{
m_matchCase
->
isChecked
()
?
m_
textBrowser
->
findText
(
m_findText
->
text
(),
QWebEnginePage
::
FindCaseSensitively
)
:
m_
textBrowser
->
findText
(
m_findText
->
text
());
m_matchCase
->
isChecked
()
?
m_
webEngineView
->
findText
(
m_findText
->
text
(),
QWebEnginePage
::
FindCaseSensitively
)
:
m_
webEngineView
->
findText
(
m_findText
->
text
());
}
void
DocumentationPanelWidget
::
searchBackward
()
{
m_matchCase
->
isChecked
()
?
m_
textBrowser
->
findText
(
m_findText
->
text
(),
QWebEnginePage
::
FindCaseSensitively
|
QWebEnginePage
::
FindBackward
)
:
m_
textBrowser
->
findText
(
m_findText
->
text
(),
QWebEnginePage
::
FindBackward
);
m_matchCase
->
isChecked
()
?
m_
webEngineView
->
findText
(
m_findText
->
text
(),
QWebEnginePage
::
FindCaseSensitively
|
QWebEnginePage
::
FindBackward
)
:
m_
webEngineView
->
findText
(
m_findText
->
text
(),
QWebEnginePage
::
FindBackward
);
}
void
DocumentationPanelWidget
::
downloadResource
(
QWebEngineDownloadItem
*
resource
)
{
// default download directory is ~/Downloads on Linux
m_
textBrowser
->
page
()
->
download
(
resource
->
url
());
m_
webEngineView
->
page
()
->
download
(
resource
->
url
());
resource
->
accept
();
KMessageBox
::
information
(
this
,
i18n
(
"The file has been downloaded successfully at Downloads."
),
i18n
(
"Download Successfull"
));
disconnect
(
m_
textBrowser
->
page
()
->
profile
(),
&
QWebEngineProfile
::
downloadRequested
,
this
,
&
DocumentationPanelWidget
::
downloadResource
);
disconnect
(
m_
webEngineView
->
page
()
->
profile
(),
&
QWebEngineProfile
::
downloadRequested
,
this
,
&
DocumentationPanelWidget
::
downloadResource
);
}
src/panelplugins/documentationpanel/documentationpanelwidget.h
View file @
5326340f
...
...
@@ -16,6 +16,7 @@
---
Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
Copyright (C) 2020 Alexander Semke <alexander.semke@web.de>
*/
#ifndef _DOCUMENTATIONPANELWIDGET_H
...
...
@@ -23,13 +24,11 @@
#include <QBuffer>
#include <QHelpEngine>
#include <QMap>
#include <QWebEngineUrlRequestJob>
#include <QWebEngineUrlSchemeHandler>
#include <QWidget>
class
QComboBox
;
class
QHelpEngine
;
class
QHelpContentWidget
;
class
QHelpIndexWidget
;
class
QLineEdit
;
...
...
@@ -50,7 +49,6 @@ class DocumentationPanelWidget : public QWidget
void
updateBackend
(
const
QString
&
,
const
QString
&
);
Q_SIGNALS:
void
activateBrowser
();
void
zoomFactorChanged
();
private
Q_SLOTS
:
...
...
@@ -68,10 +66,10 @@ class DocumentationPanelWidget : public QWidget
void
updateDocumentation
();
QHelpEngine
*
m_engine
=
nullptr
;
QWebEngineView
*
m_
textBrowser
=
nullptr
;
QStackedWidget
*
m_
displayArea
=
nullptr
;
QHelpIndexWidget
*
m_index
=
nullptr
;
QHelpContentWidget
*
m_content
=
nullptr
;
QWebEngineView
*
m_
webEngineView
=
nullptr
;
QStackedWidget
*
m_
stackedWidget
=
nullptr
;
QHelpIndexWidget
*
m_index
Widget
=
nullptr
;
QHelpContentWidget
*
m_content
Widget
=
nullptr
;
QString
m_backend
;
QStringList
m_docNames
;
QStringList
m_docPaths
;
...
...
@@ -83,7 +81,6 @@ class DocumentationPanelWidget : public QWidget
QToolButton
*
m_matchCase
=
nullptr
;
QComboBox
*
m_documentationSelector
=
nullptr
;
QMap
<
QString
,
QStringList
>
m_helpFiles
;
QString
m_currentQchFileName
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment