QRectF
dmz::QtCanvasObjectText::_outline_rect () const {

   QRectF rect;

   if (_text.length ()) {

      const int Padding (8);
      QFontMetricsF metrics = qApp->font ();

      rect.setSize (metrics.size (0, _text));

      if (_drawBackground) {

         rect.adjust (-Padding, -Padding, Padding, Padding);
      }

      if (_alignment == Qt::AlignLeft) {

         rect.translate (0, -rect.center ().y ());
      }
      else if (_alignment == Qt::AlignRight) {

         rect.translate (-rect.width (), -rect.center ().y ());
      }
      else {

         rect.translate (-rect.center ());
      }
   }

   return rect;
}
QPainterPath
Shapes::max(const QRectF &bound, Style style)
{
    _S(3) _S(4) _S(8)
    QPainterPath path;
    switch (style)
    {
    case Square:
        path.addRect(bound);
        path.addRect(bound.adjusted(0, s4, -s4, 0));
        path.addRect(bound.adjusted(0, 2*s3, -2*s3, 0));
        break;
    case LasseKongo:
    {
        _S(5);
        const float d = 3*s5;
        QRectF rect = bound.adjusted(0,0,-d,-d);
        QRectF rect2(0,0,d,d);
        
        path.addRect(rect);
        rect2.moveCenter(rect.bottomRight());
        path.moveTo(rect2.center()); path.arcTo(rect2, 90, 90); path.closeSubpath();

        rect.translate(d,0);
        path.addRect(rect);
        rect2.moveCenter(rect.bottomLeft());
        path.moveTo(rect2.center()); path.arcTo(rect2, 0, 90); path.closeSubpath();
        
        rect.translate(0,d);
        path.addRect(rect);
        rect2.moveCenter(rect.topLeft());
        path.moveTo(rect2.center()); path.arcTo(rect2, -90, 90); path.closeSubpath();
        
        rect.translate(-d,0);
        path.addRect(rect);
        rect2.moveCenter(rect.topRight());
        path.moveTo(rect2.center()); path.arcTo(rect2, -180, 90); path.closeSubpath();
        break;
    }
    default:
    case Round:
        //path.moveTo(bound.center());
        //path.arcTo(bound, 0, 180);
        //path.closeSubpath();
        break;
    case TheRob:
        path.moveTo(bound.center());
        path.arcTo(bound, 0, 180);
        path.closeSubpath();
        path.moveTo(bound.center());
        path.arcTo(bound.adjusted(s8,s8,-s8,-s8), 0, 180);
        path.closeSubpath();
        path.addEllipse(bound.adjusted(s4,s4,-s4,-s4));
        break;
    }
    return path;
}
Exemple #3
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);
}
void MapObjectLabel::syncWithMapObject(MapRenderer *renderer)
{
    const bool nameVisible = mObject->isVisible() && !mObject->name().isEmpty();
    setVisible(nameVisible);

    if (!nameVisible)
        return;

    const QFontMetricsF metrics(QGuiApplication::font());
    QRectF boundingRect = metrics.boundingRect(mObject->name());
    boundingRect.translate(-boundingRect.width() / 2, -labelDistance);
    boundingRect.adjust(-labelMargin*2, -labelMargin, labelMargin*2, labelMargin);

    QPointF pixelPos = renderer->pixelToScreenCoords(mObject->position());
    QRectF bounds = objectBounds(mObject, renderer);

    // Adjust the bounding box for object rotation
    QTransform transform;
    transform.translate(pixelPos.x(), pixelPos.y());
    transform.rotate(mObject->rotation());
    transform.translate(-pixelPos.x(), -pixelPos.y());
    bounds = transform.mapRect(bounds);

    // Center the object name on the object bounding box
    QPointF pos((bounds.left() + bounds.right()) / 2, bounds.top());

    setPos(pos + mObject->objectGroup()->offset());

    if (mBoundingRect != boundingRect) {
        prepareGeometryChange();
        mBoundingRect = boundingRect;
    }
}
Exemple #5
0
void MapObjectItem::syncWithMapObject()
{
    // Update the whole object when the name or type has changed
    if (mObject->name() != mName || mObject->type() != mType) {
        mName = mObject->name();
        mType = mObject->type();
        update();
        mResizeHandle->update();
    }

    QString toolTip = mName;
    if (!mType.isEmpty())
        toolTip += QLatin1String(" (") + mType + QLatin1String(")");
    setToolTip(toolTip);

    MapRenderer *renderer = mMapDocument->renderer();
    const QPointF pixelPos = renderer->tileToPixelCoords(mObject->position());
    QRectF bounds = renderer->boundingRect(mObject);
    bounds.translate(-pixelPos);

    mSyncing = true;
    setPos(pixelPos);

    if (mBoundingRect != bounds) {
        // Notify the graphics scene about the geometry change in advance
        prepareGeometryChange();
        mBoundingRect = bounds;
        const QPointF bottomRight = mObject->bounds().bottomRight();
        const QPointF handlePos = renderer->tileToPixelCoords(bottomRight);
        mResizeHandle->setPos(handlePos - pixelPos);
    }
    mSyncing = false;
}
Exemple #6
0
/*!
  Returns the smallest rectangle that contains all glyphs in this QGlyphRun. If a bounding rect
  has been set using setBoundingRect(), then this will be returned. Otherwise the bounding rect
  will be calculated based on the font metrics of the glyphs in the glyph run.

  \since 5.0
*/
QRectF QGlyphRun::boundingRect() const
{
    if (!d->boundingRect.isEmpty() || !d->rawFont.isValid())
        return d->boundingRect;

    qreal minX, minY, maxX, maxY;
    minX = minY = maxX = maxY = 0;

    for (int i = 0, n = qMin(d->glyphIndexDataSize, d->glyphPositionDataSize); i < n; ++i) {
        QRectF glyphRect = d->rawFont.boundingRect(d->glyphIndexData[i]);
        glyphRect.translate(d->glyphPositionData[i]);

        if (i == 0) {
            minX = glyphRect.left();
            minY = glyphRect.top();
            maxX = glyphRect.right();
            maxY = glyphRect.bottom();
        } else {
            minX = qMin(glyphRect.left(), minX);
            minY = qMin(glyphRect.top(), minY);
            maxX = qMax(glyphRect.right(),maxX);
            maxY = qMax(glyphRect.bottom(), maxY);
        }
    }

    return QRectF(QPointF(minX, minY), QPointF(maxX, maxY));
}
Exemple #7
0
  void ChatNode::addTeteToMinMax(Tete* tete,
                                 float* min_x, float* min_y,
                                 float* max_x, float* max_y) {
    //return;
    if(tete == NULL)
      return;
    if(tete->tete_node() == NULL)
      return;

    QRectF local_bound = tete->tete_node()->boundingRect();
    QRectF bound = local_bound;
    bound.moveTo(tete->tete_node()->pos());
    bound.translate(-local_bound.width()/2,-local_bound.height()/2);

    //std::cerr << bound.topLeft().y() << " " << *min_y << std::endl;

    if(bound.topLeft().x() < *min_x)
      *min_x = bound.topLeft().x();
    if(bound.topLeft().y() < *min_y)
      *min_y = bound.topLeft().y();
    if(bound.bottomRight().x() > *max_x)
      *max_x = bound.bottomRight().x();
    if(bound.bottomRight().y() > *max_y)
      *max_y = bound.bottomRight().y();
  }
