87 lines
1.6 KiB
C++
Executable File
87 lines
1.6 KiB
C++
Executable File
#include "track_entry_previewer.h"
|
|
#include "track_entry.h"
|
|
#include "track_entry_painters.h"
|
|
#include "track_content_widget.h"
|
|
|
|
#include <QPainter>
|
|
#include <QDrag>
|
|
#include <QMimeData>
|
|
#include <QMouseEvent>
|
|
|
|
|
|
namespace LtsScriptTimeline
|
|
{
|
|
|
|
QDataStream &operator<<(QDataStream &ds, const TrackEntry &te);
|
|
QDataStream &operator>>(QDataStream &ds, TrackEntry &te);
|
|
|
|
TrackEntryPreviewer::TrackEntryPreviewer(QWidget *parent)
|
|
: QWidget(parent)
|
|
, m_te(nullptr)
|
|
{
|
|
|
|
|
|
setVisible(false);
|
|
}
|
|
|
|
|
|
TrackEntryPreviewer::~TrackEntryPreviewer()
|
|
{}
|
|
|
|
|
|
void TrackEntryPreviewer::setTrackEntry(TrackEntry *te)
|
|
{
|
|
m_te = te;
|
|
|
|
if (m_te->isSet)
|
|
return;
|
|
|
|
connect(m_te, &TrackEntry::destroyed,
|
|
this, [this]()
|
|
{
|
|
m_te = nullptr;
|
|
emit signalDelete();
|
|
});
|
|
}
|
|
|
|
|
|
void TrackEntryPreviewer::mousePressEvent(QMouseEvent *event)
|
|
{
|
|
|
|
if (!m_te || event->buttons() != Qt::LeftButton)
|
|
return;
|
|
|
|
m_te->isSet = true;
|
|
QByteArray itemData(TrackContentWidget::itemsToData({ m_te }, 0));
|
|
m_te->isSet = false;
|
|
|
|
QMimeData *mimeData = new QMimeData;
|
|
mimeData->setData(TrackContentWidget::mime, itemData);
|
|
|
|
QDrag *drag = new QDrag(this);
|
|
drag->setDragCursor(QPixmap(), Qt::CopyAction);
|
|
drag->setMimeData(mimeData);
|
|
|
|
emit signalStartDrag();
|
|
|
|
if (drag->exec(Qt::CopyAction) == Qt::CopyAction)
|
|
emit signalDelete();
|
|
|
|
emit signalStopDrag();
|
|
}
|
|
|
|
|
|
void TrackEntryPreviewer::paintEvent(QPaintEvent *event)
|
|
{
|
|
QWidget::paintEvent(event);
|
|
|
|
QPainter painter(this);
|
|
|
|
if (!m_te)
|
|
return;
|
|
|
|
drawTrackEntry(m_te, painter, rect().adjusted(0, 0, -1, -1), false, isEnabled());
|
|
}
|
|
|
|
}
|