mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
EditWindow: support middle click to close a tab
This commit is contained in:
parent
a53fdf27b6
commit
33f4631f91
@ -143,6 +143,9 @@ confirm_reload_folder=true
|
||||
; Whether double click on a tab to close it
|
||||
double_click_close_tab=true
|
||||
|
||||
; Whether middle click on a tab to close it
|
||||
middle_click_close_tab=true
|
||||
|
||||
; Whether enable tools dock widget
|
||||
tools_dock_checked=true
|
||||
|
||||
|
@ -232,6 +232,9 @@ void VConfigManager::initialize()
|
||||
m_doubleClickCloseTab = getConfigFromSettings("global",
|
||||
"double_click_close_tab").toBool();
|
||||
|
||||
m_middleClickCloseTab = getConfigFromSettings("global",
|
||||
"middle_click_close_tab").toBool();
|
||||
|
||||
int tmpStartupPageMode = getConfigFromSettings("global",
|
||||
"startup_page_type").toInt();
|
||||
if (tmpStartupPageMode < (int)StartupPageType::Invalid
|
||||
|
@ -378,6 +378,8 @@ public:
|
||||
|
||||
bool getDoubleClickCloseTab() const;
|
||||
|
||||
bool getMiddleClickClostTab() const;
|
||||
|
||||
StartupPageType getStartupPageType() const;
|
||||
void setStartupPageType(StartupPageType p_type);
|
||||
|
||||
@ -873,6 +875,9 @@ private:
|
||||
// Whether double click on a tab to close it.
|
||||
bool m_doubleClickCloseTab;
|
||||
|
||||
// Whether middle click on a tab to close it.
|
||||
bool m_middleClickCloseTab;
|
||||
|
||||
// Type of the pages to open on startup.
|
||||
StartupPageType m_startupPageType;
|
||||
|
||||
@ -2085,6 +2090,11 @@ inline bool VConfigManager::getDoubleClickCloseTab() const
|
||||
return m_doubleClickCloseTab;
|
||||
}
|
||||
|
||||
inline bool VConfigManager::getMiddleClickClostTab() const
|
||||
{
|
||||
return m_middleClickCloseTab;
|
||||
}
|
||||
|
||||
inline StartupPageType VConfigManager::getStartupPageType() const
|
||||
{
|
||||
return m_startupPageType;
|
||||
|
@ -47,6 +47,10 @@ VEditWindow::VEditWindow(VEditArea *editArea, QWidget *parent)
|
||||
|
||||
QTabBar *bar = tabBar();
|
||||
bar->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
if (g_config->getMiddleClickClostTab()) {
|
||||
bar->installEventFilter(this);
|
||||
}
|
||||
|
||||
connect(bar, &QTabBar::customContextMenuRequested,
|
||||
this, &VEditWindow::tabbarContextMenuRequested);
|
||||
|
||||
@ -1305,3 +1309,19 @@ QVector<TabNavigationInfo> VEditWindow::getTabsNavigationInfo() const
|
||||
|
||||
return infos;
|
||||
}
|
||||
|
||||
bool VEditWindow::eventFilter(QObject *p_obj, QEvent *p_event)
|
||||
{
|
||||
if (p_obj == tabBar() && p_event->type() == QEvent::MouseButtonRelease) {
|
||||
QMouseEvent *me = static_cast<QMouseEvent *>(p_event);
|
||||
if (me->button() == Qt::MiddleButton) {
|
||||
// Close current tab.
|
||||
int idx = tabBar()->tabAt(me->pos());
|
||||
if (idx != -1) {
|
||||
closeTab(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QTabWidget::eventFilter(p_obj, p_event);
|
||||
}
|
||||
|
@ -110,6 +110,8 @@ protected:
|
||||
// Drop the data.
|
||||
void dropEvent(QDropEvent *p_event) Q_DECL_OVERRIDE;
|
||||
|
||||
bool eventFilter(QObject *p_obj, QEvent *p_event) Q_DECL_OVERRIDE;
|
||||
|
||||
signals:
|
||||
// Status of current VEditTab has update.
|
||||
void tabStatusUpdated(const VEditTabInfo &p_info);
|
||||
|
Loading…
x
Reference in New Issue
Block a user