fixed notebookpagedroppreview animation

This commit is contained in:
fourtf
2017-01-26 09:26:18 +01:00
parent d012aa922d
commit a5e7ef9980
5 changed files with 54 additions and 30 deletions
+21 -6
View File
@@ -1,6 +1,7 @@
#include "widgets/notebookpagedroppreview.h"
#include "colorscheme.h"
#include <QDebug>
#include <QPainter>
namespace chatterino {
@@ -10,8 +11,10 @@ NotebookPageDropPreview::NotebookPageDropPreview(QWidget *parent)
: QWidget(parent)
, positionAnimation(this, "geometry")
, desiredGeometry()
, animate(false)
{
setHidden(true);
this->positionAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic));
this->setHidden(true);
}
void
@@ -23,6 +26,12 @@ NotebookPageDropPreview::paintEvent(QPaintEvent *)
ColorScheme::getInstance().DropPreviewBackground);
}
void
NotebookPageDropPreview::hideEvent(QHideEvent *)
{
animate = false;
}
void
NotebookPageDropPreview::setBounds(const QRect &rect)
{
@@ -30,13 +39,19 @@ NotebookPageDropPreview::setBounds(const QRect &rect)
return;
}
this->positionAnimation.stop();
this->positionAnimation.setDuration(50);
this->positionAnimation.setStartValue(geometry());
this->positionAnimation.setEndValue(rect);
this->positionAnimation.start();
if (animate) {
this->positionAnimation.stop();
this->positionAnimation.setDuration(50);
this->positionAnimation.setStartValue(this->geometry());
this->positionAnimation.setEndValue(rect);
this->positionAnimation.start();
} else {
this->setGeometry(rect);
}
this->desiredGeometry = rect;
animate = true;
}
}
}