summaryrefslogtreecommitdiff
path: root/src/tabbar.cpp
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2009-08-27 13:54:14 +0200
committerAndrea Diamantini <adjam7@gmail.com>2009-08-27 13:54:14 +0200
commitc039fcb3c2be73bf6c95012b3e5f5f53ef1b42e3 (patch)
tree18f3e854e494f9cbccc9a2c83afdf2f30996319d /src/tabbar.cpp
parentRemoved setHistoryMenu function (diff)
downloadrekonq-c039fcb3c2be73bf6c95012b3e5f5f53ef1b42e3.tar.xz
New tab button code improvements.
Patch from Johannes Zellner (thanks)
Diffstat (limited to 'src/tabbar.cpp')
-rw-r--r--src/tabbar.cpp38
1 files changed, 36 insertions, 2 deletions
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);
+}