コード例 #1
0
void OnMonitorRectItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
    Q_UNUSED(widget)
    Q_UNUSED(option)

    painter->setPen(pen());
    //painter->setClipRect(option->rect);
    const QRectF r = rect();
    painter->drawRect(r);
    QRectF handle = painter->worldTransform().inverted().mapRect(QRectF(0, 0, 6, 6));
    if (isEnabled()) {
        handle.moveTopLeft(r.topLeft());
        painter->fillRect(handle, QColor(Qt::yellow));
        handle.moveTopRight(r.topRight());
        painter->fillRect(handle, QColor(Qt::yellow));
        handle.moveBottomLeft(r.bottomLeft());
        painter->fillRect(handle, QColor(Qt::yellow));
        handle.moveBottomRight(r.bottomRight());
        painter->fillRect(handle, QColor(Qt::yellow));
    }
    
    // Draw cross at center
    QPointF center = r.center();
    painter->drawLine(center + QPointF(-handle.width(), 0), center + QPointF(handle.width(), 0));
    painter->drawLine(center + QPointF(0, handle.height()), center + QPointF(0, -handle.height()));
}
コード例 #2
0
void QQuickTextNodeEngine::addImage(const QRectF &rect, const QImage &image, qreal ascent,
                                    SelectionState selectionState,
                                    QTextFrameFormat::Position layoutPosition)
{
    QRectF searchRect = rect;
    if (layoutPosition == QTextFrameFormat::InFlow) {
        if (m_currentLineTree.isEmpty()) {
            searchRect.moveTopLeft(m_position + m_currentLine.position() + QPointF(0,1));
        } else {
            const BinaryTreeNode *lastNode = m_currentLineTree.data() + m_currentLineTree.size() - 1;
            if (lastNode->glyphRun.isRightToLeft()) {
                QPointF lastPos = lastNode->boundingRect.topLeft();
                searchRect.moveTopRight(lastPos - QPointF(0, ascent - lastNode->ascent));
            } else {
                QPointF lastPos = lastNode->boundingRect.topRight();
                searchRect.moveTopLeft(lastPos - QPointF(0, ascent - lastNode->ascent));
            }
        }
    }

    BinaryTreeNode::insert(&m_currentLineTree, searchRect, image, ascent, selectionState);
    m_hasContents = true;
}
コード例 #3
0
void TransformableGraphicsGuide::update()
{
	if (isVisible())
	{
		FigureEditor::EditMode mode = editor->mode();

		bool scaleMode( mode == FigureEditor::Scale );
		topRightRect.setVisible(scaleMode);
		topLeftRect.setVisible(scaleMode);
		bottomRightRect.setVisible(scaleMode);
		bottomLeftRect.setVisible(scaleMode);

		if (scaleMode)
		{
			QPointF cen;
			QPolygonF poly;

			if (editor->hasSelection())
			{
				QGraphicsPolygonItem* item = editor->selection();
				if (item == 0)
					return;
				cen  = mapFromScene(editor->selectionTransformPos());
				poly = mapFromScene(item->polygon());
			}
			else
			{
				QGraphicsPolygonItem* item = dynamic_cast<QGraphicsPolygonItem*>(parentItem());
				cen  = editor->triangleTransformPos();
				poly = item->polygon();
			}
			QRectF f( poly.boundingRect() );
			qreal xmax = qMax(qAbs(f.left() - cen.x()), qAbs(f.right()  - cen.x()));
			qreal ymax = qMax(qAbs(f.top()  - cen.y()), qAbs(f.bottom() - cen.y()));
			QPointF pmax(xmax, ymax);
			QRectF r(pmax, -pmax);

			r.moveCenter(cen);
			outerRect = r;
			QRectF l = parentItem()->mapRectFromScene(QRectF(QPointF(0.0, 0.0), QSizeF(10, 10)));
			QPen pen( editor->guideColor() );

			l.moveBottomLeft(r.topRight());
			topRightRect.setPen(pen);
			topRightRect.setRect(l);

			l.moveBottomRight(r.topLeft());
			topLeftRect.setPen(pen);
			topLeftRect.setRect(l);

			l.moveTopLeft(r.bottomRight());
			bottomRightRect.setPen(pen);
			bottomRightRect.setRect(l);

			l.moveTopRight(r.bottomLeft());
			bottomLeftRect.setPen(pen);
			bottomLeftRect.setRect(l);
		}
		else if (mode == FigureEditor::Rotate)
		{
			QGraphicsPolygonItem* item;
			QPointF cen;
			QPolygonF poly;
			if (editor->hasSelection())
			{
				item = editor->selection();
				if (item == 0)
					return;
				cen  = mapFromScene(editor->selectionTransformPos());
				poly = mapFromScene(item->polygon());
			}
			else
			{
				item = dynamic_cast<QGraphicsPolygonItem*>(parentItem());
				poly = item->polygon();
				cen = editor->triangleTransformPos();
			}
			qreal rmax = 0.0;
			foreach (QPointF p, poly)
			{
				QLineF l(p, cen);
				qreal len(l.length());
				if (len > rmax)
					rmax = len;
			}
			qreal height = rmax * 2.0;
			outerRect = QRectF(cen.x() - rmax, cen.y() - rmax, height, height);
		}