2011-08-02 16:19:20 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
|
|
|
* Copyright (C) 2010-2011 nowrep
|
|
|
|
*
|
|
|
|
* 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))
|
|
|
|
, 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
|
|
|
|
|
|
|
m_aniGroup = new QParallelAnimationGroup();
|
|
|
|
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();
|
|
|
|
} else if (m_direction == Up) {
|
|
|
|
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()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimatedWidget::resizeEvent(QResizeEvent *event)
|
|
|
|
{
|
|
|
|
if (event->size().width() != m_widget->width())
|
|
|
|
m_widget->resize(event->size().width(), m_widget->height());
|
|
|
|
|
|
|
|
QWidget::resizeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimatedWidget::~AnimatedWidget()
|
|
|
|
{
|
|
|
|
delete m_positionAni;
|
2011-09-11 19:15:06 +02:00
|
|
|
delete m_heightAni;
|
2011-08-02 16:19:20 +02:00
|
|
|
delete m_aniGroup;
|
|
|
|
delete m_widget;
|
|
|
|
}
|