Exemple #8
0
  void ChatNode::updateAllTetesRect(){
    std::vector<Tete*> tetes = chat_->tetes();

    if(tetes.empty()){
      all_tetes_rect_ = QRectF(-1, -1, 2, 2);
      return;
    }

    TeteNode* first_node = NULL;
    // Find the first non-null node
    for(unsigned int i = 0u; first_node == NULL; i++){
      first_node = tetes[i]->tete_node();
    }

    QRectF local_bound = first_node->boundingRect();
    QRectF bound = local_bound;
    bound.moveTo(first_node->pos());
    // Translate more due to text
    bound.translate(-local_bound.width()/2,-local_bound.height()/2);

    float min_x = bound.topLeft().x();
    float min_y = bound.topLeft().y();
    float max_x = bound.bottomRight().x();
    float max_y = bound.bottomRight().y();

    for(std::vector<Tete*>::const_iterator it = tetes.begin(); it != tetes.end(); ++it){
      addTeteToMinMax(*it, &min_x, &min_y, &max_x, &max_y);
    }

    all_tetes_rect_ = QRectF(QPointF(min_x, min_y),
                             QPointF(max_x, max_y)).normalized();
  }
	QRectF frameRect(const QRectF &area, const QPoint &off = {0, 0}, QRectF *letterbox = nullptr) {
		QRectF rect = area;
		if (p->hasFrame()) {
			const double aspect = p->targetAspectRatio();
			QSizeF frame(aspect, 1.0), letter(p->targetCropRatio(aspect), 1.0);
			letter.scale(area.width(), area.height(), Qt::KeepAspectRatio);
			frame.scale(letter, Qt::KeepAspectRatioByExpanding);
			QPointF pos(area.x(), area.y());
			pos.rx() += (area.width() - frame.width())*0.5;
			pos.ry() += (area.height() - frame.height())*0.5;
			rect = {pos, frame};

			QPointF xy(area.width(), area.height());
			xy.rx() -= letter.width(); xy.ry() -= letter.height();	xy *= 0.5;
			QPointF offset = off;
			offset.rx() *= letter.width()/100.0;
			offset.ry() *= letter.height()/100.0;
			if (alignment & Qt::AlignLeft)
				offset.rx() -= xy.x();
			else if (alignment & Qt::AlignRight)
				offset.rx() += xy.x();
			if (alignment & Qt::AlignTop)
				offset.ry() -= xy.y();
			else if (alignment & Qt::AlignBottom)
				offset.ry() += xy.y();
			rect.translate(offset);
			xy += offset;
			if (letterbox)
				*letterbox = {xy, letter};
		}
		return rect;
	}
