fix tabbar of the edit area in macOS

1. revert a3b83b7f81192bdbeabb1ba8a7eed57beb4 to avoid flashing;
2. Explicitly specify usesScrollButtons in VEditWindow;
This commit is contained in:
Le Tan 2017-03-17 20:58:54 -07:00
parent 045d6f0241
commit 94ad4adc1c
2 changed files with 2 additions and 35 deletions

View File

@ -17,12 +17,13 @@ VEditWindow::VEditWindow(VNote *vnote, VEditArea *editArea, QWidget *parent)
initTabActions(); initTabActions();
setupCornerWidget(); setupCornerWidget();
// Explicit speficy in macOS.
setUsesScrollButtons(true);
setTabsClosable(true); setTabsClosable(true);
setMovable(true); setMovable(true);
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
QTabBar *bar = tabBar(); QTabBar *bar = tabBar();
bar->installEventFilter(this);
bar->setContextMenuPolicy(Qt::CustomContextMenu); bar->setContextMenuPolicy(Qt::CustomContextMenu);
connect(bar, &QTabBar::customContextMenuRequested, connect(bar, &QTabBar::customContextMenuRequested,
this, &VEditWindow::tabbarContextMenuRequested); 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() VEditTab *VEditWindow::currentEditTab()
{ {
int idx = currentIndex(); int idx = currentIndex();

View File

@ -49,7 +49,6 @@ public:
protected: protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
signals: signals:
void tabStatusChanged(const VFile *p_file, const VEditTab *p_editTab, bool p_editMode); 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 generateTooltip(const VFile *p_file) const;
inline QString generateTabText(const QString &p_name, bool p_modified) const; inline QString generateTabText(const QString &p_name, bool p_modified) const;
bool canRemoveSplit(); bool canRemoveSplit();
// If the scroller of the tabBar() is visible
bool scrollerVisible() const;
void setLeftCornerWidgetVisible(bool p_visible);
VNote *vnote; VNote *vnote;
VEditArea *m_editArea; VEditArea *m_editArea;