My Project  0.0.16
QUCS Mapping
 All Classes Namespaces 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 
18 #include <qhbox.h>
19 #include <qlabel.h>
20 #include <qlayout.h>
21 #include <qlineedit.h>
22 #include <qvalidator.h>
23 #include <qpushbutton.h>
24 #include <qmessagebox.h>
25 #include <qbuttongroup.h>
26 #include <qradiobutton.h>
27 #include <qvgroupbox.h>
28 #include <qstring.h>
29 #include <qstringlist.h>
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  setCaption(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  QVGroupBox *setGroup = new QVGroupBox(tr("Digital Simulation Settings"), this);
49  all->addWidget(setGroup);
50 
51  QButtonGroup *toggleGroup = new QButtonGroup();
52  simRadio = new QRadioButton(tr("Simulation"), setGroup);
53  simRadio->setChecked(Doc->simulation);
54 
55  QHBox *hb1 = new QHBox(setGroup);
56  hb1->setSpacing(5);
57  TimeLabel = new QLabel(tr("Duration of Simulation:"), hb1);
59  TimeEdit = new QLineEdit(hb1);
60  TimeEdit->setValidator(Validator);
61  TimeEdit->setText(SimTime);
62 
63  QRadioButton *comRadio = new QRadioButton(tr("Precompile Module"), setGroup);
64  toggleGroup->insert(simRadio);
65  toggleGroup->insert(comRadio);
66  connect(toggleGroup, SIGNAL(clicked(int)), SLOT(slotChangeMode(int)));
67 
68  QHBox *hb3 = new QHBox(setGroup);
69  hb3->setSpacing(5);
70  NameLabel = new QLabel(tr("Library Name:"), hb3);
71  NameEdit = new QLineEdit(hb3);
72  NameEdit->setText(Doc->Library);
73 
74  setGroup->addSpace(15);
75  QHBox *hb2 = new QHBox(setGroup);
76  hb2->setSpacing(5);
77  LibLabel = new QLabel(tr("Libraries:"), hb2);
78  LibEdit = new QLineEdit(hb2);
79  LibEdit->setText(Doc->Libraries);
80 
81  all->addSpacing(5);
82  all->addStretch();
83  QHBox *Buttons = new QHBox(this);
84  all->addWidget(Buttons);
85  QPushButton *ButtonOk = new QPushButton(tr("Ok"), Buttons);
86  QPushButton *ButtonCancel = new QPushButton(tr("Cancel"), Buttons);
87  connect(ButtonOk, SIGNAL(clicked()), SLOT(slotOk()));
88  connect(ButtonCancel, SIGNAL(clicked()), SLOT(reject()));
89 
90  simRadio->setChecked(Doc->simulation);
91  Doc->SimOpenDpl = Doc->simulation ? true : false;
92  comRadio->setChecked(!Doc->simulation);
93  slotChangeMode(!Doc->simulation);
94 
95  ButtonOk->setDefault(true);
96  if(Doc->simulation) {
97  setFocusProxy(TimeEdit);
98  TimeEdit->setFocus();
99  }
100  else {
101  setFocusProxy(NameEdit);
102  NameEdit->setFocus();
103  }
104 }
105 
107 {
108  delete Validator;
109 }
110 
111 void DigiSettingsDialog::slotOk()
112 {
113  bool changed = false;
114  if(SimTime != TimeEdit->text()) {
115  if(simRadio->isChecked()) {
116  QString s = TimeEdit->text();
117  if(!VHDL_Time(s, tr("Document Settings"))) {
118  QMessageBox::critical(this, tr("Error"), s.mid(1));
119  reject();
120  return;
121  } else {
122  Doc->SimTime = s;
123  changed = true;
124  }
125  }
126  }
127  if(Doc->Libraries != LibEdit->text()) {
128  QStringList lst = QStringList::split(' ',LibEdit->text());
129  Doc->Libraries = lst.join(" ");
130  changed = true;
131  }
132  if(Doc->simulation != simRadio->isChecked()) {
133  Doc->simulation = simRadio->isChecked();
134  Doc->SimOpenDpl = Doc->simulation ? true : false;
135  changed = true;
136  }
137  if(Doc->Library != NameEdit->text()) {
138  QString lib = NameEdit->text().stripWhiteSpace();
139  Doc->Library = lib;
140  changed = true;
141  }
142 
143  if(changed) {
144  Doc->SetChanged = true;
145  Doc->slotSetChanged();
146  }
147  accept();
148 }
149 
150 void DigiSettingsDialog::slotChangeMode(int idx)
151 {
152  switch(idx) {
153  case 0:
154  TimeEdit->setEnabled(true);
155  TimeEdit->setFocus();
156  TimeLabel->setEnabled(true);
157  NameEdit->setEnabled(false);
158  NameLabel->setEnabled(false);
159  break;
160  case 1:
161  TimeEdit->setEnabled(false);
162  TimeLabel->setEnabled(false);
163  NameEdit->setEnabled(true);
164  NameLabel->setEnabled(true);
165  break;
166  }
167 }