Changeset 15 in flair-src for trunk/tools/FlairGCS/src/Picture.cpp


Ignore:
Timestamp:
Apr 8, 2016, 3:40:57 PM (5 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/FlairGCS/src/Picture.cpp

    r10 r15  
    1212#include <QVBoxLayout>
    1313
    14 Picture::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);
     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);
    1819
    19     parent->addWidget(box,row,col);
     20  parent->addWidget(box, row, col);
    2021
    21     label=new QLabel();
     22  label = new QLabel();
    2223
    23     layout = new QVBoxLayout;
    24     layout->addWidget(label);
    25     box->setLayout(layout);
     24  layout = new QVBoxLayout;
     25  layout->addWidget(label);
     26  box->setLayout(layout);
    2627
    27     visible_widget=box;
     28  visible_widget = box;
    2829
    29     label->setAlignment(Qt::AlignCenter);
     30  label->setAlignment(Qt::AlignCenter);
    3031
    31     im_width=width;
    32     im_height=height;
    33     label->setMinimumSize(width,height);
    34     label->setMaximumSize(width,height);
    35     receivesize=width*height;
     32  im_width = width;
     33  im_height = height;
     34  label->setMinimumSize(width, height);
     35  label->setMaximumSize(width, height);
     36  receivesize = width * height;
    3637
    37     for(int i=0;i<256;i++)
    38     {
    39         color_table.append(qRgb(i,i,i));
     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    printf("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    printf("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;
    4072    }
    4173
    42     label->installEventFilter(this);
     74    default:
     75      break;
     76    }
     77  }
     78  return label->eventFilter(o, e);
    4379}
    4480
     81void Picture::mousePressEvent(QMouseEvent *event) {
    4582
    46 Picture::~Picture()
    47 {
    48     delete layout;
     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  }
    4997}
    5098
    51 void 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 
    69 bool 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 
    88 void 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 
    110 void Picture::XmlEvent(QDomElement dom)
    111 {
    112     XmlSetup(dom);
    113 }
     99void Picture::XmlEvent(QDomElement dom) { XmlSetup(dom); }
Note: See TracChangeset for help on using the changeset viewer.