added animation to NotebookPageDropPreview

This commit is contained in:
fourtf 2017-01-16 17:20:48 +01:00
parent d7f98030e1
commit 7901071408
3 changed files with 28 additions and 2 deletions

View file

@ -175,8 +175,10 @@ NotebookPage::setPreviewRect(QPoint mousePos)
{
for (DropRegion region : m_dropRegions) {
if (region.rect.contains(mousePos)) {
m_preview.move(region.rect.x(), region.rect.y());
m_preview.resize(region.rect.width(), region.rect.height());
m_preview.setBounds(region.rect);
// m_preview.move(region.rect.x(), region.rect.y());
// m_preview.resize(region.rect.width(),
// region.rect.height());
m_preview.show();
m_preview.raise();

View file

@ -4,6 +4,8 @@
NotebookPageDropPreview::NotebookPageDropPreview(QWidget *parent)
: QWidget(parent)
, m_positionAnimation(this, "geometry")
, m_desiredGeometry()
{
setHidden(true);
}
@ -16,3 +18,19 @@ NotebookPageDropPreview::paintEvent(QPaintEvent *)
painter.fillRect(8, 8, width() - 17, height() - 17,
ColorScheme::instance().DropPreviewBackground);
}
void
NotebookPageDropPreview::setBounds(const QRect &rect)
{
if (rect == m_desiredGeometry) {
return;
}
m_positionAnimation.stop();
m_positionAnimation.setDuration(50);
m_positionAnimation.setStartValue(geometry());
m_positionAnimation.setEndValue(rect);
m_positionAnimation.start();
m_desiredGeometry = rect;
}

View file

@ -1,6 +1,7 @@
#ifndef NOTEBOOKPAGEDROPPREVIEW_H
#define NOTEBOOKPAGEDROPPREVIEW_H
#include <QPropertyAnimation>
#include <QWidget>
class NotebookPageDropPreview : public QWidget
@ -8,8 +9,13 @@ class NotebookPageDropPreview : public QWidget
public:
NotebookPageDropPreview(QWidget *parent);
void setBounds(const QRect &rect);
protected:
void paintEvent(QPaintEvent *);
QPropertyAnimation m_positionAnimation;
QRect m_desiredGeometry;
};
#endif // NOTEBOOKPAGEDROPPREVIEW_H