void Paintbox::refreshBrushPreview() { if (item != NULL) brush_viewer->scene()->removeItem(item); item = brush_viewer->scene()->addPixmap(QPixmap::fromImage( raster(getBrush(), (int) ((brush_viewer->width()-2) * size_slider->value() / 100.0), (int)((brush_viewer->height()-2) * size_slider->value() / 100.0), getHardness()) ) ); brush_viewer->setSceneRect(item->boundingRect()); }
void fillItemFromPolygon(QGraphicsItemGroup *item, const CLBoundingBox *pBB, const CLPolygon* pPoly, const CLGroup *group, const CLRenderResolver* resolver) { QPainterPath& path = *getPath(pPoly, pBB); path.setFillRule(Qt::WindingFill); if (pPoly->isSetFillRule()) { switch (pPoly->getFillRule()) { case CLGraphicalPrimitive2D::EVENODD: path.setFillRule(Qt::OddEvenFill); break; case CLGraphicalPrimitive2D::NONZERO: default: path.setFillRule(Qt::WindingFill); break; } } if (group->isSetFillRule()) { switch (group->getFillRule()) { case CLGraphicalPrimitive2D::EVENODD: path.setFillRule(Qt::OddEvenFill); break; case CLGraphicalPrimitive2D::NONZERO: default: path.setFillRule(Qt::WindingFill); break; } } QGraphicsPathItem *pathItem = new QGraphicsPathItem(path); QPen *pen = getPen(pPoly, group, resolver, pBB); pathItem->setPen(*pen); delete pen; QBrush *brush = getBrush(pPoly, group, resolver, pBB); pathItem->setBrush(*brush); delete brush; transform(pathItem, pPoly, group); item->addToGroup(pathItem); }
void fillItemFromEllipse(QGraphicsItemGroup *item, const CLBoundingBox *pBB, const CLEllipse *pEllipse, const CLGroup *group, const CLRenderResolver* resolver) { double x = pBB->getPosition().getX() + pEllipse->getCX().getAbsoluteValue() + pEllipse->getCX().getRelativeValue() / 100.0 * pBB->getDimensions().getWidth(); double y = pBB->getPosition().getY() + pEllipse->getCY().getAbsoluteValue() + pEllipse->getCY().getRelativeValue() / 100.0 * pBB->getDimensions().getHeight(); double rx = pEllipse->getRX().getAbsoluteValue() + pEllipse->getRX().getRelativeValue() / 100.0 * pBB->getDimensions().getWidth(); double ry = pEllipse->getRY().getAbsoluteValue() + pEllipse->getRY().getRelativeValue() / 100.0 * pBB->getDimensions().getHeight(); QGraphicsEllipseItem* ellipseItem = new QGraphicsEllipseItem( x - rx, y - ry, rx * 2, ry * 2); QPen *pen = getPen(pEllipse, group, resolver, pBB); ellipseItem->setPen(*pen); delete pen; QBrush *brush = getBrush(pEllipse, group, resolver, pBB); ellipseItem->setBrush(*brush); delete brush; transform(ellipseItem, pEllipse, group); item->addToGroup(ellipseItem); }
void fillItemFromRectangle(QGraphicsItemGroup *item, const CLBoundingBox *pBB, const CLRectangle *pRect, const CLGroup *group, const CLRenderResolver* resolver) { double x = pBB->getPosition().getX() + pRect->getX().getAbsoluteValue() + pRect->getX().getRelativeValue() / 100.0 * pBB->getDimensions().getWidth(); double y = pBB->getPosition().getY() + pRect->getY().getAbsoluteValue() + pRect->getY().getRelativeValue() / 100.0 * pBB->getDimensions().getHeight(); double w = pRect->getWidth().getAbsoluteValue() + pRect->getWidth().getRelativeValue() / 100.0 * pBB->getDimensions().getWidth(); double h = pRect->getHeight().getAbsoluteValue() + pRect->getHeight().getRelativeValue() / 100.0 * pBB->getDimensions().getHeight(); double rx = pRect->getRadiusX().getAbsoluteValue() + pRect->getRadiusX().getRelativeValue() / 100.0 * pBB->getDimensions().getWidth(); double ry = pRect->getRadiusY().getAbsoluteValue() + pRect->getRadiusY().getRelativeValue() / 100.0 * pBB->getDimensions().getHeight(); QGraphicsRectItem* result = new QRoundedRect( x, y, w, h, rx, ry); QPen *pen = getPen(pRect, group, resolver, pBB); result->setPen(*pen); delete pen; QBrush *brush = getBrush(pRect, group, resolver, pBB); result->setBrush(*brush); delete brush; transform(result, pRect, group); item->addToGroup(result); }
void addLineEndingToItem(QGraphicsPathItem* item, const CLLineEnding* ending, const CLGroup* group, const CLRenderResolver* resolver, QPointF point, QPointF second, QGraphicsItemGroup* itemGroup) { const CLGroup* lineGroup = ending->getGroup(); for (size_t i = 0; i < lineGroup->getNumElements(); ++i) { const CLPolygon* poly = dynamic_cast<const CLPolygon*>(lineGroup->getElement(i)); const CLRenderCurve* rcurve = dynamic_cast<const CLRenderCurve*>(lineGroup->getElement(i)); const CLEllipse* ellipse = dynamic_cast<const CLEllipse*>(lineGroup->getElement(i)); const CLRectangle* rect = dynamic_cast<const CLRectangle*>(lineGroup->getElement(i)); if (rcurve != NULL) { QPainterPath path = item->path(); QPainterPath& linePath = *getPath(rcurve, ending->getBoundingBox()); applyRotationalMapping(linePath, ending, point, second); linePath.translate(point); path.addPath(linePath); item->setPath(path); } else if (poly != NULL) { QPainterPath path = item->path(); QPainterPath& linePath = *getPath(poly, ending->getBoundingBox()); applyRotationalMapping(linePath, ending, point, second); linePath.translate(point); path.addPath(linePath); item->setPath(path); if (poly->isSetFill() || group->isSetFill()) { QBrush* brush = getBrush(poly, ending->getGroup(), resolver, ending->getBoundingBox()); QPen* pen = getPen(poly, ending->getGroup(), resolver, ending->getBoundingBox()); linePath.setFillRule(Qt::WindingFill); if (poly->isSetFillRule()) { switch (poly->getFillRule()) { case CLGraphicalPrimitive2D::EVENODD: linePath.setFillRule(Qt::OddEvenFill); break; case CLGraphicalPrimitive2D::NONZERO: default: linePath.setFillRule(Qt::WindingFill); break; } } if (group->isSetFillRule()) { switch (group->getFillRule()) { case CLGraphicalPrimitive2D::EVENODD: linePath.setFillRule(Qt::OddEvenFill); break; case CLGraphicalPrimitive2D::NONZERO: default: linePath.setFillRule(Qt::WindingFill); break; } } QGraphicsPathItem* outline = new QGraphicsPathItem(linePath); outline->setPen(*pen); outline->setBrush(*brush); itemGroup->addToGroup(outline); } } else if (ellipse != NULL) { QPainterPath path = item->path(); QPainterPath& linePath = *getPath(ellipse, ending->getBoundingBox()); applyRotationalMapping(linePath, ending, point, second); linePath.translate(point); path.addPath(linePath); item->setPath(path); if (ellipse->isSetFill() || group->isSetFill()) { QBrush* brush = getBrush(ellipse, ending->getGroup(), resolver, ending->getBoundingBox()); QPen* pen = getPen(ellipse, ending->getGroup(), resolver, ending->getBoundingBox()); QGraphicsPathItem* outline = new QGraphicsPathItem(linePath); outline->setPen(*pen); outline->setBrush(*brush); itemGroup->addToGroup(outline); } } else if (rect != NULL) { QPainterPath path = item->path(); QPainterPath& linePath = *getPath(rect, ending->getBoundingBox()); applyRotationalMapping(linePath, ending, point, second); linePath.translate(point); path.addPath(linePath); item->setPath(path); if (rect->isSetFill() || group->isSetFill()) { QBrush* brush = getBrush(rect, ending->getGroup(), resolver, ending->getBoundingBox()); QPen* pen = getPen(rect, ending->getGroup(), resolver, ending->getBoundingBox()); QGraphicsPathItem* outline = new QGraphicsPathItem(linePath); outline->setPen(*pen); outline->setBrush(*brush); itemGroup->addToGroup(outline); } } } }
bool Brushes::unserializeBrush(pugi::xml_node node, wxArrayString& warnings) { pugi::xml_attribute attribute; if (!(attribute = node.attribute("name"))) { warnings.push_back(wxT("Brush node without name.")); return false; } const std::string& brushName = attribute.as_string(); if (brushName == "all" || brushName == "none") { warnings.push_back(wxString(wxT("Using reserved brushname \"")) << wxstr(brushName) << wxT("\".")); return false; } Brush* brush = getBrush(brushName); if (!brush) { if (!(attribute = node.attribute("type"))) { warnings.push_back(wxT("Couldn't read brush type")); return false; } const std::string brushType = attribute.as_string(); if (brushType == "border" || brushType == "ground") { brush = newd GroundBrush(); } else if (brushType == "wall") { brush = newd WallBrush(); } else if (brushType == "wall decoration") { brush = newd WallDecorationBrush(); } else if (brushType == "carpet") { brush = newd CarpetBrush(); } else if (brushType == "table") { brush = newd TableBrush(); } else if (brushType == "doodad") { brush = newd DoodadBrush(); } else { warnings.push_back(wxString(wxT("Unknown brush type ")) << wxstr(brushType)); return false; } ASSERT(brush); brush->setName(brushName); } if (!node.first_child()) { brushes.insert(std::make_pair(brush->getName(), brush)); return true; } wxArrayString subWarnings; brush->load(node, subWarnings); if(!subWarnings.empty()) { warnings.push_back(wxString(wxT("Errors while loading brush \"")) << wxstr(brush->getName()) << wxT("\"")); warnings.insert(warnings.end(), subWarnings.begin(), subWarnings.end()); } if(brush->getName() == "all" || brush->getName() == "none") { warnings.push_back(wxString(wxT("Using reserved brushname '")) << wxstr(brush->getName()) << wxT("'.")); delete brush; return false; } Brush* otherBrush = getBrush(brush->getName()); if(otherBrush) { if(otherBrush != brush) { warnings.push_back(wxString(wxT("Duplicate brush name ")) << wxstr(brush->getName()) << wxT(". Undefined behaviour may ensue.")); } else { // Don't insert return true; } } brushes.insert(std::make_pair(brush->getName(), brush)); return true; }
// --------------------------------------------------------------------- int SymbolWidget::analyseLine(const QString& Row) { QPen Pen; QBrush Brush; QColor Color; QString s; int i1, i2, i3, i4, i5, i6; s = Row.section(' ',0,0); // component type if(s == ".PortSym") { // here: ports are open nodes if(!getCompLineIntegers(Row, &i1, &i2, &i3)) return -1; Arcs.append(new struct Arc(i1-4, i2-4, 8, 8, 0, 16*360, QPen(Qt::red,1))); if((i1-4) < x1) x1 = i1-4; // keep track of component boundings if((i1+4) > x2) x2 = i1+4; if((i2-4) < y1) y1 = i2-4; if((i2+4) > y2) y2 = i2+4; return 0; // do not count Ports } else if(s == "Line") { if(!getCompLineIntegers(Row, &i1, &i2, &i3, &i4)) return -1; if(!getPen(Row, Pen, 5)) return -1; i3 += i1; i4 += i2; Lines.append(new Line(i1, i2, i3, i4, Pen)); if(i1 < x1) x1 = i1; // keep track of component boundings if(i1 > x2) x2 = i1; if(i2 < y1) y1 = i2; if(i2 > y2) y2 = i2; if(i3 < x1) x1 = i3; if(i3 > x2) x2 = i3; if(i4 < y1) y1 = i4; if(i4 > y2) y2 = i4; return 1; } else if(s == "EArc") { if(!getCompLineIntegers(Row, &i1, &i2, &i3, &i4, &i5, &i6)) return -1; if(!getPen(Row, Pen, 7)) return -1; Arcs.append(new struct Arc(i1, i2, i3, i4, i5, i6, Pen)); if(i1 < x1) x1 = i1; // keep track of component boundings if(i1+i3 > x2) x2 = i1+i3; if(i2 < y1) y1 = i2; if(i2+i4 > y2) y2 = i2+i4; return 1; } else if(s == ".ID") { if(!getCompLineIntegers(Row, &i1, &i2)) return -1; Text_x = i1; Text_y = i2; Prefix = Row.section(' ',3,3); if(Prefix.isEmpty()) Prefix = "X"; return 0; // do not count IDs } else if(s == "Arrow") { if(!getCompLineIntegers(Row, &i1, &i2, &i3, &i4, &i5, &i6)) return -1; if(!getPen(Row, Pen, 7)) return -1; double beta = atan2(double(i6), double(i5)); double phi = atan2(double(i4), double(i3)); double Length = sqrt(double(i6*i6 + i5*i5)); i3 += i1; i4 += i2; if(i1 < x1) x1 = i1; // keep track of component boundings if(i1 > x2) x2 = i1; if(i3 < x1) x1 = i3; if(i3 > x2) x2 = i3; if(i2 < y1) y1 = i2; if(i2 > y2) y2 = i2; if(i4 < y1) y1 = i4; if(i4 > y2) y2 = i4; Lines.append(new Line(i1, i2, i3, i4, Pen)); // base line double w = beta+phi; i5 = i3-int(Length*cos(w)); i6 = i4-int(Length*sin(w)); Lines.append(new Line(i3, i4, i5, i6, Pen)); // arrow head if(i5 < x1) x1 = i5; // keep track of component boundings if(i5 > x2) x2 = i5; if(i6 < y1) y1 = i6; if(i6 > y2) y2 = i6; w = phi-beta; i5 = i3-int(Length*cos(w)); i6 = i4-int(Length*sin(w)); Lines.append(new Line(i3, i4, i5, i6, Pen)); if(i5 < x1) x1 = i5; // keep track of component boundings if(i5 > x2) x2 = i5; if(i6 < y1) y1 = i6; if(i6 > y2) y2 = i6; return 1; } else if(s == "Ellipse") { 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 Area(i1, i2, i3, i4, Pen, Brush)); if(i1 < x1) x1 = i1; // keep track of component boundings if(i1 > x2) x2 = i1; if(i2 < y1) y1 = i2; if(i2 > y2) y2 = i2; if(i1+i3 < x1) x1 = i1+i3; if(i1+i3 > x2) x2 = i1+i3; if(i2+i4 < y1) y1 = i2+i4; if(i2+i4 > y2) y2 = i2+i4; return 1; } else if(s == "Rectangle") { 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 Area(i1, i2, i3, i4, Pen, Brush)); if(i1 < x1) x1 = i1; // keep track of component boundings if(i1 > x2) x2 = i1; if(i2 < y1) y1 = i2; if(i2 > y2) y2 = i2; if(i1+i3 < x1) x1 = i1+i3; if(i1+i3 > x2) x2 = i1+i3; if(i2+i4 < y1) y1 = i2+i4; if(i2+i4 > y2) y2 = i2+i4; return 1; } else if(s == "Text") { // must be last in order to reuse "s" ********* if(!getCompLineIntegers(Row, &i1, &i2, &i3)) return -1; Color.setNamedColor(Row.section(' ',4,4)); if(!Color.isValid()) return -1; s = Row.mid(Row.indexOf('"')+1); // Text (can contain " !!!) s = s.left(s.length()-1); if(s.isEmpty()) return -1; s.replace("\\n", "\n"); s.replace("\\\\", "\\"); Texts.append(new Text(i1, i2, s, Color, float(i3))); QFont Font(QucsSettings.font); Font.setPointSizeF(float(i3)); QFontMetrics metrics(Font, 0); // use the the screen-compatible metric QSize r = metrics.size(0, s); // get size of text i3 = i1 + r.width(); i4 = i2 + r.height(); if(i1 < x1) x1 = i1; // keep track of component boundings if(i3 > x2) x2 = i3; if(i2 < y1) y1 = i2; if(i4 > y2) y2 = i4; } return 0; }
void MemChartPrivate::drawRect(QPainter *painter, const QRectF &rect, Qt::Orientation o, const QColor &startColor, const QColor &stopColor) { painter->setBrush(getBrush(rect,o,startColor,stopColor)); painter->drawRect(rect); }