summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/mainview.cpp96
-rw-r--r--src/mainview.h12
-rw-r--r--src/mainwindow.cpp4
-rw-r--r--src/tabbar.cpp58
-rw-r--r--src/tabbar.h8
5 files changed, 103 insertions, 75 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();
}
}
diff --git a/src/mainview.h b/src/mainview.h
index c2795048..f0fe183d 100644
--- a/src/mainview.h
+++ b/src/mainview.h
@@ -39,6 +39,9 @@
// KDE Includes
#include <KTabWidget>
+// Qt Includes
+#include <QtGui/QToolButton>
+
// Forward Declarations
class QUrl;
class QWebFrame;
@@ -78,6 +81,8 @@ public:
*
*/
void updateTabBar();
+
+ QToolButton *addTabButton() const;
void clear();
/**
@@ -137,10 +142,14 @@ private slots:
void windowCloseRequested();
+ void postLaunch();
+
protected:
virtual void resizeEvent(QResizeEvent *event);
private:
+ void updateTabButtonPosition();
+
/**
* This function creates (if not exists) and returns a QLabel
* with a loading QMovie.
@@ -158,6 +167,9 @@ private:
QString m_loadingGitPath;
+ // the new tab button
+ QToolButton *m_addTabButton;
+
int m_currentTabIndex;
QList<HistoryItem> m_recentlyClosedTabs;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index f079c8b9..76e75dcf 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -240,7 +240,7 @@ QSize MainWindow::sizeHint() const
}
-KActionCollection *MainWindow::actionCollection () const
+KActionCollection *MainWindow::actionCollection() const
{
return m_ac;
}
@@ -460,7 +460,7 @@ void MainWindow::setupSidePanel()
void MainWindow::slotUpdateConfiguration()
{
// ============== General ==================
- mainView()->updateTabBar();
+ m_view->updateTabBar();
// =========== Fonts ==============
QWebSettings *defaultSettings = QWebSettings::globalSettings();
diff --git a/src/tabbar.cpp b/src/tabbar.cpp
index 65a65f7e..b92c938a 100644
--- a/src/tabbar.cpp
+++ b/src/tabbar.cpp
@@ -64,7 +64,6 @@
TabBar::TabBar(MainView *parent)
: KTabBar(parent)
, m_parent(parent)
- , m_addTabButton(new QToolButton(this))
, m_currentTabPreview(-1)
{
setElideMode(Qt::ElideRight);
@@ -77,8 +76,6 @@ TabBar::TabBar(MainView *parent)
connect(this, SIGNAL(contextMenu(int, const QPoint &)), this, SLOT(slotContextMenuRequested(int, const QPoint &)));
connect(this, SIGNAL(emptyAreaContextMenu(const QPoint &)), this, SLOT(slotEmptyAreaContextMenu(const QPoint &)));
-
- QTimer::singleShot(0, this, SLOT(postLaunch()));
}
@@ -87,27 +84,9 @@ TabBar::~TabBar()
}
-void TabBar::postLaunch()
-{
- // 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);
-}
-
-
QSize TabBar::tabSizeHint(int index) const
{
- int buttonSize = m_addTabButton->size().width();
+ int buttonSize = m_parent->addTabButton()->size().width();
int tabBarWidth = m_parent->size().width() - buttonSize;
int baseWidth = m_parent->sizeHint().width()/BASE_WIDTH_DIVISOR;
int minWidth = m_parent->sizeHint().width()/MIN_WIDTH_DIVISOR;
@@ -243,6 +222,7 @@ void TabBar::leaveEvent(QEvent *event)
KTabBar::leaveEvent(event);
}
+
void TabBar::mousePressEvent(QMouseEvent *event)
{
// just close tab on middle mouse click
@@ -253,40 +233,6 @@ void TabBar::mousePressEvent(QMouseEvent *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);
- }
-}
-
-
void TabBar::slotContextMenuRequested(int tab, const QPoint &pos)
{
m_actualIndex = tab;
diff --git a/src/tabbar.h b/src/tabbar.h
index f68528b8..1601b3b6 100644
--- a/src/tabbar.h
+++ b/src/tabbar.h
@@ -42,7 +42,6 @@
// Forward Declarations
class QPoint;
-class QToolButton;
class QMouseEvent;
class QEvent;
@@ -63,7 +62,6 @@ public:
~TabBar();
void showTabPreview(int tab);
- void updateNewTabButton();
signals:
void cloneTab(int index);
@@ -77,6 +75,7 @@ protected:
* Added to fix tab dimension
*/
virtual QSize tabSizeHint(int index) const;
+
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void leaveEvent(QEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
@@ -87,14 +86,13 @@ private slots:
void closeOtherTabs();
void reloadTab();
- void postLaunch();
-
void slotContextMenuRequested(int, const QPoint &);
void slotEmptyAreaContextMenu(const QPoint &);
private:
+ friend class MainView;
+
MainView *m_parent;
- QToolButton *m_addTabButton;
/**
* the index in which we are seeing a Context menu