Ejemplo n.º 1
0
void DegreesLabel270::paintEvent( QPaintEvent* event )
{
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    QTextLayout textLayout(content, p.font());
    textLayout.beginLayout();
    drawRotatedText(&p, ROTATE270, width(), height()/2, content);
}
Ejemplo n.º 2
0
  void paintEvent(QPaintEvent *)
  {
    QPainter p(this);
#if 1
    QTextDocument document;
    document.setHtml("<br>T<br>e<br>s<br>t<br>");
    document.drawContents(&p);
#else
    drawRotatedText(&p, 90, width() / 2, height() / 2, "The vertical text");
#endif
  }
Ejemplo n.º 3
0
void QgsComposerRuler::paintEvent( QPaintEvent* event )
{
    Q_UNUSED( event );
    if ( !mComposition )
    {
        return;
    }

    QPainter p( this );

    QTransform t = mTransform.inverted();

    p.setFont( *mRulerFont );

    //find optimum scale for ruler (size of numbered divisions)
    int magnitude = 1;
    int multiple = 1;
    int mmDisplay;
    mmDisplay = optimumScale( mScaleMinPixelsWidth, magnitude, multiple );

    //find optimum number of small divisions
    int numSmallDivisions = optimumNumberDivisions( mmDisplay, multiple );

    if ( mDirection == Horizontal )
    {
        if ( qgsDoubleNear( width(), 0 ) )
        {
            return;
        }

        //start x-coordinate
        double startX = t.map( QPointF( 0, 0 ) ).x();
        double endX = t.map( QPointF( width(), 0 ) ).x();

        //start marker position in mm
        double markerPos = ( floor( startX / mmDisplay ) + 1 ) * mmDisplay;

        //draw minor ticks marks which occur before first major tick
        drawSmallDivisions( &p, markerPos, numSmallDivisions, -mmDisplay );

        while ( markerPos <= endX )
        {
            double pixelCoord = mTransform.map( QPointF( markerPos, 0 ) ).x();

            //draw large division and text
            p.drawLine( pixelCoord, 0, pixelCoord, mRulerMinSize );
            p.drawText( QPointF( pixelCoord + mPixelsBetweenLineAndText, mTextBaseline ), QString::number( markerPos ) );

            //draw small divisions
            drawSmallDivisions( &p, markerPos, numSmallDivisions, mmDisplay, endX );

            markerPos += mmDisplay;
        }
    }
    else //vertical
    {
        if ( qgsDoubleNear( height(), 0 ) )
        {
            return;
        }

        double startY = t.map( QPointF( 0, 0 ) ).y(); //start position in mm (total including space between pages)
        double endY = t.map( QPointF( 0, height() ) ).y(); //stop position in mm (total including space between pages)
        int startPage = ( int )( startY / ( mComposition->paperHeight() + mComposition->spaceBetweenPages() ) );
        if ( startPage < 0 )
        {
            startPage = 0;
        }

        if ( startY < 0 )
        {
            double beforePageCoord = -mmDisplay;
            double firstPageY = mTransform.map( QPointF( 0, 0 ) ).y();

            //draw negative rulers which fall before first page
            while ( beforePageCoord > startY )
            {
                double pixelCoord = mTransform.map( QPointF( 0, beforePageCoord ) ).y();
                p.drawLine( 0, pixelCoord, mRulerMinSize, pixelCoord );
                //calc size of label
                QString label = QString::number( beforePageCoord );
                int labelSize = mRulerFontMetrics->width( label );

                //draw label only if it fits in before start of next page
                if ( pixelCoord + labelSize + 8 < firstPageY )
                {
                    drawRotatedText( &p, QPointF( mTextBaseline, pixelCoord + mMinSpacingVerticalLabels + labelSize ), label );
                }

                //draw small divisions
                drawSmallDivisions( &p, beforePageCoord, numSmallDivisions, mmDisplay );

                beforePageCoord -= mmDisplay;
            }

            //draw minor ticks marks which occur before first major tick
            drawSmallDivisions( &p, beforePageCoord + mmDisplay, numSmallDivisions, -mmDisplay, startY );
        }

        int endPage = ( int )( endY / ( mComposition->paperHeight() + mComposition->spaceBetweenPages() ) );
        if ( endPage > ( mComposition->numPages() - 1 ) )
        {
            endPage = mComposition->numPages() - 1;
        }

        double nextPageStartPos = 0;
        int nextPageStartPixel = 0;

        for ( int i = startPage; i <= endPage; ++i )
        {
            double pageCoord = 0; //page coordinate in mm
            //total (composition) coordinate in mm, including space between pages
            double totalCoord = i * ( mComposition->paperHeight() + mComposition->spaceBetweenPages() );

            //position of next page
            if ( i < endPage )
            {
                //not the last page
                nextPageStartPos = ( i + 1 ) * ( mComposition->paperHeight() + mComposition->spaceBetweenPages() );
                nextPageStartPixel = mTransform.map( QPointF( 0, nextPageStartPos ) ).y();
            }
            else
            {
                //is the last page
                nextPageStartPos = 0;
                nextPageStartPixel = 0;
            }

            while (( totalCoord < nextPageStartPos ) || (( nextPageStartPos == 0 ) && ( totalCoord <= endY ) ) )
            {
                double pixelCoord = mTransform.map( QPointF( 0, totalCoord ) ).y();
                p.drawLine( 0, pixelCoord, mRulerMinSize, pixelCoord );
                //calc size of label
                QString label = QString::number( pageCoord );
                int labelSize = mRulerFontMetrics->width( label );

                //draw label only if it fits in before start of next page
                if (( pixelCoord + labelSize + 8 < nextPageStartPixel )
                        || ( nextPageStartPixel == 0 ) )
                {
                    drawRotatedText( &p, QPointF( mTextBaseline, pixelCoord + mMinSpacingVerticalLabels + labelSize ), label );
                }

                //draw small divisions
                drawSmallDivisions( &p, totalCoord, numSmallDivisions, mmDisplay, nextPageStartPos );

                pageCoord += mmDisplay;
                totalCoord += mmDisplay;
            }
        }
    }

    //draw current marker pos
    drawMarkerPos( &p );
}
Ejemplo n.º 4
0
void ScoreWidget::showPlayerScore (int i, const QString scoreBullet, const QString scoreMountain,
  const QString scoreLeftWhist, const QString scoreRightWhist, const int scoreTotal)
{
  const int PoolWidth = 60;
  const int Pool2Width = 85;
  int PaperWidth = width();
  int PaperHeight = height();
  QPainter p(this);
  if (m_landscape)
  {
      p.translate(PaperWidth, 0);
      p.rotate(90);
      qSwap(PaperWidth, PaperHeight);
  }
  QPoint center(PaperWidth/2, PaperHeight-PaperWidth/2);
  p.setPen(qRgb(0, 0, 0));
  QFont fnt(p.font());
  QRect r1 = p.boundingRect(rect(), Qt::AlignHCenter, QString::number(scoreTotal));
  switch (i)
  {
    case 1:
      // Bullet
      p.setPen(qRgb(0, 128, 0));
      p.drawText(PoolWidth+r1.height()+4, PaperHeight-PoolWidth-4, scoreBullet);
      // Mountain
      p.setPen(qRgb(235, 0, 0));
      p.drawText(Pool2Width+r1.height()+4, PaperHeight-Pool2Width-4, scoreMountain);
      // Whists
      p.setPen(qRgb(0, 0, 0));
      p.drawText(r1.height()+4, PaperHeight-4, scoreLeftWhist);
      p.drawText(center.x()+4, PaperHeight-4, scoreRightWhist);
      // Total score
      if (scoreTotal >= 0)
        p.setPen(qRgb(0, 0, 235));
      else
        p.setPen(qRgb(235, 0, 0));
      fnt.setBold(true);
      p.setFont(fnt);
      p.drawText(center.x()-r1.width()/2, center.y()+100, QString::number(scoreTotal));
      break;
    case 2:
      // Bullet
      p.setPen(qRgb(0, 128, 0));
      drawRotatedText(p, PoolWidth+4, 4, 90, scoreBullet);
      // Mountain
      p.setPen(qRgb(235, 0, 0));
      drawRotatedText(p, Pool2Width+4, 4, 90, scoreMountain);
      // Whists
      p.setPen(qRgb(0, 0, 0));
      drawRotatedText(p, 4, 4, 90, scoreLeftWhist);
      drawRotatedText(p, 4, (PaperHeight-PoolWidth)/2+4, 90, scoreRightWhist);
      // Total score
      if (scoreTotal >= 0)
        p.setPen(qRgb(0, 0, 235));
      else
        p.setPen(qRgb(235, 0, 0));
      fnt.setBold(true);
      p.setFont(fnt);
      if(!m_landscape) {
        drawRotatedText(p, center.x() - 60, (PaperHeight - Pool2Width - r1.width())/2,
          90, QString::number(scoreTotal));
      } else {
        drawRotatedText(p, center.x() - 60, (PaperHeight - Pool2Width + r1.width())/2,
          -90, QString::number(scoreTotal));
      }
      break;
    case 3:
      // Bullet
      p.setPen(qRgb(0, 128, 0));
      drawRotatedText(p, PaperWidth-PoolWidth-4, PaperHeight-PoolWidth-r1.height(), -90, scoreBullet);
      // Mountain
      p.setPen(qRgb(235, 0, 0));
      drawRotatedText(p, PaperWidth-Pool2Width-4, PaperHeight-Pool2Width-r1.height(), -90, scoreMountain);
      // Whists
      p.setPen(qRgb(0, 0, 0));
      drawRotatedText(p, PaperWidth-4, PaperHeight-r1.height()-4, -90, scoreLeftWhist);
      drawRotatedText(p, PaperWidth-4, (PaperHeight-PoolWidth)/2-4, -90, scoreRightWhist);
      // Total score
      if (scoreTotal >= 0)
        p.setPen(qRgb(0, 0, 235));
      else
        p.setPen(qRgb(235, 0, 0));
      fnt.setBold(true);
      p.setFont(fnt);
      drawRotatedText(p, center.x() + 80, (PaperHeight - Pool2Width + r1.width())/2,
        -90, QString::number(scoreTotal));
      break;
    default: ;
  }
  fnt.setBold(false);
  p.setFont(fnt);
  p.end();
}
Ejemplo n.º 5
0
void ScoreWidget::paintBlankPaper ()
{
  int PaperWidth = m_paperBmp->width();
  int PaperHeight = m_paperBmp->height();
  const int PoolWidth = 60;
  const int Pool2Width = 85;
  const int maxPoolRadius = 20;

  QPainter p(m_paperBmp);
  if (m_landscape)
  {
      p.translate(PaperWidth, 0);
      p.rotate(90);
      qSwap(PaperWidth, PaperHeight);
  }

  p.setRenderHints(QPainter::Antialiasing);
  QRect NewRect = QRect(0, 0, PaperWidth, PaperHeight);
  QImage img(QString(":/pics/scorepaper.png"));
  p.drawImage(0, 0, img);
  p.setPen(Qt::black);

  // Draw borders of paper
  p.drawRect(NewRect);
  QPoint center(PaperWidth/2, PaperHeight-PaperWidth/2);

  // Diagonal lines from bottom corners to circle
  p.drawLine(NewRect.bottomLeft(), center);
  p.drawLine(NewRect.bottomRight(), center);

  // Central vertical line
  p.drawLine( center.x(), 0, center.x(), center.y() );

  // External border of pool
  p.drawRect(PoolWidth, 0, PaperWidth-2*PoolWidth, PaperHeight-PoolWidth);

  // Border of mountain
  p.drawRect(Pool2Width, 0, PaperWidth-2*Pool2Width, PaperHeight-Pool2Width);

  // Player lines
  p.drawLine(0, (PaperHeight-PoolWidth)/2, PoolWidth, (PaperHeight-PoolWidth)/2);
  p.drawLine(PaperWidth, (PaperHeight-PoolWidth)/2, PaperWidth-PoolWidth, (PaperHeight-PoolWidth)/2);
  p.drawLine(PaperWidth/2, PaperHeight, PaperWidth/2, PaperHeight-PoolWidth);

  // Circle with MaxPool value
  QRadialGradient g(center, maxPoolRadius, center+QPoint(-maxPoolRadius/2,-maxPoolRadius/2));
  g.setColorAt(0, Qt::white);
  g.setColorAt(1, qRgb(250, 250, 0));
  
  QBrush b1(g);
  p.setBrush(b1);
  p.drawEllipse(center, maxPoolRadius, maxPoolRadius);

  // Draw text  
  // MaxPool
  QFont fnt(p.font());
  fnt.setBold(true);
  p.setFont(fnt);
  p.drawText(QRect(center.x() - maxPoolRadius, center.y() - maxPoolRadius,
    maxPoolRadius*2, maxPoolRadius*2), QString::number(m_model->optMaxPool), QTextOption(Qt::AlignCenter));
  fnt.setBold(false);
  p.setFont(fnt);
  
  // Players' names
  QBrush brush(qRgb(255, 255, 255));
  p.setBrush(brush);
  const QRect r1 = p.boundingRect(NewRect, Qt::AlignHCenter, m_model->player(1)->nick());
  const QRect r2 = p.boundingRect(NewRect, Qt::AlignHCenter, m_model->player(2)->nick());
  const QRect r3 = p.boundingRect(NewRect, Qt::AlignHCenter, m_model->player(3)->nick());
  p.drawText(QRect(center.x()-r1.width()/2, center.y()+55, r1.width(), r1.height()),
    m_model->player(1)->nick(), QTextOption(Qt::AlignHCenter));
  drawRotatedText(p, center.x() - 30, (PaperHeight - Pool2Width + (m_landscape ? 1 : -1) * r2.width())/2,
    r2.width(), r2.height(), m_landscape ? -90 : 90, m_model->player(2)->nick());
  drawRotatedText(p, center.x() + 30, (PaperHeight - Pool2Width + r3.width())/2,
    r3.width(), r3.height(), -90, m_model->player(3)->nick());

  p.end();
}
Ejemplo n.º 6
0
void QgsLayoutRuler::paintEvent( QPaintEvent *event )
{
  Q_UNUSED( event );
  if ( !mView || !mView->currentLayout() )
  {
    return;
  }

  QgsLayout *layout = mView->currentLayout();
  QPainter p( this );

  drawGuideMarkers( &p, layout );

  QTransform t = mTransform.inverted();
  p.setFont( mRulerFont );
  // keep same default color, but lower opacity a tad
  QBrush brush = p.brush();
  QColor color = brush.color();
  color.setAlphaF( 0.7 );
  brush.setColor( color );
  p.setBrush( brush );
  QPen pen = p.pen();
  color = pen.color();
  color.setAlphaF( 0.7 );
  pen.setColor( color );
  p.setPen( pen );

  //find optimum scale for ruler (size of numbered divisions)
  int magnitude = 1;
  int multiple = 1;
  int mmDisplay = optimumScale( mScaleMinPixelsWidth, magnitude, multiple );

  //find optimum number of small divisions
  int numSmallDivisions = optimumNumberDivisions( mmDisplay, multiple );

  switch ( mOrientation )
  {
    case Qt::Horizontal:
    {
      if ( qgsDoubleNear( width(), 0 ) )
      {
        return;
      }

      //start x-coordinate
      double startX = t.map( QPointF( 0, 0 ) ).x();
      double endX = t.map( QPointF( width(), 0 ) ).x();

      //start marker position in mm
      double markerPos = ( std::floor( startX / mmDisplay ) + 1 ) * mmDisplay;

      //draw minor ticks marks which occur before first major tick
      drawSmallDivisions( &p, markerPos, numSmallDivisions, -mmDisplay );

      while ( markerPos <= endX )
      {
        double pixelCoord = mTransform.map( QPointF( markerPos, 0 ) ).x();

        //draw large division and text
        p.drawLine( pixelCoord, 0, pixelCoord, mRulerMinSize );
        p.drawText( QPointF( pixelCoord + mPixelsBetweenLineAndText, mTextBaseline ), QString::number( markerPos ) );

        //draw small divisions
        drawSmallDivisions( &p, markerPos, numSmallDivisions, mmDisplay, endX );

        markerPos += mmDisplay;
      }
      break;
    }
    case Qt::Vertical:
    {
      if ( qgsDoubleNear( height(), 0 ) )
      {
        return;
      }

      double startY = t.map( QPointF( 0, 0 ) ).y(); //start position in mm (total including space between pages)
      double endY = t.map( QPointF( 0, height() ) ).y(); //stop position in mm (total including space between pages)

      // work out start page
      int startPage = 0;
      int endPage = 0;
      double currentY = 0;
      double currentPageY = 0;
      for ( int page = 0; page < layout->pageCollection()->pageCount(); ++page )
      {
        if ( currentY < startY )
        {
          startPage = page;
          currentPageY = currentY;
        }
        endPage = page;

        currentY += layout->pageCollection()->page( startPage )->rect().height() + layout->pageCollection()->spaceBetweenPages();
        if ( currentY > endY )
          break;
      }

      if ( startY < 0 )
      {
        double beforePageCoord = -mmDisplay;
        double firstPageY = mTransform.map( QPointF( 0, 0 ) ).y();

        //draw negative rulers which fall before first page
        while ( beforePageCoord > startY )
        {
          double pixelCoord = mTransform.map( QPointF( 0, beforePageCoord ) ).y();
          p.drawLine( 0, pixelCoord, mRulerMinSize, pixelCoord );
          //calc size of label
          QString label = QString::number( beforePageCoord );
          int labelSize = mRulerFontMetrics->width( label );

          //draw label only if it fits in before start of next page
          if ( pixelCoord + labelSize + 8 < firstPageY )
          {
            drawRotatedText( &p, QPointF( mTextBaseline, pixelCoord + mMinSpacingVerticalLabels + labelSize ), label );
          }

          //draw small divisions
          drawSmallDivisions( &p, beforePageCoord, numSmallDivisions, mmDisplay );

          beforePageCoord -= mmDisplay;
        }

        //draw minor ticks marks which occur before first major tick
        drawSmallDivisions( &p, beforePageCoord + mmDisplay, numSmallDivisions, -mmDisplay, startY );
      }

      double nextPageStartPos = 0;
      int nextPageStartPixel = 0;

      for ( int i = startPage; i <= endPage; ++i )
      {
        double pageCoord = 0; //page coordinate in mm
        //total (composition) coordinate in mm, including space between pages

        double totalCoord = currentPageY;

        //position of next page
        if ( i < endPage )
        {
          //not the last page
          nextPageStartPos = currentPageY + layout->pageCollection()->page( i )->rect().height() + layout->pageCollection()->spaceBetweenPages();
          nextPageStartPixel = mTransform.map( QPointF( 0, nextPageStartPos ) ).y();
        }
        else
        {
          //is the last page
          nextPageStartPos = 0;
          nextPageStartPixel = 0;
        }

        while ( ( totalCoord < nextPageStartPos ) || ( ( nextPageStartPos == 0 ) && ( totalCoord <= endY ) ) )
        {
          double pixelCoord = mTransform.map( QPointF( 0, totalCoord ) ).y();
          p.drawLine( 0, pixelCoord, mRulerMinSize, pixelCoord );
          //calc size of label
          QString label = QString::number( pageCoord );
          int labelSize = mRulerFontMetrics->width( label );

          //draw label only if it fits in before start of next page
          if ( ( pixelCoord + labelSize + 8 < nextPageStartPixel )
               || ( nextPageStartPixel == 0 ) )
          {
            drawRotatedText( &p, QPointF( mTextBaseline, pixelCoord + mMinSpacingVerticalLabels + labelSize ), label );
          }

          //draw small divisions
          drawSmallDivisions( &p, totalCoord, numSmallDivisions, mmDisplay, nextPageStartPos );

          pageCoord += mmDisplay;
          totalCoord += mmDisplay;
        }
        if ( i < endPage )
          currentPageY += layout->pageCollection()->page( i )->rect().height() + layout->pageCollection()->spaceBetweenPages();
      }
      break;
    }
  }

  //draw current marker pos
  drawMarkerPos( &p );
}