예제 #1
0
void QwtPlotZoomer::zoom( const QRectF &rect )
{
    if ( d_data->maxStackDepth >= 0 &&
            int( d_data->zoomRectIndex ) >= d_data->maxStackDepth )
    {
        return;
    }

    const QRectF zoomRect = rect.normalized();
    if ( zoomRect != d_data->zoomStack[d_data->zoomRectIndex] )
    {
        for ( uint i = d_data->zoomStack.count() - 1;
           i > d_data->zoomRectIndex; i-- )
        {
            ( void )d_data->zoomStack.pop();
        }

        d_data->zoomStack.push( zoomRect );
        d_data->zoomRectIndex++;

        rescale();

        Q_EMIT zoomed( zoomRect );
    }
}
예제 #2
0
/*!
   \return Bounding rectangle of the data
   \sa QwtPlotRasterItem::interval()
*/
QRectF QwtPlotRasterItem::boundingRect() const
{
    const QwtInterval intervalX = interval( Qt::XAxis );
    const QwtInterval intervalY = interval( Qt::YAxis );

    if ( !intervalX.isValid() && !intervalY.isValid() )
        return QRectF(); // no bounding rect

    QRectF r;

    if ( intervalX.isValid() )
    {
        r.setLeft( intervalX.minValue() );
        r.setRight( intervalX.maxValue() );
    }
    else
    {
        r.setLeft(-0.5 * FLT_MAX);
        r.setWidth(FLT_MAX);
    }

    if ( intervalY.isValid() )
    {
        r.setTop( intervalY.minValue() );
        r.setBottom( intervalY.maxValue() );
    }
    else
    {
        r.setTop(-0.5 * FLT_MAX);
        r.setHeight(FLT_MAX);
    }

    return r.normalized();
}
예제 #3
0
void ImageScene::mouseMoveEvent(QGraphicsSceneMouseEvent* in_mEvent) {
	if (m_pPixmap == NULL) {
		return;
	}
	qreal x = in_mEvent->scenePos().x(), y = in_mEvent->scenePos().y();
	if ( 	x < m_pPixmap->offset().x() ) {
		x = m_pPixmap->offset().x();
	} else if ( x - m_pPixmap->offset().x() >= m_pPixmap->pixmap().rect().width() ) {
		x = m_pPixmap->pixmap().rect().width() + m_pPixmap->offset().x() - 1;
	}
	if ( y < m_pPixmap->offset().y() ) {
		y = m_pPixmap->offset().y();
	} else if ( y - m_pPixmap->offset().y() >= m_pPixmap->pixmap().rect().height() ) {
		y = m_pPixmap->pixmap().rect().height() + m_pPixmap->offset().y() - 1;
	}
	if (m_pSelection != NULL) {
		QRectF rect;
		rect.setCoords ( m_SelectionPosition.x(),
				 m_SelectionPosition.y(),
				 x,y );
		m_pSelection->setRect ( rect.normalized());
	} else {
		m_pSelection = QGraphicsScene::addRect (x,y,0,0, m_SelectionPen, m_SelectionBrush);
		m_pSelection->setParentItem (m_pPixmap);
		m_SelectionPosition = m_pSelection->rect().topLeft();
	}

	if  ( 	m_pSelection->rect().width() < 1 ||
		m_pSelection->rect().height() < 1 )
	{
		m_pSelection->setVisible(false);
	} else {
		m_pSelection->setVisible(true);
	}
}
예제 #4
0
 TShape::TShape(const enum TShapeType ShapeType_, const QRectF &Rect_, const QString& Name_,
    const unsigned FillColor_, const unsigned BorderColor_, const unsigned BorderWidth_)
    : TGeometry(Name_), m_ShapeType(ShapeType_), m_FillColor(FillColor_),
      m_BorderColor(BorderColor_), m_BorderWidth(BorderWidth_)
 {
 setGeometryType("Shape");
 m_BoundingBoxF = Rect_.normalized();
 m_TextPosition = Middle;
 }
