diff --git a/qucs/components/component.cpp b/qucs/components/component.cpp index 639f6f6ba..ffcea43e7 100644 --- a/qucs/components/component.cpp +++ b/qucs/components/component.cpp @@ -193,13 +193,14 @@ void Component::paint(ViewPainter *p) { int x, y, a, b, xb, yb; QFont f = p->Painter->font(); // save current font QFont newFont = f; + const bool correctSimulator = (Simulator & QucsSettings.DefaultSimulator) == QucsSettings.DefaultSimulator; if (Model.at(0) == '.') { // is simulation component (dc, ac, ...) newFont.setPointSizeF(p->Scale * Texts.first()->Size); newFont.setWeight(QFont::DemiBold); p->Painter->setFont(newFont); p->map(cx, cy, x, y); - if ((Simulator & QucsSettings.DefaultSimulator) == QucsSettings.DefaultSimulator) { + if (correctSimulator) { if ((Model == ".CUSTOMSIM") || (Model == ".DISTO") || (Model == ".NOISE") || (Model == ".PZ") || (Model == ".SENS") || (Model == ".SENS_AC") || @@ -238,75 +239,38 @@ void Component::paint(ViewPainter *p) { p->Painter->drawLine(x + xb - 1, y, a + xb, b); } else { // normal components go here - // paint all lines - for (qucs::Line *p1: Lines) { - if ((Simulator & QucsSettings.DefaultSimulator) == QucsSettings.DefaultSimulator) { - p->Painter->setPen(p1->style); - } else { - p->Painter->setPen(WrongSimulatorPen); - } - p->drawLine(cx + p1->x1, cy + p1->y1, cx + p1->x2, cy + p1->y2); + auto draw_primitive = [&](qucs::DrawingPrimitive* prim, ViewPainter* p) { + p->Painter->setPen(correctSimulator ? prim->penHint() : WrongSimulatorPen); + p->Painter->setBrush(prim->brushHint()); + prim->draw(p, cx, cy); + }; + + for (qucs::DrawingPrimitive *line: Lines) { + draw_primitive(line, p); } - // paint all arcs - for (qucs::Arc *p3: Arcs) { - if ((Simulator & QucsSettings.DefaultSimulator) == QucsSettings.DefaultSimulator) { - p->Painter->setPen(p3->style); - } else { - p->Painter->setPen(WrongSimulatorPen); - } - p->drawArc(cx + p3->x, cy + p3->y, p3->w, p3->h, p3->angle, p3->arclen); + for (qucs::DrawingPrimitive *arc: Arcs) { + draw_primitive(arc, p); } - // paint all rectangles - for (qucs::Area *pa: Rects) { - if ((Simulator & QucsSettings.DefaultSimulator) == QucsSettings.DefaultSimulator) { - p->Painter->setPen(pa->Pen); - } else { - p->Painter->setPen(WrongSimulatorPen); - } - p->Painter->setBrush(pa->Brush); - p->drawRect(cx + pa->x, cy + pa->y, pa->w, pa->h); + for (qucs::DrawingPrimitive *rect: Rects) { + draw_primitive(rect, p); } - // paint all ellipses - for (qucs::Area *pa: Ellips) { - if ((Simulator & QucsSettings.DefaultSimulator) == QucsSettings.DefaultSimulator) { - p->Painter->setPen(pa->Pen); - } else { - p->Painter->setPen(WrongSimulatorPen); - } - p->Painter->setBrush(pa->Brush); - p->drawEllipse(cx + pa->x, cy + pa->y, pa->w, pa->h); + for (qucs::DrawingPrimitive *ellips: Ellipses) { + draw_primitive(ellips, p); } p->Painter->setBrush(Qt::NoBrush); - newFont.setWeight(QFont::Light); - // keep track of painter state p->Painter->save(); QTransform wm = p->Painter->worldTransform(); - // write all text - for (Text *pt: Texts) { - p->Painter->setWorldTransform( - QTransform(pt->mCos, -pt->mSin, pt->mSin, pt->mCos, - p->DX + float(cx + pt->x) * p->Scale, - p->DY + float(cy + pt->y) * p->Scale)); - newFont.setPointSizeF(p->Scale * pt->Size); - newFont.setOverline(pt->over); - newFont.setUnderline(pt->under); - p->Painter->setFont(newFont); - if ((Simulator & QucsSettings.DefaultSimulator) == QucsSettings.DefaultSimulator) { - p->Painter->setPen(pt->Color); - } else { - p->Painter->setPen(WrongSimulatorPen); - } - int w, h; - w = p->drawTextMapped(pt->s, 0, 0, &h); - Q_UNUSED(w) - Q_UNUSED(h) + + for (qucs::DrawingPrimitive *text: Texts) { + draw_primitive(text, p); } + p->Painter->setWorldTransform(wm); p->Painter->setWorldMatrixEnabled(false); @@ -373,50 +337,41 @@ void Component::paintIcon(QPixmap *pixmap) p->drawEllipse(cx+pp->x-2,cy+pp->y-2,4,4); } - for (qucs::Line *p1: Lines) { - p1->style.setWidth(3); - p->Painter->setPen(p1->style); - p->drawLine(cx + p1->x1, cy + p1->y1, cx + p1->x2, cy + p1->y2); + for (qucs::DrawingPrimitive *line: Lines) { + auto pen = line->penHint(); + pen.setWidth(3); + p->Painter->setPen(pen); + line->draw(p, cx, cy); } // paint all arcs - for (qucs::Arc *p3: Arcs) { - p3->style.setWidth(3); - p->Painter->setPen(p3->style); - p->drawArc(cx + p3->x, cy + p3->y, p3->w, p3->h, p3->angle, p3->arclen); + for (qucs::DrawingPrimitive *arc: Arcs) { + auto pen = arc->penHint(); + pen.setWidth(3); + p->Painter->setPen(pen); + arc->draw(p, cx, cy); } // paint all rectangles - for (qucs::Area *pa: Rects) { - pa->Pen.setWidth(3); - p->Painter->setPen(pa->Pen); - p->Painter->setBrush(pa->Brush); - p->drawRect(cx + pa->x, cy + pa->y, pa->w, pa->h); + for (qucs::DrawingPrimitive *rect: Rects) { + auto pen = rect->penHint(); + pen.setWidth(3); + p->Painter->setPen(pen); + p->Painter->setBrush(rect->brushHint()); + rect->draw(p, cx, cy); } // paint all ellipses - for (qucs::Area *pa: Ellips) { - p->Painter->setPen(pa->Pen); - p->Painter->setBrush(pa->Brush); - p->drawEllipse(cx + pa->x, cy + pa->y, pa->w, pa->h); + for (qucs::DrawingPrimitive *ellipse: Ellipses) { + p->Painter->setPen(ellipse->penHint()); + p->Painter->setBrush(ellipse->brushHint()); + ellipse->draw(p, cx, cy); } - p->Painter->setBrush(Qt::NoBrush); - newFont.setWeight(QFont::Light); - - for (Text *pt: Texts) { - p->Painter->setWorldTransform( - QTransform(pt->mCos, -pt->mSin, pt->mSin, pt->mCos, - p->DX + float(cx + pt->x) * p->Scale, - p->DY + float(cy + pt->y) * p->Scale)); - newFont.setPointSizeF(p->Scale * pt->Size); - newFont.setOverline(pt->over); - newFont.setUnderline(pt->under); - p->Painter->setFont(newFont); - p->Painter->setPen(pt->Color); - w = p->drawTextMapped(pt->s, 0, 0, &h); - Q_UNUSED(w) - Q_UNUSED(h) + for (qucs::DrawingPrimitive *text: Texts) { + p->Painter->setPen(text->penHint()); + p->Painter->setBrush(text->brushHint()); + text->draw(p, cx, cy); } } } @@ -482,10 +437,10 @@ void Component::paintScheme(Schematic *p) { p->PostPaintEvent(_Arc, cx + p3->x, cy + p3->y, p3->w, p3->h, p3->angle, p3->arclen); - for (qucs::Area *pa: Rects) // paint all rectangles + for (qucs::Rect *pa: Rects) // paint all rectangles p->PostPaintEvent(_Rect, cx + pa->x, cy + pa->y, pa->w, pa->h); - for (qucs::Area *pa: Ellips) // paint all ellipses + for (qucs::Ellips *pa: Ellipses) // paint all ellipses p->PostPaintEvent(_Ellipse, cx + pa->x, cy + pa->y, pa->w, pa->h); } @@ -540,7 +495,7 @@ void Component::rotate() { } // rotate all rectangles - for (qucs::Area *pa: Rects) { + for (qucs::Rect *pa: Rects) { tmp = -pa->x; pa->x = pa->y; pa->y = tmp - pa->w; @@ -550,7 +505,7 @@ void Component::rotate() { } // rotate all ellipses - for (qucs::Area *pa: Ellips) { + for (qucs::Ellips *pa: Ellipses) { tmp = -pa->x; pa->x = pa->y; pa->y = tmp - pa->w; @@ -638,11 +593,11 @@ void Component::mirrorX() { } // mirror all rectangles - for (qucs::Area *pa: Rects) + for (qucs::Rect *pa: Rects) pa->y = -pa->y - pa->h; // mirror all ellipses - for (qucs::Area *pa: Ellips) + for (qucs::Ellips *pa: Ellipses) pa->y = -pa->y - pa->h; QFont f = QucsSettings.font; @@ -699,11 +654,11 @@ void Component::mirrorY() { } // mirror all rectangles - for (qucs::Area *pa: Rects) + for (qucs::Rect *pa: Rects) pa->x = -pa->x - pa->w; // mirror all ellipses - for (qucs::Area *pa: Ellips) + for (qucs::Ellips *pa: Ellipses) pa->x = -pa->x - pa->w; int tmp; @@ -1278,7 +1233,7 @@ int Component::analyseLine(const QString &Row, int numProps) { if (!getIntegers(Row, &i1, &i2, &i3, &i4)) return -1; if (!getPen(Row, Pen, 5)) return -1; if (!getBrush(Row, Brush, 8)) return -1; - Ellips.append(new qucs::Area(i1, i2, i3, i4, Pen, Brush)); + Ellipses.append(new qucs::Ellips(i1, i2, i3, i4, Pen, Brush)); if (i1 < x1) x1 = i1; // keep track of component boundings if (i1 > x2) x2 = i1; @@ -1293,7 +1248,7 @@ int Component::analyseLine(const QString &Row, int numProps) { if (!getIntegers(Row, &i1, &i2, &i3, &i4)) return -1; if (!getPen(Row, Pen, 5)) return -1; if (!getBrush(Row, Brush, 8)) return -1; - Rects.append(new qucs::Area(i1, i2, i3, i4, Pen, Brush)); + Rects.append(new qucs::Rect(i1, i2, i3, i4, Pen, Brush)); if (i1 < x1) x1 = i1; // keep track of component boundings if (i1 > x2) x2 = i1; @@ -1461,7 +1416,7 @@ void Component::copyComponent(Component *pc) { Lines = pc->Lines; Arcs = pc->Arcs; Rects = pc->Rects; - Ellips = pc->Ellips; + Ellipses = pc->Ellipses; Texts = pc->Texts; } @@ -1477,7 +1432,7 @@ void MultiViewComponent::recreate(Schematic *Doc) { Doc->deleteComp(this); } - Ellips.clear(); + Ellipses.clear(); Texts.clear(); Ports.clear(); Lines.clear(); @@ -1717,7 +1672,7 @@ void GateComponent::createSymbol() { Texts.append(new Text(-10, 3 - y, "&", Qt::darkBlue, 15.0)); else if (Model.at(0) == 'X') { if (Model.at(1) == 'N') { - Ellips.append(new qucs::Area(xr, -4, 8, 8, + Ellipses.append(new qucs::Ellips(xr, -4, 8, 8, QPen(Qt::darkBlue, 0), QBrush(Qt::darkBlue))); Texts.append(new Text(-11, 3 - y, "=1", Qt::darkBlue, 15.0)); } else @@ -1747,7 +1702,7 @@ void GateComponent::createSymbol() { } if (Model.at(0) == 'N') - Ellips.append(new qucs::Area(xr, -4, 8, 8, + Ellipses.append(new qucs::Ellips(xr, -4, 8, 8, QPen(Qt::darkBlue, 0), QBrush(Qt::darkBlue))); Ports.append(new Port(30, 0)); diff --git a/qucs/components/component.h b/qucs/components/component.h index 3b1979c8c..a20f2b4af 100644 --- a/qucs/components/component.h +++ b/qucs/components/component.h @@ -83,8 +83,8 @@ class Component : public Element { QList Lines; QList Arcs; - QList Rects; - QList Ellips; + QList Rects; + QList Ellipses; QList Ports; QList Texts; Q3PtrList Props; diff --git a/qucs/components/logical_inv.cpp b/qucs/components/logical_inv.cpp index 16292b8c6..d505efd3c 100644 --- a/qucs/components/logical_inv.cpp +++ b/qucs/components/logical_inv.cpp @@ -122,7 +122,7 @@ void Logical_Inv::createSymbol() xr = 10; } - Ellips.append(new qucs::Area(xr,-4, 8, 8, + Ellipses.append(new qucs::Ellips(xr,-4, 8, 8, QPen(Qt::darkBlue,0), QBrush(Qt::darkBlue))); Lines.append(new qucs::Line( xr, 0, 30, 0, QPen(Qt::darkBlue,2))); diff --git a/qucs/components/relais.cpp b/qucs/components/relais.cpp index 2a82c68a3..5b8eab11f 100644 --- a/qucs/components/relais.cpp +++ b/qucs/components/relais.cpp @@ -43,7 +43,7 @@ Relais::Relais() Lines.append(new qucs::Line( 30, 15, 30, 30,QPen(Qt::darkBlue,2))); Lines.append(new qucs::Line( 30, 15, 45,-15,QPen(Qt::darkBlue,2))); Arcs.append(new qucs::Arc( 27,-18, 5, 5, 0, 16*360,QPen(Qt::darkBlue,2))); - Ellips.append(new qucs::Area( 27, 12, 6, 6, QPen(Qt::darkBlue,2), + Ellipses.append(new qucs::Ellips( 27, 12, 6, 6, QPen(Qt::darkBlue,2), QBrush(Qt::darkBlue, Qt::SolidPattern))); Ports.append(new Port(-30,-30)); diff --git a/qucs/components/switch.cpp b/qucs/components/switch.cpp index 42cba67ea..b65a6410d 100644 --- a/qucs/components/switch.cpp +++ b/qucs/components/switch.cpp @@ -176,7 +176,7 @@ void Switch::createSymbol() Lines.append(new qucs::Line(-30, 0,-15, 0,QPen(Qt::darkBlue,2))); Lines.append(new qucs::Line( 17, 0, 30, 0,QPen(Qt::darkBlue,2))); Arcs.append(new qucs::Arc( 12, -3, 5, 5, 0, 16*360,QPen(Qt::darkBlue,2))); - Ellips.append(new qucs::Area(-18, -3, 6, 6, QPen(Qt::darkBlue,2), + Ellipses.append(new qucs::Ellips(-18, -3, 6, 6, QPen(Qt::darkBlue,2), QBrush(Qt::darkBlue, Qt::SolidPattern))); Ports.append(new Port(-30, 0)); diff --git a/qucs/components/vacomponent.cpp b/qucs/components/vacomponent.cpp index 94a4eb425..85d80f7f5 100644 --- a/qucs/components/vacomponent.cpp +++ b/qucs/components/vacomponent.cpp @@ -219,7 +219,7 @@ void vacomponent::createSymbol(QJsonObject json) colorfill = getString(paint, "colorfill"); stylefill = getString(paint, "stylefill"); - Rects.append (new qucs::Area (x, y, w, h, + Rects.append (new qucs::Rect (x, y, w, h, QPen (QColor (color), thick, penMap.value(style)), QBrush(QColor (colorfill), brushMap.value(stylefill)) )); @@ -236,7 +236,7 @@ void vacomponent::createSymbol(QJsonObject json) colorfill = getString(paint, "colorfill"); stylefill = getString(paint, "stylefill"); - Ellips.append (new qucs::Area (x, y, w, h, + Ellipses.append (new qucs::Ellips (x, y, w, h, QPen (QColor (color), thick, penMap.value(style)), QBrush(QColor (colorfill), brushMap.value(stylefill)) )); diff --git a/qucs/diagrams/diagram.cpp b/qucs/diagrams/diagram.cpp index c5e42a597..e0f3d7fbe 100644 --- a/qucs/diagrams/diagram.cpp +++ b/qucs/diagrams/diagram.cpp @@ -104,16 +104,22 @@ void Diagram::paint(ViewPainter *p) { } void Diagram::paintDiagram(ViewPainter *p) { + // Drawing primitives in Diagram have their coordinates + // as if they exist in space where Y-axis oriented upwards + // in contrast to downwards-oriented Y-axis of ViewPainter. + // We need to pass this flag to draw primitives correctly. + const bool y_directed_upwards = true; + // paint all lines - for (qucs::Line *pl: Lines) { - p->Painter->setPen(pl->style); - p->drawLine(cx + pl->x1, cy - pl->y1, cx + pl->x2, cy - pl->y2); + for (qucs::DrawingPrimitive* line : Lines) { + p->Painter->setPen(line->penHint()); + line->draw(p, cx, cy, y_directed_upwards); } // paint all arcs (1 pixel larger to compensate for strange circle method) - for (qucs::Arc *pa: Arcs) { - p->Painter->setPen(pa->style); - p->drawArc(cx + pa->x, cy - pa->y, pa->w, pa->h, pa->angle, pa->arclen); + for (qucs::DrawingPrimitive* arc : Arcs) { + p->Painter->setPen(arc->penHint()); + arc->draw(p, cx, cy, y_directed_upwards); } // draw all graphs diff --git a/qucs/diagrams/tabdiagram.cpp b/qucs/diagrams/tabdiagram.cpp index 5bcc6d4e8..2397cbcb0 100644 --- a/qucs/diagrams/tabdiagram.cpp +++ b/qucs/diagrams/tabdiagram.cpp @@ -55,9 +55,9 @@ void TabDiagram::paint(ViewPainter *p) void TabDiagram::paintDiagram(ViewPainter *p) { // paint all lines - for (qucs::Line *pl : Lines) { - p->Painter->setPen(pl->style); - p->drawLine(cx+pl->x1, cy-pl->y1, cx+pl->x2, cy-pl->y2); + for (qucs::DrawingPrimitive* line : Lines) { + p->Painter->setPen(line->penHint()); + line->draw(p, cx, cy, true); } if(x1 > 0) { // paint scroll bar ? diff --git a/qucs/diagrams/timingdiagram.cpp b/qucs/diagrams/timingdiagram.cpp index 181ab5aee..cdfcb1563 100644 --- a/qucs/diagrams/timingdiagram.cpp +++ b/qucs/diagrams/timingdiagram.cpp @@ -54,9 +54,9 @@ void TimingDiagram::paint(ViewPainter *p) void TimingDiagram::paintDiagram(ViewPainter *p) { // paint all lines - for(qucs::Line *pl : Lines) { - p->Painter->setPen(pl->style); - p->drawLine(cx+pl->x1, cy-pl->y1, cx+pl->x2, cy-pl->y2); + for(qucs::DrawingPrimitive* line : Lines) { + p->Painter->setPen(line->penHint()); + line->draw(p, cx, cy, true); } p->Painter->setPen(Qt::black); diff --git a/qucs/element.cpp b/qucs/element.cpp index 37f85b0f7..b680b6f51 100644 --- a/qucs/element.cpp +++ b/qucs/element.cpp @@ -17,6 +17,103 @@ #include "element.h" +namespace qucs { + +void Line::draw(ViewPainter* painter, int cx, int cy, bool y_grows_up) const { + // For explanation please refer to parent class doc + if (y_grows_up) { + painter->drawLine(cx + x1, cy - y1, cx + x2, cy - y2); + } else { + painter->drawLine(cx + x1, cy + y1, cx + x2, cy + y2); + } +} + +void Line::draw(QPainter* painter, int cx, int cy, bool y_grows_up) const { + // For explanation please refer to parent class doc + if (y_grows_up) { + painter->drawLine(cx + x1, cy - y1, cx + x2, cy - y2); + } else { + painter->drawLine(cx + x1, cy + y1, cx + x2, cy + y2); + } +} + +void Arc::draw(ViewPainter* painter, int cx, int cy, bool y_grows_up) const { + // For explanation please refer to parent class doc + if (y_grows_up) { + painter->drawArc(cx + x, cy - y, w, h, angle, arclen); + } else { + painter->drawArc(cx + x, cy + y, w, h, angle, arclen); + } +} + +void Arc::draw(QPainter* painter, int cx, int cy, bool y_grows_up) const { + // For explanation please refer to parent class doc + if (y_grows_up) { + painter->drawArc(cx + x, cy - y, w, h, angle, arclen); + } else { + painter->drawArc(cx + x, cy + y, w, h, angle, arclen); + } +} + +void Rect::draw(ViewPainter* painter, int cx, int cy, bool y_grows_up) const { + // For explanation please refer to parent class doc + if (y_grows_up) { + painter->drawRect(cx + x, cy - y, w, h); + } else { + painter->drawRect(cx + x, cy + y, w, h); + } +} + +void Rect::draw(QPainter* painter, int cx, int cy, bool y_grows_up) const { + // For explanation please refer to parent class doc + if (y_grows_up) { + painter->drawRect(cx + x, cy - y, w, h); + } else { + painter->drawRect(cx + x, cy + y, w, h); + } +} + +void Ellips::draw(ViewPainter* painter, int cx, int cy, bool y_grows_up) const { + // For explanation please refer to parent class doc + if (y_grows_up) { + painter->drawEllipse(cx + x, cy - y, w, h); + } else { + painter->drawEllipse(cx + x, cy + y, w, h); + } +} + +void Ellips::draw(QPainter* painter, int cx, int cy, bool y_grows_up) const { + // For explanation please refer to parent class doc + if (y_grows_up) { + painter->drawEllipse(cx + x, cy - y, w, h); + } else { + painter->drawEllipse(cx + x, cy + y, w, h); + } +} + +} // namespace qucs + +void Text::draw(ViewPainter *painter, int cx, int cy, bool) const { + painter->Painter->save(); + + QFont newFont = painter->Painter->font(); + newFont.setWeight(QFont::Light); + newFont.setPointSizeF(painter->Scale * Size); + newFont.setOverline(over); + newFont.setUnderline(under); + painter->Painter->setFont(newFont); + + painter->Painter->setWorldTransform( + QTransform(mCos, -mSin, mSin, mCos, + painter->DX + float(cx + x) * painter->Scale, + painter->DY + float(cy + y) * painter->Scale)); + + painter->drawTextMapped(s, 0, 0); + + painter->Painter->restore(); +} + + Element::Element() { Type = isDummyElement; diff --git a/qucs/element.h b/qucs/element.h index 6e6676f9c..fb7462416 100644 --- a/qucs/element.h +++ b/qucs/element.h @@ -37,39 +37,102 @@ #ifndef ELEMENT_H #define ELEMENT_H +#include "viewpainter.h" +#include #include #include class Node; -class QPainter; class WireLabel; class Schematic; namespace qucs { // otherwise conflict with // coming from Qt5 headers -struct Line { +class DrawingPrimitive { +public: + /** + Draws a primitive using given @c ViewPainter + + Params @c cx and @c cy define offset on corresponding axis. Actually, the + proper way to offset primitive coordinates is to use "translate" mechanism + of QPainter, but historically Qucs-S codebase doesn't use it, relying + instead on manual control of offsets. I think this something what should be + refactored; lines, ellipses, etc. should not be aware of any "offsets". + + Boolean switch @c y_grows_up tells whether Y-axis coordinates of + primitive should be treated as if they are defined in space where the + Y-axis directed upwards or downwards. Painting devices like QPainter or + ViewPainter always operate in space where Y-axis directed downwards, but + drawing primitives maybe defined with upwards Y-axis in mind, so to draw + them correctly this switch must be used. Inheriting implementations MUST + take this switch into account and alter their drawing logic accordingly. + This is actually a workaround for a couple of cases. Diagram and some + of its subclasses define a handful of primitives in upwards Y-axis space + (I believe it's easier to reason about lines, rectangles, etc. that way when + you drawing a diagram). It should be refactored in future: that's a painting + device liability change orientation, calculate offsets, etc. Drawing + primitives should concentrate on drawing only. + + @param cx offset on X-axis + @param cy offset on Y-axis + @param y_grows_up Y-axis orientation switch + */ + virtual void draw([[maybe_unused]] ViewPainter* painter, [[maybe_unused]] int cx, [[maybe_unused]] int cy, [[maybe_unused]] bool y_grows_up=false) const {}; + /** + The same as the version with @c ViewPainter, but with @c QPainter + */ + virtual void draw([[maybe_unused]] QPainter* painter, [[maybe_unused]] int cx, [[maybe_unused]] int cy, [[maybe_unused]] bool y_grows_up=false) const {}; + virtual QBrush brushHint() const { return Qt::NoBrush; } + virtual QPen penHint() const { return Qt::NoPen; } +}; + +struct Line : DrawingPrimitive { Line(int _x1, int _y1, int _x2, int _y2, QPen _style) : x1(_x1), y1(_y1), x2(_x2), y2(_y2), style(_style) {}; int x1, y1, x2, y2; QPen style; + void draw(ViewPainter* painter, int cx, int cy, bool y_grows_up=false) const override; + void draw(QPainter* painter, int cx, int cy, bool y_grows_up=false) const override; + QPen penHint() const override { return style; } }; -struct Arc { +struct Arc : DrawingPrimitive { Arc(int _x, int _y, int _w, int _h, int _angle, int _arclen, QPen _style) : x(_x), y(_y), w(_w), h(_h), angle(_angle), arclen(_arclen), style(_style) {}; int x, y, w, h, angle, arclen; QPen style; + void draw(ViewPainter* painter, int cx, int cy, bool y_grows_up=false) const override; + void draw(QPainter* painter, int cx, int cy, bool y_grows_up=false) const override; + QPen penHint() const override { return style; } +}; + +struct Rect : DrawingPrimitive { + Rect(int _x, int _y, int _w, int _h, QPen _Pen, + QBrush _Brush = QBrush(Qt::NoBrush)) + : x(_x), y(_y), w(_w), h(_h), Pen(_Pen), Brush(_Brush) {}; + int x, y, w, h; + QPen Pen; + QBrush Brush; // filling style/color + void draw(ViewPainter* painter, int cx, int cy, bool y_grows_up=false) const override; + void draw(QPainter* painter, int cx, int cy, bool y_grows_up=false) const override; + QPen penHint() const override { return Pen; } + QBrush brushHint() const override { return Brush; } }; -struct Area { - Area(int _x, int _y, int _w, int _h, QPen _Pen, +// 'ellipse' conflicts 'ellipse' defined in paintings.h in the same namespace +struct Ellips : DrawingPrimitive { + Ellips(int _x, int _y, int _w, int _h, QPen _Pen, QBrush _Brush = QBrush(Qt::NoBrush)) : x(_x), y(_y), w(_w), h(_h), Pen(_Pen), Brush(_Brush) {}; int x, y, w, h; QPen Pen; QBrush Brush; // filling style/color + void draw(ViewPainter* painter, int cx, int cy, bool y_grows_up=false) const override; + void draw(QPainter* painter, int cx, int cy, bool y_grows_up=false) const override; + QPen penHint() const override { return Pen; } + QBrush brushHint() const override { return Brush; } }; } @@ -84,7 +147,7 @@ struct Port { Node *Connection; }; -struct Text { +struct Text : qucs::DrawingPrimitive { Text(int _x, int _y, const QString& _s, QColor _Color = QColor(0,0,0), float _Size = 10.0, float _mCos=1.0, float _mSin=0.0) : x(_x), y(_y), s(_s), Color(_Color), Size(_Size), @@ -94,6 +157,8 @@ struct Text { QColor Color; float Size, mSin, mCos; // font size and rotation coefficients bool over, under; // text attributes + void draw(ViewPainter* painter, int cx, int cy, bool y_grows_up=false) const override; + QPen penHint() const override { return Color; } }; struct Property { diff --git a/qucs/main.cpp b/qucs/main.cpp index d024d7a95..bb549734d 100644 --- a/qucs/main.cpp +++ b/qucs/main.cpp @@ -578,8 +578,8 @@ void createIcons() { QList Lines = c->Lines; QList Arcs = c-> Arcs; - QList Rects = c-> Rects; - QList Ellips = c-> Ellips; + QList Rects = c-> Rects; + QList Ellips = c-> Ellipses; QList Ports = c->Ports; QList Texts = c->Texts; @@ -598,11 +598,11 @@ void createIcons() { scene->addPath(*path); } - for(qucs::Area *a: Rects) { + for(qucs::Rect *a: Rects) { scene->addRect(a->x, a->y, a->w, a->h, a->Pen, a->Brush); } - for(qucs::Area *a: Ellips) { + for(qucs::Ellips *a: Ellips) { scene->addEllipse(a->x, a->y, a->w, a->h, a->Pen, a->Brush); } diff --git a/qucs/symbolwidget.cpp b/qucs/symbolwidget.cpp index 3b6cc8ca6..415466c2e 100644 --- a/qucs/symbolwidget.cpp +++ b/qucs/symbolwidget.cpp @@ -130,33 +130,29 @@ void SymbolWidget::paintEvent(QPaintEvent*) Painter.drawText(dx, y2-y1+2, 0, 0, Qt::AlignLeft | Qt::TextDontClip, DragNDropText); // paint all lines - for(int i=0; istyle); - Painter.drawLine(cx+pl->x1, cy+pl->y1, cx+pl->x2, cy+pl->y2); + for (auto* line : Lines) { + Painter.setPen(line->penHint()); + line->draw(&Painter, cx, cy); } // paint all arcs - for(int i=0; istyle); - Painter.drawArc(cx+pc->x, cy+pc->y, pc->w, pc->h, pc->angle, pc->arclen); + for (auto* arc : Arcs) { + Painter.setPen(arc->penHint()); + arc->draw(&Painter, cx, cy); } // paint all rectangles - for(int i=0; iPen); - Painter.setBrush(pa->Brush); - Painter.drawRect(cx+pa->x, cy+pa->y, pa->w, pa->h); + for (auto* rect : Rects) { + Painter.setPen(rect->penHint()); + Painter.setBrush(rect->brushHint()); + rect->draw(&Painter, cx, cy); } // paint all ellipses - for(int i=0; iPen); - Painter.setBrush(pa->Brush); - Painter.drawEllipse(cx+pa->x, cy+pa->y, pa->w, pa->h); + for (auto* ellipse : Ellipses) { + Painter.setPen(ellipse->penHint()); + Painter.setBrush(ellipse->brushHint()); + ellipse->draw(&Painter, cx, cy); } Painter.setPen(QPen(Qt::black,1)); @@ -183,7 +179,7 @@ int SymbolWidget::createStandardSymbol(const QString& Lib_, const QString& Comp_ Arcs.clear(); Lines.clear(); Rects.clear(); - Ellips.clear(); + Ellipses.clear(); Texts.clear(); LibraryPath = Lib_; ComponentName = Comp_; @@ -415,7 +411,7 @@ int SymbolWidget::setSymbol( QString& SymbolString, Arcs.clear(); Lines.clear(); Rects.clear(); - Ellips.clear(); + Ellipses.clear(); Texts.clear(); LibraryPath = Lib_; ComponentName = Comp_; @@ -562,7 +558,7 @@ int SymbolWidget::analyseLine(const QString& Row) if(!getCompLineIntegers(Row, &i1, &i2, &i3, &i4)) return -1; if(!getPen(Row, Pen, 5)) return -1; if(!getBrush(Row, Brush, 8)) return -1; - Ellips.append(new qucs::Area(i1, i2, i3, i4, Pen, Brush)); + Ellipses.append(new qucs::Ellips(i1, i2, i3, i4, Pen, Brush)); if(i1 < x1) x1 = i1; // keep track of component boundings if(i1 > x2) x2 = i1; @@ -578,7 +574,7 @@ int SymbolWidget::analyseLine(const QString& Row) if(!getCompLineIntegers(Row, &i1, &i2, &i3, &i4)) return -1; if(!getPen(Row, Pen, 5)) return -1; if(!getBrush(Row, Brush, 8)) return -1; - Rects.append(new qucs::Area(i1, i2, i3, i4, Pen, Brush)); + Rects.append(new qucs::Rect(i1, i2, i3, i4, Pen, Brush)); if(i1 < x1) x1 = i1; // keep track of component boundings if(i1 > x2) x2 = i1; diff --git a/qucs/symbolwidget.h b/qucs/symbolwidget.h index b38e418f1..45f609e4a 100644 --- a/qucs/symbolwidget.h +++ b/qucs/symbolwidget.h @@ -77,7 +77,8 @@ class SymbolWidget : public QWidget { int cx, cy, x1, x2, y1, y2; QList Lines; QList Arcs; - QList Rects, Ellips; + QList Rects; + QList Ellipses; QList Texts; };