Skip to content

Commit

Permalink
Restored the tooltip of the tab closing button
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
veloman-yunkan committed Mar 20, 2024
1 parent 9960964 commit 1daefcc
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/tabbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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++) {
Expand Down Expand Up @@ -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, [=]() {
Expand Down

0 comments on commit 1daefcc

Please sign in to comment.