summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mainview.cpp24
-rw-r--r--src/mainview.h6
-rw-r--r--src/mainwindow.cpp2
-rw-r--r--src/tabbar.cpp83
-rw-r--r--src/tabbar.h4
5 files changed, 56 insertions, 63 deletions
diff --git a/src/mainview.cpp b/src/mainview.cpp
index ba7b720e..a0b0c6e7 100644
--- a/src/mainview.cpp
+++ b/src/mainview.cpp
@@ -131,7 +131,7 @@ int MainView::webViewIndex(WebView *webView) const
}
-void MainView::showTabBar()
+void MainView::updateTabBar()
{
if (ReKonfig::alwaysShowTabBar())
{
@@ -139,6 +139,7 @@ void MainView::showTabBar()
{
m_tabBar->show();
}
+ m_tabBar->updateNewTabButton();
}
else
{
@@ -152,6 +153,7 @@ void MainView::showTabBar()
{
m_tabBar->show();
}
+ m_tabBar->updateNewTabButton();
}
}
}
@@ -283,15 +285,15 @@ WebView *MainView::newWebView(bool focused, bool nearParent)
insertTab(currentIndex() + 1, webView, i18n("(Untitled)"));
else
addTab(webView, i18n("(Untitled)"));
-
+
+ updateTabBar();
+
if (focused)
{
setCurrentWidget(webView);
}
emit tabsChanged();
-
- showTabBar();
return webView;
}
@@ -369,7 +371,7 @@ void MainView::slotCloseOtherTabs(int index)
slotCloseTab(i);
}
- showTabBar();
+ updateTabBar();
}
@@ -383,7 +385,7 @@ void MainView::slotCloneTab(int index)
WebView *tab = newWebView();
tab->setUrl(webView(index)->url());
- showTabBar();
+ updateTabBar();
}
@@ -418,6 +420,7 @@ void MainView::slotCloseTab(int index)
QWidget *webView = widget(index);
removeTab(index);
+ updateTabBar(); // UI operation: do it ASAP!!
webView->deleteLater(); // webView is scheduled for deletion.
emit tabsChanged();
@@ -426,8 +429,6 @@ void MainView::slotCloseTab(int index)
{
currentWebView()->setFocus();
}
-
- showTabBar();
}
@@ -578,3 +579,10 @@ KUrl::List MainView::recentlyClosedTabs()
{
return m_recentlyClosedTabs;
}
+
+
+void MainView::resizeEvent(QResizeEvent *event)
+{
+ updateTabBar();
+ KTabWidget::resizeEvent(event);
+} \ No newline at end of file
diff --git a/src/mainview.h b/src/mainview.h
index 96710919..db4c455d 100644
--- a/src/mainview.h
+++ b/src/mainview.h
@@ -76,7 +76,7 @@ public:
* "Always Show TabBar" option
*
*/
- void showTabBar();
+ void updateTabBar();
void clear();
/**
@@ -136,7 +136,9 @@ private slots:
void windowCloseRequested();
-
+protected:
+ virtual void resizeEvent(QResizeEvent *event);
+
private:
/**
* This function creates (if not exists) and returns a QLabel
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 62f82e58..6dd1024b 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -451,7 +451,7 @@ void MainWindow::setupSidePanel()
void MainWindow::slotUpdateConfiguration()
{
// ============== General ==================
- mainView()->showTabBar();
+ mainView()->updateTabBar();
// =========== Fonts ==============
QWebSettings *defaultSettings = QWebSettings::globalSettings();
diff --git a/src/tabbar.cpp b/src/tabbar.cpp
index 94f2c274..bde1e63e 100644
--- a/src/tabbar.cpp
+++ b/src/tabbar.cpp
@@ -89,11 +89,6 @@ TabBar::~TabBar()
void TabBar::postLaunch()
{
- // HACK this is used to fix add tab button position
- QToolButton *secondAddTabButton = new QToolButton(this);
- secondAddTabButton->setAutoRaise(true);
- secondAddTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly);
-
// Find the correct MainWindow of this tab button
MainWindowList list = Application::instance()->mainWindowList();
Q_FOREACH(QPointer<MainWindow> w, list)
@@ -101,18 +96,12 @@ void TabBar::postLaunch()
if (w->isAncestorOf(this))
{
m_addTabButton->setDefaultAction(w->actionByName("new_tab"));
- secondAddTabButton->setDefaultAction(w->actionByName("new_tab"));
break;
}
}
m_addTabButton->setAutoRaise(true);
m_addTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly);
- m_addTabButton->show();
-
- // stupid tabbar, that's what you gain...
- m_parent->setCornerWidget(secondAddTabButton);
- m_parent->cornerWidget()->hide();
}
@@ -147,13 +136,6 @@ QSize TabBar::tabSizeHint(int index) const
}
-void TabBar::tabLayoutChange()
-{
- setTabButtonPosition();
- KTabBar::tabLayoutChange();
-}
-
-
void TabBar::contextMenuRequested(const QPoint &position)
{
KMenu menu;
@@ -205,37 +187,6 @@ void TabBar::reloadTab()
}
-void TabBar::setTabButtonPosition()
-{
- if(count() >= MIN_WIDTH_DIVISOR - 1)
- {
- if(m_addTabButton->isVisible())
- {
- m_addTabButton->hide();
- m_parent->cornerWidget()->show();
- }
- return;
- }
-
- if(m_addTabButton->isHidden())
- {
- m_addTabButton->show();
- m_parent->cornerWidget()->hide();
- }
-
- int tabWidgetWidth = frameSize().width();
- int tabBarWidth = tabSizeHint(0).width()*count();
- int newPosY = height() - m_addTabButton->height();
- int newPosX = tabWidgetWidth - m_addTabButton->width();
-
- if (tabBarWidth + m_addTabButton->width() < tabWidgetWidth)
- newPosX = tabBarWidth;
-
- m_addTabButton->move(newPosX, newPosY);
- m_addTabButton->show();
-}
-
-
void TabBar::showTabPreview(int tab)
{
WebView *view = m_parent->webView(tab);
@@ -316,3 +267,37 @@ void TabBar::leaveEvent(QEvent *event)
KTabBar::leaveEvent(event);
}
+
+
+void TabBar::updateNewTabButton()
+{
+ static bool ButtonInCorner = false;
+
+ int tabWidgetWidth = m_parent->frameSize().width();
+ int tabBarWidth = tabSizeHint(0).width() * count();
+
+ if (tabBarWidth + m_addTabButton->width() > tabWidgetWidth)
+ {
+ if(ButtonInCorner)
+ return;
+ m_parent->setCornerWidget(m_addTabButton);
+ ButtonInCorner = true;
+ }
+ else
+ {
+ if(ButtonInCorner)
+ {
+ m_parent->setCornerWidget(0);
+ m_addTabButton->show();
+ ButtonInCorner = false;
+ }
+
+ int newPosX = tabWidgetWidth - m_addTabButton->width();
+ int newPosY = height() - m_addTabButton->height();
+
+ if (tabBarWidth + m_addTabButton->width() < tabWidgetWidth)
+ newPosX = tabBarWidth;
+
+ m_addTabButton->move(newPosX, newPosY);
+ }
+}
diff --git a/src/tabbar.h b/src/tabbar.h
index dd08f7b8..580021c4 100644
--- a/src/tabbar.h
+++ b/src/tabbar.h
@@ -63,6 +63,7 @@ public:
~TabBar();
void showTabPreview(int tab);
+ void updateNewTabButton();
signals:
void cloneTab(int index);
@@ -76,7 +77,6 @@ protected:
* Added to fix tab dimension
*/
virtual QSize tabSizeHint(int index) const;
- virtual void tabLayoutChange();
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void leaveEvent(QEvent *event);
@@ -89,8 +89,6 @@ private slots:
void postLaunch();
private:
- void setTabButtonPosition();
-
MainView *m_parent;
QToolButton *m_addTabButton;