Пример #1
0
void WidgetStyle::WidgetScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
    if(m_mouseButton == Qt::LeftButton)
    {
        QRectF rect = m_rectItem->rect();
        QPointF point = event->scenePos();

        if(point.x() >= m_topLeftRect.x() && point.y() >= m_topLeftRect.y())
        {
            rect.setTopLeft(m_topLeftRect);
            rect.setBottomRight(point);
        }
        else if(point.x() >= m_topLeftRect.x() && point.y() <= m_topLeftRect.y())
        {
            rect.setBottomLeft(m_topLeftRect);
            rect.setTopRight(point);
        }
        else if(point.x() <= m_topLeftRect.x() && point.y() >= m_topLeftRect.y())
        {
            rect.setTopRight(m_topLeftRect);
            rect.setBottomLeft(point);
        }
        else if(point.x() <= m_topLeftRect.x() && point.y() <= m_topLeftRect.y())
        {
            rect.setBottomRight(m_topLeftRect);
            rect.setTopLeft(point);
        }
        m_rectItem->setRect(rect);
        m_wgtStyle->distinguishRect(rect);
    }
    QGraphicsScene::mouseMoveEvent(event);
}
Пример #2
0
    void paint(QPainter * painter,
            const QStyleOptionGraphicsItem * option, QWidget * widget)
    {
        Q_UNUSED(option);
        Q_UNUSED(widget);

        // BasicWidget::paint(painter, option, widget);
        if (iconInSvg().isValid()) {
            QRectF iconRect = QRectF(QPointF(), iconSize());
            QSizeF sizeDiff = size() - iconRect.size();

            iconRect.setTopLeft(QPointF(sizeDiff.width() / 2, sizeDiff.height() / 2));
            if (animate) {
                iconInSvg().paint(painter,
                    iconRect.left(),
                    iconRect.top(),
                    "frame" + QString::number(frame));
            } else {
                iconInSvg().paint(painter,
                    iconRect.left(),
                    iconRect.top(),
                    "frame" + QString::number(
                        (frame > 0) ? frameCount : 0
                    ));

            }
        }
    }
