コード例 #1
0
QPainterPath OrthogonalRenderer::shape(const MapObject *object) const
{
    QPainterPath path;

    if (!object->cell().isEmpty()) {
        path.addRect(boundingRect(object));
    } else {
        switch (object->shape()) {
        case MapObject::Rectangle: {
            const QRectF bounds = object->bounds();
            const QRectF rect(tileToPixelCoords(bounds.topLeft()),
                              tileToPixelCoords(bounds.bottomRight()));

            if (rect.isNull()) {
                path.addEllipse(rect.topLeft(), 20, 20);
            } else {
                path.addRoundedRect(rect, 10, 10);
            }
            break;
        }
        case MapObject::Polygon:
        case MapObject::Polyline: {
            const QPointF &pos = object->position();
            const QPolygonF polygon = object->polygon().translated(pos);
            const QPolygonF screenPolygon = tileToPixelCoords(polygon);
            if (object->shape() == MapObject::Polygon) {
                path.addPolygon(screenPolygon);
            } else {
                for (int i = 1; i < screenPolygon.size(); ++i) {
                    path.addPolygon(lineToPolygon(screenPolygon[i - 1],
                                                  screenPolygon[i]));
                }
                path.setFillRule(Qt::WindingFill);
            }
            break;
        }
        case MapObject::Ellipse: {
            const QRectF bounds = object->bounds();
            const QRectF rect(tileToPixelCoords(bounds.topLeft()),
                              tileToPixelCoords(bounds.bottomRight()));

            if (rect.isNull()) {
                path.addEllipse(rect.topLeft(), 20, 20);
            } else {
                path.addEllipse(rect);
            }
            break;
        }
        }
    }

    return path;
}
コード例 #2
0
ファイル: tiledlistview.cpp プロジェクト: jhj/aqp-qt5
void TiledListView::paintOutline(QPainter *painter,
                                 const QRectF &rectangle)
{
    const QRectF rect = rectangle.adjusted(0, 0, -1, -1);
    painter->save();
    painter->setPen(QPen(palette().dark().color(), 0.5));
    painter->drawRect(rect);
    painter->setPen(QPen(Qt::black, 0.5));
    painter->drawLine(rect.bottomLeft(), rect.bottomRight());
    painter->drawLine(rect.bottomRight(), rect.topRight());
    painter->restore();
}
コード例 #3
0
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();
}
コード例 #4
0
ファイル: qwt_column_symbol.cpp プロジェクト: Au-Zone/qwt
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() );
}
コード例 #5
0
ファイル: node.cpp プロジェクト: 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();
    }
}
コード例 #6
0
ファイル: NodeGraph05.cpp プロジェクト: MrKepzie/Natron
NATRON_NAMESPACE_ENTER
//using std::cout; using std::endl;

