Skip to content
This repository has been archived by the owner on May 10, 2018. It is now read-only.

Commit

Permalink
Disabled opacity effect in animated tab previews by default.
Browse files Browse the repository at this point in the history
It can still be enabled with ENABLE_OPACITY_EFFECT build variable.
This is final fix for #663
  • Loading branch information
nowrep committed Feb 7, 2013
1 parent 9c31ff8 commit efe5ed8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
10 changes: 10 additions & 0 deletions BUILDING
Expand Up @@ -100,6 +100,16 @@ Available Defines
example:
$ export NONBLOCK_JS_DIALOGS="true"

ENABLE_OPACITY_EFFECT Enable opacity effect on animated tab previews. Tab previews
will then fade-in on show.
However, this feature may result in wrong scrolling into
anchor (#) links. Rendering of opacity effect may also be
garbled due to Flash.
(disabled by default)

example:
$ export ENABLE_OPACITY_EFFECT="true"


Windows specific defines:

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -15,6 +15,7 @@ Version 1.4.0
* use .qupzilla/tmp instead of /tmp for temporary data
* saving passwords should now work for much more sites
* don't steal Ctrl+B/U/I shortcuts from page
* disabled by default opacity effect on tab previews - see BUILDING
* fixed scrolling to anchor in background tabs
* fixed parsing UTF-8 filenames in Content-Disposition header
* fixed crash with context menu in websearchbar and locationbar
Expand Down
19 changes: 18 additions & 1 deletion src/lib/webview/tabpreview.cpp
@@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 Alexander Samilovskih <alexsamilovskih@gmail.com>
* Copyright (C) 2010-2013 Alexander Samilovskih <alexsamilovskih@gmail.com>
* David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -59,9 +59,11 @@ TabPreview::TabPreview(QupZilla* mainClass, QWidget* parent)
setMaximumWidth(250);
setMaximumHeight(170);

#ifdef ENABLE_OPACITY_EFFECT
setGraphicsEffect(&m_opacityEffect);
m_opacityEffect.setOpacity(0.0);
connect(&m_opacityTimeLine, SIGNAL(frameChanged(int)), this, SLOT(setOpacity(int)));
#endif

m_animation.setDuration(400);
m_animation.setFrameRange(0, 100);
Expand Down Expand Up @@ -99,6 +101,7 @@ void TabPreview::setAnimationsEnabled(bool enabled)

void TabPreview::hideAnimated()
{
#ifdef ENABLE_OPACITY_EFFECT
if (m_opacityTimeLine.state() == QTimeLine::Running) {
m_opacityTimeLine.stop();
}
Expand All @@ -114,12 +117,16 @@ void TabPreview::hideAnimated()
else {
QFrame::hide();
}
#endif
QFrame::hide();
}

void TabPreview::hide()
{
m_previewIndex = -1;
#ifdef ENABLE_OPACITY_EFFECT
disconnect(&m_opacityTimeLine, SIGNAL(finished()), this, SLOT(hide()));
#endif

QFrame::hide();
}
Expand Down Expand Up @@ -163,8 +170,12 @@ void TabPreview::showOnRect(const QRect &r)
finishingGeometry = QRect(calculatePosition(r, previewSize), previewSize);
}

#ifdef ENABLE_OPACITY_EFFECT
if (!m_animationsEnabled) {
m_opacityEffect.setOpacity(1.0);
#else
if (!m_animationsEnabled || !wasVisible) {
#endif
QFrame::setGeometry(finishingGeometry);
return;
}
Expand All @@ -176,14 +187,18 @@ void TabPreview::showOnRect(const QRect &r)
m_startGeometry = finishingGeometry;
}

QFrame::setGeometry(m_startGeometry);

calculateSteps(m_startGeometry, finishingGeometry);
m_animation.start();
}

#ifdef ENABLE_OPACITY_EFFECT
void TabPreview::setOpacity(int opacity)
{
m_opacityEffect.setOpacity(opacity / 100.0);
}
#endif

void TabPreview::setAnimationFrame(int frame)
{
Expand All @@ -198,6 +213,7 @@ void TabPreview::setAnimationFrame(int frame)

void TabPreview::showAnimated()
{
#ifdef ENABLE_OPACITY_EFFECT
disconnect(&m_opacityTimeLine, SIGNAL(finished()), this, SLOT(hide()));

if (m_opacityTimeLine.state() == QTimeLine::Running) {
Expand All @@ -208,6 +224,7 @@ void TabPreview::showAnimated()
m_opacityTimeLine.setStartFrame(m_opacityEffect.opacity() * 100);
m_opacityTimeLine.setEndFrame(100);
m_opacityTimeLine.start();
#endif
}

void TabPreview::paintEvent(QPaintEvent* pe)
Expand Down
11 changes: 9 additions & 2 deletions src/lib/webview/tabpreview.h
@@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 Alexander Samilovskih <alexsamilovskih@gmail.com>
* Copyright (C) 2010-2013 Alexander Samilovskih <alexsamilovskih@gmail.com>
* David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -21,7 +21,10 @@

#include <QFrame>
#include <QTimeLine>

#ifdef ENABLE_OPACITY_EFFECT
#include <QGraphicsOpacityEffect>
#endif

class QupZilla;
class WebTab;
Expand All @@ -48,8 +51,10 @@ public slots:
void show();

private slots:
void setOpacity(int opacity);
void setAnimationFrame(int frame);
#ifdef ENABLE_OPACITY_EFFECT
void setOpacity(int opacity);
#endif

protected:
void paintEvent(QPaintEvent* pe);
Expand All @@ -66,8 +71,10 @@ private slots:
int m_previewIndex;
bool m_animationsEnabled;

#ifdef ENABLE_OPACITY_EFFECT
QTimeLine m_opacityTimeLine;
QGraphicsOpacityEffect m_opacityEffect;
#endif

QTimeLine m_animation;
QRect m_startGeometry;
Expand Down
6 changes: 4 additions & 2 deletions src/lib/webview/webtab.cpp
Expand Up @@ -257,12 +257,14 @@ QPixmap WebTab::renderTabPreview()
{
TabbedWebView* currentWebView = p_QupZilla->weView();
WebPage* page = m_view->page();
const QSize oldSize = currentWebView ? currentWebView->page()->viewportSize() : page->viewportSize();
const QSize oldSize = page->viewportSize();
const QPoint originalScrollPosition = page->mainFrame()->scrollPosition();

// Hack to ensure rendering the same preview before and after the page was shown for the first time
// This can occur eg. with opening background tabs
page->setViewportSize(oldSize);
if (currentWebView) {
page->setViewportSize(currentWebView->size());
}

const int previewWidth = 230;
const int previewHeight = 150;
Expand Down

0 comments on commit efe5ed8

Please sign in to comment.