Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 //== INCLUDES =================================================================
51 #include <QPushButton>
52 #include <QVBoxLayout>
53 #include <QScrollArea>
54 #include <QLineEdit>
55 #include <QLabel>
56 
57 
58 #include "scene/elementInput.hh"
59 
60 #include "configDialog.hh"
61 #include "configValue.hh"
62 //== NAMESPACES ===============================================================
63 namespace VSI {
64 
65 //=============================================================================
66 //
67 // CLASS VSI::ConfigDialog - IMPLEMENTATION
68 //
69 //=============================================================================
70 
72 ConfigDialog::ConfigDialog (QVector<ElementInput *> _inputs, QString _name, QWidget * _parent) :
73  QDialog (_parent),
74  inputs_ (_inputs),
75  name_(0)
76 {
77  QVBoxLayout *vL = new QVBoxLayout;
78  QVBoxLayout *configL = new QVBoxLayout;
79 
80  if (!_name.isNull ())
81  {
82  QHBoxLayout *nameL = new QHBoxLayout;
83  QLabel *l = new QLabel(tr("Element name:"));
84  name_ = new QLineEdit;
85  name_->setText (_name);
86  nameL->addWidget (l);
87  nameL->addWidget (name_);
88  nameL->setStretchFactor(name_, 1);
89 
90  vL->addLayout (nameL);
91  }
92 
93  foreach (ElementInput *i, _inputs)
94  {
95  ConfigValue *v = new ConfigValue (i);
96 
97  if (!v->main_)
98  {
99  delete v;
100  continue;
101  }
102 
103  if (_inputs.size () > 1)
104  configL->addWidget (v->group_);
105  else
106  vL->addWidget (v->group_);
107 
108  values_.append (v);
109  }
110 
111  configL->addStretch(1);
112 
113  QPushButton *ok = new QPushButton ("OK");
114  QPushButton *cancel = new QPushButton ("Cancel");
115 
116  connect (ok, SIGNAL (pressed ()), this, SLOT (ok ()));
117  connect (cancel, SIGNAL (pressed ()), this, SLOT (reject ()));
118 
119  QHBoxLayout *buttonL = new QHBoxLayout;
120  buttonL->addStretch();
121  buttonL->addWidget (ok);
122  buttonL->addWidget (cancel);
123 
124  if (_inputs.size () > 1)
125  {
126  QWidget *sW = new QWidget;
127  sW->setLayout (configL);
128  QScrollArea *sA = new QScrollArea;
129  sA->setWidget (sW);
130  sA->setWidgetResizable (true);
131  vL->addWidget (sA);
132  resize (500, 300);
133  }
134  else
135  resize (500, 0);
136 
137  vL->addLayout (buttonL);
138 
139  setLayout (vL);
140 
141 
142 }
143 
144 //------------------------------------------------------------------------------
145 
148 {
149  foreach (ConfigValue *v, values_)
150  delete v;
151 }
152 
153 //------------------------------------------------------------------------------
154 
156 {
157 
158  if (name_)
159  return name_->text ();
160 
161  return QString ();
162 
163 }
164 
165 //------------------------------------------------------------------------------
166 
167 // OK pressed
168 void VSI::ConfigDialog::ok ()
169 {
170  foreach (ConfigValue *v, values_)
171  {
172  if (!v->constant_ || v->constant_->isChecked ())
173  v->input_->set (true);
174  else
175  v->input_->set (false);
176 
177  if (v->forceAskUser_ && v->forceAskUser_->isChecked ())
178  v->input_->setForceAsk (true);
179  else
180  v->input_->setForceAsk (false);
181  v->input_->setValue (v->main_->toValue ());
182  }
183  QDialog::accept ();
184 }
185 
186 //------------------------------------------------------------------------------
187 }
ConfigDialog(QVector< ElementInput * > _inputs, QString _name=QString(), QWidget *_parent=0)
Constructor.
Definition: configDialog.cc:72
void setValue(QString _value)
Set to a user value.
void setForceAsk(bool _set)
"ForceAsk" flag to mark an optional input for asking during script execution
QString name()
return entered name
virtual QString toValue()=0
Return the type configuration result to a string.
void set(bool _set)
"Set" flag to mark input as set by user
~ConfigDialog()
Destructor.