void
NodeGraph::moveNodeToCenterOfVisiblePortion(const NodeGuiPtr &n)
{
    QRectF viewPos = visibleSceneRect();
    QPointF position;
    position.setX( ( viewPos.bottomRight().x() + viewPos.topLeft().x() ) / 2. );
    position.setY( ( viewPos.topLeft().y() + viewPos.bottomRight().y() ) / 2. );

    position = n->mapFromScene(position);
    position = n->mapToParent(position);
    n->setPosition( position.x(), position.y() );
}
コード例 #7
0
ファイル: ImageView.cpp プロジェクト: 4sp1r3/scantailor
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());
	}
}
コード例 #8
0
ファイル: diagramitem.cpp プロジェクト: MarianMMX/qt-creator
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);
}
コード例 #9
0
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);
}
コード例 #10
0
QgsRectangle::QgsRectangle( QRectF const & qRectF )
{
  xmin = qRectF.topLeft().x();
  ymin = qRectF.topLeft().y();
  xmax = qRectF.bottomRight().x();
  ymax = qRectF.bottomRight().y();
}
コード例 #11
0
void QtViewportInteractionEngine::focusEditableArea(const QRectF& caretArea, const QRectF& targetArea)
{
    QRectF endArea = itemRectFromCSS(targetArea);

    qreal endItemScale = itemScaleFromCSS(innerBoundedCSSScale(2.0));
    const QRectF viewportRect = m_viewport->boundingRect();

    qreal x;
    const qreal borderOffset = 10;
    if ((endArea.width() + borderOffset) * endItemScale <= viewportRect.width()) {
        // Center the input field in the middle of the view, if it is smaller than
        // the view at the scale target.
        x = viewportRect.center().x() - endArea.width() * endItemScale / 2.0;
    } else {
        // Ensure that the caret always has borderOffset contents pixels to the right
        // of it, and secondarily (if possible), that the area has borderOffset
        // contents pixels to the left of it.
        qreal caretOffset = itemCoordFromCSS(caretArea.x()) - endArea.x();
        x = qMin(viewportRect.width() - (caretOffset + borderOffset) * endItemScale, borderOffset * endItemScale);
    }

    const QPointF hotspot = QPointF(endArea.x(), endArea.center().y());
    const QPointF viewportHotspot = QPointF(x, /* FIXME: visibleCenter */ viewportRect.center().y());

    QPointF endPosition = hotspot * endItemScale - viewportHotspot;
    QRectF endPosRange = computePosRangeForItemAtScale(endItemScale);

    endPosition = boundPosition(endPosRange.topLeft(), endPosition, endPosRange.bottomRight());

    QRectF endVisibleContentRect(endPosition / endItemScale, viewportRect.size() / endItemScale);

    animateItemRectVisible(endVisibleContentRect);
}
コード例 #12
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);
}
コード例 #13
0
void KarbonCalligraphyTool::paint(QPainter &painter, const KoViewConverter &converter)
{
    if (m_selectedPath) {
        painter.save();
        painter.setRenderHints(QPainter::Antialiasing, false);
        painter.setPen(Qt::red);   // TODO make configurable
        QRectF rect = m_selectedPath->boundingRect();
        QPointF p1 = converter.documentToView(rect.topLeft());
        QPointF p2 = converter.documentToView(rect.bottomRight());
        painter.drawRect(QRectF(p1, p2));
        painter.restore();
    }

    if (!m_shape) {
        return;
    }

    painter.save();

    painter.setTransform(m_shape->absoluteTransformation(&converter) *
                         painter.transform());
    KoShapePaintingContext paintContext; //FIXME
    m_shape->paint(painter, converter, paintContext);

    painter.restore();
}
コード例 #14
0
void GestXmlLoader::readCurve(QDomElement const &arch)
{
	QRectF rect = readRectOfXandY(arch);
	GestCurve* item = new GestCurve(rect.topLeft().x(), rect.topLeft().y(), rect.bottomRight().x(), rect.bottomRight().y());
	mScene->addItem(item);
	mScene->setLastAdded(item);
}
コード例 #15
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
}
コード例 #16
0
ファイル: WorkflowGUIUtils.cpp プロジェクト: m-angelov/ugene
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);
}
コード例 #17
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
}
コード例 #18
0
ファイル: GripperWidget.cpp プロジェクト: Aharobot/roscorobot
 void GripperWidget::drawBackground(QPainter *painter, const QRectF &rect)
 //draw the scene background
 {
     Q_UNUSED(rect);

     // Shadow
     QRectF sceneRect = this->sceneRect();
     QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
     QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
     if (rightShadow.intersects(rect) || rightShadow.contains(rect))
         painter->fillRect(rightShadow, Qt::darkGray);
     if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
         painter->fillRect(bottomShadow, Qt::darkGray);


     // Fill
     QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
     gradient.setColorAt(0, Qt::white);
     gradient.setColorAt(1, Qt::lightGray);
     painter->fillRect(rect.intersect(sceneRect), gradient);
     painter->setBrush(Qt::NoBrush);
     painter->drawRect(sceneRect);


     painter->setPen(Qt::blue);
     painter->drawLine(0, GRIPPER_BOTTOM_LINE, GRIPPER_X, GRIPPER_BOTTOM_LINE);
     painter->drawLine(GRIPPER_LEFT_LINE, 0, GRIPPER_LEFT_LINE, GRIPPER_Y);
     painter->drawLine(GRIPPER_RIGHT_LINE, 0, GRIPPER_RIGHT_LINE, GRIPPER_Y);

     painter->setPen(QPen(Qt::green,2));
     painter->drawArc(GRIPPER_CENTER_X - GRIPPER_CIRCLE_RADIUS,
                              GRIPPER_CENTER_Y - GRIPPER_CIRCLE_RADIUS,
                              GRIPPER_CIRCLE_RADIUS * 2,GRIPPER_CIRCLE_RADIUS  * 2,
                              0, 360 * 64);
 }