예제 #5
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;
}
예제 #6
0
void CartesianRenderItem::paintRelations(QPainter *painter) {

  QRectF normalRect = rect();
  normalRect = normalRect.normalized();

  painter->save();
  painter->translate(normalRect.x(), normalRect.y());

  foreach (RelationPtr relation, relationList()) {
    //FIXME static_cast to kstvcurve and take advantage of extra api

    CurveRenderContext context;
    context.painter = painter;
    context.window = QRect(); //no idea if this should be floating point
    context.penWidth = painter->pen().width(); //floating point??
    context.xLog = isXAxisLog();
    context.yLog = isYAxisLog();
    context.xLogBase = xLogBase();
    context.yLogBase = yLogBase();
    context.foregroundColor = painter->pen().color();
    context.backgroundColor = painter->brush().color();

    //FIXME rename these methods in kstvcurve
    //FIXME Completely refactor KstCurveRenderContext now that we know what these are

    //Set the projection box...
    context.XMin = projectionRect().left();
    context.XMax = projectionRect().right();
    context.YMin = projectionRect().top();
    context.YMax = projectionRect().bottom();

    //Set the log box...
    context.x_max = isXAxisLog() ? logXHi(context.XMax, context.xLogBase) : context.XMax;
    context.y_max = isYAxisLog() ? logXHi(context.YMax, context.yLogBase) : context.YMax;
    context.x_min = isXAxisLog() ? logXLo(context.XMin, context.xLogBase) : context.XMin;
    context.y_min = isYAxisLog() ? logXLo(context.YMin, context.yLogBase) : context.YMin;

    //These are the bounding box in regular QGV coord
    context.Lx = plotRect().left();
    context.Hx = plotRect().right();
    context.Ly = plotRect().top();
    context.Hy = plotRect().bottom();

    //To convert between the last two...
    double m_X = double(plotRect().width()-1)/(context.x_max - context.x_min);
    double m_Y = -double(plotRect().height()-1)/(context.y_max - context.y_min);
    double b_X = context.Lx - m_X * context.x_min;
    double b_Y = context.Ly - m_Y * context.y_max;

    context.m_X = m_X;
    context.m_Y = m_Y;
    context.b_X = b_X;
    context.b_Y = b_Y;

    relation->paint(context);
  }
예제 #7
0
/*!
   Transform a rectangle from paint to scale coordinates

   \param xMap X map
   \param yMap Y map
   \param rect Rectangle in paint coordinates
   \return Rectangle in scale coordinates
   \sa transform()
*/
QRectF QwtScaleMap::invTransform( const QwtScaleMap &xMap,
    const QwtScaleMap &yMap, const QRectF &rect )
{
    const double x1 = xMap.invTransform( rect.left() );
    const double x2 = xMap.invTransform( rect.right() - 1 );
    const double y1 = yMap.invTransform( rect.top() );
    const double y2 = yMap.invTransform( rect.bottom() - 1 );

    const QRectF r( x1, y1, x2 - x1, y2 - y1 );
    return r.normalized();
}
예제 #8
0
void MapHelperUniversal::move(const QRectF &rgn)
{
    Q_D(MapHelperUniversal);
    if (d->states.testFlag(stMove))
        return;

    MapSubHelperMove *sub = new MapSubHelperMove(d->map);
    d->addSubhelper(sub);
    if (!rgn.isEmpty())
        sub->initData(rgn.normalized());
}
예제 #9
0
/***********************************************************************
 *Funtion : Get the handle rect
 *Return  : QRectF handle rect.
 *Parameter: handle id.
 **********************************************************************/
QRectF SamDrawItemBase::getHandleRect(int iHandleID, QRectF &qrcBondingRect)
{
    QRectF qrRect;
    // get the center of the handle in logical coords
    QPointF qpPoint = getHandle(iHandleID, qrcBondingRect);

    /*Set the rect and normalize it*/
    qrRect.setRect(qpPoint.rx()-SAMDRAW_TRACKER_POS_OFT, qpPoint.ry()-SAMDRAW_TRACKER_POS_OFT, SAMDRAW_TRACKER_SIZE, SAMDRAW_TRACKER_SIZE);
    qrRect = qrRect.normalized();

    return qrRect;
}
예제 #10
0
/**
 * @brief GridItem::firstDataInterval Determins the first grid interval in data space.
 */
QRectF GridItem::firstDataInterval(QRectF dataRect) const
{
	QSizeF interval(m_minDistance, m_minDistance);
	interval = m_transform->sceneToData(interval);
	interval = niceInterval(interval);
	if (m_useManualInterval) {
		interval.setWidth(std::max(m_manualInterval.width(), interval.width()));
		interval.setHeight(std::max(m_manualInterval.height(), interval.height()));
	}
	QPointF start = intervalStart(dataRect.normalized().topLeft(), interval, QPointF());
	return QRectF(start, interval);
}
예제 #11
0
void QgsLayoutItemGroup::attemptResize( const QgsLayoutSize &size, bool includesFrame )
{
  if ( !mLayout )
    return;

  if ( !shouldBlockUndoCommands() )
    mLayout->undoStack()->beginMacro( tr( "Resize Group" ) );

  QRectF oldRect = rect();
  QSizeF newSizeLayoutUnits = mLayout->convertToLayoutUnits( size );
  QRectF newRect;
  newRect.setSize( newSizeLayoutUnits );

  //also resize all items within the group
  for ( QgsLayoutItem *item : qgis::as_const( mItems ) )
  {
    if ( !item )
      continue;

    std::unique_ptr< QgsAbstractLayoutUndoCommand > command;
    if ( !shouldBlockUndoCommands() )
    {
      command.reset( createCommand( QString(), 0 ) );
      command->saveBeforeState();
    }

    QRectF itemRect = mapRectFromItem( item, item->rect() );
    QgsLayoutUtils::relativeResizeRect( itemRect, oldRect, newRect );

    itemRect = itemRect.normalized();
    QPointF newPos = mapToScene( itemRect.topLeft() );

    QgsLayoutSize itemSize = mLayout->convertFromLayoutUnits( itemRect.size(), item->sizeWithUnits().units() );
    item->attemptResize( itemSize, includesFrame );

    // translate new position to current item units
    QgsLayoutPoint itemPos = mLayout->convertFromLayoutUnits( newPos, item->positionWithUnits().units() );
    item->attemptMove( itemPos, false );

    if ( command )
    {
      command->saveAfterState();
      mLayout->undoStack()->push( command.release() );
    }
  }
  QgsLayoutItem::attemptResize( size );
  if ( !shouldBlockUndoCommands() )
    mLayout->undoStack()->endMacro();

  resetBoundingRect();
}
예제 #12
0
/**
 * @brief GridItem::firstSceneInterval Determins the first grid interval in scene space
 */
QRectF GridItem::firstSceneInterval(QRectF sceneRect) const
{
	QSizeF interval(m_minDistance, m_minDistance);
	interval = m_transform->sceneToData(interval);
	interval = niceInterval(interval);
	if (m_useManualInterval) {
		interval.setWidth(std::max(m_manualInterval.width(), interval.width()));
		interval.setHeight(std::max(m_manualInterval.height(), interval.height()));
	}
	interval = m_transform->dataToScene(interval);
	interval = QSizeF(std::fabs(interval.width()), std::fabs(interval.height()));
	QPointF start = intervalStart(sceneRect.normalized().topLeft(), interval, m_transform->origin());
	return QRectF(start, interval);
}
예제 #13
0
void LensItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
	QRectF r = rect();
	double dx = (mousePoint.x() - event->screenPos().x()) / scaling;
	if (handle == 0)
	{
		QPointF tl = r.topLeft();
		tl = tl - QPointF(dx, dx);
		r.setTopLeft(tl);
		setRect(r.normalized());
	}
	else if (handle == 1)
	{
		QPointF tl = r.topRight();
		tl = tl - QPointF(dx, -dx);
		r.setTopRight(tl);
		setRect(r.normalized());
	}
	else if (handle == 2)
	{
		QPointF tl = r.bottomRight();
		tl = tl - QPointF(dx, dx);
		r.setBottomRight(tl);
		setRect(r.normalized());
	}
	else if (handle == 3)
	{
		QPointF tl = r.bottomLeft();
		tl = tl - QPointF(dx, -dx);
		r.setBottomLeft(tl);
		setRect(r.normalized());
	}
	else
		QGraphicsItem::mouseMoveEvent(event);
	mousePoint = event->screenPos();
	dialog->lensSelected(this);
}
예제 #14
0
/*! Find a minimal rectangle that encapsulates the polygon. The
    rectangle is returned in the QRectF object.
 */
