125 lines
3.7 KiB
C++
125 lines
3.7 KiB
C++
#include "viewwidget.h"
|
|
#include "qimageview.h"
|
|
#include "qimagewidget.h"
|
|
#include <QGridLayout>
|
|
#include <QDebug>
|
|
viewWidget::viewWidget(QWidget *parent) : QWidget(parent)
|
|
{
|
|
setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::MSWindowsFixedSizeDialogHint
|
|
| Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint);
|
|
|
|
init();
|
|
}
|
|
|
|
viewWidget::~viewWidget()
|
|
{
|
|
if (qgraphicsScene) {
|
|
delete qgraphicsScene;
|
|
qgraphicsScene = nullptr;
|
|
}
|
|
/* if (m_pImage) {
|
|
delete m_pImage;
|
|
m_pImage = nullptr;
|
|
}*/
|
|
qDebug() << " [INFO] " << " m_key:" << m_key << " delete success!" ;
|
|
}
|
|
|
|
void viewWidget::init()
|
|
{
|
|
|
|
m_Font.setFamily("Microsoft YaHei");
|
|
m_Font.setPixelSize(20);
|
|
|
|
//QString m_style = "QLabel{border-with:0; border-style:outset; background:transparent; color:rgb(255,255,255);}"; //报警 Unknown property border-with
|
|
QString m_style = "QLabel{ border-style:outset; background:transparent; color:rgb(255,255,255);}";
|
|
QLabel* m_lab = new QLabel;
|
|
m_lab->setFont(m_Font);
|
|
m_lab->setStyleSheet(m_style);
|
|
m_lab->setAlignment(Qt::AlignCenter);
|
|
labptr.reset(m_lab);
|
|
|
|
|
|
//显示窗口
|
|
qgraphicsScene = new QGraphicsScene;
|
|
m_view = new QImageView(this);
|
|
m_view->setScene(qgraphicsScene);//Sets the current scene to scene. If scene is already being viewed, this function does nothing.
|
|
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);//关闭滑动条
|
|
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
//label
|
|
QLabel* m_pos = new QLabel;
|
|
m_pos->setFont(m_Font);
|
|
m_pos->setStyleSheet(m_style);
|
|
m_pos->setAlignment(Qt::AlignCenter);
|
|
label_ptr.reset(m_pos);
|
|
|
|
QVBoxLayout* vBox = new QVBoxLayout;
|
|
layout_ptr.reset(vBox);
|
|
//vBox->addWidget(m_lab);
|
|
//vBox->addWidget(m_view);
|
|
//vBox->addWidget(m_pos);
|
|
//vBox->setContentsMargins(0, 0, 0, 0);
|
|
|
|
QGridLayout* vBox1 = new QGridLayout;
|
|
layout2_ptr.reset(vBox1);
|
|
vBox1->addWidget(m_lab, 0, 0, 1, -1);
|
|
vBox1->addWidget(m_view, 0, 0, 20, -1);
|
|
vBox1->addWidget(m_pos, 19, 0, 1, -1);
|
|
vBox->addLayout(vBox1, -1);
|
|
|
|
delete this->layout();
|
|
this->setLayout(vBox);
|
|
setSizePolicy(QSizePolicy (QSizePolicy::Preferred, QSizePolicy::Expanding));
|
|
|
|
}
|
|
|
|
void viewWidget::resizeEvent(QResizeEvent *event)
|
|
{
|
|
Q_UNUSED(event);
|
|
|
|
}
|
|
|
|
void viewWidget::setName(QString name)
|
|
{
|
|
m_Name = name;
|
|
|
|
labptr->setText(m_Name);
|
|
}
|
|
|
|
|
|
|
|
void viewWidget::reciveImage(QString key,QImage* image)
|
|
{
|
|
//qDebug() << __FUNCTION__ << "line:" << __LINE__ << " key:" << key;
|
|
try
|
|
{
|
|
/*foreach (QGraphicsItem *item, view_ptr->scene()->items())
|
|
{
|
|
view_ptr->scene()->removeItem(item);
|
|
}*/
|
|
|
|
m_pImage = new QImageWidget(image);
|
|
qgraphicsScene->clear();
|
|
int nwith = m_view->width();//获取界面控件Graphics View的宽度
|
|
int nheight = m_view->height();//获取界面控件Graphics View的高度
|
|
m_pImage->setQGraphicsViewWH(nwith, nheight);//将界面控件Graphics View的width和height传进类m_Image中
|
|
qgraphicsScene->addItem(m_pImage);//将QGraphicsItem类对象放进QGraphicsScene中
|
|
m_view->setSceneRect(QRectF(-(nwith / 2), -(nheight / 2), nwith, nheight));
|
|
// ui->graphicsView->setScene(qgraphicsScene);
|
|
m_view->setFocus();//将界面的焦点设置到当前Graphics View控件
|
|
}
|
|
catch (QString ev)
|
|
{
|
|
qDebug() << " [Error] " << " ev:" << ev;
|
|
}
|
|
//qDebug() << __FUNCTION__ << " line:" << __LINE__ << " reciveData success!";
|
|
}
|
|
|
|
void viewWidget::reciveData(QString cameraName,QByteArray byte)
|
|
{
|
|
//qDebug() << __FUNCTION__ << " line:" << __LINE__ << " byte len:" << byte.length();
|
|
label_ptr->setText(byte);
|
|
}
|
|
|
|
|