2015-03-25 09:48:26 +08:00
|
|
|
/*
|
|
|
|
Copyright (C) 2013 by Maxim Biro <nurupo.contributions@gmail.com>
|
2015-06-06 09:40:08 +08:00
|
|
|
Copyright © 2015 by The qTox Project
|
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
2015-03-25 09:48:26 +08: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.
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
qTox is distributed in the hope that it will be useful,
|
2015-03-25 09:48:26 +08:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-06-06 09:40:08 +08:00
|
|
|
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 qTox. If not, see <http://www.gnu.org/licenses/>.
|
2015-03-25 09:48:26 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "flyoutoverlaywidget.h"
|
|
|
|
|
|
|
|
#include <QPropertyAnimation>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QBitmap>
|
2015-03-25 21:43:40 +08:00
|
|
|
#include <QTimer>
|
2015-03-25 09:48:26 +08:00
|
|
|
|
|
|
|
FlyoutOverlayWidget::FlyoutOverlayWidget(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
setContentsMargins(0, 0, 0, 0);
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
animation = new QPropertyAnimation(this, QByteArrayLiteral("flyoutPercent"), this);
|
|
|
|
animation->setKeyValueAt(0, 0.0f);
|
|
|
|
animation->setKeyValueAt(1, 1.0f);
|
|
|
|
animation->setDuration(200);
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
connect(animation, &QAbstractAnimation::finished, this, &FlyoutOverlayWidget::finishedAnimation);
|
|
|
|
setFlyoutPercent(0);
|
2015-04-02 22:31:58 +08:00
|
|
|
hide();
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
FlyoutOverlayWidget::~FlyoutOverlayWidget()
|
|
|
|
{
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int FlyoutOverlayWidget::animationDuration() const
|
|
|
|
{
|
|
|
|
return animation->duration();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlyoutOverlayWidget::setAnimationDuration(int timeMs)
|
|
|
|
{
|
|
|
|
animation->setDuration(timeMs);
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal FlyoutOverlayWidget::flyoutPercent() const
|
|
|
|
{
|
|
|
|
return percent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlyoutOverlayWidget::setFlyoutPercent(qreal progress)
|
|
|
|
{
|
|
|
|
percent = progress;
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
QSize self = size();
|
|
|
|
setMask(QRegion(0, 0, self.width() * progress + 1, self.height()));
|
|
|
|
move(startPos.x() + self.width() - self.width() * percent, startPos.y());
|
|
|
|
setVisible (progress != 0);
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FlyoutOverlayWidget::isShown() const
|
|
|
|
{
|
|
|
|
return (percent == 1);
|
|
|
|
}
|
|
|
|
|
2015-04-02 22:56:16 +08:00
|
|
|
bool FlyoutOverlayWidget::isBeingAnimated() const
|
|
|
|
{
|
|
|
|
return (animation->state() == QAbstractAnimation::Running);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FlyoutOverlayWidget::isBeingShown() const
|
|
|
|
{
|
|
|
|
return (isBeingAnimated() && animation->direction() == QAbstractAnimation::Forward);
|
|
|
|
}
|
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
void FlyoutOverlayWidget::animateShow()
|
|
|
|
{
|
2015-04-02 22:56:16 +08:00
|
|
|
if (percent == 1.0f)
|
|
|
|
return;
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-04-02 22:56:16 +08:00
|
|
|
if (animation->state() != QAbstractAnimation::Running)
|
|
|
|
this->startPos = pos();
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-04-02 22:56:16 +08:00
|
|
|
startAnimation(true);
|
2015-03-25 09:48:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FlyoutOverlayWidget::animateHide()
|
|
|
|
{
|
2015-04-02 22:56:16 +08:00
|
|
|
if (animation->state() != QAbstractAnimation::Running)
|
|
|
|
this->startPos = pos();
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-04-02 22:56:16 +08:00
|
|
|
startAnimation(false);
|
2015-03-25 09:48:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FlyoutOverlayWidget::finishedAnimation()
|
|
|
|
{
|
|
|
|
bool hide = (animation->direction() == QAbstractAnimation::Backward);
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-25 21:43:40 +08:00
|
|
|
// Delay it by a few frames to let the system catch up on rendering
|
|
|
|
if (hide)
|
2015-05-08 02:35:35 +08:00
|
|
|
QTimer::singleShot(50, this, SIGNAL(hidden()));
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
}
|
2015-04-02 22:56:16 +08:00
|
|
|
|
|
|
|
void FlyoutOverlayWidget::startAnimation(bool forward)
|
|
|
|
{
|
2015-04-02 23:10:26 +08:00
|
|
|
setAttribute(Qt::WA_TransparentForMouseEvents, !forward);
|
2015-04-02 22:56:16 +08:00
|
|
|
animation->setDirection(forward ? QAbstractAnimation::Forward : QAbstractAnimation::Backward);
|
|
|
|
animation->start();
|
|
|
|
animation->setCurrentTime(animation->duration() * percent);
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-04-02 22:56:16 +08:00
|
|
|
}
|