QRectF Polygon2D::GetSurroundingRectangle() const
{
	QRectF rc;

   if(m_vecV.size()) {
		Point2D pt1, pt2;
		GetSurroundingRectangle(pt1, pt2);
		rc.setCoords(
			pt1.GetX(), pt2.GetY(),	// left, top 
			pt2.GetX(), pt1.GetY()  // right, bottom.
		);
   }

	return rc.normalized();
}
예제 #15
0
/*!
  \return Normalized bounding rectangle of the axes
  \sa QwtPlot::autoReplot(), QwtPlot::replot().
*/
QRectF QwtPlotPicker::scaleRect() const
{
    QRectF rect;

    if ( plot() )
    {
        const QwtScaleDiv &xs = plot()->axisScaleDiv( xAxis() );
        const QwtScaleDiv &ys = plot()->axisScaleDiv( yAxis() );

        rect = QRectF( xs.lowerBound(), ys.lowerBound(),
            xs.range(), ys.range() );
        rect = rect.normalized();
    }

    return rect;
}
예제 #16
0
QRect CanvasBase::viewToCellCoordinates(const QRectF& viewRect) const
{
    register Sheet * const sheet = activeSheet();
    if (!sheet)
        return QRect();

    // NOTE Stefan: Do not consider the layout direction in this case.
    const QRectF rect = viewConverter()->viewToDocument(viewRect.normalized()).translated(offset());

    qreal tmp;
    const int left = sheet->leftColumn(rect.left(), tmp);
    const int right = sheet->rightColumn(rect.right());
    const int top = sheet->topRow(rect.top(), tmp);
    const int bottom = sheet->bottomRow(rect.bottom());

    return QRect(left, top, right - left + 1, bottom - top + 1);
}
/**
 * Draws a 3D cuboid by extending a 2D rectangle in the z-axis
 *
 * @param rect The rectangle to draw
 * @param brush The brush fill the surfaces of the cuboid with
 * @param pen The pen to draw the edges with
 * @param props The 3D properties to use for drawing the cuboid
 * @return The drawn cuboid as a polygon
 */
