23 #include <qlineedit.h>
24 #include <qstatusbar.h>
25 #include <qtabwidget.h>
26 #include <qmessagebox.h>
27 #include <qfiledialog.h>
29 #include <qvalidator.h>
36 #include "components/ground.h"
53 bool QucsApp::performToggleAction(
bool on, QAction *Action,
69 if(Function)
if((Doc->*Function)()) {
70 Action->blockSignals(
true);
72 Action->blockSignals(
false);
73 Doc->viewport()->update();
91 Doc->viewport()->update();
133 if (isTextDocument (Doc)) {
134 Doc->clearParagraphBackground (Doc->
tmpPosX);
152 if(Doc->inherits(
"QTextEdit")) {
153 Doc->viewport()->setFocus();
169 performToggleAction(on,
insWire, 0,
176 performToggleAction(on,
insLabel, 0,
191 performToggleAction(on,
moveText, 0,
200 if(Doc->inherits(
"QTextEdit")) {
207 performToggleAction(on,
magPlus, 0,
216 if(w->inherits(
"QTextEdit")) {
217 ((
TextDoc*)w)->viewport()->setFocus();
219 select->blockSignals(
true);
221 select->blockSignals(
false);
230 Doc->viewport()->update();
233 select->blockSignals(
true);
235 select->blockSignals(
false);
249 if(Doc->inherits(
"QTextEdit")) {
250 ((
TextDoc*)Doc)->viewport()->setFocus();
267 if(
view->
drawn) Doc->viewport()->update();
297 Doc->viewport()->setFocus ();
298 Doc->clearParagraphBackground (Doc->
tmpPosX);
302 Doc->getCursorPosition (&x, &y);
333 if(
view->
drawn) Doc->viewport()->update();
366 if(
view->
drawn) Doc->viewport()->update();
399 if(
view->
drawn) Doc->viewport()->update();
410 if(Doc->inherits(
"QTextEdit")) {
411 ((
TextDoc*)Doc)->viewport()->setFocus();
419 Doc->viewport()->update();
428 if(Doc->inherits(
"QTextEdit")) {
429 ((
TextDoc*)Doc)->viewport()->setFocus();
437 Doc->viewport()->update();
449 QMessageBox::information(
this, tr(
"Info"),
450 tr(
"At least two elements must be selected !"));
451 Doc->viewport()->update();
463 QMessageBox::information(
this, tr(
"Info"),
464 tr(
"At least two elements must be selected !"));
465 Doc->viewport()->update();
477 QMessageBox::information(
this, tr(
"Info"),
478 tr(
"At least two elements must be selected !"));
479 Doc->viewport()->update();
491 QMessageBox::information(
this, tr(
"Info"),
492 tr(
"At least two elements must be selected !"));
493 Doc->viewport()->update();
505 Doc->viewport()->update();
517 Doc->viewport()->update();
529 QMessageBox::information(
this, tr(
"Info"),
530 tr(
"At least two elements must be selected !"));
531 Doc->viewport()->update();
543 QMessageBox::information(
this, tr(
"Info"),
544 tr(
"At least two elements must be selected !"));
545 Doc->viewport()->update();
556 if(Doc->inherits(
"QTextEdit")) {
557 ((
TextDoc*)Doc)->viewport()->setFocus();
558 ((
TextDoc*)Doc)->selectAll(
true);
561 ((
Schematic*)Doc)->selectElements(INT_MIN, INT_MIN, INT_MAX, INT_MAX,
true);
575 Doc->viewport()->update();
586 if (!File.isEmpty()) com << File;
587 QProcess *QucsEditor =
new QProcess(com);
588 QucsEditor->setCommunication(0);
589 if(!QucsEditor->start()) {
590 QMessageBox::critical(
this, tr(
"Error"), tr(
"Cannot start text editor!"));
626 if(!QucsFilter->start()) {
627 QMessageBox::critical(
this, tr(
"Error"),
628 tr(
"Cannot start filter synthesis program!"));
643 if(!QucsLine->start()) {
644 QMessageBox::critical(
this, tr(
"Error"),
645 tr(
"Cannot start line calculation program!"));
658 QProcess *QucsLibrary =
660 if(!QucsLibrary->start()) {
661 QMessageBox::critical(
this, tr(
"Error"),
662 tr(
"Cannot start library program!"));
685 if(!QucsAtt->start()) {
686 QMessageBox::critical(
this, tr(
"Error"),
687 tr(
"Cannot start attenuator calculation program!"));
699 showHTML(
"index.html");
705 showHTML(
"start.html");
709 void QucsApp::showHTML(
const QString& Page)
713 QProcess *
QucsHelp =
new QProcess(com);
714 QucsHelp->setCommunication(0);
715 if(!QucsHelp->start()) {
716 QMessageBox::critical(
this, tr(
"Error"), tr(
"Cannot start qucshelp!"));
743 if(Doc->inherits(
"QTextEdit")) {
744 ((
TextDoc*)Doc)->viewport()->setFocus();
749 if(d->exec() == QDialog::Accepted) {
750 ((
Schematic*)Doc)->setChanged(
true,
true);
762 QMessageBox::critical(
this, tr(
"Error"), tr(
"No project open!"));
767 QStringList List = QFileDialog::getOpenFileNames(
769 this, 0, tr(
"Select files to copy"));
772 statusBar()->message(tr(
"No files copied."), 2000);
777 char *Buffer = (
char*)malloc(0x10000);
781 QStringList::Iterator it = FileList.begin();
787 QFile origFile, destFile;
788 while(it != FileList.end()) {
790 origFile.setName(*it);
792 QDir::separator() + Info.fileName());
794 if(!origFile.open(IO_ReadOnly)) {
795 QMessageBox::critical(
this, tr(
"Error"), tr(
"Cannot open \"%1\" !").
arg(*it));
800 if(destFile.exists())
801 if(QMessageBox::information(
this, tr(
"Overwrite"),
802 tr(
"File \"%1\" already exists.\nOverwrite ?").
arg(*it), QMessageBox::Yes,
803 QMessageBox::No|QMessageBox::Default|QMessageBox::Escape)
804 != QMessageBox::Yes) {
810 if(!destFile.open(IO_WriteOnly)) {
811 QMessageBox::critical(
this, tr(
"Error"), tr(
"Cannot create \"%1\" !").
arg(*it));
819 Num = origFile.readBlock(Buffer, 0x10000);
821 QMessageBox::critical(
this, tr(
"Error"), tr(
"Cannot read \"%1\" !").
arg(*it));
824 Num = destFile.writeBlock(Buffer, Num);
826 QMessageBox::critical(
this, tr(
"Error"), tr(
"Cannot write \"%1\" !").
arg(*it));
829 }
while(Num == 0x10000);
838 statusBar()->message(tr(
"Ready."));
842 void QucsApp::slotCursorLeft()
846 QPtrList<Element> movingElements;
850 if((movingElements.count() - markerCount) < 1) {
851 if(markerCount > 0) {
853 movingElements.clear();
856 if(Doc->
scrollLeft(Doc->horizontalScrollBar()->lineStep()))
857 Doc->scrollBy(-Doc->horizontalScrollBar()->lineStep(), 0);
860 Doc->viewport()->update();
871 void QucsApp::slotCursorRight()
875 QPtrList<Element> movingElements;
879 if((movingElements.count() - markerCount) < 1) {
880 if(markerCount > 0) {
882 movingElements.clear();
885 if(Doc->
scrollRight(-Doc->horizontalScrollBar()->lineStep()))
886 Doc->scrollBy(Doc->horizontalScrollBar()->lineStep(), 0);
889 Doc->viewport()->update();
900 void QucsApp::slotCursorUp()
906 int Begin = pp->Description.find(
'[');
907 if(Begin < 0)
return;
910 End = pp->Description.findRev(
',', End);
911 if(End < Begin)
return;
913 int Pos = pp->Description.findRev(
',', End);
914 if(Pos < Begin) Pos =
Begin;
916 if(pp->Description.at(Pos) ==
' ') Pos++;
917 editText->setText(pp->Description.mid(Pos, End-Pos+1));
922 QPtrList<Element> movingElements;
926 if((movingElements.count() - markerCount) < 1) {
927 if(markerCount > 0) {
929 movingElements.clear();
932 if(Doc->
scrollUp(Doc->verticalScrollBar()->lineStep()))
933 Doc->scrollBy(0, -Doc->verticalScrollBar()->lineStep());
936 Doc->viewport()->update();
947 void QucsApp::slotCursorDown()
953 int Pos = pp->Description.find(
'[');
955 Pos = pp->Description.find(
editText->text(), Pos);
957 Pos = pp->Description.find(
',', Pos);
960 if(pp->Description.at(Pos) ==
' ') Pos++;
961 int End = pp->Description.find(
',', Pos);
963 End = pp->Description.find(
']', Pos);
966 editText->setText(pp->Description.mid(Pos, End-Pos));
971 QPtrList<Element> movingElements;
975 if((movingElements.count() - markerCount) < 1) {
976 if(markerCount > 0) {
978 movingElements.clear();
981 if(Doc->
scrollDown(-Doc->verticalScrollBar()->lineStep()))
982 Doc->scrollBy(0, Doc->verticalScrollBar()->lineStep());
985 Doc->viewport()->update();
1004 f.setPointSizeFloat( Doc->
Scale *
float(f.pointSize()) );
1014 pp = pc->
Props.first();
1021 pp = pc->
Props.next();
1055 Doc->viewport()->update();
1066 pp = pc->
Props.next();
1097 z =
editText->fontMetrics().lineSpacing();
1109 void QucsApp::slotResizePropEdit(
const QString&
t)
1112 editText->fontMetrics().lineSpacing());
1116 void QucsApp::slotCreateLib()
1121 QMessageBox::critical(
this, tr(
"Error"), tr(
"Please open project with subcircuits!"));
1129 void QucsApp::slotImportData()
1134 QMessageBox::critical(
this, tr(
"Error"), tr(
"Please open project first!"));
1139 if(d->exec() == QDialog::Accepted)
1144 void QucsApp::slotExportGraphAsCsv()
1153 QMessageBox::critical(
this, tr(
"Error"), tr(
"Please select a diagram graph!"));
1157 QString
s = QFileDialog::getSaveFileName(
1159 tr(
"CSV file")+
" (*.csv);;" + tr(
"Any File")+
" (*)",
1160 this, 0, tr(
"Enter an Output File Name"));
1166 if(Info.extension().isEmpty())
1171 if(QMessageBox::information(
this, tr(
"Info"),
1172 tr(
"Output file already exists!")+
"\n"+tr(
"Overwrite it?"),
1173 tr(
"&Yes"), tr(
"&No"), 0,1,1))
1176 if(!
File.open(IO_WriteOnly)) {
1177 QMessageBox::critical(
this, QObject::tr(
"Error"),
1178 QObject::tr(
"Cannot create output file!"));
1182 QTextStream Stream(&
File);
1189 Stream <<
'\"' << pD->
Var <<
"\";";
1190 Stream <<
"\"r " << g->
Var <<
"\";\"i " << g->
Var <<
"\"\n";
1196 for(n = 0; n < Count; n++) {
1203 Stream << *(py) <<
';' << *(py+1) <<
'\n';
1211 void QucsApp::slotCreatePackage()
1220 void QucsApp::slotExtractPackage()