Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+83
@@ -0,0 +1,83 @@
|
||||
#include "topic_previewer.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
namespace TopicEditorBase
|
||||
{
|
||||
|
||||
TopicPreviewer::TopicPreviewer(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
// setMinimumSize(50, 50);
|
||||
// setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
TopicPreviewer::~TopicPreviewer()
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC
|
||||
|
||||
void TopicPreviewer::setTopicData(const TopicData &data)
|
||||
{
|
||||
m_topicData = data;
|
||||
|
||||
if (m_topicData.state) // is already set (no d&d)
|
||||
return;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// PROTECTED
|
||||
|
||||
void TopicPreviewer::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
// check if it's a drag + topic data is valid
|
||||
if (m_topicData.topicType == TopicType::Invalid || m_topicData.duration < 1 || event->buttons() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
m_topicData.state = true; // temporary !
|
||||
QByteArray byteArray;
|
||||
QDataStream dataStream(&byteArray, QIODevice::WriteOnly);
|
||||
dataStream << m_topicData;
|
||||
m_topicData.state = false; // set back, so that THIS te is kept unset
|
||||
QMimeData *mimeData = new QMimeData;
|
||||
mimeData->setData(TopicData::mime, byteArray);
|
||||
QDrag *drag = new QDrag(this);
|
||||
drag->setDragCursor(QPixmap(), Qt::CopyAction);
|
||||
drag->setMimeData(mimeData);
|
||||
emit startDragMe();
|
||||
if (drag->exec(Qt::CopyAction) == Qt::CopyAction) // exec... grr...
|
||||
emit deleteMe();
|
||||
emit stopDragMe();
|
||||
}
|
||||
|
||||
|
||||
void TopicPreviewer::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QWidget::paintEvent(event);
|
||||
|
||||
if (m_topicData.topicType == TopicType::Invalid)
|
||||
return;
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setClipping(true);
|
||||
painter.setClipRect(rect(), Qt::ReplaceClip);
|
||||
painter.setPen(isEnabled() ? Qt::black : Qt::lightGray);
|
||||
painter.setBrush(QBrush(topicTypeColor(m_topicData.topicType)));
|
||||
painter.drawRect(rect().adjusted(0, 0, -1, -1));
|
||||
painter.drawText(rect().adjusted(3, 16, -1, -1), m_topicData.description);
|
||||
if (!isEnabled())
|
||||
{
|
||||
painter.setBrush(QBrush(QColor(255, 255, 255, 204)));
|
||||
painter.drawRect(rect().adjusted(0, 0, -1, -1));
|
||||
}
|
||||
// drawTrackEntry(m_te, painter, rect().adjusted(0, 0, -1, -1), false, isEnabled());
|
||||
}
|
||||
|
||||
} // namespace TopicEditorBase
|
||||
Reference in new issue
Block a user