26 #include <qsplitter.h>
30 #include <qmessagebox.h>
33 #include <qfiledialog.h>
34 #include <qinputdialog.h>
35 #include <qapplication.h>
36 #include <qclipboard.h>
38 #include <qtextedit.h>
39 #include <qcheckbox.h>
41 #include <qtabwidget.h>
42 #include <qcombobox.h>
43 #include <qiconview.h>
44 #include <qpushbutton.h>
45 #include <qlistview.h>
48 #include <qfiledialog.h>
50 #include <qtoolbutton.h>
51 #include <qstatusbar.h>
53 #include <qpopupmenu.h>
56 #include <qlineedit.h>
57 #include <qstringlist.h>
58 #include <qdragobject.h>
59 #include <qsyntaxhighlighter.h>
70 #include "components/components.h"
98 myIconView(QWidget* parent_) : QIconView(parent_, 0, 0) {};
103 QIconViewItem *Item = currentItem();
107 QIconDrag *DragPic =
new QIconDrag( viewport() );
108 DragPic->setPixmap( QPixmap(
empty_xpm), QPoint(0, 0) );
109 DragPic->append( QIconDragItem(),
110 QRect( Item->pixmapRect().width() / -2,
111 Item->pixmapRect().height() / -2,
112 Item->pixmapRect().width(), Item->pixmapRect().height() ),
113 QRect( Item->textRect().width() / -2,
114 Item->pixmapRect().height() / 2 + 5,
115 Item->textRect().width(), Item->textRect().height() ) );
124 setCaption(
"Qucs " PACKAGE_VERSION);
127 tr(
"Schematic")+
" (*.sch);;"+
128 tr(
"Data Display")+
" (*.dpl);;"+
129 tr(
"Qucs Documents")+
" (*.sch *.dpl);;"+
130 tr(
"VHDL Sources")+
" (*.vhdl *.vhd);;"+
131 tr(
"Verilog Sources")+
" (*.v);;"+
132 tr(
"Verilog-A Sources")+
" (*.va);;"+
133 tr(
"Octave Scripts")+
" (*.m *.oct);;"+
134 tr(
"Any File")+
" (*)";
135 QucsWorkDir.setPath(QDir::homeDirPath()+QDir::convertSeparators (
"/.qucs"));
136 QucsHomeDir.setPath(QDir::homeDirPath()+QDir::convertSeparators (
"/.qucs"));
151 viewToolBar->setOn(
true);
152 viewStatusBar->setOn(
true);
153 viewBrowseDock->setOn(
true);
154 slotViewOctaveDock(
false);
156 HierarchyHistory.setAutoDelete(
true);
160 Printer =
new QPrinter(QPrinter::HighResolution);
161 #if defined (QT_VERSION) && QT_VERSION > 0x030200
162 Printer->setOptionEnabled(QPrinter::PrintSelection,
true);
163 Printer->setOptionEnabled(QPrinter::PrintPageRange,
false);
164 Printer->setOptionEnabled(QPrinter::PrintToFile,
true);
166 Printer->setColorMode(QPrinter::Color);
167 Printer->setFullPage(
true);
175 switchSchematicDoc(
true);
178 for(
int z=1; z<qApp->argc(); z++) {
179 QString
arg = qApp->argv()[z];
182 if(arg.contains(
":/")) {
183 QString f = QDir::convertSeparators(QUriDrag::uriToLocalFile(arg));
184 if(f.isEmpty()) f = arg;
205 void QucsApp::initContentListView()
208 ConOthers =
new QListViewItem(Content, tr(
"Others"));
209 ConDatasets =
new QListViewItem(Content, tr(
"Datasets"));
210 ConDisplays =
new QListViewItem(Content, tr(
"Data Displays"));
211 ConOctave =
new QListViewItem(Content, tr(
"Octave"));
212 ConVerilog =
new QListViewItem(Content, tr(
"Verilog"));
213 ConVerilogA =
new QListViewItem(Content, tr(
"Verilog-A"));
214 ConSources =
new QListViewItem(Content, tr(
"VHDL"));
215 ConSchematics =
new QListViewItem(Content, tr(
"Schematics"));
218 void QucsApp::initView()
226 SIGNAL(currentChanged(QWidget*)), SLOT(slotChangeView(QWidget*)));
232 connect(dock, SIGNAL(visibilityChanged(
bool)), SLOT(slotToggleDock(
bool)));
241 connect(
editText, SIGNAL(textChanged(
const QString&)),
242 SLOT(slotResizePropEdit(
const QString&)));
243 connect(
editText, SIGNAL(lostFocus()), SLOT(slotHideEdit()));
247 QVBox *ProjGroup =
new QVBox(
this);
248 QHBox *ProjButts =
new QHBox(ProjGroup);
249 QPushButton *ProjNew =
new QPushButton(tr(
"New"),ProjButts);
250 connect(ProjNew, SIGNAL(clicked()), SLOT(slotProjNewButt()));
251 QPushButton *ProjOpen =
new QPushButton(tr(
"Open"),ProjButts);
252 connect(ProjOpen, SIGNAL(clicked()), SLOT(slotProjOpenButt()));
253 QPushButton *ProjDel =
new QPushButton(tr(
"Delete"),ProjButts);
254 connect(ProjDel, SIGNAL(clicked()), SLOT(slotProjDelButt()));
256 Projects =
new QListBox(ProjGroup);
257 TabView->
addPage(ProjGroup, tr(
"Projects"));
259 tr(
"content of project directory"));
261 connect(Projects, SIGNAL(doubleClicked(QListBoxItem*)),
262 SLOT(slotOpenProject(QListBoxItem*)));
266 Content =
new QListView(
this);
267 Content->setRootIsDecorated(
true);
268 Content->setSorting(-1);
269 Content->addColumn(tr(
"Content of"));
270 Content->addColumn(tr(
"Note"));
271 Content->setColumnWidthMode(0,QListView::Manual);
272 Content->setColumnWidth(0, 150);
274 initContentListView();
275 TabView->
addPage(Content,tr(
"Content"));
276 TabView->
setTabToolTip(TabView->
id(Content), tr(
"content of current project"));
278 connect(Content, SIGNAL(doubleClicked(QListViewItem*)),
279 SLOT(slotOpenContent(QListViewItem*)));
280 connect(Content, SIGNAL(clicked(QListViewItem*)),
281 SLOT(slotSelectSubcircuit(QListViewItem*)));
282 connect(Content, SIGNAL(expanded(QListViewItem*)),
283 SLOT(slotExpandContentList(QListViewItem*)));
287 QVBox *CompGroup =
new QVBox(
this);
288 CompChoose =
new QComboBox(CompGroup);
290 TabView->
addPage(CompGroup,tr(
"Components"));
291 TabView->
setTabToolTip(TabView->
id(CompGroup), tr(
"components and diagrams"));
295 connect(CompChoose, SIGNAL(activated(
int)), SLOT(slotSetCompView(
int)));
296 connect(
CompComps, SIGNAL(clicked(QIconViewItem*)),
299 setDockEnabled(dock,DockTop,
false);
300 setDockEnabled(dock,DockBottom,
false);
301 moveDockWindow(dock,DockLeft);
306 octDock =
new QDockWindow(QDockWindow::InDock,
this);
307 octDock->setCloseMode(QDockWindow::Always);
308 connect(octDock, SIGNAL(visibilityChanged(
bool)), SLOT(slotToggleOctave(
bool)));
310 moveDockWindow(octDock, Qt::DockBottom);
328 if(isTextDocument (w))
343 File = QDir::convertSeparators (File);
344 while ((d =
getDoc (No++)) != 0)
345 if (QDir::convertSeparators (d->
DocName) == File) {
346 if (Pos) *Pos = No - 1;
355 void QucsApp::fillComboBox (
bool setAll)
357 CompChoose->setSizeLimit (11);
358 CompChoose->clear ();
361 for (QStringList::Iterator it = cats.begin (); it != cats.end (); ++it) {
362 if (*it != QObject::tr(
"paintings")) {
363 if (setAll) CompChoose->insertItem (*it);
365 else CompChoose->insertItem (*it);
372 void QucsApp::slotSetCompView (
int index)
376 QPtrList<Module> Comps;
378 if (CompChoose->count () <= 0)
return;
379 QString item = CompChoose->text (index);
380 if ((index + 1) >= CompChoose->count ())
388 for (Mod = Comps.first(); Mod; Mod = Comps.next ()) {
390 *(Mod->
info) (Name, File,
false);
413 ((QScrollView*)
DocumentTab->currentPage())->viewport()->update();
431 QPtrList<Module> Comps;
432 if((CompChoose->currentItem()+1) >= CompChoose->count())
437 Infos = Comps.at(i)->info;
450 void QucsApp::initCursorMenu()
459 SIGNAL(contextMenuRequested(QListViewItem*,
const QPoint&,
int)),
468 if(item->parent() != 0) {
469 if(item->parent()->nextSibling())
480 QListViewItem *Item = Content->selectedItem();
481 if(Item == 0)
return;
483 slotOpenContent(Item);
489 QListViewItem *Item = Content->selectedItem();
492 QString Name = Item->text(0);
494 QMessageBox::critical(
this, tr(
"Error"),
495 tr(
"Cannot rename an open file!"));
499 QString Suffix = Name.section(
'.',-1);
500 QString
Base = Name.section(
'.',0,-2);
501 if(Base.isEmpty()) Base = Name;
504 QString
s = QInputDialog::getText(tr(
"Rename file"), tr(
"Enter new name:"),
505 QLineEdit::Normal, Base, &ok,
this);
507 if(s.isEmpty())
return;
513 NewName = s+
"."+Suffix;
515 if(!file.rename(Name, NewName)) {
516 QMessageBox::critical(
this, tr(
"Error"), tr(
"Cannot rename file: ")+Name);
519 Item->setText(0, NewName);
525 QListViewItem *item = Content->selectedItem();
526 if(item == 0)
return;
527 QString FileName =
QucsWorkDir.filePath(item->text(0));
530 QMessageBox::critical(
this, tr(
"Error"),
531 tr(
"Cannot delete an open file!"));
536 No = QMessageBox::warning(
this, tr(
"Warning"),
537 tr(
"This will delete the file permanently! Continue ?"),
538 tr(
"No"), tr(
"Yes"));
541 if(!QFile::remove(FileName)) {
542 QMessageBox::critical(
this, tr(
"Error"),
543 tr(
"Cannot delete schematic: ")+item->text(0));
547 item->parent()->takeItem(item);
554 QString Type = tr(
"unknown");
556 Type = tr(
"Verilog source");
557 else if (Ext ==
"va")
558 Type = tr(
"Verilog-A source");
559 else if (Ext ==
"vhd" || Ext ==
"vhdl")
560 Type = tr(
"VHDL source");
561 else if (Ext ==
"dat")
562 Type = tr(
"data file");
563 else if (Ext ==
"dpl")
564 Type = tr(
"data display");
565 else if (Ext ==
"sch")
566 Type = tr(
"schematic");
567 else if (Ext ==
"sym")
569 else if (Ext ==
"vhdl.cfg" || Ext ==
"vhdl.cfg")
570 Type = tr(
"VHDL configuration");
571 else if (Ext ==
"cfg")
572 Type = tr(
"configuration");
580 QListViewItem * item = Content->selectedItem ();
583 QString
s = item->text (0);
586 const char * extensions[] =
587 {
"sch",
"dpl",
"dat",
"vhdl",
"vhd",
"v",
"sym",
588 "vhdl.cfg",
"vhd.cfg",
"va", 0 };
591 for (i = 0; extensions[
i] != 0; i++) {
592 QString Short = s +
"." + extensions[
i];
596 QMessageBox::critical(
this, tr(
"Error"),
597 tr(
"Cannot delete the open file \"%1\"!").
arg(Short));
604 for (i = 0; extensions[
i] != 0; i++) {
605 QString Short = s +
"." + extensions[
i];
607 bool exists = QFile::exists (Long);
612 No = QMessageBox::warning (
this, tr(
"Warning"),
613 tr(
"This will delete the files%1permanently! Continue ?").
arg(Str),
614 tr(
"No"), tr(
"Yes"));
619 for (i = 0; extensions[
i] != 0; i++) {
620 QString Short = s +
"." + extensions[
i];
622 bool exists = QFile::exists (Name);
625 if (!QFile::remove (Name)) {
626 QMessageBox::critical(
this, tr(
"Error"),
627 tr(
"Cannot delete %1: \"%2\"!").
arg(
fileType (extensions[i])).
632 item = Content->findItem (Short, 0);
634 item->parent()->takeItem (item);
647 void QucsApp::readProjects()
649 QDir ProjDir(QDir::homeDirPath());
650 if(!ProjDir.cd(
".qucs")) {
651 if(!ProjDir.mkdir(
".qucs")) {
652 QMessageBox::warning(
this, tr(
"Warning"),
653 tr(
"Cannot create work directory !"));
660 QStringList PrDirs = ProjDir.entryList(
"*", QDir::Dirs, QDir::Name);
665 QStringList::iterator it;
667 for(it = PrDirs.begin(); it != PrDirs.end(); it++)
668 if ((*it).right(4) ==
"_prj") {
669 (*it) = (*it).left((*it).length()-4);
670 Projects->insertItem(*it);
676 void QucsApp::slotProjNewButt()
681 if(d->exec() != QDialog::Accepted)
return;
684 if(projDir.mkdir(d->
ProjName->text()+
"_prj")) {
685 Projects->insertItem(d->
ProjName->text(),0);
687 slotOpenProject(Projects->firstItem());
689 else QMessageBox::information(
this, tr(
"Info"),
690 tr(
"Cannot create project directory !"));
699 if(!file.open(IO_ReadOnly)) {
707 QTextStream ReadWhole(&file);
708 QString FileString = ReadWhole.read();
710 QTextStream stream(&FileString, IO_ReadOnly);
719 Line = stream.readLine();
720 Line = Line.stripWhiteSpace();
721 }
while(Line.isEmpty());
723 if(Line.left(16) !=
"<Qucs Schematic ") {
728 Line = Line.mid(16, Line.length()-17);
735 while(!stream.atEnd()) {
736 Line = stream.readLine();
737 if(Line ==
"<Components>")
break;
741 while(!stream.atEnd()) {
742 Line = stream.readLine();
743 if(Line ==
"</Components>") {
748 Line = Line.stripWhiteSpace();
749 QString
s = Line.section(
' ',0,0);
750 if(s ==
"<Port") z++;
758 void QucsApp::readProjectFiles()
761 while(ConSchematics->firstChild())
762 delete ConSchematics->firstChild();
763 while(ConDisplays->firstChild())
764 delete ConDisplays->firstChild();
765 while(ConDatasets->firstChild())
766 delete ConDatasets->firstChild();
767 while(ConSources->firstChild())
768 delete ConSources->firstChild();
769 while(ConVerilog->firstChild())
770 delete ConVerilog->firstChild();
771 while(ConVerilogA->firstChild())
772 delete ConVerilogA->firstChild();
773 while(ConOthers->firstChild())
774 delete ConOthers->firstChild();
775 while(ConOctave->firstChild())
776 delete ConOctave->firstChild();
780 QStringList Elements =
QucsWorkDir.entryList(
"*", QDir::Files, QDir::Name);
781 QStringList::iterator it;
783 for(it = Elements.begin(); it != Elements.end(); ++it) {
789 new QListViewItem(ConSchematics, (*it).ascii(),
790 QString::number(n)+tr(
"-port"));
791 else new QListViewItem(ConSchematics, (*it).ascii());
794 else if(Str ==
"dpl")
795 new QListViewItem(ConDisplays, (*it).ascii());
796 else if(Str ==
"dat")
797 new QListViewItem(ConDatasets, (*it).ascii());
798 else if((Str ==
"vhdl") || (Str ==
"vhd"))
799 new QListViewItem(ConSources, (*it).ascii());
801 new QListViewItem(ConVerilog, (*it).ascii());
803 new QListViewItem(ConVerilogA, (*it).ascii());
804 else if((Str ==
"m") || (Str ==
"oct"))
805 new QListViewItem(ConOctave, (*it).ascii());
807 new QListViewItem(ConOthers, (*it).ascii());
813 void QucsApp::openProject(
const QString& Path,
const QString& Name)
823 QDir ProjDir(QDir::cleanDirPath(Path));
824 if(!ProjDir.exists() || !ProjDir.isReadable()) {
825 QMessageBox::critical(
this, tr(
"Error"),
826 tr(
"Cannot access project directory: ")+Path);
832 Content->setColumnText(0,tr(
"Content of '")+Name+tr(
"'"));
833 ConSchematics->setOpen(
false);
834 ConSchematics->setOpen(
true);
840 setCaption(
"Qucs " PACKAGE_VERSION + tr(
" - Project: ")+Name);
845 void QucsApp::slotMenuOpenProject()
847 QFileDialog *d =
new QFileDialog(
QucsHomeDir.path());
848 d->setCaption(tr(
"Choose Project Directory for Opening"));
849 d->setShowHiddenFiles(
true);
850 d->setMode(QFileDialog::DirectoryOnly);
851 if(d->exec() != QDialog::Accepted)
return;
853 QString
s = d->selectedFile();
854 if(s.isEmpty())
return;
856 s = s.left(s.length()-1);
857 int i = s.findRev(
'/');
858 if(i > 0) s = s.mid(i+1);
860 openProject(d->selectedFile(),
s);
865 void QucsApp::slotProjOpenButt()
869 QListBoxItem *item = Projects->selectedItem();
870 if(item) slotOpenProject(item);
871 else QMessageBox::information(
this, tr(
"Info"),
872 tr(
"No project is selected !"));
877 void QucsApp::slotOpenProject(QListBoxItem *item)
879 openProject(
QucsHomeDir.filePath(item->text()+
"_prj"), item->text());
884 void QucsApp::slotMenuCloseProject()
893 setCaption(
"Qucs " PACKAGE_VERSION + tr(
" - Project: "));
894 QucsWorkDir.setPath(QDir::homeDirPath()+QDir::convertSeparators (
"/.qucs"));
897 Content->setColumnText(0,tr(
"Content of"));
898 initContentListView();
905 bool QucsApp::deleteDirectoryContent(QDir& Dir)
908 QStringList Files = Dir.entryList(
"*", QDir::Files);
909 QStringList::iterator it;
910 for(it = Files.begin(); it != Files.end(); it++) {
911 if(!Dir.remove(*it)) {
912 QMessageBox::information(
this, tr(
"Info"),
913 tr(
"Cannot delete file: ")+(*it));
920 Files = Dir.entryList(
"*", QDir::Dirs);
923 for(it = Files.begin(); it != Files.end(); it++) {
925 if(!deleteDirectoryContent(myDir))
928 if(!myDir.rmdir(*it)) {
929 QMessageBox::information(
this, tr(
"Info"),
930 tr(
"Cannot remove directory: ")+(*it));
938 bool QucsApp::deleteProject(
const QString& Path,
const QString& Name)
943 QMessageBox::information(
this, tr(
"Info"),
944 tr(
"Cannot delete an open project !"));
949 if(QMessageBox::warning(
this, tr(
"Warning"),
950 tr(
"This will destroy all the project files permanently ! Continue ?"),
951 tr(
"&Yes"), tr(
"&No"), 0,1,1))
return false;
953 QDir projDir = QDir(Path);
954 if(!deleteDirectoryContent(projDir))
958 if(!projDir.rmdir(Name+
"_prj")) {
959 QMessageBox::information(
this, tr(
"Info"),
960 tr(
"Cannot remove project directory !"));
969 void QucsApp::slotMenuDelProject()
971 QFileDialog *d =
new QFileDialog(
QucsHomeDir.path());
972 d->setCaption(tr(
"Choose Project Directory for Deleting"));
973 d->setShowHiddenFiles(
true);
974 d->setMode(QFileDialog::DirectoryOnly);
975 if(d->exec() != QDialog::Accepted)
return;
977 QString s = d->selectedFile();
978 if(s.isEmpty())
return;
980 s = s.left(s.length()-1);
981 int i = s.findRev(
'/');
982 if(i > 0) s = s.mid(i+1);
983 s = s.left(s.length()-4);
984 deleteProject(d->selectedFile(),
s);
990 void QucsApp::slotProjDelButt()
992 QListBoxItem *item = Projects->selectedItem();
994 QMessageBox::information(
this, tr(
"Info"),
995 tr(
"No project is selected !"));
999 if(!deleteProject(
QucsHomeDir.filePath(item->text()+
"_prj"),
1000 item->text()))
return;
1001 Projects->removeItem(Projects->currentItem());
1012 statusBar()->message(tr(
"Creating new schematic..."));
1017 statusBar()->message(tr(
"Ready."));
1023 statusBar()->message(tr(
"Creating new text editor..."));
1028 statusBar()->message(tr(
"Ready."));
1047 QFileInfo Info(Name);
1048 if(Info.extension(
false) ==
"sch" || Info.extension(
false) ==
"dpl" ||
1049 Info.extension(
false) ==
"sym")
1078 statusBar()->message(tr(
"Opening file..."));
1080 QString s = QFileDialog::getOpenFileName(
1082 QucsFileFilter,
this, 0, tr(
"Enter a Schematic Name"));
1085 statusBar()->message(tr(
"Opening aborted"), 2000);
1088 lastDirOpenSave =
s;
1089 statusBar()->message(tr(
"Ready."));
1094 bool QucsApp::saveFile(
QucsDoc *Doc)
1102 int Result = Doc->
save();
1103 if(Result < 0)
return false;
1105 updatePortNumber(Doc, Result);
1112 statusBar()->message(tr(
"Saving file..."));
1118 statusBar()->message(tr(
"Saving aborted"), 2000);
1119 statusBar()->message(tr(
"Ready."));
1124 statusBar()->message(tr(
"Ready."));
1128 bool QucsApp::saveAs()
1134 bool intoView =
true;
1143 if(lastDirOpenSave.isEmpty()) s = QDir::currentDirPath();
1150 QString ext =
"vhdl;vhd;v;va;sch;dpl;m;oct";
1151 QStringList extlist = QStringList::split (
';', ext);
1153 if(isTextDocument (w))
1154 Filter = tr(
"VHDL Sources")+
" (*.vhdl *.vhd);;" +
1155 tr(
"Verilog Sources")+
" (*.v);;"+
1156 tr(
"Verilog-A Sources")+
" (*.va);;"+
1157 tr(
"Octave Scripts")+
" (*.m *.oct);;"+
1158 tr(
"Any File")+
" (*)";
1160 Filter = QucsFileFilter;
1161 s = QFileDialog::getSaveFileName(s, Filter,
1162 this,
"", tr(
"Enter a Document Name"));
1163 if(s.isEmpty())
return false;
1165 ext = Info.extension(
false);
1167 !extlist.contains(ext)) {
1168 if(isTextDocument (w))
1175 if(QFile::exists(s)) {
1176 n = QMessageBox::warning(
this, tr(
"Warning"),
1177 tr(
"The file '")+Info.fileName()+tr(
"' already exists!\n")+
1178 tr(
"Saving will overwrite the old one! Continue?"),
1179 tr(
"No"), tr(
"Yes"), tr(
"Cancel"));
1180 if(n == 2)
return false;
1181 if(n == 0)
continue;
1188 QMessageBox::information(
this, tr(
"Info"),
1189 tr(
"Cannot overwrite an open document"));
1196 lastDirOpenSave = Info.dirPath(
true);
1201 s = Info.fileName();
1202 QString ext = Info.extension (
false);
1204 Content->setSelected(
new QListViewItem(ConSchematics, s),
true);
1205 else if(ext ==
"dpl")
1206 Content->setSelected(
new QListViewItem(ConDisplays, s),
true);
1207 else if(ext ==
"dat")
1208 Content->setSelected(
new QListViewItem(ConDatasets, s),
true);
1209 else if((ext ==
"vhdl") || (ext ==
"vhd"))
1210 Content->setSelected(
new QListViewItem(ConSources, s),
true);
1212 Content->setSelected(
new QListViewItem(ConVerilog, s),
true);
1213 else if(ext ==
"va")
1214 Content->setSelected(
new QListViewItem(ConVerilogA, s),
true);
1215 else if(ext ==
"m" || ext ==
"oct")
1216 Content->setSelected(
new QListViewItem(ConOctave, s),
true);
1218 Content->setSelected(
new QListViewItem(ConOthers, s),
true);
1223 if(n < 0)
return false;
1225 updatePortNumber(Doc, n);
1232 statusBar()->message(tr(
"Saving file under new filename..."));
1238 statusBar()->message(tr(
"Saving aborted"), 3000);
1239 statusBar()->message(tr(
"Ready."));
1244 statusBar()->message(tr(
"Ready."));
1251 statusBar()->message(tr(
"Saving all files..."));
1257 while((Doc=
getDoc(No++)) != 0) {
1265 ((QScrollView*)
DocumentTab->currentPage())->viewport()->update();
1267 statusBar()->message(tr(
"Ready."));
1273 statusBar()->message(tr(
"Closing file..."));
1278 switch(QMessageBox::warning(
this,tr(
"Closing Qucs document"),
1279 tr(
"The document contains unsaved changes!\n")+
1280 tr(
"Do you want to save the changes before closing?"),
1281 tr(
"&Save"), tr(
"&Discard"), tr(
"Cancel"), 0, 2)) {
1293 statusBar()->message(tr(
"Ready."));
1308 Result = sd->exec();
1315 while((doc =
getDoc()) != 0)
1318 switchEditMode(
true);
1324 void QucsApp::slotChangeView(QWidget *w)
1331 if (isTextDocument (w)) {
1335 if(mainAccel->isEnabled())
1336 switchSchematicDoc (
false);
1343 if(mainAccel->isEnabled()) {
1345 if((CompChoose->count() > 1) == d->
symbolMode)
1346 changeSchematicSymbolMode (d);
1349 switchSchematicDoc(
true);
1350 changeSchematicSymbolMode(d);
1357 if(!HierarchyHistory.isEmpty())
1358 if(*(HierarchyHistory.getLast()) !=
"*") {
1359 HierarchyHistory.clear();
1360 popH->setEnabled(
false);
1366 void QucsApp::slotNextTab()
1383 if (isTextDocument (w)) {
1387 if (ext ==
"m" || ext ==
"oct") {
1390 else if (ext ==
"va") {
1420 void QucsApp::updatePortNumber(
QucsDoc *currDoc,
int No)
1424 QString pathName = currDoc->
DocName;
1426 QFileInfo Info (pathName);
1427 QString Model,
File, Name = Info.fileName();
1434 for(p = ConSchematics->firstChild(); p!=0; p = p->nextSibling()) {
1435 if(p->text(0) == Name) {
1436 if(No == 0) p->setText(1,
"");
1437 else p->setText(1,QString::number(No)+tr(
"-port"));
1442 else if (ext ==
"vhdl" || ext ==
"vhd") {
1445 else if (ext ==
"v") {
1454 if(isTextDocument (w))
continue;
1459 if(pc->Model == Model) {
1460 File = pc->Props.getFirst()->Value;
1461 if((File == pathName) || (File == Name)) {
1477 void QucsApp::printCurrentDocument(
bool fitToPage)
1479 statusBar()->message(tr(
"Printing..."));
1483 Printer->setOrientation(QPrinter::Portrait);
1485 Printer->setOrientation(QPrinter::Landscape);
1489 if(Printer->setup(
this)) {
1491 QPainter Painter(Printer);
1492 if(!Painter.device())
1495 for(
int z=Printer->numCopies(); z>0 ; z--) {
1496 if(Printer->aborted())
1500 Printer->printRange() == QPrinter::AllPages, fitToPage);
1502 if(!Printer->newPage())
1507 statusBar()->message(tr(
"Ready."));
1511 statusBar()->message(tr(
"Printer Error."));
1517 printCurrentDocument(
false);
1524 printCurrentDocument(
true);
1531 statusBar()->message(tr(
"Exiting application..."));
1534 int exit = QMessageBox::information(
this,
1535 tr(
"Quit..."), tr(
"Do you really want to quit?"),
1536 tr(
"Yes"), tr(
"No"));
1544 statusBar()->message(tr(
"Ready."));
1563 statusBar()->message(tr(
"Cutting selection..."));
1566 if(isTextDocument (Doc)) {
1567 ((
TextDoc*)Doc)->viewport()->setFocus();
1573 QClipboard *cb = QApplication::clipboard();
1577 cb->setText(s, QClipboard::Clipboard);
1578 Doc->viewport()->update();
1581 statusBar()->message(tr(
"Ready."));
1587 statusBar()->message(tr(
"Copying selection to clipboard..."));
1590 if(isTextDocument (Doc)) {
1591 ((
TextDoc*)Doc)->viewport()->setFocus();
1597 QClipboard *cb = QApplication::clipboard();
1601 cb->setText(s, QClipboard::Clipboard);
1603 statusBar()->message(tr(
"Ready."));
1616 QString *ps =
new QString(
"*");
1617 HierarchyHistory.append(ps);
1621 HierarchyHistory.remove();
1625 *(HierarchyHistory.getLast()) = Doc->
DocName;
1626 popH->setEnabled(
true);
1635 if(HierarchyHistory.count() == 0)
return;
1637 QString Doc = *(HierarchyHistory.getLast());
1638 *(HierarchyHistory.last()) =
"*";
1641 *(HierarchyHistory.getLast()) = Doc;
1645 HierarchyHistory.remove();
1646 if(HierarchyHistory.count() == 0)
1647 popH->setEnabled(
false);
1674 void QucsApp::slotSimulate()
1680 if(isTextDocument (w)) {
1684 if(d->exec() == QDialog::Rejected)
1692 if(!saveAs())
return;
1697 if(Doc->
lastSaved < Info.lastModified()) {
1698 int No = QMessageBox::warning(
this, tr(
"Warning"),
1699 tr(
"The document was modified by another program !") +
'\n' +
1700 tr(
"Do you want to reload or keep this version ?"),
1701 tr(
"Reload"), tr(
"Keep it"));
1709 if(Info.extension(
false) ==
"m" || Info.extension(
false) ==
"oct") {
1713 slotViewOctaveDock(
true);
1721 connect(sim, SIGNAL(SimulationEnded(
int,
SimMessage*)),
this,
1722 SLOT(slotAfterSimulation(
int,
SimMessage*)));
1723 connect(sim, SIGNAL(displayDataPage(QString&, QString&)),
1724 this, SLOT(slotChangePage(QString&, QString&)));
1735 void QucsApp::slotAfterSimulation(
int Status,
SimMessage *sim)
1737 if(Status != 0)
return;
1773 if(w)
if(!isTextDocument (sim->
DocWidget))
1788 void QucsApp::slotDCbias()
1796 void QucsApp::slotChangePage(QString& DocName, QString& DataDisplay)
1798 if(DataDisplay.isEmpty())
return;
1800 QFileInfo Info(DocName);
1801 QString Name = Info.dirPath() + QDir::separator() + DataDisplay;
1812 if (ext !=
"vhd" && ext !=
"vhdl" && ext !=
"v" && ext !=
"va" &&
1813 ext !=
"oct" && ext !=
"m")
1819 if(file.open(IO_ReadOnly)) {
1828 if(file.open(IO_ReadWrite)) {
1829 new QListViewItem(ConDisplays, DataDisplay);
1833 QMessageBox::critical(
this, tr(
"Error"), tr(
"Cannot create ")+Name);
1844 if(!isTextDocument (w))
1848 if (Name.right(4) ==
".dpl") {
1850 CompChoose->setCurrentItem (i);
1851 slotSetCompView (i);
1861 QMessageBox::critical(
this, tr(
"Error"), tr(
"No page set !"));
1865 if(d->
DocName.right(2) ==
".m" ||
1866 d->
DocName.right(4) ==
".oct")
1867 slotViewOctaveDock(
true);
1874 void QucsApp::slotOpenContent(QListViewItem *item)
1878 if(item == 0)
return;
1879 if(item->parent() == 0)
return;
1891 QFileInfo Info(
QucsWorkDir.filePath(item->text(0)));
1892 QString Suffix = Info.extension(
false);
1894 if (Suffix ==
"sch" || Suffix ==
"dpl" || Suffix ==
"vhdl" ||
1895 Suffix ==
"v" || Suffix ==
"va" ||
1896 Suffix ==
"m" || Suffix ==
"oct") {
1899 if(item->text(1).isEmpty())
1900 if(Suffix ==
"sch")
return;
1902 select->blockSignals(
true);
1904 select->blockSignals(
false);
1914 if(Suffix ==
"dat") {
1925 if(Suffix == (*it).section(
'/',0,0)) {
1926 com = QStringList::split(
" ", (*it).section(
'/',1,1));
1927 com << Info.absFilePath();
1928 QProcess *Program =
new QProcess(com);
1929 Program->setCommunication(0);
1930 if(!Program->start()) {
1931 QMessageBox::critical(
this, tr(
"Error"),
1932 tr(
"Cannot start \"%1\"!").
arg(Info.absFilePath()));
1946 void QucsApp::slotSelectSubcircuit(QListViewItem *item)
1951 Content->clearSelection();
1956 bool isVHDL =
false;
1957 bool isVerilog =
false;
1958 if(item->parent() == 0)
return;
1959 if(item->parent()->text(0) == tr(
"Schematics")) {
1960 if(item->text(1).isEmpty())
1963 else if(item->parent()->text(0) == tr(
"VHDL"))
1965 else if(item->parent()->text(0) == tr(
"Verilog"))
1989 Comp->
Props.first()->Value = item->text(0);
1994 ((QScrollView*)
DocumentTab->currentPage())->viewport()->update();
2005 void QucsApp::slotExpandContentList(QListViewItem*)
2013 void QucsApp::switchSchematicDoc (
bool SchematicMode)
2015 mainAccel->setEnabled (SchematicMode);
2018 if (!SchematicMode) {
2025 select->blockSignals (
true);
2027 select->blockSignals (
false);
2038 alignTop->setEnabled (SchematicMode);
2044 distrHor->setEnabled (SchematicMode);
2046 onGrid->setEnabled (SchematicMode);
2047 moveText->setEnabled (SchematicMode);
2052 intoH->setEnabled (SchematicMode);
2053 popH->setEnabled (SchematicMode);
2054 dcbias->setEnabled (SchematicMode);
2055 insWire->setEnabled (SchematicMode);
2056 insLabel->setEnabled (SchematicMode);
2057 insPort->setEnabled (SchematicMode);
2062 editFind->setEnabled (!SchematicMode);
2068 void QucsApp::switchEditMode(
bool SchematicMode)
2070 fillComboBox(SchematicMode);
2073 intoH->setEnabled(SchematicMode);
2074 popH->setEnabled(SchematicMode);
2079 insPort->setEnabled(SchematicMode);
2080 insWire->setEnabled(SchematicMode);
2081 insLabel->setEnabled(SchematicMode);
2084 simulate->setEnabled(SchematicMode);
2088 void QucsApp::changeSchematicSymbolMode(
Schematic *Doc)
2094 switchEditMode(
false);
2097 switchEditMode(
true);
2101 bool QucsApp::isTextDocument(QWidget *w) {
2102 if (w->inherits(
"QTextEdit"))
2116 if (isTextDocument (w)) {
2119 QFileInfo Info(TDoc->
DocName);
2120 QString sym = Info.baseName(
true)+
".sym";
2139 changeSchematicSymbolMode(SDoc);
2141 SDoc->viewport()->update();
2148 if(SDoc->
DocName.right(4) ==
".sym") {
2155 changeSchematicSymbolMode(SDoc);
2157 SDoc->viewport()->update();
2181 Dia->
S11degEdit->setText(QString::number(Imag));
2185 if(Dia->exec() != QDialog::Accepted)
2199 if(z <= 0) DataSet = Doc->
DataSet;
2200 else DataSet = pm->
pGraph->
Var.mid(z+1);
2201 double Freq = pm->
VarPos[0];
2204 DataSet = Info.dirPath()+QDir::separator()+DataSet;
2211 QMessageBox::critical(0, tr(
"Error"), tr(
"Could not load S[1,1]."));
2215 pg =
new Graph(
"S[1,2]");
2218 QMessageBox::critical(0, tr(
"Error"), tr(
"Could not load S[1,2]."));
2222 pg =
new Graph(
"S[2,1]");
2225 QMessageBox::critical(0, tr(
"Error"), tr(
"Could not load S[2,1]."));
2229 pg =
new Graph(
"S[2,2]");
2232 QMessageBox::critical(0, tr(
"Error"), tr(
"Could not load S[2,2]."));
2236 DataX *Data = Diag->
Graphs.getFirst()->cPointsX.first();
2237 if(Data->
Var !=
"frequency") {
2238 QMessageBox::critical(0, tr(
"Error"), tr(
"Wrong dependency!"));
2242 double *Value = Data->
Points;
2244 for(z=0; z<Data->
count; z++)
2245 if(*(Value++) == Freq)
break;
2248 double S11real = *(Diag->
Graphs.first()->cPointsY + 2*z);
2249 double S11imag = *(Diag->
Graphs.current()->cPointsY + 2*z + 1);
2250 double S12real = *(Diag->
Graphs.next()->cPointsY + 2*z);
2251 double S12imag = *(Diag->
Graphs.current()->cPointsY + 2*z + 1);
2252 double S21real = *(Diag->
Graphs.next()->cPointsY + 2*z);
2253 double S21imag = *(Diag->
Graphs.current()->cPointsY + 2*z + 1);
2254 double S22real = *(Diag->
Graphs.next()->cPointsY + 2*z);
2255 double S22imag = *(Diag->
Graphs.current()->cPointsY + 2*z + 1);
2262 Dia->
S11magEdit->setText(QString::number(S11real));
2263 Dia->
S11degEdit->setText(QString::number(S11imag));
2264 Dia->
S12magEdit->setText(QString::number(S12real));
2265 Dia->
S12degEdit->setText(QString::number(S12imag));
2266 Dia->
S21magEdit->setText(QString::number(S21real));
2267 Dia->
S21degEdit->setText(QString::number(S21imag));
2268 Dia->
S22magEdit->setText(QString::number(S22real));
2269 Dia->
S22degEdit->setText(QString::number(S22imag));
2272 if(Dia->exec() != QDialog::Accepted)
2287 void QucsApp::slotHideEdit()