Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
digisettingsdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  digisettingsdialog.cpp
3  ------------------------
4  begin : Sat Apr 01 2006
5  copyright : (C) 2006 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 #include <QtGui>
18 #include <QLabel>
19 #include <QLineEdit>
20 #include <QValidator>
21 #include <QPushButton>
22 #include <QMessageBox>
23 #include <QButtonGroup>
24 #include <QRadioButton>
25 #include <QGroupBox>
26 #include <QString>
27 #include <QStringList>
28 #include <QVBoxLayout>
29 #include <QHBoxLayout>
30 
31 #include "digisettingsdialog.h"
32 #include "textdoc.h"
33 #include "main.h"
34 
35 
37  : QDialog(Doc_) //, 0, true, Qt::WDestructiveClose)
38 {
39  Doc = Doc_;
40  setWindowTitle(tr("Document Settings"));
41 
42  Expr.setPattern("[0-9][0-9a-zA-Z ]+"); // valid expression for LineEdit
43  Validator = new QRegExpValidator(Expr, this);
44 
45  QVBoxLayout *all = new QVBoxLayout(this);
46  all->setMargin(5);
47 
48  QGroupBox *setGroup = new QGroupBox(tr("Digital Simulation Settings"));
49  all->addWidget(setGroup);
50 
51  QVBoxLayout *group = new QVBoxLayout();
52  setGroup->setLayout(group);
53 
54  QButtonGroup *toggleGroup = new QButtonGroup();
55  simRadio = new QRadioButton(tr("Simulation"));
56  group->addWidget(simRadio);
57  simRadio->setChecked(Doc->simulation);
58 
59  QHBoxLayout *hb1 = new QHBoxLayout();
60  hb1->setSpacing(5);
61  TimeLabel = new QLabel(tr("Duration of Simulation:"));
62  hb1->addWidget(TimeLabel);
64  TimeEdit = new QLineEdit();
65  hb1->addWidget(TimeEdit);
66  TimeEdit->setValidator(Validator);
67  TimeEdit->setText(SimTime);
68  group->addLayout(hb1);
69 
70  QRadioButton *comRadio = new QRadioButton(tr("Precompile Module"));
71  group->addWidget(comRadio);
72  toggleGroup->insert(simRadio);
73  toggleGroup->insert(comRadio);
74  connect(toggleGroup, SIGNAL(buttonClicked(int)), SLOT(slotChangeMode(int)));
75 
76  QHBoxLayout *hb3 = new QHBoxLayout();
77  hb3->setSpacing(5);
78  NameLabel = new QLabel(tr("Library Name:"));
79  hb3->addWidget(NameLabel);
80  NameEdit = new QLineEdit();
81  hb3->addWidget(NameEdit);
82  NameEdit->setText(Doc->Library);
83  group->addLayout(hb3);
84 
85  group->addSpacing(15);
86 
87  QHBoxLayout *hb2 = new QHBoxLayout();
88  hb2->setSpacing(5);
89  LibLabel = new QLabel(tr("Libraries:"));
90  hb2->addWidget(LibLabel);
91  LibEdit = new QLineEdit();
92  hb2->addWidget(LibEdit);
93  LibEdit->setText(Doc->Libraries);
94  group->addLayout(hb2);
95 
96  all->addSpacing(5);
97  all->addStretch();
98  QHBoxLayout *Buttons = new QHBoxLayout();
99  QPushButton *ButtonOk = new QPushButton(tr("Ok"));
100  QPushButton *ButtonCancel = new QPushButton(tr("Cancel"));
101  Buttons->addWidget(ButtonOk);
102  Buttons->addWidget(ButtonCancel);
103  connect(ButtonOk, SIGNAL(clicked()), SLOT(slotOk()));
104  connect(ButtonCancel, SIGNAL(clicked()), SLOT(reject()));
105  all->addLayout(Buttons);
106 
107  simRadio->setChecked(Doc->simulation);
108  Doc->SimOpenDpl = Doc->simulation ? true : false;
109  comRadio->setChecked(!Doc->simulation);
111 
112  ButtonOk->setDefault(true);
113  if(Doc->simulation) {
114  setFocusProxy(TimeEdit);
115  TimeEdit->setFocus();
116  }
117  else {
118  setFocusProxy(NameEdit);
119  NameEdit->setFocus();
120  }
121 }
122 
124 {
125  delete Validator;
126 }
127 
129 {
130  bool changed = false;
131  if(SimTime != TimeEdit->text()) {
132  if(simRadio->isChecked()) {
133  QString s = TimeEdit->text();
134  if(!VHDL_Time(s, tr("Document Settings"))) {
135  QMessageBox::critical(this, tr("Error"), s.mid(1));
136  reject();
137  return;
138  } else {
139  Doc->SimTime = s;
140  changed = true;
141  }
142  }
143  }
144  if(Doc->Libraries != LibEdit->text()) {
145  QStringList lst = QStringList::split(' ',LibEdit->text());
146  Doc->Libraries = lst.join(" ");
147  changed = true;
148  }
149  if(Doc->simulation != simRadio->isChecked()) {
150  Doc->simulation = simRadio->isChecked();
151  Doc->SimOpenDpl = Doc->simulation ? true : false;
152  changed = true;
153  }
154  if(Doc->Library != NameEdit->text()) {
155  QString lib = NameEdit->text().stripWhiteSpace();
156  Doc->Library = lib;
157  changed = true;
158  }
159 
160  if(changed) {
161  Doc->SetChanged = true;
162  Doc->slotSetChanged();
163  }
164  accept();
165 }
166 
168 {
169  switch(idx) {
170  case 0:
171  TimeEdit->setEnabled(true);
172  TimeEdit->setFocus();
173  TimeLabel->setEnabled(true);
174  NameEdit->setEnabled(false);
175  NameLabel->setEnabled(false);
176  break;
177  case 1:
178  TimeEdit->setEnabled(false);
179  TimeLabel->setEnabled(false);
180  NameEdit->setEnabled(true);
181  NameLabel->setEnabled(true);
182  break;
183  }
184 }
QString Libraries
Definition: textdoc.h:73
Definition of the TextDoc class.
QRegExpValidator * Validator
bool SimOpenDpl
Definition: qucsdoc.h:61
QString Library
Definition: textdoc.h:72
bool simulation
Definition: textdoc.h:71
Definitions and declarations for the main application.
bool loadSimulationTime(QString &)
TextDoc::loadSimulationTime set SimTime member variable.
Definition: textdoc.cpp:411
bool VHDL_Time(QString &t, const QString &Name)
Definition: main.cpp:513
void slotSetChanged()
TextDoc::slotSetChanged togles tab icon to indicate unsaved changes.
Definition: textdoc.cpp:286
QRadioButton * comRadio
QString SimTime
Definition: qucsdoc.h:55
QRadioButton * simRadio
The TextDoc class definition.
Definition: textdoc.h:49
bool SetChanged
Definition: textdoc.h:80