Developer Documentation
configDialog.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 
43 
44 //== INCLUDES =================================================================
45 #include <QPushButton>
46 #include <QVBoxLayout>
47 #include <QScrollArea>
48 #include <QLineEdit>
49 #include <QLabel>
50 
51 
52 #include "scene/elementInput.hh"
53 
54 #include "configDialog.hh"
55 #include "configValue.hh"
56 //== NAMESPACES ===============================================================
57 namespace VSI {
58 
59 //=============================================================================
60 //
61 // CLASS VSI::ConfigDialog - IMPLEMENTATION
62 //
63 //=============================================================================
64 
66 ConfigDialog::ConfigDialog (QVector<ElementInput *> _inputs, QString _name, QWidget * _parent) :
67  QDialog (_parent),
68  inputs_ (_inputs),
69  name_(0)
70 {
71  QVBoxLayout *vL = new QVBoxLayout;
72  QVBoxLayout *configL = new QVBoxLayout;
73 
74  if (!_name.isNull ())
75  {
76  QHBoxLayout *nameL = new QHBoxLayout;
77  QLabel *l = new QLabel(tr("Element name:"));
78  name_ = new QLineEdit;
79  name_->setText (_name);
80  nameL->addWidget (l);
81  nameL->addWidget (name_);
82  nameL->setStretchFactor(name_, 1);
83 
84  vL->addLayout (nameL);
85  }
86 
87  foreach (ElementInput *i, _inputs)
88  {
89  ConfigValue *v = new ConfigValue (i);
90 
91  if (!v->main_)
92  {
93  delete v;
94  continue;
95  }
96 
97  if (_inputs.size () > 1)
98  configL->addWidget (v->group_);
99  else
100  vL->addWidget (v->group_);
101 
102  values_.append (v);
103  }
104 
105  configL->addStretch(1);
106 
107  QPushButton *ok = new QPushButton ("OK");
108  QPushButton *cancel = new QPushButton ("Cancel");
109 
110  connect (ok, SIGNAL (pressed ()), this, SLOT (ok ()));
111  connect (cancel, SIGNAL (pressed ()), this, SLOT (reject ()));
112 
113  QHBoxLayout *buttonL = new QHBoxLayout;
114  buttonL->addStretch();
115  buttonL->addWidget (ok);
116  buttonL->addWidget (cancel);
117 
118  if (_inputs.size () > 1)
119  {
120  QWidget *sW = new QWidget;
121  sW->setLayout (configL);
122  QScrollArea *sA = new QScrollArea;
123  sA->setWidget (sW);
124  sA->setWidgetResizable (true);
125  vL->addWidget (sA);
126  resize (500, 300);
127  }
128  else
129  resize (500, 0);
130 
131  vL->addLayout (buttonL);
132 
133  setLayout (vL);
134 
135 
136 }
137 
138 //------------------------------------------------------------------------------
139 
141 ConfigDialog::~ ConfigDialog()
142 {
143  foreach (ConfigValue *v, values_)
144  delete v;
145 }
146 
147 //------------------------------------------------------------------------------
148 
150 {
151 
152  if (name_)
153  return name_->text ();
154 
155  return QString ();
156 
157 }
158 
159 //------------------------------------------------------------------------------
160 
161 // OK pressed
162 void VSI::ConfigDialog::ok ()
163 {
164  foreach (ConfigValue *v, values_)
165  {
166  if (!v->constant_ || v->constant_->isChecked ())
167  v->input_->set (true);
168  else
169  v->input_->set (false);
170 
171  if (v->forceAskUser_ && v->forceAskUser_->isChecked ())
172  v->input_->setForceAsk (true);
173  else
174  v->input_->setForceAsk (false);
175  v->input_->setValue (v->main_->toValue ());
176  }
177  QDialog::accept ();
178 }
179 
180 //------------------------------------------------------------------------------
181 }
void set(bool _set)
"Set" flag to mark input as set by user
QString name()
return entered name
ConfigDialog(QVector< ElementInput *> _inputs, QString _name=QString(), QWidget *_parent=0)
Constructor.
Definition: configDialog.cc:66
void setForceAsk(bool _set)
"ForceAsk" flag to mark an optional input for asking during script execution
void setValue(QString _value)
Set to a user value.
virtual QString toValue()=0
Return the type configuration result to a string.