Esempio n. 1
0
QPainterPath
TriggerPoint::shape() const
{
  QPainterPath path;
  float line = BasicBox::LINE_WIDTH / 2;
  QPointF adjustX(-line, 0);
  QPointF adjustY(0, -line);
  QRectF rect = boundingRect();
  switch (_abstract->boxExtremity()) {
      case BOX_START:
        path.moveTo(rect.topLeft() + adjustX);
        path.lineTo(rect.bottomLeft() + adjustX + adjustY);
        path.lineTo(rect.bottomRight() + adjustY);
        path.lineTo(rect.bottomRight() + adjustY - QPointF(0, rect.height() / 5.));
        path.quadTo(rect.topRight(), rect.topLeft() + adjustX);
        break;

      case BOX_END:
        path.moveTo(rect.topRight());
        path.lineTo(rect.bottomRight() + adjustY);
        path.lineTo(rect.bottomLeft() + adjustY);
        path.lineTo(rect.bottomLeft() + adjustY - QPointF(0, rect.height() / 5.));
        path.quadTo(rect.topLeft(), rect.topRight());
        break;

      default:
        break;
    }

  return path;
}
Esempio n. 2
0
void
FormCheckBox::draw( QPainter * painter, const QPen & pen, const QFont & font,
	const QRectF & rect, qreal width, bool isChecked, const QString & text )
{
	painter->setPen( pen );

	painter->drawRect( rect );

	if( isChecked )
	{
		painter->drawLine( QLineF( rect.topLeft().x() + 4.0,
			rect.topLeft().y() + rect.height() / 2.0,
			rect.topLeft().x() + rect.width() / 2.0,
			rect.bottomLeft().y() - 4.0 ) );

		painter->drawLine( QLineF(
			rect.topLeft().x() + rect.width() / 2.0,
			rect.bottomLeft().y() - 4.0,
			rect.topRight().x() - 4.0,
			rect.topRight().y() + 4.0 ) );
	}

	painter->setFont( font );

	QRectF r = rect;

	r.setRight( rect.x() + width );
	r.moveLeft( rect.x() + rect.height() + 4.0 );

	painter->drawText( r, Qt::AlignLeft | Qt::AlignVCenter, text );
}
void BoundingPoint::mouseMoveEvent(QGraphicsSceneMouseEvent* event){
    if(_canMove){
        //_canBeSelected = false;
        //_isMoving = true;
        qDebug("mouse move");

        QRectF zone = _scene->pointsBoundingZone();
        QPointF pos(event->scenePos().x(), event->scenePos().y());
        if(pos.x() < zone.bottomLeft().x()){
            pos.setX(zone.bottomLeft().x());
        }else if(pos.x() > zone.bottomRight().x()){
            pos.setX(zone.bottomRight().x());
        }
        if(pos.y() < 0){
            pos.setY(0);
        }else if(pos.y() > zone.bottomLeft().y()){
            pos.setY(zone.bottomLeft().y());
        }

        this->moveTo(pos);

    }else{
        QGraphicsItem::mousePressEvent(event);
    }
    _scene->update(_scene->sceneRect());
 }
