2011-08-02 16:19:20 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2012-01-01 15:29:55 +01:00
|
|
|
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
2011-08-02 16:19:20 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#include "animatedwidget.h"
|
2012-02-29 18:33:50 +01:00
|
|
|
|
|
|
|
#include <QResizeEvent>
|
2011-08-02 16:19:20 +02:00
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
AnimatedWidget::AnimatedWidget(const Direction &direction, int duration, QWidget* parent)
|
2011-08-02 16:19:20 +02:00
|
|
|
: QWidget(parent)
|
|
|
|
, m_direction(direction)
|
2012-04-10 20:52:10 +02:00
|
|
|
, m_stepHeight(0)
|
|
|
|
, m_stepY(0)
|
|
|
|
, m_widget(new QWidget(this))
|
2011-08-02 16:19:20 +02:00
|
|
|
{
|
2012-04-10 20:52:10 +02:00
|
|
|
m_timeLine.setDuration(duration);
|
|
|
|
m_timeLine.setFrameRange(0, 100);
|
|
|
|
connect(&m_timeLine, SIGNAL(frameChanged(int)), this, SLOT(animateFrame(int)));
|
2011-08-02 16:19:20 +02:00
|
|
|
|
|
|
|
setMaximumHeight(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimatedWidget::startAnimation()
|
|
|
|
{
|
2012-04-10 20:52:10 +02:00
|
|
|
if (m_timeLine.state() == QTimeLine::Running) {
|
2012-03-17 16:01:12 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-10 20:52:10 +02:00
|
|
|
int shown = 0;
|
|
|
|
int hidden = 0;
|
|
|
|
|
2011-08-02 16:19:20 +02:00
|
|
|
if (m_direction == Down) {
|
2012-04-10 20:52:10 +02:00
|
|
|
shown = 0;
|
|
|
|
hidden = -m_widget->height();
|
2011-08-02 16:19:20 +02:00
|
|
|
}
|
|
|
|
|
2012-04-10 20:52:10 +02:00
|
|
|
m_widget->move(QPoint(m_widget->pos().x(), hidden));
|
2011-08-02 16:19:20 +02:00
|
|
|
|
2012-04-10 20:52:10 +02:00
|
|
|
m_stepY = (hidden - shown) / 100.0;
|
|
|
|
m_startY = hidden;
|
|
|
|
m_stepHeight = m_widget->height() / 100.0;
|
2011-08-02 16:19:20 +02:00
|
|
|
|
2012-04-10 20:52:10 +02:00
|
|
|
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);
|
2011-08-02 16:19:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnimatedWidget::hide()
|
|
|
|
{
|
2012-04-10 20:52:10 +02:00
|
|
|
if (m_timeLine.state() == QTimeLine::Running) {
|
2012-03-17 16:01:12 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-10 20:52:10 +02:00
|
|
|
m_timeLine.setDirection(QTimeLine::Backward);
|
|
|
|
m_timeLine.start();
|
2011-08-02 16:19:20 +02:00
|
|
|
|
2012-04-10 20:52:10 +02:00
|
|
|
connect(&m_timeLine, SIGNAL(finished()), this, SLOT(close()));
|
2012-07-01 12:07:00 +02:00
|
|
|
|
|
|
|
QWidget* p = parentWidget();
|
|
|
|
if (p) {
|
|
|
|
p->setFocus();
|
|
|
|
}
|
2011-08-02 16:19:20 +02:00
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
void AnimatedWidget::resizeEvent(QResizeEvent* event)
|
2011-08-02 16:19:20 +02:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (event->size().width() != m_widget->width()) {
|
2011-08-02 16:19:20 +02:00
|
|
|
m_widget->resize(event->size().width(), m_widget->height());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-08-02 16:19:20 +02:00
|
|
|
|
|
|
|
QWidget::resizeEvent(event);
|
|
|
|
}
|