QEditorView::QEditorView(QWidget *parent) : QGraphicsView(parent){ fproject = NULL; this->setUpdatesEnabled(false); ffieldColor = Qt::darkGray; frenderer = rdSoftware; fscene = new QEditorScene(this); setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing); //<<< setAlignment(Qt::AlignLeft | Qt::AlignTop); setScene(fscene); setSceneRect(0,0,1920,1080); setDragMode(QGraphicsView::RubberBandDrag); setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing); //<<< setContextMenuPolicy(Qt::DefaultContextMenu); fGlWidget = NULL; setViewportUpdateMode(QGraphicsView::FullViewportUpdate); //<<<!!! setCacheMode(QGraphicsView::CacheBackground); this->setUpdatesEnabled(true);}
class QRouteArrow : public QRailItem{Q_OBJECT QPointF fpoints[2]; //начальная и конечная точки стрелки qreal fwidth; qreal fheight; qreal fwidth2; QPointF fbegA,fbegB; //точки в начале QPointF fendA1,fendA2; //точки в конце (1 - ближе к центру, 2-дальше от центра) QPointF fendB1,fendB2; //тоже но с другой стороны от линии QPointF fendC; //точка отсутпа от конечной на которой будет рисоваться стрелка QPolygonF fpolygon;protected: QPainterPath shape() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); QRectF boundingRect() const; QRectF outlineRect() const; void recalculate();public: QRouteArrow(bool Init = true, QGraphicsItem *parent = 0); void setBegin(QPointF pos); void setEnd(QPointF pos);};
QRouteArrow::QRouteArrow(bool Init, QGraphicsItem *parent): QRailItem(Init,parent){ fStrokeColor = Qt::white; fColor = Qt::transparent; fwidth = 2; fwidth2 = 6; fheight = 15; if(Init) { fpoints[0].setX(0); fpoints[0].setY(0); fpoints[1].setX(50); fpoints[1].setY(50); prepareGeometryChange(); recalculate(); } else { qMemSet(fpoints,0,sizeof(fpoints)); }}QPainterPath QRouteArrow::shape() const{ QPainterPath path; path.addPolygon(fpolygon); return path;}void QRouteArrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * /* widget */){ painter->setPen(fStrokeColor); painter->setBrush(fColor); painter->drawPolygon(fpolygon);}QRectF QRouteArrow::boundingRect() const{ return QRectF(fpoints[0],fpoints[1]);}QRectF QRouteArrow::outlineRect() const{ return boundingRect().adjusted(-fwidth,-fwidth,fwidth,fwidth);}void QRouteArrow::setBegin(QPointF pos){ if(fpoints[0]!=pos) { fpoints[0]=pos; prepareGeometryChange(); recalculate(); }}void QRouteArrow::setEnd(QPointF pos){ if(fpoints[1]!=pos) { fpoints[1]=pos; prepareGeometryChange(); recalculate(); }}
QRectF QRouteArrow::boundingRect() const{ return shape().boundingRect();}