Пример #3
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));
    }
}
Пример #4
0
void core::Connector::setEndObject(GraphicObject *end)
{
	if(!end) return;

	endObject = end;

//	qDebug() << currentMousePos;
	//we use currentMousePos instead internal currentMousePos from "end" object due update mouse position problems
	//there are conflicts when moving mouse so using this currentMousePos ensures mouse pos is always updated

//	qDebug() << portRect;
	endPoint = mapFromItem(end, end->getCurrentPortPos(mapToItem(end, currentMousePos)));
	isBuildingConector = false;
//	qDebug() << portCenter;

	QRectF container = getContainerRect();


	if(currentMousePos.x() < 0 && currentMousePos.y() < 0){
		container.setTopLeft(endPoint );
	}else if(currentMousePos.x() < 0 && currentMousePos.y() >= 0){
		container.setBottomLeft(endPoint );
	}else if(currentMousePos.x() >= 0 && currentMousePos.y() < 0){
		container.setTopRight(endPoint );
	}else if(currentMousePos.x() >= 0 && currentMousePos.y() >= 0){
		container.setBottomRight(endPoint );
	}else{
		container= QRectF(0, 0, 0, 0);
	}

	setContainerRect(container);
}
Пример #5
0
void QgsMapCanvasItem::setRect( const QgsRectangle& rect, bool resetRotation )
{
  mRect = rect;
  //updatePosition();

  QRectF r; // empty rect by default
  if ( !mRect.isEmpty() )
  {
    // rect encodes origin of the item (xMin,yMax from map to canvas units)
    // and size (rect size / map units per pixel)
    r.setTopLeft( toCanvasCoordinates( QPointF( mRect.xMinimum(), mRect.yMaximum() ) ) );
    const QgsMapToPixel* m2p = mMapCanvas->getCoordinateTransform();
    double res = m2p->mapUnitsPerPixel();
    r.setSize( QSizeF( mRect.width() / res, mRect.height() / res ) );
  }

  // set position in canvas where the item will have coordinate (0,0)
  prepareGeometryChange();
  setPos( r.topLeft() );
  mItemSize = QSizeF( r.width() + 2, r.height() + 2 );

  if ( resetRotation )
  {
    mRectRotation = mMapCanvas->rotation();
    setRotation( 0 );
  }

  // QgsDebugMsg(QString("[%1,%2]-[%3x%4]").arg((int) r.left()).arg((int) r.top()).arg((int) r.width()).arg((int) r.height()));

  update();
}
Пример #6
0
void BlurItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
  QGraphicsRectItem::mouseMoveEvent(event);

  const QPointF pos = event->scenePos();
  QRectF r;

  r.setTopLeft(m_point);
  r.setBottomRight(event->scenePos());

  if (r.width() < 0) {
    r.setLeft(pos.x());
    r.setRight(m_point.x());
  }

  if (r.height() < 0) {
    r.setTop(pos.y());
    r.setBottom(m_point.y());
  }

  r = r.intersected(m_item->scene()->sceneRect());

  setRect(r);
  setSelected(true);
  m_item->setOffset(r.topLeft());

  reload(m_pixmap);
}
Пример #7
0
QRectF coils::boundingRect() const
{
    QRectF rect;
    rect.setTopLeft(QPointF(-15,-15));
    rect.setBottomRight(QPointF(15,15));
    return rect;
}
Пример #8
0
void ColorScaleWidget::paintColorScale(QPainter& painter, const QRect& rect) {
  painter.setPen(Qt::NoPen);
  map<float, Color> colorMap = colorScale->getColorMap();

  if (colorScale->isGradient()) {
    QPoint start;
    QPoint stop;

    if (orientation == Qt::Horizontal) {
      start = QPoint(rect.left(), rect.center().y());
      stop = QPoint(rect.right(), rect.center().y());
    }
    else {
      start = QPoint(rect.center().x(), rect.bottom());
      stop = QPoint(rect.center().x(), rect.top());
    }

    QLinearGradient qLinearGradient(start, stop);

    for (map<float, Color>::iterator it = colorMap.begin(); it != colorMap.end(); ++it) {
      qLinearGradient.setColorAt(it->first, QColor(it->second[0], it->second[1], it->second[2], it->second[3]));
    }

    painter.fillRect(rect, qLinearGradient);
  }
  else {
    unsigned int nb = 0;
    float rectWidth = ((float) rect.width()) / colorMap.size();
    float rectHeight = ((float) rect.height()) / colorMap.size();

    for (map<float, Color>::iterator it = colorMap.begin(); it != colorMap.end(); ++it) {
      QRectF rectangle;

      if (orientation == Qt::Horizontal) {
        rectangle.setTopLeft(QPointF(rect.left() + nb * rectWidth, rect.top()));
        rectangle.setSize(QSizeF(rectWidth, rect.height()));
      }
      else {
        rectangle.setTopLeft(QPointF(rect.left(), rect.bottom() - (nb + 1) * rectHeight));
        rectangle.setSize(QSizeF(rect.width(), rectHeight));
      }

      painter.fillRect(rectangle, QBrush(QColor(it->second[0], it->second[1], it->second[2], it->second[3])));
      ++nb;
    }
  }
}
Пример #9
0
//! \brief Return bounding rectangle arround a wireline
QRectF WireLine::boundingRect() const
{
   QRectF rect;
   rect.setTopLeft(p1());
   rect.setBottomRight(p2());
   rect = rect.normalized();
   rect.adjust(-m_adjust, -m_adjust, +m_adjust, +m_adjust);
   return rect;
}
Пример #10
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;
}
Пример #11
0
void GraphDraw::drawSquare(QPointF pt, double w)
{
    painter.setRenderHint(QPainter::Antialiasing, false);

    QRectF rect;
    rect.setTopLeft(pt + QPointF(-w,-w));
    rect.setBottomRight(pt + QPointF(w,w));

    painter.drawRect(rect);
}
QRectF UB1HEditableGraphicsSquareItem::rect() const
{
    QRectF r;
    r.setTopLeft(pos());

    r.setWidth(wIsNeg ? -mSide : mSide);
    r.setHeight(hIsNeg ? -mSide : mSide);

    return r;
}
Пример #13
0
bool core::Connector::eventFilter(QObject *sender, QEvent *event)
{
//	qDebug () << event->type();
	if(event->type() == QEvent::MouseMove){
		QMouseEvent *hEvent = (QMouseEvent*)event;

		GraphicDetailedView *gdv = (GraphicDetailedView*)sender;

		QPointF pos = mapFromScene(gdv->mapToScene(hEvent->pos()));
		currentMousePos = pos;

//		qDebug() << currentMousePos << "<< currentMousePos";

		QRectF container = getContainerRect();

		if(pos.x() < 0 && pos.y() < 0){
			container.setTopLeft(pos);
			container.setBottomRight(QPointF(0, 0));
		}else if(pos.x() < 0 && pos.y() >= 0){
			container.setBottomLeft(pos);
			container.setTopRight(QPointF(0, 0));
		}else if(pos.x() >= 0 && pos.y() < 0){
			container.setTopRight(pos);
			container.setBottomLeft(QPointF(0, 0));
		}else if(pos.x() >= 0 && pos.y() >= 0){
			container.setBottomRight(pos);
			container.setTopLeft(QPointF(0, 0));
		}else{
			container= QRectF(0, 0, 0, 0);
		}

		setContainerRect(container);

		if(isBuildingConector){
			updateConectorLine(beginPoint, pos);
		}

		return true;
	}

	return GraphicObject::eventFilter(sender, event);
}
Пример #14
0
static QRectF buildReferenceRect( const PolarCoordinatePlane* plane )
{
    QRectF contentsRect;
    QPointF referencePointAtTop = plane->translate( QPointF( 1, 0 ) );
    QPointF temp = plane->translate( QPointF( 0, 0 ) ) - referencePointAtTop;
    const double offset = temp.y();
    referencePointAtTop.setX( referencePointAtTop.x() - offset );
    contentsRect.setTopLeft( referencePointAtTop );
    contentsRect.setBottomRight( referencePointAtTop + QPointF( 2*offset, 2*offset) );
    return contentsRect;
}
Пример #15
0
void AutoFindPath::onTimeout()
{
    qreal x1 = tempPointF_.x();
    qreal y1 = tempPointF_.y();

    qreal x2 = toPointF_.x();
    qreal y2 = toPointF_.y();

    qreal xNegative = (x2 - x1) > 0 ? 1.0 : -1.0;
    qreal yNegative = (y2 - y1) > 0 ? 1.0 : -1.0;

    xNegative = 1.0;
    yNegative = 1.0;
    qreal fromDistance = qSqrt(qPow(x2-x1, 2) + qPow(y2-y1, 2));

    qreal xdif = xNegative * pace_ * (x2 - x1) / fromDistance;
    qreal ydif = yNegative * pace_ * (y2 - y1) / fromDistance;

    qreal x3 = x1 + xdif;
    qreal y3 = y1 + ydif;
    qreal toDistance = qSqrt(qPow(x3-x2, 2) + qPow(y3-y2, 2));

//    qDebug() << tempPointF_ << toPointF_<< xNegative << yNegative<<fromDistance<<toDistance<< xdif << ydif;

    tempPointF_.setX(x3);
    tempPointF_.setY(y3);

    if (toDistance <= radius_) {
//        qDebug() << "STOP!";
        timer_.stop();
        if (rolePathMap_.contains(role_)) {
            rolePathMap_.remove(role_);
        }
        this->deleteLater();
    }

    qreal ration = qAtan2(ydif, xdif);
    qreal degree = qRadiansToDegrees(ration);
//    qDebug() << ration << degree;
    role_->setRotation(degree + 90);
//    setRotation(rotation() + dx);

    role_->setPos(tempPointF_);
//    role_->setEyeDirection();

//    role_->update();
//    QRectF rect = role_->mapRectToScene(role_->boundingRect());
    QPointF pos = role_->mapToScene(role_->pos());
    QRectF rect;
    rect.setTopLeft(pos);
    rect.setWidth(20);
    rect.setHeight(20);
    role_->scene()->invalidate();
}
QRectF UB1HEditableGraphicsCircleItem::rect() const
{
    QRectF r;
    r.setTopLeft(pos());

    int rx = wIsNeg ? -mRadius : mRadius;
    int ry = hIsNeg ? -mRadius : mRadius;

    r.setWidth(rx*2);
    r.setHeight(ry*2);

    return r;
}
Пример #17
0
	void GraphicsView::mouseMoveEvent(QMouseEvent* event)
	{
		if (m_dragging)
		{
			QRectF rect = sceneRect();
			rect.setTopLeft(QPointF(m_xPrev - event->localPos().x() + rect.x(), m_yPrev - event->localPos().y() + rect.y()));
			m_xPrev = event->localPos().x();
			m_yPrev = event->localPos().y();
			setSceneRect(rect);
			emit sceneMoved();
		}
		QGraphicsView::mouseMoveEvent(event);
	}
