diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2009-08-27 13:54:14 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2009-08-27 13:54:14 +0200 |
commit | c039fcb3c2be73bf6c95012b3e5f5f53ef1b42e3 (patch) | |
tree | 18f3e854e494f9cbccc9a2c83afdf2f30996319d /src | |
parent | Removed setHistoryMenu function (diff) | |
download | rekonq-c039fcb3c2be73bf6c95012b3e5f5f53ef1b42e3.tar.xz |
New tab button code improvements.
Patch from Johannes Zellner (thanks)
Diffstat (limited to 'src')
-rw-r--r-- | src/mainview.cpp | 76 | ||||
-rw-r--r-- | src/mainview.h | 9 | ||||
-rw-r--r-- | src/tabbar.cpp | 38 | ||||
-rw-r--r-- | src/tabbar.h | 6 |
4 files changed, 51 insertions, 78 deletions
diff --git a/src/mainview.cpp b/src/mainview.cpp index 832a0683..3fc8856b 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -66,7 +66,6 @@ MainView::MainView(QWidget *parent) : KTabWidget(parent) , m_urlBar(new UrlBar(this)) , m_tabBar(new TabBar(this)) - , m_addTabButton(new QToolButton(this)) , m_currentTabIndex(0) { // setting tabbar @@ -93,8 +92,6 @@ MainView::MainView(QWidget *parent) setTabsClosable(true); connect(m_tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(slotCloseTab(int))); - - QTimer::singleShot(0, this, SLOT(postLaunch())); } @@ -103,60 +100,12 @@ MainView::~MainView() } -void MainView::postLaunch() -{ - m_addTabButton->setDefaultAction(Application::instance()->mainWindow()->actionByName("new_tab")); - m_addTabButton->setAutoRaise(true); - m_addTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly); -} - - -void MainView::addTabButtonPosition() -{ - 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); - m_addTabButton->show(); - ButtonInCorner = false; - } - - int newPos = tabWidgetWidth - m_addTabButton->width(); - m_addTabButton->move(newPos, 0); - - if (tabBar()->tabSizeHint(0).width()>=sizeHint().width()/4) - m_addTabButton->move(tabBarWidth, 0); - else - m_addTabButton->move(tabWidgetWidth - m_addTabButton->width(), 0); - } -} - - TabBar *MainView::tabBar() const { return m_tabBar; } -QToolButton *MainView::addTabButton() const -{ - return m_addTabButton; -} - - UrlBar *MainView::urlBar() const { return m_urlBar; @@ -182,22 +131,20 @@ void MainView::showTabBar() if (m_tabBar->isHidden()) { m_tabBar->show(); - m_addTabButton->show(); } - return; - } - - if (m_tabBar->count() == 1) - { - m_tabBar->hide(); - m_addTabButton->hide(); } else { - if (m_tabBar->isHidden()) + if (m_tabBar->count() == 1) { - m_tabBar->show(); - m_addTabButton->show(); + m_tabBar->hide(); + } + else + { + if (m_tabBar->isHidden()) + { + m_tabBar->show(); + } } } } @@ -332,7 +279,6 @@ WebView *MainView::newWebView(bool focused) emit tabsChanged(); showTabBar(); - addTabButtonPosition(); return webView; } @@ -405,7 +351,6 @@ void MainView::slotCloseOtherTabs(int index) } showTabBar(); - addTabButtonPosition(); } @@ -420,7 +365,6 @@ void MainView::slotCloneTab(int index) tab->setUrl(webView(index)->url()); showTabBar(); - addTabButtonPosition(); } @@ -463,7 +407,6 @@ void MainView::slotCloseTab(int index) } showTabBar(); - addTabButtonPosition(); } @@ -623,7 +566,6 @@ void MainView::mouseDoubleClickEvent(QMouseEvent *event) //WARNING Need to be fi void MainView::resizeEvent(QResizeEvent *event) { - addTabButtonPosition(); KTabWidget::resizeEvent(event); } diff --git a/src/mainview.h b/src/mainview.h index ae6019b7..06956d5e 100644 --- a/src/mainview.h +++ b/src/mainview.h @@ -38,7 +38,6 @@ #include <KTabWidget> // Qt Includes -#include <QtGui/QToolButton> // Forward Declarations class QUrl; @@ -67,7 +66,6 @@ public: UrlBar *urlBar() const; WebView *webView(int index) const; - QToolButton *addTabButton() const; TabBar *tabBar() const; WebView *currentWebView() const; @@ -128,17 +126,12 @@ private slots: void windowCloseRequested(); - void postLaunch(); - protected: virtual void mouseDoubleClickEvent(QMouseEvent *event); virtual void resizeEvent(QResizeEvent *event); private: - - void addTabButtonPosition(); - /** * This function creates (if not exists) and returns a QLabel * with a loading QMovie. @@ -155,8 +148,6 @@ private: TabBar *m_tabBar; QString m_loadingGitPath; - - QToolButton *m_addTabButton; int m_currentTabIndex; }; diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 64367263..d676af55 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -47,11 +47,13 @@ #include <QtCore/QString> #include <QtGui/QFont> +#include <QtGui/QToolButton> TabBar::TabBar(QWidget *parent) : KTabBar(parent) , m_parent(parent) + , m_addTabButton(new QToolButton(this)) { setElideMode(Qt::ElideRight); setContextMenuPolicy(Qt::CustomContextMenu); @@ -59,6 +61,8 @@ TabBar::TabBar(QWidget *parent) setMovable(true); connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &))); + + QTimer::singleShot(0, this, SLOT(postLaunch())); } @@ -67,11 +71,20 @@ TabBar::~TabBar() } +void TabBar::postLaunch() +{ + m_addTabButton->setDefaultAction(Application::instance()->mainWindow()->actionByName("new_tab")); + m_addTabButton->setAutoRaise(true); + m_addTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly); + m_addTabButton->show(); +} + + QSize TabBar::tabSizeHint(int index) const { //TODO Create a SuperTabWidget class - int buttonSize = ((MainView *)m_parent)->addTabButton()->size().width(); + int buttonSize = m_addTabButton->size().width(); int tabBarWidth = m_parent->size().width() - buttonSize; int baseWidth = m_parent->sizeHint().width()/4; int minWidth = m_parent->sizeHint().width()/8; @@ -83,7 +96,7 @@ QSize TabBar::tabSizeHint(int index) const } else { - if (tabBarWidth/count()>minWidth) + if (count() > 0 && tabBarWidth/count()>minWidth) { w = tabBarWidth/count(); } @@ -100,6 +113,13 @@ QSize TabBar::tabSizeHint(int index) const } +void TabBar::tabLayoutChange() +{ + setTabButtonPosition(); + QTabBar::tabLayoutChange(); +} + + void TabBar::contextMenuRequested(const QPoint &position) { KMenu menu; @@ -149,3 +169,17 @@ void TabBar::reloadTab() { emit reloadTab(m_actualIndex); } + + +void TabBar::setTabButtonPosition() +{ + int tabWidgetWidth = frameSize().width(); + int tabBarWidth = tabSizeHint(0).width()*count(); + int newPosY = height()/2.0 - m_addTabButton->height()/2.0; + int newPosX = tabWidgetWidth - m_addTabButton->width(); + + if (tabBarWidth + m_addTabButton->width() < tabWidgetWidth) + newPosX = tabBarWidth; + + m_addTabButton->move(newPosX, newPosY); +} diff --git a/src/tabbar.h b/src/tabbar.h index 854469b4..a86ba4d6 100644 --- a/src/tabbar.h +++ b/src/tabbar.h @@ -35,6 +35,7 @@ // Forward Declarations class QPoint; +class QToolButton; /** * Tab bar with a few more features such as @@ -63,6 +64,7 @@ protected: * Added to fix tab dimension */ virtual QSize tabSizeHint(int index) const; + virtual void tabLayoutChange(); private slots: void cloneTab(); @@ -70,11 +72,15 @@ private slots: void closeOtherTabs(); void reloadTab(); void contextMenuRequested(const QPoint &position); + void postLaunch(); private: friend class MainView; + void setTabButtonPosition(); + QWidget *m_parent; + QToolButton *m_addTabButton; /** * the index in which we are seeing a Context menu |