Ignore:
Timestamp:
04/08/16 15:40:57 (6 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

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

    r10 r15  
    1212#include "Layout.h"
    1313
     14Vector3DSpinBox::Vector3DSpinBox(Layout *parent, int row, int col, QString name,
     15                                 QString value[3], float min, float max,
     16                                 float step, int decimals)
     17    : XmlWidget(name, "Vector3DSpinBox", parent) {
     18  for (int i = 0; i < 3; i++) {
     19    doublespinbox[i].setRange(min, max);
     20    doublespinbox[i].setSingleStep(step);
     21    doublespinbox[i].setDecimals(decimals);
     22  }
    1423
    15 Vector3DSpinBox::Vector3DSpinBox(Layout* parent,int row, int col,QString name,QString value[3],float min,float max,float step,int decimals): XmlWidget(name,"Vector3DSpinBox",parent) {
    16     for(int i=0;i<3;i++) {
    17         doublespinbox[i].setRange(min,max);
    18         doublespinbox[i].setSingleStep(step);
    19         doublespinbox[i].setDecimals(decimals);
     24  adjust_decimals(value);
     25
     26  for (int i = 0; i < 3; i++) {
     27    doublespinbox[i].setValue(value[i].toDouble());
     28    doublespinbox_value[i] = doublespinbox[i].cleanText();
     29
     30    // event filter for qdoublespinbox and its child (qlinedit and incremnt
     31    // qbuttons)
     32    doublespinbox[i].installEventFilter(this);
     33    QObjectList o_list = doublespinbox[i].children();
     34    for (int j = 0; j < o_list.length(); j++) {
     35      QLineEdit *cast = qobject_cast<QLineEdit *>(o_list[j]);
     36      if (cast)
     37        cast->installEventFilter(this);
    2038    }
    2139
    22     adjust_decimals(value);
     40    connect(&doublespinbox[i], SIGNAL(valueChanged(const QString &)), this,
     41            SLOT(valuechanged(const QString &)));
     42  }
    2343
    24     for(int i=0;i<3;i++) {
    25         doublespinbox[i].setValue(value[i].toDouble());
    26         doublespinbox_value[i]=doublespinbox[i].cleanText();
     44  SetValues(value);
    2745
    28         //event filter for qdoublespinbox and its child (qlinedit and incremnt qbuttons)
    29         doublespinbox[i].installEventFilter(this);
    30         QObjectList o_list = doublespinbox[i].children();
    31         for(int j = 0; j < o_list.length(); j++) {
    32             QLineEdit *cast = qobject_cast<QLineEdit*>(o_list[j]);
    33             if(cast)
    34                 cast->installEventFilter(this);
    35         }
     46  // creation et ajout QGroupBox
     47  box = new QGroupBox(name);
     48  box->setObjectName(name);
     49  visible_widget = box;
     50  parent->addWidget(box, row, col);
     51  qgridlayout = new QGridLayout(new QWidget());
     52  box->setLayout(qgridlayout);
    3653
    37         connect(&doublespinbox[i],SIGNAL(valueChanged(const QString &)),this, SLOT(valuechanged(const QString &)));
    38     }
    39 
    40     SetValues(value);
    41 
    42     //creation et ajout QGroupBox
    43     box = new QGroupBox(name);
    44     box->setObjectName(name);
    45     visible_widget=box;
    46     parent->addWidget(box,row,col);
    47     qgridlayout=new QGridLayout(new QWidget());
    48     box->setLayout(qgridlayout);
    49 
    50     AddElement("x:",0);
    51     AddElement("y:",1);
    52     AddElement("z:",2);
     54  AddElement("x:", 0);
     55  AddElement("y:", 1);
     56  AddElement("z:", 2);
    5357}
    5458
    55 Vector3DSpinBox::~Vector3DSpinBox() {
     59Vector3DSpinBox::~Vector3DSpinBox() {}
     60
     61void Vector3DSpinBox::SetValues(QString value[3]) {
     62  SetAttribute("value_x", value[0]);
     63  SetAttribute("value_y", value[1]);
     64  SetAttribute("value_z", value[2]);
    5665}
    5766
    58 void Vector3DSpinBox::SetValues(QString value[3]) {
    59     SetAttribute("value_x",value[0]);
    60     SetAttribute("value_y",value[1]);
    61     SetAttribute("value_z",value[2]);
    62 }
     67void Vector3DSpinBox::AddElement(QString name, int index) {
     68  QWidget *widget = new QWidget();
     69  QFormLayout *object_layout = new QFormLayout(widget);
     70  object_layout->setHorizontalSpacing(2);
     71  object_layout->setVerticalSpacing(2);
     72  object_layout->setContentsMargins(2, 2, 2, 2);
    6373
    64 void Vector3DSpinBox::AddElement(QString name,int index) {
    65     QWidget* widget=new QWidget();
    66     QFormLayout* object_layout = new QFormLayout(widget);
    67     object_layout->setHorizontalSpacing(2);
    68     object_layout->setVerticalSpacing(2);
    69     object_layout->setContentsMargins (2,2,2,2);
     74  object_layout->addRow(name, &doublespinbox[index]);
    7075
    71     object_layout->addRow(name,&doublespinbox[index]);
    72 
    73     qgridlayout->addWidget(widget,index,0);
     76  qgridlayout->addWidget(widget, index, 0);
    7477}
    7578
    7679void Vector3DSpinBox::adjust_decimals(QString value[3]) {
    77     for(int i=0;i<3;i++) {
    78         //auto adjust decimals
    79         QLocale locale;
    80         value[i].remove(locale.groupSeparator());
     80  for (int i = 0; i < 3; i++) {
     81    // auto adjust decimals
     82    QLocale locale;
     83    value[i].remove(locale.groupSeparator());
    8184
    82         QStringList parts = value[i].split(locale.decimalPoint());
    83         if(parts.count() == 2) {
    84             doublespinbox[i].setDecimals(parts[1].size());
    85         }
     85    QStringList parts = value[i].split(locale.decimalPoint());
     86    if (parts.count() == 2) {
     87      doublespinbox[i].setDecimals(parts[1].size());
    8688    }
     89  }
    8790}
    8891
    8992bool Vector3DSpinBox::eventFilter(QObject *object, QEvent *event) {
    90     for(int i=0;i<3;i++) {
    91         if(object==&doublespinbox[i] && event->type()==QEvent::MouseButtonPress) {
    92             if (((QMouseEvent*)event)->button() == Qt::RightButton) {
    93                 QMenu * menu = new QMenu("menu", doublespinbox);
    94                 QAction *a,*b,*c,*z;
     93  for (int i = 0; i < 3; i++) {
     94    if (object == &doublespinbox[i] &&
     95        event->type() == QEvent::MouseButtonPress) {
     96      if (((QMouseEvent *)event)->button() == Qt::RightButton) {
     97        QMenu *menu = new QMenu("menu", doublespinbox);
     98        QAction *a, *b, *c, *z;
    9599
    96                 a=menu->addAction("add decimal");
    97                 b=menu->addAction("remove decimal");
     100        a = menu->addAction("add decimal");
     101        b = menu->addAction("remove decimal");
    98102
    99                 if(doublespinbox[i].decimals()==0) b->setEnabled(false);
    100                 z=menu->exec(((QMouseEvent*)event)->globalPos());
     103        if (doublespinbox[i].decimals() == 0)
     104          b->setEnabled(false);
     105        z = menu->exec(((QMouseEvent *)event)->globalPos());
    101106
    102                 if(z==a) doublespinbox[i].setDecimals(doublespinbox[i].decimals()+1);
    103                 if(z==b) doublespinbox[i].setDecimals(doublespinbox[i].decimals()-1);
    104                 delete menu;
    105                 return true;
    106             }
    107         }
     107        if (z == a)
     108          doublespinbox[i].setDecimals(doublespinbox[i].decimals() + 1);
     109        if (z == b)
     110          doublespinbox[i].setDecimals(doublespinbox[i].decimals() - 1);
     111        delete menu;
     112        return true;
     113      }
    108114    }
    109     return object->eventFilter(object, event);
     115  }
     116  return object->eventFilter(object, event);
    110117}
    111118
    112119void Vector3DSpinBox::SetUptodate(void) {
    113     ui_to_var();
    114     ui_to_xml();
    115     visible_widget->setPalette(black_pal);
     120  ui_to_var();
     121  ui_to_xml();
     122  visible_widget->setPalette(black_pal);
    116123}
    117124
    118125void Vector3DSpinBox::ui_to_var(void) {
    119     for(int i=0;i<3;i++) {
    120         doublespinbox_value[i]=doublespinbox[i].cleanText();
    121     }
     126  for (int i = 0; i < 3; i++) {
     127    doublespinbox_value[i] = doublespinbox[i].cleanText();
     128  }
    122129}
    123130
    124131void Vector3DSpinBox::ui_to_xml(void) {
    125     SetAttribute("value_x",doublespinbox[0].cleanText());
    126     SetAttribute("value_y",doublespinbox[1].cleanText());
    127     SetAttribute("value_z",doublespinbox[2].cleanText());
     132  SetAttribute("value_x", doublespinbox[0].cleanText());
     133  SetAttribute("value_y", doublespinbox[1].cleanText());
     134  SetAttribute("value_z", doublespinbox[2].cleanText());
    128135}
    129136
    130137void Vector3DSpinBox::Reset(void) {
    131     //le setvalue fait un arrondi pour l'affichage, la variable n'est donc plus egale
    132     //on reprend la valeur de la boite et on force la couleur a noir
    133     adjust_decimals(doublespinbox_value);
    134     for(int i=0;i<3;i++) {
    135         doublespinbox[i].setValue(doublespinbox_value[i].toDouble());
    136         doublespinbox_value[i]= doublespinbox[i].cleanText();
    137     }
    138     visible_widget->setPalette(black_pal);
     138  // le setvalue fait un arrondi pour l'affichage, la variable n'est donc plus
     139  // egale
     140  // on reprend la valeur de la boite et on force la couleur a noir
     141  adjust_decimals(doublespinbox_value);
     142  for (int i = 0; i < 3; i++) {
     143    doublespinbox[i].setValue(doublespinbox_value[i].toDouble());
     144    doublespinbox_value[i] = doublespinbox[i].cleanText();
     145  }
     146  visible_widget->setPalette(black_pal);
    139147}
    140148
    141149void Vector3DSpinBox::LoadEvent(QDomElement dom) {
    142     if(doublespinbox[0].isEnabled()) {
    143         doublespinbox[0].setValue((dom.attribute("value_x")).toDouble());
    144     }
    145     if(doublespinbox[1].isEnabled()) {
    146         doublespinbox[1].setValue((dom.attribute("value_y")).toDouble());
    147     }
    148     if(doublespinbox[2].isEnabled()) {
    149         doublespinbox[2].setValue((dom.attribute("value_z")).toDouble());
    150     }
     150  if (doublespinbox[0].isEnabled()) {
     151    doublespinbox[0].setValue((dom.attribute("value_x")).toDouble());
     152  }
     153  if (doublespinbox[1].isEnabled()) {
     154    doublespinbox[1].setValue((dom.attribute("value_y")).toDouble());
     155  }
     156  if (doublespinbox[2].isEnabled()) {
     157    doublespinbox[2].setValue((dom.attribute("value_z")).toDouble());
     158  }
    151159}
    152160
    153161void Vector3DSpinBox::valuechanged(const QString &value) {
    154     for(int i=0;i<3;i++) {
    155         if((QDoubleSpinBox*)sender()==&doublespinbox[i] && value!=doublespinbox_value[i]) {
    156             visible_widget->setPalette(red_pal);
    157             return;
    158         }
     162  for (int i = 0; i < 3; i++) {
     163    if ((QDoubleSpinBox *)sender() == &doublespinbox[i] &&
     164        value != doublespinbox_value[i]) {
     165      visible_widget->setPalette(red_pal);
     166      return;
    159167    }
    160     visible_widget->setPalette(black_pal);
     168  }
     169  visible_widget->setPalette(black_pal);
    161170}
    162171
    163172bool Vector3DSpinBox::IsUptodate(void) {
    164     //si le widget n'est pas enabled, sa palette est differente de rouge (greyed) donc on renvoit true
    165     //permet de ne pas envoyer les modifs d'un widget disabled
    166     //if(label->palette()==red_pal) return false;
    167     if(visible_widget->palette()==red_pal) return false;
    168     return true;
     173  // si le widget n'est pas enabled, sa palette est differente de rouge (greyed)
     174  // donc on renvoit true
     175  // permet de ne pas envoyer les modifs d'un widget disabled
     176  // if(label->palette()==red_pal) return false;
     177  if (visible_widget->palette() == red_pal)
     178    return false;
     179  return true;
    169180}
    170 
Note: See TracChangeset for help on using the changeset viewer.