Hi there,
I was working on the tabbar placement, sometime last week.
(My girlfriend was missing the feature ;-) )
With the attached patch I introduced the option to show the Tabbar at the top
or at the bottom of the TabBarWidget.
Also this NewTabButton-thingy is now a child of the TabBar class so all the
position handling and showing is much easier and also more consistent.
Johannes
diff --git a/src/mainview.cpp b/src/mainview.cpp
index 9dfa797..8d43d1a 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;
@@ -177,27 +126,30 @@ int MainView::webViewIndex(WebView *webView) const
void MainView::showTabBar()
{
+ if (ReKonfig::tabBarAtTop())
+ setTabPosition(QTabWidget::North);
+ else
+ setTabPosition(QTabWidget::South);
+
if (ReKonfig::alwaysShowTabBar())
{
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();
+ }
}
}
}
@@ -333,7 +285,6 @@ WebView *MainView::newWebView(bool focused)
emit tabsChanged();
showTabBar();
- addTabButtonPosition();
return webView;
}
@@ -406,7 +357,6 @@ void MainView::slotCloseOtherTabs(int index)
}
showTabBar();
- addTabButtonPosition();
}
@@ -421,7 +371,6 @@ void MainView::slotCloneTab(int index)
tab->setUrl(webView(index)->url());
showTabBar();
- addTabButtonPosition();
}
@@ -464,7 +413,6 @@ void MainView::slotCloseTab(int index)
}
showTabBar();
- addTabButtonPosition();
}
@@ -622,7 +570,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 ae6019b..06956d5 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/settings_general.ui b/src/settings_general.ui
index 2390435..2d415b4 100644
--- a/src/settings_general.ui
+++ b/src/settings_general.ui
@@ -94,6 +94,13 @@
</property>
</widget>
</item>
+ <item>
+ <widget class="QCheckBox" name="kcfg_tabBarAtTop">
+ <property name="text">
+ <string>Show tab bar on top</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
diff --git a/src/tabbar.cpp b/src/tabbar.cpp
index f3449d2..311ef29 100644
--- a/src/tabbar.cpp
+++ b/src/tabbar.cpp
@@ -48,11 +48,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);
@@ -60,6 +62,8 @@ TabBar::TabBar(QWidget *parent)
setMovable(true);
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this,
SLOT(contextMenuRequested(const QPoint &)));
+
+ QTimer::singleShot(0, this, SLOT(postLaunch()));
}
@@ -68,11 +72,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;
@@ -84,7 +97,7 @@ QSize TabBar::tabSizeHint(int index) const
}
else
{
- if (tabBarWidth/count()>minWidth)
+ if (count() > 0 && tabBarWidth/count()>minWidth)
{
w = tabBarWidth/count();
}
@@ -101,6 +114,13 @@ QSize TabBar::tabSizeHint(int index) const
}
+void TabBar::tabLayoutChange()
+{
+ setTabButtonPosition();
+ QTabBar::tabLayoutChange();
+}
+
+
void TabBar::contextMenuRequested(const QPoint &position)
{
KMenu menu;
@@ -150,3 +170,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 854469b..a86ba4d 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
_______________________________________________
rekonq mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/rekonq