EditWindow: support middle click to close a tab

This commit is contained in:
Le Tan 2018-08-14 21:09:18 +08:00
parent a53fdf27b6
commit 33f4631f91
5 changed files with 38 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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);
}

View File

@ -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);