Qucs-GUI
0.0.19
|
00001 /*************************************************************************** 00002 digisettingsdialog.cpp 00003 ------------------------ 00004 begin : Sat Apr 01 2006 00005 copyright : (C) 2006 by Michael Margraf 00006 email : michael.margraf@alumni.tu-berlin.de 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 <QLabel> 00018 #include <QLineEdit> 00019 #include <QValidator> 00020 #include <QPushButton> 00021 #include <QMessageBox> 00022 #include <QButtonGroup> 00023 #include <QRadioButton> 00024 #include <QGroupBox> 00025 #include <QString> 00026 #include <QStringList> 00027 #include <QVBoxLayout> 00028 #include <QHBoxLayout> 00029 00030 #include "digisettingsdialog.h" 00031 #include "textdoc.h" 00032 #include "misc.h" 00033 00034 00035 DigiSettingsDialog::DigiSettingsDialog(TextDoc *Doc_) 00036 : QDialog(Doc_) 00037 { 00038 Doc = Doc_; 00039 setWindowTitle(tr("Document Settings")); 00040 00041 Expr.setPattern("[0-9][0-9a-zA-Z ]+"); // valid expression for LineEdit 00042 Validator = new QRegExpValidator(Expr, this); 00043 00044 QVBoxLayout *all = new QVBoxLayout(this); 00045 all->setMargin(5); 00046 00047 QGroupBox *setGroup = new QGroupBox(tr("Digital Simulation Settings")); 00048 all->addWidget(setGroup); 00049 00050 QVBoxLayout *group = new QVBoxLayout(); 00051 setGroup->setLayout(group); 00052 00053 QButtonGroup *toggleGroup = new QButtonGroup(); 00054 simRadio = new QRadioButton(tr("Simulation")); 00055 group->addWidget(simRadio); 00056 simRadio->setChecked(Doc->simulation); 00057 00058 QHBoxLayout *hb1 = new QHBoxLayout(); 00059 hb1->setSpacing(5); 00060 TimeLabel = new QLabel(tr("Duration of Simulation:")); 00061 hb1->addWidget(TimeLabel); 00062 Doc->loadSimulationTime(SimTime); 00063 TimeEdit = new QLineEdit(); 00064 hb1->addWidget(TimeEdit); 00065 TimeEdit->setValidator(Validator); 00066 TimeEdit->setText(SimTime); 00067 group->addLayout(hb1); 00068 00069 QRadioButton *comRadio = new QRadioButton(tr("Precompile Module")); 00070 group->addWidget(comRadio); 00071 toggleGroup->insert(simRadio); 00072 toggleGroup->insert(comRadio); 00073 connect(toggleGroup, SIGNAL(buttonClicked(int)), SLOT(slotChangeMode(int))); 00074 00075 QHBoxLayout *hb3 = new QHBoxLayout(); 00076 hb3->setSpacing(5); 00077 NameLabel = new QLabel(tr("Library Name:")); 00078 hb3->addWidget(NameLabel); 00079 NameEdit = new QLineEdit(); 00080 hb3->addWidget(NameEdit); 00081 NameEdit->setText(Doc->Library); 00082 group->addLayout(hb3); 00083 00084 group->addSpacing(15); 00085 00086 QHBoxLayout *hb2 = new QHBoxLayout(); 00087 hb2->setSpacing(5); 00088 LibLabel = new QLabel(tr("Libraries:")); 00089 hb2->addWidget(LibLabel); 00090 LibEdit = new QLineEdit(); 00091 hb2->addWidget(LibEdit); 00092 LibEdit->setText(Doc->Libraries); 00093 group->addLayout(hb2); 00094 00095 all->addSpacing(5); 00096 all->addStretch(); 00097 QHBoxLayout *Buttons = new QHBoxLayout(); 00098 QPushButton *ButtonOk = new QPushButton(tr("Ok")); 00099 QPushButton *ButtonCancel = new QPushButton(tr("Cancel")); 00100 Buttons->addWidget(ButtonOk); 00101 Buttons->addWidget(ButtonCancel); 00102 connect(ButtonOk, SIGNAL(clicked()), SLOT(slotOk())); 00103 connect(ButtonCancel, SIGNAL(clicked()), SLOT(reject())); 00104 all->addLayout(Buttons); 00105 00106 simRadio->setChecked(Doc->simulation); 00107 Doc->SimOpenDpl = Doc->simulation ? true : false; 00108 comRadio->setChecked(!Doc->simulation); 00109 slotChangeMode(!Doc->simulation); 00110 00111 ButtonOk->setDefault(true); 00112 if(Doc->simulation) { 00113 setFocusProxy(TimeEdit); 00114 TimeEdit->setFocus(); 00115 } 00116 else { 00117 setFocusProxy(NameEdit); 00118 NameEdit->setFocus(); 00119 } 00120 } 00121 00122 DigiSettingsDialog::~DigiSettingsDialog() 00123 { 00124 delete Validator; 00125 } 00126 00127 void DigiSettingsDialog::slotOk() 00128 { 00129 bool changed = false; 00130 if(SimTime != TimeEdit->text()) { 00131 if(simRadio->isChecked()) { 00132 QString s = TimeEdit->text(); 00133 if(!misc::VHDL_Time(s, tr("Document Settings"))) { 00134 QMessageBox::critical(this, tr("Error"), s.mid(1)); 00135 reject(); 00136 return; 00137 } else { 00138 Doc->SimTime = s; 00139 changed = true; 00140 } 00141 } 00142 } 00143 if(Doc->Libraries != LibEdit->text()) { 00144 QStringList lst = QStringList::split(' ',LibEdit->text()); 00145 Doc->Libraries = lst.join(" "); 00146 changed = true; 00147 } 00148 if(Doc->simulation != simRadio->isChecked()) { 00149 Doc->simulation = simRadio->isChecked(); 00150 Doc->SimOpenDpl = Doc->simulation ? true : false; 00151 changed = true; 00152 } 00153 if(Doc->Library != NameEdit->text()) { 00154 QString lib = NameEdit->text().trimmed(); 00155 Doc->Library = lib; 00156 changed = true; 00157 } 00158 00159 if(changed) { 00160 Doc->SetChanged = true; 00161 Doc->slotSetChanged(); 00162 } 00163 accept(); 00164 } 00165 00166 void DigiSettingsDialog::slotChangeMode(int idx) 00167 { 00168 switch(idx) { 00169 case 0: 00170 TimeEdit->setEnabled(true); 00171 TimeEdit->setFocus(); 00172 TimeLabel->setEnabled(true); 00173 NameEdit->setEnabled(false); 00174 NameLabel->setEnabled(false); 00175 break; 00176 case 1: 00177 TimeEdit->setEnabled(false); 00178 TimeLabel->setEnabled(false); 00179 NameEdit->setEnabled(true); 00180 NameLabel->setEnabled(true); 00181 break; 00182 } 00183 }