23 #include "components/component.h"
34 #include <qinputdialog.h>
35 #include <qclipboard.h>
36 #include <qapplication.h>
37 #include <qmessagebox.h>
38 #include <qpopupmenu.h>
41 #include <qtabwidget.h>
47 #define DOC_X_POS(x) (int(float(x)/Doc->Scale) + Doc->ViewX1)
48 #define DOC_Y_POS(y) (int(float(y)/Doc->Scale) + Doc->ViewY1)
49 #define DOC_X_FPOS (float(Event->pos().x())/Doc->Scale + float(Doc->ViewX1))
50 #define DOC_Y_FPOS (float(Event->pos().y())/Doc->Scale + float(Doc->ViewY1))
52 #define SCR_X_POS(x) int(float(x - Doc->ViewX1) * Doc->Scale)
53 #define SCR_Y_POS(y) int(float(y - Doc->ViewY1) * Doc->Scale)
67 focusMEvent =
new QMouseEvent(QEvent::MouseButtonPress, QPoint(0,0),
68 Qt::NoButton, Qt::NoButton);
82 p->translate(-Doc->contentsX(), -Doc->contentsY());
85 p->setPen(Qt::DotLine);
86 p->setRasterOp(Qt::NotROP);
92 QClipboard *cb = QApplication::clipboard();
93 QString
s = cb->text(QClipboard::Clipboard);
94 QTextStream stream(&s, IO_ReadOnly);
99 int xmax, xmin, ymax, ymin;
100 xmin = ymin = INT_MAX;
101 xmax = ymax = INT_MIN;
105 if(pe->
x1 < xmin) xmin = pe->
x1;
106 if(pe->
x2 > xmax) xmax = pe->
x2;
107 if(pe->
y1 < ymin) ymin = pe->
y1;
108 if(pe->
y2 > ymax) ymax = pe->
y2;
111 if(pe->
cx < xmin) xmin = pe->
cx;
112 if(pe->
cx > xmax) xmax = pe->
cx;
113 if(pe->
cy < ymin) ymin = pe->
cy;
114 if(pe->
cy > ymax) ymax = pe->
cy;
118 xmin = -((xmax+xmin) >> 1);
119 ymin = -((ymax+ymin) >> 1);
125 pe->
cx += xmin; pe->
x1 += xmin;
126 pe->
cy += ymin; pe->
y1 += ymin;
138 int Result = Dia->exec();
139 if(Result == 0)
return;
141 QString Name = Dia->
NodeName->text();
145 if(Name.isEmpty() && Value.isEmpty()) {
154 if(Result == 1)
return;
159 if(pl->
cx > (pl->
x1+(pl->
x2>>1)))
160 pl->
x1 -= pl->
x2 - old_x2;
164 Doc->viewport()->update();
174 for(pe = movElements->first(); pe!=0; pe = movElements->next()) {
179 if(pe->
y1 == pe->
y2) {
181 if(((
Wire*)pe)->Label) {
183 ((
Wire*)pe)->Label = 0;
213 movElements->clear();
220 Doc->viewport()->update();
230 for(pe = movElements->first(); pe != 0; pe = movElements->next()) {
234 if(((
unsigned long)pw->
Port1) > 3) {
235 pw->
x1 +=
x; pw->
y1 += y;
238 else {
if(
long(pw->
Port1) & 1) { pw->
x1 +=
x; }
239 if(
long(pw->
Port1) & 2) { pw->
y1 += y; } }
241 if(((
unsigned long)pw->
Port2) > 3) { pw->
x2 +=
x; pw->
y2 += y; }
242 else {
if(
long(pw->
Port2) & 1) pw->
x2 += x;
243 if(
long(pw->
Port2) & 2) pw->
y2 += y; }
267 int x = Event->pos().x();
268 int y = Event->pos().y();
276 QPainter painter(Doc->viewport());
280 QPainter paintUnscaled(Doc->viewport());
281 paintUnscaled.setRasterOp(Qt::NotROP);
283 x -= Doc->contentsX();
284 y -= Doc->contentsY();
286 &paintUnscaled, x, y,
drawn);
302 QPainter painter(Doc->viewport());
322 painter.drawLine(
MAx3, MAy2,
MAx2, MAy2);
335 QPainter painter(Doc->viewport());
336 painter.setPen(Qt::DotLine);
337 painter.setRasterOp(Qt::NotROP);
348 MAy3 =
SCR_Y_POS(MAy3) - Doc->contentsY();
350 MAx2 = Doc->visibleWidth();
351 MAy2 = Doc->visibleHeight();
354 painter.drawLine(0, MAy3,
MAx2, MAy3);
362 QPainter painter(Doc->viewport());
381 QPainter painter(Doc->viewport());
394 QPainter painter(Doc->viewport());
406 Doc->viewport()->repaint();
419 else {
if(
long(pw->
Port2) & 1) pw->
x2 += MAx1;
420 if(
long(pw->
Port2) & 2) pw->
y2 += MAy1; }
430 else pe->setCenter(MAx1, MAy1,
true);
432 pe->paintScheme(&painter);
447 QPainter painter(Doc->viewport());
462 if((Event->state() & Qt::ControlButton) == 0)
472 pe->paintScheme(&painter);
485 QPainter painter(Doc->viewport());
509 QPainter p(Doc->viewport());
512 Doc->contentsX(), Doc->contentsY());
523 QPainter painter(Doc->viewport());
524 painter.setRasterOp(Qt::NotROP);
532 MAx3 = Event->pos().x() - Doc->contentsX();
533 MAy3 = Event->pos().y() - Doc->contentsY();
543 QPainter painter(Doc->viewport());
544 painter.setRasterOp(Qt::NotROP);
557 MAx3 = Event->pos().x() - Doc->contentsX();
558 MAy3 = Event->pos().y() - Doc->contentsY();
573 QPainter painter(Doc->viewport());
574 painter.setRasterOp(Qt::NotROP);
583 MAx3 = Event->pos().x() - Doc->contentsX();
584 MAy3 = Event->pos().y() - Doc->contentsY();
596 QPainter painter(Doc->viewport());
597 painter.setRasterOp(Qt::NotROP);
604 painter.drawArc(
MAx3-10,
MAy3-8, 21, 10, 16*20, 16*140);
608 MAx3 = Event->pos().x() - Doc->contentsX();
609 MAy3 = Event->pos().y() - Doc->contentsY();
615 painter.drawArc(
MAx3-10,
MAy3-8, 21, 10, 16*20, 16*140);
623 QPainter painter(Doc->viewport());
624 painter.setRasterOp(Qt::NotROP);
631 painter.drawArc(
MAx3-8,
MAy3-10, 10, 21, 16*110, 16*140);
635 MAx3 = Event->pos().x() - Doc->contentsX();
636 MAy3 = Event->pos().y() - Doc->contentsY();
642 painter.drawArc(
MAx3-8,
MAy3-10, 10, 21, 16*110, 16*140);
649 QPainter painter(Doc->viewport());
650 painter.setRasterOp(Qt::NotROP);
655 painter.drawArc(
MAx3-10,
MAy3-10, 21, 21, -16*20, 16*240);
659 MAx3 = Event->pos().x() - Doc->contentsX();
660 MAy3 = Event->pos().y() - Doc->contentsY();
664 painter.drawArc(
MAx3-10,
MAy3-10, 21, 21, -16*20, 16*240);
671 QPainter painter(Doc->viewport());
672 painter.setRasterOp(Qt::NotROP);
675 painter.drawRect(
MAx3,
MAy3-9, 14, 10);
681 MAx3 = Event->pos().x() - Doc->contentsX();
682 MAy3 = Event->pos().y() - Doc->contentsY();
684 painter.drawRect(
MAx3,
MAy3-9, 14, 10);
693 QPainter painter(Doc->viewport());
694 painter.setRasterOp(Qt::NotROP);
706 MAx3 = Event->pos().x() - Doc->contentsX();
707 MAy3 = Event->pos().y() - Doc->contentsY();
721 QPainter painter(Doc->viewport());
722 painter.setRasterOp(Qt::NotROP);
736 MAx3 = Event->pos().x() - Doc->contentsX();
737 MAy3 = Event->pos().y() - Doc->contentsY();
752 QPainter painter(Doc->viewport());
773 QPainter painter(Doc->viewport());
774 painter.setRasterOp(Qt::NotROP);
779 painter.drawEllipse(
MAx3+12,
MAy3-6, 13, 13);
783 MAx3 = Event->pos().x() - Doc->contentsX();
784 MAy3 = Event->pos().y() - Doc->contentsY();
788 painter.drawEllipse(
MAx3+12,
MAy3-6, 13, 13);
815 QObject::tr(
"Edit Properties"),
QucsMain, SLOT(slotEditElement()));
841 QString
s = QObject::tr(
"power matching");
843 s = QObject::tr(
"noise matching");
847 SLOT(slot2PortMatching()));
883 Doc->viewport()->update();
890 int x = int(fX), y = int(fY);
906 QMessageBox::information(0, QObject::tr(
"Info"),
907 QObject::tr(
"The ground potential cannot be labeled!"));
914 if(Dia->exec() == 0)
return;
920 if(Name.isEmpty() && Value.isEmpty() ) {
946 if(pw) pw->
setName(Name, Value, x-pw->
x1 + y-pw->
y1, xl, yl);
947 else pn->
setName(Name, Value, xl, yl);
951 Doc->viewport()->update();
960 if(Event->state() & Qt::ControlButton) Ctrl =
true;
1005 Doc->grabKeyboard();
1024 Doc->grabKeyboard();
1030 Doc->viewport()->update();
1069 Doc->grabKeyboard();
1070 Doc->viewport()->update();
1099 Doc->viewport()->update();
1117 Doc->viewport()->update();
1127 if(c->
Ports.count() < 1)
return;
1137 Doc->viewport()->update();
1148 if(c->
Ports.count() < 1)
return;
1158 Doc->viewport()->update();
1188 pl = ((
Wire*)e)->Label;
1189 ((
Wire*)e)->Label = 0;
1190 Doc->
Wires->setAutoDelete(
false);
1192 ((
Wire*)e)->Label = pl;
1198 Doc->
Wires->setAutoDelete(
true);
1206 ((
Painting*)e)->Bounding(x1,y1,x2,y2);
1213 Doc->viewport()->update();
1222 QPainter painter(Doc->viewport());
1226 int x1, y1, x2, y2, rot;
1229 switch(Event->button()) {
1230 case Qt::LeftButton :
1235 if(Comp->
tx < Comp->
x1) Comp->
tx -= x2 - x1;
1242 Doc->viewport()->update();
1248 while(rot--) Comp->
rotate();
1251 case Qt::RightButton :
1252 if(Comp->
Ports.count() == 0)
1266 if(Event->button() != Qt::LeftButton)
return;
1273 Info.dirPath() + QDir::separator() + Doc->
DataSet, Doc);
1274 if(dia->exec() == QDialog::Rejected) {
1275 Doc->viewport()->update();
1284 Doc->viewport()->repaint();
1299 Doc->viewport()->update();
1311 QPainter painter(Doc->viewport());
1312 painter.setPen(Qt::DotLine);
1313 painter.setRasterOp(Qt::NotROP);
1337 QPainter painter(Doc->viewport());
1340 int set1 = 0, set2 = 0;
1341 switch(Event->button()) {
1342 case Qt::LeftButton :
1374 Doc->viewport()->update();
1381 case Qt::RightButton :
1423 Doc->viewport()->update();
1439 Doc->viewport()->update();
1456 Doc->viewport()->update();
1460 Doc->grabKeyboard();
1474 Doc->grabKeyboard();
1475 Doc->viewport()->update();
1488 if(Event->state() & Qt::ControlButton) ctrl =
true;
1499 Doc->releaseKeyboard();
1504 Doc->viewport()->update();
1512 if(Event->button() != Qt::LeftButton)
return;
1515 if(Event->state() & Qt::ControlButton) Ctrl =
true;
1521 Doc->releaseKeyboard();
1526 Doc->viewport()->update();
1533 if(Event->button() != Qt::LeftButton)
return;
1542 Doc->viewport()->update();
1553 Doc->releaseKeyboard();
1564 if(Event->button() != Qt::LeftButton)
return;
1594 for(
Marker *pm = pg->Markers.first(); pm!=0; pm = pg->Markers.next()) {
1607 Doc->releaseKeyboard();
1609 Doc->viewport()->update();
1617 if(Event->button() != Qt::LeftButton)
return;
1623 Doc->releaseKeyboard();
1625 Doc->viewport()->update();
1646 pe->
cx += x1; pe->
x1 += x1;
1647 pe->
cy += y1; pe->
y1 += y1;
1672 pe->
x1 = pe->
y1 - y1 + x1;
1673 pe->
y1 = x1 - x2 + y1;
1675 pe->
x2 = pe->
y2 - y1 + x1;
1676 pe->
y2 = x1 - x2 + y1;
1680 ((
Painting*)pe)->getCenter(x2, y2);
1681 pe->
setCenter(y2 - y1 + x1, x1 - x2 + y1);
1694 int x1, y1, x2, y2, rot;
1696 QPainter painter(Doc->viewport());
1699 switch(Event->button()) {
1700 case Qt::LeftButton :
1706 if(pe->x1 == pe->x2)
if(pe->y1 == pe->y2)
break;
1708 if (Doc->
Wires->containsRef ((
Wire*)pe))
1714 ((
Diagram*)pe)->loadGraphData(Info.dirPath() + QDir::separator() +
1716 Doc->
enlargeView(pe->cx, pe->cy-pe->y2, pe->cx+pe->x2, pe->cy);
1720 ((
Painting*)pe)->Bounding(x1,y1,x2,y2);
1749 Doc->viewport()->update();
1754 case Qt::RightButton :
1777 if(Event->button() != Qt::LeftButton)
return;
1781 Doc->releaseKeyboard();
1785 Doc->viewport()->update();
1793 if(Event->button() != Qt::LeftButton)
return;
1795 MAx1 = Event->pos().x();
1796 MAy1 = Event->pos().y();
1799 if((Doc->
Scale * DX) < 6.0) {
1804 MAx1 = int(DX *
float(Event->pos().x()));
1805 MAy1 = int(DX *
float(Event->pos().y()));
1808 float xScale = float(Doc->visibleWidth()) / DX;
1809 float yScale = float(Doc->visibleHeight()) / DY;
1810 if(xScale > yScale) xScale = yScale;
1811 yScale = Doc->
Scale;
1817 MAx1 = int(
float(
MAx1) * xScale) - Doc->contentsX();
1818 MAy1 = int(
float(
MAy1) * xScale) - Doc->contentsY();
1824 Doc->releaseKeyboard();
1852 if(c->
Model ==
"GND")
return;
1854 if(c->
Model ==
"SPICE") {
1856 if(sd->exec() != 1)
break;
1858 else if(c->
Model ==
".Opt") {
1860 if(od->exec() != 1)
break;
1864 if(cd->exec() != 1)
break;
1879 if(dia->
Name.at(0) ==
'T') {
1880 if(dia->
Name ==
"Time") {
1881 if(dia->
cy <
int(fY)) {
1888 if(dia->
cx >
int(fX)) {
1897 Info.dirPath() + QDir::separator() + Doc->
DataSet, Doc);
1898 if(ddia->exec() != QDialog::Rejected)
1909 if(dia->
Graphs.findRef(pg) >= 0)
1915 Info.dirPath() + QDir::separator() + Doc->
DataSet, Doc, pg);
1916 if(ddia->exec() != QDialog::Rejected)
1937 if(mdia->exec() > 1)
1948 Doc->viewport()->update();
1955 Doc->releaseKeyboard();