My Project  0.0.16
QUCS Mapping
 All Classes Namespaces 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 
18 #include "id_text.h"
19 #include "id_dialog.h"
20 
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(QPen::black,1));
43  p->map(cx, cy, x, y);
44 
45  QRect r;
46  p->Painter->drawText(x, y, 0, 0, Qt::DontClip, Prefix, -1, &r);
47  x2 = r.width();
48  y2 = p->LineSpacing;
49 
50  p->Painter->drawText(x, y+y2, 0, 0, Qt::DontClip, "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::DontClip, 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(QPen::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 // --------------------------------------------------------------------------
72 void ID_Text::paintScheme(QPainter *p)
73 {
74  p->drawRect(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 
151 // --------------------------------------------------------------------------
152 // Checks if the coordinates x/y point to the painting.
153 bool ID_Text::getSelected(float fX, float fY, float)
154 {
155  if(int(fX) < cx) return false;
156  if(int(fY) < cy) return false;
157  if(int(fX) > cx+x2) return false;
158  if(int(fY) > cy+y2) return false;
159 
160  return true;
161 }
162 
163 // --------------------------------------------------------------------------
164 // Rotates around the center.
166 {
167 }
168 
169 // --------------------------------------------------------------------------
170 // Mirrors about center line.
172 {
173 }
174 
175 // --------------------------------------------------------------------------
176 // Mirrors about center line.
178 {
179 }
180 
181 // --------------------------------------------------------------------------
182 // Calls the property dialog for the painting and changes them accordingly.
183 // If there were changes, it returns 'true'.
185 {
186  ID_Dialog *d = new ID_Dialog(this);
187  if(d->exec() == QDialog::Rejected) {
188  delete d;
189  return false;
190  }
191 
192  delete d;
193  return true;
194 }