Qucs-GUI  0.0.18
 All Data Structures 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 #include <QtGui>
18 #include "labeldialog.h"
19 #include "../wirelabel.h"
20 
21 #include <QLabel>
22 #include <QLineEdit>
23 #include <QPushButton>
24 #include <QValidator>
25 #include <QGridLayout>
26 
27 
28 LabelDialog::LabelDialog(WireLabel *pl, QWidget *parent)
29  : QDialog(parent) //, 0, true)
30 {
31  setWindowTitle(tr("Insert Nodename"));
32 
33  pLabel = pl;
34  gbox = new QGridLayout(this);
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:"));
42  gbox->addWidget(Label1,0,0);
43 
44  NodeName = new QLineEdit();
45  if(pLabel) NodeName->setText(pLabel->Name);
46  NodeName->setValidator(Validator1);
47  gbox->addWidget(NodeName,1,0,1,3);
48 
49  Expr2.setPattern("[^\"=]+"); // valid expression for LineEdit
50  Validator2 = new QRegExpValidator(Expr2, this);
51 
52  Label2 = new QLabel(tr("Initial node voltage:"));
53  gbox->addWidget(Label2,2,0);
54  InitValue = new QLineEdit();
55  if(pLabel) InitValue->setText(pLabel->initValue);
56  InitValue->setValidator(Validator2);
57  gbox->addWidget(InitValue,2,1,1,2);
58 
59  ButtonMore = new QPushButton(tr("Less..."));
60  gbox->addWidget(ButtonMore,3,0);
61  ButtonOk = new QPushButton(tr("Ok"));
62  gbox->addWidget(ButtonOk,3,1);
63  ButtonCancel = new QPushButton(tr("Cancel"));
64  gbox->addWidget(ButtonCancel,3,2);
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 
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 
105 {
106  done(0);
107 }
108 
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 }
LabelDialog(WireLabel *, QWidget *parent=0)
Definition: labeldialog.cpp:28
QPushButton * ButtonCancel
Definition: labeldialog.h:48
void slotCancel()
QRegExp Expr2
Definition: labeldialog.h:51
QPushButton * ButtonMore
Definition: labeldialog.h:48
QGridLayout * gbox
Definition: labeldialog.h:49
QRegExpValidator * Validator1
Definition: labeldialog.h:50
WireLabel * pLabel
Definition: labeldialog.h:54
QRegExp Expr1
Definition: labeldialog.h:51
QRegExpValidator * Validator2
Definition: labeldialog.h:50
QString Name
Definition: wirelabel.h:46
QPushButton * ButtonOk
Definition: labeldialog.h:48
QLineEdit * InitValue
Definition: labeldialog.h:40
void slotExtend()
Definition: labeldialog.cpp:89
QString initValue
Definition: wirelabel.h:46
QLineEdit * NodeName
Definition: labeldialog.h:40
QLabel * Label2
Definition: labeldialog.h:52