| 1 | #include "Picture.h"
|
---|
| 2 | #include "Layout.h"
|
---|
| 3 | #include <QMenu>
|
---|
| 4 | #include <QInputDialog>
|
---|
| 5 | #include <QLabel>
|
---|
| 6 | #include <QMouseEvent>
|
---|
| 7 | #include <QGroupBox>
|
---|
| 8 | #include <QVBoxLayout>
|
---|
| 9 |
|
---|
| 10 | Picture::Picture(Layout* parent,int row, int col,QString name,uint16_t width, uint16_t height,bool enabled,int period):DataRemote(name,"Picture",parent,enabled,period)
|
---|
| 11 | {
|
---|
| 12 | box = new QGroupBox(name);
|
---|
| 13 | box->setObjectName(name);
|
---|
| 14 |
|
---|
| 15 | parent->addWidget(box,row,col);
|
---|
| 16 |
|
---|
| 17 | label=new QLabel();
|
---|
| 18 |
|
---|
| 19 | layout = new QVBoxLayout;
|
---|
| 20 | layout->addWidget(label);
|
---|
| 21 | box->setLayout(layout);
|
---|
| 22 |
|
---|
| 23 | visible_widget=box;
|
---|
| 24 |
|
---|
| 25 | label->setAlignment(Qt::AlignCenter);
|
---|
| 26 |
|
---|
| 27 | im_width=width;
|
---|
| 28 | im_height=height;
|
---|
| 29 | label->setMinimumSize(width,height);
|
---|
| 30 | label->setMaximumSize(width,height);
|
---|
| 31 | receivesize=width*height;
|
---|
| 32 |
|
---|
| 33 | for(int i=0;i<256;i++)
|
---|
| 34 | {
|
---|
| 35 | color_table.append(qRgb(i,i,i));
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | label->installEventFilter(this);
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | Picture::~Picture()
|
---|
| 43 | {
|
---|
| 44 | delete layout;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | void Picture::BufEvent(char** buf,int *buf_size,uint16_t period,bool big_endian)
|
---|
| 48 | {
|
---|
| 49 | if(big_endian) printf("Picture::BufEvent, big endian not handled\n");
|
---|
| 50 |
|
---|
| 51 | if(IsEnabled()==false || RefreshRate_ms()!=period) return;
|
---|
| 52 |
|
---|
| 53 | if((*buf_size)>=im_width*im_height)
|
---|
| 54 | {
|
---|
| 55 | QImage image= QImage((const uchar*)*buf,im_width,im_height,QImage::Format_Indexed8);//Format_RGB888);
|
---|
| 56 | *buf+=im_width*im_height;
|
---|
| 57 | image.setColorTable(color_table);
|
---|
| 58 |
|
---|
| 59 | label->setPixmap(QPixmap::fromImage(image));
|
---|
| 60 | }
|
---|
| 61 | else
|
---|
| 62 | printf("buffer trop petit\n");
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | bool Picture::eventFilter(QObject *o, QEvent *e)
|
---|
| 66 | {
|
---|
| 67 | if ( o == label )
|
---|
| 68 | {
|
---|
| 69 | switch(e->type())
|
---|
| 70 | {
|
---|
| 71 | case QEvent::MouseButtonPress:
|
---|
| 72 | {
|
---|
| 73 | mousePressEvent((QMouseEvent*)e);
|
---|
| 74 | break;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | default:
|
---|
| 78 | break;
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 | return label->eventFilter(o, e);
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | void Picture::mousePressEvent(QMouseEvent * event)
|
---|
| 85 | {
|
---|
| 86 |
|
---|
| 87 | if(event->x() > 0 && event->x() < label->width() &&
|
---|
| 88 | event->y() > 0 && event->y() < label->height() &&
|
---|
| 89 | event->button() == Qt::RightButton)
|
---|
| 90 | {
|
---|
| 91 |
|
---|
| 92 | QMenu * menu = new QMenu("nom", label);
|
---|
| 93 | // ajout des actions
|
---|
| 94 | QAction *a,*z;
|
---|
| 95 |
|
---|
| 96 | a=menu->addAction("get frame");
|
---|
| 97 | a->setEnabled(!auto_refresh);
|
---|
| 98 |
|
---|
| 99 | appendmenu(menu);
|
---|
| 100 | z=execmenu(label,menu,event->globalPos());
|
---|
| 101 | delete menu;
|
---|
| 102 |
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | void Picture::XmlEvent(QDomElement dom)
|
---|
| 107 | {
|
---|
| 108 | XmlSetup(dom);
|
---|
| 109 | }
|
---|