Skip to content

Commit

Permalink
Able to print diagram independently from markers
Browse files Browse the repository at this point in the history
Diagram::paint() was splitted into two methods: Diagram::painDiagram()
and Diagram::paintMarkers(). It allow to print diagram without markers
and supress marker lines when only diagram is selcted and markers are
outside diagram.
  • Loading branch information
ra3xdh committed Jun 20, 2016
1 parent d721cbf commit c9fcce6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 51 deletions.
109 changes: 59 additions & 50 deletions qucs/qucs/diagrams/diagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,63 +91,72 @@ Diagram::~Diagram()
*/
void Diagram::paint(ViewPainter *p)
{
// paint all lines
foreach(Line *pl, Lines) {
p->Painter->setPen(pl->style);
p->drawLine(cx+pl->x1, cy-pl->y1, cx+pl->x2, cy-pl->y2);
}

// paint all arcs (1 pixel larger to compensate for strange circle method)
foreach(Arc *pa, Arcs) {
p->Painter->setPen(pa->style);
p->drawArc(cx+pa->x, cy-pa->y, pa->w, pa->h, pa->angle, pa->arclen);
}

// draw all graphs
foreach(Graph *pg, Graphs)
pg->paint(p, cx, cy);

// keep track of painter state
p->Painter->save();
paintDiagram(p);
paintMarkers(p);
}

// write whole text (axis label inclusively)
QMatrix wm = p->Painter->worldMatrix();
foreach(Text *pt, Texts) {
p->Painter->setWorldMatrix(
QMatrix(pt->mCos, -pt->mSin, pt->mSin, pt->mCos,
p->DX + float(cx+pt->x) * p->Scale,
p->DY + float(cy-pt->y) * p->Scale));
void Diagram::paintDiagram(ViewPainter *p)
{
// paint all lines
foreach(Line *pl, Lines) {
p->Painter->setPen(pl->style);
p->drawLine(cx+pl->x1, cy-pl->y1, cx+pl->x2, cy-pl->y2);
}

p->Painter->setPen(pt->Color);
p->Painter->drawText(0, 0, pt->s);
}
p->Painter->setWorldMatrix(wm);
p->Painter->setWorldMatrixEnabled(false);
// paint all arcs (1 pixel larger to compensate for strange circle method)
foreach(Arc *pa, Arcs) {
p->Painter->setPen(pa->style);
p->drawArc(cx+pa->x, cy-pa->y, pa->w, pa->h, pa->angle, pa->arclen);
}

// restore painter state
p->Painter->restore();
// draw all graphs
foreach(Graph *pg, Graphs)
pg->paint(p, cx, cy);

// draw markers last, so they are at the top of painting layers
foreach(Graph *pg, Graphs)
foreach(Marker *pm, pg->Markers)
pm->paint(p, cx, cy);
// keep track of painter state
p->Painter->save();

// write whole text (axis label inclusively)
QMatrix wm = p->Painter->worldMatrix();
foreach(Text *pt, Texts) {
p->Painter->setWorldMatrix(
QMatrix(pt->mCos, -pt->mSin, pt->mSin, pt->mCos,
p->DX + float(cx+pt->x) * p->Scale,
p->DY + float(cy-pt->y) * p->Scale));

if(isSelected) {
int x_, y_;
float fx_, fy_;
p->map(cx, cy-y2, x_, y_);
fx_ = float(x2)*p->Scale + 10;
fy_ = float(y2)*p->Scale + 10;
p->Painter->setPen(pt->Color);
p->Painter->drawText(0, 0, pt->s);
}
p->Painter->setWorldMatrix(wm);
p->Painter->setWorldMatrixEnabled(false);

// restore painter state
p->Painter->restore();


if(isSelected) {
int x_, y_;
float fx_, fy_;
p->map(cx, cy-y2, x_, y_);
fx_ = float(x2)*p->Scale + 10;
fy_ = float(y2)*p->Scale + 10;

p->Painter->setPen(QPen(Qt::darkGray,3));
p->Painter->drawRect(x_-5, y_-5, TO_INT(fx_), TO_INT(fy_));
p->Painter->setPen(QPen(Qt::darkRed,2));
p->drawResizeRect(cx, cy-y2); // markers for changing the size
p->drawResizeRect(cx, cy);
p->drawResizeRect(cx+x2, cy-y2);
p->drawResizeRect(cx+x2, cy);
}
}

p->Painter->setPen(QPen(Qt::darkGray,3));
p->Painter->drawRect(x_-5, y_-5, TO_INT(fx_), TO_INT(fy_));
p->Painter->setPen(QPen(Qt::darkRed,2));
p->drawResizeRect(cx, cy-y2); // markers for changing the size
p->drawResizeRect(cx, cy);
p->drawResizeRect(cx+x2, cy-y2);
p->drawResizeRect(cx+x2, cy);
}
void Diagram::paintMarkers(ViewPainter *p, bool paintAll)
{
// draw markers last, so they are at the top of painting layers
foreach(Graph *pg, Graphs)
foreach(Marker *pm, pg->Markers)
if ((pm->Type & 1)||paintAll) pm->paint(p, cx, cy);
}

// ------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions qucs/qucs/diagrams/diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class Diagram : public Element {
virtual QString extraMarkerText(Marker const*) const {return "";}

virtual void paint(ViewPainter*);
void paintDiagram(ViewPainter* p);
void paintMarkers(ViewPainter* p, bool paintAll = true);
void setCenter(int, int, bool relative=false);
void getCenter(int&, int&);
void paintScheme(Schematic*);
Expand Down
3 changes: 2 additions & 1 deletion qucs/qucs/schematic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,8 @@ void Schematic::paintSchToViewpainter(ViewPainter *p, bool printAll, bool toImag

selected = pd->isSelected;
pd->isSelected = false;
pd->paint(p); // paint all selected diagrams with graphs and markers
pd->paintDiagram(p); // paint all selected diagrams with graphs and markers
pd->paintMarkers(p,printAll);
pd->isSelected = selected;

// revert selection of graphs and markers
Expand Down

0 comments on commit c9fcce6

Please sign in to comment.