27 #include <qapplication.h>
29 #include <qstringlist.h>
30 #include <qtextcodec.h>
31 #include <qtranslator.h>
33 #include <qtextstream.h>
34 #include <qmessagebox.h>
53 if(!file.open(IO_ReadOnly))
return false;
55 QTextStream stream(&file);
56 QString
Line, Setting;
59 while(!stream.atEnd()) {
60 Line = stream.readLine();
61 Setting = Line.section(
'=',0,0);
62 Line = Line.section(
'=',1).stripWhiteSpace();
63 if(Setting ==
"Position") {
64 QucsSettings.
x = Line.section(
",",0,0).toInt(&ok);
65 QucsSettings.
y = Line.section(
",",1,1).toInt(&ok); }
66 else if(Setting ==
"Size") {
67 QucsSettings.
dx = Line.section(
",",0,0).toInt(&ok);
68 QucsSettings.
dy = Line.section(
",",1,1).toInt(&ok); }
69 else if(Setting ==
"Font") {
70 QucsSettings.
font.fromString(Line);
74 =
floor(4.0/3.0 * QucsSettings.
font.pointSize());
76 else if(Setting ==
"BGColor") {
77 QucsSettings.
BGColor.setNamedColor(Line); }
78 else if(Setting ==
"maxUndo") {
79 QucsSettings.
maxUndo = Line.toInt(&ok); }
80 else if(Setting ==
"Editor") {
81 QucsSettings.
Editor = Line; }
82 else if(Setting ==
"FileType") {
84 else if(Setting ==
"Language") {
86 else if(Setting ==
"SyntaxColor") {
87 QucsSettings.
Comment.setNamedColor(Line.section(
",", 0,0));
88 QucsSettings.
String.setNamedColor(Line.section(
",", 1,1));
89 QucsSettings.
Integer.setNamedColor(Line.section(
",", 2,2));
90 QucsSettings.
Real.setNamedColor(Line.section(
",", 3,3));
91 QucsSettings.
Character.setNamedColor(Line.section(
",", 4,4));
92 QucsSettings.
Type.setNamedColor(Line.section(
",", 5,5));
93 QucsSettings.
Attribute.setNamedColor(Line.section(
",", 6,6));
94 QucsSettings.
Directive.setNamedColor(Line.section(
",", 7,7));
95 QucsSettings.
Task.setNamedColor(Line.section(
",", 8,8));
97 else if(Setting ==
"NodeWiring") {
110 if(!file.open(IO_WriteOnly)) {
111 QMessageBox::warning(0, QObject::tr(
"Warning"),
112 QObject::tr(
"Cannot save settings !"));
116 QTextStream stream(&file);
118 stream <<
"Settings file, Qucs " PACKAGE_VERSION
"\n"
119 <<
"Position=" << qucs->x() <<
"," << qucs->y() <<
"\n"
120 <<
"Size=" << qucs->width() <<
"," << qucs->height() <<
"\n"
122 <<
"Language=" << QucsSettings.
Language <<
"\n"
123 <<
"BGColor=" << QucsSettings.
BGColor.name() <<
"\n"
124 <<
"maxUndo=" << QucsSettings.
maxUndo <<
"\n"
125 <<
"Editor=" << QucsSettings.
Editor <<
"\n"
127 << QucsSettings.
Comment.name() <<
","
128 << QucsSettings.
String.name() <<
","
129 << QucsSettings.
Integer.name() <<
","
130 << QucsSettings.
Real.name() <<
","
132 << QucsSettings.
Type.name() <<
","
135 << QucsSettings.
Task.name() <<
"\n"
136 <<
"NodeWiring=" << QucsSettings.
NodeWiring <<
"\n";
138 QStringList::Iterator it = QucsSettings.
FileTypes.begin();
139 while(it != QucsSettings.
FileTypes.end())
140 stream <<
"FileType=" << (*(it++)) <<
"\n";
150 if(fabs(imag) < 1
e-250) Text = QString::number(real,
'g',Precision);
152 Text = QString::number(imag,
'g',Precision);
153 if(Text.at(0) ==
'-') {
157 else Text =
"+j"+Text;
158 Text = QString::number(real,
'g',Precision) + Text;
166 if(fabs(imag) < 1
e-250) Text = QString::number(real,
'g',Precision);
168 Text = QString::number(
sqrt(real*real+imag*imag),
'g',Precision) +
" / ";
169 Text += QString::number(180.0/
M_PI*
atan2(imag,real),
'g',Precision) +
'°';
177 if(fabs(imag) < 1
e-250) Text = QString::number(real,
'g',Precision);
179 Text = QString::number(
sqrt(real*real+imag*imag),
'g',Precision);
180 Text +=
" / " + QString::number(
atan2(imag,real),
'g',Precision) +
"rad";
189 char *p, Buffer[512], Format[6] =
"%.00g";
197 Format[2] += Precision / 10;
198 Format[3] += Precision % 10;
200 sprintf(Buffer, Format, num);
204 if(*(p++) ==
'+') { a = 1; }
205 if(*p ==
'0') { a++; p++; }
209 }
while(*(p++) != 0);
212 return QString(Buffer);
218 char Format[6] =
"%.8e";
219 if(fabs(num) < 1
e-250)
return QString(
"0");
220 if(fabs(
log10(fabs(num))) < 3.0) Format[3] =
'g';
223 char *p, *pe, Buffer[512];
225 sprintf(Buffer, Format, num);
226 p = pe =
strchr(Buffer,
'e');
228 if(*(++p) ==
'+') { a = 1; }
229 if(*(++p) ==
'0') { a++; p++; }
233 }
while(*(p++) != 0);
238 if(!pe) pe = Buffer + strlen(Buffer);
241 if((--p) <= Buffer)
break;
243 while( (*(p++) = *(pe++)) != 0 ) ;
247 return QString(Buffer);
251 void str2num(
const QString& s_,
double& Number, QString&
Unit,
double& Factor)
253 QString str = s_.stripWhiteSpace();
270 QRegExp Expr( QRegExp(
"[^0-9\\x2E\\x2D\\x2B]") );
271 int i = str.find( Expr );
273 if((str.at(i).latin1() | 0x20) ==
'e') {
274 int j = str.find( Expr , ++i);
279 Number = str.left(i).toDouble();
280 Unit = str.mid(i).stripWhiteSpace();
282 switch(Unit.at(0).latin1()) {
283 case 'T': Factor = 1e12;
break;
284 case 'G': Factor = 1e9;
break;
285 case 'M': Factor = 1e6;
break;
286 case 'k': Factor = 1e3;
break;
287 case 'c': Factor = 1
e-2;
break;
288 case 'm': Factor = 1
e-3;
break;
289 case 'u': Factor = 1
e-6;
break;
290 case 'n': Factor = 1
e-9;
break;
291 case 'p': Factor = 1
e-12;
break;
292 case 'f': Factor = 1
e-15;
break;
294 default: Factor = 1.0;
304 double cal = fabs(Num);
306 cal =
log10(cal) / 3.0;
307 if(cal < -0.2) cal -= 0.98;
310 if(Expo >= -5)
if(Expo <= 4)
312 case -5: c =
'f';
break;
313 case -4: c =
'p';
break;
314 case -3: c =
'n';
break;
315 case -2: c =
'u';
break;
316 case -1: c =
'm';
break;
317 case 1: c =
'k';
break;
318 case 2: c =
'M';
break;
319 case 3: c =
'G';
break;
320 case 4: c =
'T';
break;
323 if(c) Num /=
pow(10.0,
double(3*Expo));
326 QString Str = QString::number(Num);
339 while((i=Text.find(
"\\x", i)) >= 0) {
341 ch = n.mid(2).toUShort(&ok, 16);
342 if(ok) Text.replace(n, QChar(ch));
345 Text.replace(
"\\n",
"\n");
346 Text.replace(
"\\\\",
"\\");
352 Text.replace(
'\\',
"\\\\");
353 Text.replace(
'\n',
"\\n");
358 while((ch=Text.at(i++)) != QChar(0)) {
359 if(ch > QChar(0x7F)) {
360 sprintf(Str,
"\\x%04X", ch.unicode());
361 Text.replace(ch, Str);
372 return QDir::cleanDirPath(s);
378 QFileInfo Info(Name);
379 return Info.fileName();
388 if(Info.extension() ==
"sch")
389 s = s.left(s.length()-4);
390 if(s.at(0) <=
'9')
if(s.at(0) >=
'0')
392 s.replace(QRegExp(
"\\W"),
"_");
393 s.replace(
"__",
"_");
403 if(strtod(td.latin1(), 0) != 0.0) {
409 else if(isalpha(td.latin1()[0])) {
424 double Time = strtod(t.latin1(), &p);
425 while(*p ==
' ') p++;
428 if(strcmp(p,
"fs") == 0)
break;
429 if(strcmp(p,
"ps") == 0)
break;
430 if(strcmp(p,
"ns") == 0)
break;
431 if(strcmp(p,
"us") == 0)
break;
432 if(strcmp(p,
"ms") == 0)
break;
433 if(strcmp(p,
"sec") == 0)
break;
434 if(strcmp(p,
"min") == 0)
break;
435 if(strcmp(p,
"hr") == 0)
break;
437 t =
"§" + QObject::tr(
"Error: Wrong time format in \"%1\". Use positive number with units").arg(Name)
438 +
" fs, ps, ns, us, ms, sec, min, hr.\n";
442 t = QString::number(Time) +
" " + QString(p);
450 if(strtod(Value.latin1(), 0) != 0.0) {
465 if(strtod(td.latin1(), 0) != 0.0) {
471 else if(isalpha(td.latin1()[0])) {
486 double Time = strtod(t.latin1(), &p);
488 while(*p ==
' ') p++;
491 if(strcmp(p,
"fs") == 0) { factor = 1
e-3;
break; }
492 if(strcmp(p,
"ps") == 0) { factor = 1;
break; }
493 if(strcmp(p,
"ns") == 0) { factor = 1e3;
break; }
494 if(strcmp(p,
"us") == 0) { factor = 1e6;
break; }
495 if(strcmp(p,
"ms") == 0) { factor = 1e9;
break; }
496 if(strcmp(p,
"sec") == 0) { factor = 1e12;
break; }
497 if(strcmp(p,
"min") == 0) { factor = 1e12*60;
break; }
498 if(strcmp(p,
"hr") == 0) { factor = 1e12*60*60;
break; }
500 t =
"§" + QObject::tr(
"Error: Wrong time format in \"%1\". Use positive number with units").arg(Name)
501 +
" fs, ps, ns, us, ms, sec, min, hr.\n";
505 t = QString::number(Time*factor);
512 QStringList sl = QStringList::split(
'.',PACKAGE_VERSION);
513 QStringList ll = QStringList::split(
'.',Line);
514 if (ll.count() != 3 || sl.count() != 3)
516 int sv = (*sl.at(1)).toInt() * 10000 + (*sl.at(2)).toInt() * 100 +
518 int lv = (*ll.at(1)).toInt() * 10000 + (*ll.at(2)).toInt() * 100 +
532 int main(
int argc,
char *argv[])
535 QucsSettings.
font = QFont(
"Helvetica", 12);
541 QApplication a(argc, argv);
542 QDesktopWidget *d = a.desktop();
545 QucsSettings.
x = w/8;
546 QucsSettings.
y = h/8;
547 QucsSettings.
dx = w*3/4;
548 QucsSettings.
dy = h*3/4;
551 char * var = getenv (
"QUCSDIR");
553 QDir QucsDir = QDir (var);
554 QString QucsDirStr = QucsDir.canonicalPath ();
556 QDir::convertSeparators (QucsDirStr +
"/bin/");
558 QDir::convertSeparators (QucsDirStr +
"/share/qucs/bitmaps/");
560 QDir::convertSeparators (QucsDirStr +
"/share/qucs/lang/");
562 QDir::convertSeparators (QucsDirStr +
"/share/qucs/library/");
564 QDir::convertSeparators (QucsDirStr +
"/share/qucs/octave/");
566 QucsSettings.
BinDir = BINARYDIR;
568 QucsSettings.
LangDir = LANGUAGEDIR;
569 QucsSettings.
LibDir = LIBRARYDIR;
574 QucsWorkDir.setPath(QDir::homeDirPath()+QDir::convertSeparators (
"/.qucs"));
575 QucsHomeDir.setPath(QDir::homeDirPath()+QDir::convertSeparators (
"/.qucs"));
578 if(!QucsSettings.
BGColor.isValid())
579 QucsSettings.
BGColor.setRgb(255, 250, 225);
582 if(!QucsSettings.
Comment.isValid())
583 QucsSettings.
Comment = Qt::gray;
584 if(!QucsSettings.
String.isValid())
585 QucsSettings.
String = Qt::red;
586 if(!QucsSettings.
Integer.isValid())
587 QucsSettings.
Integer = Qt::blue;
588 if(!QucsSettings.
Real.isValid())
589 QucsSettings.
Real = Qt::darkMagenta;
592 if(!QucsSettings.
Type.isValid())
593 QucsSettings.
Type = Qt::darkRed;
598 if(!QucsSettings.
Task.isValid())
599 QucsSettings.
Task = Qt::darkRed;
601 var = getenv (
"ASCODIR");
603 QDir AscoDir = QDir (var);
604 QString AscoDirStr = AscoDir.canonicalPath ();
606 QDir::convertSeparators (AscoDirStr +
"/bin/");
611 a.setFont(QucsSettings.
font);
613 QTranslator tor( 0 );
614 QString lang = QucsSettings.
Language;
616 lang = QTextCodec::locale();
617 tor.load( QString(
"qucs_") + lang, QucsSettings.
LangDir);
618 a.installTranslator( &tor );
622 setlocale (LC_NUMERIC,
"C");
625 a.setMainWidget(QucsMain);
627 int result = a.exec();