Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vasettingsdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  vasettingsdialog.cpp
3  ----------------------
4  begin : Sun Oct 26 2009
5  copyright : (C) 2009 by Stefan Jahn
6  email : stefa@lkcc.org
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 <QHBoxLayout>
19 #include <QVBoxLayout>
20 #include <QLabel>
21 #include <QLineEdit>
22 #include <QValidator>
23 #include <QPushButton>
24 #include <QMessageBox>
25 #include <QButtonGroup>
26 #include <QCheckBox>
27 #include <QGroupBox>
28 #include <QString>
29 #include <QStringList>
30 #include <QPushButton>
31 #include <QFileDialog>
32 #include <QGridLayout>
33 
34 #include "vasettingsdialog.h"
35 #include "textdoc.h"
36 #include "main.h"
37 
38 
40  : QDialog (Doc_)
41 {
42  Doc = Doc_;
43  setWindowTitle(tr("Document Settings"));
44 
45  QString Module = Doc->getModuleName ();
46 
47  Expr.setPattern("[0-9a-zA-Z /\\]+"); // valid expression for IconEdit
48  Validator = new QRegExpValidator (Expr, this);
49 
50  vLayout = new QVBoxLayout(this);
51 
52  QGroupBox * codeGroup = new QGroupBox (tr("Code Creation Settings"));
53  vLayout->addWidget(codeGroup);
54  QVBoxLayout *vbox = new QVBoxLayout();
55  codeGroup->setLayout(vbox);
56 
57  QGridLayout * all = new QGridLayout ();
58  vbox->addLayout(all);
59 
60  if (Doc->Icon.isEmpty ())
61  Doc->Icon = Module + ".png";
62 
63  IconButt = new QLabel ();
64  IconButt->setPixmap (QPixmap (Doc->Icon));
65  all->addWidget (IconButt, 0, 0, 1, 1);
66 
67  IconEdit = new QLineEdit ();
68  IconEdit->setValidator (Validator);
69  IconEdit->setText (Doc->Icon);
70  IconEdit->setCursorPosition (0);
71  all->addWidget (IconEdit, 0, 1, 1, 3);
72 
73  BrowseButt = new QPushButton (tr("Browse"));
74  connect (BrowseButt, SIGNAL (clicked()), SLOT (slotBrowse()));
75  all->addWidget (BrowseButt, 0, 4, 1, 1);
76 
77  QLabel * l1 = new QLabel (tr("Output file:"));
78  l1->setAlignment (Qt::AlignRight);
79  all->addWidget (l1, 1, 0, 1, 1);
80  OutputEdit = new QLineEdit ();
81  OutputEdit->setText (Module + ".cpp");
82  all->addWidget (OutputEdit, 1, 1, 1, 3);
83 
84  RecreateCheck = new QCheckBox (tr("Recreate"));
85  all->addWidget (RecreateCheck, 1, 4, 1, 1);
86  RecreateCheck->setChecked (Doc->recreate);
87 
88  if (Doc->ShortDesc.isEmpty ())
89  Doc->ShortDesc = Module;
90 
91  QLabel * l2 = new QLabel (tr("Icon description:"));
92  l2->setAlignment (Qt::AlignRight);
93  all->addWidget (l2, 2, 0);
94  ShortDescEdit = new QLineEdit ();
95  ShortDescEdit->setText (Doc->ShortDesc);
96  all->addWidget (ShortDescEdit, 2, 1, 1, 3);
97 
98  if (Doc->LongDesc.isEmpty ())
99  Doc->LongDesc = Module + " verilog device";
100 
101  QLabel * l3 = new QLabel (tr("Description:"));
102  l3->setAlignment (Qt::AlignRight);
103  all->addWidget (l3, 3, 0);
104  LongDescEdit = new QLineEdit ();
105  LongDescEdit->setText (Doc->LongDesc);
106  all->addWidget (LongDescEdit, 3, 1, 1, 3);
107 
108  toggleGroupDev = new QButtonGroup ();
109  QRadioButton * nonRadio =
110  new QRadioButton (tr("unspecified device"));
111  QRadioButton * bjtRadio =
112  new QRadioButton (tr("NPN/PNP polarity"));
113  QRadioButton * mosRadio =
114  new QRadioButton (tr("NMOS/PMOS polarity"));
115  toggleGroupDev->addButton(nonRadio, 0);
116  toggleGroupDev->addButton(bjtRadio, DEV_BJT);
117  toggleGroupDev->addButton(mosRadio, DEV_MOS);
118  if (Doc->devtype & DEV_BJT)
119  bjtRadio->setChecked (true);
120  else if (Doc->devtype & DEV_MOS)
121  mosRadio->setChecked (true);
122  else
123  nonRadio->setChecked (true);
124  all->addMultiCellWidget (nonRadio, 4, 4, 0, 1);
125  all->addWidget (bjtRadio, 4, 2);
126  all->addMultiCellWidget (mosRadio, 4, 4, 3, 4);
127 
128  toggleGroupTyp = new QButtonGroup ();
129  QRadioButton * anaRadio =
130  new QRadioButton (tr("analog only"));
131  QRadioButton * digRadio =
132  new QRadioButton (tr("digital only"));
133  QRadioButton * allRadio =
134  new QRadioButton (tr("both"));
135  toggleGroupTyp->addButton(digRadio, DEV_DIG);
136  toggleGroupTyp->addButton(anaRadio, DEV_ANA);
137  toggleGroupTyp->addButton(allRadio, DEV_ALL);
138  if ((Doc->devtype & DEV_ALL) == DEV_ALL)
139  allRadio->setChecked (true);
140  else if (Doc->devtype & DEV_ANA)
141  anaRadio->setChecked (true);
142  else
143  digRadio->setChecked (true);
144  all->addMultiCellWidget (anaRadio, 5, 5, 0, 1);
145  all->addWidget (allRadio, 5, 2);
146  all->addMultiCellWidget (digRadio, 5, 5, 3, 4);
147 
148  QHBoxLayout * Buttons = new QHBoxLayout ();
149  vbox->addLayout(Buttons);
150  QPushButton * ButtonOk = new QPushButton (tr("Ok"));
151  Buttons->addWidget(ButtonOk);
152  QPushButton * ButtonCancel = new QPushButton (tr("Cancel"));
153  Buttons->addWidget(ButtonCancel);
154  connect (ButtonOk, SIGNAL(clicked()), SLOT(slotOk()));
155  connect (ButtonCancel, SIGNAL(clicked()), SLOT(reject()));
156  ButtonOk->setDefault(true);
157 
158 }
159 
161 {
162  delete Validator;
163 }
164 
166 {
167  bool changed = false;
168 
169  if (Doc->Icon != IconEdit->text ()) {
170  Doc->Icon = IconEdit->text ();
171  changed = true;
172  }
173  if (Doc->ShortDesc != ShortDescEdit->text ()) {
174  Doc->ShortDesc = ShortDescEdit->text ();
175  changed = true;
176  }
177  if (Doc->LongDesc != LongDescEdit->text ()) {
178  Doc->LongDesc = LongDescEdit->text ();
179  changed = true;
180  }
181  if (Doc->DataSet != OutputEdit->text ()) {
182  Doc->DataSet = OutputEdit->text ();
183  changed = true;
184  }
185  if (Doc->recreate != RecreateCheck->isChecked ()) {
186  Doc->recreate = RecreateCheck->isChecked ();
187  changed = true;
188  }
189  if ((Doc->devtype & DEV_MASK_TYP) != toggleGroupTyp->checkedId()) {
190  Doc->devtype &= ~DEV_MASK_TYP;
191  Doc->devtype |= toggleGroupTyp->checkedId();
192  changed = true;
193  }
194  if ((Doc->devtype & DEV_MASK_DEV) != toggleGroupDev->checkedId()) {
195  Doc->devtype &= ~DEV_MASK_DEV;
196  Doc->devtype |= toggleGroupDev->checkedId();
197  changed = true;
198  }
199 
200  if (changed) {
201  Doc->SetChanged = true;
202  Doc->slotSetChanged ();
203  }
204  accept ();
205 }
206 
208 {
209  QString s = QFileDialog::getOpenFileName (
210  lastDir.isEmpty () ? QString (".") : lastDir,
211  tr("PNG files")+" (*.png);;"+
212  tr("Any file")+" (*)",
213  this, 0, tr("Enter an Icon File Name"));
214 
215  if (!s.isEmpty ()) {
216  QFileInfo Info (s);
217  lastDir = Info.dirPath (true); // remember last directory
218  IconEdit->setText (s);
219  IconButt->setPixmap (QPixmap (s));
220  }
221 }
QButtonGroup * toggleGroupTyp
Definition of the TextDoc class.
#define DEV_BJT
Definition: textdoc.h:37
QPushButton * BrowseButt
QRegExpValidator * Validator
bool recreate
Definition: textdoc.h:77
QLineEdit * OutputEdit
#define DEV_MASK_TYP
Definition: textdoc.h:43
QCheckBox * RecreateCheck
QString Icon
Definition: textdoc.h:76
Definitions and declarations for the main application.
QString getModuleName(void)
TextDoc::getModuleName parse the module name ou of the text file contents.
Definition: textdoc.cpp:496
QString LongDesc
Definition: textdoc.h:75
QLineEdit * ShortDescEdit
QString lastDir
Definition: main.cpp:55
QVBoxLayout * vLayout
#define DEV_MOS
Definition: textdoc.h:38
int devtype
Definition: textdoc.h:78
Definition: module.h:30
void slotSetChanged()
TextDoc::slotSetChanged togles tab icon to indicate unsaved changes.
Definition: textdoc.cpp:286
#define DEV_ALL
Definition: textdoc.h:42
VASettingsDialog(TextDoc *)
#define DEV_DIG
Definition: textdoc.h:40
QString DataSet
Definition: qucsdoc.h:52
QLineEdit * LongDescEdit
QLineEdit * IconEdit
The TextDoc class definition.
Definition: textdoc.h:49
#define DEV_MASK_DEV
Definition: textdoc.h:39
QButtonGroup * toggleGroupDev
bool SetChanged
Definition: textdoc.h:80
QString ShortDesc
Definition: textdoc.h:74
#define DEV_ANA
Definition: textdoc.h:41