summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2009-10-09 02:08:01 +0200
committerAndrea Diamantini <adjam7@gmail.com>2009-10-09 02:08:01 +0200
commit9ca2eb6a61ea5307923cab67c789e1c0ba2086d5 (patch)
treec9e79ffcd2c0e2a777bdd883757cfba8af5586b4
parent- Some things in the right position (diff)
downloadrekonq-9ca2eb6a61ea5307923cab67c789e1c0ba2086d5.tar.xz
HUGE COMMIT
1) moved lionel preview implementation to tabbar class. This to simplify MainView management AND to use TabBar::tabSizeHint(). Now previews are of the same width of the tab :) 2) cleaned a bit TabBar code 3) fixed scrollButton bug, via a "rude" HACK: an hidden toolbutton shown when tabs are more than.. a number! 4) Changed tabbar::tabsizehint implementation using 2 stupid constants: BASE_WIDTH_DIVISOR and MIN_WIDTH_DIVISOR. Just play with them to modify tab dimension and resize quite all :) Good night, guys!
-rw-r--r--src/mainview.cpp80
-rw-r--r--src/mainview.h13
-rw-r--r--src/tabbar.cpp124
-rw-r--r--src/tabbar.h23
4 files changed, 139 insertions, 101 deletions
diff --git a/src/mainview.cpp b/src/mainview.cpp
index c77efe83..0abf6996 100644
--- a/src/mainview.cpp
+++ b/src/mainview.cpp
@@ -42,7 +42,6 @@
#include "webview.h"
#include "sessionmanager.h"
#include "homepage.h"
-#include "websnap.h"
// KDE Includes
#include <KUrl>
@@ -63,9 +62,6 @@
#include <QtGui/QLabel>
#include <QtGui/QMovie>
#include <QtGui/QWidget>
-#include <QtGui/QMouseEvent>
-#include <QtGui/QPainter>
-#include <QtGui/QVBoxLayout>
MainView::MainView(QWidget *parent)
@@ -73,7 +69,6 @@ MainView::MainView(QWidget *parent)
, m_urlBar(new UrlBar(this))
, m_tabBar(new TabBar(this))
, m_currentTabIndex(0)
- , m_currentTabPreview(-1)
{
// setting tabbar
setTabBar(m_tabBar);
@@ -574,78 +569,3 @@ QLabel *MainView::animatedLoading(int index, bool addMovie)
m_tabBar->setTabButton(index, QTabBar::LeftSide, label);
return label;
}
-
-
-void MainView::resizeEvent(QResizeEvent *event)
-{
- KTabWidget::resizeEvent(event);
-}
-
-
-void MainView::mouseMoveEvent(QMouseEvent *event)
-{
- //Find the tab under the mouse
- int i = 0;
- int tab = -1;
- while (i<count() && tab==-1)
- {
- if (m_tabBar->tabRect(i).contains(event->pos())) tab = i;
- i++;
- }
-
- //if found and not the current tab then show tab preview
- if (tab!=-1 && tab!=m_tabBar->currentIndex() && m_currentTabPreview!=tab)
- {
- showTabPreview(tab);
- m_currentTabPreview=tab;
- }
-
- //if current tab or not found then hide previous tab preview
- if (tab==m_tabBar->currentIndex() || tab==-1)
- {
- if ( m_previewPopup)
- {
- m_previewPopup->hide();
- }
- m_currentTabPreview=-1;
- }
-
- KTabWidget::mouseMoveEvent(event);
-}
-
-void MainView::leaveEvent(QEvent *event)
-{
- //if leave tabwidget then hide previous tab preview
- if ( m_previewPopup)
- {
- m_previewPopup->hide();
- }
- m_currentTabPreview=-1;
- KTabWidget::leaveEvent(event);
-}
-
-
-void MainView::showTabPreview(int tab)
-{
- int w=200;
- int h=w*((0.0+webView(tab)->height())/webView(tab)->width());
-
- //delete previous tab preview
- if (m_previewPopup)
- {
- delete m_previewPopup;
- }
-
- m_previewPopup = new KPassivePopup(this);
- m_previewPopup->setFrameShape(QFrame::StyledPanel);
- m_previewPopup->setFrameShadow(QFrame::Plain);
- m_previewPopup->setFixedSize(w, h);
- QLabel *l = new QLabel();
- l->setPixmap(WebSnap::renderPreview(*(webView(tab)->page()), w, h));
- m_previewPopup->setView(l);
- m_previewPopup->layout()->setAlignment(Qt::AlignTop);
- m_previewPopup->layout()->setMargin(0);
-
- QPoint pos(m_tabBar->tabRect(tab).x(),m_tabBar->tabRect(tab).y()+m_tabBar->tabRect(tab).height());
- m_previewPopup->show(mapToGlobal(pos));
-}
diff --git a/src/mainview.h b/src/mainview.h
index f8c94032..48e0b58b 100644
--- a/src/mainview.h
+++ b/src/mainview.h
@@ -47,8 +47,6 @@ class QMouseEvent;
class TabBar;
class UrlBar;
-class KPassivePopup;
-
/**
* This class represent rekonq Main View. It contains all WebViews and a stack widget
@@ -91,9 +89,6 @@ public:
*/
WebView *newWebView(bool focused = true, bool nearParent = false);
- virtual void mouseMoveEvent(QMouseEvent *event);
- virtual void leaveEvent(QEvent *event);
- void showTabPreview(int tab);
signals:
// tab widget signals
@@ -139,11 +134,8 @@ private slots:
void webViewUrlChanged(const QUrl &url);
void windowCloseRequested();
-
-protected:
-
- virtual void resizeEvent(QResizeEvent *event);
+
private:
/**
* This function creates (if not exists) and returns a QLabel
@@ -163,9 +155,6 @@ private:
QString m_loadingGitPath;
int m_currentTabIndex;
-
- QPointer<KPassivePopup> m_previewPopup;
- int m_currentTabPreview;
};
#endif // MAINVIEW_H
diff --git a/src/tabbar.cpp b/src/tabbar.cpp
index 651265d1..815a153d 100644
--- a/src/tabbar.cpp
+++ b/src/tabbar.cpp
@@ -36,24 +36,35 @@
#include "mainwindow.h"
#include "urlbar.h"
#include "webview.h"
+#include "websnap.h"
// KDE Includes
#include <KShortcut>
#include <KStandardShortcut>
#include <KDebug>
#include <KGlobalSettings>
+#include <KPassivePopup>
// Qt Includes
#include <QtCore/QString>
#include <QtGui/QFont>
#include <QtGui/QToolButton>
+#include <QtGui/QLabel>
+#include <QtGui/QMouseEvent>
+#include <QtGui/QPainter>
+#include <QtGui/QVBoxLayout>
-TabBar::TabBar(QWidget *parent)
+#define BASE_WIDTH_DIVISOR 4
+#define MIN_WIDTH_DIVISOR 8
+
+
+TabBar::TabBar(MainView *parent)
: KTabBar(parent)
, m_parent(parent)
, m_addTabButton(new QToolButton(this))
+ , m_currentTabPreview(-1)
{
setElideMode(Qt::ElideRight);
@@ -77,6 +88,11 @@ 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)
@@ -84,6 +100,7 @@ void TabBar::postLaunch()
if (w->isAncestorOf(this))
{
m_addTabButton->setDefaultAction(w->actionByName("new_tab"));
+ secondAddTabButton->setDefaultAction(w->actionByName("new_tab"));
break;
}
}
@@ -91,17 +108,19 @@ void TabBar::postLaunch()
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();
}
QSize TabBar::tabSizeHint(int index) const
{
- //TODO Create a SuperTabWidget class
-
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;
+ int baseWidth = m_parent->sizeHint().width()/BASE_WIDTH_DIVISOR;
+ int minWidth = m_parent->sizeHint().width()/MIN_WIDTH_DIVISOR;
int w;
if (baseWidth*count()<tabBarWidth)
@@ -187,13 +206,106 @@ 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()/2.0 - m_addTabButton->height()/2.0;
+ 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);
+
+ int w = tabSizeHint(tab).width();
+ int h = w*((0.0 + view->height())/view->width());
+
+ //delete previous tab preview
+ if (m_previewPopup)
+ {
+ delete m_previewPopup;
+ }
+
+ m_previewPopup = new KPassivePopup(this);
+ m_previewPopup->setFrameShape(QFrame::StyledPanel);
+ m_previewPopup->setFrameShadow(QFrame::Plain);
+ m_previewPopup->setFixedSize(w, h);
+ QLabel *l = new QLabel();
+ l->setPixmap(WebSnap::renderPreview(*(view->page()), w, h));
+ m_previewPopup->setView(l);
+ m_previewPopup->layout()->setAlignment(Qt::AlignTop);
+ m_previewPopup->layout()->setMargin(0);
+
+ QPoint pos( tabRect(tab).x() , tabRect(tab).y() + tabRect(tab).height() );
+ m_previewPopup->show(mapToGlobal(pos));
+}
+
+
+void TabBar::mouseMoveEvent(QMouseEvent *event)
+{
+ //Find the tab under the mouse
+ int i = 0;
+ int tab = -1;
+ while (i<count() && tab==-1)
+ {
+ if (tabRect(i).contains(event->pos()))
+ {
+ tab = i;
+ }
+ i++;
+ }
+
+ //if found and not the current tab then show tab preview
+ if (tab != -1 && tab != currentIndex() && m_currentTabPreview != tab)
+ {
+ showTabPreview(tab);
+ m_currentTabPreview = tab;
+ }
+
+ //if current tab or not found then hide previous tab preview
+ if (tab==currentIndex() || tab==-1)
+ {
+ if ( m_previewPopup)
+ {
+ m_previewPopup->hide();
+ }
+ m_currentTabPreview = -1;
+ }
+
+ KTabBar::mouseMoveEvent(event);
+}
+
+
+void TabBar::leaveEvent(QEvent *event)
+{
+ //if leave tabwidget then hide previous tab preview
+ if ( m_previewPopup)
+ {
+ m_previewPopup->hide();
+ }
+ m_currentTabPreview = -1;
+
+ KTabBar::leaveEvent(event);
}
diff --git a/src/tabbar.h b/src/tabbar.h
index 56e2d230..dd08f7b8 100644
--- a/src/tabbar.h
+++ b/src/tabbar.h
@@ -31,12 +31,22 @@
#define TABBAR_H
+// Local Includes
+#include "mainview.h"
+
+// Qt Includes
+#include <QPointer>
+
// KDE Includes
#include <KTabBar>
// Forward Declarations
class QPoint;
class QToolButton;
+class QMouseEvent;
+class QEvent;
+
+class KPassivePopup;
/**
@@ -49,9 +59,11 @@ class TabBar : public KTabBar
Q_OBJECT
public:
- TabBar(QWidget *parent = 0);
+ TabBar(MainView *parent = 0);
~TabBar();
+ void showTabPreview(int tab);
+
signals:
void cloneTab(int index);
void closeTab(int index);
@@ -65,7 +77,9 @@ protected:
*/
virtual QSize tabSizeHint(int index) const;
virtual void tabLayoutChange();
-
+ virtual void mouseMoveEvent(QMouseEvent *event);
+ virtual void leaveEvent(QEvent *event);
+
private slots:
void cloneTab();
void closeTab();
@@ -77,13 +91,16 @@ private slots:
private:
void setTabButtonPosition();
- QWidget *m_parent;
+ MainView *m_parent;
QToolButton *m_addTabButton;
/**
* the index in which we are seeing a Context menu
*/
int m_actualIndex;
+
+ QPointer<KPassivePopup> m_previewPopup;
+ int m_currentTabPreview;
};
#endif