[Kst] branches/work/kst/portto4/kst/src/libkstapp

Mike Fenton mike at staikos.net
Tue May 12 21:58:52 CEST 2009


SVN commit 967184 by fenton:

Extend ArrowItem shape to include ArrowHead/Tail.


 M  +18 -0     arrowitem.cpp  
 M  +3 -0      arrowitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/arrowitem.cpp #967183:967184
@@ -44,6 +44,8 @@
 void ArrowItem::paint(QPainter *painter) {
   painter->drawLine(line());
 
+  start.clear();
+  end.clear();
   if (_startArrowHead) {
     double deltax = (parentView()->defaultFont().pixelSize() / 2) * _startArrowScale;
     double theta = atan2(double(line().y2() - line().y1()), double(line().x2() - line().x1())) - M_PI / 2.0;
@@ -61,6 +63,7 @@
     pts.append(line().p1() + QPointF(x1, y1));
     pts.append(line().p1() + QPointF(x2, y2));
     painter->drawPolygon(pts);
+    start = pts;
   }
 
   if (_endArrowHead) {
@@ -80,10 +83,25 @@
     pts.append(line().p2() + QPointF(x1, y1));
     pts.append(line().p2() + QPointF(x2, y2));
     painter->drawPolygon(pts);
+    end = pts;
   }
 }
 
 
+QPainterPath ArrowItem::shape() const {
+  QPainterPath selectPath;
+  selectPath.setFillRule(Qt::WindingFill);
+  selectPath.addPolygon(rect());
+  selectPath.addPolygon(start);
+  selectPath.addPolygon(end);
+  if ((!isSelected() && !isHovering()) || (parentView()->mouseMode() == View::Create)) {
+  } else {
+    selectPath.addPath(grips());
+  }
+  return selectPath;
+}
+
+
 void ArrowItem::save(QXmlStreamWriter &xml) {
   if (isVisible()) {
     xml.writeStartElement("arrow");
--- branches/work/kst/portto4/kst/src/libkstapp/arrowitem.h #967183:967184
@@ -39,6 +39,8 @@
     qreal endArrowScale() { return _endArrowScale; }
     void setEndArrowScale(const qreal scale) { _endArrowScale = scale; }
 
+    virtual QPainterPath shape() const;
+
   public Q_SLOTS:
     virtual void edit();
 
@@ -47,6 +49,7 @@
     bool _endArrowHead;
     qreal _startArrowScale;
     qreal _endArrowScale;
+    QPolygonF start, end;
 };
 
 class KST_EXPORT CreateArrowCommand : public CreateCommand


More information about the Kst mailing list