Exemple #10
0
void ResizeHandler::expandByChildren(QRectF &contents) const
{
	QVector<int> const sizeOfForestalling = mElementType.sizeOfForestalling();

	for (const QGraphicsItem * const childItem : mTargetNode.childItems()) {
		QRectF curChildItemBoundingRect = childBoundingRect(childItem, contents);

		if (curChildItemBoundingRect.width() == 0 || curChildItemBoundingRect.height() == 0) {
			continue;
		}

		// it seems to be more appropriate to use childItem->pos() but it causes
		// bad behaviour when dropping one element to another
		curChildItemBoundingRect.translate(childItem->scenePos() - mTargetNode.scenePos());

		contents.setLeft(qMin(curChildItemBoundingRect.left() - sizeOfForestalling[0]
						, contents.left()));
		contents.setRight(qMax(curChildItemBoundingRect.right() + sizeOfForestalling[2]
						, contents.right()));
		contents.setTop(qMin(curChildItemBoundingRect.top() - sizeOfForestalling[1]
						, contents.top()));
		contents.setBottom(qMax(curChildItemBoundingRect.bottom() + sizeOfForestalling[3]
						, contents.bottom()));
	}
}
QPainterPath
Shapes::keepBelow(const QRectF &bound, Style style)
{
    _S(2) _S(3) _S(4)
    QPainterPath path;
    switch (style)
    {
    case Square:
    case LasseKongo:
        path.addRect(bound.adjusted(s4, 2*s3, -s4, 0));
        path.addRect(bound.adjusted(0, 0, -2*s3, -2*s3));
        path.addRect(bound.adjusted(2*s3, 0, 0, -2*s3));
        break;
    default:
    case Round:
    case TheRob:
        QRectF rect = bound.adjusted(0, 0, -s2, -s2);
        path.moveTo(bound.center() + QPointF(0, s2));
        path.arcTo(bound.translated(0, s2), 0, 180);
        path.closeSubpath();
        path.moveTo(rect.center());
        path.arcTo(rect, 0, 180);
        path.closeSubpath();
        rect.translate(s2, 0);
        path.moveTo(rect.center());
        path.arcTo(rect, 0, 180);
        path.closeSubpath();
        break;
    }
    return path;
}
QPainterPath
Shapes::unAboveBelow(const QRectF &bound, Style style)
{
    _S(6) _S(3) _S(4)
    QPainterPath path;
    switch (style)
    {
        case Square:
        case LasseKongo:
            path.addRect(bound.adjusted(0, s4, -2*s3, -s4));
            path.addRect(bound.adjusted(2*s3, s4, 0, -s4));
            break;
        default:
        case Round:
        case TheRob:
            QRectF rect = bound.adjusted(0,0,-s6, 0);
            path.moveTo(rect.center());
            path.arcTo(rect, 90, 180);
            path.closeSubpath();
            rect.translate(s6,0);
            path.moveTo(rect.center());
            path.arcTo(rect, -90, 180);
            path.closeSubpath();
            break;
    }
    return path;
}
Exemple #13
0
void QAttribute::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    {
        // Rettangolo

        if (selct)// se selezionato allora .
            painter->fillRect(boundingRect(),QColor(255,19,0,125)); // riempo tutto il rettangolo di rosso.
        QRectF Rect = boundingRect();// ottengo  il rettangolo
        qreal bx =(Rect.width()/6)+(Rect.width()/8);
        qreal by =(Rect.height()*(80))/100 ;
        qreal ox =(Rect.left()+Rect.width()/2.8);
        qreal oy =Rect.topLeft().y()+Rect.height()-by ;
        painter->fillRect(ox+1,oy+11,bx-1,by-12,Qt::white);
        // Testo
        QRectF *typetext = new  QRectF();
        painter->drawText(QRectF(Rect.x(),oy-25,Rect.width(),30),Qt::AlignCenter,attribute->Caption(),typetext);
        qreal px = typetext->left()+this->attribute->getCaptionWidth();
        qreal py = typetext->top()+this->attribute->getCaptionHeight();
        typetext->translate(20,typetext->height()+1);
        typetext->setLeft(Rect.x()+16);

        painter->drawText(*typetext,attribute->GetattributeTypeStr(),QTextOption(Qt::AlignVCenter));

        painter->drawRect(ox,oy+10,bx,by-11);
        if (this->grabRefer->GrabberItem()==this)
        painter->drawLine(px,py,px+5,py);
        // inserire tipo ....
// draw right and left arrow that permit to change type.
    }
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);
    }
}
void QQuickTextNodeEngine::BinaryTreeNode::insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const QGlyphRun &glyphRun, SelectionState selectionState,
                                             QQuickTextNode::Decorations decorations, const QColor &textColor,
                                             const QColor &backgroundColor, const QPointF &position)
{
    QRectF searchRect = glyphRun.boundingRect();
    searchRect.translate(position);

    if (qFuzzyIsNull(searchRect.width()) || qFuzzyIsNull(searchRect.height()))
        return;

    decorations |= (glyphRun.underline() ? QQuickTextNode::Underline : QQuickTextNode::NoDecoration);
    decorations |= (glyphRun.overline()  ? QQuickTextNode::Overline  : QQuickTextNode::NoDecoration);
    decorations |= (glyphRun.strikeOut() ? QQuickTextNode::StrikeOut : QQuickTextNode::NoDecoration);
    decorations |= (backgroundColor.isValid() ? QQuickTextNode::Background : QQuickTextNode::NoDecoration);

    qreal ascent = glyphRun.rawFont().ascent();
    insert(binaryTree, BinaryTreeNode(glyphRun,
                                      selectionState,
                                      searchRect,
                                      decorations,
                                      textColor,
                                      backgroundColor,
                                      position,
                                      ascent));
}
Exemple #16
0
void SquareRootElement::layout( const AttributeManager* am )
{
    RowElement::layout( am );

    qreal thinSpace = am->layoutSpacing( this );
    qreal symbolHeight = baseLine();
    if( height() > symbolHeight*1.3 ) symbolHeight = height();
    symbolHeight += thinSpace;
    qreal tickWidth = symbolHeight / 3.0;

    m_lineThickness = am->lineThickness(this);

    // Set the sqrt dimensions 
    QPointF childOffset( tickWidth + thinSpace, thinSpace + m_lineThickness );

    setWidth( width() + childOffset.x());
    setHeight( height() + childOffset.y());
    setBaseLine( baseLine() + childOffset.y());

    // Adapt the children's positions to the new offset
    foreach( BasicElement* element, childElements() )
        element->setOrigin( element->origin() + childOffset );

    QRectF rect = childrenBoundingRect();
    rect.translate(childOffset);
    setChildrenBoundingRect(rect);

    // Draw the sqrt symbol into a QPainterPath as buffer
    m_rootSymbol = QPainterPath();
    m_rootSymbol.moveTo( m_lineThickness, 2.0 * symbolHeight / 3.0 );
    m_rootSymbol.lineTo( 0 + tickWidth/2.0, symbolHeight-m_lineThickness/2 );
    m_rootSymbol.lineTo( 0 + tickWidth, m_lineThickness/2 );
    m_rootSymbol.lineTo( width() - m_lineThickness/2, m_lineThickness/2 );

}
void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const QByteArray& previous)
{
    Q_UNUSED(previous);

   QGraphicsView* parent = scene()->views()[0];
   if (current.isEmpty() || !parent || current != "text") {
        if (m_roleEditor) {
            emit roleEditingCanceled(index(), current, data().value(current));

            disconnect(m_roleEditor, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
                       this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
            disconnect(m_roleEditor, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
                       this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
            m_roleEditor->deleteLater();
            m_roleEditor = 0;
        }
        return;
    }

    Q_ASSERT(!m_roleEditor);

    const TextInfo* textInfo = m_textInfo.value("text");

    m_roleEditor = new KItemListRoleEditor(parent);
    m_roleEditor->setIndex(index());
    m_roleEditor->setRole(current);
    m_roleEditor->setFont(styleOption().font);

    const QString text = data().value(current).toString();
    m_roleEditor->setPlainText(text);

    QTextOption textOption = textInfo->staticText.textOption();
    m_roleEditor->document()->setDefaultTextOption(textOption);

    const int textSelectionLength = selectionLength(text);

    if (textSelectionLength > 0) {
        QTextCursor cursor = m_roleEditor->textCursor();
        cursor.movePosition(QTextCursor::StartOfBlock);
        cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, textSelectionLength);
        m_roleEditor->setTextCursor(cursor);
    }

    connect(m_roleEditor, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
            this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
    connect(m_roleEditor, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
            this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));

    // Adjust the geometry of the editor
    QRectF rect = roleEditingRect(current);
    const int frameWidth = m_roleEditor->frameWidth();
    rect.adjust(-frameWidth, -frameWidth, frameWidth, frameWidth);
    rect.translate(pos());
    if (rect.right() > parent->width()) {
        rect.setWidth(parent->width() - rect.left());
    }
    m_roleEditor->setGeometry(rect.toRect());
    m_roleEditor->show();
    m_roleEditor->setFocus();
}
Exemple #18
0
static void extendMapRect(QRect &mapBoundingRect, const MapRenderer &renderer)
{
    // Start with the basic map size
    QRectF rect(mapBoundingRect);

    // Take into account large tiles extending beyond their cell
    for (const Layer *layer : renderer.map()->tileLayers()) {
        const TileLayer *tileLayer = static_cast<const TileLayer*>(layer);
        const QPointF offset = tileLayer->totalOffset();

        for (int y = 0; y < tileLayer->height(); ++y) {
            for (int x = 0; x < tileLayer->width(); ++x) {
                const Cell &cell = tileLayer->cellAt(x, y);

                if (!cell.isEmpty()) {
                    QRectF r = cellRect(renderer, cell, QPointF(x, y));
                    r.translate(offset);
                    rect |= r;
                }
            }
        }
    }

    mapBoundingRect = rect.toAlignedRect();
}
void CanvasMode_EditArc::applyValues(double start, double end, double height, double width)
{
	PageItem *currItem = m_doc->m_Selection->itemAt(0);
	PageItem_Arc *item = currItem->asArc();
	QPointF mPoint = item->PoLine.pointQF(0);
	QRectF upRect = QRectF(QPointF(0, 0), QPointF(currItem->width(), currItem->height())).normalized();
	QRectF upRect2 = QRectF(mPoint.x() - item->arcWidth / 2.0, mPoint.y() - item->arcHeight / 2.0, item->arcWidth, item->arcHeight);
	upRect = upRect2.united(upRect);
	upRect.translate(currItem->xPos(), currItem->yPos());
	QTransform bb;
	bb.scale(height / width, 1.0);
	QLineF inp = QLineF(QPointF(width / 2.0, height / 2.0), QPointF(width, height / 2.0));
	inp.setAngle(start);
	QLineF res = bb.map(inp);
	inp.setAngle(end);
	QLineF ena = bb.map(inp);
	startAngle = res.angle();
	endAngle = ena.angle();
	double nSweep = endAngle - startAngle;
	if (nSweep < 0)
		nSweep += 360;
	QPainterPath pp;
	pp.moveTo(mPoint);
	pp.arcTo(QRectF(mPoint.x() - width / 2.0, mPoint.y() - height / 2.0, width, height), startAngle, nSweep);
	pp.closeSubpath();
	currItem->PoLine.fromQPainterPath(pp);
	m_doc->AdjustItemSize(currItem);
	if(UndoManager::undoEnabled())
	{
		ScItemState<QPair<FPointArray, FPointArray> > *ss = new ScItemState<QPair<FPointArray, FPointArray> >(Um::EditArc,"",Um::IPolygon);
		FPointArray old = item->PoLine;
		ss->set("ARC","arc");
		ss->set("OLD_WIDTH",item->arcWidth);
		ss->set("NEW_WIDTH",width);
		ss->set("OLD_XPOS",item->xPos());
		ss->set("OLD_YPOS",item->yPos());
		ss->set("OLD_HEIGHT",item->arcHeight);
		ss->set("NEW_HEIGHT",height);
		ss->set("OLD_START",item->arcStartAngle);
		ss->set("NEW_START",startAngle);
		ss->set("OLD_SWEEP",item->arcSweepAngle);
		ss->set("NEW_SWEEP",nSweep);
		ss->setItem(qMakePair(old,item->PoLine));
		ss->set("NEW_XPOS",item->xPos());
		ss->set("NEW_YPOS",item->yPos());
		undoManager->action(currItem,ss);
	}
	item->arcStartAngle = startAngle;
	item->arcSweepAngle = nSweep;
	item->arcWidth = width;
	item->arcHeight = height;
	startPoint = currItem->PoLine.pointQF(2);
	endPoint = currItem->PoLine.pointQF(currItem->PoLine.size() - 4);
	centerPoint = currItem->PoLine.pointQF(0);
	widthPoint = QPointF(centerPoint.x() - item->arcWidth / 2.0, centerPoint.y());
	heightPoint = QPointF(centerPoint.x(), centerPoint.y() - item->arcHeight / 2.0);
	QTransform itemMatrix = currItem->getTransform();
	m_doc->regionsChanged()->update(itemMatrix.mapRect(QRectF(0, 0, currItem->width(), currItem->height())).adjusted(-currItem->width() / 2.0, -currItem->height() / 2.0, currItem->width(), currItem->height()));
}
Exemple #20
0
bool ClassItem::intersectShapeWithLine(const QLineF &line, QPointF *intersectionPoint, QLineF *intersectionLine) const
{
    QPolygonF polygon;
    // TODO if m_customIcon then use that shape + label's shape as intersection path
    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);
}
Exemple #21
0
QRectF PdfDocument::lineBoundingRect(int line_number) const {
	QRectF rect;
	rect.setTopLeft(m_lines[line_number-1]);
	rect.setWidth(pageDim().width());
	rect.setHeight(50);
	rect.translate(0, -25);
	qDebug() << "Line rectangle" << rect;
	return rect;
}
Exemple #22
0
QRectF KisDuplicateOpSettings::paintOutlineRect(const QPointF& pos, KisImageSP image) const
{
    KisBrushSP brush = m_optionsWidget->m_brushOption->brush();
    QPointF hotSpot = brush->hotSpot(1.0, 1.0);
    QRectF rect = image->pixelToDocument(QRect(0,0, brush->width(), brush->height()) );
    rect.translate( pos - hotSpot + QPoint(1,1) );
    rect |= duplicateOutlineRect(pos, image);
    return rect;
}
Exemple #23
0
QRectF usecaseclass::outlineRect() const
{
    const int Padding = 60;
    QFontMetricsF metrics = qApp->font();
    QRectF rect = metrics.boundingRect(myText);
    rect.adjust(-Padding, -Padding, +Padding, +Padding);
    rect.translate(-rect.center());
    return rect;
}
Exemple #24
0
QRectF QNodeItem::outlineRect() const
{
    const int Padding = 6;
    QFontMetricsF metrics = qApp->font();
    QRectF rect = metrics.boundingRect(text);
    rect.adjust(-Padding, -Padding, +Padding, +Padding);
    rect.translate(-rect.center());
    return rect;
}
Exemple #25
0
QRectF CenterRectSlaveFromMaster( const QRectF Master ,
                                               QRectF Slave  )
{
  QRectF SlaveOnline = Slave.translated(Master.center());
  const qreal wi = Slave.width() / 2;
  const qreal hi = Slave.height() / 2;
  SlaveOnline.translate( 0 - wi , 0 - hi ); 
  return SlaveOnline;
}
Exemple #26
0
static bool visibleIn(const QRectF &area, MapObject *object,
                      MapRenderer *renderer)
{
    QRectF boundingRect = renderer->boundingRect(object);

    if (object->rotation() != 0) {
        // Rotate around object position
        QPointF pos = renderer->pixelToScreenCoords(object->position());
        boundingRect.translate(-pos);

        QTransform transform;
        transform.rotate(object->rotation());
        boundingRect = transform.mapRect(boundingRect);

        boundingRect.translate(pos);
    }

    return intersects(area, boundingRect);
}
inline static QImage notes(const QStringList &notes, QSize *size, const QSize &requestedSize)
{
    QSvgRenderer *renderer = notesRenderer();
    static const QString clefId = QStringLiteral("clef");
    static const QRectF clefRect = renderer->boundsOnElement(idPrefix + clefId);
    static const QString staffLinesId = QStringLiteral("stafflines");
    static const QRectF staffLinesOriginalRect = renderer->boundsOnElement(idPrefix + staffLinesId);
    static const qreal clefRightY = clefRect.right() - staffLinesOriginalRect.left();
    static const qreal linesSpacePerNote = clefRect.width() * 1.75;
    const qreal linesSpaceForNotes = notes.count() * linesSpacePerNote;
    QRectF imageRect = staffLinesOriginalRect;
    imageRect.setWidth(clefRightY + linesSpaceForNotes);
    QSize resultSize = imageRect.size().toSize();
    if (size)
        *size = resultSize;
    resultSize.scale(requestedSize, Qt::KeepAspectRatio);
    QImage result(resultSize, QImage::Format_ARGB32);
    if (result.isNull())
        qDebug() << Q_FUNC_INFO << "notes image is NULL! Notes:" << notes;
    result.fill(Qt::transparent);
    QPainter p(&result);
    const qreal scaleFactor = resultSize.width() / imageRect.width();
    p.scale(scaleFactor, scaleFactor);
    p.translate(-imageRect.topLeft());

    renderer->render(&p, idPrefix + staffLinesId, imageRect);
    renderer->render(&p, idPrefix + clefId, clefRect);

    int currentNoteIndex = 0;
    foreach(const QString &currentNote, notes) {
        const QString trimmedNote = currentNote.trimmed();
        const QString note = trimmedNote.at(0).toLower();
        const QString noteID = QStringLiteral("note_") + note;
        QRectF noteRect = renderer->boundsOnElement(idPrefix + noteID);
        const qreal noteCenterX = clefRightY + (currentNoteIndex + 0.125) * linesSpacePerNote + noteRect.width();
        currentNoteIndex++;
        const qreal noteXTranslate = noteCenterX - noteRect.center().x();
        noteRect.translate(noteXTranslate, 0);
        renderer->render(&p, idPrefix + noteID, noteRect);
        if (trimmedNote.length() > 1) {
            static const QString sharpId = QStringLiteral("sharp");
            static const QString flatId = QStringLiteral("flat");
            static const QRectF noteCHeadRect = renderer->boundsOnElement(idPrefix + QStringLiteral("note_c_head"));
            const bool sharp = trimmedNote.endsWith(QStringLiteral("sharp"));
            const QString &noteSign = sharp ? sharpId : flatId;
            const QRectF noteHeadRect = renderer->boundsOnElement(idPrefix + QStringLiteral("note_") + note + QStringLiteral("_head"));
            const QRectF signRect = renderer->boundsOnElement(idPrefix + noteSign)
                    .translated(noteXTranslate, 0)
                    .translated(noteHeadRect.topLeft() - noteCHeadRect.topLeft());
            renderer->render(&p, idPrefix + noteSign, signRect);
        }
    }

    return result;
}
Exemple #28
0
void
Panner::moveTo(QPoint p)
{
    QPointF sp = mapToScene(p);
    QRectF nr = m_pannedRect;
    double d = sp.x() - nr.center().x();
    nr.translate(d, 0);
    slotSetPannedRect(nr);
    emit pannedRectChanged(m_pannedRect);
    viewport()->update();
}
void OrthogonalRenderer::drawTileLayer(QPainter *painter,
                                       const TileLayer *layer,
                                       const QRectF &exposed) const
{
    const QTransform savedTransform = painter->transform();

    const int tileWidth = map()->tileWidth();
    const int tileHeight = map()->tileHeight();
    const QPointF layerPos(layer->x() * tileWidth,
                           layer->y() * tileHeight);

    painter->translate(layerPos);

    int startX = 0;
    int startY = 0;
    int endX = layer->width();
    int endY = layer->height();

    if (!exposed.isNull()) {
        QMargins drawMargins = layer->drawMargins();
        drawMargins.setTop(drawMargins.top() - tileHeight);
        drawMargins.setRight(drawMargins.right() - tileWidth);

        QRectF rect = exposed.adjusted(-drawMargins.right(),
                                       -drawMargins.bottom(),
                                       drawMargins.left(),
                                       drawMargins.top());

        rect.translate(-layerPos);

        startX = qMax((int) rect.x() / tileWidth, 0);
        startY = qMax((int) rect.y() / tileHeight, 0);
        endX = qMin((int) std::ceil(rect.right()) / tileWidth + 1, endX);
        endY = qMin((int) std::ceil(rect.bottom()) / tileHeight + 1, endY);
    }

    CellRenderer renderer(painter);

    for (int y = startY; y < endY; ++y) {
        for (int x = startX; x < endX; ++x) {
            const Cell &cell = layer->cellAt(x, y);
            if (cell.isEmpty())
                continue;

            renderer.render(cell,
                            QPointF(x * tileWidth, (y + 1) * tileHeight),
                            CellRenderer::BottomLeft);
        }
    }

    renderer.flush();

    painter->setTransform(savedTransform);
}
QRectF FileManager::scaleArea()
{
	int ScaleFactor = this->getSize().height() * _heightPercent * 2;
	QRectF bounding = this->getPaintArea();
	bounding.setLeft( bounding.left() - ScaleFactor );
	bounding.setRight( bounding.right() + ScaleFactor );
	bounding.setTop( bounding.top() - ScaleFactor );
	bounding.setBottom( bounding.bottom() + ScaleFactor );
	bounding.translate( this->_FileTrans.x(), this->_FileTrans.y() );
	return bounding;
}