Skip to content

Commit

Permalink
Merge pull request #656 from kiwix/540-part1-title-icon-changed
Browse files Browse the repository at this point in the history
Partial fix of #540: do not emit others object signals.
  • Loading branch information
kelson42 authored Jul 8, 2021
2 parents d8ac53d + d8e585d commit 7fe5134
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
12 changes: 12 additions & 0 deletions src/tabbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,18 @@ void TabBar::fullScreenRequested(QWebEngineFullScreenRequest request)
}
}

void TabBar::on_webview_titleChanged(const QString& title)
{
ZimView* tab = qobject_cast<ZimView*>(sender()->parent());
if (! tab)
return;

setTitleOf(title, tab);

if (currentZimView() == tab)
emit currentTitleChanged(title);
}

void TabBar::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::MiddleButton) {
Expand Down
4 changes: 1 addition & 3 deletions src/tabbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
class TabBar : public QTabBar
{
Q_OBJECT
Q_PROPERTY(QString currentZimId READ currentZimId NOTIFY currentZimIdChanged)

public:
TabBar(QWidget* parent=nullptr);
void setStackedWidget(QStackedWidget* widget);
Expand Down Expand Up @@ -54,13 +52,13 @@ class TabBar : public QTabBar
signals:
void webActionEnabledChanged(QWebEnginePage::WebAction action, bool enabled);
void libraryPageDisplayed(bool displayed);
void currentZimIdChanged(const QString& zimId);
void currentTitleChanged(const QString& title);

public slots:
void closeTab(int index);
void onCurrentChanged(int index);
void fullScreenRequested(QWebEngineFullScreenRequest request);
void on_webview_titleChanged(const QString& title);

private:
QStackedWidget* mp_stackedWidget;
Expand Down
19 changes: 3 additions & 16 deletions src/zimview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ZimView::ZimView(TabBar *tabBar, QWidget *parent)
layout->addWidget(mp_findInPageBar);
layout->setContentsMargins(0,0,0,0);
layout->setSpacing(0);
setLayout(layout);
setLayout(layout); // now 'mp_webView' has 'this' as the parent QObject
mp_findInPageBar->hide();
auto app = KiwixApp::instance();
connect(app->getAction(KiwixApp::ZoomInAction), &QAction::triggered,
Expand Down Expand Up @@ -44,23 +44,10 @@ ZimView::ZimView(TabBar *tabBar, QWidget *parent)
settingsManager->deleteSettings(key);
});
connect(mp_webView->page(), &QWebEnginePage::fullScreenRequested, mp_tabBar, &TabBar::fullScreenRequested);
connect(mp_webView, &WebView::titleChanged, this,
[=](const QString& str) {
mp_tabBar->setTitleOf(str, this);
if (mp_tabBar->currentZimView() != this) {
return;
}
emit mp_tabBar->currentTitleChanged(str);
});
connect(mp_webView, &WebView::titleChanged, mp_tabBar, &TabBar::on_webview_titleChanged);
connect(mp_webView, &WebView::iconChanged, this,
[=](const QIcon& icon) { mp_tabBar->setIconOf(icon, this); });
connect(mp_webView, &WebView::zimIdChanged, this,
[=](const QString& zimId) {
if (mp_tabBar->currentZimView() != this) {
return;
}
emit mp_tabBar->currentZimIdChanged(zimId);
});

connect(mp_webView->page()->action(QWebEnginePage::Back), &QAction::changed,
[=]() {
if (mp_tabBar->currentZimView() != this) {
Expand Down
3 changes: 0 additions & 3 deletions src/zimview.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ class ZimView : public QWidget
FindInPageBar *getFindInPageBar() { return mp_findInPageBar; }
void openFindInPageBar();

signals:

private:
WebView *mp_webView;
TabBar *mp_tabBar;
FindInPageBar *mp_findInPageBar;

};

#endif // ZIMVIEW_H

0 comments on commit 7fe5134

Please sign in to comment.