Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+86
@@ -0,0 +1,86 @@
|
||||
#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
|
||||
{
|
||||
// only for dnd
|
||||
QDataStream &operator<<(QDataStream &ds, const TrackEntry &te);
|
||||
QDataStream &operator>>(QDataStream &ds, TrackEntry &te);
|
||||
|
||||
TrackEntryPreviewer::TrackEntryPreviewer(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_te(nullptr)
|
||||
{
|
||||
// setMinimumSize(50, 50);
|
||||
// setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
TrackEntryPreviewer::~TrackEntryPreviewer()
|
||||
{}
|
||||
|
||||
|
||||
void TrackEntryPreviewer::setTrackEntry(TrackEntry *te)
|
||||
{
|
||||
m_te = te;
|
||||
|
||||
if (m_te->isSet) // is already set (no d&d)
|
||||
return;
|
||||
|
||||
connect(m_te, &TrackEntry::destroyed,
|
||||
this, [this]()
|
||||
{
|
||||
m_te = nullptr;
|
||||
emit signalDelete();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void TrackEntryPreviewer::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
// check if it's a drag + te exists
|
||||
if (!m_te || event->buttons() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
m_te->isSet = true; // temporary !
|
||||
QByteArray itemData(TrackContentWidget::itemsToData({ m_te }, 0));
|
||||
m_te->isSet = false; // set back, so that THIS te is kept unset
|
||||
|
||||
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) // exec... grr...
|
||||
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());
|
||||
}
|
||||
|
||||
} // namespace LtsScriptTimeline
|
||||
Reference in new issue
Block a user