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

Last change on this file since 55 was 15, checked in by Bayard Gildas, 9 years ago

sources reformatted with flair-format-dir script

File size: 2.4 KB
RevLine 
[10]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[10]4// %flair:license}
[9]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
[15]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);
[9]19
[15]20 parent->addWidget(box, row, col);
[9]21
[15]22 label = new QLabel();
[9]23
[15]24 layout = new QVBoxLayout;
25 layout->addWidget(label);
26 box->setLayout(layout);
[9]27
[15]28 visible_widget = box;
[9]29
[15]30 label->setAlignment(Qt::AlignCenter);
[9]31
[15]32 im_width = width;
33 im_height = height;
34 label->setMinimumSize(width, height);
35 label->setMaximumSize(width, height);
36 receivesize = width * height;
[9]37
[15]38 for (int i = 0; i < 256; i++) {
39 color_table.append(qRgb(i, i, i));
40 }
[9]41
[15]42 label->installEventFilter(this);
[9]43}
44
[15]45Picture::~Picture() { delete layout; }
[9]46
[15]47void Picture::BufEvent(char **buf, int *buf_size, uint16_t period,
48 bool big_endian) {
49 if (big_endian)
50 printf("Picture::BufEvent, big endian not handled\n");
[9]51
[15]52 if (IsEnabled() == false || RefreshRate_ms() != period)
53 return;
[9]54
[15]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);
[9]60
[15]61 label->setPixmap(QPixmap::fromImage(image));
62 } else
63 printf("buffer trop petit\n");
64}
[9]65
[15]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;
[9]72 }
73
[15]74 default:
75 break;
76 }
77 }
78 return label->eventFilter(o, e);
[9]79}
80
[15]81void Picture::mousePressEvent(QMouseEvent *event) {
[9]82
[15]83 if (event->x() > 0 && event->x() < label->width() && event->y() > 0 &&
84 event->y() < label->height() && event->button() == Qt::RightButton) {
[9]85
[15]86 QMenu *menu = new QMenu("nom", label);
87 // ajout des actions
88 QAction *a, *z;
[9]89
[15]90 a = menu->addAction("get frame");
91 a->setEnabled(!auto_refresh);
[9]92
[15]93 appendmenu(menu);
94 z = execmenu(label, menu, event->globalPos());
95 delete menu;
96 }
[9]97}
98
[15]99void Picture::XmlEvent(QDomElement dom) { XmlSetup(dom); }
Note: See TracBrowser for help on using the repository browser.