mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
Set the tab's text to the title of the webView.
The `titleChanged` signal is emitted twice: - At beggining of loading with the Url of the page. - Once the parsing is done and the `<title></title>` html tag has been found.
This commit is contained in:
parent
81766be447
commit
cb21a6816e
@ -9,6 +9,8 @@ KTabWidget::KTabWidget(QWidget *parent) :
|
|||||||
KiwixWebView* KTabWidget::createNewTab(bool setCurrent)
|
KiwixWebView* KTabWidget::createNewTab(bool setCurrent)
|
||||||
{
|
{
|
||||||
KiwixWebView* webView = new KiwixWebView();
|
KiwixWebView* webView = new KiwixWebView();
|
||||||
|
QObject::connect(webView, &KiwixWebView::titleChanged, this,
|
||||||
|
[=](const QString& str) { setTitleOf(webView, str); });
|
||||||
// Ownership of webview is passed to the tabWidget
|
// Ownership of webview is passed to the tabWidget
|
||||||
addTab(webView, "");
|
addTab(webView, "");
|
||||||
if (setCurrent) {
|
if (setCurrent) {
|
||||||
@ -25,3 +27,13 @@ void KTabWidget::openUrl(std::shared_ptr<kiwix::Reader> reader, const QUrl& url,
|
|||||||
}
|
}
|
||||||
webView->setUrl(url);
|
webView->setUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KTabWidget::setTitleOf(KiwixWebView* webView, const QString& title)
|
||||||
|
{
|
||||||
|
if (title.startsWith("zim://")) {
|
||||||
|
auto url = QUrl(title);
|
||||||
|
setTabText(indexOf(webView), url.path());
|
||||||
|
} else {
|
||||||
|
setTabText(indexOf(webView), title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -13,6 +13,7 @@ public:
|
|||||||
|
|
||||||
KiwixWebView* createNewTab(bool setCurrent);
|
KiwixWebView* createNewTab(bool setCurrent);
|
||||||
void openUrl(std::shared_ptr<kiwix::Reader> reader, const QUrl &url, bool newTab);
|
void openUrl(std::shared_ptr<kiwix::Reader> reader, const QUrl &url, bool newTab);
|
||||||
|
void setTitleOf(KiwixWebView* webView, const QString& title);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KTABWIDGET_H
|
#endif // KTABWIDGET_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user