From 94ad4adc1cbda222cc547e9f0913c1cf178acd25 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Fri, 17 Mar 2017 20:58:54 -0700 Subject: [PATCH] fix tabbar of the edit area in macOS 1. revert a3b83b7f81192bdbeabb1ba8a7eed57beb4 to avoid flashing; 2. Explicitly specify usesScrollButtons in VEditWindow; --- src/veditwindow.cpp | 33 ++------------------------------- src/veditwindow.h | 4 ---- 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/src/veditwindow.cpp b/src/veditwindow.cpp index 10c1ef1d..2f30ce2a 100644 --- a/src/veditwindow.cpp +++ b/src/veditwindow.cpp @@ -17,12 +17,13 @@ VEditWindow::VEditWindow(VNote *vnote, VEditArea *editArea, QWidget *parent) initTabActions(); setupCornerWidget(); + // Explicit speficy in macOS. + setUsesScrollButtons(true); setTabsClosable(true); setMovable(true); setContextMenuPolicy(Qt::CustomContextMenu); QTabBar *bar = tabBar(); - bar->installEventFilter(this); bar->setContextMenuPolicy(Qt::CustomContextMenu); connect(bar, &QTabBar::customContextMenuRequested, this, &VEditWindow::tabbarContextMenuRequested); @@ -595,36 +596,6 @@ void VEditWindow::updateNotebookInfo(const VNotebook *p_notebook) } } -bool VEditWindow::eventFilter(QObject *watched, QEvent *event) -{ - if (event->type() == QEvent::Resize) { - setLeftCornerWidgetVisible(scrollerVisible()); - } - return QTabWidget::eventFilter(watched, event); -} - -bool VEditWindow::scrollerVisible() const -{ - QTabBar *bar = tabBar(); - int barWidth = rect().width() - leftBtn->width() - rightBtn->width(); - int nrTab = count(); - int tabsWidth = 0; - for (int i = 0; i < nrTab; ++i) { - tabsWidth += bar->tabRect(i).width(); - } - return tabsWidth > barWidth; -} - -void VEditWindow::setLeftCornerWidgetVisible(bool p_visible) -{ - if (p_visible) { - setCornerWidget(leftBtn, Qt::TopLeftCorner); - leftBtn->setVisible(true); - } else { - setCornerWidget(NULL, Qt::TopLeftCorner); - } -} - VEditTab *VEditWindow::currentEditTab() { int idx = currentIndex(); diff --git a/src/veditwindow.h b/src/veditwindow.h index c7ceeb95..5a1cb100 100644 --- a/src/veditwindow.h +++ b/src/veditwindow.h @@ -49,7 +49,6 @@ public: protected: void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE; signals: void tabStatusChanged(const VFile *p_file, const VEditTab *p_editTab, bool p_editMode); @@ -91,9 +90,6 @@ private: inline QString generateTooltip(const VFile *p_file) const; inline QString generateTabText(const QString &p_name, bool p_modified) const; bool canRemoveSplit(); - // If the scroller of the tabBar() is visible - bool scrollerVisible() const; - void setLeftCornerWidgetVisible(bool p_visible); VNote *vnote; VEditArea *m_editArea;