Continues migration with DDS, Common
This commit is contained in:
1 parent
9b15cee841
commit
fa48db111e
668 files changed
+111841
-2
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)
|
||||
{
|
||||
|
||||
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
TopicPreviewer::~TopicPreviewer()
|
||||
{}
|
||||
|
||||
|
||||
|
||||
|
||||
void TopicPreviewer::setTopicData(const TopicData &data)
|
||||
{
|
||||
m_topicData = data;
|
||||
|
||||
if (m_topicData.state)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void TopicPreviewer::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
|
||||
if (m_topicData.topicType == TopicType::Invalid || m_topicData.duration < 1 || event->buttons() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
m_topicData.state = true;
|
||||
QByteArray byteArray;
|
||||
QDataStream dataStream(&byteArray, QIODevice::WriteOnly);
|
||||
dataStream << m_topicData;
|
||||
m_topicData.state = false;
|
||||
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)
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user