mirror-chatterino2/widgets/notebookpagedroppreview.cpp

55 lines
1.2 KiB
C++
Raw Normal View History

2017-01-18 21:30:23 +01:00
#include "widgets/notebookpagedroppreview.h"
2017-01-01 02:30:42 +01:00
#include "colorscheme.h"
#include <QDebug>
2017-01-18 04:52:47 +01:00
#include <QPainter>
2017-04-14 17:47:28 +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()
, animate(false)
2017-01-01 02:30:42 +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-04-12 17:46:44 +02:00
void NotebookPageDropPreview::hideEvent(QHideEvent *)
{
animate = false;
}
2017-04-12 17:46:44 +02:00
void NotebookPageDropPreview::setBounds(const QRect &rect)
{
2017-01-18 04:33:30 +01:00
if (rect == this->desiredGeometry) {
return;
}
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-18 04:33:30 +01:00
this->desiredGeometry = rect;
animate = true;
}
2017-01-18 21:30:23 +01:00
}
}