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
fbe56da1
Commit
fbe56da1
authored
Jul 11, 2020
by
Shubham .
Browse files
Change the Documentation panel layout
parent
de72b626
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/panelplugins/documentationpanel/documentationpanelwidget.cpp
View file @
fbe56da1
...
...
@@ -24,19 +24,17 @@
#include <KLocalizedString>
#include <QApplication>
#include <QByteArray>
#include <QComboBox>
#include <QDebug>
#include <Q
HBox
Layout>
#include <Q
Grid
Layout>
#include <QHelpContentWidget>
#include <QHelpEngine>
#include <QHelpIndexWidget>
#include <QIcon>
#include <QLineEdit>
#include <QPushButton>
#include <QSplitter>
#include <QStandardPaths>
#include <Q
Tab
Widget>
#include <Q
Stacked
Widget>
#include <QWebEngineProfile>
#include <QWebEngineUrlScheme>
#include <QWebEngineView>
...
...
@@ -61,28 +59,36 @@ DocumentationPanelWidget::DocumentationPanelWidget(Cantor::Session* session, QWi
loadDocumentation
();
// create a container for Search tab
QWidget
*
container
=
new
QWidget
(
this
);
QHBoxLayout
*
clayout
=
new
QHBoxLayout
(
this
);
container
->
setLayout
(
clayout
);
QPushButton
*
home
=
new
QPushButton
(
this
);
home
->
setIcon
(
QIcon
::
fromTheme
(
QLatin1String
(
"user-home"
))
);
home
->
setToolTip
(
QLatin1String
(
"Go to the contents"
)
);
home
->
setEnabled
(
false
);
m_input
=
new
QLineEdit
(
this
);
m_input
->
setPlaceholderText
(
i18n
(
"Search..."
));
QPushButton
*
search
=
new
QPushButton
(
i18n
(
"Search"
),
this
);
QComboBox
*
documentationSelector
=
new
QComboBox
(
this
);
// iterate through the available docs, but for now just display maxima and octave
documentationSelector
->
addItem
(
QIcon
::
fromTheme
(
session
->
backend
()
->
icon
()),
m_backend
);
clayout
->
addWidget
(
m_input
);
clayout
->
addWidget
(
search
);
// real time searcher
QLineEdit
*
search
=
new
QLineEdit
(
this
);
search
->
setPlaceholderText
(
QLatin1String
(
"Search through keywords..."
));
QTabWidget
*
tabWidget
=
new
QTabWidget
(
this
);
tabWidget
->
setMovable
(
true
);
tabWidget
->
setElideMode
(
Qt
::
ElideRight
);
QStackedWidget
*
m_displayArea
=
new
QStackedWidget
(
this
);
m_displayArea
->
addWidget
(
m_engine
->
contentWidget
());
// Add different tabs to the widget
tabWid
ge
t
->
addTab
(
m_engine
->
contentWidget
(),
i18n
(
"Contents"
));
tabWid
ge
t
->
addTab
(
m_engine
->
indexWidget
(),
i18n
(
"Index
"
));
tabWid
ge
t
->
addTab
(
container
,
i18n
(
"Search"
)
);
QPushButton
*
findPage
=
new
QPushButton
(
this
);
findPa
ge
->
setIcon
(
QIcon
::
fromTheme
(
QLatin1String
(
"search"
)
));
findPa
ge
->
setToolTip
(
QLatin1String
(
"Find in text of current page
"
));
findPa
ge
->
setEnabled
(
false
);
m_textBrowser
=
new
QWebEngineView
(
this
);
m_displayArea
->
addWidget
(
m_textBrowser
);
/* Adding the index widget to implement the logic for context sensitive help
* This widget would be NEVER shown*/
m_index
=
m_engine
->
indexWidget
();
m_displayArea
->
addWidget
(
m_index
);
static
bool
qthelpRegistered
=
false
;
if
(
!
qthelpRegistered
)
...
...
@@ -105,18 +111,44 @@ DocumentationPanelWidget::DocumentationPanelWidget(Cantor::Session* session, QWi
m_textBrowser
->
show
();
}
Q
Splitter
*
splitter
=
new
QSplitter
(
Qt
::
Horizontal
,
this
);
splitter
->
addWidget
(
tabWidget
);
splitter
->
addWidget
(
m_textBrowser
);
QHBoxLayout
*
layout
=
new
QHBoxLayout
(
this
);
layout
->
addWidget
(
splitter
);
Q
GridLayout
*
layout
=
new
QGridLayout
(
this
);
layout
->
addWidget
(
home
,
0
,
0
);
layout
->
addWidget
(
documentationSelector
,
0
,
1
);
layout
->
addWidget
(
search
,
0
,
2
);
layout
->
addWidget
(
findPage
,
0
,
3
);
layout
->
addWidget
(
m_displayArea
,
1
,
0
,
2
,
0
);
//TODO QHelpIndexWidget::linkActivated is obsolete, use QHelpIndexWidget::documentActivated instead
// display the documentation browser whenever contents are clicked
connect
(
m_engine
->
contentWidget
(),
&
QHelpContentWidget
::
linkActivated
,
[
=
](){
m_displayArea
->
setCurrentIndex
(
1
);
});
connect
(
this
,
&
DocumentationPanelWidget
::
activateBrowser
,
[
=
]{
m_displayArea
->
setCurrentIndex
(
1
);
});
connect
(
m_displayArea
,
&
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
{
findPage
->
setEnabled
(
false
);
home
->
setEnabled
(
false
);
}
else
{
findPage
->
setEnabled
(
true
);
home
->
setEnabled
(
true
);
}
});
connect
(
home
,
&
QPushButton
::
clicked
,
[
=
]{
m_displayArea
->
setCurrentIndex
(
0
);
});
connect
(
m_engine
->
contentWidget
(),
&
QHelpContentWidget
::
linkActivated
,
this
,
&
DocumentationPanelWidget
::
displayHelp
);
connect
(
m_engine
->
indexWidget
(),
&
QHelpIndexWidget
::
linkActivated
,
this
,
&
DocumentationPanelWidget
::
displayHelp
);
connect
(
m_engine
->
indexWidget
(),
&
QHelpIndexWidget
::
activated
,
this
,
&
DocumentationPanelWidget
::
refreshIndexWidget
);
connect
(
search
,
&
QPushButton
::
clicked
,
this
,
&
DocumentationPanelWidget
::
doSearch
);
connect
(
m_index
,
&
QHelpIndexWidget
::
linkActivated
,
this
,
&
DocumentationPanelWidget
::
displayHelp
);
setSession
(
session
);
}
...
...
@@ -125,6 +157,8 @@ DocumentationPanelWidget::~DocumentationPanelWidget()
{
delete
m_engine
;
delete
m_textBrowser
;
delete
m_displayArea
;
delete
m_index
;
}
void
DocumentationPanelWidget
::
setSession
(
Cantor
::
Session
*
session
)
...
...
@@ -139,35 +173,20 @@ void DocumentationPanelWidget::displayHelp(const QUrl& url)
const
QModelIndex
index
=
m_engine
->
indexWidget
()
->
currentIndex
();
const
QString
indexText
=
index
.
data
(
Qt
::
DisplayRole
).
toString
();
qDebug
()
<<
indexText
<<
"index pressed"
;
}
void
DocumentationPanelWidget
::
doSearch
(
)
void
DocumentationPanelWidget
::
contextSensitiveHelp
(
const
QString
&
keyword
)
{
const
QString
text
=
m_input
->
text
();
if
(
!
text
.
isEmpty
())
{
qDebug
()
<<
"searching for"
<<
text
;
// loop through all the content Widgets url and then if text is found in them, then display the QListView
}
// First make sure we have display browser as the current widget on the QStackedWidget, if not then set it
// use index widget on index 2, to do the below
//m_displayArea->setCurrentIndex(2);
}
emit
activateBrowser
();
void
DocumentationPanelWidget
::
contextSensitiveHelp
(
const
QString
&
keyword
)
{
qDebug
()
<<
"Context sensitive help for "
<<
keyword
;
QHelpIndexWidget
*
index
=
m_engine
->
indexWidget
();
index
->
filterIndices
(
keyword
);
// filter exactly, no wildcards
index
->
activateCurrentItem
();
// this internally emitts the QHelpIndexWidget::linkActivated signal
}
void
DocumentationPanelWidget
::
refreshIndexWidget
()
{
QHelpIndexWidget
*
index
=
m_engine
->
indexWidget
();
index
->
filterIndices
(
QString
());
index
->
activateCurrentItem
();
m_index
->
filterIndices
(
keyword
);
// filter exactly, no wildcards
m_index
->
activateCurrentItem
();
// this internally emitts the QHelpIndexWidget::linkActivated signal
}
void
DocumentationPanelWidget
::
loadDocumentation
()
...
...
src/panelplugins/documentationpanel/documentationpanelwidget.h
View file @
fbe56da1
...
...
@@ -33,7 +33,8 @@ namespace Cantor
}
class
QHelpEngine
;
class
QLineEdit
;
class
QHelpIndexWidget
;
class
QStackedWidget
;
class
QUrl
;
class
QWebEngineView
;
...
...
@@ -55,16 +56,18 @@ class DocumentationPanelWidget : public QWidget
public:
Cantor
::
Session
*
m_session
=
nullptr
;
Q_SIGNALS:
void
activateBrowser
();
private
Q_SLOTS
:
void
displayHelp
(
const
QUrl
&
);
void
contextSensitiveHelp
(
const
QString
&
);
void
doSearch
();
void
refreshIndexWidget
();
private:
QHelpEngine
*
m_engine
=
nullptr
;
QWebEngineView
*
m_textBrowser
=
nullptr
;
QLineEdit
*
m_input
=
nullptr
;
QStackedWidget
*
m_displayArea
=
nullptr
;
QHelpIndexWidget
*
m_index
=
nullptr
;
QString
m_backend
;
};
...
...
@@ -73,7 +76,7 @@ class QtHelpSchemeHandler : public QWebEngineUrlSchemeHandler
{
Q_OBJECT
public:
public:
QtHelpSchemeHandler
(
QHelpEngine
*
helpEngine
)
:
m_HelpEngine
(
helpEngine
)
{
}
...
...
@@ -89,7 +92,7 @@ class QtHelpSchemeHandler : public QWebEngineUrlSchemeHandler
}
}
private:
private:
QHelpEngine
*
m_HelpEngine
;
};
...
...
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