diff options
Diffstat (limited to 'src/tabbar.cpp')
-rw-r--r-- | src/tabbar.cpp | 97 |
1 files changed, 69 insertions, 28 deletions
diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 460a2464..f8da57b1 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 @@ -93,13 +93,13 @@ QSize TabBar::tabSizeHint(int index) const int minWidth = view->sizeHint().width()/MIN_WIDTH_DIVISOR; int w; - if (baseWidth*count()<tabBarWidth) + if (baseWidth*count() < tabBarWidth) { w = baseWidth; } else { - if (count() > 0 && tabBarWidth/count()>minWidth) + if (count() > 0 && tabBarWidth/count() > minWidth) { w = tabBarWidth/count(); } @@ -150,40 +150,49 @@ 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, true) ); + + 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 @@ -208,9 +217,9 @@ void TabBar::mouseMoveEvent(QMouseEvent *event) //if current tab or not found then hide previous tab preview if (tab==currentIndex() || tab==-1) { - if ( m_previewPopup) + if ( !m_previewPopup.isNull() ) { - m_previewPopup->hide(); + m_previewPopup.data()->hide(); } m_currentTabPreview = -1; } @@ -225,9 +234,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,6 +247,15 @@ 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; @@ -278,3 +296,26 @@ void TabBar::emptyAreaContextMenu(const QPoint &pos) 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; + } +} |