[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 "FormLayout.h"
|
---|
| 6 | #include "Layout.h"
|
---|
| 7 | #include <QWidget>
|
---|
| 8 | #include <QFormLayout>
|
---|
| 9 | #include <QEvent>
|
---|
| 10 |
|
---|
[15] | 11 | FormLayout::FormLayout(Layout *parent, int row, int col, QString name,
|
---|
| 12 | QString type)
|
---|
| 13 | : XmlWidget(name, type, parent) {
|
---|
| 14 | visible_widget = new QWidget();
|
---|
[9] | 15 |
|
---|
[15] | 16 | // create a grid to put label and object
|
---|
| 17 | visible_widget->setObjectName(name);
|
---|
[9] | 18 |
|
---|
[15] | 19 | parent->addWidget(visible_widget, row, col);
|
---|
| 20 | object_layout = new QFormLayout(visible_widget);
|
---|
| 21 | object_layout->setHorizontalSpacing(2);
|
---|
| 22 | object_layout->setVerticalSpacing(2);
|
---|
| 23 | object_layout->setContentsMargins(2, 2, 2, 2);
|
---|
[9] | 24 |
|
---|
[15] | 25 | visible_widget->installEventFilter(this);
|
---|
[9] | 26 | }
|
---|
| 27 |
|
---|
[15] | 28 | FormLayout::~FormLayout() {}
|
---|
[9] | 29 |
|
---|
[15] | 30 | bool FormLayout::IsUptodate(void) {
|
---|
| 31 | // si le widget n'est pas enabled, sa palette est differente de rouge (greyed)
|
---|
| 32 | // donc on renvoit true
|
---|
| 33 | // permet de ne pas envoyer les modifs d'un widget disabled
|
---|
| 34 | // if(label->palette()==red_pal) return false;
|
---|
| 35 | if (visible_widget->palette() == red_pal)
|
---|
| 36 | return false;
|
---|
| 37 | return true;
|
---|
[9] | 38 | }
|
---|
| 39 |
|
---|
[15] | 40 | bool FormLayout::eventFilter(QObject *o, QEvent *e) {
|
---|
| 41 | if (o == visible_widget) {
|
---|
| 42 | switch (e->type()) {
|
---|
| 43 | case QEvent::EnabledChange: {
|
---|
| 44 | QPalette palette = visible_widget->palette();
|
---|
| 45 | QPalette result;
|
---|
[9] | 46 |
|
---|
[15] | 47 | if (palette == red_pal)
|
---|
| 48 | result = red_pal_greyed;
|
---|
| 49 | if (palette == red_pal_greyed)
|
---|
| 50 | result = red_pal;
|
---|
| 51 | if (palette == black_pal)
|
---|
| 52 | result = black_pal_greyed;
|
---|
| 53 | if (palette == black_pal_greyed)
|
---|
| 54 | result = black_pal;
|
---|
[9] | 55 |
|
---|
[15] | 56 | visible_widget->setPalette(result);
|
---|
| 57 | }
|
---|
[9] | 58 |
|
---|
[15] | 59 | default:
|
---|
| 60 | break;
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | return QObject::eventFilter(o, e);
|
---|
[9] | 64 | }
|
---|