My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
settingsdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  settingsdialog.cpp
3  --------------------
4  begin : Mon Oct 20 2003
5  copyright : (C) 2003, 2004 by Michael Margraf
6  email : michael.margraf@alumni.tu-berlin.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "settingsdialog.h"
19 
20 #include "node.h"
21 #include "qucs.h"
22 #include "mnemo.h"
23 #include "schematic.h"
24 
25 #include <qhbox.h>
26 #include <qlabel.h>
27 #include <qwidget.h>
28 #include <qlayout.h>
29 #include <qregexp.h>
30 #include <qlineedit.h>
31 #include <qtextedit.h>
32 #include <qcheckbox.h>
33 #include <qcombobox.h>
34 #include <qtabwidget.h>
35 #include <qvalidator.h>
36 #include <qpushbutton.h>
37 
38 
40  : QDialog(Doc_, 0, TRUE, Qt::WDestructiveClose)
41 {
42  Doc = Doc_;
43  setCaption(tr("Edit File Properties"));
44 
45  all = new QVBoxLayout(this); // to provide the neccessary size
46  QTabWidget *t = new QTabWidget(this);
47  all->addWidget(t);
48 
49  // ...........................................................
50  QWidget *Tab1 = new QWidget(t);
51  QGridLayout *gp = new QGridLayout(Tab1,6,2,5,5);
52 
53  QLabel *l1 = new QLabel(tr("Data Display:"), Tab1);
54  gp->addWidget(l1,1,0);
55  Input_DataDisplay = new QLineEdit(Tab1);
56  gp->addWidget(Input_DataDisplay,1,1);
57 
58  QLabel *l2 = new QLabel(tr("Data Set:"), Tab1);
59  gp->addWidget(l2,0,0);
60  Input_DataSet = new QLineEdit(Tab1);
61  gp->addWidget(Input_DataSet,0,1);
62 
63  Check_OpenDpl = new QCheckBox(tr("open data display after simulation"),
64  Tab1);
65  gp->addMultiCellWidget(Check_OpenDpl,2,2,0,1);
66 
67  QLabel *l20 = new QLabel(tr("Octave Script:"), Tab1);
68  gp->addWidget(l20,3,0);
69  Input_Script = new QLineEdit(Tab1);
70  gp->addWidget(Input_Script,3,1);
71 
72  Check_RunScript = new QCheckBox(tr("run script after simulation"),
73  Tab1);
74  gp->addMultiCellWidget(Check_RunScript,4,4,0,1);
75 
76  t->addTab(Tab1, tr("Simulation"));
77 
78  // ...........................................................
79  QWidget *Tab2 = new QWidget(t);
80  QGridLayout *gp2 = new QGridLayout(Tab2,4,2,5,5);
81  Check_GridOn = new QCheckBox(tr("show Grid"),Tab2);
82  gp2->addMultiCellWidget(Check_GridOn,0,0,0,1);
83 
84  valExpr = new QRegExpValidator(QRegExp("[1-9]\\d{0,2}"), this);
85 
86  QLabel *l3 = new QLabel(tr("horizontal Grid:"), Tab2);
87  gp2->addWidget(l3,1,0);
88  Input_GridX = new QLineEdit(Tab2);
89  Input_GridX->setValidator(valExpr);
90  gp2->addWidget(Input_GridX,1,1);
91 
92  QLabel *l4 = new QLabel(tr("vertical Grid:"), Tab2);
93  gp2->addWidget(l4,2,0);
94  Input_GridY = new QLineEdit(Tab2);
95  Input_GridY->setValidator(valExpr);
96  gp2->addWidget(Input_GridY,2,1);
97 
98  t->addTab(Tab2, tr("Grid"));
99 
100  // ...........................................................
101  QWidget *Tab3 = new QWidget(t);
102  QGridLayout *gp3 = new QGridLayout(Tab3,5,2,5,5);
103  Combo_Frame = new QComboBox(Tab3);
104  Combo_Frame->insertItem(tr("no Frame"));
105  Combo_Frame->insertItem(tr("DIN A5 landscape"));
106  Combo_Frame->insertItem(tr("DIN A5 portrait"));
107  Combo_Frame->insertItem(tr("DIN A4 landscape"));
108  Combo_Frame->insertItem(tr("DIN A4 portrait"));
109  Combo_Frame->insertItem(tr("DIN A3 landscape"));
110  Combo_Frame->insertItem(tr("DIN A3 portrait"));
111  Combo_Frame->insertItem(tr("Letter landscape"));
112  Combo_Frame->insertItem(tr("Letter portrait"));
113  gp3->addMultiCellWidget(Combo_Frame,0,0,0,1);
114 
115  Input_Frame0 = new QTextEdit(Tab3);
116  Input_Frame0->setTextFormat(Qt::PlainText);
117  Input_Frame0->setWordWrap(QTextEdit::NoWrap);
118  gp3->addMultiCellWidget(Input_Frame0,1,2,0,1);
119 
120  Input_Frame1 = new QLineEdit(Tab3);
121  gp3->addMultiCellWidget(Input_Frame1,3,3,0,1);
122 
123  Input_Frame2 = new QLineEdit(Tab3);
124  gp3->addWidget(Input_Frame2,4,0);
125  Input_Frame3 = new QLineEdit(Tab3);
126  gp3->addWidget(Input_Frame3,4,1);
127 
128  t->addTab(Tab3, tr("Frame"));
129 
130  // ...........................................................
131  // buttons on the bottom of the dialog (independent of the TabWidget)
132  QHBox *Butts = new QHBox(this);
133  Butts->setSpacing(5);
134  Butts->setMargin(5);
135  all->addWidget(Butts);
136 
137  QPushButton *OkButt = new QPushButton(tr("OK"), Butts);
138  connect(OkButt, SIGNAL(clicked()), SLOT(slotOK()));
139  QPushButton *ApplyButt = new QPushButton(tr("Apply"), Butts);
140  connect(ApplyButt, SIGNAL(clicked()), SLOT(slotApply()));
141  QPushButton *CancelButt = new QPushButton(tr("Cancel"), Butts);
142  connect(CancelButt, SIGNAL(clicked()), SLOT(reject()));
143 
144  OkButt->setDefault(true);
145 
146  // ...........................................................
147  // fill the fields with the QucsDoc-Properties
148 
149  Input_DataSet->setText(Doc->DataSet);
150  Input_DataDisplay->setText(Doc->DataDisplay);
151  Input_Script->setText(Doc->Script);
152  Check_OpenDpl->setChecked(Doc->SimOpenDpl);
153  Check_RunScript->setChecked(Doc->SimRunScript);
154  Check_GridOn->setChecked(Doc->GridOn);
155  Input_GridX->setText(QString::number(Doc->GridX));
156  Input_GridY->setText(QString::number(Doc->GridY));
157  Combo_Frame->setCurrentItem(Doc->showFrame);
158 
159  QString Text_;
160  decode_String(Text_ = Doc->Frame_Text0);
161  Input_Frame0->setText(Text_);
162  decode_String(Text_ = Doc->Frame_Text1);
163  Input_Frame1->setText(Text_);
164  decode_String(Text_ = Doc->Frame_Text2);
165  Input_Frame2->setText(Text_);
166  decode_String(Text_ = Doc->Frame_Text3);
167  Input_Frame3->setText(Text_);
168 
169  resize(250, 200);
170 }
171 
173 {
174  delete all;
175  delete valExpr;
176 }
177 
178 // -----------------------------------------------------------
179 void SettingsDialog::slotOK()
180 {
181  slotApply();
182  accept();
183 }
184 
185 // -----------------------------------------------------------
186 void SettingsDialog::slotApply()
187 {
188  bool changed = false;
189 
190  if(Doc->DataSet != Input_DataSet->text()) {
191  Doc->DataSet = Input_DataSet->text();
192  changed = true;
193  }
194 
195  if(Doc->DataDisplay != Input_DataDisplay->text()) {
196  Doc->DataDisplay = Input_DataDisplay->text();
197  changed = true;
198  }
199 
200  if(Doc->Script != Input_Script->text()) {
201  Doc->Script = Input_Script->text();
202  changed = true;
203  }
204 
205  if(Doc->SimOpenDpl != Check_OpenDpl->isChecked()) {
206  Doc->SimOpenDpl = Check_OpenDpl->isChecked();
207  changed = true;
208  }
209 
210  if(Doc->SimRunScript != Check_RunScript->isChecked()) {
211  Doc->SimRunScript = Check_RunScript->isChecked();
212  changed = true;
213  }
214 
215  if(Doc->GridOn != Check_GridOn->isChecked()) {
216  Doc->GridOn = Check_GridOn->isChecked();
217  changed = true;
218  }
219 
220  if(Doc->GridX != Input_GridX->text()) {
221  Doc->GridX = Input_GridX->text().toInt();
222  changed = true;
223  }
224 
225  if(Doc->GridY != Input_GridY->text()) {
226  Doc->GridY = Input_GridY->text().toInt();
227  changed = true;
228  }
229 
230  if(Doc->showFrame != Combo_Frame->currentItem()) {
231  Doc->showFrame = Combo_Frame->currentItem();
232  changed = true;
233  }
234 
235  QString t;
236  encode_String(Input_Frame0->text(), t);
237  if(Doc->Frame_Text0 != t) {
238  Doc->Frame_Text0 = t;
239  changed = true;
240  }
241 
242  encode_String(Input_Frame1->text(), t);
243  if(Doc->Frame_Text1 != t) {
244  Doc->Frame_Text1 = t;
245  changed = true;
246  }
247 
248  encode_String(Input_Frame2->text(), t);
249  if(Doc->Frame_Text2 != t) {
250  Doc->Frame_Text2 = t;
251  changed = true;
252  }
253 
254  encode_String(Input_Frame3->text(), t);
255  if(Doc->Frame_Text3 != t) {
256  Doc->Frame_Text3 = t;
257  changed = true;
258  }
259 
260  if(changed) {
261  Doc->setChanged(true);
262  Doc->viewport()->repaint();
263  }
264 }