Changeset 13537 for branches/OMEdit/OMEditGUI/EllipseAnnotation.cpp
- Timestamp:
- 2012-10-20T20:27:24+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OMEdit/OMEditGUI/EllipseAnnotation.cpp
r13405 r13537 37 37 38 38 39 EllipseAnnotation _OMC::EllipseAnnotation_OMC(QString annotation, Component_OMC*pParent)40 : ShapeAnnotation _OMC(pParent)39 EllipseAnnotation::EllipseAnnotation(QString annotation, Component *pParent) 40 : ShapeAnnotation(pParent) 41 41 { 42 42 parseShapeAnnotation(annotation); 43 43 } 44 44 45 void EllipseAnnotation _OMC::parseShapeAnnotation(QString annotation)45 void EllipseAnnotation::parseShapeAnnotation(QString annotation) 46 46 { 47 47 GraphicItem::parseShapeAnnotation(annotation); … … 65 65 } 66 66 67 QRectF EllipseAnnotation_OMC::boundingRect() const68 {69 return shape().boundingRect();70 }71 72 QPainterPath EllipseAnnotation_OMC::shape() const73 {74 QPainterPath path;75 path.addEllipse(getBoundingRect());76 return addPathStroker(path);77 }78 79 void EllipseAnnotation_OMC::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)80 {81 Q_UNUSED(option);82 Q_UNUSED(widget);83 if (transformOriginPoint() != boundingRect().center())84 setTransformOriginPoint(boundingRect().center());85 drawEllipseAnnotaion(painter);86 }87 88 void EllipseAnnotation_OMC::drawEllipseAnnotaion(QPainter *painter)89 {90 applyLinePattern(painter);91 applyFillPattern(painter);92 QPainterPath path;93 path.addEllipse(boundingRect());94 painter->drawPath(path);95 }96 97 98 EllipseAnnotation::EllipseAnnotation(QString shape, Component *pParent)99 : ShapeAnnotation(pParent), mpComponent(pParent)100 {101 initializeFields();102 parseShapeAnnotation(shape, mpComponent->getOMCProxy());103 }104 105 EllipseAnnotation::EllipseAnnotation(GraphicsView *graphicsView, QGraphicsItem *pParent)106 : ShapeAnnotation(graphicsView, pParent)107 {108 // initialize all fields with default values109 initializeFields();110 mIsCustomShape = true;111 setAcceptHoverEvents(true);112 connect(this, SIGNAL(updateShapeAnnotation()), mpGraphicsView, SLOT(addClassAnnotation()));113 }114 115 EllipseAnnotation::EllipseAnnotation(QString shape, GraphicsView *graphicsView, QGraphicsItem *pParent)116 : ShapeAnnotation(graphicsView, pParent)117 {118 // initialize all fields with default values119 initializeFields();120 parseShapeAnnotation(shape, mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow()->getOMCProxy());121 mIsCustomShape = true;122 setAcceptHoverEvents(true);123 connect(this, SIGNAL(updateShapeAnnotation()), mpGraphicsView, SLOT(addClassAnnotation()));124 }125 126 67 QRectF EllipseAnnotation::boundingRect() const 127 68 { … … 140 81 Q_UNUSED(option); 141 82 Q_UNUSED(widget); 142 143 83 if (transformOriginPoint() != boundingRect().center()) 144 {145 84 setTransformOriginPoint(boundingRect().center()); 146 }147 85 drawEllipseAnnotaion(painter); 148 86 } … … 150 88 void EllipseAnnotation::drawEllipseAnnotaion(QPainter *painter) 151 89 { 90 applyLinePattern(painter); 91 applyFillPattern(painter); 152 92 QPainterPath path; 153 154 switch (this->mFillPattern)155 {156 case Qt::LinearGradientPattern:157 {158 QLinearGradient gradient(boundingRect().center().x(), boundingRect().center().y(), boundingRect().center().x(), boundingRect().y());159 gradient.setColorAt(0.0, this->mFillColor);160 gradient.setColorAt(1.0, this->mLineColor);161 gradient.setSpread(QGradient::ReflectSpread);162 painter->setBrush(gradient);163 break;164 }165 case Qt::Dense1Pattern:166 {167 QLinearGradient gradient(boundingRect().center().x(), boundingRect().center().y(),168 boundingRect().x(), boundingRect().center().y());169 gradient.setColorAt(0.0, this->mFillColor);170 gradient.setColorAt(1.0, this->mLineColor);171 gradient.setSpread(QGradient::ReflectSpread);172 painter->setBrush(gradient);173 break;174 }175 case Qt::RadialGradientPattern:176 {177 QRadialGradient gradient(boundingRect().center().x(), boundingRect().center().y(), boundingRect().width());178 gradient.setColorAt(0.0, this->mFillColor);179 gradient.setColorAt(1.0, this->mLineColor);180 gradient.setSpread(QGradient::ReflectSpread);181 painter->setBrush(gradient);182 break;183 }184 default:185 painter->setBrush(QBrush(this->mFillColor, this->mFillPattern));186 break;187 }188 // make the pen width upper rounded, otherwise ellipse is distorted189 qreal thickness = ceil(mThickness);190 191 QPen pen(mLineColor, thickness, this->mLinePattern);192 pen.setCosmetic(true);193 painter->setPen(pen);194 195 93 path.addEllipse(boundingRect()); 196 94 painter->drawPath(path); 197 95 } 198 199 void EllipseAnnotation::addPoint(QPointF point)200 {201 mExtent.append(point);202 }203 204 void EllipseAnnotation::updateEndPoint(QPointF point)205 {206 mExtent.back() = point;207 }208 209 void EllipseAnnotation::drawRectangleCornerItems()210 {211 mIsFinishedCreatingShape = true;212 for (int i = 0 ; i < this->mExtent.size() ; i++)213 {214 QPointF point = this->mExtent.at(i);215 RectangleCornerItem *rectangleCornerItem = new RectangleCornerItem(point.x(), point.y(), i, this);216 mRectangleCornerItemsList.append(rectangleCornerItem);217 }218 emit updateShapeAnnotation();219 }220 221 QString EllipseAnnotation::getShapeAnnotation()222 {223 QString annotationString;224 annotationString.append("Ellipse(");225 226 if (!mVisible)227 {228 annotationString.append("visible=false,");229 }230 231 annotationString.append("rotation=").append(QString::number(this->rotation())).append(",");232 233 annotationString.append("lineColor={");234 annotationString.append(QString::number(mLineColor.red())).append(",");235 annotationString.append(QString::number(mLineColor.green())).append(",");236 annotationString.append(QString::number(mLineColor.blue()));237 annotationString.append("},");238 239 annotationString.append("fillColor={");240 annotationString.append(QString::number(mFillColor.red())).append(",");241 annotationString.append(QString::number(mFillColor.green())).append(",");242 annotationString.append(QString::number(mFillColor.blue()));243 annotationString.append("},");244 245 QMap<QString, Qt::PenStyle>::iterator it;246 for (it = this->mLinePatternsMap.begin(); it != this->mLinePatternsMap.end(); ++it)247 {248 if (it.value() == mLinePattern)249 {250 annotationString.append("pattern=LinePattern.").append(it.key()).append(",");251 break;252 }253 }254 255 QMap<QString, Qt::BrushStyle>::iterator fill_it;256 for (fill_it = this->mFillPatternsMap.begin(); fill_it != this->mFillPatternsMap.end(); ++fill_it)257 {258 if (fill_it.value() == mFillPattern)259 {260 annotationString.append("fillPattern=FillPattern.").append(fill_it.key()).append(",");261 break;262 }263 }264 265 annotationString.append("lineThickness=").append(QString::number(mThickness)).append(",");266 annotationString.append("extent={{");267 annotationString.append(QString::number(mapToScene(mExtent.at(0)).x())).append(",");268 annotationString.append(QString::number(mapToScene(mExtent.at(0)).y())).append("},{");269 annotationString.append(QString::number(mapToScene(mExtent.at(1)).x())).append(",");270 annotationString.append(QString::number(mapToScene(mExtent.at(1)).y()));271 annotationString.append("}}");272 273 annotationString.append(")");274 return annotationString;275 }276 277 void EllipseAnnotation::updatePoint(int index, QPointF point)278 {279 mExtent.replace(index, point);280 }281 282 void EllipseAnnotation::parseShapeAnnotation(QString shape, OMCProxy *omc)283 {284 // Remove { } from shape285 286 shape = shape.replace("{", "");287 shape = shape.replace("}", "");288 289 // parse the shape to get the list of attributes of Ellipse.290 QStringList list = StringHandler::getStrings(shape);291 if (list.size() < 14)292 {293 return;294 }295 296 // if first item of list is true then the Ellipse should be visible.297 this->mVisible = static_cast<QString>(list.at(0)).contains("true");298 299 int index = 0;300 mOrigin.setX(static_cast<QString>(list.at(1)).toFloat());301 mOrigin.setY(static_cast<QString>(list.at(2)).toFloat());302 mRotation = static_cast<QString>(list.at(3)).toFloat();303 index = 3;304 // 2,3,4 items of list contains the line color.305 index = index + 1;306 int red, green, blue;307 308 red = static_cast<QString>(list.at(index)).toInt();309 index = index + 1;310 green = static_cast<QString>(list.at(index)).toInt();311 index = index + 1;312 blue = static_cast<QString>(list.at(index)).toInt();313 this->mLineColor = QColor (red, green, blue);314 315 // 5,6,7 items of list contains the fill color.316 index = index + 1;317 red = static_cast<QString>(list.at(index)).toInt();318 index = index + 1;319 green = static_cast<QString>(list.at(index)).toInt();320 index = index + 1;321 blue = static_cast<QString>(list.at(index)).toInt();322 this->mFillColor = QColor (red, green, blue);323 324 // 8 item of the list contains the line pattern.325 index = index + 1;326 QString linePattern = StringHandler::getLastWordAfterDot(list.at(index));327 QMap<QString, Qt::PenStyle>::iterator it;328 for (it = this->mLinePatternsMap.begin(); it != this->mLinePatternsMap.end(); ++it)329 {330 if (it.key().compare(linePattern) == 0)331 {332 this->mLinePattern = it.value();333 break;334 }335 }336 337 // 9 item of the list contains the fill pattern.338 index = index + 1;339 QString fillPattern = StringHandler::getLastWordAfterDot(list.at(index));340 QMap<QString, Qt::BrushStyle>::iterator fill_it;341 for (fill_it = this->mFillPatternsMap.begin(); fill_it != this->mFillPatternsMap.end(); ++fill_it)342 {343 if (fill_it.key().compare(fillPattern) == 0)344 {345 this->mFillPattern = fill_it.value();346 break;347 }348 }349 350 // 10 item of the list contains the thickness.351 index = index + 1;352 this->mThickness = static_cast<QString>(list.at(index)).toFloat();353 354 // 11, 12, 13, 14 items of the list contains the extent points of Ellipse.355 index = index + 1;356 qreal x = static_cast<QString>(list.at(index)).toFloat();357 index = index + 1;358 qreal y = static_cast<QString>(list.at(index)).toFloat();359 QPointF p1 (x, y);360 index = index + 1;361 x = static_cast<QString>(list.at(index)).toFloat();362 index = index + 1;363 y = static_cast<QString>(list.at(index)).toFloat();364 QPointF p2 (x, y);365 366 this->mExtent.append(p1);367 this->mExtent.append(p2);368 }
Note: See TracChangeset
for help on using the changeset viewer.