6 #include <QtGui/QGraphicsItem>
7 #include <QtCore/QSharedPointer>
10 #include <QtGui/QFontMetrics>
11 #include <QtGui/QPixmap>
12 #include <QtCore/QFile>
13 #include <QtGui/QGraphicsScene>
40 QRectF pathRect = item->boundingRect();
51 matrix = matrix.translate(pathRect.x(), pathRect.y());
52 matrix = matrix.inverted();
56 translate = translate.translate(pathRect.x(), pathRect.y());
57 matrix = matrix * translate;
58 item->setTransform(matrix,
true);
62 QRectF pathRect = item->boundingRect();
73 matrix = matrix.translate(pathRect.x(), pathRect.y());
74 matrix = matrix.inverted();
78 translate = translate.translate(pathRect.x(), pathRect.y());
79 matrix = matrix * translate;
80 item->setTransform(matrix,
true);
86 if (cd == NULL)
return QColor();
94 return QColor(Qt::transparent);
112 QSharedPointer<QLinearGradient> result = QSharedPointer<QLinearGradient>(
new QLinearGradient(x1, y1, x2, y2));
117 result->setSpread(QGradient::ReflectSpread);
121 result->setSpread(QGradient::RepeatSpread);
125 result->setSpread(QGradient::PadSpread);
149 QSharedPointer<QRadialGradient> result = QSharedPointer<QRadialGradient>(
new QRadialGradient(cx, cy, r, fx, fy));
154 result->setSpread(QGradient::ReflectSpread);
158 result->setSpread(QGradient::RepeatSpread);
162 result->setSpread(QGradient::PadSpread);
190 return QSharedPointer<QGradient>();
195 QString font(
"Verdana");
double fontSize = 10, weight = 50;
bool italic =
false;
211 weight = QFont::Bold;
216 weight = QFont::Normal;
223 weight = QFont::Bold;
228 weight = QFont::Normal;
253 QSharedPointer<QFont> result = QSharedPointer<QFont>(
new QFont(font, -1, weight, italic));
254 result->setPixelSize(fontSize);
258 result->setStyleHint(QFont::Serif);
260 else if (font ==
"sans-serif" || font ==
"sans")
262 result->setStyleHint(QFont::SansSerif);
264 else if (font ==
"monospace")
266 result->setStyleHint(QFont::Monospace);
282 return QSharedPointer<QBrush>(
new QBrush(*
getGradient(base, pBB, resolver)));
287 else if (group != NULL && group->
isSetFill())
293 return QSharedPointer<QBrush>(
new QBrush(*
getGradient(base, pBB, resolver)));
299 return QSharedPointer<QBrush>(
new QBrush());
304 QColor color;
double width;
314 else return QSharedPointer<QPen>(
new QPen(Qt::transparent));
324 else return QSharedPointer<QPen>(
new QPen(Qt::transparent));
326 QSharedPointer<QPen> result = QSharedPointer<QPen>(
new QPen(color, width));
327 result->setCapStyle(Qt::RoundCap);
328 result->setJoinStyle(Qt::RoundJoin);
332 const std::vector<unsigned int>& raw = item->
getDashArray();
333 std::vector<unsigned int>::const_iterator start = raw.begin();
334 QVector<qreal> pattern;
336 while (start != raw.end())
342 result->setDashPattern(pattern);
346 const std::vector<unsigned int>& raw = group->
getDashArray();
347 std::vector<unsigned int>::const_iterator start = raw.begin();
348 QVector<qreal> pattern;
350 while (start != raw.end())
356 result->setDashPattern(pattern);
369 QGraphicsEllipseItem* ellipseItem =
new QGraphicsEllipseItem(
370 x - rx, y - ry, rx * 2, ry * 2);
371 QSharedPointer<QPen> pen =
getPen(pEllipse, group, resolver, pBB);
372 ellipseItem->setPen(*pen);
374 QSharedPointer<QBrush> brush =
getBrush(pEllipse, group, resolver, pBB);
375 ellipseItem->setBrush(*brush);
378 item->addToGroup(ellipseItem);
431 QGraphicsPathItem *pathItem =
new QGraphicsPathItem(path);
432 QSharedPointer<QPen> pen =
getPen(NULL, group, resolver, pBB);
433 pathItem->setPen(*pen);
438 item->addToGroup(pathItem);
470 QSharedPointer<QPainterPath> path = QSharedPointer<QPainterPath>(
new QPainterPath());
473 std::vector<CLRenderPoint*>::const_iterator it = elements.begin();
476 for (; it != elements.end(); ++it)
498 path->closeSubpath();
513 QSharedPointer<QPainterPath> path = QSharedPointer<QPainterPath>(
new QPainterPath());
515 path->addRoundedRect(x, y, w, h, rx, ry);
528 QSharedPointer<QPainterPath> path = QSharedPointer<QPainterPath>(
new QPainterPath());
530 path->addEllipse(x - rx, y - ry, 2 * rx, 2 * ry);
537 QSharedPointer<QPainterPath> path = QSharedPointer<QPainterPath>(
new QPainterPath());
540 std::vector<CLRenderPoint*>::const_iterator it = elements.begin();
543 for (; it != elements.end(); ++it)
570 qreal length = (qreal) sqrt(vector.x() * vector.x() + vector.y() * vector.y());
572 if (length == 0) length = 1;
574 return QPointF(vector.x() / length, vector.y() / length);
582 QPointF directionVector(point.x() - second.x(), point.y() - second.y());
585 if (directionVector.x() == 0 && directionVector.y() == 0)
588 QPointF orthogonlVector;
590 if (directionVector.x() == 0)
591 orthogonlVector = QPointF(directionVector.y(), 0);
593 orthogonlVector = QPointF(-directionVector.y() * directionVector.x(),
594 1 - directionVector.y() * directionVector.y());
598 QTransform rotateMatrix(directionVector.x(), directionVector.y(), orthogonlVector.x(),
599 orthogonlVector.y(), 0, 0);
601 linePath = rotateMatrix.map(linePath);
617 QPainterPath path = item->path();
620 linePath->translate(point);
621 path.addPath(*linePath.data());
624 else if (poly != NULL)
626 QPainterPath path = item->path();
629 linePath->translate(point);
630 path.addPath(*linePath);
638 linePath->setFillRule(Qt::WindingFill);
645 linePath->setFillRule(Qt::OddEvenFill);
650 linePath->setFillRule(Qt::WindingFill);
660 linePath->setFillRule(Qt::OddEvenFill);
665 linePath->setFillRule(Qt::WindingFill);
670 QGraphicsPathItem* outline =
new QGraphicsPathItem(*linePath);
672 outline->setPen(*pen);
673 outline->setBrush(*brush);
674 itemGroup->addToGroup(outline);
677 else if (ellipse != NULL)
679 QPainterPath path = item->path();
682 linePath->translate(point);
683 path.addPath(*linePath);
690 QGraphicsPathItem* outline =
new QGraphicsPathItem(*linePath);
691 outline->setPen(*pen);
692 outline->setBrush(*brush);
693 itemGroup->addToGroup(outline);
696 else if (rect != NULL)
698 QPainterPath path = item->path();
701 linePath->translate(point);
702 path.addPath(*linePath);
709 QGraphicsPathItem* outline =
new QGraphicsPathItem(*linePath);
710 outline->setPen(*pen);
711 outline->setBrush(*brush);
712 itemGroup->addToGroup(outline);
720 QSharedPointer<QPainterPath> path =
getPath(pCurve, pBB);
722 QGraphicsPathItem *pathItem =
new QGraphicsPathItem(*path);
723 QSharedPointer<QPen> pen =
getPen(pCurve, group, resolver, pBB);
724 pathItem->setPen(*pen);
726 item->addToGroup(pathItem);
731 if (path->elementCount() > 1)
733 if (group -> isSetStartHead())
736 addLineEndingToItem(pathItem, line, group, resolver, path->elementAt(0), path->elementAt(1), item);
747 addLineEndingToItem(pathItem, line, group, resolver, path->elementAt(path->elementCount() - 1), path->elementAt(path->elementCount() - 2), item);
752 addLineEndingToItem(pathItem, line, line->
getGroup(), resolver, path->elementAt(path->elementCount() - 1), path->elementAt(path->elementCount() - 2), item);
761 QSharedPointer<QPainterPath> path =
getPath(pPoly, pBB);
762 path->setFillRule(Qt::WindingFill);
769 path->setFillRule(Qt::OddEvenFill);
774 path->setFillRule(Qt::WindingFill);
784 path->setFillRule(Qt::OddEvenFill);
789 path->setFillRule(Qt::WindingFill);
794 QGraphicsPathItem *pathItem =
new QGraphicsPathItem(*path);
795 QSharedPointer<QPen> pen =
getPen(pPoly, group, resolver, pBB);
796 pathItem->setPen(*pen);
797 QSharedPointer<QBrush> brush =
getBrush(pPoly, group, resolver, pBB);
798 pathItem->setBrush(*brush);
802 item->addToGroup(pathItem);
807 qreal width = item->boundingRect().width();
808 qreal height = item->boundingRect().height();
814 QPointF pos = item->pos();
857 QPointF pos = item->pos();
904 QGraphicsTextItem* result =
new QGraphicsTextItem(pText->
getText().c_str());
905 result ->setPos(x, y);
916 QSharedPointer<QFont> font =
getFont(pText, group, resolver, pBB);
920 result->setFont(*font);
926 item->addToGroup(result);
938 if (!fileName->exists())
942 fileName =
new QFile(file.c_str());
945 if (!fileName->exists())
951 QPixmap pixmap(fileName->fileName());
952 pixmap = pixmap.scaled(w, h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
954 QGraphicsPixmapItem* result =
new QGraphicsPixmapItem(
956 result->setPos(x, y);
959 item->addToGroup(result);
973 QSharedPointer<QPen> pen =
getPen(pRect, group, resolver, pBB);
974 result->setPen(*pen);
976 QSharedPointer<QBrush> brush =
getBrush(pRect, group, resolver, pBB);
977 result->setBrush(*brush);
980 item->addToGroup(result);
990 if (numElements == 0)
995 for (
size_t i = 0; i < numElements; ++i)
1003 const CLText* text =
dynamic_cast<const CLText*
>(object);
1005 const CLGroup* childGroup =
dynamic_cast<const CLGroup*
>(object);
1007 if (ellipse != NULL)
1011 else if (rect != NULL)
1015 else if (text != NULL)
1019 else if (curve != NULL)
1023 else if (rcurve != NULL)
1027 else if (poly != NULL)
1031 else if (image != NULL)
1035 else if (childGroup != NULL)
1046 if (resolver == NULL || group == NULL || bounds == NULL || item == NULL)
1049 QSharedPointer<QPen> pen =
getPen(NULL, group, resolver, bounds);
1052 if (item->path().elementCount() < 2)
1055 QPointF start = item->path().elementAt(0);
1056 QPointF second = item->path().elementAt(1);
1057 QPointF end = item->path().elementAt(item->path().elementCount() - 1);
1058 QPointF secondLast = item->path().elementAt(item->path().elementCount() - 2);
1060 if (group -> isSetStartHead())
1075 if (resolver == NULL || style == NULL || bounds == NULL || group == NULL)
1078 for (
int i = 0; i < group->childItems().size(); ++i)
1085 if (resolver == NULL || style == NULL || bounds == NULL || item == NULL)
1091 QSharedPointer<QFont> font =
getFont(NULL, style, resolver, bounds);
1095 item->setFont(*font);
1103 if (resolver == NULL || style == NULL || bounds == NULL || group == NULL)
1111 if (resolver == NULL || scene == NULL)
return;
1113 QBrush brush(
getColor(fill, resolver));
1114 scene->setBackgroundBrush(brush);
const CLRelAbsVector & getRadius() const
const CLRelAbsVector & basePoint1_X() const
void fillItemFromImage(QGraphicsItemGroup *item, const CLBoundingBox *pBB, const CLImage *pImage, const CLGroup *group, const CLRenderResolver *)
const CLRelAbsVector & getCenterY() const
const CLRelAbsVector & getYPoint1() const
const C_FLOAT64 & getWidth() const
const CLRelAbsVector & getCenterX() const
bool isSetDashArray() const
const CLRelAbsVector & basePoint2_Y() const
const CLRelAbsVector & getHeight() const
const CLColorDefinition * getColorDefinition(const std::string &id) const
bool isSetFontWeight() const
const std::string & getStartHead() const
QSharedPointer< QFont > getFont(const CLText *item, const CLGroup *group, const CLRenderResolver *, const CLBoundingBox *pBB)
bool isSetEndHead() const
const CLRelAbsVector & getY() const
const CLRelAbsVector & getRadiusY() const
qreal linear(qreal a, qreal b, qreal t)
bool isSetFontFamily() const
const CLRelAbsVector & getWidth() const
double getStrokeWidth() const
bool isSetFontSize() const
static void setBackground(QGraphicsScene *scene, const std::string &fill, const CLRenderResolver *resolver)
double getRelativeValue() const
bool setColorValue(const std::string &valueString)
unsigned char getBlue() const
CLGradientStop * getGradientStop(size_t i)
bool isSetFontStyle() const
bool isSetStrokeWidth() const
const CLRelAbsVector & basePoint2_X() const
const CLRelAbsVector & getXPoint2() const
const std::string & getFontFamily() const
const CLRelAbsVector & getFontSize() const
const std::string & getStroke() const
const CLPoint & getBase1() const
bool isSetFontSize() const
static void fillGroupFromStyle(QGraphicsItemGroup *group, const CLBoundingBox *bounds, const CLStyle *style, const CLRenderResolver *resolver)
CLRelAbsVector & getFontSize()
const std::string & getImageReference() const
bool isSetFontFamily() const
size_t getNumGradientStops() const
bool isSetVTextAnchor() const
const CLRelAbsVector & getX() const
const CLRelAbsVector & getRX() const
FONT_STYLE getFontStyle() const
QSharedPointer< QPen > getPen(const CLGraphicalPrimitive1D *item, const CLGroup *group, const CLRenderResolver *resolver, const CLBoundingBox *)
const CLDimensions & getDimensions() const
const CLRelAbsVector & getY() const
const CLRelAbsVector & getCY() const
const CLRelAbsVector & getRadiusX() const
void applyRotationalMapping(QPainterPath &linePath, const CLLineEnding *ending, QPointF point, QPointF second)
void moveToPoint(QPainterPath &path, const CLRenderPoint *current, const CLBoundingBox *pBB)
const std::string & getStopColor() const
void addToPath(QPainterPath &path, const CLRenderCubicBezier *cubic, const CLBoundingBox *pBB)
const CLPoint & getBase2() const
const CLRelAbsVector & getOffset() const
QSharedPointer< QBrush > getBrush(const CLGraphicalPrimitive2D *item, const CLGroup *group, const CLRenderResolver *resolver, const CLBoundingBox *pBB)
const CLPoint & getEnd() const
const CLRelAbsVector & getHeight() const
const std::string & getEndHead() const
const C_FLOAT64 & getX() const
const CLRelAbsVector & getFocalPointY() const
const CLPoint & getPosition() const
const std::string & getStartHead() const
unsigned char getGreen() const
const CLGroup * getGroup() const
CCopasiObject * getElement(size_t n)
static void applyStyle(QGraphicsTextItem *item, const CLBoundingBox *bounds, const CLGroup *style, const CLRenderResolver *resolver)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
const CLGroup * getGroup() const
bool isSetTextAnchor() const
unsigned char getRed() const
QPointF normalizePoint(const QPointF &vector)
void fillItemFromGroup(QGraphicsItemGroup *item, const CLBoundingBox *bounds, const CLGroup *group, const CLRenderResolver *resolver)
std::vector< CLPoint > getListOfPoints() const
const std::string & getEndHead() const
bool isSetFillRule() const
void transform(QGraphicsItem *item, const CLTransformation2D *trans, const CLGroup *group)
const CLRelAbsVector & getWidth() const
bool isSetFontStyle() const
QSharedPointer< QRadialGradient > getRadialGradient(const CLRadialGradient *radial, const CLBoundingBox *bounds, const CLRenderResolver *resolver)
CLText::FONT_STYLE getFontStyle() const
bool isSetStartHead() const
unsigned char getAlpha() const
CLText::FONT_WEIGHT getFontWeight() const
const CLRelAbsVector & getXOffset() const
const CLRelAbsVector & getRY() const
CLBoundingBox * getBoundingBox()
CLText::TEXT_ANCHOR getVTextAnchor() const
const CLRelAbsVector & getYOffset() const
void fillItemFromText(QGraphicsItemGroup *item, const CLBoundingBox *pBB, const CLText *pText, const CLGroup *group, const CLRenderResolver *resolver)
QSharedPointer< QGradient > getGradient(const CLGradientBase *base, const CLBoundingBox *bounds, const CLRenderResolver *resolver)
const C_FLOAT64 & getY() const
void fillItemFromRenderCurve(QGraphicsItemGroup *item, const CLBoundingBox *pBB, const CLRenderCurve *pCurve, const CLGroup *group, const CLRenderResolver *resolver)
double getAbsoluteValue() const
const C_FLOAT64 & getHeight() const
const std::string & getFillColor() const
void addLineEndingToItem(QGraphicsPathItem *item, const CLLineEnding *ending, const CLGroup *group, const CLRenderResolver *resolver, QPointF point, QPointF second, QGraphicsItemGroup *itemGroup)
const CLLineSegment * getSegmentAt(size_t i) const
bool isSetEndHead() const
std::vector< CLRenderPoint * > * getListOfElements()
const std::string & getFontFamily() const
QColor getColor(const CLColorDefinition *cd)
const CLRelAbsVector & getFocalPointX() const
bool isSetTextAnchor() const
bool getIsEnabledRotationalMapping() const
const CLRelAbsVector & getCX() const
QSharedPointer< QLinearGradient > getLinearGradient(const CLLinearGradient *linear, const CLBoundingBox *bounds, const CLRenderResolver *resolver)
TEXT_ANCHOR getVTextAnchor() const
const CLRelAbsVector & basePoint1_Y() const
const std::string & getText() const
QSharedPointer< QPainterPath > getPath(const CLPolygon *pCurve, const CLBoundingBox *pBB)
const std::vector< CLRenderPoint * > * getListOfCurveElements() const
SPREADMETHOD getSpreadMethod() const
const CLLineEnding * getLineEnding(const std::string &id) const
FILL_RULE getFillRule() const
const CLRelAbsVector & getX() const
void fillItemFromRectangle(QGraphicsItemGroup *item, const CLBoundingBox *pBB, const CLRectangle *pRect, const CLGroup *group, const CLRenderResolver *resolver)
CLText::TEXT_ANCHOR getTextAnchor() const
const CLGradientBase * getGradientBase(const std::string &id) const
bool isSetFontWeight() const
size_t getNumElements() const
void fillItemFromPolygon(QGraphicsItemGroup *item, const CLBoundingBox *pBB, const CLPolygon *pPoly, const CLGroup *group, const CLRenderResolver *resolver)
const CLRelAbsVector & getYPoint2() const
size_t getNumCurveSegments() const
TEXT_ANCHOR getTextAnchor() const
const CLRelAbsVector & getXPoint1() const
bool isSetVTextAnchor() const
const std::vector< unsigned int > & getDashArray() const
void fillItemFromCurve(QGraphicsItemGroup *item, const CLBoundingBox *pBB, const CLCurve *pCurve, const CLGroup *group, const CLRenderResolver *resolver)
bool isContinuous() const
const CLPoint & getStart() const
FONT_WEIGHT getFontWeight() const
void adjustPosition(QGraphicsTextItem *item, const CLBoundingBox *pBB, const CLText *pText, const CLGroup *group)
void fillItemFromEllipse(QGraphicsItemGroup *item, const CLBoundingBox *pBB, const CLEllipse *pEllipse, const CLGroup *group, const CLRenderResolver *resolver)