You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.2 KiB
C++
66 lines
1.2 KiB
C++
#include "qmyvideolabel.h"
|
|
#include <QtCore>
|
|
#include <QPainter>
|
|
#include <QImage>
|
|
#include <QMutexLocker>
|
|
|
|
|
|
QMYVideoLabel::QMYVideoLabel(QWidget *parent) : QLabel(parent)
|
|
{
|
|
m_pimage = new QImage(16, 16, QImage::Format_RGB888);
|
|
m_pimage->fill(QColor(0, 0, 255));
|
|
}
|
|
|
|
|
|
QMYVideoLabel::~QMYVideoLabel()
|
|
{
|
|
if(m_pimage != nullptr)
|
|
{
|
|
delete m_pimage;
|
|
}
|
|
m_pimage = nullptr;
|
|
}
|
|
|
|
void QMYVideoLabel::SetMode(const int mode)
|
|
{
|
|
m_mode= mode;
|
|
}
|
|
|
|
void QMYVideoLabel::SetImage(uchar *pRGB, const int width, const int height)
|
|
{
|
|
QMutexLocker lock(&m_mutex);
|
|
if(m_pimage != nullptr)
|
|
{
|
|
delete m_pimage;
|
|
}
|
|
|
|
m_pimage = new QImage(pRGB, width, height, QImage::Format_RGB32);
|
|
}
|
|
|
|
|
|
void QMYVideoLabel::SetImage(QImage &img)
|
|
{
|
|
QMutexLocker lock(&m_mutex);
|
|
if(m_pimage != nullptr)
|
|
{
|
|
delete m_pimage;
|
|
}
|
|
|
|
m_pimage = new QImage(img);
|
|
}
|
|
|
|
void QMYVideoLabel::paintEvent(QPaintEvent *event)
|
|
{
|
|
if(m_mode != 0)
|
|
{
|
|
QMutexLocker lock(&m_mutex);
|
|
QPainter painter(this);
|
|
if(m_pimage)
|
|
{
|
|
painter.drawImage(this->rect(), *m_pimage);
|
|
}
|
|
}else{
|
|
QLabel::paintEvent(event);
|
|
}
|
|
}
|