24 #include <qpopupmenu.h>
25 #include <qcombobox.h>
26 #include <qclipboard.h>
27 #include <qapplication.h>
30 #include <qvgroupbox.h>
31 #include <qpushbutton.h>
32 #include <qmessagebox.h>
33 #include <qtextedit.h>
49 setCaption(
"Qucs Library Tool " PACKAGE_VERSION);
51 QMenuBar * menuBar =
new QMenuBar (
this);
54 QPopupMenu * fileMenu =
new QPopupMenu ();
56 new QAction (
"Manage User Libraries...", tr(
"Manage User &Libraries..."), CTRL+Key_M,
this);
57 manageLib->addTo (fileMenu);
58 connect(manageLib, SIGNAL(activated()), SLOT(slotManageLib()));
60 fileMenu->insertSeparator();
63 new QAction (
"Quit", tr(
"&Quit"), CTRL+Key_Q,
this);
64 fileQuit->addTo (fileMenu);
65 connect(fileQuit, SIGNAL(activated()), SLOT(slotQuit()));
68 QPopupMenu * helpMenu =
new QPopupMenu ();
70 new QAction (tr(
"Help"), tr(
"&Help"), Key_F1,
this);
71 helpHelp->addTo (helpMenu);
72 connect(helpHelp, SIGNAL(activated()), SLOT(slotHelp()));
74 new QAction (tr(
"About"), tr(
"About"), 0, helpMenu);
75 helpAbout->addTo (helpMenu);
76 connect(helpAbout, SIGNAL(activated()), SLOT(slotAbout()));
79 menuBar->insertItem (tr(
"&File"), fileMenu);
80 menuBar->insertSeparator ();
81 menuBar->insertItem (tr(
"&Help"), helpMenu);
84 QVBoxLayout * all =
new QVBoxLayout (
this);
89 QWidget * Space =
new QWidget (
this);
90 Space->setFixedSize(5, menuBar->height() + 2);
91 all->addWidget (Space);
94 QHBox * h =
new QHBox (
this);
100 QVGroupBox * LibGroup =
new QVGroupBox (tr(
"Component Selection"), h);
101 Library =
new QComboBox (LibGroup);
102 connect(
Library, SIGNAL(activated(
int)), SLOT(slotSelectLibrary(
int)));
104 connect(
CompList, SIGNAL(highlighted(QListBoxItem*)),
105 SLOT(slotShowComponent(QListBoxItem*)));
107 QHBox * h1 =
new QHBox (LibGroup);
108 QPushButton * SearchButton =
new QPushButton (tr(
"Search..."), h1);
109 connect(SearchButton, SIGNAL(clicked()), SLOT(slotSearchComponent()));
110 h1->setStretchFactor(
new QWidget(h1), 5);
114 QVGroupBox *CompGroup =
new QVGroupBox (tr(
"Component"), h);
115 CompDescr =
new QTextEdit(CompGroup);
116 CompDescr->setTextFormat(Qt::PlainText);
117 CompDescr->setReadOnly(
true);
118 CompDescr->setWordWrap(QTextEdit::NoWrap);
122 QHBox * h2 =
new QHBox (CompGroup);
123 QPushButton * CopyButton =
new QPushButton (tr(
"Copy to clipboard"), h2);
124 connect(CopyButton, SIGNAL(clicked()), SLOT(slotCopyToClipBoard()));
125 QPushButton * ShowButton =
new QPushButton (tr(
"Show Model"), h2);
126 connect(ShowButton, SIGNAL(clicked()), SLOT(slotShowModel()));
129 putLibrariesIntoCombobox();
139 void QucsLib::putLibrariesIntoCombobox()
144 QStringList LibFiles;
145 QStringList::iterator it;
147 LibFiles =
UserLibDir.entryList(
"*.lib", QDir::Files, QDir::Name);
148 UserLibCount = LibFiles.count();
150 for(it = LibFiles.begin(); it != LibFiles.end(); it++)
151 Library->insertItem((*it).left((*it).length()-4));
155 LibFiles = LibDir.entryList(
"*.lib", QDir::Files, QDir::Name);
157 for(it = LibFiles.begin(); it != LibFiles.end(); it++)
158 Library->insertItem((*it).left((*it).length()-4));
160 slotSelectLibrary(0);
164 void QucsLib::slotAbout()
166 QMessageBox::about(
this, tr(
"About..."),
167 "QucsLib Version " PACKAGE_VERSION
"\n"+
168 tr(
"Library Manager for Qucs\n")+
169 tr(
"Copyright (C) 2005 by Michael Margraf\n")+
170 "\nThis is free software; see the source for copying conditions."
171 "\nThere is NO warranty; not even for MERCHANTABILITY or "
172 "\nFITNESS FOR A PARTICULAR PURPOSE.");
176 void QucsLib::slotQuit()
188 void QucsLib::closeEvent(QCloseEvent *Event)
200 void QucsLib::slotManageLib()
203 putLibrariesIntoCombobox();
207 void QucsLib::slotHelp()
210 d->setCaption(tr(
"QucsLib Help"));
213 tr(
"QucsLib is a program to manage Qucs component libraries. "
214 "On the left side of the application window the available "
215 "libraries can be browsed to find the wanted component. "
216 "By clicking on the component name its description can be "
217 "seen on the right side. The selected component is "
218 "transported to the Qucs application by clicking on the "
219 "button \"Copy to Clipboard\". Being back in the schematic "
220 "window the component can be inserted by pressing CTRL-V "
221 " (paste from clipboard).") +
"\n" +
222 tr(
"A more comfortable way: The component can also be placed "
223 "onto the schematic by using Drag n'Drop."));
228 void QucsLib::slotCopyToClipBoard()
230 QString
s =
"<Qucs Schematic " PACKAGE_VERSION
">\n";
231 s +=
"<Components>\n " +
236 QClipboard *cb = QApplication::clipboard();
241 void QucsLib::slotShowModel()
244 d->setCaption(tr(
"Model"));
247 d->
Text->setWordWrap(QTextEdit::NoWrap);
249 d->
VHDLText->setWordWrap(QTextEdit::NoWrap);
256 void QucsLib::slotSelectLibrary(
int Index)
258 int Start,
End, NameStart, NameEnd;
260 if(
Library->text(End) == tr(
"Search result")) {
271 if(Index < UserLibCount)
272 file.setName(
UserLibDir.absPath() + QDir::separator() +
Library->text(Index) +
".lib");
276 if(!file.open(IO_ReadOnly)) {
277 QMessageBox::critical(
this, tr(
"Error"),
278 tr(
"Cannot open \"%1\".").
arg(
283 QTextStream ReadWhole(&file);
284 QString LibraryString = ReadWhole.read();
287 Start = LibraryString.find(
"<Qucs Library ");
289 QMessageBox::critical(
this, tr(
"Error"), tr(
"Library is corrupt."));
292 End = LibraryString.find(
'>', Start);
294 QMessageBox::critical(
this, tr(
"Error"), tr(
"Library is corrupt."));
297 QString LibName = LibraryString.mid(Start, End-Start).section(
'"', 1, 1);
299 Start = LibraryString.find(
"\n<", End);
300 if(Start < 0)
return;
301 if(LibraryString.mid(Start+2, 14) ==
"DefaultSymbol>") {
302 End = LibraryString.find(
"\n</DefaultSymbol>");
304 QMessageBox::critical(
this, tr(
"Error"), tr(
"Library is corrupt."));
312 while((Start=LibraryString.find(
"\n<Component ", Start)) > 0) {
314 NameStart = Start + 11;
315 NameEnd = LibraryString.find(
'>', NameStart);
316 if(NameEnd < 0)
continue;
318 End = LibraryString.find(
"\n</Component>", NameEnd);
319 if(End < 0)
continue;
322 CompList->insertItem(LibraryString.mid(NameStart, NameEnd-NameStart));
323 LibraryComps.append(LibName+
'\n'+LibraryString.mid(Start, End-Start));
331 void QucsLib::slotSearchComponent()
334 d->setCaption(tr(
"Search Library Component"));
335 if(d->exec() == QDialog::Accepted)
336 QMessageBox::information(
this, tr(
"Result"),
337 tr(
"No appropriate component found."));
341 void QucsLib::slotShowComponent(QListBoxItem *Item)
346 QString LibName = (*CompString).section(
'\n', 0, 0);
347 CompDescr->setText(
"Name: " + Item->text());
348 CompDescr->append(
"Library: " + LibName);
349 CompDescr->append(
"----------------------------");
351 if(
Library->currentItem() < UserLibCount)
352 LibName =
UserLibDir.absPath() + QDir::separator() + LibName;
355 if(!getSection(
"Description", *CompString, content))
357 CompDescr->append(content);
359 if(!getSection(
"Model", *CompString, content))
365 if(!getSection(
"VHDLModel", *CompString, content))
369 if(!getSection(
"VerilogModel", *CompString, content))
373 if(!getSection(
"Symbol", *CompString, content))
375 if(!content.isEmpty())
376 Symbol->
setSymbol(content, LibName, Item->text());
382 bool QucsLib::getSection(QString section, QString &list, QString &content)
385 Start = list.find(
"<"+section+
">");
388 Start += section.length()+2;
389 End = list.find(
"</"+section+
">", Start);
391 QMessageBox::critical(
this, tr(
"Error"), tr(
"Library is corrupt."));
394 content = list.mid(Start, End-Start);
395 content.replace(QRegExp(
"\\n\\x20+"),
"\n").remove(0, 1);