mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
MainWindow: support tooltip for tab bar of dock widgets
This commit is contained in:
parent
e4edee269b
commit
d8635e957c
@ -1,4 +1,4 @@
|
|||||||
# Welcome To VNote
|
# Welcome to VNote
|
||||||
A pleasant note-taking platform.
|
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).
|
For more information, please visit [**VNote's Home Page**](https://vnotex.github.io/vnote) or [Home Page on Gitee](https://tamlok.gitee.io/vnote).
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
#include <QWindowStateChangeEvent>
|
#include <QWindowStateChangeEvent>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QBitArray>
|
#include <QBitArray>
|
||||||
|
#include <QHelpEvent>
|
||||||
|
#include <QToolTip>
|
||||||
|
|
||||||
#include "toolbox.h"
|
#include "toolbox.h"
|
||||||
#include "notebookexplorer.h"
|
#include "notebookexplorer.h"
|
||||||
@ -806,6 +808,11 @@ void MainWindow::updateDockWidgetTabBar()
|
|||||||
{
|
{
|
||||||
QBitArray tabifiedDocks(m_docks.size(), false);
|
QBitArray tabifiedDocks(m_docks.size(), false);
|
||||||
Q_FOREACH(QTabBar* tabBar, this->findChildren<QTabBar*>(QString(), Qt::FindDirectChildrenOnly)) {
|
Q_FOREACH(QTabBar* tabBar, this->findChildren<QTabBar*>(QString(), Qt::FindDirectChildrenOnly)) {
|
||||||
|
if (!m_tabBarsMonitored.contains(tabBar)) {
|
||||||
|
m_tabBarsMonitored.insert(tabBar);
|
||||||
|
tabBar->installEventFilter(this);
|
||||||
|
}
|
||||||
|
|
||||||
tabBar->setDrawBase(false);
|
tabBar->setDrawBase(false);
|
||||||
|
|
||||||
const int sz = ConfigMgr::getInst().getCoreConfig().getDocksTabBarIconSize();
|
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<QHelpEvent *>(p_event);
|
||||||
|
auto tabBar = static_cast<QTabBar *>(p_obj);
|
||||||
|
int idx = tabBar->tabAt(helpEve->pos());
|
||||||
|
bool done = false;
|
||||||
|
if (idx > -1) {
|
||||||
|
auto dock = reinterpret_cast<QDockWidget *>(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);
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QBitArray>
|
#include <QBitArray>
|
||||||
|
#include <QSet>
|
||||||
|
|
||||||
#include "toolbarhelper.h"
|
#include "toolbarhelper.h"
|
||||||
#include "statusbarhelper.h"
|
#include "statusbarhelper.h"
|
||||||
@ -88,6 +89,8 @@ namespace vnotex
|
|||||||
|
|
||||||
void changeEvent(QEvent *p_event) Q_DECL_OVERRIDE;
|
void changeEvent(QEvent *p_event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
bool eventFilter(QObject *p_obj, QEvent *p_event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void closeOnQuit();
|
void closeOnQuit();
|
||||||
|
|
||||||
@ -212,6 +215,9 @@ namespace vnotex
|
|||||||
QTimer *m_tipsTimer = nullptr;
|
QTimer *m_tipsTimer = nullptr;
|
||||||
|
|
||||||
QStringList m_visibleDocksBeforeExpand;
|
QStringList m_visibleDocksBeforeExpand;
|
||||||
|
|
||||||
|
// We need to install event filter to the tabbar of tabified dock widgets.
|
||||||
|
QSet<QTabBar *> m_tabBarsMonitored;
|
||||||
};
|
};
|
||||||
} // ns vnotex
|
} // ns vnotex
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user