Qucs-GUI
0.0.19
|
00001 /*************************************************************************** 00002 id_text.cpp 00003 ------------- 00004 begin : Thu Oct 14 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 "id_text.h" 00018 #include "id_dialog.h" 00019 #include "schematic.h" 00020 00021 #include <QPainter> 00022 00023 ID_Text::ID_Text(int cx_, int cy_) 00024 { 00025 Name = ".ID "; 00026 isSelected = false; 00027 cx = cx_; 00028 cy = cy_; 00029 x2 = y2 = 20; 00030 00031 Prefix = "SUB"; 00032 } 00033 00034 ID_Text::~ID_Text() 00035 { 00036 } 00037 00038 // -------------------------------------------------------------------------- 00039 void ID_Text::paint(ViewPainter *p) 00040 { 00041 int x, y; 00042 p->Painter->setPen(QPen(Qt::black,1)); 00043 p->map(cx, cy, x, y); 00044 00045 QRect r; 00046 p->Painter->drawText(x, y, 0, 0, Qt::TextDontClip, Prefix, -1, &r); 00047 x2 = r.width(); 00048 y2 = p->LineSpacing; 00049 00050 p->Painter->drawText(x, y+y2, 0, 0, Qt::TextDontClip, "File=name", -1, &r); 00051 if(x2 < r.width()) x2 = r.width(); 00052 y2 += p->LineSpacing; 00053 00054 QList<SubParameter *>::const_iterator it; 00055 for(it = Parameter.constBegin(); it != Parameter.constEnd(); it++) { 00056 if((*it)->display) { 00057 p->Painter->drawText(x, y+y2, 0, 0, Qt::TextDontClip, (*it)->Name, -1, &r); 00058 if(x2 < r.width()) x2 = r.width(); 00059 y2 += p->LineSpacing; 00060 } 00061 } 00062 00063 if(isSelected) { 00064 p->Painter->setPen(QPen(Qt::darkGray,3)); 00065 p->Painter->drawRoundRect(x-4, y-4, x2+8, y2+8); 00066 } 00067 00068 x2 = int(float(x2) / p->Scale); 00069 y2 = int(float(y2) / p->Scale); 00070 } 00071 00072 // -------------------------------------------------------------------------- 00073 void ID_Text::paintScheme(Schematic *p) 00074 { 00075 p->PostPaintEvent(_Rect, cx, cy, x2, y2); 00076 } 00077 00078 // -------------------------------------------------------------------------- 00079 void ID_Text::getCenter(int& x, int &y) 00080 { 00081 x = cx+(x2>>1); 00082 y = cy+(y2>>1); 00083 } 00084 00085 // -------------------------------------------------------------------------- 00086 // Sets the center of the painting to x/y. 00087 void ID_Text::setCenter(int x, int y, bool relative) 00088 { 00089 if(relative) { cx += x; cy += y; } 00090 else { cx = x-(x2>>1); cy = y-(y2>>1); } 00091 } 00092 00093 // -------------------------------------------------------------------------- 00094 bool ID_Text::load(const QString& s) 00095 { 00096 bool ok; 00097 00098 QString n; 00099 n = s.section(' ',1,1); // cx 00100 cx = n.toInt(&ok); 00101 if(!ok) return false; 00102 00103 n = s.section(' ',2,2); // cy 00104 cy = n.toInt(&ok); 00105 if(!ok) return false; 00106 00107 Prefix = s.section(' ',3,3); // Prefix 00108 if(Prefix.isEmpty()) return false; 00109 00110 int i = 1; 00111 for(;;) { 00112 n = s.section('"', i,i); 00113 if(n.isEmpty()) break; 00114 00115 Parameter.append(new SubParameter( 00116 (n.at(0) == '0') ? false : true, 00117 n.section('=', 1,2), 00118 n.section('=', 3,3), 00119 n.section('=', 4,4))); 00120 00121 i += 2; 00122 } 00123 00124 return true; 00125 } 00126 00127 // -------------------------------------------------------------------------- 00128 QString ID_Text::save() 00129 { 00130 QString s = Name+QString::number(cx)+" "+QString::number(cy)+" "; 00131 s += Prefix; 00132 00133 QList<SubParameter *>::const_iterator it; 00134 for(it = Parameter.constBegin(); it != Parameter.constEnd(); it++) { 00135 s += (((*it)->display)? " \"1=" : " \"0="); 00136 s += (*it)->Name + "=" + (*it)->Description + "=" + (*it)->Type + "\""; 00137 } 00138 00139 return s; 00140 } 00141 00142 // -------------------------------------------------------------------------- 00143 QString ID_Text::saveCpp() 00144 { 00145 QString s = 00146 QString ("tx = %1; ty = %2;"). 00147 arg(cx).arg(cy); 00148 return s; 00149 } 00150 00151 QString ID_Text::saveJSON() 00152 { 00153 QString s = QString ("\"tx\" : %1,\n \"ty\" : %2,").arg(cx).arg(cy); 00154 return s; 00155 } 00156 00157 // -------------------------------------------------------------------------- 00158 // Checks if the coordinates x/y point to the painting. 00159 bool ID_Text::getSelected(float fX, float fY, float) 00160 { 00161 if(int(fX) < cx) return false; 00162 if(int(fY) < cy) return false; 00163 if(int(fX) > cx+x2) return false; 00164 if(int(fY) > cy+y2) return false; 00165 00166 return true; 00167 } 00168 00169 // -------------------------------------------------------------------------- 00170 // Rotates around the center. 00171 void ID_Text::rotate() 00172 { 00173 } 00174 00175 // -------------------------------------------------------------------------- 00176 // Mirrors about center line. 00177 void ID_Text::mirrorX() 00178 { 00179 } 00180 00181 // -------------------------------------------------------------------------- 00182 // Mirrors about center line. 00183 void ID_Text::mirrorY() 00184 { 00185 } 00186 00187 // -------------------------------------------------------------------------- 00188 // Calls the property dialog for the painting and changes them accordingly. 00189 // If there were changes, it returns 'true'. 00190 bool ID_Text::Dialog() 00191 { 00192 ID_Dialog *d = new ID_Dialog(this); 00193 if(d->exec() == QDialog::Rejected) { 00194 delete d; 00195 return false; 00196 } 00197 00198 delete d; 00199 return true; 00200 }