Пример #18
0
QRectF KoPatternBackground::patternRectFromFillSize(const QSizeF &size)
{
    Q_D(KoPatternBackground);
    QRectF rect;

    switch (d->repeat) {
    case Tiled:
        rect.setTopLeft(d->offsetFromRect(QRectF(QPointF(), size), d->targetSize()));
        rect.setSize(d->targetSize());
        break;
    case Original:
        rect.setLeft(0.5 * (size.width() - d->targetSize().width()));
        rect.setTop(0.5 * (size.height() - d->targetSize().height()));
        rect.setSize(d->targetSize());
        break;
    case Stretched:
        rect.setTopLeft(QPointF(0.0, 0.0));
        rect.setSize(size);
        break;
    }

    return rect;
}
void QNodeItem::setPos(const QPointF& Pos)
{
	if (Pos == pos())
		return;

	QGraphicsEllipseItem::setPos(Pos);

	QRectF EllipseRect;

	EllipseRect.setTopLeft(QPointF(-m_Radius, -m_Radius));
	EllipseRect.setWidth(2.0f * m_Radius);
	EllipseRect.setHeight(2.0f * m_Radius);

	setRect(EllipseRect);
}
Пример #20
0
void PrintTool::updateDragging(MapCoordF mouse_pos_map)
{
	QPointF delta = QPointF(mouse_pos_map - click_pos_map);
	QRectF area = map_printer->getPrintArea();
	switch (region)
	{
		case Inside:
			area.moveTopLeft(area.topLeft() + delta);
			break;
		case LeftBorder:
			area.setLeft(area.left() + delta.rx());
			break;
		case TopLeftCorner:
			area.setTopLeft(area.topLeft() + delta);
			break;
		case TopBorder:
			area.setTop(area.top() + delta.ry());
			break;
		case TopRightCorner:
			area.setTopRight(area.topRight() + delta);
			break;
		case RightBorder:
			area.setRight(area.right() + delta.rx());
			break;
		case BottomRightCorner:
			area.setBottomRight(area.bottomRight() + delta);
			break;
		case BottomBorder:
			area.setBottom(area.bottom() + delta.ry());
			break;
		case BottomLeftCorner:
			area.setBottomLeft(area.bottomLeft() + delta);
			break;
		case Outside:
			Q_ASSERT(false); // Handled outside.
		case Unknown:
			; // Nothing
	}
	
	if (area.left() < area.right() && area.top() < area.bottom())
	{
		map_printer->setPrintArea(area);
		click_pos_map = mouse_pos_map;
	}
}
Пример #21
0
void ResizingGrip::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
    // ==========================================================================================
    // VERSION 1: Resize AreaItem and then move it to 0,0
    // ==========================================================================================

    QRectF  resizableZone = _areaItem->getRect().translated(_areaItem->scenePos());
    QPointF scenePos = event->scenePos();

    switch(_position)
    {
        case TOPLEFT:
            resizableZone.setTopLeft(scenePos);
            break;
        case TOPCENTER:
            resizableZone.setTop(scenePos.y());
            break;
        case TOPRIGHT:
            resizableZone.setTopRight(scenePos);
            break;
        case LEFTCENTER:
            resizableZone.setLeft(scenePos.x());
            break;
        case RIGHTCENTER:
            resizableZone.setRight(scenePos.x());
            break;
        case BOTTOMLEFT:
            resizableZone.setBottomLeft(scenePos);
            break;
        case BOTTOMCENTER:
            resizableZone.setBottom(scenePos.y());
            break;
        case BOTTOMRIGHT:
            resizableZone.setBottomRight(scenePos);
            break;
        default:
            Q_ASSERT(false);
    }

    //resizableZone.moveTopLeft(QPointF(0, 0));
    _areaItem->updateMainDiagram(resizableZone);

    event->accept();
}
void PdfThumbProvider::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, ThumbWidget *widget)
{
    if ( widget && painter ) {
        int pageIndex = widget->getPageIndex();
        QRectF expsRect = option->exposedRect;
        expsRect.setTopLeft(QPointF(0,0));
        if ((!painter->clipRegion().isEmpty()) && (!painter->clipRegion().contains(expsRect.toRect()))) {
            return;
        }
        qreal thumbWidth = widget->style()->preferredSize().width();

        QPixmap thumbnail;
        if ( !QPixmapCache::find(widget->key(), &thumbnail) ) {
            qreal pageWidth = data->loader->pageSize(pageIndex).width();
            qreal scale = PdfLoader::DPIPerInch * (thumbWidth / pageWidth);

            qDebug() <<  __PRETTY_FUNCTION__ << "getThumbnail";
            QImage thumb = data->loader->getThumbnail(pageIndex, scale);
            if (thumb.isNull()) {
                widget->startSpinner(expsRect.center());
                return;
            }
            thumbnail = QPixmap::fromImage(thumb.scaledToWidth(thumbWidth));
            m_lastThumbanailSize = QSizeF(thumbnail.size());
            widget->setKey(QPixmapCache::insert(thumbnail));
            painter->drawPixmap(QPointF(0,0), thumbnail, expsRect);
            widget->stopSpinner();
        } else {
            if (thumbnail.width() != thumbWidth) {
                qDebug() << "Thumbnail is scaled to Thumbnail widget ";
                thumbnail = thumbnail.scaledToWidth(thumbWidth);
                QPixmapCache::replace(widget->key(), thumbnail);
                m_lastThumbanailSize = QSizeF(thumbnail.size());
            }
            painter->drawPixmap(QPointF(0,0), thumbnail, expsRect);
        }

        if (m_lastThumbanailSize.height() > 0) {
            widget->setSize(m_lastThumbanailSize, 2);
        }
    }
}
Пример #23
0
QRectF RelationshipView::__boundingRect(void)
{
	float x1=0, y1=0, x2=0, y2=0;
	unsigned i, count;
	QPointF p;
	QRectF rect;
	vector<QPointF> points=dynamic_cast<BaseRelationship *>(this->getSourceObject())->getPoints();

	//The reference size will be the relationship descriptor dimension
	x1=descriptor->pos().x();
	y1=descriptor->pos().y();
	x2=descriptor->pos().x() + descriptor->boundingRect().width();
	y2=descriptor->pos().y() + descriptor->boundingRect().height();

	//Checks if some point is out of reference dimension
	count=points.size();
	for(i=0; i < count; i++)
	{
		p=points[i];
		if(x1 > p.x()) x1=p.x() - GRAPHIC_PNT_RADIUS;
		if(y1 > p.y()) y1=p.y() - GRAPHIC_PNT_RADIUS;
		if(x2 < p.x()) x2=p.x() + GRAPHIC_PNT_RADIUS;
		if(y2 < p.y()) y2=p.y() + GRAPHIC_PNT_RADIUS;
	}

	//Checks if some label is out of reference dimension
	for(i=0; i < 3; i++)
	{
		if(labels[i])
		{
			rect.setTopLeft(labels[i]->scenePos());
			rect.setSize(labels[i]->boundingRect().size());
			if(x1 > rect.left()) x1=rect.left();
			if(y1 > rect.top()) y1=rect.top();
			if(x2 < rect.right()) x2=rect.right();
			if(y2 < rect.bottom()) y2=rect.bottom();
		}
	}

	return(QRectF(x1, y1, x2, y2));
}
Пример #24
0
//-----------------------------------------------------------
QRectF OGRelacionamento::__boundingRect(void)
{
 float x1=0, y1=0, x2=0, y2=0;
 unsigned i, qtd;
 QPointF p;
 QRectF ret;
 vector<QPointF> pontos=dynamic_cast<RelacionamentoBase *>(this->obterObjetoOrigem())->obterPontos();

 //O tamanho de referência será o do descritor
 x1=descritor->pos().x();
 y1=descritor->pos().y();
 x2=descritor->pos().x() + descritor->boundingRect().width();
 y2=descritor->pos().y() + descritor->boundingRect().height();

 //Verifica se algum dos pontos extrapola a dimensão de referência
 qtd=pontos.size();
 for(i=0; i < qtd; i++)
 {
  p=pontos[i];
  if(x1 > p.x()) x1=p.x() - RAIO_PNT_GRAFICO;
  if(y1 > p.y()) y1=p.y() - RAIO_PNT_GRAFICO;
  if(x2 < p.x()) x2=p.x() + RAIO_PNT_GRAFICO;
  if(y2 < p.y()) y2=p.y() + RAIO_PNT_GRAFICO;
 }

 //Verifica se a dimensão de um dos rótulos extrapola a dimensão de referência
 for(i=0; i < 3; i++)
 {
  if(rotulos[i])
  {
   ret.setTopLeft(rotulos[i]->scenePos());
   ret.setSize(rotulos[i]->boundingRect().size());
   if(x1 > ret.left()) x1=ret.left();
   if(y1 > ret.top()) y1=ret.top();
   if(x2 < ret.right()) x2=ret.right();
   if(y2 < ret.bottom()) y2=ret.bottom();
  }
 }

 return(QRectF(x1, y1, x2, y2));
}
Пример #25
0
QRectF CPcbSegment::boundingRect() const
{
	CPcbSegment* me=(CPcbSegment*)this;
	QRectF rect;
	if ( me->drawable() )
	{
		me->setZValue(me->layerIndex());
		rect = me->shape().boundingRect();
	}
	else
	{
		if ( me->pcb() != NULL && me->pcb()->structure() != NULL && me->pcb()->structure()->boundary() != NULL )
		{
			QPointF topLeft = me->pcb()->structure()->boundary()->boundingRect().topLeft();
			rect.setTopLeft(topLeft);
			rect.setWidth(0);
			rect.setHeight(0);
		}
	}
	return rect;
}
Пример #26
0
void QgsMapCanvasItem::setRect( const QgsRectangle& rect )
{
  mRect = rect;
  //updatePosition();

  QRectF r; // empty rect by default
  if ( !mRect.isEmpty() )
  {
    r.setTopLeft( toCanvasCoordinates( QgsPoint( mRect.xMinimum(), mRect.yMinimum() ) ) );
    r.setBottomRight( toCanvasCoordinates( QgsPoint( mRect.xMaximum(), mRect.yMaximum() ) ) );
    r = r.normalized();
  }

  // set position in canvas where the item will have coordinate (0,0)
  prepareGeometryChange();
  setPos( r.topLeft() );
  mItemSize = QSizeF( r.width() + 2, r.height() + 2 );

  // QgsDebugMsg(QString("[%1,%2]-[%3x%4]").arg((int) r.left()).arg((int) r.top()).arg((int) r.width()).arg((int) r.height()));

  update();
}
Пример #27
0
int QgsComposition::boundingRectOfSelectedItems( QRectF& bRect )
{
  QList<QgsComposerItem*> selectedItems = selectedComposerItems();
  if ( selectedItems.size() < 1 )
  {
    return 1;
  }

  //set the box to the first item
  QgsComposerItem* currentItem = selectedItems.at( 0 );
  double minX = currentItem->transform().dx();
  double minY = currentItem->transform().dy();
  double maxX = minX + currentItem->rect().width();
  double maxY = minY + currentItem->rect().height();

  double currentMinX, currentMinY, currentMaxX, currentMaxY;

  for ( int i = 1; i < selectedItems.size(); ++i )
  {
    currentItem = selectedItems.at( i );
    currentMinX = currentItem->transform().dx();
    currentMinY = currentItem->transform().dy();
    currentMaxX = currentMinX + currentItem->rect().width();
    currentMaxY = currentMinY + currentItem->rect().height();

    if ( currentMinX < minX )
      minX = currentMinX;
    if ( currentMaxX > maxX )
      maxX = currentMaxX;
    if ( currentMinY < minY )
      minY = currentMinY;
    if ( currentMaxY > maxY )
      maxY = currentMaxY;
  }

  bRect.setTopLeft( QPointF( minX, minY ) );
  bRect.setBottomRight( QPointF( maxX, maxY ) );
  return 0;
}
Пример #28
0
void QReportPage::paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*)
{
    QPen penPage(Qt::black, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
    QBrush brushPage(Qt::white);
    painter->setBrush(brushPage);
    painter->setPen(penPage);

    QRectF rc = this->rect();

    // draw page frame
    painter->fillRect(rc, Qt::white);
    painter->drawRect(rc);

    // set margins
    rc.setTopLeft(QPoint(_marginLeft, _marginTop));
    rc.setWidth(rc.width() - _marginRight);
    rc.setHeight(rc.height() - _marginBottom);

    if (_gridType == ::DotGrid)
        for (int i = rc.left(); i <= rc.right(); i = i + _gridSize)
            for (int j = rc.top(); j <= rc.bottom(); j = j + _gridSize)
                painter->drawPoint(i, j);


    if (_gridType == ::LinesGrid) {
        painter->setPen(QPen(Qt::lightGray));
        for (int i = rc.left(); i <= rc.right(); i = i + _gridSize)
            painter->drawLine(i, rc.top(), i, rc.bottom());
        for (int j = rc.top(); j <= rc.bottom(); j = j + _gridSize)
            painter->drawLine(rc.left(), j, rc.right(), j);
    }//if

    // draw inside margins
    painter->setBrush(Qt::NoBrush);
    painter->setPen(QPen(QColor(180, 190, 220)));
    painter->drawRect(rc);

}
Пример #29
0
void ColorWheel::resizeEvent(QResizeEvent* event) {
    // update wheel region
    QSize size(event->size());
    int diameter = qMin(size.width(), size.height());
    wheelRegion_ = QRegion(diameter/2, diameter/2, diameter-2*margin_, diameter-2*margin_, QRegion::Ellipse);
    wheelRegion_.translate(-(diameter-2*margin_)/2, -(diameter-2*margin_)/2);
    int tmp = 2*(margin_+wheelWidth_);
    QRegion subRe(diameter/2, diameter/2, diameter-tmp, diameter-tmp, QRegion::Ellipse);
    subRe.translate(-(diameter-tmp)/2, -(diameter-tmp)/2);
    wheelRegion_ -= subRe;
    
    // update square region
    int w = qMin(width(), height());
    qreal r = w/2.0 - margin_; // radius of outer circle
    qreal ir = r - wheelWidth_; // radius of inner circle
    qreal m = w/2.0 - ir/std::sqrt(2.0); // left corner of square

    QRectF rect;
    rect.setTopLeft(QPointF(m, m));
    rect.setWidth(2.0 * ir / std::sqrt(2.0));
    rect.setHeight(2.0 * ir / std::sqrt(2.0));
    squareRegion_ = QRegion(rect.toRect());
}
Пример #30
0
void ExampleView::setDropTarget(const Element* el)
      {
      if (dropTarget != el) {
            if (dropTarget) {
                  dropTarget->setDropTarget(false);
                  dropTarget = 0;
                  }
            dropTarget = el;
            if (dropTarget) {
                  dropTarget->setDropTarget(true);
                  }
            }
      if (!dropAnchor.isNull()) {
            QRectF r;
            r.setTopLeft(dropAnchor.p1());
            r.setBottomRight(dropAnchor.p2());
            dropAnchor = QLineF();
            }
      if (dropRectangle.isValid()) {
            dropRectangle = QRectF();
            }
      update();
      }