summaryrefslogtreecommitdiff
path: root/src/mainview.cpp
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2009-10-29 11:26:42 +0100
committerAndrea Diamantini <adjam7@gmail.com>2009-10-29 11:26:42 +0100
commit228bd405a579f1653462809dae12cb48f2df941c (patch)
tree1a62c2c4bd57acdf35a233deed20e88141656345 /src/mainview.cpp
parentimported userAgentFromUrl method from KWebKit (diff)
downloadrekonq-228bd405a579f1653462809dae12cb48f2df941c.tar.xz
Fixing hide/show tab bar and flickering new tabs.
That happened because of the code moving from mainview to tabbar (my fault) (tabbar cannot draw and be drawn..)
Diffstat (limited to 'src/mainview.cpp')
-rw-r--r--src/mainview.cpp96
1 files changed, 84 insertions, 12 deletions
diff --git a/src/mainview.cpp b/src/mainview.cpp
index 0956e3ff..04ede24c 100644
--- a/src/mainview.cpp
+++ b/src/mainview.cpp
@@ -68,6 +68,7 @@ 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
@@ -97,13 +98,82 @@ MainView::MainView(QWidget *parent)
// current page index changing
connect(this, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentChanged(int)));
+ QTimer::singleShot(0, this, SLOT(postLaunch()));
+}
+
+
+MainView::~MainView()
+{
+}
+
+
+void MainView::postLaunch()
+{
// Session Manager
connect (this, SIGNAL(tabsChanged()), Application::sessionManager(), SLOT(saveSession()));
+
+ // Find the correct MainWindow of this tab button
+ MainWindowList list = Application::instance()->mainWindowList();
+ Q_FOREACH(QPointer<MainWindow> w, list)
+ {
+ if (w->isAncestorOf(this))
+ {
+ m_addTabButton->setDefaultAction(w->actionByName("new_tab"));
+ break;
+ }
+ }
+
+ m_addTabButton->setAutoRaise(true);
+ m_addTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly);
}
-MainView::~MainView()
+void MainView::updateTabButtonPosition()
{
+ kDebug() << "updating new tab button position..";
+
+ static bool ButtonInCorner = false;
+
+ int tabWidgetWidth = frameSize().width();
+ int tabBarWidth = m_tabBar->tabSizeHint(0).width()*m_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;
+ }
+
+ // detecting X position
+ int newPosX = tabBarWidth;
+ int tabWidthHint = m_tabBar->tabSizeHint(0).width();
+ if (tabWidthHint < sizeHint().width()/4)
+ newPosX = tabWidgetWidth - m_addTabButton->width();
+
+ // detecting Y position
+ int newPosY = m_tabBar->height() - m_addTabButton->height();
+ if(newPosY < 0)
+ newPosY = 5; // this hardcoded value is used in just ONE situation:
+ // the first time an user changes the "Always Show Tab Bar" settings
+ // try some better fixes, if you can :D
+
+ m_addTabButton->move(newPosX, newPosY);
+ }
+}
+
+
+QToolButton *MainView::addTabButton() const
+{
+ return m_addTabButton;
}
@@ -138,23 +208,25 @@ void MainView::updateTabBar()
if (m_tabBar->isHidden())
{
m_tabBar->show();
+ m_addTabButton->show();
}
- m_tabBar->updateNewTabButton();
+ updateTabButtonPosition();
+ return;
+ }
+
+ if (m_tabBar->count() == 1)
+ {
+ m_tabBar->hide();
+ m_addTabButton->hide();
}
else
{
- if (m_tabBar->count() == 1)
- {
- m_tabBar->hide();
- }
- else
+ if (m_tabBar->isHidden())
{
- if (m_tabBar->isHidden())
- {
- m_tabBar->show();
- }
- m_tabBar->updateNewTabButton();
+ m_tabBar->show();
+ m_addTabButton->show();
}
+ updateTabButtonPosition();
}
}