QPolygonF StockDiagram::Private::ThreeDPainter::drawThreeDRect( const QRectF &rect, const QBrush &brush,
                                                                const QPen &pen, const ThreeDProperties &props )
{
    // Restores the painting properties when destroyed
    PainterSaver painterSaver( painter );

    // Make sure that the top really is the top
    const QRectF normalizedRect = rect.normalized();

    // Calculate all the four sides of the rectangle
    const QLineF topSide = QLineF( normalizedRect.topLeft(), normalizedRect.topRight() );
    const QLineF bottomSide = QLineF( normalizedRect.bottomLeft(), normalizedRect.bottomRight() );
    const QLineF leftSide = QLineF( normalizedRect.topLeft(), normalizedRect.bottomLeft() );
    const QLineF rightSide = QLineF( normalizedRect.topRight(), normalizedRect.bottomRight() );

    QPolygonF drawnPolygon;

    // Shorter names are easier on the eyes
    const qreal angle = props.angle;

    // Only top and right side is visible
    if ( angle >= 0.0 && angle < 90.0 ) {
        drawnPolygon = drawnPolygon.united( drawThreeDLine( topSide, brush, pen, props ) );
        drawnPolygon = drawnPolygon.united( drawThreeDLine( rightSide, brush, pen, props ) );
    // Only top and left side is visible
    } else if ( angle >= 90.0 && angle < 180.0 ) {
        drawnPolygon = drawnPolygon.united( drawThreeDLine( topSide, brush, pen, props ) );
        drawnPolygon = drawnPolygon.united( drawThreeDLine( leftSide, brush, pen, props ) );
    // Only bottom and left side is visible
    } else if ( angle >= 180.0 && angle < 270.0 ) {
        drawnPolygon = drawnPolygon.united( drawThreeDLine( bottomSide, brush, pen, props ) );
        drawnPolygon = drawnPolygon.united( drawThreeDLine( leftSide, brush, pen, props ) );
    // Only bottom and right side is visible
    } else if ( angle >= 270.0 && angle <= 360.0 ) {
        drawnPolygon = drawnPolygon.united( drawThreeDLine( bottomSide, brush, pen, props ) );
        drawnPolygon = drawnPolygon.united( drawThreeDLine( rightSide, brush, pen, props ) );
    }

    // Draw the front side
    painter->setPen( pen );
    painter->setBrush( brush );
    painter->drawRect( normalizedRect );

    return drawnPolygon;
}
    void setCornerRects( const QPainterPath &path )
    {
        QPointF pos( 0.0, 0.0 );

        for ( int i = 0; i < path.elementCount(); i++ )
        {
            QPainterPath::Element el = path.elementAt(i); 
            switch( el.type )
            {
                case QPainterPath::MoveToElement:
                case QPainterPath::LineToElement:
                {
                    pos.setX( el.x );
                    pos.setY( el.y );
                    break;
                }
                case QPainterPath::CurveToElement:
                {
                    QRectF r( pos, QPointF( el.x, el.y ) );
                    clipRects += r.normalized();

                    pos.setX( el.x );
                    pos.setY( el.y );

                    break;
                }
                case QPainterPath::CurveToDataElement:
                {
                    if ( clipRects.size() > 0 )
                    {
                        QRectF r = clipRects.last();
                        r.setCoords( 
                            qMin( r.left(), el.x ),
                            qMin( r.top(), el.y ),
                            qMax( r.right(), el.x ),
                            qMax( r.bottom(), el.y )
                        );
                        clipRects.last() = r.normalized();
                    }
                    break;
                }
            }
        }
    }
