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;
}
Example #2
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);
}
Example #3
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();
}
Example #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;
}
void FacebookContactUI::paintFrontView(QPainter *painter, const QRectF &rect)
{
    QPainterPath backgroundPath;
    backgroundPath.addRoundedRect(rect, 6.0, 6.0);

    painter->fillPath(backgroundPath, QColor(235, 235, 235));

    if (d->mSearchBox) {
        QRectF searchBoxRect = QRectF (0.0, d->mScrollView->contentRect().height() + 28,
                                       rect.width(), rect.height());

        QRectF searchBoxLineRect = QRectF (0.0, d->mScrollView->contentRect().height() + 29,
                                       rect.width(), rect.height());

        QPen pen = QPen(QColor(220, 220, 220), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
        painter->setPen(pen);

        QLinearGradient linearGrad(searchBoxRect.topRight(), searchBoxRect.bottomRight());

        linearGrad.setColorAt(0, QColor(93, 103, 114));
        linearGrad.setColorAt(1, QColor(66, 77, 88));

        painter->fillRect(searchBoxRect, linearGrad);
        painter->drawLine(searchBoxRect.topRight(), searchBoxRect.topLeft());
        pen = QPen(QColor(88, 88, 88), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
        painter->setPen(pen);
        painter->drawLine(searchBoxLineRect.topRight(), searchBoxLineRect.topLeft());
    }
}
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;
}
void ItemScene::determinePointsInSelection()
{
    QRectF controlRect = this->selectionPathItem->path().controlPointRect();
    QPainterPath path = this->selectionPathItem->path();

    QImage sourceImage = this->imageFileItem->pixmap().toImage();
    QImage extractedImage(controlRect.width(), controlRect.height(), QImage::Format_RGB888);

    for(int yPos = controlRect.topLeft().y(); yPos < controlRect.topLeft().y() + controlRect.height(); yPos++)
    {
        for(int xPos = controlRect.topLeft().x(); xPos < controlRect.topLeft().x() + controlRect.width(); xPos++)
        {
            if(path.contains(QPointF(xPos, yPos)))
            {
                extractedImage.setPixel( xPos - (controlRect.topRight().x() - controlRect.width()), yPos - (controlRect.bottomLeft().y() - controlRect.height()),sourceImage.pixel(xPos, yPos));
            }
            else extractedImage.setPixel( xPos - (controlRect.topRight().x() - controlRect.width()), yPos - (controlRect.bottomLeft().y() - controlRect.height()), QRgb(qRgb(255,255,255)));

        }
    }

    this->imageFileItem->setPixmap(QPixmap::fromImage(extractedImage));
    this->imageFileItem->setPos(this->sceneRect().center().operator -=(QPointF(extractedImage.width()/2, extractedImage.height()/2)));
    this->imageFileItem->update();

    this->removeItem(this->selectionPathItem);

    for(QList<SelectionMarker*>::iterator iterator = this->selectionMarkers->begin(); iterator != this->selectionMarkers->end(); iterator++)
    {
       this->removeItem( (*iterator));
    }
}
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);
}
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() };
}
Example #10
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;
}
Example #11
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;
                }
            }
        }
    }
}
Example #12
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);
}
Example #13
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());
    }
}
Example #14
0
void SlippyMapWidget::setViewportArea(QRectF theRect)
{
    qreal zoom = 360.0 / theRect.width();
    zoom = log10(zoom)/log10(2.0);
    if (zoom < MINZOOMLEVEL)
        zoom = MINZOOMLEVEL;
    if (zoom > MAXZOOMLEVEL)
        zoom = MAXZOOMLEVEL;
    p->VpZoom = int(zoom);

    p->VpLon = long2tile(theRect.topRight().x(), p->VpZoom);
    p->VpLat = lat2tile(theRect.topRight().y(), p->VpZoom);
}
Example #15
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() );
}
Example #16
0
File: node.cpp Project: 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();
    }
}
Example #17
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());
	}
}
Example #18
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);
}
Example #19
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
}
Example #20
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));
    }
}
Example #21
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));
}
Example #22
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);
}
Example #23
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;
}
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);
}
Example #25
0
void SensorViewer::drawBackground(QPainter *painter, const QRectF &rect)
{
	const int digAfterDot = 1;
	QRectF sceneRect = this->sceneRect();

	// Fill section
	QLinearGradient gradient(sceneRect.bottomLeft(), sceneRect.topRight());
	gradient.setColorAt(0, Qt::black);
	gradient.setColorAt(1, Qt::darkGreen);
	painter->fillRect(mScene->sceneRect(), gradient);
	painter->setBrush(Qt::NoBrush);
	painter->setBrush(Qt::CrossPattern);
	painter->drawRect(mScene->sceneRect());

	// Text display section
	QRectF textRect(sceneRect.left() + 4, sceneRect.top() + 4, 50, 50);
	QString maxDisplay(QString::number(mPointsDataProcessor->maxLimit(), 'f', digAfterDot));
	QString minDisplay(QString::number(mPointsDataProcessor->minLimit(), 'f', digAfterDot));
	QString currentDisplay(QString::number(mOutputValue, 'f', digAfterDot));

	QFont font = painter->font();
	font.setBold(true);
	font.setPointSize(10);
	painter->setFont(font);
	painter->setPen(Qt::lightGray);
	painter->drawText(textRect.translated(2, 2), maxDisplay);
	painter->drawText(textRect.translated(2, sceneRect.height() - 20), minDisplay);
	painter->drawText(textRect.translated(sceneRect.width() - 35, sceneRect.height() - 20), currentDisplay);
	painter->setPen(Qt::black);
	Q_UNUSED(rect);
}
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 );
}
Example #27
0
    /*!
     * \brief Utility method that returns the resize handle area around rect for the point passed.
     *
     * \param point   The point to be tested for collision with handle rectangle around rect.
     * \param handles The bitmask indicating the handle areas to be tested.
     * \param rect    The rectangle around which resize handles are to be tested.
     */
    ResizeHandle handleHitTest(const QPointF& point, ResizeHandles handles,
            const QRectF& rect)
    {
        if(handles == Qucs::NoHandle) {
            return Qucs::NoHandle;
        }

        if(handles.testFlag(Qucs::TopLeftHandle)) {
            if(Qucs::handleRect.translated(rect.topLeft()).contains(point)) {
                return Qucs::TopLeftHandle;
            }
        }

        if(handles.testFlag(Qucs::TopRightHandle)) {
            if(Qucs::handleRect.translated(rect.topRight()).contains(point)) {
                return Qucs::TopRightHandle;
            }
        }

        if(handles.testFlag(Qucs::BottomLeftHandle)){
            if(Qucs::handleRect.translated(rect.bottomLeft()).contains(point)) {
                return Qucs::BottomLeftHandle;
            }
        }

        if(handles.testFlag(Qucs::BottomRightHandle)){
            if(Qucs::handleRect.translated(rect.bottomRight()).contains(point)) {
                return Qucs::BottomRightHandle;
            }
        }

        return Qucs::NoHandle;
    }
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
}
Example #29
0
void TextBrowser::paintEvent(QPaintEvent* event)
{
    QTextBrowser::paintEvent(event);

    QPainter painter(viewport());

    QTextBlock block;
    if (ub > 0)
        block = document()->findBlockByNumber(ub);

    if (block.isValid())
    {
        painter.save();
        painter.setPen(Qt::DashLine);
        painter.translate(-horizontalScrollBar()->value(), -verticalScrollBar()->value());

        QRectF br = document()->documentLayout()->blockBoundingRect(block);
        painter.drawLine(br.topLeft(), br.topRight());
        painter.restore();
    }

    QLinearGradient gradient(0, 0, 0, 3);
    gradient.setColorAt(0.0, palette().color(QPalette::Dark));
    gradient.setColorAt(1.0, Qt::transparent);
    painter.fillRect(0, 0, width(), 3, gradient);
}
Example #30
0
void DesignerGUIUtils::paintSamplesArrow(QPainter* painter) {
    QPen pen(Qt::darkGray);
    pen.setWidthF(2);
    painter->setPen(pen);
    painter->setRenderHint(QPainter::SmoothPixmapTransform);
    QFont f = painter->font();
    painter->resetTransform();
    f.setFamily("Times New Roman");
    f.setPointSizeF(20);
    f.setItalic(true);
    painter->setFont(f);

    QRectF approx(50,50, 400, 400);
    QString txt = QObject::tr("Select a sample to start");
    QRectF res = painter->boundingRect(approx, Qt::AlignLeft | Qt::AlignTop, txt);
    res.adjust(-5,-3,15,3);

    QPainterPath p(QPointF(5, res.center().y()));
    p.lineTo(res.topLeft());
    p.lineTo(res.topRight());
    p.lineTo(res.bottomRight());
    p.lineTo(res.bottomLeft());
    p.closeSubpath();
    QColor yc = QColor(255,255,160);//QColor(Qt::yellow).lighter();yc.setAlpha(127);
    painter->fillPath(p, QBrush(yc));
    painter->drawPath(p);
    painter->setPen(Qt::black);
    painter->drawText(approx, Qt::AlignLeft | Qt::AlignTop, txt);
}