[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] | 14 | Picture::Picture(Layout *parent, int row, int col, QString name, uint16_t width,
|
---|
[437] | 15 | uint16_t height, bool enabled, uint16_t period)
|
---|
[15] | 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] | 45 | Picture::~Picture() { delete layout; }
|
---|
[9] | 46 |
|
---|
[444] | 47 | void Picture::BufEvent(char **buf, int *buf_size, uint16_t period,uint16_t nb_buffering,bool big_endian) {
|
---|
[15] | 48 | if (big_endian)
|
---|
[244] | 49 | fprintf(stderr,"Picture::BufEvent, big endian not handled\n");
|
---|
[9] | 50 |
|
---|
[444] | 51 | if (IsEnabled() == false || RefreshRate_ms() != period || NbBuffering()!=nb_buffering) return;
|
---|
[9] | 52 |
|
---|
[15] | 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);
|
---|
[9] | 58 |
|
---|
[15] | 59 | label->setPixmap(QPixmap::fromImage(image));
|
---|
| 60 | } else
|
---|
[244] | 61 | fprintf(stderr,"buffer trop petit\n");
|
---|
[15] | 62 | }
|
---|
[9] | 63 |
|
---|
[15] | 64 | bool Picture::eventFilter(QObject *o, QEvent *e) {
|
---|
| 65 | if (o == label) {
|
---|
| 66 | switch (e->type()) {
|
---|
| 67 | case QEvent::MouseButtonPress: {
|
---|
| 68 | mousePressEvent((QMouseEvent *)e);
|
---|
| 69 | break;
|
---|
[9] | 70 | }
|
---|
| 71 |
|
---|
[15] | 72 | default:
|
---|
| 73 | break;
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 | return label->eventFilter(o, e);
|
---|
[9] | 77 | }
|
---|
| 78 |
|
---|
[15] | 79 | void Picture::mousePressEvent(QMouseEvent *event) {
|
---|
[9] | 80 |
|
---|
[15] | 81 | if (event->x() > 0 && event->x() < label->width() && event->y() > 0 &&
|
---|
| 82 | event->y() < label->height() && event->button() == Qt::RightButton) {
|
---|
[9] | 83 |
|
---|
[15] | 84 | QMenu *menu = new QMenu("nom", label);
|
---|
| 85 | // ajout des actions
|
---|
| 86 | QAction *a, *z;
|
---|
[9] | 87 |
|
---|
[15] | 88 | a = menu->addAction("get frame");
|
---|
[444] | 89 | a->setEnabled(!IsEnabled());
|
---|
[9] | 90 |
|
---|
[15] | 91 | appendmenu(menu);
|
---|
| 92 | z = execmenu(label, menu, event->globalPos());
|
---|
| 93 | delete menu;
|
---|
| 94 | }
|
---|
[9] | 95 | }
|
---|
| 96 |
|
---|
[269] | 97 | void Picture::XmlEvent(QDomElement *dom) { XmlSetup(dom); }
|
---|