Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
id_text.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  id_text.cpp
3  -------------
4  begin : Thu Oct 14 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 "id_text.h"
19 #include "id_dialog.h"
20 #include "schematic.h"
21 
22 ID_Text::ID_Text(int cx_, int cy_)
23 {
24  Name = ".ID ";
25  isSelected = false;
26  cx = cx_;
27  cy = cy_;
28  x2 = y2 = 20;
29 
30  Prefix = "SUB";
31  Parameter.setAutoDelete(true);
32 }
33 
35 {
36 }
37 
38 // --------------------------------------------------------------------------
40 {
41  int x, y;
42  p->Painter->setPen(QPen(Qt::black,1));
43  p->map(cx, cy, x, y);
44 
45  QRect r;
46  p->Painter->drawText(x, y, 0, 0, Qt::TextDontClip, Prefix, -1, &r);
47  x2 = r.width();
48  y2 = p->LineSpacing;
49 
50  p->Painter->drawText(x, y+y2, 0, 0, Qt::TextDontClip, "File=name", -1, &r);
51  if(x2 < r.width()) x2 = r.width();
52  y2 += p->LineSpacing;
53 
54  SubParameter *pp;
55  for(pp = Parameter.first(); pp != 0; pp = Parameter.next())
56  if(pp->display) {
57  p->Painter->drawText(x, y+y2, 0, 0, Qt::TextDontClip, pp->Name, -1, &r);
58  if(x2 < r.width()) x2 = r.width();
59  y2 += p->LineSpacing;
60  }
61 
62  if(isSelected) {
63  p->Painter->setPen(QPen(Qt::darkGray,3));
64  p->Painter->drawRoundRect(x-4, y-4, x2+8, y2+8);
65  }
66 
67  x2 = int(float(x2) / p->Scale);
68  y2 = int(float(y2) / p->Scale);
69 }
70 
71 // --------------------------------------------------------------------------
73 {
74  p->PostPaintEvent(_Rect, cx, cy, x2, y2);
75 }
76 
77 // --------------------------------------------------------------------------
78 void ID_Text::getCenter(int& x, int &y)
79 {
80  x = cx+(x2>>1);
81  y = cy+(y2>>1);
82 }
83 
84 // --------------------------------------------------------------------------
85 // Sets the center of the painting to x/y.
86 void ID_Text::setCenter(int x, int y, bool relative)
87 {
88  if(relative) { cx += x; cy += y; }
89  else { cx = x-(x2>>1); cy = y-(y2>>1); }
90 }
91 
92 // --------------------------------------------------------------------------
93 bool ID_Text::load(const QString& s)
94 {
95  bool ok;
96 
97  QString n;
98  n = s.section(' ',1,1); // cx
99  cx = n.toInt(&ok);
100  if(!ok) return false;
101 
102  n = s.section(' ',2,2); // cy
103  cy = n.toInt(&ok);
104  if(!ok) return false;
105 
106  Prefix = s.section(' ',3,3); // Prefix
107  if(Prefix.isEmpty()) return false;
108 
109  int i = 1;
110  for(;;) {
111  n = s.section('"', i,i);
112  if(n.isEmpty()) break;
113 
114  Parameter.append(new SubParameter(
115  (n.at(0) == '0') ? false : true,
116  n.section('=', 1,2),
117  n.section('=', 3,3),
118  n.section('=', 4,4)));
119 
120  i += 2;
121  }
122 
123  return true;
124 }
125 
126 // --------------------------------------------------------------------------
127 QString ID_Text::save()
128 {
129  QString s = Name+QString::number(cx)+" "+QString::number(cy)+" ";
130  s += Prefix;
131 
132  SubParameter *pp;
133  for(pp = Parameter.first(); pp != 0; pp = Parameter.next()) {
134  if(pp->display) s += " \"1=";
135  else s += " \"0=";
136  s += pp->Name + "=" + pp->Description + "=" + pp->Type + "\"";
137  }
138 
139  return s;
140 }
141 
142 // --------------------------------------------------------------------------
144 {
145  QString s =
146  QString ("tx = %1; ty = %2;").
147  arg(cx).arg(cy);
148  return s;
149 }
150 
152 {
153  QString s = QString ("\"tx\" : %1,\n \"ty\" : %2,").arg(cx).arg(cy);
154  return s;
155 }
156 
157 // --------------------------------------------------------------------------
158 // Checks if the coordinates x/y point to the painting.
159 bool ID_Text::getSelected(float fX, float fY, float)
160 {
161  if(int(fX) < cx) return false;
162  if(int(fY) < cy) return false;
163  if(int(fX) > cx+x2) return false;
164  if(int(fY) > cy+y2) return false;
165 
166  return true;
167 }
168 
169 // --------------------------------------------------------------------------
170 // Rotates around the center.
172 {
173 }
174 
175 // --------------------------------------------------------------------------
176 // Mirrors about center line.
178 {
179 }
180 
181 // --------------------------------------------------------------------------
182 // Mirrors about center line.
184 {
185 }
186 
187 // --------------------------------------------------------------------------
188 // Calls the property dialog for the painting and changes them accordingly.
189 // If there were changes, it returns 'true'.
191 {
192  ID_Dialog *d = new ID_Dialog(this);
193  if(d->exec() == QDialog::Rejected) {
194  delete d;
195  return false;
196  }
197 
198  delete d;
199  return true;
200 }
QString Prefix
Definition: id_text.h:59
QPainter * Painter
Definition: viewpainter.h:58
void PostPaintEvent(PE pe, int x1=0, int y1=0, int x2=0, int y2=0, int a=0, int b=0, bool PaintOnViewport=false)
Definition: schematic.cpp:533
QString Description
Definition: id_text.h:34
float Scale
Definition: viewpainter.h:59
void map(int, int, int &, int &)
Definition: viewpainter.cpp:63
void paint(ViewPainter *)
Definition: id_text.cpp:39
int y2
Definition: element.h:153
int LineSpacing
Definition: viewpainter.h:60
bool load(const QString &)
Definition: id_text.cpp:93
bool Dialog()
Definition: id_text.cpp:190
void mirrorX()
Definition: id_text.cpp:177
QString save()
Definition: id_text.cpp:127
int cx
Definition: element.h:153
void setCenter(int, int, bool relative=false)
Definition: id_text.cpp:86
bool getSelected(float, float, float)
Definition: id_text.cpp:159
void mirrorY()
Definition: id_text.cpp:183
bool isSelected
Definition: element.h:151
QString saveCpp()
Definition: id_text.cpp:143
void paintScheme(Schematic *)
Definition: id_text.cpp:72
QString Name
Definition: painting.h:55
void rotate()
Definition: id_text.cpp:171
~ID_Text()
Definition: id_text.cpp:34
ID_Text(int cx_=0, int cy_=0)
Definition: id_text.cpp:22
QString Type
Definition: id_text.h:34
QString Name
Definition: id_text.h:34
bool display
Definition: id_text.h:31
int cy
Definition: element.h:153
Q3PtrList< SubParameter > Parameter
Definition: id_text.h:60
int x2
Definition: element.h:153
QString saveJSON()
Definition: id_text.cpp:151
void getCenter(int &, int &)
Definition: id_text.cpp:78