My Project  0.0.16
QUCS Mapping
 All Classes Namespaces 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 
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 <qcheckbox.h>
27 #include <qvgroupbox.h>
28 #include <qstring.h>
29 #include <qstringlist.h>
30 #include <qbutton.h>
31 #include <qtoolbutton.h>
32 #include <qpixmap.h>
33 #include <qimage.h>
34 #include <qradiobutton.h>
35 #include <qfileinfo.h>
36 #include <qfiledialog.h>
37 
38 #include "vasettingsdialog.h"
39 #include "textdoc.h"
40 #include "main.h"
41 
42 
44  : QDialog (Doc_, 0, true, Qt::WDestructiveClose)
45 {
46  Doc = Doc_;
47  setCaption (tr("Document Settings"));
48 
49  QString Module = Doc->getModuleName ();
50 
51  Expr.setPattern("[0-9a-zA-Z /\\]+"); // valid expression for IconEdit
52  Validator = new QRegExpValidator (Expr, this);
53 
54  QGridLayout * box = new QGridLayout (this, 1, 1, 5);
55 
56  QVGroupBox * setGroup = new QVGroupBox (tr("Code Creation Settings"), this);
57  box->addWidget (setGroup, 0, 0);
58  QWidget * f = new QWidget (setGroup);
59  QGridLayout * all = new QGridLayout (f, 7, 5, 5);
60 
61  if (Doc->Icon.isEmpty ())
62  Doc->Icon = Module + ".png";
63 
64  IconButt = new QLabel (f);
65  IconButt->setPixmap (QPixmap (Doc->Icon));
66  all->addWidget (IconButt, 0, 0);
67 
68  IconEdit = new QLineEdit (f);
69  IconEdit->setValidator (Validator);
70  IconEdit->setText (Doc->Icon);
71  IconEdit->setCursorPosition (0);
72  all->addMultiCellWidget (IconEdit, 0, 0, 1, 3);
73 
74  BrowseButt = new QPushButton (tr("Browse"), f);
75  connect (BrowseButt, SIGNAL (clicked()), SLOT (slotBrowse()));
76  all->addWidget (BrowseButt, 0, 4);
77 
78  QLabel * l1 = new QLabel (tr("Output file:"), f);
79  l1->setAlignment (Qt::AlignRight);
80  all->addWidget (l1, 1, 0);
81  OutputEdit = new QLineEdit (f);
82  OutputEdit->setText (Module + ".cpp");
83  all->addMultiCellWidget (OutputEdit, 1, 1, 1, 3);
84 
85  RecreateCheck = new QCheckBox (tr("Recreate"), f);
86  all->addWidget (RecreateCheck, 1, 4);
87  RecreateCheck->setChecked (Doc->recreate);
88 
89  if (Doc->ShortDesc.isEmpty ())
90  Doc->ShortDesc = Module;
91 
92  QLabel * l2 = new QLabel (tr("Icon description:"), f);
93  l2->setAlignment (Qt::AlignRight);
94  all->addWidget (l2, 2, 0);
95  ShortDescEdit = new QLineEdit (f);
96  ShortDescEdit->setText (Doc->ShortDesc);
97  all->addMultiCellWidget (ShortDescEdit, 2, 2, 1, 4);
98 
99  if (Doc->LongDesc.isEmpty ())
100  Doc->LongDesc = Module + " verilog device";
101 
102  QLabel * l3 = new QLabel (tr("Description:"), f);
103  l3->setAlignment (Qt::AlignRight);
104  all->addWidget (l3, 3, 0);
105  LongDescEdit = new QLineEdit (f);
106  LongDescEdit->setText (Doc->LongDesc);
107  all->addMultiCellWidget (LongDescEdit, 3, 3, 1, 4);
108 
109  toggleGroupDev = new QButtonGroup ();
110  QRadioButton * nonRadio =
111  new QRadioButton (tr("unspecified device"), f);
112  QRadioButton * bjtRadio =
113  new QRadioButton (tr("NPN/PNP polarity"), f);
114  QRadioButton * mosRadio =
115  new QRadioButton (tr("NMOS/PMOS polarity"), f);
116  toggleGroupDev->insert (nonRadio, 0);
117  toggleGroupDev->insert (bjtRadio, DEV_BJT);
118  toggleGroupDev->insert (mosRadio, DEV_MOS);
119  if (Doc->devtype & DEV_BJT)
120  bjtRadio->setChecked (true);
121  else if (Doc->devtype & DEV_MOS)
122  mosRadio->setChecked (true);
123  else
124  nonRadio->setChecked (true);
125  all->addMultiCellWidget (nonRadio, 4, 4, 0, 1);
126  all->addWidget (bjtRadio, 4, 2);
127  all->addMultiCellWidget (mosRadio, 4, 4, 3, 4);
128 
129  toggleGroupTyp = new QButtonGroup ();
130  QRadioButton * anaRadio =
131  new QRadioButton (tr("analog only"), f);
132  QRadioButton * digRadio =
133  new QRadioButton (tr("digital only"), f);
134  QRadioButton * allRadio =
135  new QRadioButton (tr("both"), f);
136  toggleGroupTyp->insert (digRadio, DEV_DIG);
137  toggleGroupTyp->insert (anaRadio, DEV_ANA);
138  toggleGroupTyp->insert (allRadio, DEV_ALL);
139  if ((Doc->devtype & DEV_ALL) == DEV_ALL)
140  allRadio->setChecked (true);
141  else if (Doc->devtype & DEV_ANA)
142  anaRadio->setChecked (true);
143  else
144  digRadio->setChecked (true);
145  all->addMultiCellWidget (anaRadio, 5, 5, 0, 1);
146  all->addWidget (allRadio, 5, 2);
147  all->addMultiCellWidget (digRadio, 5, 5, 3, 4);
148 
149  QHBox * Buttons = new QHBox (f);
150  all->addMultiCellWidget (Buttons, 6, 6, 0, 4);
151  QPushButton * ButtonOk = new QPushButton (tr("Ok"), Buttons);
152  QPushButton * ButtonCancel = new QPushButton (tr("Cancel"), Buttons);
153  connect (ButtonOk, SIGNAL(clicked()), SLOT(slotOk()));
154  connect (ButtonCancel, SIGNAL(clicked()), SLOT(reject()));
155  ButtonOk->setDefault(true);
156 }
157 
159 {
160  delete Validator;
161 }
162 
163 void VASettingsDialog::slotOk ()
164 {
165  bool changed = false;
166 
167  if (Doc->Icon != IconEdit->text ()) {
168  Doc->Icon = IconEdit->text ();
169  changed = true;
170  }
171  if (Doc->ShortDesc != ShortDescEdit->text ()) {
172  Doc->ShortDesc = ShortDescEdit->text ();
173  changed = true;
174  }
175  if (Doc->LongDesc != LongDescEdit->text ()) {
176  Doc->LongDesc = LongDescEdit->text ();
177  changed = true;
178  }
179  if (Doc->DataSet != OutputEdit->text ()) {
180  Doc->DataSet = OutputEdit->text ();
181  changed = true;
182  }
183  if (Doc->recreate != RecreateCheck->isChecked ()) {
184  Doc->recreate = RecreateCheck->isChecked ();
185  changed = true;
186  }
187  if ((Doc->devtype & DEV_MASK_TYP) != toggleGroupTyp->selectedId ()) {
188  Doc->devtype &= ~DEV_MASK_TYP;
189  Doc->devtype |= toggleGroupTyp->selectedId ();
190  changed = true;
191  }
192  if ((Doc->devtype & DEV_MASK_DEV) != toggleGroupDev->selectedId ()) {
193  Doc->devtype &= ~DEV_MASK_DEV;
194  Doc->devtype |= toggleGroupDev->selectedId ();
195  changed = true;
196  }
197 
198  if (changed) {
199  Doc->SetChanged = true;
200  Doc->slotSetChanged ();
201  }
202  accept ();
203 }
204 
205 void VASettingsDialog::slotBrowse ()
206 {
207  QString s = QFileDialog::getOpenFileName (
208  lastDir.isEmpty () ? QString (".") : lastDir,
209  tr("PNG files")+" (*.png);;"+
210  tr("Any file")+" (*)",
211  this, 0, tr("Enter an Icon File Name"));
212 
213  if (!s.isEmpty ()) {
214  QFileInfo Info (s);
215  lastDir = Info.dirPath (true); // remember last directory
216  IconEdit->setText (s);
217  IconButt->setPixmap (QPixmap (s));
218  }
219 }