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

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

modifs segfault when closing connection

File size: 2.4 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, int 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,
48                       bool big_endian) {
49  if (big_endian)
50    fprintf(stderr,"Picture::BufEvent, big endian not handled\n");
51
52  if (IsEnabled() == false || RefreshRate_ms() != period)
53    return;
54
55  if ((*buf_size) >= im_width * im_height) {
56    QImage image = QImage((const uchar *)*buf, im_width, im_height,
57                          QImage::Format_Indexed8); // Format_RGB888);
58    *buf += im_width *im_height;
59    image.setColorTable(color_table);
60
61    label->setPixmap(QPixmap::fromImage(image));
62  } else
63    fprintf(stderr,"buffer trop petit\n");
64}
65
66bool Picture::eventFilter(QObject *o, QEvent *e) {
67  if (o == label) {
68    switch (e->type()) {
69    case QEvent::MouseButtonPress: {
70      mousePressEvent((QMouseEvent *)e);
71      break;
72    }
73
74    default:
75      break;
76    }
77  }
78  return label->eventFilter(o, e);
79}
80
81void Picture::mousePressEvent(QMouseEvent *event) {
82
83  if (event->x() > 0 && event->x() < label->width() && event->y() > 0 &&
84      event->y() < label->height() && event->button() == Qt::RightButton) {
85
86    QMenu *menu = new QMenu("nom", label);
87    // ajout des actions
88    QAction *a, *z;
89
90    a = menu->addAction("get frame");
91    a->setEnabled(!auto_refresh);
92
93    appendmenu(menu);
94    z = execmenu(label, menu, event->globalPos());
95    delete menu;
96  }
97}
98
99void Picture::XmlEvent(QDomElement dom) { XmlSetup(dom); }
Note: See TracBrowser for help on using the repository browser.