mirror-chatterino2/src/widgets/helper/droppreview.cpp

54 lines
1.3 KiB
C++
Raw Normal View History

2017-11-12 17:21:50 +01:00
#include "widgets/helper/droppreview.hpp"
2017-12-31 00:50:07 +01:00
#include "singletons/thememanager.hpp"
2017-01-01 02:30:42 +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
NotebookPageDropPreview::NotebookPageDropPreview(BaseWidget *parent)
: BaseWidget(parent)
2017-01-18 04:33:30 +01:00
, positionAnimation(this, "geometry")
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);
painter.fillRect(8, 8, this->width() - 17, this->height() - 17,
this->themeManager->splits.dropPreview);
2017-01-01 02:30:42 +01:00
}
2017-04-12 17:46:44 +02:00
void NotebookPageDropPreview::hideEvent(QHideEvent *)
{
this->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 (this->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;
this->animate = true;
}
} // namespace widgets
} // namespace chatterino