2011-08-02 16:19:20 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2011-12-15 18:34:48 +01:00
|
|
|
* Copyright (C) 2010-2011 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"
|
|
|
|
#include <QDebug>
|
|
|
|
|
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_widget(new QWidget(this))
|
2011-11-06 17:01:23 +01:00
|
|
|
, Y_SHOWN(0)
|
|
|
|
, Y_HIDDEN(0)
|
2011-08-02 16:19:20 +02:00
|
|
|
, m_direction(direction)
|
|
|
|
{
|
|
|
|
m_positionAni = new QPropertyAnimation(m_widget, "pos");
|
2011-09-11 19:15:06 +02:00
|
|
|
m_positionAni->setDuration(duration);
|
2011-08-02 16:19:20 +02:00
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
m_heightAni = new QPropertyAnimation(this, "fixedheight");
|
|
|
|
m_heightAni->setDuration(duration);
|
2011-08-02 16:19:20 +02:00
|
|
|
|
2011-12-04 20:09:44 +01:00
|
|
|
m_aniGroup = new QParallelAnimationGroup(this);
|
2011-08-02 16:19:20 +02:00
|
|
|
m_aniGroup->addAnimation(m_positionAni);
|
2011-09-11 19:15:06 +02:00
|
|
|
m_aniGroup->addAnimation(m_heightAni);
|
2011-08-02 16:19:20 +02:00
|
|
|
|
|
|
|
setMaximumHeight(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimatedWidget::startAnimation()
|
|
|
|
{
|
|
|
|
if (m_direction == Down) {
|
|
|
|
Y_SHOWN = 0;
|
|
|
|
Y_HIDDEN = -m_widget->height();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else if (m_direction == Up) {
|
2011-08-02 16:19:20 +02:00
|
|
|
Y_SHOWN = 0;
|
|
|
|
Y_HIDDEN = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_widget->move(QPoint(m_widget->pos().x(), Y_HIDDEN));
|
|
|
|
|
|
|
|
m_positionAni->setEndValue(QPoint(m_widget->pos().x(), Y_SHOWN));
|
2011-09-11 19:15:06 +02:00
|
|
|
m_heightAni->setEndValue(m_widget->height());
|
2011-08-02 16:19:20 +02:00
|
|
|
|
|
|
|
m_aniGroup->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimatedWidget::hide()
|
|
|
|
{
|
|
|
|
m_positionAni->setEndValue(QPoint(m_widget->pos().x(), Y_HIDDEN));
|
2011-09-11 19:15:06 +02:00
|
|
|
m_heightAni->setEndValue(0);
|
2011-08-02 16:19:20 +02:00
|
|
|
|
|
|
|
m_aniGroup->start();
|
|
|
|
connect(m_aniGroup, SIGNAL(finished()), this, SLOT(close()));
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimatedWidget::~AnimatedWidget()
|
|
|
|
{
|
|
|
|
}
|