コード例 #19
0
HsWidgetPositioningOnWidgetAdd::Result HsAnchorPointInCenter::convert(
    const QRectF &contentArea,
    const QList<QRectF> &existingRects,
    const QList<QRectF> &newRects,
    const QPointF &startPoint )
{
    Q_UNUSED(existingRects);
    Q_UNUSED(startPoint)

    HsWidgetPositioningOnWidgetAdd::Result result;
    QList<QRectF> toGeometries;

    //Offset for widgets' centers position to each other
    qreal k = contentArea.height()/contentArea.width(); //slope of the diagonal
    qreal offset_x = offset/(sqrt(k + 1));
    qreal offset_y = k*offset_x;
    QPointF offsetPoint(offset_x, offset_y);

    //First widget to the center of the content area
    QPointF anchorPoint = contentArea.center();
    foreach (QRectF g, newRects) {
        g.moveCenter(anchorPoint);
        toGeometries << g;
        anchorPoint -= offsetPoint;
        if(!contentArea.contains(anchorPoint)) {
            anchorPoint = contentArea.bottomRight();
        }
    }
コード例 #20
0
ファイル: item.cpp プロジェクト: damiansimanuk/qucs-qt4
    /*!
     * \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;
    }
コード例 #21
0
QRectF OrthogonalRenderer::boundingRect(const MapObject *object) const
{
    const QRectF bounds = object->bounds();
    const QRectF rect(tileToPixelCoords(bounds.topLeft()),
                      tileToPixelCoords(bounds.bottomRight()));


	///如果有路径就取路径的外框盒

     if(object->getPoly()!=NULL)
	 {
		 QRectF rect= object->getPoly()->boundingRect();
		 rect.translate(this->tileToPixelCoords(object->position()));
		 return rect;
	 }

    // The -2 and +3 are to account for the pen width and shadow
    if (object->tile()) {
        const QPointF bottomLeft = rect.topLeft();
        const QPixmap &img = object->tile()->image();
        return QRectF(bottomLeft.x(),
                      bottomLeft.y() - img.height(),
                      img.width(),
                      img.height()).adjusted(-1, -1, 1, 1);
    } else if (rect.isNull()) {
        return rect.adjusted(-10 - 2, -10 - 2, 10 + 3, 10 + 3);
    } else {
        const int nameHeight = object->name().isEmpty() ? 0 : 15;
        return rect.adjusted(-2, -nameHeight - 2, 3, 3);
    }
}
コード例 #22
0
ファイル: graphicline.cpp プロジェクト: Caneda/Caneda
 //! \copydoc Painting::shapeForRect()
 QPainterPath GraphicLine::shapeForRect(const QRectF &rect) const
 {
     QPainterPath path;
     path.moveTo(rect.topLeft());
     path.lineTo(rect.bottomRight());
     return path;
 }
コード例 #23
0
QPainterPath OrthogonalRenderer::shape(const MapObject *object) const
{
    const QRectF bounds = object->bounds();
    const QRectF rect(tileToPixelCoords(bounds.topLeft()),
                      tileToPixelCoords(bounds.bottomRight()));

    QPainterPath path;

	///加入多边形选择
	/*if(object->getPoly()!=NULL)
	{
		QRectF rectF=object->getPoly()->boundingRect();
		rectF.translate(this->tileToPixelCoords(object->position()));
		path.addRoundRect()

	}*/


    if (object->tile()||object->getPoly()!=NULL) {
        path.addRect(boundingRect(object));
    } else if (rect.isNull()) {
        path.addEllipse(rect.topLeft(), 20, 20);
    } else {
        path.addRoundedRect(rect, 10, 10);
    }


    return path;
}
コード例 #24
0
QRectF Projection::toProjectedRectF(const QRectF& Viewport, const QRect& screen) const
{
    QPointF tl, br;
    QRectF pViewport;

    tl = project(Viewport.topLeft());
    br = project(Viewport.bottomRight());
    pViewport = QRectF(tl, br);

    QPointF pCenter(pViewport.center());

    qreal wv, hv;
    //wv = (pViewport.width() / Viewport.londiff()) * ((double)screen.width() / Viewport.londiff());
    //hv = (pViewport.height() / Viewport.latdiff()) * ((double)screen.height() / Viewport.latdiff());

    qreal Aspect = (double)screen.width() / screen.height();
    qreal pAspect = fabs(pViewport.width() / pViewport.height());

    if (pAspect > Aspect) {
        wv = fabs(pViewport.width());
        hv = fabs(pViewport.height() * pAspect / Aspect);
    } else {
        wv = fabs(pViewport.width() * Aspect / pAspect);
        hv = fabs(pViewport.height());
    }

    pViewport = QRectF((pCenter.x() - wv/2), (pCenter.y() + hv/2), wv, -hv);

    return pViewport;
}
コード例 #25
0
void PlotGraph::drawBackground(QPainter *painter, const QRectF &rect)
{
    Q_UNUSED(rect);

    // Shadow
    QRectF sceneRect = this->sceneRect();

    // Fill
    QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
    gradient.setColorAt(0, Qt::white);
    gradient.setColorAt(1, Qt::white);
    painter->setOpacity(0.7);
    painter->fillRect(rect.intersected(sceneRect), gradient);
    painter->setBrush(Qt::NoBrush);
    painter->drawRect(sceneRect);

    painter->setPen(QPen(Qt::black, 3));
    painter->drawLine(
                QPointF(xOrigin, yMax),
                QPointF(xOrigin, yOrigin + 10));
    painter->drawLine(
                QPointF(xOrigin - 5, yOrigin),
                QPointF(xMax, yOrigin));

}
コード例 #26
0
void MainMenuScene::createGameButtons()
{
  const double buttonSpacing = 1.5;
  QSignalMapper* signalMapper = new QSignalMapper(this);
  QRectF tableRect = getTableRect();
  double totalHeight = 0;
  std::array<Button*, static_cast<unsigned int>(Games::MAX)> buttons;
  for ( unsigned int i = 1; i != m_gameNames.size(); ++i )
  {
    buttons[i] = new Button(m_gameNames[i]);
    totalHeight += buttonSpacing * buttons[i]->boundingRect().height();
  }
  double currentOffsetY = -0.5 * totalHeight;
  for ( unsigned int i = 1; i != m_gameNames.size(); ++i )
  {
    QRectF buttonRect = buttons[i]->boundingRect();
    QPointF buttonOffset = buttonRect.bottomRight() - buttonRect.topLeft();
    buttons[i]->setPos(tableRect.center() + QPointF(0, currentOffsetY) - 0.5*buttonOffset );
    currentOffsetY += buttonSpacing * buttonRect.height();
    connect(buttons[i], SIGNAL(pressed()), signalMapper, SLOT(map()));
    signalMapper->setMapping(buttons[i], i );
    addItem( buttons[i] );
  }
  connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(slotGameButtonPressed(int)));
}
コード例 #27
0
ファイル: automappingutils.cpp プロジェクト: Bertram25/tiled
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));
    }
}
コード例 #28
0
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());
    }
}
コード例 #29
0
void MainWindow::draggedRect(QRectF rect)
{
    QList<QPointF> coords;
    coords.append(rect.topLeft());
    coords.append(rect.bottomRight());
    mc->setViewAndZoomIn(coords);

    double latminpoint = rect.bottom();
    double latmaxpoint = rect.top();
    double lonminpoint = rect.left();
    double lonmaxpoint = rect.right();

    if ( latminpoint > latmaxpoint ) switchPoint( latminpoint, latmaxpoint );
    if ( lonminpoint > lonmaxpoint ) switchPoint( lonminpoint, lonmaxpoint );

    ui->minLatField->setText(QString::number(latminpoint));
    ui->maxLatField->setText(QString::number(latmaxpoint));
    ui->minLonField->setText(QString::number(lonminpoint));
    ui->maxLonField->setText(QString::number(lonmaxpoint));

    updateArea();

    QList<Point*> points;
    points.append(new Point(lonminpoint, latminpoint, "1"));
    points.append(new Point(lonminpoint, latmaxpoint, "1"));
    points.append(new Point(lonmaxpoint, latmaxpoint, "1"));
    points.append(new Point(lonmaxpoint, latminpoint, "1"));
    points.append(new Point(lonminpoint, latminpoint, "1"));
    QPen* linepen = new QPen(Qt::red);
    linepen->setWidth(2);
    LineString* ls = new LineString(points, "Boundary Area", linepen);
    mainlayer->clearGeometries();
    mainlayer->addGeometry(ls);
}
コード例 #30
0
void QtViewportInteractionEngine::wheelEvent(QWheelEvent* ev)
{
    if (scrollAnimationActive() || scaleAnimationActive() || pinchGestureActive())
        return; // Ignore.


    // A normal scroll-tick should have a delta of 120 (1/8) degrees. Convert this to
    // local standard scroll step of 3 lines of 20 pixels.
    static const int cDefaultQtScrollStep = 20;
    static const int wheelScrollLines = 3;
    const int wheelTick = wheelScrollLines * cDefaultQtScrollStep;

    int pixelDelta = ev->delta() * (wheelTick / 120.f);

    QPointF newPosition = m_viewport->contentPos();

    if (ev->orientation() == Qt::Horizontal)
        newPosition.rx() -= pixelDelta;
    else
        newPosition.ry() -= pixelDelta;

    QRectF endPosRange = computePosRangeForItemAtScale(m_content->contentsScale());

    QPointF currentPosition = m_viewport->contentPos();
    newPosition = boundPosition(endPosRange.topLeft(), newPosition, endPosRange.bottomRight());
    m_viewport->setContentPos(newPosition);

    emit contentViewportChanged(currentPosition - newPosition);
}