1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

[ComboTabBar] Fixed right scroll button being hidden on resize

When resizing window and triggering overflow, right scroll button
was hidden until the next resize event.
This commit is contained in:
S. Razi Alavizadeh 2014-03-30 16:40:36 +02:00 committed by nowrep
parent b95da97904
commit b26d9b06ab
4 changed files with 42 additions and 36 deletions

View File

@ -41,6 +41,7 @@ ComboTabBar::ComboTabBar(QWidget* parent)
, m_mainTabBar(0)
, m_pinnedTabBar(0)
, m_mainBarOverFlowed(false)
, m_lastAppliedOverflow(false)
, m_usesScrollButtons(false)
{
m_mainTabBar = new TabBarHelper(this);
@ -328,6 +329,14 @@ void ComboTabBar::updateTabBars()
m_pinnedTabBar->update();
}
void ComboTabBar::emitOverFlowChanged()
{
if (m_mainBarOverFlowed != m_lastAppliedOverflow) {
emit overFlowChanged(m_mainBarOverFlowed);
m_lastAppliedOverflow = m_mainBarOverFlowed;
}
}
int ComboTabBar::count() const
{
return pinnedTabsCount() + m_mainTabBar->count();
@ -590,27 +599,6 @@ void ComboTabBar::wheelEvent(QWheelEvent* event)
}
}
void ComboTabBar::resizeEvent(QResizeEvent* event)
{
QWidget::resizeEvent(event);
// Handle overflowing eg. when entering fullscreen
if (m_mainBarOverFlowed != m_mainTabBarWidget->isOverflowed()) {
setMinimumWidths();
}
// Workaround for containers being hidden on very fast resizing
if (m_rightContainer->isVisible()) {
m_rightContainer->hide();
m_rightContainer->show();
}
if (m_leftContainer->isVisible()) {
m_leftContainer->hide();
m_leftContainer->show();
}
}
bool ComboTabBar::eventFilter(QObject* obj, QEvent* ev)
{
if (m_bluredBackground) {
@ -819,7 +807,7 @@ void ComboTabBar::setMinimumWidths()
if (realTabBarWidth <= width()) {
if (m_mainBarOverFlowed) {
m_mainBarOverFlowed = false;
emit overFlowChanged(false);
QTimer::singleShot(0, this, SLOT(emitOverFlowChanged()));
}
m_mainTabBar->useFastTabSizeHint(false);
@ -828,7 +816,7 @@ void ComboTabBar::setMinimumWidths()
else {
if (!m_mainBarOverFlowed) {
m_mainBarOverFlowed = true;
emit overFlowChanged(true);
QTimer::singleShot(0, this, SLOT(emitOverFlowChanged()));
}
// All tabs have now same width, we can use fast tabSizeHint
@ -1221,9 +1209,9 @@ TabBarScrollWidget::TabBarScrollWidget(QTabBar* tabBar, QWidget* parent)
setLayout(hLayout);
m_scrollArea->viewport()->setAutoFillBackground(false);
connect(m_scrollBar, SIGNAL(valueChanged(int)), this, SLOT(scrollBarValueChange()));
connect(m_scrollBar, SIGNAL(valueChanged(int)), this, SLOT(updateScrollButtonsState()));
scrollBarValueChange();
updateScrollButtonsState();
overFlowChanged(false);
}
@ -1297,7 +1285,7 @@ void TabBarScrollWidget::setUpLayout()
setFixedHeight(height);
}
void TabBarScrollWidget::scrollBarValueChange()
void TabBarScrollWidget::updateScrollButtonsState()
{
m_leftScrollButton->setEnabled(m_scrollBar->value() != m_scrollBar->minimum());
m_rightScrollButton->setEnabled(m_scrollBar->value() != m_scrollBar->maximum());
@ -1309,10 +1297,6 @@ void TabBarScrollWidget::overFlowChanged(bool overflowed)
m_leftScrollButton->setVisible(showScrollButtons);
m_rightScrollButton->setVisible(showScrollButtons);
if (showScrollButtons) {
m_scrollArea->resize(m_scrollArea->size());
}
}
void TabBarScrollWidget::scrollStart()
@ -1398,7 +1382,7 @@ void TabBarScrollWidget::setUsesScrollButtons(bool useButtons)
{
if (useButtons != m_usesScrollButtons) {
m_usesScrollButtons = useButtons;
scrollBarValueChange();
updateScrollButtonsState();
m_tabBar->setElideMode(m_tabBar->elideMode());
}
}
@ -1431,6 +1415,13 @@ void TabBarScrollWidget::mouseMoveEvent(QMouseEvent* event)
event->ignore();
}
void TabBarScrollWidget::resizeEvent(QResizeEvent* event)
{
QWidget::resizeEvent(event);
updateScrollButtonsState();
}
CloseButton::CloseButton(QWidget* parent)
: QAbstractButton(parent)

View File

@ -153,6 +153,7 @@ private slots:
void slotTabMoved(int from, int to);
void closeTabFromButton();
void updateTabBars();
void emitOverFlowChanged();
protected:
int mainTabBarWidth() const;
@ -162,7 +163,6 @@ protected:
void showEvent(QShowEvent* event);
void enterEvent(QEvent* event);
void leaveEvent(QEvent* event);
void resizeEvent(QResizeEvent* event);
bool eventFilter(QObject* obj, QEvent* ev);
virtual int comboTabBarPixelMetric(SizeType sizeType) const;
@ -191,6 +191,7 @@ private:
QString m_closeButtonsToolTip;
bool m_mainBarOverFlowed;
bool m_lastAppliedOverflow;
bool m_usesScrollButtons;
bool m_bluredBackground;
};
@ -287,12 +288,13 @@ public slots:
void setUpLayout();
private slots:
void scrollBarValueChange();
void overFlowChanged(bool overflowed);
void scrollStart();
void updateScrollButtonsState();
private:
void mouseMoveEvent(QMouseEvent* event);
void resizeEvent(QResizeEvent* event);
QTabBar* m_tabBar;
QScrollArea* m_scrollArea;

