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); auto webView = new JupyterWebView(this);
ui->tabWidget->addTab(webView, "Tab"); ui->tabWidget->addTab(webView, "Tab");
webView->setTabWidget(ui->tabWidget);
return webView; return webView;
} }
#endif #endif
@ -73,6 +74,15 @@ void JupyterWidget::creationFailed()
JupyterWebView::JupyterWebView(JupyterWidget *mainWidget, QWidget *parent) : QWebEngineView(parent) JupyterWebView::JupyterWebView(JupyterWidget *mainWidget, QWidget *parent) : QWebEngineView(parent)
{ {
this->mainWidget = mainWidget; 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) QWebEngineView *JupyterWebView::createWindow(QWebEnginePage::WebWindowType type)
@ -85,6 +95,27 @@ QWebEngineView *JupyterWebView::createWindow(QWebEnginePage::WebWindowType type)
return nullptr; 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
#endif #endif

View File

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