当前位置: 首页>>代码示例>>C++>>正文


C++ QRectF::setWidth方法代码示例

本文整理汇总了C++中QRectF::setWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ QRectF::setWidth方法的具体用法?C++ QRectF::setWidth怎么用?C++ QRectF::setWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QRectF的用法示例。


在下文中一共展示了QRectF::setWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: draw

void SimpleText::draw(QPainter* p) const
      {
      p->setFont(textStyle().fontPx(spatium()));
      p->setBrush(Qt::NoBrush);
      p->setPen(textColor());
      int rows = _layout.size();
      if (_editMode && _cursor.hasSelection()) {
            int r1 = _cursor.selectLine;
            int r2 = _cursor.line;
            int c1 = _cursor.selectColumn;
            int c2 = _cursor.column;

            if (r1 > r2) {
                  qSwap(r1, r2);
                  qSwap(c1, c2);
                  }
            else if (r1 == r2) {
                  if (c1 > c2)
                        qSwap(c1, c2);
                  }
            for (int row = 0; row < rows; ++row) {
                  const TLine& t = _layout.at(row);
                  p->drawText(t.pos, t.text);
                  if (row >= r1 && row <= r2) {
                        QBrush bg(QColor("steelblue"));
                        QFontMetricsF fm(_textStyle.fontPx(spatium()));
                        QRectF br;
                        if (row == r1 && r1 == r2) {
                              QString left  = t.text.left(c1);
                              QString mid   = t.text.mid(c1, c2 - c1);
                              QString right = t.text.mid(c2);

                              QPointF r (fm.width(left), 0.0);
                              br = fm.boundingRect(mid).translated(t.pos + r);
                              br.setWidth(fm.width(mid));
                              }
                        else if (row == r1) {
                              QString left  = t.text.left(c1);
                              QString right = t.text.mid(c1);

                              QPointF r (fm.width(left), 0.0);
                              br = fm.boundingRect(right).translated(t.pos + r);
                              br.setWidth(fm.width(right));
                              }
                        else if (row == r2) {
                              QString left  = t.text.left(c2);

                              br = fm.boundingRect(left).translated(t.pos);
                              br.setWidth(fm.width(left));
                              }
                        else  {
                              br = fm.boundingRect(t.text).translated(t.pos);
                              br.setWidth(fm.width(t.text));
                              }
                        drawSelection(p, br);
                        }
                  }
            }
      else {
            for (int row = 0; row < rows; ++row) {
                  const TLine& t = _layout.at(row);
                  p->drawText(t.pos, t.text);
                  }
            }

      if (_editMode) {
            p->setBrush(QColor("steelblue"));
            p->drawRect(cursorRect());
            }
      }
开发者ID:parinporecha,项目名称:MuseScore,代码行数:70,代码来源:simpletext.cpp

示例2: grabZone

Selection::GrabZone Selection::grabZone(QPointF pagePos, qreal zoom)
{
  GrabZone grabZone = GrabZone::None;
  QRectF bRect = m_selectionPolygon.boundingRect();
  QRectF moveRect = bRect;

  qreal scaled_ad = m_ad / zoom;

  QRectF topRect = bRect;
  topRect.setTop(topRect.top() - scaled_ad);
  topRect.setHeight(scaled_ad);

  QRectF bottomRect = bRect;
  bottomRect.setTop(bottomRect.bottom());
  bottomRect.setHeight(scaled_ad);

  QRectF leftRect = bRect;
  leftRect.setLeft(leftRect.left() - scaled_ad);
  leftRect.setWidth(scaled_ad);

  QRectF rightRect = bRect;
  rightRect.setLeft(rightRect.right());
  rightRect.setWidth(scaled_ad);

  QRectF topLeftRect = bRect;
  topLeftRect.setLeft(topLeftRect.left() - scaled_ad);
  topLeftRect.setTop(topLeftRect.top() - scaled_ad);
  topLeftRect.setWidth(scaled_ad);
  topLeftRect.setHeight(scaled_ad);

  QRectF topRightRect = bRect;
  topRightRect.setLeft(topRightRect.right());
  topRightRect.setTop(topRightRect.top() - scaled_ad);
  topRightRect.setWidth(scaled_ad);
  topRightRect.setHeight(scaled_ad);

  QRectF bottomLeftRect = bRect;
  bottomLeftRect.setLeft(bottomLeftRect.left() - scaled_ad);
  bottomLeftRect.setTop(bottomLeftRect.bottom());
  bottomLeftRect.setWidth(scaled_ad);
  bottomLeftRect.setHeight(scaled_ad);

  QRectF bottomRightRect = bRect;
  bottomRightRect.setLeft(bottomRightRect.right());
  bottomRightRect.setTop(bottomRightRect.bottom());
  bottomRightRect.setWidth(scaled_ad);
  bottomRightRect.setHeight(scaled_ad);

  QRectF rotateRect = bRect;
  rotateRect.setTop(rotateRect.top() - 1.0 * scaled_ad - (m_rotateRectCenter + m_rotateRectRadius) / zoom);
  rotateRect.setLeft(rotateRect.center().x() - m_rotateRectRadius / zoom);
  rotateRect.setWidth(2.0 * m_rotateRectRadius / zoom);
  rotateRect.setHeight(2.0 * m_rotateRectRadius / zoom);

  if (moveRect.contains(pagePos))
  {
    grabZone = GrabZone::Move;
  }
  else if (topRect.contains(pagePos))
  {
    grabZone = GrabZone::Top;
  }
  else if (bottomRect.contains(pagePos))
  {
    grabZone = GrabZone::Bottom;
  }
  else if (leftRect.contains(pagePos))
  {
    grabZone = GrabZone::Left;
  }
  else if (rightRect.contains(pagePos))
  {
    grabZone = GrabZone::Right;
  }
  else if (topLeftRect.contains(pagePos))
  {
    grabZone = GrabZone::TopLeft;
  }
  else if (topRightRect.contains(pagePos))
  {
    grabZone = GrabZone::TopRight;
  }
  else if (bottomLeftRect.contains(pagePos))
  {
    grabZone = GrabZone::BottomLeft;
  }
  else if (bottomRightRect.contains(pagePos))
  {
    grabZone = GrabZone::BottomRight;
  }
  else if (rotateRect.contains(pagePos))
  {
    grabZone = GrabZone::Rotate;
  }
  qInfo() << bRect;
  qInfo() << rotateRect;
  return grabZone;
}
开发者ID:nhoda,项目名称:MrWriter,代码行数:98,代码来源:selection.cpp

示例3: evalItemRect

