Qucs-GUI
0.0.19
|
00001 /*************************************************************************** 00002 vasettingsdialog.cpp 00003 ---------------------- 00004 begin : Sun Oct 26 2009 00005 copyright : (C) 2009 by Stefan Jahn 00006 email : stefa@lkcc.org 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 #include <QHBoxLayout> 00018 #include <QVBoxLayout> 00019 #include <QLabel> 00020 #include <QLineEdit> 00021 #include <QValidator> 00022 #include <QPushButton> 00023 #include <QMessageBox> 00024 #include <QButtonGroup> 00025 #include <QCheckBox> 00026 #include <QGroupBox> 00027 #include <QString> 00028 #include <QStringList> 00029 #include <QPushButton> 00030 #include <QFileDialog> 00031 #include <QGridLayout> 00032 #include <QRadioButton> 00033 00034 #include "vasettingsdialog.h" 00035 #include "textdoc.h" 00036 #include "main.h" 00037 00038 00039 VASettingsDialog::VASettingsDialog (TextDoc * Doc_) 00040 : QDialog (Doc_) 00041 { 00042 Doc = Doc_; 00043 setWindowTitle(tr("Document Settings")); 00044 00045 QString Module = Doc->getModuleName (); 00046 00047 Expr.setPattern("[0-9a-zA-Z /\\]+"); // valid expression for IconEdit 00048 Validator = new QRegExpValidator (Expr, this); 00049 00050 vLayout = new QVBoxLayout(this); 00051 00052 QGroupBox * codeGroup = new QGroupBox (tr("Code Creation Settings")); 00053 vLayout->addWidget(codeGroup); 00054 QVBoxLayout *vbox = new QVBoxLayout(); 00055 codeGroup->setLayout(vbox); 00056 00057 QGridLayout * all = new QGridLayout (); 00058 vbox->addLayout(all); 00059 00060 if (Doc->Icon.isEmpty ()) 00061 Doc->Icon = Module + ".png"; 00062 00063 IconButt = new QLabel (); 00064 IconButt->setPixmap (QPixmap (Doc->Icon)); 00065 all->addWidget (IconButt, 0, 0, 1, 1); 00066 00067 IconEdit = new QLineEdit (); 00068 IconEdit->setValidator (Validator); 00069 IconEdit->setText (Doc->Icon); 00070 IconEdit->setCursorPosition (0); 00071 all->addWidget (IconEdit, 0, 1, 1, 3); 00072 00073 BrowseButt = new QPushButton (tr("Browse")); 00074 connect (BrowseButt, SIGNAL (clicked()), SLOT (slotBrowse())); 00075 all->addWidget (BrowseButt, 0, 4, 1, 1); 00076 00077 QLabel * l1 = new QLabel (tr("Output file:")); 00078 l1->setAlignment (Qt::AlignRight); 00079 all->addWidget (l1, 1, 0, 1, 1); 00080 OutputEdit = new QLineEdit (); 00081 OutputEdit->setText (Module + ".cpp"); 00082 all->addWidget (OutputEdit, 1, 1, 1, 3); 00083 00084 RecreateCheck = new QCheckBox (tr("Recreate")); 00085 all->addWidget (RecreateCheck, 1, 4, 1, 1); 00086 RecreateCheck->setChecked (Doc->recreate); 00087 00088 if (Doc->ShortDesc.isEmpty ()) 00089 Doc->ShortDesc = Module; 00090 00091 QLabel * l2 = new QLabel (tr("Icon description:")); 00092 l2->setAlignment (Qt::AlignRight); 00093 all->addWidget (l2, 2, 0); 00094 ShortDescEdit = new QLineEdit (); 00095 ShortDescEdit->setText (Doc->ShortDesc); 00096 all->addWidget (ShortDescEdit, 2, 1, 1, 3); 00097 00098 if (Doc->LongDesc.isEmpty ()) 00099 Doc->LongDesc = Module + " verilog device"; 00100 00101 QLabel * l3 = new QLabel (tr("Description:")); 00102 l3->setAlignment (Qt::AlignRight); 00103 all->addWidget (l3, 3, 0); 00104 LongDescEdit = new QLineEdit (); 00105 LongDescEdit->setText (Doc->LongDesc); 00106 all->addWidget (LongDescEdit, 3, 1, 1, 3); 00107 00108 toggleGroupDev = new QButtonGroup (); 00109 QRadioButton * nonRadio = 00110 new QRadioButton (tr("unspecified device")); 00111 QRadioButton * bjtRadio = 00112 new QRadioButton (tr("NPN/PNP polarity")); 00113 QRadioButton * mosRadio = 00114 new QRadioButton (tr("NMOS/PMOS polarity")); 00115 toggleGroupDev->addButton(nonRadio, 0); 00116 toggleGroupDev->addButton(bjtRadio, DEV_BJT); 00117 toggleGroupDev->addButton(mosRadio, DEV_MOS); 00118 if (Doc->devtype & DEV_BJT) 00119 bjtRadio->setChecked (true); 00120 else if (Doc->devtype & DEV_MOS) 00121 mosRadio->setChecked (true); 00122 else 00123 nonRadio->setChecked (true); 00124 all->addMultiCellWidget (nonRadio, 4, 4, 0, 1); 00125 all->addWidget (bjtRadio, 4, 2); 00126 all->addMultiCellWidget (mosRadio, 4, 4, 3, 4); 00127 00128 toggleGroupTyp = new QButtonGroup (); 00129 QRadioButton * anaRadio = 00130 new QRadioButton (tr("analog only")); 00131 QRadioButton * digRadio = 00132 new QRadioButton (tr("digital only")); 00133 QRadioButton * allRadio = 00134 new QRadioButton (tr("both")); 00135 toggleGroupTyp->addButton(digRadio, DEV_DIG); 00136 toggleGroupTyp->addButton(anaRadio, DEV_ANA); 00137 toggleGroupTyp->addButton(allRadio, DEV_ALL); 00138 if ((Doc->devtype & DEV_ALL) == DEV_ALL) 00139 allRadio->setChecked (true); 00140 else if (Doc->devtype & DEV_ANA) 00141 anaRadio->setChecked (true); 00142 else 00143 digRadio->setChecked (true); 00144 all->addMultiCellWidget (anaRadio, 5, 5, 0, 1); 00145 all->addWidget (allRadio, 5, 2); 00146 all->addMultiCellWidget (digRadio, 5, 5, 3, 4); 00147 00148 QHBoxLayout * Buttons = new QHBoxLayout (); 00149 vbox->addLayout(Buttons); 00150 QPushButton * ButtonOk = new QPushButton (tr("Ok")); 00151 Buttons->addWidget(ButtonOk); 00152 QPushButton * ButtonCancel = new QPushButton (tr("Cancel")); 00153 Buttons->addWidget(ButtonCancel); 00154 connect (ButtonOk, SIGNAL(clicked()), SLOT(slotOk())); 00155 connect (ButtonCancel, SIGNAL(clicked()), SLOT(reject())); 00156 ButtonOk->setDefault(true); 00157 00158 } 00159 00160 VASettingsDialog::~VASettingsDialog () 00161 { 00162 delete Validator; 00163 } 00164 00165 void VASettingsDialog::slotOk () 00166 { 00167 bool changed = false; 00168 00169 if (Doc->Icon != IconEdit->text ()) { 00170 Doc->Icon = IconEdit->text (); 00171 changed = true; 00172 } 00173 if (Doc->ShortDesc != ShortDescEdit->text ()) { 00174 Doc->ShortDesc = ShortDescEdit->text (); 00175 changed = true; 00176 } 00177 if (Doc->LongDesc != LongDescEdit->text ()) { 00178 Doc->LongDesc = LongDescEdit->text (); 00179 changed = true; 00180 } 00181 if (Doc->DataSet != OutputEdit->text ()) { 00182 Doc->DataSet = OutputEdit->text (); 00183 changed = true; 00184 } 00185 if (Doc->recreate != RecreateCheck->isChecked ()) { 00186 Doc->recreate = RecreateCheck->isChecked (); 00187 changed = true; 00188 } 00189 if ((Doc->devtype & DEV_MASK_TYP) != toggleGroupTyp->checkedId()) { 00190 Doc->devtype &= ~DEV_MASK_TYP; 00191 Doc->devtype |= toggleGroupTyp->checkedId(); 00192 changed = true; 00193 } 00194 if ((Doc->devtype & DEV_MASK_DEV) != toggleGroupDev->checkedId()) { 00195 Doc->devtype &= ~DEV_MASK_DEV; 00196 Doc->devtype |= toggleGroupDev->checkedId(); 00197 changed = true; 00198 } 00199 00200 if (changed) { 00201 Doc->SetChanged = true; 00202 Doc->slotSetChanged (); 00203 } 00204 accept (); 00205 } 00206 00207 void VASettingsDialog::slotBrowse () 00208 { 00209 QString s = QFileDialog::getOpenFileName ( 00210 lastDir.isEmpty () ? QString (".") : lastDir, 00211 tr("PNG files")+" (*.png);;"+ 00212 tr("Any file")+" (*)", 00213 this, 0, tr("Enter an Icon File Name")); 00214 00215 if (!s.isEmpty ()) { 00216 QFileInfo Info (s); 00217 lastDir = Info.dirPath (true); // remember last directory 00218 IconEdit->setText (s); 00219 IconButt->setPixmap (QPixmap (s)); 00220 } 00221 }