From dd81e53fff6cfdccfa7459f6631182de4fbd8e3d Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 16 Feb 2011 18:09:34 +0100 Subject: This patch cleans up tabbar update: show/hide when ReKonfig::alwaysShowTabBar() is off and update tab button position. It also removes a "feature" introduced to hide/show tab button on tab moving: it has negative effects on tab middle click closing. Reviewed by: NOBODY (oops..) --- src/mainview.cpp | 86 +++++++++++++++++++++++++++----------------------------- src/mainview.h | 2 -- src/tabbar.cpp | 29 ++++--------------- src/tabbar.h | 1 - 4 files changed, 48 insertions(+), 70 deletions(-) (limited to 'src') diff --git a/src/mainview.cpp b/src/mainview.cpp index 1cf003e9..fe6413a1 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -58,11 +58,11 @@ MainView::MainView(MainWindow *parent) - : KTabWidget(parent) - , m_widgetBar(new StackedUrlBar(this)) - , m_addTabButton(0) - , m_currentTabIndex(0) - , m_parentWindow(parent) + : KTabWidget(parent) + , m_widgetBar(new StackedUrlBar(this)) + , m_addTabButton(0) + , m_currentTabIndex(0) + , m_parentWindow(parent) { // setting tabbar TabBar *tabBar = new TabBar(this); @@ -121,43 +121,6 @@ void MainView::postLaunch() } -void MainView::updateTabButtonPosition() -{ - static bool ButtonInCorner = false; - - int tabWidgetWidth = frameSize().width(); - int tabBarWidth = tabBar()->tabSizeHint(0).width() * tabBar()->count(); - - if (tabBarWidth + m_addTabButton->width() > tabWidgetWidth) - { - if (ButtonInCorner) - return; - setCornerWidget(m_addTabButton); - ButtonInCorner = true; - } - else - { - if (ButtonInCorner) - { - setCornerWidget(0); - // new window problem - if(count()>1) - m_addTabButton->show(); - ButtonInCorner = false; - } - - // detecting X position - int newPosX = tabBarWidth; - int tabWidthHint = tabBar()->tabSizeHint(0).width(); - if (tabWidthHint < sizeHint().width() / 4) - newPosX = tabWidgetWidth - m_addTabButton->width(); - - m_addTabButton->move(newPosX, 0); - m_addTabButton->show(); - } -} - - TabBar *MainView::tabBar() const { TabBar *tabBar = qobject_cast(KTabWidget::tabBar()); @@ -179,21 +142,56 @@ WebTab *MainView::currentWebTab() const void MainView::updateTabBar() { - if (ReKonfig::alwaysShowTabBar() || tabBar()->count() > 1) + if (ReKonfig::alwaysShowTabBar() || count() > 1) { if (tabBar()->isHidden()) { tabBar()->show(); + } + + // this to ensure tab button visibility also on new window creation + if(m_addTabButton->isHidden()) + { m_addTabButton->show(); } + } else { tabBar()->hide(); m_addTabButton->hide(); + return; + } + + // update tab button position + static bool ButtonInCorner = false; + + int tabWidgetWidth = frameSize().width(); + int tabBarWidth = tabBar()->tabSizeHint(0).width() * tabBar()->count(); + + if (tabBarWidth + m_addTabButton->width() > tabWidgetWidth) + { + if (ButtonInCorner) + return; + setCornerWidget(m_addTabButton); + ButtonInCorner = true; } + else + { + if (ButtonInCorner) + { + setCornerWidget(0); + ButtonInCorner = false; + } - updateTabButtonPosition(); + // detecting X position + int newPosX = tabBarWidth; + int tabWidthHint = tabBar()->tabSizeHint(0).width(); + if (tabWidthHint < sizeHint().width() / 4) + newPosX = tabWidgetWidth - m_addTabButton->width(); + + m_addTabButton->move(newPosX, 0); + } } diff --git a/src/mainview.h b/src/mainview.h index 00975206..6af4012c 100644 --- a/src/mainview.h +++ b/src/mainview.h @@ -161,8 +161,6 @@ protected: virtual void resizeEvent(QResizeEvent *event); private: - void updateTabButtonPosition(); - /** * This function creates (if not exists) and returns a QLabel * with a loading QMovie. diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 6b12a794..be20ecd3 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -70,12 +70,12 @@ static inline QByteArray highlightPropertyName(int index) TabBar::TabBar(QWidget *parent) - : KTabBar(parent) - , m_actualIndex(-1) - , m_currentTabPreviewIndex(-1) - , m_isFirstTimeOnTab(true) - , m_tabHighlightEffect(new TabHighlightEffect(this)) - , m_animationMapper(new QSignalMapper(this)) + : KTabBar(parent) + , m_actualIndex(-1) + , m_currentTabPreviewIndex(-1) + , m_isFirstTimeOnTab(true) + , m_tabHighlightEffect(new TabHighlightEffect(this)) + , m_animationMapper(new QSignalMapper(this)) { setElideMode(Qt::ElideRight); @@ -230,13 +230,6 @@ void TabBar::mouseMoveEvent(QMouseEvent *event) return; } - if (event->buttons() & Qt::LeftButton) - { - // hide addNewTabButton when moving tabs - MainView *view = qobject_cast(parent()); - QTimer::singleShot(200, view->addTabButton(), SLOT(hide())); - } - KTabBar::mouseMoveEvent(event); if (ReKonfig::hoveringTabOption() == 0) @@ -357,15 +350,6 @@ void TabBar::emptyAreaContextMenu(const QPoint &pos) } -void TabBar::mouseReleaseEvent(QMouseEvent *event) -{ - MainView *mv = qobject_cast(parent()); - QTimer::singleShot(200, mv->addTabButton(), SLOT(show())); - - KTabBar::mouseReleaseEvent(event); -} - - void TabBar::tabRemoved(int index) { if (ReKonfig::hoveringTabOption() == 0) @@ -462,4 +446,3 @@ void TabBar::removeAnimation(int index) m_animationMapper->removeMappings(anim); delete anim; } - diff --git a/src/tabbar.h b/src/tabbar.h index d0d9d3e6..ca6adbba 100644 --- a/src/tabbar.h +++ b/src/tabbar.h @@ -82,7 +82,6 @@ protected: virtual void mouseMoveEvent(QMouseEvent *event); virtual void leaveEvent(QEvent *event); virtual void mousePressEvent(QMouseEvent *event); - virtual void mouseReleaseEvent(QMouseEvent *event); virtual void tabRemoved(int index); private slots: -- cgit v1.2.1