mirror-chatterino2/widgets/notebookpagedroppreview.cpp

43 lines
917 B
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"
2017-01-18 04:52:47 +01:00
#include <QPainter>
2017-01-18 21:30:23 +01:00
namespace chatterino {
namespace widgets {
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-01 02:30:42 +01:00
{
setHidden(true);
2017-01-01 02:30:42 +01:00
}
2017-01-11 18:52:09 +01: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,
ColorScheme::instance().DropPreviewBackground);
2017-01-01 02:30:42 +01:00
}
void
NotebookPageDropPreview::setBounds(const QRect &rect)
{
2017-01-18 04:33:30 +01:00
if (rect == this->desiredGeometry) {
return;
}
2017-01-18 04:33:30 +01:00
this->positionAnimation.stop();
this->positionAnimation.setDuration(50);
this->positionAnimation.setStartValue(geometry());
this->positionAnimation.setEndValue(rect);
this->positionAnimation.start();
2017-01-18 04:33:30 +01:00
this->desiredGeometry = rect;
}
2017-01-18 21:30:23 +01:00
}
}