View File

@ -80,6 +80,7 @@ TabBar::TabBar(BrowserWindow* window, TabWidget* tabWidget)
setUsesScrollButtons(true);
setCloseButtonsToolTip(BrowserWindow::tr("Close Tab"));
connect(this, SIGNAL(scrollBarValueChanged(int)), this, SLOT(hideTabPreview()));
connect(this, SIGNAL(overFlowChanged(bool)), this, SLOT(overflowChanged(bool)));
}
void TabBar::loadSettings()
@ -170,6 +171,16 @@ void TabBar::contextMenuRequested(const QPoint &position)
m_window->action(QSL("Other/RestoreClosedTab"))->setEnabled(true);
}
void TabBar::overflowChanged(bool overflowed)
{
// Make sure close buttons on inactive tabs are hidden
// This is needed for when leaving fullscreen from non-overflowed to overflowed state
if (overflowed && m_showCloseOnInactive != 1) {
setTabsClosable(false);
showCloseButton(currentIndex());
}
}
void TabBar::closeAllButCurrent()
{
QMessageBox::StandardButton button = QMessageBox::question(this, tr("Close Tabs"), tr("Do you really want to close other tabs?"),
@ -197,7 +208,7 @@ QSize TabBar::tabSizeHint(int index, bool fast) const
QSize size = ComboTabBar::tabSizeHint(index);
// The overflowed tabs have similar size and we can use this fast method
// The overflowed tabs have same size and we can use this fast method
if (fast) {
size.setWidth(index >= pinnedTabsCount() ? MINIMUM_TAB_WIDTH : PINNED_TAB_WIDTH);
return size;

View File

@ -59,18 +59,20 @@ signals:
private slots:
void currentTabChanged(int index);
void contextMenuRequested(const QPoint &position);
void overflowChanged(bool overflowed);
void reloadTab() { emit reloadTab(m_clickedTab); }
void stopTab() { emit stopTab(m_clickedTab); }
void closeTab() { emit closeTab(m_clickedTab); }
void duplicateTab() { emit duplicateTab(m_clickedTab); }
void detachTab() { emit detachTab(m_clickedTab); }
void closeAllButCurrent();
void bookmarkTab();
void pinTab();
void closeCurrentTab();
void closeAllButCurrent();
void closeTabFromButton();
void showTabPreview(bool delayed = true);