Qucs-GUI
0.0.19
|
00001 /*************************************************************************** 00002 labeldialog.cpp 00003 ---------------- 00004 begin : Thu Dec 09 2004 00005 copyright : (C) 2004 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 "labeldialog.h" 00018 #include "../wirelabel.h" 00019 00020 #include <QLabel> 00021 #include <QLineEdit> 00022 #include <QPushButton> 00023 #include <QValidator> 00024 #include <QGridLayout> 00025 00026 00027 LabelDialog::LabelDialog(WireLabel *pl, QWidget *parent) 00028 : QDialog(parent) 00029 { 00030 setWindowTitle(tr("Insert Nodename")); 00031 00032 pLabel = pl; 00033 gbox = new QGridLayout(this); 00034 00035 // valid expression for LineEdit: alpha-numeric, but must start with 00036 // letter and never two "_" together 00037 Expr1.setPattern("[a-zA-Z]([0-9a-zA-Z]|_(?!_))+\\!{0,1}"); 00038 Validator1 = new QRegExpValidator(Expr1, this); 00039 00040 QLabel *Label1 = new QLabel(tr("Enter the label:")); 00041 gbox->addWidget(Label1,0,0); 00042 00043 NodeName = new QLineEdit(); 00044 if(pLabel) NodeName->setText(pLabel->Name); 00045 NodeName->setValidator(Validator1); 00046 gbox->addWidget(NodeName,1,0,1,3); 00047 00048 Expr2.setPattern("[^\"=]+"); // valid expression for LineEdit 00049 Validator2 = new QRegExpValidator(Expr2, this); 00050 00051 Label2 = new QLabel(tr("Initial node voltage:")); 00052 gbox->addWidget(Label2,2,0); 00053 InitValue = new QLineEdit(); 00054 if(pLabel) InitValue->setText(pLabel->initValue); 00055 InitValue->setValidator(Validator2); 00056 gbox->addWidget(InitValue,2,1,1,2); 00057 00058 ButtonMore = new QPushButton(tr("Less...")); 00059 gbox->addWidget(ButtonMore,3,0); 00060 ButtonOk = new QPushButton(tr("Ok")); 00061 gbox->addWidget(ButtonOk,3,1); 00062 ButtonCancel = new QPushButton(tr("Cancel")); 00063 gbox->addWidget(ButtonCancel,3,2); 00064 00065 for(;;) { 00066 if(pLabel) if(!pLabel->initValue.isEmpty()) break; 00067 Label2->hide(); 00068 InitValue->hide(); 00069 ButtonMore->setText(tr("More...")); 00070 break; 00071 } 00072 00073 connect(ButtonMore, SIGNAL(clicked()), SLOT(slotExtend())); 00074 connect(ButtonOk, SIGNAL(clicked()), SLOT(slotOk())); 00075 connect(ButtonCancel, SIGNAL(clicked()), SLOT(slotCancel())); 00076 00077 ButtonOk->setDefault(true); 00078 setFocusProxy(NodeName); 00079 } 00080 00081 LabelDialog::~LabelDialog() 00082 { 00083 delete gbox; 00084 delete Validator1; 00085 delete Validator2; 00086 } 00087 00088 void LabelDialog::slotExtend() 00089 { 00090 if(Label2->isHidden()) { 00091 Label2->setHidden(false); 00092 InitValue->setHidden(false); 00093 ButtonMore->setText(tr("Less...")); 00094 } 00095 else { 00096 Label2->hide(); 00097 InitValue->hide(); 00098 ButtonMore->setText(tr("More...")); 00099 } 00100 00101 } 00102 00103 void LabelDialog::slotCancel() 00104 { 00105 done(0); 00106 } 00107 00108 void LabelDialog::slotOk() 00109 { 00110 NodeName->setText(NodeName->text().trimmed()); 00111 InitValue->setText(InitValue->text().trimmed()); 00112 00113 bool changed = false; 00114 if(pLabel) { 00115 if(pLabel->Name != NodeName->text()) { 00116 pLabel->Name = NodeName->text(); 00117 changed = true; 00118 } 00119 00120 if(pLabel->initValue != InitValue->text()) { 00121 pLabel->initValue = InitValue->text(); 00122 changed = true; 00123 } 00124 } 00125 00126 if(changed) done(2); 00127 else done(1); 00128 }