2017-01-18 21:30:23 +01:00
|
|
|
#include "widgets/notebookpagedroppreview.h"
|
2017-01-01 02:30:42 +01:00
|
|
|
#include "colorscheme.h"
|
|
|
|
|
2017-01-26 09:26:18 +01:00
|
|
|
#include <QDebug>
|
2017-01-18 04:52:47 +01:00
|
|
|
#include <QPainter>
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2017-01-15 17:13:25 +01:00
|
|
|
NotebookPageDropPreview::NotebookPageDropPreview(QWidget *parent)
|
2017-01-01 02:30:42 +01:00
|
|
|
: QWidget(parent)
|
2017-01-18 04:33:30 +01:00
|
|
|
, positionAnimation(this, "geometry")
|
|
|
|
, desiredGeometry()
|
2017-01-26 09:26:18 +01:00
|
|
|
, animate(false)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2017-01-26 09:26:18 +01:00
|
|
|
this->positionAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic));
|
|
|
|
this->setHidden(true);
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void NotebookPageDropPreview::paintEvent(QPaintEvent *)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
painter.fillRect(8, 8, width() - 17, height() - 17,
|
2017-01-24 20:15:12 +01:00
|
|
|
ColorScheme::getInstance().DropPreviewBackground);
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
2017-01-16 17:20:48 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void NotebookPageDropPreview::hideEvent(QHideEvent *)
|
2017-01-26 09:26:18 +01:00
|
|
|
{
|
|
|
|
animate = false;
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void NotebookPageDropPreview::setBounds(const QRect &rect)
|
2017-01-16 17:20:48 +01:00
|
|
|
{
|
2017-01-18 04:33:30 +01:00
|
|
|
if (rect == this->desiredGeometry) {
|
2017-01-16 17:20:48 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-26 09:26:18 +01:00
|
|
|
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);
|
|
|
|
}
|
2017-01-16 17:20:48 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
this->desiredGeometry = rect;
|
2017-01-26 09:26:18 +01:00
|
|
|
|
|
|
|
animate = true;
|
2017-01-16 17:20:48 +01:00
|
|
|
}
|
2017-01-18 21:30:23 +01:00
|
|
|
}
|
|
|
|
}
|