My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
labeldialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  labeldialog.cpp
3  ----------------
4  begin : Thu Dec 09 2004
5  copyright : (C) 2004 by Michael Margraf
6  email : michael.margraf@alumni.tu-berlin.de
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 "labeldialog.h"
19 #include "../wirelabel.h"
20 
21 #include <qlayout.h>
22 #include <qlabel.h>
23 #include <qlineedit.h>
24 #include <qpushbutton.h>
25 #include <qvalidator.h>
26 
27 
28 LabelDialog::LabelDialog(WireLabel *pl, QWidget *parent)
29  : QDialog(parent, 0, true)
30 {
31  setCaption(tr("Insert Nodename"));
32 
33  pLabel = pl;
34  gbox = new QGridLayout(this,4,3,5,5);
35 
36  // valid expression for LineEdit: alpha-numeric, but must start with
37  // letter and never two "_" together
38  Expr1.setPattern("[a-zA-Z]([0-9a-zA-Z]|_(?!_))+\\!{0,1}");
39  Validator1 = new QRegExpValidator(Expr1, this);
40 
41  QLabel *Label1 = new QLabel(tr("Enter the label:"),this);
42  gbox->addWidget(Label1,0,0);
43 
44  NodeName = new QLineEdit(this);
45  if(pLabel) NodeName->setText(pLabel->Name);
46  NodeName->setValidator(Validator1);
47  gbox->addMultiCellWidget(NodeName,1,1,0,3);
48 
49  Expr2.setPattern("[^\"=]+"); // valid expression for LineEdit
50  Validator2 = new QRegExpValidator(Expr2, this);
51 
52  Label2 = new QLabel(tr("Initial node voltage:"),this);
53  gbox->addWidget(Label2,2,0);
54  InitValue = new QLineEdit(this);
55  if(pLabel) InitValue->setText(pLabel->initValue);
56  InitValue->setValidator(Validator2);
57  gbox->addMultiCellWidget(InitValue,2,2,1,3);
58 
59  ButtonMore = new QPushButton(tr("Less..."),this);
60  gbox->addWidget(ButtonMore,3,1);
61  ButtonOk = new QPushButton(tr("Ok"),this);
62  gbox->addWidget(ButtonOk,3,2);
63  ButtonCancel = new QPushButton(tr("Cancel"),this);
64  gbox->addWidget(ButtonCancel,3,3);
65 
66  for(;;) {
67  if(pLabel) if(!pLabel->initValue.isEmpty()) break;
68  Label2->hide();
69  InitValue->hide();
70  ButtonMore->setText(tr("More..."));
71  break;
72  }
73 
74  connect(ButtonMore, SIGNAL(clicked()), SLOT(slotExtend()));
75  connect(ButtonOk, SIGNAL(clicked()), SLOT(slotOk()));
76  connect(ButtonCancel, SIGNAL(clicked()), SLOT(slotCancel()));
77 
78  ButtonOk->setDefault(true);
79  setFocusProxy(NodeName);
80 }
81 
83 {
84  delete gbox;
85  delete Validator1;
86  delete Validator2;
87 }
88 
89 void LabelDialog::slotExtend()
90 {
91  if(Label2->isHidden()) {
92  Label2->setHidden(false);
93  InitValue->setHidden(false);
94  ButtonMore->setText(tr("Less..."));
95  }
96  else {
97  Label2->hide();
98  InitValue->hide();
99  ButtonMore->setText(tr("More..."));
100  }
101 
102 }
103 
104 void LabelDialog::slotCancel()
105 {
106  done(0);
107 }
108 
109 void LabelDialog::slotOk()
110 {
111  NodeName->setText(NodeName->text().stripWhiteSpace());
112  InitValue->setText(InitValue->text().stripWhiteSpace());
113 
114  bool changed = false;
115  if(pLabel) {
116  if(pLabel->Name != NodeName->text()) {
117  pLabel->Name = NodeName->text();
118  changed = true;
119  }
120 
121  if(pLabel->initValue != InitValue->text()) {
122  pLabel->initValue = InitValue->text();
123  changed = true;
124  }
125  }
126 
127  if(changed) done(2);
128  else done(1);
129 }