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

Last change on this file since 474 was 444, checked in by Sanahuja Guillaume, 3 years ago

update buffering (gcs part)
seems to work!

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