From d8635e957ca585ac137f61f6acb1c824791fdcc0 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Mon, 30 Aug 2021 20:59:50 +0800 Subject: [PATCH] MainWindow: support tooltip for tab bar of dock widgets --- src/data/extra/docs/en/welcome.md | 2 +- src/widgets/mainwindow.cpp | 34 +++++++++++++++++++++++++++++++ src/widgets/mainwindow.h | 6 ++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/data/extra/docs/en/welcome.md b/src/data/extra/docs/en/welcome.md index de337292..75a5a621 100644 --- a/src/data/extra/docs/en/welcome.md +++ b/src/data/extra/docs/en/welcome.md @@ -1,4 +1,4 @@ -# Welcome To VNote +# Welcome to VNote A pleasant note-taking platform. For more information, please visit [**VNote's Home Page**](https://vnotex.github.io/vnote) or [Home Page on Gitee](https://tamlok.gitee.io/vnote). diff --git a/src/widgets/mainwindow.cpp b/src/widgets/mainwindow.cpp index 9e438f22..54ed9104 100644 --- a/src/widgets/mainwindow.cpp +++ b/src/widgets/mainwindow.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include "toolbox.h" #include "notebookexplorer.h" @@ -806,6 +808,11 @@ void MainWindow::updateDockWidgetTabBar() { QBitArray tabifiedDocks(m_docks.size(), false); Q_FOREACH(QTabBar* tabBar, this->findChildren(QString(), Qt::FindDirectChildrenOnly)) { + if (!m_tabBarsMonitored.contains(tabBar)) { + m_tabBarsMonitored.insert(tabBar); + tabBar->installEventFilter(this); + } + tabBar->setDrawBase(false); const int sz = ConfigMgr::getInst().getCoreConfig().getDocksTabBarIconSize(); @@ -958,3 +965,30 @@ void MainWindow::checkForUpdates() } }); } + +bool MainWindow::eventFilter(QObject *p_obj, QEvent *p_event) +{ + if (p_event->type() == QEvent::ToolTip) { + // The QTabBar of the tabified dock widgets does not show tooltip due to Qt's internal implementation. + auto helpEve = static_cast(p_event); + auto tabBar = static_cast(p_obj); + int idx = tabBar->tabAt(helpEve->pos()); + bool done = false; + if (idx > -1) { + auto dock = reinterpret_cast(tabBar->tabData(idx).toULongLong()); + if (dock) { + done = true; + QToolTip::showText(helpEve->globalPos(), dock->property(c_propertyDockTitle).toString()); + } + } + + if (!done) { + QToolTip::hideText(); + p_event->ignore(); + } + + return true; + } + + return QMainWindow::eventFilter(p_obj, p_event); +} diff --git a/src/widgets/mainwindow.h b/src/widgets/mainwindow.h index b7fabe1a..b18bfa76 100644 --- a/src/widgets/mainwindow.h +++ b/src/widgets/mainwindow.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "toolbarhelper.h" #include "statusbarhelper.h" @@ -88,6 +89,8 @@ namespace vnotex void changeEvent(QEvent *p_event) Q_DECL_OVERRIDE; + bool eventFilter(QObject *p_obj, QEvent *p_event) Q_DECL_OVERRIDE; + private slots: void closeOnQuit(); @@ -212,6 +215,9 @@ namespace vnotex QTimer *m_tipsTimer = nullptr; QStringList m_visibleDocksBeforeExpand; + + // We need to install event filter to the tabbar of tabified dock widgets. + QSet m_tabBarsMonitored; }; } // ns vnotex