30 #include <qlineedit.h>
31 #include <qfileinfo.h>
32 #include <qiconview.h>
33 #include <qtabwidget.h>
34 #include <qdragobject.h>
35 #include <qpaintdevicemetrics.h>
85 UndoStack.append(
new QString(
" i\n</>\n</>\n</>\n</>\n"));
86 UndoSymbol.append(
new QString(
" i\n</>\n</>\n</>\n</>\n"));
90 QFileInfo Info(Name_);
94 QObject::tr(
"untitled"));
108 setVScrollBarMode(QScrollView::AlwaysOn);
109 setHScrollBarMode(QScrollView::AlwaysOn);
111 viewport()->setMouseTracking(
true);
112 viewport()->setAcceptDrops(
true);
114 connect(horizontalScrollBar(),
116 connect(horizontalScrollBar(),
118 connect(verticalScrollBar(),
120 connect(verticalScrollBar(),
126 connect(
this, SIGNAL(horizontalSliderReleased()),
127 viewport(), SLOT(update()));
128 connect(
this, SIGNAL(verticalSliderReleased()),
129 viewport(), SLOT(update()));
132 connect(
this, SIGNAL(horizontalSliderPressed()),
App, SLOT(slotHideEdit()));
133 connect(
this, SIGNAL(verticalSliderPressed()),
App, SLOT(slotHideEdit()));
155 int h = 30*((countPort-1)/2) + 10;
159 new GraphicLine(-20, -h, 40, 0, QPen(QPen::darkBlue,2)));
161 new GraphicLine( 20, -h, 0,2*h, QPen(QPen::darkBlue,2)));
163 new GraphicLine(-20, h, 40, 0, QPen(QPen::darkBlue,2)));
165 new GraphicLine(-20, -h, 0,2*h, QPen(QPen::darkBlue,2)));
167 unsigned int i=0, y = 10-h;
171 new GraphicLine(-30, y, 10, 0, QPen(QPen::darkBlue,2)));
174 if(i == countPort)
break;
177 new GraphicLine( 20, y, 10, 0, QPen(QPen::darkBlue,2)));
192 if (
DocName.right(4) ==
".sym") {
194 App->
symEdit->setStatusTip(tr(
"Edits the Text"));
195 App->
symEdit->setWhatsThis(tr(
"Edit Text\n\nEdits the text file"));
198 App->
symEdit->setMenuText(tr(
"Edit Schematic"));
199 App->
symEdit->setStatusTip(tr(
"Edits the schematic"));
200 App->
symEdit->setWhatsThis(tr(
"Edit Schematic\n\nEdits the schematic"));
204 App->
symEdit->setMenuText(tr(
"Edit Circuit Symbol"));
205 App->
symEdit->setStatusTip(tr(
"Edits the symbol for this schematic"));
207 tr(
"Edit Circuit Symbol\n\nEdits the symbol for this schematic"));
225 else App->
undo->setEnabled(
false);
227 else App->
redo->setEnabled(
false);
238 else App->
undo->setEnabled(
false);
240 else App->
redo->setEnabled(
false);
254 QString base = Info.baseName (
true);
255 QString ext = Info.extension (
false);
286 UndoSymbol.append(
new QString(createSymbolUndoString(Op)));
308 UndoStack.append(
new QString(createUndoString(Op)));
324 case 1: xall = 1020; yall = 765;
break;
325 case 2: xall = 765; yall = 1020;
break;
326 case 3: xall = 1530; yall = 1020;
break;
327 case 4: xall = 1020; yall = 1530;
break;
328 case 5: xall = 2295; yall = 1530;
break;
329 case 6: xall = 1530; yall = 2295;
break;
330 case 7: xall = 1414; yall = 1054;
break;
331 case 8: xall = 1054; yall = 1414;
break;
332 default:
return false;
346 p->
Painter->setPen(QPen(Qt::black,0));
348 int x1_, y1_, x2_, y2_;
349 p->
map(xall, yall, x1_, y1_);
350 x2_ = int(xall * p->
Scale) + 1;
351 y2_ = int(yall * p->
Scale) + 1;
352 p->
Painter->drawRect(x1_, y1_, -x2_, -y2_);
353 p->
Painter->drawRect(x1_-d, y1_-d, 2*d-x2_, 2*d-y2_);
356 int step = xall / ((xall+127) / 255);
357 for(z=step; z<=xall-
step; z+=
step) {
358 p->
map(z, 0, x2_, y2_);
359 p->
Painter->drawLine(x2_, y2_, x2_, y2_+d);
360 p->
Painter->drawLine(x2_, y1_-d, x2_, y1_);
362 char Letter[2] =
"1";
363 for(z=step/2+5; z<xall; z+=
step) {
365 p->
map(z, yall+3, x2_, y2_);
366 p->
Painter->drawText(x2_, y2_-d, 0, 0, Qt::DontClip, Letter);
370 step = yall / ((yall+127) / 255);
371 for(z=step; z<=yall-
step; z+=
step) {
372 p->
map(0, z, x2_, y2_);
373 p->
Painter->drawLine(x2_, y2_, x2_+d, y2_);
374 p->
Painter->drawLine(x1_-d, y2_, x1_, y2_);
377 for(z=step/2+5; z<yall; z+=
step) {
379 p->
map(xall+5, z, x2_, y2_);
380 p->
Painter->drawText(x2_-d, y2_, 0, 0, Qt::DontClip, Letter);
385 p->
map(xall-340, yall-3, x1_, y1_);
386 p->
map(xall-3, yall-3, x2_, y2_);
389 d = int(6.0 * p->
Scale);
390 z = int(200.0 * p->
Scale);
392 p->
Painter->drawLine(x1_, y1_, x2_, y1_);
397 p->
Painter->drawLine(x1_, y1_, x2_, y1_);
400 p->
Painter->drawRect(x2_, y2_, x1_-x2_-1, y1_-y2_-1);
411 paintGrid(&Painter, contentsX(), contentsY(),
412 visibleWidth(), visibleHeight());
423 pw->Label->paint(&Painter);
427 for(pn =
Nodes->first(); pn != 0; pn =
Nodes->next()) {
441 for(pn =
Nodes->first(); pn != 0; pn =
Nodes->next()) {
442 if(pn->
Name.isEmpty())
continue;
446 if(z & 1) x -= Painter.
Painter->fontMetrics().width(pn->
Name);
453 Painter.
Painter->setPen(QPen::darkGreen);
455 Painter.
Painter->setPen(QPen::blue);
475 float x = float(Event->pos().x())/
Scale +
float(
ViewX1);
476 float y = float(Event->pos().y())/
Scale +
float(
ViewY1);
478 if(Event->button() != Qt::LeftButton)
510 QPaintDeviceMetrics pmetrics(Painter->device());
511 float printerDpiX = (float)pmetrics.logicalDpiX();
512 float printerDpiY = (float)pmetrics.logicalDpiY();
513 float printerW = (float)pmetrics.width();
514 float printerH = (float)pmetrics.height();
515 QPainter pa(viewport());
516 QPaintDeviceMetrics smetrics(pa.device());
517 float screenDpiX = (float)smetrics.logicalDpiX();
518 float screenDpiY = (float)smetrics.logicalDpiY();
519 float PrintScale = 0.5;
521 int marginX = (int)(40 * printerDpiX / screenDpiX);
522 int marginY = (int)(40 * printerDpiY / screenDpiY);
525 float ScaleX = float(printerW - 2*marginX) /
527 float ScaleY = float(printerH - 2*marginY) /
541 if(
UsedX1 > 0) StartX = 0;
542 if(
UsedY1 > 0) StartY = 0;
545 float PrintRatio = printerDpiX / screenDpiX;
546 QFont oldFont = Painter->font();
547 p.
init(Painter, PrintScale * PrintRatio,
548 -StartX, -StartY, -marginX, -marginY,
549 PrintScale, PrintRatio);
555 if(pc->isSelected || printAll) {
556 selected = pc->isSelected;
557 pc->isSelected =
false;
561 pc->print(&p, screenDpiX / printerDpiX);
563 pc->isSelected = selected;
567 if(pw->isSelected || printAll) {
568 selected = pw->isSelected;
569 pw->isSelected =
false;
571 pw->isSelected = selected;
574 if(pw->Label->isSelected || printAll) {
575 selected = pw->Label->isSelected;
576 pw->Label->isSelected =
false;
577 pw->Label->paint(&p);
578 pw->Label->isSelected = selected;
584 for(pe = pn->Connections.first(); pe != 0; pe = pn->Connections.next())
590 if(pn->Label->isSelected || printAll) {
592 pn->Label->isSelected =
false;
593 pn->Label->paint(&p);
594 pn->Label->isSelected = selected;
601 if(pd->isSelected || printAll) {
603 for(pg = pd->Graphs.first(); pg != 0; pg = pd->Graphs.next()) {
612 selected = pd->isSelected;
613 pd->isSelected =
false;
615 pd->isSelected = selected;
618 for(pg = pd->Graphs.first(); pg != 0; pg = pd->Graphs.next()) {
629 if(pp->isSelected || printAll) {
630 selected = pp->isSelected;
631 pp->isSelected =
false;
633 pp->isSelected = selected;
636 Painter->setFont(oldFont);
648 viewport()->setHidden(
true);
653 viewport()->setHidden(
false);
655 viewport()->update();
665 scrollBy(
int(s *
float(contentsX()+visibleWidth()/2)),
666 int(s *
float(contentsY()+visibleHeight()/2)) );
683 float xScale = float(visibleWidth()) / float(
UsedX2-
UsedX1+80);
684 float yScale = float(visibleHeight()) / float(
UsedY2-
UsedY1+80);
685 if(xScale > yScale) xScale = yScale;
713 if(x2==0)
if(y2==0)
if(x1==0)
if(y1==0) x2 = y2 = 800;
719 resizeContents(x2-x1+80, y2-y1+80);
720 viewport()->update();
755 if(x<0) x -= (
GridX >> 1) - 1;
756 else x +=
GridX >> 1;
759 if(y<0) y -= (
GridY >> 1) - 1;
760 else y +=
GridY >> 1;
769 p->
Painter->setPen(QPen(QPen::black,0));
772 p->
Painter->drawLine(-3+dx, dy, 4+dx, dy);
773 p->
Painter->drawLine( dx,-3+dy, dx, 4+dy);
780 if(x1<0) x1 -=
GridX - 1;
782 x1 -= x1 % (
GridX << 1);
784 if(y1<0) y1 -=
GridY - 1;
786 y1 -= y1 % (
GridY << 1);
788 float X,
Y,
Y0, DX, DY;
790 Y = Y0 = float(y1)*
Scale + p->
DY;
791 x1 = X > 0.0 ? int(X + 0.5) : int(X - 0.5);
792 y1 = Y > 0.0 ? int(Y + 0.5) : int(Y - 0.5);
795 int xEnd = x1 + Width;
796 int yEnd = y1 + Height;
799 while(DX <= 8.0) DX *= 1.5;
800 while(DY <= 8.0) DY *= 1.5;
804 y1 = Y > 0.0 ? int(Y + 0.5) : int(Y - 0.5);
808 y1 = Y > 0.0 ? int(Y + 0.5) : int(Y - 0.5);
811 x1 = X > 0.0 ? int(X + 0.5) : int(X - 0.5);
820 Font.setPointSizeFloat(
Scale *
float(Font.pointSize()) );
821 QFontMetrics metrics(Font);
822 return (
Scale /
float(metrics.lineSpacing()));
853 if(x1 < xmin) xmin = x1;
854 if(x2 > xmax) xmax = x2;
855 if(y1 < ymin) ymin = y1;
856 if(y2 > ymax) ymax = y2;
860 for(pw =
Wires->first(); pw != 0; pw =
Wires->next()) {
861 if(pw->
x1 < xmin) xmin = pw->
x1;
862 if(pw->
x2 > xmax) xmax = pw->
x2;
863 if(pw->
y1 < ymin) ymin = pw->
y1;
864 if(pw->
y2 > ymax) ymax = pw->
y2;
868 if(pl->
x1 < xmin) xmin = pl->
x1;
869 if((pl->
x1+pl->
x2) > xmax) xmax = pl->
x1 + pl->
x2;
870 if(pl->
y1 > ymax) ymax = pl->
y1;
871 if((pl->
y1-pl->
y2) < ymin) ymin = pl->
y1 - pl->
y2;
879 if(pl->
x1 < xmin) xmin = pl->
x1;
880 if((pl->
x1+pl->
x2) > xmax) xmax = pl->
x1 + pl->
x2;
881 if(pl->
y1 > ymax) ymax = pl->
y1;
882 if((pl->
y1-pl->
y2) < ymin) ymin = pl->
y1 - pl->
y2;
889 if(x1 < xmin) xmin = x1;
890 if(x2 > xmax) xmax = x2;
891 if(y1 < ymin) ymin = y1;
892 if(y2 > ymax) ymax = y2;
896 for(
Marker *pm = pg->Markers.first(); pm!=0; pm = pg->Markers.next()) {
897 pm->Bounding(x1, y1, x2, y2);
898 if(x1 < xmin) xmin = x1;
899 if(x2 > xmax) xmax = x2;
900 if(y1 < ymin) ymin = y1;
901 if(y2 > ymax) ymax = y2;
908 if(x1 < xmin) xmin = x1;
909 if(x2 > xmax) xmax = x2;
910 if(y1 < ymin) ymin = y1;
911 if(y2 > ymax) ymax = y2;
919 Wires->setAutoDelete(
false);
922 int x1=INT_MAX, y1=INT_MAX;
923 int x2=INT_MIN, y2=INT_MIN;
924 QPtrList<Element> ElementCache;
926 copyComponents(x1, y1, x2, y2, &ElementCache);
927 copyWires(x1, y1, x2, y2, &ElementCache);
929 if(y1 == INT_MAX)
return false;
931 Wires->setAutoDelete(
true);
944 for(
Element *pe = ElementCache.first(); pe != 0; pe = ElementCache.next())
958 pw->
x1 = pw->
y1 - y1 + x1;
959 pw->
y1 = x1 - x2 + y1;
961 pw->
x2 = pw->
y2 - y1 + x1;
962 pw->
y2 = x1 - x2 + y1;
966 pl->
cx = pl->
cy - y1 + x1;
967 pl->
cy = x1 - x2 + y1;
979 pl->
x1 = pl->
y1 - y1 + x1;
980 pl->
y1 = x1 - x2 + y1;
986 pl->
x1 = pl->
y1 - y1 + x1;
987 pl->
y1 = x1 - x2 + y1;
990 pl->
cx = pl->
cy - y1 + x1;
991 pl->
cy = x1 - x2 + y1;
1005 ElementCache.clear();
1016 Wires->setAutoDelete(
false);
1020 QPtrList<Element> ElementCache;
1021 if(!copyComps2WiresPaints(x1, y1, x2, y2, &ElementCache))
1023 Wires->setAutoDelete(
true);
1036 for(
Element *pe = ElementCache.first(); pe != 0; pe = ElementCache.next())
1048 pw->
y1 = y1 - pw->
y1;
1049 pw->
y2 = y1 - pw->
y2;
1051 if(pl) pl->
cy = y1 - pl->
cy;
1057 pl->
y1 = y1 - pl->
y1;
1062 pl->
y1 = y1 - pl->
y1;
1063 pl->
cy = y1 - pl->
cy;
1076 ElementCache.clear();
1085 Wires->setAutoDelete(
false);
1089 QPtrList<Element> ElementCache;
1090 if(!copyComps2WiresPaints(x1, y1, x2, y2, &ElementCache))
1092 Wires->setAutoDelete(
true);
1104 for(
Element *pe = ElementCache.first(); pe != 0; pe = ElementCache.next())
1116 pw->
x1 = x1 - pw->
x1;
1117 pw->
x2 = x1 - pw->
x2;
1119 if(pl) pl->
cx = x1 - pl->
cx;
1125 pl->
x1 = x1 - pl->
x1;
1130 pl->
x1 = x1 - pl->
x1;
1131 pl->
cx = x1 - pl->
cx;
1144 ElementCache.clear();
1155 pd->loadGraphData(Info.dirPath()+QDir::separator()+
DataSet);
1162 QString
s = createClipboardFile();
1171 return pasteFromClipboard(stream, pe);
1186 lastSaved = QDateTime::currentDateTime();
1215 if(saveDocument() < 0)
1267 if(pp->
Name ==
".PortSym ")
1274 QString Suffix = Info.extension (
false);
1277 if (Suffix ==
"vhd" || Suffix ==
"vhdl") {
1278 QStringList::iterator it;
1279 QStringList Names, GNames, GTypes, GDefs;
1284 QString Name = Info.dirPath() + QDir::separator() +
DataDisplay;
1294 Names = QStringList::split(
",",VInfo.
PortNames);
1297 if(pp->
Name ==
".ID ") {
1300 id->Parameter.clear();
1301 GNames = QStringList::split(
",",VInfo.
GenNames);
1302 GTypes = QStringList::split(
",",VInfo.
GenTypes);
1303 GDefs = QStringList::split(
",",VInfo.
GenDefs);
1304 for(Number = 1, it = GNames.begin(); it != GNames.end(); ++it) {
1307 *it+
"="+GDefs[Number-1],
1308 tr(
"generic")+
" "+QString::number(Number),
1314 for(Number = 1, it = Names.begin(); it != Names.end(); ++it, Number++) {
1317 Str = QString::number(Number);
1320 if(pp->
Name ==
".PortSym ")
1321 if(((
PortSymbol*)pp)->numberStr == Str)
break;
1332 else if (Suffix ==
"v") {
1334 QStringList::iterator it;
1340 QString Name = Info.dirPath() + QDir::separator() +
DataDisplay;
1350 Names = QStringList::split(
",",VInfo.
PortNames);
1353 if(pp->
Name ==
".ID ") {
1356 id->Parameter.clear();
1359 for(Number = 1, it = Names.begin(); it != Names.end(); ++it, Number++) {
1362 Str = QString::number(Number);
1365 if(pp->
Name ==
".PortSym ")
1366 if(((
PortSymbol*)pp)->numberStr == Str)
break;
1377 else if (Suffix ==
"va") {
1379 QStringList::iterator it;
1385 QString Name = Info.dirPath() + QDir::separator() +
DataDisplay;
1395 Names = QStringList::split(
",",VInfo.
PortNames);
1398 if(pp->
Name ==
".ID ") {
1401 id->Parameter.clear();
1404 for(Number = 1, it = Names.begin(); it != Names.end(); ++it, Number++) {
1407 Str = QString::number(Number);
1410 if(pp->
Name ==
".PortSym ")
1411 if(((
PortSymbol*)pp)->numberStr == Str)
break;
1425 if(pc->Model ==
"Port") {
1428 Str = pc->Props.getFirst()->Value;
1431 if(pp->
Name ==
".PortSym ")
1432 if(((
PortSymbol*)pp)->numberStr == Str)
break;
1445 if(pp->
Name ==
".PortSym ")
1468 else App->
undo->setEnabled(
false);
1470 else App->
redo->setEnabled(
false);
1472 if(ps->at(1) ==
'i')
1491 else App->
undo->setEnabled(
false);
1493 else App->
redo->setEnabled(
false);
1495 if(ps->at(1) ==
'i') {
1500 else if(
UndoSymbol.current()->at(1) ==
'i') {
1521 else App->
undo->setEnabled(
false);
1523 else App->
redo->setEnabled(
false);
1525 if(ps->at(1) ==
'i')
1544 else App->
undo->setEnabled(
false);
1546 else App->
redo->setEnabled(
false);
1548 if(ps->at(1) ==
'i') {
1553 else if(
UndoSymbol.current()->at(1) ==
'i') {
1571 QPtrList<WireLabel> LabelCache;
1576 if(pc->isSelected) {
1579 for(pp = pc->Ports.first(); pp != 0; pp = pc->Ports.next())
1594 pc->isSelected =
false;
1599 for(pl = LabelCache.first(); pl != 0; pl = LabelCache.next()) {
1608 Wires->setAutoDelete(
false);
1614 if(pw->isSelected) {
1617 if(pw->Port1->Label) {
1618 if(pw->Port1->Connections.count() < 2) {
1619 pLabel = pw->Port1->Label;
1620 pw->Port1->Label = 0;
1623 else if(pw->Port2->Label) {
1624 if(pw->Port2->Connections.count() < 2) {
1625 pLabel = pw->Port2->Label;
1626 pw->Port2->Label = 0;
1636 pw->isSelected =
false;
1656 Wires->setAutoDelete(
true);
1661 if(pn->Label->isSelected) {
1662 setOnGrid(pn->Label->x1, pn->Label->y1);
1663 pn->Label->isSelected =
false;
1669 if(pd->isSelected) {
1671 pd->isSelected =
false;
1675 for(
Graph *pg = pd->Graphs.first(); pg != 0; pg = pd->Graphs.next())
1677 for(
Marker *pm = pg->Markers.first(); pm != 0; pm = pg->Markers.next())
1678 if(pm->isSelected) {
1679 x = pm->x1 + pd->cx;
1680 y = pm->y1 + pd->cy;
1682 pm->x1 = x - pd->cx;
1683 pm->y1 = y - pd->cy;
1684 pm->isSelected =
false;
1691 if(pa->isSelected) {
1693 pa->isSelected =
false;
1733 int delta = Event->delta() >> 1;
1736 if((Event->state() & Qt::ShiftButton) ||
1737 (Event->orientation() == Horizontal)) {
1738 if(delta > 0) {
if(
scrollLeft(delta)) scrollBy(-delta, 0); }
1739 else {
if(
scrollRight(delta)) scrollBy(-delta, 0); }
1740 viewport()->update();
1744 else if(Event->state() & Qt::ControlButton) {
1746 if(delta < 0) Scaling = float(delta)/-60.0/1.1;
1747 else Scaling = 1.1*60.0/float(delta);
1750 scrollBy(
int(Scaling *
float(Event->pos().x())),
1751 int(Scaling *
float(Event->pos().y())) );
1755 if(delta > 0) {
if(
scrollUp(delta)) scrollBy(0, -delta); }
1756 else {
if(
scrollDown(delta)) scrollBy(0, -delta); }
1757 viewport()->update();
1771 diff = contentsY() -
step;
1773 resizeContents(contentsWidth(), contentsHeight()-diff);
1781 if(step < diff) diff =
step;
1782 resizeContents(contentsWidth(), contentsHeight()-diff);
1796 diff = contentsHeight() - contentsY()-visibleHeight() +
step;
1798 resizeContents(contentsWidth(), contentsHeight()-diff);
1806 if(step > diff) diff =
step;
1807 resizeContents(contentsWidth(), contentsHeight()+diff);
1822 diff = contentsX() -
step;
1824 resizeContents(contentsWidth()-diff, contentsHeight());
1832 if(step < diff) diff =
step;
1833 resizeContents(contentsWidth()-diff, contentsHeight());
1847 diff = contentsWidth() - contentsX()-visibleWidth() +
step;
1849 resizeContents(contentsWidth()-diff, contentsHeight());
1857 if(step > diff) diff =
step;
1858 resizeContents(contentsWidth()+diff, contentsHeight());
1871 scrollUp(verticalScrollBar()->lineStep());
1872 viewport()->update();
1881 scrollDown(-verticalScrollBar()->lineStep());
1882 viewport()->update();
1891 scrollLeft(horizontalScrollBar()->lineStep());
1892 viewport()->update();
1902 viewport()->update();
1918 QUriDrag::decode(Event, List);
1926 for(
unsigned int i=0;
i < List.count();
i++)
1927 App->
gotoPage(QDir::convertSeparators(QUriDrag::uriToLocalFile(List.at(
i))));
1934 QMouseEvent
e(QEvent::MouseButtonPress, Event->pos(),
1935 Qt::LeftButton, Qt::NoButton);
1955 if(Event->provides(
"text/uri-list"))
1956 if(QUriDrag::canDecode(Event)) {
1963 if(Event->provides(
"text/plain")) {
1965 if(QTextDrag::decode(Event, s))
1966 if(s.left(15) ==
"QucsComponent:<") {
1979 if(Event->format(1) == 0) {
1982 if(Event->provides(
"application/x-qiconlist")) {
2006 QPainter painter(viewport());
2025 QMouseEvent
e(QEvent::MouseMove, Event->pos(), Qt::NoButton, Qt::NoButton);