void BaseFrameGraphicsView::mouseReleaseEvent(QMouseEvent * event)
{
	float scale, offset_x, offset_y;
	this->computeScaleOffsets(scale, offset_x, offset_y);

	qDebug() << "Release X : " << (event->pos().x()-offset_x)/scale << " Y : " << (event->pos().y()-offset_y)/scale;

	if(event->button() == Qt::LeftButton)
	{
		if(!correct_bb && drag  && !m_item_rect->isSelected())
		{
			QRectF rect = m_item_rect->rect();
			emit sig_bb_set(rect);
			rect.normalized();
			drag = false;
		}
	}
	QGraphicsView::mouseReleaseEvent(event);
}
예제 #20
0
void QgsMapCanvasItem::setRect( const QgsRectangle& rect )
{
  mRect = rect;
  //updatePosition();

  QRectF r; // empty rect by default
  if ( !mRect.isEmpty() )
  {
    r = toCanvasCoordinates( mRect.toRectF() );
    r = r.normalized();
  }

  // set position in canvas where the item will have coordinate (0,0)
  prepareGeometryChange();
  setPos( r.topLeft() ); // TODO: compute from (0,0) using toMapCoordinates ?
  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();
}
예제 #21
0
MarkerItem::MarkerItem(const QRectF& Rect, int type, QGraphicsItem* parent):
	QGraphicsItemGroup(parent), rect(Rect.normalized()), myType(type)
{
	mode = Rectangle;
	_isSinglePoint = false;
	arrow = new ArrowItem(QLineF(rect.center(), rect.bottomRight()));
	arrow->setArrowhead(ArrowHead::Start);
	box = new RectItem(rect);
	circle = new EllipseItem(rect);
	arrow->setIsMarker(true);
	box->setIsMarker(true);
	circle->setIsMarker(true);
	text = new SimpleTextItem("");
	setFlag(QGraphicsItem::ItemIsSelectable);
	addToGroup(arrow);
	addToGroup(box);
	addToGroup(circle);
	addToGroup(text);
	setType(type);
	HasContainer = false;
}
예제 #22
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();
}
예제 #23
0
/*!
   \return Bounding rectangle of the data
   \sa QwtPlotRasterItem::interval()
*/
QRectF QwtPlotRasterItem::boundingRect() const
{
    const QwtInterval intervalX = interval( Qt::XAxis );
    const QwtInterval intervalY = interval( Qt::YAxis );

    if ( !intervalX.isValid() && !intervalY.isValid() )
        return QRectF(); // no bounding rect

    QRectF r;

    if ( intervalX.isValid() )
    {
        r.setLeft( intervalX.minValue() );
        r.setRight( intervalX.maxValue() );
    }
    else
    {
        const float max = std::numeric_limits<float>::max();

        r.setLeft( -0.5 * max );
        r.setWidth( max );
    }

    if ( intervalY.isValid() )
    {
        r.setTop( intervalY.minValue() );
        r.setBottom( intervalY.maxValue() );
    }
    else
    {
        const float max = std::numeric_limits<float>::max();

        r.setTop( -0.5 * max );
        r.setHeight( max );
    }

    return r.normalized();
}
예제 #24
0
static void qtmDrawRoundedRect(QPainter *p, const QRectF &rect, qreal xRadius, qreal yRadius,
                               Qt::SizeMode mode)
{
  QRectF r = rect.normalized();
  
  if (r.isNull())
    return;
  
  if (mode == Qt::AbsoluteSize) {
    qreal w = r.width() / 2;
    qreal h = r.height() / 2;
    
    xRadius = 100 * qMin(xRadius, w) / w;
    yRadius = 100 * qMin(yRadius, h) / h;
  } else {
    if (xRadius > 100)                          // fix ranges
      xRadius = 100;
    
    if (yRadius > 100)
      yRadius = 100;
  }
  
  QPainterPath path;
  
  if (xRadius <= 0 || yRadius <= 0) {             // add normal rectangle
    path.addRect(r);
  } else {
    qreal x = r.x();
    qreal y = r.y();
    qreal w = r.width();
    qreal h = r.height();
    qreal rxx2 = w*xRadius/100;
    qreal ryy2 = h*yRadius/100;
    
#ifdef Q_WS_X11
    // There is a bug (probably in arcTo) for small sizes.
    // We use a rough linear approx.
    rxx2 /= 4;
    ryy2 /= 4;
    path.moveTo(x+rxx2,y);
    path.lineTo(x+w-rxx2, y);
    path.lineTo(x+w, y+ryy2);
    path.lineTo(x+w, y+h-ryy2);    
    path.lineTo(x+w-rxx2, y+h);    
    path.lineTo(x+rxx2, y+h);    
    path.lineTo(x, y+h-ryy2);    
    path.lineTo(x, y+ryy2);    
    path.closeSubpath();
#else
    path.moveTo(x+rxx2,y);
    path.arcMoveTo(x, y, rxx2, ryy2, 90);
    path.arcTo(x, y, rxx2, ryy2, 90, 90);
    path.arcTo(x, y+h-ryy2, rxx2, ryy2, 2*90, 90);
    path.arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 3*90, 90);
    path.arcTo(x+w-rxx2, y, rxx2, ryy2, 0, 90);
    path.closeSubpath();
#endif
  }
  
  p->drawPath(path);
}
예제 #25
0
void QcMultiSlider::paintEvent( QPaintEvent *e )
{
  using namespace QtCollider::Style;
  using QtCollider::Style::Ellipse;
  using QtCollider::Style::RoundRect;

  Q_UNUSED(e);
  QPainter p(this);
  p.setRenderHint( QPainter::Antialiasing, true );

  RoundRect frame(rect(), 2);
  drawSunken( &p, palette(), frame, background(), hasFocus() ? focusColor() : QColor() );

  if( !_values.count() ) return;

  p.setRenderHint( QPainter::Antialiasing, false );

  bool horiz = ort == Qt::Horizontal;

  QRect bounds( contentsRect() );

  p.setClipRect( bounds );

  if( horiz ) {
    p.translate( bounds.topLeft() );
    p.rotate(90);
    p.scale(1.0, -1.0);
    bounds.setSize( QSize( bounds.height(), bounds.width() ) );
  }
  else {
    p.translate( bounds.left(), bounds.top() + bounds.height() );
    p.scale(1.0, -1.0);
  }

  int count = _values.count() - startIndex;
  double spacing, width, yscale;

  spacing = elastic ? (double) bounds.width() / count : thumbSize.width() + gap;
  width = elastic ? qMin( spacing, (double) thumbSize.width() ) : thumbSize.width();
  yscale = bounds.height();
  if( !isFilled ) yscale -= thumbSize.height();

  const QColor & fillClr = fillColor();

  // selection

  if( highlight ) {
    int i = _currentIndex - startIndex;
    int c = qMin( count - i, _selectionSize );
    if(c) {
      QRect r;
      r.setHeight( bounds.height() );
      r.setWidth( c * spacing );
      r.moveLeft( i * spacing );

      QColor hlColor = fillClr;
      hlColor.setAlpha( 70 );
      p.fillRect( r, hlColor );
    }
  }

  p.setPen( strokeColor() );

  // lines

  if( drawLines ) {
    bool fill = isFilled & !drawRects;

    p.save();

    p.setRenderHint( QPainter::Antialiasing, true );
    p.translate( spacing * 0.5, isFilled ? 0.0 : thumbSize.height() * 0.5 );
    p.scale( 1.0, (qreal) yscale );
    if( fill ) p.setBrush( fillClr );

    QPainterPath path;

    // value line

    path.moveTo( 0, _values[startIndex] );
    for( int i = 1; i < count; ++i )
      path.lineTo( (qreal) i * spacing, _values[i + startIndex] );

    // reference line

    int refcount = _ref.count() - startIndex;
    if( refcount > 0 || fill ) {
      qreal x, y;
      int i = count - 1;

      x = i * spacing;
      y = i < refcount ? _ref[i + startIndex] : 0.f;
      if( fill ) path.lineTo(x, y);
      else path.moveTo(x, y);

      while( --i >= 0 ) {
        x = i * spacing;
        y = i < refcount ? _ref[i + startIndex] : 0.f;
        path.lineTo(x, y);
      }

      if( fill ) path.closeSubpath();
    }

    p.drawPath( path );

    p.restore();
  }

  // rects

  if( drawRects ) {
    p.setRenderHint( QPainter::Antialiasing, false );
    p.translate( (spacing - width) * 0.5, 0 );
    p.setBrush( fillClr );

    QRectF r;
    r.setWidth( width );

    if( isFilled ) {
      int refcount = _ref.count() - startIndex;
      for( int i = 0; i < count; ++i ) {
        int ref = (i < refcount ? _ref[i + startIndex] : 0.f) * yscale;
        int val = _values[i + startIndex] * yscale;
        r.moveLeft( i * spacing );
        r.moveTop( ref );
        r.setHeight( val - ref );
        if(horiz) p.drawRect(r.normalized().adjusted(0,0,-1,-1));
        else p.drawRect(r.normalized().adjusted(0,1,-1,0));
      }
    }
    else {
      r.setHeight( thumbSize.height() );
      for( int i = 0; i < count; ++i ) {
        r.moveLeft( i * spacing );
        r.moveTop( _values[i + startIndex] * yscale );
        if(horiz) p.drawRect(r.adjusted(0,0,-1,-1));
        else p.drawRect(r.adjusted(0,1,-1,0));
      }
    }
  }
}
예제 #26
0
QRectF GraphicsMultiLineItem::boundingRect() const {
	QGraphicsPolygonItem dummy(myPoly);
	int extra = 5;
	QRectF rect = dummy.boundingRect();
	return rect.normalized().adjusted(-extra, -extra, extra, extra);
}
예제 #27
0
static inline QPainterPath headerPath( const QRectF& r, int roundness,
                                       int headerHeight = 10 )
{
    QPainterPath path;
    int xRnd = roundness;
    int yRnd = roundness;
    if( r.width() > r.height() )
    {
        xRnd = int ( roundness * r.height() / r.width() );
    }
    else
    {
        yRnd = int ( roundness * r.width() / r.height() );
    }

    if( xRnd >= 100 )                        // fix ranges
    {
        xRnd = 99;
    }
    if( yRnd >= 100 )
    {
        yRnd = 99;
    }
    if( xRnd <= 0 || yRnd <= 0 )             // add normal rectangle
    {
        path.addRect( r );
        return path;
    }

    QRectF rect = r.normalized();

    if( rect.isNull() )
    {
        return path;
    }

    qreal x = rect.x();
    qreal y = rect.y();
    qreal w = rect.width();
    qreal h = rect.height();
    qreal rxx = w * xRnd / 200;
    qreal ryy = h * yRnd / 200;
    // were there overflows?
    if( rxx < 0 )
    {
        rxx = w / 200 * xRnd;
    }
    if( ryy < 0 )
    {
        ryy = h / 200 * yRnd;
    }
    qreal rxx2 = 2 * rxx;
    qreal ryy2 = 2 * ryy;

    path.arcMoveTo( x, y, rxx2, ryy2, 90 );
    path.arcTo( x, y, rxx2, ryy2, 90, 90 );
    QPointF pt = path.currentPosition();
    path.lineTo( x, pt.y() + headerHeight );
    path.lineTo( x + w, pt.y() + headerHeight );
    path.lineTo( x + w, pt.y() );
    path.arcTo( x + w - rxx2, y, rxx2, ryy2, 0, 90 );
    path.closeSubpath();

    return path;
}