1 /** -*- mode: c++ ; c-basic-offset: 2 -*-
2 * @file BoolParameter.cpp
3 * @author Sebastien Fourey
4 * @date Nov 2014
5 *
6 * @brief Declaration of the class AbstractParameter
7 *
8 * This file is part of the ZArt software's source code.
9 *
10 * Copyright Sebastien Fourey / GREYC Ensicaen (2010-...)
11 *
12 * https://foureys.users.greyc.fr/
13 *
14 * This software is a computer program whose purpose is to demonstrate
15 * the possibilities of the GMIC image processing language by offering the
16 * choice of several manipulations on a video stream acquired from a webcam. In
17 * other words, ZArt is a GUI for G'MIC real-time manipulations on the output
18 * of a webcam.
19 *
20 * This software is governed by the CeCILL license under French law and
21 * abiding by the rules of distribution of free software. You can use,
22 * modify and/ or redistribute the software under the terms of the CeCILL
23 * license as circulated by CEA, CNRS and INRIA at the following URL
24 * "http://www.cecill.info". See also the directory "Licence" which comes
25 * with this source code for the full text of the CeCILL license.
26 *
27 * As a counterpart to the access to the source code and rights to copy,
28 * modify and redistribute granted by the license, users are provided only
29 * with a limited warranty and the software's author, the holder of the
30 * economic rights, and the successive licensors have only limited
31 * liability.
32 *
33 * In this respect, the user's attention is drawn to the risks associated
34 * with loading, using, modifying and/or developing or reproducing the
35 * software by the user in light of its specific status of free software,
36 * that may mean that it is complicated to manipulate, and that also
37 * therefore means that it is reserved for developers and experienced
38 * professionals having in-depth computer knowledge. Users are therefore
39 * encouraged to load and test the software's suitability as regards their
40 * requirements in conditions enabling the security of their systems and/or
41 * data to be ensured and, more generally, to use and operate it in the
42 * same conditions as regards security.
43 *
44 * The fact that you are presently reading this means that you have had
45 * knowledge of the CeCILL license and that you accept its terms.
46 */
47 #include "BoolParameter.h"
48 #include <QCheckBox>
49 #include <QGridLayout>
50 #include <QLabel>
51 #include <QWidget>
52 #include "Common.h"
53
BoolParameter(QDomNode node,QObject * parent)54 BoolParameter::BoolParameter(QDomNode node, QObject * parent) : AbstractParameter(parent), _node(node), _label(0), _checkBox(0)
55 {
56 _name = node.attributes().namedItem("name").nodeValue();
57 QString def = node.attributes().namedItem("default").nodeValue();
58 QString value = node.toElement().attribute("savedValue", def);
59 _default = def.toInt();
60 _value = value.toInt();
61 }
62
~BoolParameter()63 BoolParameter::~BoolParameter()
64 {
65 delete _checkBox;
66 delete _label;
67 }
68
addTo(QWidget * widget,int row)69 void BoolParameter::addTo(QWidget * widget, int row)
70 {
71 QGridLayout * grid = dynamic_cast<QGridLayout *>(widget->layout());
72 if (!grid)
73 return;
74 delete _checkBox;
75 delete _label;
76 _checkBox = new QCheckBox(_name, widget);
77 _checkBox->setChecked(_value);
78 grid->addWidget(_checkBox, row, 0, 1, 3);
79 connect(_checkBox, SIGNAL(toggled(bool)), this, SLOT(onCheckBoxChanged(bool)));
80 }
81
textValue() const82 QString BoolParameter::textValue() const
83 {
84 return _value ? "1" : "0";
85 }
86
setValue(const QString & value)87 void BoolParameter::setValue(const QString & value)
88 {
89 _value = (value == "1");
90 if (_checkBox) {
91 _checkBox->setChecked(_value);
92 }
93 }
94
reset()95 void BoolParameter::reset()
96 {
97 _checkBox->setChecked(_default);
98 _value = _default;
99 }
100
onCheckBoxChanged(bool on)101 void BoolParameter::onCheckBoxChanged(bool on)
102 {
103 _value = on;
104 emit valueChanged();
105 }
106
saveValueInDOM()107 void BoolParameter::saveValueInDOM()
108 {
109 _node.toElement().setAttribute("savedValue", _checkBox->isChecked());
110 }
111