source: flair-src/trunk/tools/FlairGCS/src/Picture.cpp@ 10

Last change on this file since 10 was 10, checked in by Sanahuja Guillaume, 6 years ago

lic

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