summaryrefslogtreecommitdiff
path: root/src/tabbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tabbar.cpp')
-rw-r--r--src/tabbar.cpp163
1 files changed, 106 insertions, 57 deletions
diff --git a/src/tabbar.cpp b/src/tabbar.cpp
index 7326d7af..27835892 100644
--- a/src/tabbar.cpp
+++ b/src/tabbar.cpp
@@ -3,9 +3,9 @@
* This file is a part of the rekonq project
*
* Copyright (C) 2008 Benjamin C. Meyer <ben@meyerhome.net>
-* Copyright (C) 2008-2009 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2008-2010 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com>
-* Copyright (C) 2009 by Lionel Chauvin <megabigbug@yahoo.fr>
+* Copyright (C) 2009-2010 by Lionel Chauvin <megabigbug@yahoo.fr>
*
*
* This program is free software; you can redistribute it and/or
@@ -13,9 +13,9 @@
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
-* by the membership of KDE e.V.), which shall act as a proxy
+* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
-*
+*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -86,29 +86,29 @@ TabBar::~TabBar()
QSize TabBar::tabSizeHint(int index) const
{
MainView *view = qobject_cast<MainView *>(parent());
-
+
int buttonSize = view->addTabButton()->size().width();
int tabBarWidth = view->size().width() - buttonSize;
- int baseWidth = view->sizeHint().width()/BASE_WIDTH_DIVISOR;
- int minWidth = view->sizeHint().width()/MIN_WIDTH_DIVISOR;
+ int baseWidth = view->sizeHint().width() / BASE_WIDTH_DIVISOR;
+ int minWidth = view->sizeHint().width() / MIN_WIDTH_DIVISOR;
int w;
- if (baseWidth*count()<tabBarWidth)
+ if (baseWidth*count() < tabBarWidth)
{
w = baseWidth;
}
- else
+ else
{
- if (count() > 0 && tabBarWidth/count()>minWidth)
+ if (count() > 0 && tabBarWidth / count() > minWidth)
{
- w = tabBarWidth/count();
+ w = tabBarWidth / count();
}
else
{
w = minWidth;
}
}
-
+
int h = KTabBar::tabSizeHint(index).height();
QSize ts = QSize(w, h);
@@ -149,68 +149,83 @@ void TabBar::detachTab()
void TabBar::showTabPreview(int tab)
{
MainView *mv = qobject_cast<MainView *>(parent());
-
- WebTab *view = mv->webTab(tab);
- WebTab *currentView = mv->webTab(currentIndex());
+
+ WebTab *indexedTab = mv->webTab(tab);
+ WebTab *currentTab = mv->webTab(currentIndex());
// check if view && currentView exist before using them :)
- if(!currentView || !view)
+ if (!currentTab || !indexedTab)
return;
-
+
int w = tabSizeHint(tab).width();
- int h = w*((0.0 + currentView->height())/currentView->width());
+ int h = w * ((0.0 + currentTab->height()) / currentTab->width());
//delete previous tab preview
- if (m_previewPopup)
- {
- delete m_previewPopup;
- }
+ delete m_previewPopup.data();
+ m_previewPopup.clear();
+
+ if (indexedTab->progress() != 0)
+ return;
m_previewPopup = new KPassivePopup(this);
- m_previewPopup->setFrameShape(QFrame::StyledPanel);
- m_previewPopup->setFrameShadow(QFrame::Plain);
- m_previewPopup->setFixedSize(w, h);
+ m_previewPopup.data()->setFrameShape(QFrame::StyledPanel);
+ m_previewPopup.data()->setFrameShadow(QFrame::Plain);
+ m_previewPopup.data()->setFixedSize(w, h);
+
QLabel *l = new QLabel();
- view->page()->setViewportSize(currentView->page()->viewportSize());
- 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));
+ l->setPixmap(WebSnap::renderPreview(*indexedTab->page(), w, h));
+
+ m_previewPopup.data()->setView(l);
+ m_previewPopup.data()->layout()->setAlignment(Qt::AlignTop);
+ m_previewPopup.data()->layout()->setMargin(0);
+
+ QPoint pos(tabRect(tab).x() , tabRect(tab).y() + tabRect(tab).height());
+ m_previewPopup.data()->show(mapToGlobal(pos));
}
void TabBar::mouseMoveEvent(QMouseEvent *event)
{
+ if (event->buttons() & Qt::LeftButton)
+ {
+ // hide addNewTabButton when moving tabs
+ MainView *view = qobject_cast<MainView *>(parent());
+ QTimer::singleShot(200, view->addTabButton(), SLOT(hide()));
+ }
+
if (ReKonfig::alwaysShowTabPreviews())
{
//Find the tab under the mouse
int i = 0;
- int tab = -1;
- while (i<count() && tab==-1)
+ int tabIndex = -1;
+ while (i < count()
+ && tabIndex == -1
+ )
{
- if (tabRect(i).contains(event->pos()))
+ if (tabRect(i).contains(event->pos()))
{
- tab = i;
+ tabIndex = i;
}
i++;
}
- //if found and not the current tab then show tab preview
- if (tab != -1 && tab != currentIndex() && m_currentTabPreview != tab)
+ // if found and not the current tab then show tab preview
+ if (tabIndex != -1
+ && tabIndex != currentIndex()
+ && m_currentTabPreview != tabIndex
+ && event->buttons() == Qt::NoButton
+ )
{
- showTabPreview(tab);
- m_currentTabPreview = tab;
+ showTabPreview(tabIndex);
+ m_currentTabPreview = tabIndex;
}
- //if current tab or not found then hide previous tab preview
- if (tab==currentIndex() || tab==-1)
+ // if current tab or not found then hide previous tab preview
+ if (tabIndex == currentIndex() || tabIndex == -1)
{
- if ( m_previewPopup)
+ if (!m_previewPopup.isNull())
{
- m_previewPopup->hide();
+ m_previewPopup.data()->hide();
}
m_currentTabPreview = -1;
}
@@ -225,9 +240,9 @@ void TabBar::leaveEvent(QEvent *event)
if (ReKonfig::alwaysShowTabPreviews())
{
//if leave tabwidget then hide previous tab preview
- if ( m_previewPopup)
+ if (!m_previewPopup.isNull())
{
- m_previewPopup->hide();
+ m_previewPopup.data()->hide();
}
m_currentTabPreview = -1;
}
@@ -238,10 +253,19 @@ void TabBar::leaveEvent(QEvent *event)
void TabBar::mousePressEvent(QMouseEvent *event)
{
+ if (ReKonfig::alwaysShowTabPreviews())
+ {
+ if (!m_previewPopup.isNull())
+ {
+ m_previewPopup.data()->hide();
+ }
+ m_currentTabPreview = -1;
+ }
+
// just close tab on middle mouse click
if (event->button() == Qt::MidButton)
return;
-
+
KTabBar::mousePressEvent(event);
}
@@ -253,15 +277,17 @@ void TabBar::contextMenu(int tab, const QPoint &pos)
KMenu menu;
MainWindow *mainWindow = Application::instance()->mainWindow();
- menu.addAction(mainWindow->actionByName(QLatin1String("new_tab")));
- menu.addAction( mainWindow->actionByName("clone_tab") );
- menu.addAction( mainWindow->actionByName("detach_tab") );
+ menu.addAction(mainWindow->actionByName( QL1S("new_tab") ));
+ menu.addAction(mainWindow->actionByName( QL1S("clone_tab") ));
+
+ if (count() > 1)
+ menu.addAction(mainWindow->actionByName( QL1S("detach_tab") ));
menu.addSeparator();
- menu.addAction( mainWindow->actionByName("close_tab") );
- menu.addAction( mainWindow->actionByName("close_other_tabs") );
+ menu.addAction(mainWindow->actionByName( QL1S("close_tab") ));
+ menu.addAction(mainWindow->actionByName( QL1S("close_other_tabs") ));
menu.addSeparator();
- menu.addAction( mainWindow->actionByName("reload_tab") );
- menu.addAction( mainWindow->actionByName("reload_all_tabs") );
+ menu.addAction(mainWindow->actionByName( QL1S("reload_tab") ));
+ menu.addAction(mainWindow->actionByName( QL1S("reload_all_tabs") ));
menu.exec(pos);
}
@@ -272,9 +298,32 @@ void TabBar::emptyAreaContextMenu(const QPoint &pos)
KMenu menu;
MainWindow *mainWindow = Application::instance()->mainWindow();
- menu.addAction(mainWindow->actionByName(QLatin1String("new_tab")));
+ menu.addAction(mainWindow->actionByName( QL1S("new_tab") ));
menu.addSeparator();
- menu.addAction( mainWindow->actionByName("reload_all_tabs") );
+ menu.addAction(mainWindow->actionByName( QL1S("reload_all_tabs") ));
menu.exec(pos);
}
+
+
+void TabBar::mouseReleaseEvent(QMouseEvent *event)
+{
+ MainView *mv = qobject_cast<MainView *>(parent());
+ QTimer::singleShot(200, mv->addTabButton(), SLOT(show()));
+
+ KTabBar::mouseReleaseEvent(event);
+}
+
+
+void TabBar::tabRemoved(int index)
+{
+ Q_UNUSED(index)
+ if (ReKonfig::alwaysShowTabPreviews())
+ {
+ if (!m_previewPopup.isNull())
+ {
+ m_previewPopup.data()->hide();
+ }
+ m_currentTabPreview = -1;
+ }
+}