mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
Using QTimeLine in AnimatedWidget instead of QPropertyAnimation
This commit is contained in:
parent
90870cff11
commit
3d1b490cc5
23
src/lib/3rdparty/fancytabwidget.cpp
vendored
23
src/lib/3rdparty/fancytabwidget.cpp
vendored
@ -38,7 +38,6 @@
|
||||
#include <QMenu>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QSignalMapper>
|
||||
#include <QSplitter>
|
||||
#include <QStackedLayout>
|
||||
@ -124,7 +123,7 @@ void FancyTabProxyStyle::drawControl(
|
||||
int textFlags = Qt::AlignHCenter | Qt::AlignVCenter;
|
||||
p->drawText(text_rect, textFlags, text);
|
||||
p->setPen(selected ? QColor(60, 60, 60) : Utils::StyleHelper::panelTextColor());
|
||||
#ifndef Q_WS_MAC
|
||||
#if 0
|
||||
if (widget) {
|
||||
const QString fader_key = "tab_" + text + "_fader";
|
||||
const QString animation_key = "tab_" + text + "_animation";
|
||||
@ -220,25 +219,25 @@ bool FancyTabProxyStyle::eventFilter(QObject* o, QEvent* e)
|
||||
FancyTab::FancyTab(QWidget* tabbar)
|
||||
: QWidget(tabbar), tabbar(tabbar), m_fader(0)
|
||||
{
|
||||
animator.setPropertyName("fader");
|
||||
animator.setTargetObject(this);
|
||||
// animator.setPropertyName("fader");
|
||||
// animator.setTargetObject(this);
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
||||
}
|
||||
|
||||
void FancyTab::fadeIn()
|
||||
{
|
||||
animator.stop();
|
||||
animator.setDuration(80);
|
||||
animator.setEndValue(40);
|
||||
animator.start();
|
||||
// animator.stop();
|
||||
// animator.setDuration(80);
|
||||
// animator.setEndValue(40);
|
||||
// animator.start();
|
||||
}
|
||||
|
||||
void FancyTab::fadeOut()
|
||||
{
|
||||
animator.stop();
|
||||
animator.setDuration(160);
|
||||
animator.setEndValue(0);
|
||||
animator.start();
|
||||
// animator.stop();
|
||||
// animator.setDuration(160);
|
||||
// animator.setEndValue(0);
|
||||
// animator.start();
|
||||
}
|
||||
|
||||
void FancyTab::setFader(float value)
|
||||
|
4
src/lib/3rdparty/fancytabwidget.h
vendored
4
src/lib/3rdparty/fancytabwidget.h
vendored
@ -33,7 +33,6 @@
|
||||
#include "qz_namespace.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QProxyStyle>
|
||||
#include <QTabBar>
|
||||
#include <QTimer>
|
||||
@ -90,7 +89,6 @@ protected:
|
||||
void leaveEvent(QEvent*);
|
||||
|
||||
private:
|
||||
QPropertyAnimation animator;
|
||||
QWidget* tabbar;
|
||||
float m_fader;
|
||||
};
|
||||
@ -231,8 +229,6 @@ private:
|
||||
} // namespace Internal
|
||||
} // namespace Core
|
||||
|
||||
Q_DECLARE_METATYPE(QPropertyAnimation*);
|
||||
|
||||
using Core::Internal::FancyTab;
|
||||
using Core::Internal::FancyTabBar;
|
||||
using Core::Internal::FancyTabWidget;
|
||||
|
@ -17,64 +17,62 @@
|
||||
* ============================================================ */
|
||||
#include "animatedwidget.h"
|
||||
|
||||
#include <QPropertyAnimation>
|
||||
#include <QParallelAnimationGroup>
|
||||
#include <QResizeEvent>
|
||||
|
||||
AnimatedWidget::AnimatedWidget(const Direction &direction, int duration, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_widget(new QWidget(this))
|
||||
, Y_SHOWN(0)
|
||||
, Y_HIDDEN(0)
|
||||
, m_direction(direction)
|
||||
, m_stepHeight(0)
|
||||
, m_stepY(0)
|
||||
, m_widget(new QWidget(this))
|
||||
{
|
||||
m_positionAni = new QPropertyAnimation(m_widget, "pos");
|
||||
m_positionAni->setDuration(duration);
|
||||
|
||||
m_heightAni = new QPropertyAnimation(this, "fixedheight");
|
||||
m_heightAni->setDuration(duration);
|
||||
|
||||
m_aniGroup = new QParallelAnimationGroup(this);
|
||||
m_aniGroup->addAnimation(m_positionAni);
|
||||
m_aniGroup->addAnimation(m_heightAni);
|
||||
m_timeLine.setDuration(duration);
|
||||
m_timeLine.setFrameRange(0, 100);
|
||||
connect(&m_timeLine, SIGNAL(frameChanged(int)), this, SLOT(animateFrame(int)));
|
||||
|
||||
setMaximumHeight(0);
|
||||
}
|
||||
|
||||
void AnimatedWidget::startAnimation()
|
||||
{
|
||||
if (m_aniGroup->state() == QAnimationGroup::Running) {
|
||||
if (m_timeLine.state() == QTimeLine::Running) {
|
||||
return;
|
||||
}
|
||||
|
||||
int shown = 0;
|
||||
int hidden = 0;
|
||||
|
||||
if (m_direction == Down) {
|
||||
Y_SHOWN = 0;
|
||||
Y_HIDDEN = -m_widget->height();
|
||||
}
|
||||
else if (m_direction == Up) {
|
||||
Y_SHOWN = 0;
|
||||
Y_HIDDEN = 0;
|
||||
shown = 0;
|
||||
hidden = -m_widget->height();
|
||||
}
|
||||
|
||||
m_widget->move(QPoint(m_widget->pos().x(), Y_HIDDEN));
|
||||
m_widget->move(QPoint(m_widget->pos().x(), hidden));
|
||||
|
||||
m_positionAni->setEndValue(QPoint(m_widget->pos().x(), Y_SHOWN));
|
||||
m_heightAni->setEndValue(m_widget->height());
|
||||
m_stepY = (hidden - shown) / 100.0;
|
||||
m_startY = hidden;
|
||||
m_stepHeight = m_widget->height() / 100.0;
|
||||
|
||||
m_aniGroup->start();
|
||||
m_timeLine.setDirection(QTimeLine::Forward);
|
||||
m_timeLine.start();
|
||||
}
|
||||
|
||||
void AnimatedWidget::animateFrame(int frame)
|
||||
{
|
||||
setFixedHeight(frame * m_stepHeight);
|
||||
m_widget->move(pos().x(), m_startY - frame * m_stepY);
|
||||
}
|
||||
|
||||
void AnimatedWidget::hide()
|
||||
{
|
||||
if (m_aniGroup->state() == QAnimationGroup::Running) {
|
||||
if (m_timeLine.state() == QTimeLine::Running) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_positionAni->setEndValue(QPoint(m_widget->pos().x(), Y_HIDDEN));
|
||||
m_heightAni->setEndValue(0);
|
||||
m_timeLine.setDirection(QTimeLine::Backward);
|
||||
m_timeLine.start();
|
||||
|
||||
m_aniGroup->start();
|
||||
connect(m_aniGroup, SIGNAL(finished()), this, SLOT(close()));
|
||||
connect(&m_timeLine, SIGNAL(finished()), this, SLOT(close()));
|
||||
}
|
||||
|
||||
void AnimatedWidget::resizeEvent(QResizeEvent* event)
|
||||
@ -85,7 +83,3 @@ void AnimatedWidget::resizeEvent(QResizeEvent* event)
|
||||
|
||||
QWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
AnimatedWidget::~AnimatedWidget()
|
||||
{
|
||||
}
|
||||
|
@ -19,21 +19,18 @@
|
||||
#define NOTIFICATION_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTimeLine>
|
||||
|
||||
#include "qz_namespace.h"
|
||||
|
||||
class QPropertyAnimation;
|
||||
class QParallelAnimationGroup;
|
||||
|
||||
class QT_QUPZILLA_EXPORT AnimatedWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int fixedheight READ height WRITE setFixedHeight)
|
||||
|
||||
public:
|
||||
enum Direction { Down, Up };
|
||||
|
||||
explicit AnimatedWidget(const Direction &direction = Down, int duration = 300, QWidget* parent = 0);
|
||||
~AnimatedWidget();
|
||||
|
||||
QWidget* widget() { return m_widget; }
|
||||
|
||||
@ -41,18 +38,19 @@ public slots:
|
||||
void hide();
|
||||
void startAnimation();
|
||||
|
||||
private slots:
|
||||
void animateFrame(int frame);
|
||||
|
||||
private:
|
||||
void resizeEvent(QResizeEvent* e);
|
||||
|
||||
QPropertyAnimation* m_positionAni;
|
||||
QPropertyAnimation* m_heightAni;
|
||||
QParallelAnimationGroup* m_aniGroup;
|
||||
Direction m_direction;
|
||||
QTimeLine m_timeLine;
|
||||
qreal m_stepHeight;
|
||||
qreal m_stepY;
|
||||
int m_startY;
|
||||
|
||||
QWidget* m_widget;
|
||||
|
||||
int Y_SHOWN;
|
||||
int Y_HIDDEN;
|
||||
Direction m_direction;
|
||||
};
|
||||
|
||||
#endif // NOTIFICATION_H
|
||||
|
@ -60,7 +60,6 @@ private:
|
||||
Ui::SearchToolbar* ui;
|
||||
QupZilla* p_QupZilla;
|
||||
|
||||
QPropertyAnimation* m_animation;
|
||||
QWebPage::FindFlags m_findFlags;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user