Jupyter Tab Titles

This commit is contained in:
Florian Märkl 2018-03-02 17:56:59 +01:00
parent 7914deb887
commit a30579a536
2 changed files with 39 additions and 0 deletions

View File

@ -33,6 +33,7 @@ JupyterWebView *JupyterWidget::createNewTab()
{
auto webView = new JupyterWebView(this);
ui->tabWidget->addTab(webView, "Tab");
webView->setTabWidget(ui->tabWidget);
return webView;
}
#endif
@ -73,6 +74,15 @@ void JupyterWidget::creationFailed()
JupyterWebView::JupyterWebView(JupyterWidget *mainWidget, QWidget *parent) : QWebEngineView(parent)
{
this->mainWidget = mainWidget;
this->tabWidget = nullptr;
connect(this, &QWebEngineView::titleChanged, this, &JupyterWebView::onTitleChanged);
}
void JupyterWebView::setTabWidget(QTabWidget *tabWidget)
{
this->tabWidget = tabWidget;
updateTitle();
}
QWebEngineView *JupyterWebView::createWindow(QWebEnginePage::WebWindowType type)
@ -85,6 +95,27 @@ QWebEngineView *JupyterWebView::createWindow(QWebEnginePage::WebWindowType type)
return nullptr;
}
}
void JupyterWebView::onTitleChanged(const QString &)
{
updateTitle();
}
void JupyterWebView::updateTitle()
{
if (!tabWidget)
{
return;
}
QString title = this->title();
if (title.isEmpty())
{
title = tr("Jupyter");
}
tabWidget->setTabText(tabWidget->indexOf(this), title);
}
#endif
#endif

View File

@ -48,11 +48,19 @@ Q_OBJECT
public:
JupyterWebView(JupyterWidget *mainWidget, QWidget *parent = nullptr);
void setTabWidget(QTabWidget *tabWidget);
protected:
QWebEngineView *createWindow(QWebEnginePage::WebWindowType type) override;
private slots:
void onTitleChanged(const QString &title);
private:
JupyterWidget *mainWidget;
QTabWidget *tabWidget;
void updateTitle();
};
#endif