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.
This commit is contained in:
Veloman Yunkan 2024-03-14 13:48:24 +04:00
parent 99609644d0
commit 1daefccfbd

View File

@ -13,6 +13,15 @@ class QMenu;
#define QUITIFNULL(VIEW) if (nullptr==(VIEW)) { return; } #define QUITIFNULL(VIEW) if (nullptr==(VIEW)) { return; }
#define CURRENTIFNULL(VIEW) if(nullptr==VIEW) { VIEW = currentZimView();} #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) : TabBar::TabBar(QWidget *parent) :
QTabBar(parent) QTabBar(parent)
{ {
@ -24,21 +33,20 @@ TabBar::TabBar(QWidget *parent) :
setMovable(true); setMovable(true);
setIconSize(QSize(30, 30)); setIconSize(QSize(30, 30));
connect(this, &QTabBar::currentChanged, this, &TabBar::onCurrentChanged, Qt::QueuedConnection); connect(this, &QTabBar::currentChanged, this, &TabBar::onCurrentChanged, Qt::QueuedConnection);
auto app = KiwixApp::instance();
connect(app->getAction(KiwixApp::NextTabAction), &QAction::triggered, this, &TabBar::moveToNextTab); connect(getAction(KiwixApp::NextTabAction), &QAction::triggered, this, &TabBar::moveToNextTab);
connect(app->getAction(KiwixApp::PreviousTabAction), &QAction::triggered, this, &TabBar::moveToPreviousTab); connect(getAction(KiwixApp::PreviousTabAction), &QAction::triggered, this, &TabBar::moveToPreviousTab);
connect(app->getAction(KiwixApp::CloseCurrentTabAction), &QAction::triggered, connect(getAction(KiwixApp::CloseCurrentTabAction), &QAction::triggered,
this, [=]() { this, [=]() {
this->closeTab(currentIndex()); this->closeTab(currentIndex());
}); });
connect(app->getAction(KiwixApp::OpenHomePageAction), &QAction::triggered, connect(getAction(KiwixApp::OpenHomePageAction), &QAction::triggered,
this, [=]() { this, [=]() {
auto current = this->currentWebView(); auto current = this->currentWebView();
QUITIFNULL(current); QUITIFNULL(current);
current->setUrl("zim://" + current->zimId() + ".zim/"); current->setUrl("zim://" + current->zimId() + ".zim/");
}); });
connect(app->getAction(KiwixApp::SettingAction), &QAction::triggered, connect(getAction(KiwixApp::SettingAction), &QAction::triggered,
this, &TabBar::openOrSwitchToSettingsTab); this, &TabBar::openOrSwitchToSettingsTab);
for (int i = 0 ; i <= 9 ; i++) { for (int i = 0 ; i <= 9 ; i++) {
@ -128,6 +136,7 @@ void TabBar::setCloseTabButton(int index)
QToolButton *tb = new QToolButton(this); QToolButton *tb = new QToolButton(this);
QAction *a = new QAction(QIcon(":/icons/close.svg"), gt("close-tab"), tb); QAction *a = new QAction(QIcon(":/icons/close.svg"), gt("close-tab"), tb);
a->setToolTip(getAction(KiwixApp::CloseCurrentTabAction)->toolTip());
tb->setDefaultAction(a); tb->setDefaultAction(a);
setTabButton(index, QTabBar::RightSide, tb); setTabButton(index, QTabBar::RightSide, tb);
connect(tb, &QToolButton::triggered, this, [=]() { connect(tb, &QToolButton::triggered, this, [=]() {