1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

Added opacity effect on tab previews.

This commit is contained in:
nowrep 2012-04-09 14:09:40 +02:00
parent e5ce2f5e3d
commit d03700f917
5 changed files with 116 additions and 16 deletions

View File

@ -65,9 +65,15 @@ TabBar::TabBar(QupZilla* mainClass, TabWidget* tabWidget)
setAcceptDrops(true);
connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int)));
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &)));
connect(m_tabWidget, SIGNAL(pinnedTabClosed()), this, SLOT(pinnedTabClosed()));
connect(m_tabWidget, SIGNAL(pinnedTabAdded()), this, SLOT(pinnedTabAdded()));
m_tabPreviewTimer = new QTimer(this);
m_tabPreviewTimer->setInterval(200);
m_tabPreviewTimer->setSingleShot(true);
connect(m_tabPreviewTimer, SIGNAL(timeout()), m_tabPreview, SLOT(hideAnimated()));
}
void TabBar::loadSettings()
@ -290,6 +296,13 @@ void TabBar::closeCurrentTab()
m_tabWidget->closeTab(id);
}
void TabBar::currentTabChanged(int index)
{
Q_UNUSED(index)
hideTabPreview(false);
}
void TabBar::bookmarkTab()
{
TabbedWebView* view = p_QupZilla->weView(m_clickedTab);
@ -352,13 +365,21 @@ void TabBar::showTabPreview()
return;
}
m_tabPreviewTimer->stop();
m_tabPreview->setWebTab(webTab, m_currentTabPreview == currentIndex());
m_tabPreview->showOnRect(tabRect(m_currentTabPreview));
}
void TabBar::hideTabPreview()
void TabBar::hideTabPreview(bool delayed)
{
m_tabPreview->hide();
if (delayed) {
m_tabPreviewTimer->start();
}
else {
m_tabPreview->hideAnimated();
}
m_currentTabPreview = -1;
}
void TabBar::mouseDoubleClickEvent(QMouseEvent* event)
@ -401,6 +422,7 @@ void TabBar::mouseMoveEvent(QMouseEvent* event)
int manhattanLength = (event->pos() - m_dragStartPosition).manhattanLength();
if (manhattanLength > QApplication::startDragDistance()) {
m_tabWidget->buttonAddTab()->hide();
hideTabPreview();
}
}
@ -408,7 +430,7 @@ void TabBar::mouseMoveEvent(QMouseEvent* event)
const int tab = tabAt(event->pos());
if (tab != -1 && tab != m_currentTabPreview && event->buttons() == Qt::NoButton) {
if (tab != -1 && tab != m_currentTabPreview && event->buttons() == Qt::NoButton && m_dragStartPosition.isNull()) {
m_currentTabPreview = tab;
if (m_tabPreview->isVisible()) {
showTabPreview();
@ -423,6 +445,8 @@ void TabBar::mouseMoveEvent(QMouseEvent* event)
void TabBar::mouseReleaseEvent(QMouseEvent* event)
{
m_dragStartPosition = QPoint();
if (mApp->plugins()->processMouseRelease(Qz::ON_TabBar, this, event)) {
return;
}
@ -452,7 +476,6 @@ void TabBar::mouseReleaseEvent(QMouseEvent* event)
void TabBar::leaveEvent(QEvent* event)
{
hideTabPreview();
m_currentTabPreview = -1;
QTabBar::leaveEvent(event);
}

View File

@ -62,6 +62,7 @@ signals:
public slots:
private slots:
void currentTabChanged(int index);
void pinnedTabAdded();
void pinnedTabClosed();
@ -76,7 +77,7 @@ private slots:
void closeCurrentTab();
void showTabPreview();
void hideTabPreview();
void hideTabPreview(bool delayed = true);
private:
void mouseDoubleClickEvent(QMouseEvent* event);
@ -97,6 +98,7 @@ private:
QupZilla* p_QupZilla;
TabWidget* m_tabWidget;
TabPreview* m_tabPreview;
QTimer* m_tabPreviewTimer;
bool m_showCloseButtonWithOneTab;
bool m_showTabBarWithOneTab;

View File

@ -28,6 +28,7 @@
#include <QVBoxLayout>
#include <QStyleOptionFrame>
#include <QPropertyAnimation>
#include <QGraphicsOpacityEffect>
TabPreview::TabPreview(QupZilla* mainClass, QWidget* parent)
: QFrame(parent)
@ -55,6 +56,11 @@ TabPreview::TabPreview(QupZilla* mainClass, QWidget* parent)
setMaximumHeight(170);
m_animation = new QPropertyAnimation(this, "geometry", this);
m_opacityEffect = new QGraphicsOpacityEffect(this);
m_opacityAnimation = new QPropertyAnimation(m_opacityEffect, "opacity", this);
setGraphicsEffect(m_opacityEffect);
m_opacityEffect->setOpacity(0.0);
}
void TabPreview::setWebTab(WebTab* webTab, bool noPixmap)
@ -75,6 +81,54 @@ void TabPreview::setAnimationsEnabled(bool enabled)
m_animationsEnabled = enabled;
}
void TabPreview::hideAnimated()
{
if (m_opacityAnimation->state() == QPropertyAnimation::Running) {
m_opacityAnimation->stop();
}
if (m_animationsEnabled) {
m_opacityAnimation->setDuration(400);
m_opacityAnimation->setStartValue(m_opacityEffect->opacity());
m_opacityAnimation->setEndValue(0.0);
m_opacityAnimation->start();
connect(m_opacityAnimation, SIGNAL(finished()), this, SLOT(hide()));
}
else {
QFrame::hide();
}
}
void TabPreview::hide()
{
disconnect(m_opacityAnimation, SIGNAL(finished()), this, SLOT(hide()));
QFrame::hide();
}
void TabPreview::show()
{
if (!isVisible() && m_animationsEnabled) {
showAnimated();
}
QFrame::show();
}
void TabPreview::showAnimated()
{
disconnect(m_opacityAnimation, SIGNAL(finished()), this, SLOT(hide()));
if (m_opacityAnimation->state() == QPropertyAnimation::Running) {
m_opacityAnimation->stop();
}
m_opacityAnimation->setDuration(400);
m_opacityAnimation->setStartValue(m_opacityEffect->opacity());
m_opacityAnimation->setEndValue(1.0);
m_opacityAnimation->start();
}
void TabPreview::paintEvent(QPaintEvent* pe)
{
QStyleOptionFrame opt;
@ -150,12 +204,20 @@ void TabPreview::showOnRect(const QRect &r)
finishingGeometry = QRect(calculatePosition(r, previewSize), previewSize);
}
if (!m_animationsEnabled || !wasVisible) {
if (!m_animationsEnabled) {
m_opacityEffect->setOpacity(1.0);
QFrame::setGeometry(finishingGeometry);
QFrame::show();
return;
}
else {
setFinishingGeometry(oldGeometry, finishingGeometry);
m_animation->start();
showAnimated();
}
if (!wasVisible) {
oldGeometry = finishingGeometry;
}
setFinishingGeometry(oldGeometry, finishingGeometry);
m_animation->start();
}

View File

@ -26,7 +26,7 @@ class WebTab;
class QLabel;
class QPropertyAnimation;
class QParallelAnimationGroup;
class QGraphicsOpacityEffect;
class TabPreview : public QFrame
{
@ -39,10 +39,17 @@ public:
void setAnimationsEnabled(bool enabled);
public slots:
void hideAnimated();
void hide();
void show();
protected:
void paintEvent(QPaintEvent* pe);
private:
void showAnimated();
void setFinishingGeometry(const QRect &oldGeometry, const QRect &newGeometry);
QPoint calculatePosition(const QRect &tabRect, const QSize &previewSize);
@ -52,6 +59,8 @@ private:
bool m_animationsEnabled;
QPropertyAnimation* m_animation;
QPropertyAnimation* m_opacityAnimation;
QGraphicsOpacityEffect* m_opacityEffect;
};
#endif // TABPREVIEW_H

View File

@ -250,25 +250,29 @@ void WebTab::p_restoreTab(const WebTab::SavedTab &tab)
QPixmap WebTab::renderTabPreview()
{
WebPage* page = m_view->page();
const QSize &contentsSize = page->mainFrame()->contentsSize();
QSize oldSize = page->viewportSize();
int renderWidth = qMin(contentsSize.width(), 2000);
int renderHeight = qMin(contentsSize.height(), 1500);
int renderWidth = qMin(page->mainFrame()->contentsSize().width(), 1280);
int renderHeight = renderWidth / 23 * 15;
const int verticalScrollBarWidth = page->mainFrame()->scrollBarGeometry(Qt::Vertical).width();
const int horizontalScrollBarHeight = page->mainFrame()->scrollBarGeometry(Qt::Horizontal).height();
page->setViewportSize(QSize(renderWidth, renderHeight));
renderWidth -= verticalScrollBarWidth;
renderHeight -= horizontalScrollBarHeight;
QPixmap pageImage(renderWidth, renderHeight);
pageImage.fill(Qt::transparent);
QPainter p(&pageImage);
m_view->page()->mainFrame()->render(&p, QWebFrame::ContentsLayer, m_view->visibleRegion());
m_view->page()->mainFrame()->render(&p, QWebFrame::ContentsLayer);
p.end();
page->setViewportSize(oldSize);
pageImage = pageImage.scaled(230, 200, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
return pageImage.copy(0, 0, 230, 150);
return pageImage.scaled(230, 150, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
void WebTab::showNotification(QWidget* notif)