From 1daefccfbd62654643996a39a9705d3d7c5555ef Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Thu, 14 Mar 2024 13:48:24 +0400 Subject: [PATCH] Restored the tooltip of the tab closing button Notes: - The `getAction()` helper function was introduced in order to keep the line length within the 80 chars limit and was applied to other usages of `KiwixApp::getAction()` too. - The tooltip includes the keyboard shortcut which closes only the current tab but the tooltip is the same for all the tabs. --- src/tabbar.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 3ebba23..b265965 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -13,6 +13,15 @@ class QMenu; #define QUITIFNULL(VIEW) if (nullptr==(VIEW)) { return; } #define CURRENTIFNULL(VIEW) if(nullptr==VIEW) { VIEW = currentZimView();} +namespace +{ + +QAction* getAction(KiwixApp::Actions action) { + return KiwixApp::instance()->getAction(action); +} + +} // unnamed namespace + TabBar::TabBar(QWidget *parent) : QTabBar(parent) { @@ -24,21 +33,20 @@ TabBar::TabBar(QWidget *parent) : setMovable(true); setIconSize(QSize(30, 30)); connect(this, &QTabBar::currentChanged, this, &TabBar::onCurrentChanged, Qt::QueuedConnection); - auto app = KiwixApp::instance(); - connect(app->getAction(KiwixApp::NextTabAction), &QAction::triggered, this, &TabBar::moveToNextTab); - connect(app->getAction(KiwixApp::PreviousTabAction), &QAction::triggered, this, &TabBar::moveToPreviousTab); - connect(app->getAction(KiwixApp::CloseCurrentTabAction), &QAction::triggered, + connect(getAction(KiwixApp::NextTabAction), &QAction::triggered, this, &TabBar::moveToNextTab); + connect(getAction(KiwixApp::PreviousTabAction), &QAction::triggered, this, &TabBar::moveToPreviousTab); + connect(getAction(KiwixApp::CloseCurrentTabAction), &QAction::triggered, this, [=]() { this->closeTab(currentIndex()); }); - connect(app->getAction(KiwixApp::OpenHomePageAction), &QAction::triggered, + connect(getAction(KiwixApp::OpenHomePageAction), &QAction::triggered, this, [=]() { auto current = this->currentWebView(); QUITIFNULL(current); current->setUrl("zim://" + current->zimId() + ".zim/"); }); - connect(app->getAction(KiwixApp::SettingAction), &QAction::triggered, + connect(getAction(KiwixApp::SettingAction), &QAction::triggered, this, &TabBar::openOrSwitchToSettingsTab); for (int i = 0 ; i <= 9 ; i++) { @@ -128,6 +136,7 @@ void TabBar::setCloseTabButton(int index) QToolButton *tb = new QToolButton(this); QAction *a = new QAction(QIcon(":/icons/close.svg"), gt("close-tab"), tb); + a->setToolTip(getAction(KiwixApp::CloseCurrentTabAction)->toolTip()); tb->setDefaultAction(a); setTabButton(index, QTabBar::RightSide, tb); connect(tb, &QToolButton::triggered, this, [=]() {