QRectF QgsComposerItem::evalItemRect( const QRectF &newRect, const bool resizeOnly, const QgsExpressionContext* context )
{
  QRectF result = newRect;

  //TODO QGIS 3.0
  //maintain pre 2.12 API. remove when API break allowed
  QScopedPointer< QgsExpressionContext > scopedContext;
  const QgsExpressionContext* evalContext = context;
  if ( !evalContext )
  {
    scopedContext.reset( createExpressionContext() );
    evalContext = scopedContext.data();
  }

  //data defined position or size set? if so, update rect with data defined values
  QVariant exprVal;
  //evaulate width and height first, since they may affect position if non-top-left reference point set
  if ( dataDefinedEvaluate( QgsComposerObject::ItemWidth, exprVal, *evalContext ) )
  {
    bool ok;
    double width = exprVal.toDouble( &ok );
    QgsDebugMsg( QString( "exprVal Width:%1" ).arg( width ) );
    if ( ok && !exprVal.isNull() )
    {
      result.setWidth( width );
    }
  }
  if ( dataDefinedEvaluate( QgsComposerObject::ItemHeight, exprVal, *evalContext ) )
  {
    bool ok;
    double height = exprVal.toDouble( &ok );
    QgsDebugMsg( QString( "exprVal Height:%1" ).arg( height ) );
    if ( ok && !exprVal.isNull() )
    {
      result.setHeight( height );
    }
  }

  double x = result.left();
  //initially adjust for position mode to get x coordinate
  if ( !resizeOnly )
  {
    //adjust x-coordinate if placement is not done to a left point
    if ( mLastUsedPositionMode == UpperMiddle || mLastUsedPositionMode == Middle || mLastUsedPositionMode == LowerMiddle )
    {
      x += newRect.width() / 2.0;
    }
    else if ( mLastUsedPositionMode == UpperRight || mLastUsedPositionMode == MiddleRight || mLastUsedPositionMode == LowerRight )
    {
      x += newRect.width();
    }
  }
  else
  {
    if ( mLastUsedPositionMode == UpperMiddle || mLastUsedPositionMode == Middle || mLastUsedPositionMode == LowerMiddle )
    {
      x += rect().width() / 2.0;
    }
    else if ( mLastUsedPositionMode == UpperRight || mLastUsedPositionMode == MiddleRight || mLastUsedPositionMode == LowerRight )
    {
      x += rect().width();
    }
  }
  if ( dataDefinedEvaluate( QgsComposerObject::PositionX, exprVal, *evalContext ) )
  {
    bool ok;
    double positionX = exprVal.toDouble( &ok );
    QgsDebugMsg( QString( "exprVal Position X:%1" ).arg( positionX ) );
    if ( ok && !exprVal.isNull() )
    {
      x = positionX;
    }
  }

  double y = result.top();
  //initially adjust for position mode to get y coordinate
  if ( !resizeOnly )
  {
    //adjust y-coordinate if placement is not done to an upper point
    if ( mLastUsedPositionMode == MiddleLeft || mLastUsedPositionMode == Middle || mLastUsedPositionMode == MiddleRight )
    {
      y += newRect.height() / 2.0;
    }
    else if ( mLastUsedPositionMode == LowerLeft || mLastUsedPositionMode == LowerMiddle || mLastUsedPositionMode == LowerRight )
    {
      y += newRect.height();
    }
  }
  else
  {
    if ( mLastUsedPositionMode == MiddleLeft || mLastUsedPositionMode == Middle || mLastUsedPositionMode == MiddleRight )
    {
      y += rect().height() / 2.0;
    }
    else if ( mLastUsedPositionMode == LowerLeft || mLastUsedPositionMode == LowerMiddle || mLastUsedPositionMode == LowerRight )
    {
      y += rect().height();
    }
  }
  if ( dataDefinedEvaluate( QgsComposerObject::PositionY, exprVal, *evalContext ) )
//.........这里部分代码省略.........
开发者ID:NyakudyaA,项目名称:QGIS,代码行数:101,代码来源:qgscomposeritem.cpp

示例4: draw

/*!
  \brief Draw the raster data
  \param painter Painter
  \param xMap X-Scale Map
  \param yMap Y-Scale Map
  \param canvasRect Contents rectangle of the plot canvas
*/
void QwtPlotRasterItem::draw( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect ) const
{
    if ( canvasRect.isEmpty() || d_data->alpha == 0 )
        return;

    const bool doCache = qwtUseCache( d_data->cache.policy, painter );

    const QwtInterval xInterval = interval( Qt::XAxis );
    const QwtInterval yInterval = interval( Qt::YAxis );

    /*
        Scaling an image always results in a loss of
        precision/quality. So we always render the image in
        paint device resolution.
    */

    QwtScaleMap xxMap, yyMap;
    qwtTransformMaps( painter->transform(), xMap, yMap, xxMap, yyMap );

    QRectF paintRect = painter->transform().mapRect( canvasRect );
    QRectF area = QwtScaleMap::invTransform( xxMap, yyMap, paintRect );

    const QRectF br = boundingRect();
    if ( br.isValid() && !br.contains( area ) )
    {
        area &= br;
        if ( !area.isValid() )
            return;

        paintRect = QwtScaleMap::transform( xxMap, yyMap, area );
    }

    QRectF imageRect;
    QImage image;

    QRectF pixelRect = pixelHint(area);
    if ( !pixelRect.isEmpty() )
    {
        // one pixel of the target device in plot coordinates
        const double dx = qAbs( xxMap.invTransform( 1 ) - xxMap.invTransform( 0 ) );
        const double dy = qAbs( yyMap.invTransform( 1 ) - yyMap.invTransform( 0 ) );

        if ( dx > pixelRect.width() && dy > pixelRect.height() )
        {
            /*
              When the resolution of the data pixels is higher than
              the resolution of the target device we render in
              target device resolution.
             */
            pixelRect = QRectF();
        }
        else
        {
            /*
              If only one dimension is of the data pixel is higher
              we expand the pixel rect to the resolution of the target device.
             */

            if ( dx > pixelRect.width() )
                pixelRect.setWidth( dx );

            if ( dy > pixelRect.height() )
                pixelRect.setHeight( dy );
        }
    }

    if ( pixelRect.isEmpty() )
    {
        if ( QwtPainter::roundingAlignment( painter ) )
        {
            // we want to have maps, where the boundaries of
            // the aligned paint rectangle exactly match the area

            paintRect = qwtAlignRect(paintRect);
            qwtAdjustMaps(xxMap, yyMap, area, paintRect);
        }

        // When we have no information about position and size of
        // data pixels we render in resolution of the paint device.

        image = compose(xxMap, yyMap,
            area, paintRect, paintRect.size().toSize(), doCache);
        if ( image.isNull() )
            return;

        // Remove pixels at the boundaries, when explicitly
        // excluded in the intervals

        imageRect = qwtStripRect(paintRect, area,
            xxMap, yyMap, xInterval, yInterval);

//.........这里部分代码省略.........
开发者ID:svn2github,项目名称:Qwt_trunk,代码行数:101,代码来源:qwt_plot_rasteritem.cpp

示例5: SettingsElement

LaneSettings::LaneSettings(ProjectSettings *projectSettings, SettingsElement *parentSettingsElement, Lane *lane)
    : SettingsElement(projectSettings, parentSettingsElement, lane)
    , ui(new Ui::LaneSettings)
    , lane_(lane)
    , init_(false)
    , roadSystemItemPolyGraph_(NULL)
    , insertWidthSectionHandle_(NULL)
    , lswItem_(NULL)
{
    ui->setupUi(this);

	activateWidthGroupBox(false);
	activateInsertGroupBox(false);
	connect(ui->insertPushButton, SIGNAL(clicked(bool)), this, SLOT(activateInsertGroupBox(bool)));
	connect(ui->editPushButton, SIGNAL(clicked(bool)), this, SLOT(activateWidthGroupBox(bool)));

    // List //
    //
    QStringList typeNames;
    typeNames << Lane::parseLaneTypeBack(Lane::LT_NONE)
              << Lane::parseLaneTypeBack(Lane::LT_DRIVING)
              << Lane::parseLaneTypeBack(Lane::LT_STOP)
              << Lane::parseLaneTypeBack(Lane::LT_SHOULDER)
              << Lane::parseLaneTypeBack(Lane::LT_BIKING)
              << Lane::parseLaneTypeBack(Lane::LT_SIDEWALK)
              << Lane::parseLaneTypeBack(Lane::LT_BORDER)
              << Lane::parseLaneTypeBack(Lane::LT_RESTRICTED)
              << Lane::parseLaneTypeBack(Lane::LT_PARKING)
              << Lane::parseLaneTypeBack(Lane::LT_MWYENTRY)
              << Lane::parseLaneTypeBack(Lane::LT_MWYEXIT)
              << Lane::parseLaneTypeBack(Lane::LT_SPECIAL1)
              << Lane::parseLaneTypeBack(Lane::LT_SPECIAL2)
              << Lane::parseLaneTypeBack(Lane::LT_SPECIAL3);
    ui->typeBox->addItems(typeNames);

    /*heightGraph_ = new ProfileGraph(projectSettings->getProjectWidget(), projectSettings->getProjectData());
	heightGraph_->setParent(ui->widthGroup);
	ui->horizontalLayout_3->insertWidget(0,heightGraph_);
	//heightGraph_->getView()->setDragMode(QGraphicsView::ScrollHandDrag);
	//QGraphicsScene* pScene = new NoDeselectScene(this); 
    //heightGraph_->getView()->setScene(pScene);
	heightGraph_->getScene()->doDeselect(false);// we don't want to deselect ourselves if we click on the background, otherwise we delete ourselves--> chrash and it would not be practical anyway
	*/

    heightGraph_ = projectSettings->getProjectWidget()->getHeightGraph();

    laneEditor_ = dynamic_cast<LaneEditor *>(projectSettings->getProjectWidget()->getProjectEditor());
    if (!laneEditor_)
    {
        return; // another editor is active
    }

    roadSystemItemPolyGraph_ = new LaneWidthRoadSystemItem(heightGraph_, projectSettings->getProjectData()->getRoadSystem());
    heightGraph_->getScene()->addItem(roadSystemItemPolyGraph_);

    // Section Handle //
    //
    //insertWidthSectionHandle_ = new SectionHandle(roadSystemItemPolyGraph_);
    //insertWidthSectionHandle_->hide();
    roadSystemItemPolyGraph_->setSettings(this);
    roadSystemItemPolyGraph_->setAcceptHoverEvents(true);
    // Activate Road in ProfileGraph //
    //
    lswItem_ = new LaneSectionWidthItem(roadSystemItemPolyGraph_, lane_);
    //selectedElevationRoadItems_.insert(road, roadItem);

    // Fit View //
    //
    QRectF boundingBox = lswItem_->boundingRect();
    if (boundingBox.width() < 15.0)
    {
        boundingBox.setWidth(15.0);
    }
    if (boundingBox.height() < 10.0)
    {
        boundingBox.setHeight(10.0);
    }

    heightGraph_->getView()->fitInView(boundingBox);
    heightGraph_->getView()->zoomOut(Qt::Horizontal | Qt::Vertical);

    //ui->horizontalLayout_3->insertWidget(0,heightGraph_);
    //heightGraph_->show();
    // Initial Values //
    //
    updateId();
    updateType();
    updateLevel();
    updatePredecessor();
    updateSuccessor();
    updateWidth();

    // Done //
    //
    init_ = true;
}
开发者ID:dwickeroth,项目名称:covise,代码行数:96,代码来源:lanesettings.cpp

示例6: calculatePopupRects

/*
    Calculates the rects for the popup text and background.

    Does nothing if the rect is the same as the last time it was called.
*/
void HbIndexFeedbackPrivate::calculatePopupRects()
{
    Q_Q( HbIndexFeedback );

    if (!mItemView) {
        return;
    }

    QRectF contentRect = mItemView->mapToItem(q, mItemView->rect()).boundingRect();
    
    HbScrollBar *verticalScrollBar = mItemView->verticalScrollBar();
    HbScrollBar *horizontalScrollBar = mItemView->horizontalScrollBar();
    if (verticalScrollBar->isInteractive()) {
        contentRect.setWidth( contentRect.width() - verticalScrollBar->rect().width() );
        if (HbApplication::layoutDirection() == Qt::RightToLeft) {
            contentRect.setLeft( contentRect.left() + verticalScrollBar->rect().width() );
        }
    }
    
    if (horizontalScrollBar->isInteractive()) {
        contentRect.setHeight( contentRect.height() - horizontalScrollBar->rect().height() );
    }

    if (contentRect == mItemViewContentsRect) {
        return;
    }

    qreal margin = 0;
    q->style()->parameter(QLatin1String("hb-param-margin-gene-popup"), margin);

    QSizeF backgroundSize;
    QSizeF textSize;

    switch (mIndexFeedbackPolicy) {
        case HbIndexFeedback::IndexFeedbackSingleCharacter:
        case HbIndexFeedback::IndexFeedbackThreeCharacter:
            {
                textSize.setHeight( textHeight() );
                textSize.setWidth ( textWidth() );

                backgroundSize.setHeight( textSize.height() + 2 * margin );
                backgroundSize.setWidth ( textSize.width() + 2 * margin );

                mPopupBackgroundRect.setLeft( contentRect.left() + (contentRect.width() -
                    backgroundSize.width()) / 2.0 );
                mPopupBackgroundRect.setTop ( contentRect.top() + (contentRect.height() - 
                    backgroundSize.height()) / 2.0 );

                mPopupTextRect.setLeft( mPopupBackgroundRect.left() + margin );
                mPopupTextRect.setTop ( mPopupBackgroundRect.top()  + margin );

                mPopupBackgroundRect.setSize(backgroundSize);
                mPopupTextRect.setSize(textSize);
            }
            break;

        case HbIndexFeedback::IndexFeedbackString:
            {
                textSize.setHeight( textHeight() );
                backgroundSize.setHeight( textSize.height() + 2 * margin );

                backgroundSize.setWidth( contentRect.width() - 2 * mStringOffset );
                textSize.setWidth( backgroundSize.width() - 2 * margin );

                mPopupBackgroundRect.setLeft( contentRect.left() + mStringOffset );
                mPopupBackgroundRect.setTop( contentRect.top() + (contentRect.height() - 
                    backgroundSize.height()) / 2.0 );

                mPopupTextRect.setLeft( mPopupBackgroundRect.left() + margin );
                mPopupTextRect.setTop ( mPopupBackgroundRect.top() + margin );

                mPopupBackgroundRect.setSize(backgroundSize);
                mPopupTextRect.setSize(textSize);
            }
            break;

        case HbIndexFeedback::IndexFeedbackNone:
            {
                mPopupTextRect = QRectF();
                mPopupBackgroundRect = QRectF();
            }
            break;
    }
}
开发者ID:kuailexs,项目名称:symbiandump-mw1,代码行数:89,代码来源:hbindexfeedback_p.cpp

示例7: paintEvent

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;
  qreal spacing, width, yscale;

  spacing = elastic ? (qreal) bounds.width() / count : thumbSize.width() + gap;
  width = elastic ? qMin( spacing, (qreal) 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 );
    }
  }

  QPen pen;
  pen.setColor(strokeColor());
  pen.setWidth(0);
  p.setPen(pen);

  // 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;
//.........这里部分代码省略.........
开发者ID:ARTisERR0R,项目名称:supercollider,代码行数:101,代码来源:QcMultiSlider.cpp

示例8: paint

void GridFitting::paint(QPainter * painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
    Axis t(0, ylabel->getNpoints(), 0, xlabel->getNpoints());
    axis = t;
    if (!cw) {
        cw = widget->rect().width();
    }
    if (!ch) {
        ch = widget->rect().height();
    }
    painter->setFont(*textFont);
    painter->fillRect(widget->rect(), background);
    double w1 = 0, h1 = 0;
    offset = 30;
    w1 = offset;

    if (widget->rect().width() != w) {
        if (w) {
            rW = (double) (cw / widget->rect().width());
        } else {
            rW = 1;
        }
    }
    if (widget->rect().height() != h) {
        if (h) {
            rH = (double) (ch / widget->rect().height());
        } else {
            rH = 1;
        }
    }
    w = widget->rect().width();
    h = widget->rect().height();
    h1 = h - offset;
    painter->drawLine(QLineF(QPointF(0, h1), QPointF(w, h1)));
    painter->drawLine(QLineF(QPointF(offset, 0), QPointF(offset, h)));

    w1 = w - offset;
    h1 = h - offset;
    int k = 1, k1 = 1;


    Xintervalsw = w1 / axis.x;
    double stepx =rW * sX*Xintervalsw;
    double ticksw = tX*stepx;
    for (double i = 0; i < w; i += Xintervalsw) {
        QLineF a;
        if (i >= k * (ticksw)) {
            a.setPoints(QPointF(offset + i, h1), QPointF(offset + i, h1 - offset / 5));
            QRectF text;
            text.setX(offset + i - ticksw / 2);
            text.setY(h1);
            text.setWidth(ticksw);
            text.setHeight(20);
            QTextOption fmt(Qt::AlignTop | Qt::AlignCenter);
            double t = i / Xintervalsw;
            painter->drawText(text, QString::number(xlabel->getElement(t-1), 10, 2), fmt);
            k++;
            k1++;
            painter->drawLine(a);
        } else if (i >= k1 * stepx) {
            a.setPoints(QPointF(i + offset, h1), QPointF(i + offset, h1 - offset / 10));
            painter->drawLine(a);
            k1++;
        }
    }
    k = 1;
    k1 = 1;
    Yintervalsh = h1 / axis.y;
    ZeroPoint = axis.Hy*Yintervalsh;
    double stepy = rH * sY*Yintervalsh;
    double ticksh = tY*stepy;
    for (double i = 0,j=0; i < h1; i += Yintervalsh,j++) {
        QLineF a;
        if (i >= (k * ticksh)) {
            a.setPoints(QPointF(offset, i), QPointF(offset + offset / 5, i));
            QRectF text;
            text.setX(0);
            text.setY(i - ticksh / 2);
            text.setWidth(offset);
            QTextOption fmt(Qt::AlignHCenter | Qt::AlignCenter);
            text.setHeight(ticksh);
            QString str = QString::number(ylabel->getElement(i / Yintervalsh-1), 10, 2);
            painter->drawText(text, str, fmt);
            k++;
            k1++;
            painter->drawLine(a);
        } else if (i >= k1 * stepy) {
            a.setPoints(QPointF(offset, i), QPointF(offset + offset / 10, i));
            painter->drawLine(a);
            k1++;
        }
    }
        if (isGridOn()) {
            painter->setPen(gridpen);
            k = 1;
            for (float i = 0; i < axis.y; i++) {
                QLineF a;
                if (i >= k * sY * tY) {
                    a.setPoints(QPointF(offset, i * Yintervalsh), QPointF(w, i * Yintervalsh));
                    painter->drawLine(a);
                    k++;
//.........这里部分代码省略.........
开发者ID:FernandoDucha,项目名称:punyPast,代码行数:101,代码来源:GridFitting.cpp

示例9: evalItemRect

QRectF QgsComposerItem::evalItemRect( const QRectF &newRect, const bool resizeOnly, const QgsExpressionContext *context )
{
  QRectF result = newRect;

  //TODO QGIS 3.0
  //maintain pre 2.12 API. remove when API break allowed
  QgsExpressionContext scopedContext = createExpressionContext();
  const QgsExpressionContext *evalContext = context ? context : &scopedContext;

  //data defined position or size set? if so, update rect with data defined values
  bool ok = false;
  double ddWidth = mDataDefinedProperties.valueAsDouble( QgsComposerObject::ItemWidth, *evalContext, 0, &ok );
  //evaulate width and height first, since they may affect position if non-top-left reference point set
  if ( ok )
  {
    result.setWidth( ddWidth );
  }
  double ddHeight = mDataDefinedProperties.valueAsDouble( QgsComposerObject::ItemHeight, *evalContext, 0, &ok );
  if ( ok )
  {
    result.setHeight( ddHeight );
  }

  double x = result.left();
  //initially adjust for position mode to get x coordinate
  if ( !resizeOnly )
  {
    //adjust x-coordinate if placement is not done to a left point
    if ( mLastUsedPositionMode == UpperMiddle || mLastUsedPositionMode == Middle || mLastUsedPositionMode == LowerMiddle )
    {
      x += newRect.width() / 2.0;
    }
    else if ( mLastUsedPositionMode == UpperRight || mLastUsedPositionMode == MiddleRight || mLastUsedPositionMode == LowerRight )
    {
      x += newRect.width();
    }
  }
  else
  {
    if ( mLastUsedPositionMode == UpperMiddle || mLastUsedPositionMode == Middle || mLastUsedPositionMode == LowerMiddle )
    {
      x += rect().width() / 2.0;
    }
    else if ( mLastUsedPositionMode == UpperRight || mLastUsedPositionMode == MiddleRight || mLastUsedPositionMode == LowerRight )
    {
      x += rect().width();
    }
  }
  double ddPosX = mDataDefinedProperties.valueAsDouble( QgsComposerObject::PositionX, *evalContext, 0.0, &ok );
  if ( ok )
  {
    x = ddPosX;
  }

  double y = result.top();
  //initially adjust for position mode to get y coordinate
  if ( !resizeOnly )
  {
    //adjust y-coordinate if placement is not done to an upper point
    if ( mLastUsedPositionMode == MiddleLeft || mLastUsedPositionMode == Middle || mLastUsedPositionMode == MiddleRight )
    {
      y += newRect.height() / 2.0;
    }
    else if ( mLastUsedPositionMode == LowerLeft || mLastUsedPositionMode == LowerMiddle || mLastUsedPositionMode == LowerRight )
    {
      y += newRect.height();
    }
  }
  else
  {
    if ( mLastUsedPositionMode == MiddleLeft || mLastUsedPositionMode == Middle || mLastUsedPositionMode == MiddleRight )
    {
      y += rect().height() / 2.0;
    }
    else if ( mLastUsedPositionMode == LowerLeft || mLastUsedPositionMode == LowerMiddle || mLastUsedPositionMode == LowerRight )
    {
      y += rect().height();
    }
  }
  double ddPosY = mDataDefinedProperties.valueAsDouble( QgsComposerObject::PositionY, *evalContext, 0, &ok );
  if ( ok )
  {
    y = ddPosY;
  }

  //adjust x-coordinate if placement is not done to a left point
  if ( mLastUsedPositionMode == UpperMiddle || mLastUsedPositionMode == Middle || mLastUsedPositionMode == LowerMiddle )
  {
    x -= result.width() / 2.0;
  }
  else if ( mLastUsedPositionMode == UpperRight || mLastUsedPositionMode == MiddleRight || mLastUsedPositionMode == LowerRight )
  {
    x -= result.width();
  }

  //adjust y-coordinate if placement is not done to an upper point
  if ( mLastUsedPositionMode == MiddleLeft || mLastUsedPositionMode == Middle || mLastUsedPositionMode == MiddleRight )
  {
    y -= result.height() / 2.0;
  }
//.........这里部分代码省略.........
开发者ID:GeoCat,项目名称:QGIS,代码行数:101,代码来源:qgscomposeritem.cpp

示例10: render

    void GraphAggRenderer::render(QImage *image1, QRectF clip, 
            agg::trans_affine *t)
    {
        agg::trans_affine transform = *t;

        QImage &image = *image1;
        agg::rendering_buffer rbuf(image.bits(),
                image.width(), 
                image.height(), 
                image.width() * 4);

        agg::pixfmt_bgra32 pixf(rbuf);

        ren_base ren(pixf);
        renderer_solid r(ren);
        ren.clear(agg::rgba(1, 1, 1));

        scanline_type sl;
        agg::rasterizer_scanline_aa<> ras;

        clip.setX(-500);
        clip.setY(-500);
        clip.setWidth(1000);
        clip.setHeight(1000);
        qDebug() << "clip: box " << clip;

        agg::path_storage clip_ps;
        clip_ps.move_to(clip.x(), clip.y());
        clip_ps.line_to(clip.x() + clip.width(), clip.y());
        clip_ps.line_to(clip.x() + clip.width(), clip.y() + clip.height());
        clip_ps.line_to(clip.x(), clip.y() + clip.height());
        //clip_ps.line_to(clip.x(), clip.y());
        clip_ps.close_polygon();

        agg::path_storage &ps = m_data->ps;

        for (unsigned i = 0; i < m_data->as.size(); ++i) {
            const path_attributes &attr = m_data->as[i];
            if (attr.fill_flag) {
                //qDebug() << "++attr.fill_flag";
                ras.reset();

                agg::conv_contour<agg::path_storage> cc(ps);
                agg::conv_transform
                    < agg::conv_contour 
                    < agg::path_storage > > ct(cc, transform);

                agg::conv_gpc< 
                    agg::conv_transform < 
                    agg::conv_contour < 
                    agg::path_storage > >,
                    agg::path_storage> gpc(ct, clip_ps);
                gpc.operation(agg::gpc_and);

                //ras.add_path(ct, attr.index);
                ras.add_path(gpc, attr.index);

                r.color(attr.fill_color);
                agg::render_scanlines(ras, sl, r);
            } else if (attr.stroke_flag) {
                ras.reset();

                typedef conv_curve<path_storage> curved;
                typedef conv_stroke<curved> curved_stroked;
                typedef conv_transform<curved_stroked> curved_stroked_trans;

                agg::conv_stroke<agg::path_storage> pg(ps);
                agg::conv_transform< agg::conv_stroke < agg::path_storage >
                    > ct(pg, transform);

                agg::conv_gpc<agg::path_storage,
                    agg::path_storage> gpc(clip_ps, ps);
                /*
                agg::conv_gpc< 
                    agg::conv_transform < 
                    agg::conv_stroke < 
                    agg::path_storage > >,
                    agg::path_storage> gpc(ct, clip_ps);
                    */
                gpc.operation(agg::gpc_or);
                //gpc.operation(agg::gpc_and);

                qDebug() << attr.index;
                pg.width(attr.stroke_width);
                //ras.add_path(ct, attr.index);
                //ras.add_path(gpc, attr.index);

                ras.reset();
                gpc.rewind(attr.index);
                double x;
                double y;
                unsigned cmd;
                while(!agg::is_stop(cmd = gpc.vertex(&x, &y))) {
                    ras.add_vertex(x, y, cmd);
                    qDebug() << "++";
                }
                //ras.reset();
                //ras.add_path(clip_ps);
                //ras.add_path(ps, attr.index);

//.........这里部分代码省略.........
开发者ID:ongbe,项目名称:xchart,代码行数:101,代码来源:graph_agg_renderer1.cpp

示例11: slotMouseMove

void KUnitItem::slotMouseMove(QGraphicsSceneMouseEvent *event)
{
    if (myMode == MouseMode_RESIZE)
    {
        QPointF curPoint(event->scenePos());
        QPointF curPointItem = this->mapFromScene(curPoint);

        bool flagx = lastPoint.x() > oppositePos.x();
        bool flagx1 = curPointItem.x() > oppositePos.x();
        bool flagy = lastPoint.y() > oppositePos.y();
        bool flagy1 = curPointItem.y() > oppositePos.y();


        qreal dist = 0;

        QRectF rectf;
        rectf.setRect(m_frame.x()
                      , m_frame.y()
                      , m_frame.width()
                      , m_frame.height());


        KResizeFocus::PosInHost pos = curResizeFocus->getInHost();
        if (pos == KResizeFocus::NORTH_MIDDLE)
        {
            QPointF br = dashRect->rect().bottomRight();
            dist = Util::GetPointDistLine(oppositePos,br,curPointItem);

            if (dist < 20 || flagy != flagy1)
            {
                if (flagy)
                {
                    curPointItem.setY(oppositePos.y() + 20);
                }
                else
                {
                    curPointItem.setY(oppositePos.y() - 20);
                }
                dist = 20;
            }
            rectf.setY(curPointItem.y());
            rectf.setHeight(dist);
        }
        else if(pos == KResizeFocus::SOUTH_MIDDLE)
        {
            QPointF br = dashRect->rect().topRight();
            dist = Util::GetPointDistLine(oppositePos,br,curPointItem);

            if (dist < 20 || flagy != flagy1)
            {
                if (flagy)
                {
                    curPointItem.setY(oppositePos.y() + 20);
                }
                else
                {
                    curPointItem.setY(oppositePos.y() - 20);
                }
                dist = 20;
            }
            rectf.setHeight(dist);
        }
        else if(pos == KResizeFocus::EAST_MIDDLE)
        {
            QPointF br = dashRect->rect().bottomLeft();
            dist = Util::GetPointDistLine(oppositePos,br,curPointItem);

            if (dist < 20 || flagx != flagx1)
            {
                if (flagx)
                {
                    curPointItem.setX(oppositePos.x() + 20);
                }
                else
                {
                    curPointItem.setX(oppositePos.x() - 20);
                }
                dist = 20;
            }
            rectf.setWidth(dist);
        }
        else if(pos == KResizeFocus::WEST_MIDDLE)
        {
            QPointF br = dashRect->rect().bottomRight();
            dist = Util::GetPointDistLine(oppositePos,br,curPointItem);

            if (dist < 20 || flagx != flagx1)
            {
                if (flagx)
                {
                    curPointItem.setX(oppositePos.x() + 20);
                }
                else
                {
                    curPointItem.setX(oppositePos.x() - 20);
                }
                dist = 20;
            }
            rectf.setX(curPointItem.x());
            rectf.setWidth(dist);
//.........这里部分代码省略.........
开发者ID:leiyongmmc,项目名称:ElectricStudio1.0,代码行数:101,代码来源:kunititem.cpp

示例12: paintEvent

void BaseEditor::paintEvent(QPaintEvent *e)
{
    //copy from QPlainTextEditor
    QPainter painter(viewport());
    Q_ASSERT(qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout()));

    QPointF offset(contentOffset());

    QRect er = e->rect();
    QRect viewportRect = viewport()->rect();

    bool editable = !isReadOnly();

    QTextBlock block = firstVisibleBlock();
    qreal maximumWidth = document()->documentLayout()->documentSize().width();

    //margin
    qreal lineX = 0;
    if (conf->isDisplayRightColumnMargin()) {
        // Don't use QFontMetricsF::averageCharWidth here, due to it returning
        // a fractional size even when this is not supported by the platform.
        lineX = QFontMetricsF(document()->defaultFont()).width(QLatin1Char('X')) * conf->getRightMarginColumn() + offset.x() + 4;

        if (lineX < viewportRect.width()) {
            const QBrush background = QBrush(QColor(239, 239, 239));
            painter.fillRect(QRectF(lineX, er.top(), viewportRect.width() - lineX, er.height()),
                             background);

            const QColor col = (palette().base().color().value() > 128) ? Qt::black : Qt::white;
            const QPen pen = painter.pen();
            painter.setPen(blendColors(background.isOpaque() ? background.color() : palette().base().color(),
                                       col, 32));
            painter.drawLine(QPointF(lineX, er.top()), QPointF(lineX, er.bottom()));
            painter.setPen(pen);
        }
    }

    // Set a brush origin so that the WaveUnderline knows where the wave started
    painter.setBrushOrigin(offset);

    // keep right margin clean from full-width selection
    int maxX = offset.x() + qMax((qreal)viewportRect.width(), maximumWidth)
               - document()->documentMargin();
    er.setRight(qMin(er.right(), maxX));
    painter.setClipRect(er);


    QAbstractTextDocumentLayout::PaintContext context = getPaintContext();

    while (block.isValid()) {

        QRectF r = blockBoundingRect(block).translated(offset);
        QTextLayout *layout = block.layout();

        if (!block.isVisible()) {
            offset.ry() += r.height();
            block = block.next();
            continue;
        }

        if (r.bottom() >= er.top() && r.top() <= er.bottom()) {

            QTextBlockFormat blockFormat = block.blockFormat();

            QBrush bg = blockFormat.background();
            if (bg != Qt::NoBrush) {
                QRectF contentsRect = r;
                contentsRect.setWidth(qMax(r.width(), maximumWidth));
                fillBackground(&painter, contentsRect, bg);
            }


            QVector<QTextLayout::FormatRange> selections;
            int blpos = block.position();
            int bllen = block.length();
            for (int i = 0; i < context.selections.size(); ++i) {
                const QAbstractTextDocumentLayout::Selection &range = context.selections.at(i);
                const int selStart = range.cursor.selectionStart() - blpos;
                const int selEnd = range.cursor.selectionEnd() - blpos;
                if (selStart < bllen && selEnd > 0
                    && selEnd > selStart) {
                    QTextLayout::FormatRange o;
                    o.start = selStart;
                    o.length = selEnd - selStart;
                    o.format = range.format;
                    selections.append(o);
                } else if (!range.cursor.hasSelection() && range.format.hasProperty(QTextFormat::FullWidthSelection)
                           && block.contains(range.cursor.position())) {
                    // for full width selections we don't require an actual selection, just
                    // a position to specify the line. that's more convenience in usage.
                    QTextLayout::FormatRange o;
                    QTextLine l = layout->lineForTextPosition(range.cursor.position() - blpos);
                    o.start = l.textStart();
                    o.length = l.textLength();
                    if (o.start + o.length == bllen - 1)
                        ++o.length; // include newline
                    o.format = range.format;
                    selections.append(o);
                }
            }
//.........这里部分代码省略.........
开发者ID:3rdpaw,项目名称:MdCharm,代码行数:101,代码来源:baseeditor.cpp

示例13: drawTeamSpace

void FieldView::drawTeamSpace(QPainter& p) {
    // Get the latest LogFrame
    const LogFrame* frame = _history->at(0).get();

    if (showTeamNames) {
        // Draw Team Names
        QFont savedFont = p.font();
        QFont fontstyle = p.font();
        fontstyle.setPointSize(20);
        p.setFont(fontstyle);
        p.setPen(bluePen);
        drawText(p, QPointF(0, 4.75), QString(frame->team_name_blue().c_str()),
                 true);  // Blue
        p.setPen(yellowPen);
        drawText(p, QPointF(0, 1.75),
                 QString(frame->team_name_yellow().c_str()),
                 true);  // Yellow
        p.setFont(savedFont);
    }

    // Block off half the field
    if (!frame->use_our_half()) {
        const float FX = Field_Dimensions::Current_Dimensions.FloorWidth() / 2;
        const float FY1 = -Field_Dimensions::Current_Dimensions.Border();
        const float FY2 = Field_Dimensions::Current_Dimensions.Length() / 2;
        p.fillRect(QRectF(QPointF(-FX, FY1), QPointF(FX, FY2)),
                   QColor(0, 0, 0, 128));
    }
    if (!frame->use_opponent_half()) {
        const float FX = Field_Dimensions::Current_Dimensions.FloorWidth() / 2;
        const float FY1 = Field_Dimensions::Current_Dimensions.Length() / 2;
        const float FY2 = Field_Dimensions::Current_Dimensions.Length() +
                          Field_Dimensions::Current_Dimensions.Border();
        p.fillRect(QRectF(QPointF(-FX, FY1), QPointF(FX, FY2)),
                   QColor(0, 0, 0, 128));
    }

    if (showCoords) {
        drawCoords(p);
    }

    // History
    p.setBrush(Qt::NoBrush);
    QPainterPath ballTrail;
    for (unsigned int i = 0; i < 200 && i < _history->size(); ++i) {
        const LogFrame* oldFrame = _history->at(i).get();
        if (oldFrame && oldFrame->has_ball()) {
            QPointF pos = qpointf(oldFrame->ball().pos());

            if (i == 0)
                ballTrail.moveTo(pos);
            else
                ballTrail.lineTo(pos);
        }
    }
    QPen ballTrailPen(ballColor, 0.03);
    ballTrailPen.setCapStyle(Qt::RoundCap);
    p.setPen(ballTrailPen);
    p.drawPath(ballTrail);

    // Debug lines
    for (const DebugPath& path : frame->debug_paths()) {
        if (path.layer() < 0 || layerVisible(path.layer())) {
            tempPen.setColor(qcolor(path.color()));
            p.setPen(tempPen);
            std::vector<QPointF> pts;
            for (int i = 0; i < path.points_size(); ++i) {
                pts.push_back(qpointf(path.points(i)));
            }
            p.drawPolyline(pts.data(), pts.size());
        }
    }

    for (const DebugRobotPath& path : frame->debug_robot_paths()) {
        if (path.layer() < 0 || layerVisible(path.layer())) {
            for (int i = 0; i < path.points_size() - 1; ++i) {
                const DebugRobotPath::DebugRobotPathPoint& from =
                    path.points(i);
                const DebugRobotPath::DebugRobotPathPoint& to =
                    path.points(i + 1);

                Geometry2d::Point avgVel =
                    (Geometry2d::Point(path.points(i).vel()) +
                     Geometry2d::Point(path.points(i + 1).vel())) /
                    2;
                float pcntMaxSpd =
                    avgVel.mag() / MotionConstraints::defaultMaxSpeed();
                QColor mixedColor(std::min((int)(255 * pcntMaxSpd), 255), 0,
                                  std::min((int)(255 * (1 - pcntMaxSpd)), 255));
                QPen pen(mixedColor);
                pen.setCapStyle(Qt::RoundCap);
                pen.setWidthF(0.03);
                p.setPen(pen);

                const Geometry2d::Point fromPos = Geometry2d::Point(from.pos());
                const Geometry2d::Point toPos = Geometry2d::Point(to.pos());
                p.drawLine(fromPos.toQPointF(), toPos.toQPointF());
            }
        }
    }
//.........这里部分代码省略.........
开发者ID:idaohang,项目名称:PVA-robocup-software,代码行数:101,代码来源:FieldView.cpp

示例14: drawSlices

void QwtPieCurve::drawSlices(QPainter *painter, const QwtScaleMap &xMap,
                             const QwtScaleMap &yMap, int from, int to) const {
  const double x_width = fabs(xMap.p1() - xMap.p2());
  const double x_center =
      (xMap.p1() + xMap.p2()) * 0.5 + d_horizontal_offset * 0.01 * x_width;
  const double y_center = (yMap.p1() + yMap.p2()) * 0.5;
  const double ray_x =
      d_pie_ray * 0.005 * qMin(x_width, fabs(yMap.p1() - yMap.p2()));
  const double view_angle_rad = d_view_angle * M_PI / 180.0;
  const double ray_y = ray_x * sin(view_angle_rad);
  const double thick = 0.01 * d_thickness * ray_x * cos(view_angle_rad);

  QRectF pieRect;
  pieRect.setX(x_center - ray_x);
  pieRect.setY(y_center - ray_y);
  pieRect.setWidth(2 * ray_x);
  pieRect.setHeight(2 * ray_y);

  QRectF pieRect2 = pieRect;
  pieRect2.translate(0, thick);

  double sum = 0.0;
  for (int i = from; i <= to; i++)
    sum += y(i);

  const int sign = d_counter_clockwise ? 1 : -1;

  const int size = dataSize();
  double *start_angle = new double[size];
  double *end_angle = new double[size];
  double aux_angle = d_start_azimuth;
  for (int i = from; i <= to; i++) {
    double a = -sign * y(i) / sum * 360.0;
    start_angle[i] = aux_angle;

    double end = aux_angle + a;
    if (end >= 360)
      end -= 360;
    else if (end < 0)
      end += 360;

    end_angle[i] = end;
    aux_angle = end;
  }

  int angle = (int)(5760 * d_start_azimuth / 360.0);
  if (d_counter_clockwise)
    angle = (int)(5760 * (1 - d_start_azimuth / 360.0));

  painter->save();

  QLocale locale = (static_cast<Plot *>(plot()))->locale();
  for (int i = from; i <= to; i++) {
    const double yi = y(i);
    const double q = yi / sum;
    const int value = (int)(q * 5760);

    painter->setPen(QwtPlotCurve::pen());
    painter->setBrush(QBrush(color(i), QwtPlotCurve::brush().style()));

    double deg = q * 360;
    double start_3D_view_angle = start_angle[i];
    double end_3D_view_angle = end_angle[i];
    if (d_counter_clockwise) {
      start_3D_view_angle = end_angle[i];
      end_3D_view_angle = start_angle[i];
    }

    bool draw3D = false;
    if (deg <= 180 && start_3D_view_angle >= 0 && start_3D_view_angle < 180) {
      if ((end_3D_view_angle > 180 &&
           end_3D_view_angle > start_3D_view_angle)) {
        deg = 180 - start_3D_view_angle;
        end_3D_view_angle = 180.0;
      }
      draw3D = true;
    } else if (start_3D_view_angle >= 180 &&
               end_3D_view_angle < start_3D_view_angle) {
      if (end_3D_view_angle > 180)
        end_3D_view_angle = 180;
      deg = end_3D_view_angle;
      start_3D_view_angle = 0;
      draw3D = true;
    } else if (deg > 180 && start_3D_view_angle >= 180) {
      deg = 180;
      end_3D_view_angle = 180;
      start_3D_view_angle = 0;
      draw3D = true;
    }

    if (draw3D) {
      double rad = start_3D_view_angle / 180.0 * M_PI;
      QPointF start(x_center + ray_x * cos(rad), y_center + ray_y * sin(rad));
      QPainterPath path(start);
      path.lineTo(start.x(), start.y() + thick);
      path.arcTo(pieRect2, -start_3D_view_angle, -deg);
      QPointF aux = path.currentPosition();
      path.lineTo(aux.x(), aux.y() - thick);
      path.arcTo(pieRect, -end_3D_view_angle, deg);
      painter->drawPath(path);
//.........这里部分代码省略.........
开发者ID:liyulun,项目名称:mantid,代码行数:101,代码来源:QwtPieCurve.cpp

示例15: iconPos

void
CollectionTreeItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option,
                                   const QModelIndex &index ) const
{
    if( index.parent().isValid() ) // not a root item
    {
        QStyledItemDelegate::paint( painter, option, index );
        return;
    }

    const bool isRTL = QApplication::isRightToLeft();
    const QPoint topLeft = option.rect.topLeft();
    const int width = m_view->viewport()->size().width() - 4;
    const int height = sizeHint( option, index ).height();
    const int iconWidth = 32;
    const int iconHeight = 32;
    const int iconPadX = 4;
    const bool hasCapacity = index.data( CustomRoles::HasCapacityRole ).toBool();
    const int actionCount = index.data( CustomRoles::DecoratorRoleCount ).toInt();

    painter->save();

    QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter );

    if ( option.state & QStyle::State_Selected )
        painter->setPen( App::instance()->palette().highlightedText().color() );
    else
        painter->setPen( App::instance()->palette().text().color() );

    painter->setRenderHint( QPainter::Antialiasing );

    const int iconYPadding = ( height - iconHeight ) / 2;
    QPoint iconPos( topLeft + QPoint( iconPadX, iconYPadding ) );
    if( isRTL )
        iconPos.setX( width - iconWidth - iconPadX );


    painter->drawPixmap( iconPos,
                         index.data( Qt::DecorationRole ).value<QIcon>().pixmap( iconWidth, iconHeight ) );

    QStyleOption expanderOption( option );
    QStyle::PrimitiveElement expandedPrimitive;
    if( isRTL )
    {
        expandedPrimitive = QStyle::PE_IndicatorArrowLeft;
        expanderOption.rect.setLeft( iconPadX );
    }
    else
    {
        expandedPrimitive = QStyle::PE_IndicatorArrowRight;
        expanderOption.rect.setLeft( option.rect.right() - iconPadX - iconWidth );
    }

    expanderOption.rect.setWidth( iconWidth );
    //FIXME: CollectionTreeItemModelBase::hasChildren() returns true for root items regardless
    if( m_view->model()->hasChildren( index ) )
    {
        if( m_view->isExpanded( index ) )
        {
            QApplication::style()->drawPrimitive( QStyle::PE_IndicatorArrowDown, &expanderOption,
                                                  painter );
        }
        else
        {
            QApplication::style()->drawPrimitive( expandedPrimitive, &expanderOption,
                                                  painter );
        }
    }

    const QString collectionName = index.data( Qt::DisplayRole ).toString();
    const QString bylineText = index.data( CustomRoles::ByLineRole ).toString();

    const int actionsRectWidth = actionCount > 0 ?
                                 (ACTIONICON_SIZE * actionCount + 2*2/*margin*/) : 0;

    const int iconRight = topLeft.x() + iconWidth + iconPadX * 2;
    const int infoRectLeft = isRTL ? actionsRectWidth : iconRight;
    const int infoRectWidth = width - iconRight;

    const int titleRectWidth = infoRectWidth - actionsRectWidth;

    QRectF titleRect;
    titleRect.setLeft( infoRectLeft );
    titleRect.setTop( option.rect.top() + iconYPadding );
    titleRect.setWidth( titleRectWidth );
    titleRect.setHeight( m_bigFm->boundingRect( collectionName ).height() );

    painter->setFont( m_bigFont );
    painter->drawText( titleRect, Qt::AlignLeft, collectionName );

    const bool isHover = option.state & QStyle::State_MouseOver;
    QPoint cursorPos = m_view->mapFromGlobal( QCursor::pos() );
    cursorPos.ry() -= 20; // Where the fuck does this offset come from. I have _ZERO_ idea.

    painter->setFont( m_smallFont );  // we want smaller font for both subtitle and capacity bar
    //show the bylinetext or the capacity (if available) when hovering
    if( isHover && hasCapacity )
    {
        qreal bytesUsed = index.data( CustomRoles::UsedCapacityRole ).toReal();
        qreal bytesTotal = index.data( CustomRoles::TotalCapacityRole ).toReal();
//.........这里部分代码省略.........
开发者ID:ErrAza,项目名称:amarok,代码行数:101,代码来源:CollectionTreeItemDelegate.cpp


注:本文中的QRectF::setWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。