Esempio n. 4
0
Qt::WindowFrameSection OverlayEditorScene::rectSection(const QRectF &qrf, const QPointF &qp, qreal dist) {
	qreal left, right, top, bottom;

	top = distancePointLine(qrf.topLeft(), qrf.topRight(), qp);
	bottom = distancePointLine(qrf.bottomLeft(), qrf.bottomRight(), qp);
	left = distancePointLine(qrf.topLeft(), qrf.bottomLeft(), qp);
	right = distancePointLine(qrf.topRight(), qrf.bottomRight(), qp);

	if ((top < dist) && (top < bottom)) {
		if ((left < dist) && (left < right))
			return Qt::TopLeftSection;
		else if (right < dist)
			return Qt::TopRightSection;
		return Qt::TopSection;
	} else if (bottom < dist) {
		if ((left < dist) && (left < right))
			return Qt::BottomLeftSection;
		else if (right < dist)
			return Qt::BottomRightSection;
		return Qt::BottomSection;
	} else if (left < dist) {
		return Qt::LeftSection;
	} else if (right < dist) {
		return Qt::RightSection;
	}
	if (qrf.contains(qp))
		return Qt::TitleBarArea;

	return Qt::NoSection;
}
Esempio n. 5
0
void Collider::drawScaleOverlay(QPainter *painter, QPen pen, QRectF outlineRect)
{
    painter->setBrush (Qt::NoBrush);
    painter->setOpacity (0.9);



    pen.setStyle (Qt::SolidLine);

    // draw rect bounds
    painter->drawRect (outlineRect);
    painter->setBrush (Qt::NoBrush);
    int cSize = mScaleFeedbackRectsSize;
    //Corners

    QVector<QRectF> rects;
    // The first four is the corners and the next four is the middle of the sides.
    rects << QRectF( outlineRect.topLeft ().x()-(cSize/2), outlineRect.topLeft ().y()-(cSize/2),cSize,cSize)
          << QRectF( outlineRect.bottomLeft ().x()-(cSize/2), outlineRect.bottomLeft ().y()-(cSize/2),cSize,cSize)
          << QRectF( outlineRect.topRight ().x()-(cSize/2), outlineRect.topRight ().y()-(cSize/2),cSize,cSize)
          << QRectF( outlineRect.bottomRight ().x()-(cSize/2), outlineRect.bottomRight ().y()-(cSize/2),cSize,cSize)

          << QRectF( outlineRect.bottomRight ().x()-(outlineRect.width()/2)-(cSize/2), outlineRect.bottomRight ().y()-(cSize/2),cSize,cSize)
          << QRectF( outlineRect.bottomRight ().x()-(outlineRect.width()/2)-(cSize/2), outlineRect.topRight().y()-(cSize/2),cSize,cSize)
          << QRectF( outlineRect.bottomLeft ().x()-(cSize/2), outlineRect.bottomRight ().y()-(outlineRect.height()/2)-(cSize/2),cSize,cSize)
          << QRectF( outlineRect.bottomRight().x()-(cSize/2), outlineRect.bottomRight ().y()-(outlineRect.height()/2)-(cSize/2),cSize,cSize);

    painter->setBrush (QColor(Qt::blue));
    pen.setStyle (Qt::SolidLine);
    painter->drawRects (rects);
}
void TaskItemDelegate::paintPriorityHeader(QPainter* painter, const QRectF& rect, const QModelIndex &index) const
{
  painter->save();
  
  //Draw colored gradient as priority background
  QLinearGradient gradient(rect.topLeft(), rect.bottomRight());
  gradient.setColorAt(0, itemPriorityColor(index));
  gradient.setColorAt(1, Qt::transparent);
  
  int h = QApplication::fontMetrics().height();
  QPainterPath path;
  path.moveTo(rect.bottomLeft());
  path.quadTo(rect.bottomLeft()+QPointF(0, -h), rect.bottomLeft()+QPointF(2, -h));
  path.lineTo(rect.bottomRight()-QPointF(2, h));
  path.quadTo(rect.bottomRight()+QPointF(0, -h), rect.bottomRight());
  painter->setBrush(Qt::NoBrush);
  QPen thickPen(itemPriorityColor(index));
  thickPen.setWidth(2);
  painter->setPen(thickPen);
  painter->drawPath(path);
  
  // Draw priority text
  QString priority = index.data(Qt::DisplayRole).toString();
  painter->setPen(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
  painter->setBrush(Qt::NoBrush);
  painter->drawText(rect.bottomLeft()+QPoint(MARGIN, -2*MARGIN) ,priority);
 
  painter->restore();
}
Esempio n. 7
0
QRectF RectangleShape::boundingRect() const
{
    #define angle rotation()

    QRectF tmp = self->boundingRect();
    int centerX = (tmp.topLeft().x() + tmp.bottomRight().x()) / 2;
    int centerY = (tmp.topLeft().y() + tmp.bottomRight().y()) / 2;
    QPointF topLeft = QPoint(centerX + (tmp.topLeft().x() - centerX) * cos(angle)
            - (tmp.topLeft().x() - centerY) * sin(angle),
            centerY + (tmp.topLeft().y() - centerY) * cos(angle)
            + (tmp.topLeft().x() - centerX) * sin(angle));
    QPointF topRight = QPoint(centerX + (tmp.topRight().x() - centerX) * cos(angle)
            - (tmp.topRight().x() - centerY) * sin(angle),
            centerY + (tmp.topRight().y() - centerY) * cos(angle)
            + (tmp.topRight().x() - centerX) * sin(angle));
    QPointF bottomRight = QPoint(centerX + (tmp.bottomRight().x() - centerX) * cos(angle)
            - (tmp.bottomRight().x() - centerY) * sin(angle),
            centerY + (tmp.bottomRight().y() - centerY) * cos(angle)
            + (tmp.bottomRight().x() - centerX) * sin(angle));
    QPointF bottomLeft = QPoint(centerX + (tmp.bottomLeft().x() - centerX) * cos(angle)
            - (tmp.bottomLeft().x() - centerY) * sin(angle),
            centerY + (tmp.bottomLeft().y() - centerY) * cos(angle)
            + (tmp.bottomLeft().x() - centerX) * sin(angle));

    QPointF newTopLeft = QPointF(topLeft.x(), topRight.y());
    QPointF newBottomRight = QPointF(bottomRight.x(), bottomLeft.y());

    tmp = QRectF(newTopLeft, newBottomRight);
    return tmp;
}
static void updateAnchorLinePoints(QPointF *firstPoint, QPointF *secondPoint, const AnchorLine &anchorLine)
{
    QRectF boundingRectangle = anchorLine.qmlItemNode().instanceBoundingRect().adjusted(0., 0., 1., 1.);

    switch (anchorLine.type()) {
    case AnchorLine::Top:
        *firstPoint = boundingRectangle.topLeft();
        *secondPoint = boundingRectangle.topRight();
        break;
    case AnchorLine::Bottom:
        *firstPoint = boundingRectangle.bottomLeft();
        *secondPoint = boundingRectangle.bottomRight();
        break;
    case AnchorLine::Left:
        *firstPoint = boundingRectangle.topLeft();
        *secondPoint = boundingRectangle.bottomLeft();
        break;
    case AnchorLine::Right:
        *firstPoint = boundingRectangle.topRight();
        *secondPoint = boundingRectangle.bottomRight();
        break;
    default:
        break;
    }

    *firstPoint = anchorLine.qmlItemNode().instanceSceneTransform().map(*firstPoint);
    *secondPoint = anchorLine.qmlItemNode().instanceSceneTransform().map(*secondPoint);
}
Esempio n. 9
0
void Target::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w)
{
    Q_UNUSED(w);
    Q_UNUSED(option);
    
    QColor color;
    color = QColor("green");
    color.setAlpha(180);

    QRectF square = boundingRect();
    painter->setBrush(color);
    painter->drawRoundRect(square);

    painter->save();
    color = QColor("white");
    color.setAlpha(220); 
    painter->setPen(color);
    QPointF point1 = QPointF(square.topLeft().x() + 3, square.topLeft().y() + 3); 
    QPointF point2 = QPointF(square.bottomRight().x() - 3, square.bottomRight().y() - 3);
    QPointF point3 = QPointF(square.bottomLeft().x() + 3, square.bottomLeft().y() - 3);
    QPointF point4 = QPointF(square.topRight().x() - 3, square.topRight().y() + 3);

    painter->drawLine(point1, point2);
    painter->drawLine(point3, point4);
    painter->restore();
}
Esempio n. 10
0
static void updateGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &textureRect)
{
    auto *v = LightedPoint2D::from(g);
    v[0] = { QVector2D(rect.topLeft()), QVector2D(textureRect.topLeft()), QVector2D(), QVector2D() };
    v[1] = { QVector2D(rect.bottomLeft()), QVector2D(textureRect.bottomLeft()), QVector2D(), QVector2D() };
    v[2] = { QVector2D(rect.topRight()), QVector2D(textureRect.topRight()), QVector2D(), QVector2D() };
    v[3] = { QVector2D(rect.bottomRight()), QVector2D(textureRect.bottomRight()), QVector2D(), QVector2D() };
}
Esempio n. 11
0
void KoContextBarButton::paintEvent(QPaintEvent*)
{
    QStylePainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    QStyleOptionToolButton opt;
    initStyleOption(&opt);

    const QColor bgColor = palette().color(QPalette::Highlight);
    QColor color = bgColor.dark(CONTEXTBAR_BACKGROUND_DARKNESS);
    QColor borderColor = bgColor.light(CONTEXTBAR_BORDER_LIGHTNESS);

    if (opt.state & QStyle::State_MouseOver && opt.state & QStyle::State_Enabled) {
            color = color.light(CONTEXTBAR_MOUSEOVER_LIGHTNESS);
            borderColor = borderColor.lighter(CONTEXTBAR_MOUSEOVER_LIGHTNESS);
    }

    const QRectF rectF = QRectF(opt.rect).adjusted(0.5, 0.5, -0.5, -0.5);
    QPainterPath path;
    path.addRoundRect(rectF, CONTEXTBAR_RADIUS, CONTEXTBAR_RADIUS);

    if (m_fadingValue < 255) {
        color.setAlpha(m_fadingValue);
    }

    // Background
    painter.fillPath(path, color);

    if (opt.state & QStyle::State_Raised && opt.state & QStyle::State_Enabled) {
        // Bottom shadow
        QLinearGradient gradient(rectF.bottomLeft(), rectF.bottomLeft() - QPoint(0, 5));
        gradient.setColorAt(0, QColor::fromHsvF(0, 0, 0, .3));
        gradient.setColorAt(1, Qt::transparent);
        painter.fillPath(path, gradient);

        // Left shadow
        gradient.setFinalStop(rectF.bottomLeft() + QPoint(3, 0));
        painter.fillPath(path, gradient);
    }
    else {
        // Top shadow
        QLinearGradient gradient(rectF.topLeft(), rectF.topLeft() + QPoint(0, 5));
        gradient.setColorAt(0, QColor::fromHsvF(0, 0, 0, .3));
        gradient.setColorAt(1, Qt::transparent);
        painter.fillPath(path, gradient);

        // Left shadow
        gradient.setFinalStop(rectF.topLeft() + QPoint(5, 0));
        painter.fillPath(path, gradient);
    }

    // Border
    painter.setPen(QPen(borderColor, 0));
    painter.drawPath(path);

    // Content
    painter.drawControl(QStyle::CE_ToolButtonLabel, opt);
}
Esempio n. 12
0
bool Utils::QRectInterstects(const QRectF& r, const QLineF& lF, QPointF& a, QPointF& b)
{
    QPointF pF;
    bool hasP1 = false;
    bool hasP2 = false;

    if (QLineF(r.topLeft(), r.bottomLeft()).intersect(lF, &pF) == QLineF::BoundedIntersection) {
        a = pF;
        hasP1 = true;
    }
    if (QLineF(r.bottomLeft(), r.bottomRight()).intersect(lF, &pF) == QLineF::BoundedIntersection) {
        if (hasP1) {
            b = pF;
            hasP2 = true;
        } else {
            a = pF;
            hasP1 = true;
        }
    }
    if (QLineF(r.bottomRight(), r.topRight()).intersect(lF, &pF) == QLineF::BoundedIntersection) {
        if (hasP1) {
            b = pF;
            hasP2 = true;
        } else {
            a = pF;
            hasP1 = true;
        }
    }
    if (QLineF(r.topRight(), r.topLeft()).intersect(lF, &pF) == QLineF::BoundedIntersection) {
        if (hasP1) {
            b = pF;
            hasP2 = true;
        } else {
            a = pF;
            hasP1 = true;
        }
    }

    if (hasP1 && hasP2) {
#if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
        qreal la1 = QLineF(a,b).angleTo(lF);
#else
        qreal la1 = QLineF(a,b).angle(lF);
#endif
        if (la1 > 15.0 && la1 < 345.0) {
            QPointF t = b;
            b = a;
            a = t;
        }
    }
    if (hasP1)
        return true;
    else
        return false;
}
Esempio n. 13
0
/*!
  Draw a histogram in Lines style()

  \param painter Painter
  \param xMap Maps x-values into pixel coordinates.
  \param yMap Maps y-values into pixel coordinates.
  \param from Index of the first sample to be painted
  \param to Index of the last sample to be painted. If to < 0 the
         histogram will be painted to its last point.

  \sa setStyle(), style(), setPen()
*/
void QwtPlotHistogram::drawLines( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    int from, int to ) const
{
    const bool doAlign = QwtPainter::roundingAlignment( painter );

    painter->setPen( d_data->pen );
    painter->setBrush( Qt::NoBrush );

    for ( int i = from; i <= to; i++ )
    {
        const QwtIntervalSample sample = d_series->sample( i );
        if ( !sample.interval.isNull() )
        {
            const QwtColumnRect rect = columnRect( sample, xMap, yMap );

            QRectF r = rect.toRect();
            if ( doAlign )
            {
                r.setLeft( qRound( r.left() ) );
                r.setRight( qRound( r.right() ) );
                r.setTop( qRound( r.top() ) );
                r.setBottom( qRound( r.bottom() ) );
            }

            switch ( rect.direction )
            {
                case QwtColumnRect::LeftToRight:
                {
                    QwtPainter::drawLine( painter,
                        r.topRight(), r.bottomRight() );
                    break;
                }
                case QwtColumnRect::RightToLeft:
                {
                    QwtPainter::drawLine( painter,
                        r.topLeft(), r.bottomLeft() );
                    break;
                }
                case QwtColumnRect::TopToBottom:
                {
                    QwtPainter::drawLine( painter,
                        r.bottomRight(), r.bottomLeft() );
                    break;
                }
                case QwtColumnRect::BottomToTop:
                {
                    QwtPainter::drawLine( painter,
                        r.topRight(), r.topLeft() );
                    break;
                }
            }
        }
    }
}
Esempio n. 14
0
void CanvasRect::paint(QPainter *painter, const QTransform &tran, const QRectF &limits)
{
    QRectF plotRect = bounds();
    // Let's not waste time here...
    if (!limits.intersects(plotRect)) return;

    // TODO: This boilerplate style stuff to a CanvasShape::applyStyle(QPainter*) func?
    QPen pen;
    LineSpec *ln = lineSpec();
    pen.setColor(ln->color());
    pen.setWidthF(ln->width());

    QString style = ln->style();
    if (style == ".") {
        pen.setStyle(Qt::SolidLine);
    } else {
        pen.setStyle( LineSpec::styleMap[style] );
    }

    QBrush brush;
    brush.setStyle(Qt::SolidPattern);
    brush.setColor(fillSpec()->color());

    painter->setRenderHint(QPainter::Antialiasing);

    // Only draw the part of the rect in the view
    QRectF rect = limits.intersected(plotRect);
    // Figure out which sides still need lines...
    QVector<QLineF> lines;
    if (rect.left() == plotRect.left())
        lines << QLineF(rect.bottomLeft(), rect.topLeft());
    if (rect.right() == plotRect.right())
        lines << QLineF(rect.bottomRight(), rect.topRight());
    if (rect.top() == plotRect.top())
        lines << QLineF(rect.topLeft(), rect.topRight());
    if (rect.bottom() == plotRect.bottom())
        lines << QLineF(rect.bottomLeft(), rect.bottomRight());

    // Map the fill and lines
    QRectF mappedRect = tran.mapRect(rect);
    for (int i=0; i<lines.length(); ++i) {
        lines[i] = tran.map(lines[i]);
    }

    // Draw the rect
    painter->setPen(Qt::NoPen);
    painter->setBrush(brush);
    painter->drawRect(mappedRect);

    // Draw the outline
    painter->setBrush(Qt::NoBrush);
    painter->setPen(pen);
    painter->drawLines(lines);
}
Esempio n. 15
0
void TexturedGeometry::setRect(const QRectF &r, const QRectF &tr)
{
    setPoint(0, r.topLeft(), tr.topLeft());
    setPoint(1, r.bottomLeft(), tr.bottomLeft());
    if (tri == Strip) {
        setPoint(2, r.topRight(), tr.topRight());
        setPoint(3, r.bottomRight(), tr.bottomRight());
    } else {
        setPoint(3, r.topRight(), tr.topRight());
        setPoint(2, r.bottomRight(), tr.bottomRight());
    }
}
void UBGraphicsDelegateFrame::initializeTransform()
{
    QTransform itemTransform = delegated()->sceneTransform();
    QRectF itemRect = delegated()->boundingRect();
    QPointF topLeft = itemTransform.map(itemRect.topLeft());
    QPointF topRight = itemTransform.map(itemRect.topRight());
    QPointF  bottomLeft = itemTransform.map(itemRect.bottomLeft());

    qreal horizontalFlip = (topLeft.x() > topRight.x()) ? -1 : 1;
    mMirrorX = horizontalFlip < 0 ;
    if(horizontalFlip < 0) {
        // why this is because of the way of calculating the translations that checks which side is the most is the
        // nearest instead of checking which one is the left side.
        QPointF tmp = topLeft;
        topLeft = topRight;
        topRight = tmp;

        // because of the calculation of the height is done by lenght and not deltaY
        bottomLeft = itemTransform.map(itemRect.bottomRight());
    }

    qreal verticalFlip = (bottomLeft.y() < topLeft.y()) ? -1 : 1;
    // not sure that is usefull
    mMirrorY = verticalFlip < 0;
    if(verticalFlip < 0 && !mMirrorX) {
        topLeft = itemTransform.map(itemRect.bottomLeft());
        topRight = itemTransform.map(itemRect.bottomRight());
        bottomLeft = itemTransform.map(itemRect.topLeft());
    }

    QLineF topLine(topLeft, topRight);
    QLineF leftLine(topLeft, bottomLeft);
    qreal width = topLine.length();
    qreal height = leftLine.length();

    mAngle = topLine.angle();

    // the fact the the length is used we loose the horizontalFlip information
    // a better way to do this is using DeltaX that preserve the direction information.
    mTotalScaleX = (width / itemRect.width()) * horizontalFlip;
    mTotalScaleY = height / itemRect.height() * verticalFlip;

    QTransform tr;
    QPointF center = delegated()->boundingRect().center();
    tr.translate(center.x() * mTotalScaleX, center.y() * mTotalScaleY);
    tr.rotate(-mAngle);
    tr.translate(-center.x() * mTotalScaleX, -center.y() * mTotalScaleY);
    tr.scale(mTotalScaleX, mTotalScaleY);

    mTotalTranslateX = delegated()->transform().dx() - tr.dx();
    mTotalTranslateY = delegated()->transform().dy() - tr.dy();
}
Esempio n. 17
0
static void qwtDrawPanel( QPainter *painter, const QRectF &rect,
    const QPalette &pal, double lw )
{
    if ( lw > 0.0 )
    {
        if ( rect.width() == 0.0 )
        {
            painter->setPen( pal.window().color() );
            painter->drawLine( rect.topLeft(), rect.bottomLeft() );
            return;
        }

        if ( rect.height() == 0.0 )
        {
            painter->setPen( pal.window().color() );
            painter->drawLine( rect.topLeft(), rect.topRight() );
            return;
        }

        lw = qMin( lw, rect.height() / 2.0 - 1.0 );
        lw = qMin( lw, rect.width() / 2.0 - 1.0 );

        const QRectF outerRect = rect.adjusted( 0, 0, 1, 1 );
        const QRectF innerRect = outerRect.adjusted( lw, lw, -lw, -lw );

        QPolygonF lines[2];

        lines[0] += outerRect.bottomLeft();
        lines[0] += outerRect.topLeft();
        lines[0] += outerRect.topRight();
        lines[0] += innerRect.topRight();
        lines[0] += innerRect.topLeft();
        lines[0] += innerRect.bottomLeft();

        lines[1] += outerRect.topRight();
        lines[1] += outerRect.bottomRight();
        lines[1] += outerRect.bottomLeft();
        lines[1] += innerRect.bottomLeft();
        lines[1] += innerRect.bottomRight();
        lines[1] += innerRect.topRight();

        painter->setPen( Qt::NoPen );

        painter->setBrush( pal.light() );
        painter->drawPolygon( lines[0] );
        painter->setBrush( pal.dark() );
        painter->drawPolygon( lines[1] );
    }

    painter->fillRect( rect.adjusted( lw, lw, -lw + 1, -lw + 1 ), pal.window() );
}
Esempio n. 18
0
File: node.cpp Progetto: nanox/tupi
void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w)
{
    Q_UNUSED(w);
    Q_UNUSED(option);
    
    QColor color;
   
    if (k->typeNode != Center) {
        if (k->action == Rotate) {
            color = QColor(255, 102, 0);
            color.setAlpha(180);
        } else {
            color = QColor("green");
            color.setAlpha(200);
        }
    } else {
        if (k->generalState == Scale) {
            color = QColor(150, 150, 150);
        } else {
           color = QColor(255, 0, 0);
        }
        color.setAlpha(150);
    }

    QRectF square = boundingRect();
    painter->setBrush(color);
    painter->drawRoundRect(square);

    /* SQA: Code for debugging purposes
    #ifdef K_DEBUG
        painter->setFont(QFont(painter->font().family(), 5));
        painter->drawText(square, QString::number(k->typeNode));
    #endif
    */

    if (k->typeNode == Center) {
        painter->save();
        color = QColor("white");
        color.setAlpha(220);
        painter->setPen(color);

        QPointF point1 = QPointF(square.topLeft().x() + 2, square.topLeft().y() + 2);
        QPointF point2 = QPointF(square.bottomRight().x() - 2, square.bottomRight().y() - 2);
        QPointF point3 = QPointF(square.bottomLeft().x() + 2, square.bottomLeft().y() - 2);
        QPointF point4 = QPointF(square.topRight().x() - 2, square.topRight().y() + 2);

        painter->drawLine(point1, point2);
        painter->drawLine(point3, point4);
        painter->restore();
    }
}
Esempio n. 19
0
/// <summary>
/// Overridden paint even which draws the points, axes and curves.
/// </summary>
/// <param name="e">Ignored</param>
void CurvesGraphicsView::paintEvent(QPaintEvent* e)
{
	QGraphicsView::paintEvent(e);
	
	int i;
	QRectF rect = scene()->sceneRect();
	double w2 = width() / 2;
	double h2 = height() / 2;

	//Draw axis lines.
	m_XLine->setLine(QLineF(0, h2, width(), h2));
	m_YLine->setLine(QLineF(w2, 0, w2, height()));

	//This must be constructed every time and cannot be a member.
	QPainter painter(viewport());
	painter.setClipRect(rect);
	painter.setRenderHint(QPainter::Antialiasing);

	//Create 4 new paths. These must be constructed every time and cannot be members.
	QPainterPath paths[4] =
	{
		QPainterPath(mapFromScene(rect.bottomLeft())),
		QPainterPath(mapFromScene(rect.bottomLeft())),
		QPainterPath(mapFromScene(rect.bottomLeft())),
		QPainterPath(mapFromScene(rect.bottomLeft()))
	};

	//Draw paths for all but the topmost curve.
	for (i = 0; i < 4; i++)
	{
		paths[i].cubicTo(m_Points[i].first->pos(), m_Points[i].second->pos(), mapFromScene(rect.topRight()));

		if (m_Points[i].first->zValue() == 1)
		{
			painter.setPen(*m_Pens[i]);
			painter.drawPath(paths[i]);
		}
	}

	//Draw the topmost curve.
	for (i = 0; i < 4; i++)
	{
		if (m_Points[i].first->zValue() == 2)
		{
			painter.setPen(*m_Pens[i]);
			painter.drawPath(paths[i]);
			break;
		}
	}
}
Esempio n. 20
0
bool DiagramItem::intersectShapeWithLine(const QLineF &line, QPointF *intersectionPoint, QLineF *intersectionLine) const
{
    QPolygonF polygon;
    if (m_customIcon) {
        // TODO use customIcon path as shape
        QRectF rect = object()->rect();
        rect.translate(object()->pos());
        polygon << rect.topLeft() << rect.topRight() << rect.bottomRight() << rect.bottomLeft() << rect.topLeft();
    } else {
        QRectF rect = object()->rect();
        rect.translate(object()->pos());
        polygon << rect.topLeft() << rect.topRight() << rect.bottomRight() << rect.bottomLeft() << rect.topLeft();
    }
    return GeometryUtilities::intersect(polygon, line, intersectionPoint, intersectionLine);
}
Esempio n. 21
0
QLineF
ImageView::edgePosition(int const edge) const
{
	QRectF const r(virtualToWidget().mapRect(m_contentRect));

	if (edge == TOP) {
		return QLineF(r.topLeft(), r.topRight());
	} else if (edge == BOTTOM) {
		return QLineF(r.bottomLeft(), r.bottomRight());
	} else if (edge == LEFT) {
		return QLineF(r.topLeft(), r.bottomLeft());
	} else {
		return QLineF(r.topRight(), r.bottomRight());
	}
}
Esempio n. 22
0
void eraseRegionObjectGroup(MapDocument *mapDocument,
                            ObjectGroup *layer,
                            const QRegion &where)
{
    QUndoStack *undo = mapDocument->undoStack();

    const auto objects = layer->objects();
    for (MapObject *obj : objects) {
        // TODO: we are checking bounds, which is only correct for rectangles and
        // tile objects. polygons and polylines are not covered correctly by this
        // erase method (we are in fact deleting too many objects)
        // TODO2: toAlignedRect may even break rects.

        // Convert the boundary of the object into tile space
        const QRectF objBounds = obj->boundsUseTile();
        QPointF tl = mapDocument->renderer()->pixelToTileCoords(objBounds.topLeft());
        QPointF tr = mapDocument->renderer()->pixelToTileCoords(objBounds.topRight());
        QPointF br = mapDocument->renderer()->pixelToTileCoords(objBounds.bottomRight());
        QPointF bl = mapDocument->renderer()->pixelToTileCoords(objBounds.bottomLeft());

        QRectF objInTileSpace;
        objInTileSpace.setTopLeft(tl);
        objInTileSpace.setTopRight(tr);
        objInTileSpace.setBottomRight(br);
        objInTileSpace.setBottomLeft(bl);

        const QRect objAlignedRect = objInTileSpace.toAlignedRect();
        if (where.intersects(objAlignedRect))
            undo->push(new RemoveMapObject(mapDocument, obj));
    }
}
Esempio n. 23
0
r2d2::Box ViewScene::qrect_2_box_coordinate(QRectF rect,
    double min_z,
    double max_z){
        return r2d2::Box(
            qpoint_2_box_coordinate(rect.bottomLeft(),min_z),
            qpoint_2_box_coordinate(rect.topRight(),max_z));
}
Esempio n. 24
0
void ObjectSelectionTool::updateHandles()
{
    if (mMode == Moving || mMode == Rotating)
        return;

    const QSet<MapObjectItem*> &items = mapScene()->selectedObjectItems();
    const bool showHandles = items.size() > 0;
    QRectF boundingRect;

    if (showHandles) {
        QSetIterator<MapObjectItem*> iter(items);
        MapObjectItem *item = iter.next();
        boundingRect = item->mapToScene(item->boundingRect()).boundingRect();

        while (iter.hasNext()) {
            item = iter.next();
            boundingRect |= item->mapToScene(item->boundingRect()).boundingRect();
        }

        mCornerHandles[TopLeft]->setPos(boundingRect.topLeft());
        mCornerHandles[TopRight]->setPos(boundingRect.topRight());
        mCornerHandles[BottomLeft]->setPos(boundingRect.bottomLeft());
        mCornerHandles[BottomRight]->setPos(boundingRect.bottomRight());

        // TODO: Might be nice to make it configurable
        mRotationOrigin = boundingRect.center();
        mRotationOriginIndicator->setPos(mRotationOrigin);
    }

    mSelectionBoundingRect = boundingRect;
    setHandlesVisible(showHandles);
    mRotationOriginIndicator->setVisible(showHandles);
}
Esempio n. 25
0
QPainterPath
Shapes::menu(const QRectF &bound, bool leftSide, Style style)
{
    _S(2)
    QPainterPath path;
    switch (style)
    {
    case Square:
    {
        _S(4)
        path.addRect(bound);
        path.addRect(bound.adjusted(leftSide ? s2 : 0, s4, leftSide ? 0 : -s2, 0));
        break;
    }
    case LasseKongo:
        path.moveTo(bound.topLeft() + QPointF(0, s2));
        path.lineTo(bound.topRight() + QPointF(0, s2));
        path.lineTo(bound.bottomLeft() + QPointF(s2, 0));
        path.closeSubpath();
        break;
    default:
    case Round:
    case TheRob:
    {
        _S(9)
        path.moveTo(bound.center());
        path.arcTo(bound, leftSide ? -90 : 0, 270);
        path.closeSubpath();
        path.addRect(bound.adjusted(leftSide ? 0 : 5*s9, 5*s9, leftSide ? -5*s9 : 0, 0));
        break;
    }
    }
    return path;
}
Esempio n. 26
0
void SceneObject::paint(QPainter &painter, const KoViewConverter &converter,
                        KoShapePaintingContext &context)
{
    Q_UNUSED(context);

    //painter.setPen(QPen(QColor(172, 196, 206)));
    painter.setPen(QPen(QColor(0, 0, 0)));

#if 1
    painter.drawRect(converter.documentToView(QRectF(QPoint(0, 0), size())));
#else
    QRectF rect = converter.documentToView(boundingRect());
    QRectF rect = converter.documentToView(QRectF(QPoint(0, 0), size()));
    painter.drawRect(rect);
#endif
    kDebug(31000) << "boundingRect: " << boundingRect();
    kDebug(31000) << "outlineRect: " << outlineRect();

#if 0 // Taken from the vector shape
    QRectF  rect(QPointF(0,0), m_size);
    painter.save();

    // Draw a simple cross in a rectangle just to indicate that there is something here.
    painter.setPen(QPen(QColor(172, 196, 206)));
    painter.drawRect(rect);
    painter.drawLine(rect.topLeft(), rect.bottomRight());
    painter.drawLine(rect.bottomLeft(), rect.topRight());

    painter.restore();
#endif
}
static void qwtFillBackground( QPainter *painter, QwtPlotCanvas *canvas )
{
    QVector<QRectF> rects;

    if ( canvas->testAttribute( Qt::WA_StyledBackground ) )
    {
        QwtStyleSheetRecorder recorder( canvas->size() );

        QPainter p( &recorder );
        qwtDrawStyledBackground( canvas, &p );
        p.end();

        if ( recorder.background.brush.isOpaque() )
            rects = recorder.clipRects;
        else
            rects += canvas->rect();
    }
    else
    {
        const QRectF r = canvas->rect();
        const double radius = canvas->borderRadius();
        if ( radius > 0.0 )
        {
            QSizeF sz( radius, radius );

            rects += QRectF( r.topLeft(), sz );
            rects += QRectF( r.topRight() - QPointF( radius, 0 ), sz );
            rects += QRectF( r.bottomRight() - QPointF( radius, radius ), sz );
            rects += QRectF( r.bottomLeft() - QPointF( 0, radius ), sz );
        }
    }

    qwtFillBackground( painter, canvas, rects);
}
Esempio n. 28
0
void LinearLabel::paintEvent(QPaintEvent *e)
{
    QPainter painter(this);
    QRect r = rect();
    if(m_backgroundPixmap.isNull())
    {
        painter.fillRect(r, m_backgroundColor);
    }
    else
    {
        painter.drawPixmap(r, m_backgroundPixmap);
    }

    QFontMetrics fm = painter.fontMetrics();
    QString elidedText = fm.elidedText(m_text, Qt::ElideRight
                                       , r.width() - 4
                                       );
    if(m_linearGradient)
    {
        QRectF boundingRect = fm.boundingRect(r, m_flags,elidedText);
        m_linearGradient->setStart(boundingRect.topLeft());
        m_linearGradient->setFinalStop(boundingRect.bottomLeft());
        QPen linearPen(QBrush(*m_linearGradient), m_penWidth);
        painter.setPen(linearPen);
        painter.drawText(boundingRect, m_flags, elidedText);
    }
    else
    {
        QPen pen(m_textColor, m_penWidth);
        painter.setPen(pen);
        painter.drawText(r, m_flags, elidedText);
    }
}
Esempio n. 29
0
void MainMenuScene::createNumPlayerButtons()
{
  const double buttonSpacing = 1.5;
  const unsigned int maxPlayers = 8;
  QSignalMapper* signalMapper = new QSignalMapper(this);
  QRectF tableRect = getTableRect();
  double totalWidth = 0;
  std::array<Button*, maxPlayers+1> buttons;
  for ( unsigned int i = 1; i < buttons.size(); ++i )
  {
    buttons[i] = new Button(std::to_string(i));
    totalWidth += buttonSpacing * buttons[i]->boundingRect().width();
  }
  double currentOffsetY = -0.5 * totalWidth;
  for ( unsigned int i = 1; i < buttons.size(); ++i )
  {
    QRectF buttonRect = buttons[i]->boundingRect();
    QPointF buttonOffset = buttonRect.bottomRight() - buttonRect.topLeft();
    buttons[i]->setPos(0.5 * tableRect.center() +
                       0.25 * tableRect.bottomLeft() +
                       0.25 * tableRect.bottomRight() +
                       QPointF(currentOffsetY, 0) - 0.5*buttonOffset );
    currentOffsetY += buttonSpacing * buttonRect.width();
    connect(buttons[i], SIGNAL(pressed()), signalMapper, SLOT(map()));
    signalMapper->setMapping(buttons[i], i );
    addItem( buttons[i] );
  }
  connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(slotChangeNumPlayers(int)));
}
Esempio n. 30
0
QPointF realPointOnRectF(const QRectF& rect,RectPointName::Enum pointName)
{
	switch (pointName)
	{
	case RectPointName::TopLeft:
		return rect.topLeft();
	case RectPointName::TopRight:
		return rect.topRight();
	case RectPointName::BottomLeft:
		return rect.bottomLeft();
	case RectPointName::BottomRight:
		return rect.bottomRight();
	default:
	case RectPointName::Center:
		return rect.center();
	case RectPointName::TopCenter:
		return QPointF(rect.center().x(),rect.top());
	case RectPointName::RightCenter:
		return QPointF(rect.right(),rect.center().y());
	case RectPointName::BottomCenter:
		return QPointF(rect.center().x(),rect.bottom());
	case RectPointName::LeftCenter:
		return QPointF(rect.left(),rect.center().y());
	}
	return QPointF();	//keep compilers happy
}