Beispiel #1
0
void SubjectCanvas::draw(QPainter & p) {
  if (! visible()) return;
  p.setRenderHint(QPainter::Antialiasing, true);
  QRect r = rect();
  QColor bckgrnd = p.backgroundColor();

  p.setBackgroundMode((used_color == UmlTransparent) ? ::Qt::TransparentMode : ::Qt::OpaqueMode);

  QColor co = color(used_color);
  FILE * fp = svg();

  if (fp != 0)
    fputs("<g>\n", fp);  
  
  p.setBackgroundColor(co);
  p.setFont(the_canvas()->get_font(UmlNormalBoldFont));
  
  if (used_color != UmlTransparent)
    p.fillRect(r, co);
  
  if (fp != 0)
    fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
	    " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
	    svg_color(used_color), 
	    r.x(), r.y(), r.width() - 1, r.height() - 1);

  p.drawRect(r);
  
  r.setTop(r.top() + (int) (2*the_canvas()->zoom()));
  p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, name);
  if (fp != 0) {
    draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, name,
	      p.font(), fp);
    fputs("</g>\n", fp);
  }
    
  p.setBackgroundColor(bckgrnd);
  
  if (selected())
    show_mark(p, rect());
}
Beispiel #2
0
void TankGameWidget::PaintText(const ScreenText& txt, QPainter& painter)
{
    if (txt.Finished())
    {
        return; //shall not be rendered now
    }

    painter.save();
    painter.setPen(txt.Pen());
    QFont font=painter.font();
    font.setPixelSize(txt.FontSize());
    font.setBold(true);
    painter.setFont(font);

    int rowStep=3*txt.FontSize();

    if (txt.Position().x()<0 || txt.Position().y()<0)
    {
        int xPos=txt.Position().x();
        int yPos=txt.Position().y();
        if (xPos<0) xPos=0;
        if (yPos<0) yPos=0;
        QRect rect(xPos, yPos, m_const.boardPixelSizeFloat.x(), txt.FontSize());
        for (const QString& s : txt.Text())
        {
            painter.drawText(rect, Qt::AlignCenter, s);
            rect.setY(rect.y()+rowStep);
        }
    }
    else
    {
        auto pos=ToScreen(txt.Position(), 0, 0);
        for (const QString& s : txt.Text())
        {
            painter.drawText(pos, s);
            pos.setY(pos.y()+rowStep);
        }
    }

    painter.restore();
}
Beispiel #3
0
void GameWindow::render()
{

    bool needsInitialize = false;
    if (!m_context) {
        m_context = new QOpenGLContext(this);
        m_context->setFormat(requestedFormat());
        m_context->create();
        needsInitialize = true;
    }

    m_context->makeCurrent(this);

    if (needsInitialize)
    {
        initializeOpenGLFunctions();
    }

    if (!m_device)
        m_device = new QOpenGLPaintDevice();

    m_device->setSize(size());

    QPainter p;

    elapsed = elapsedTimer.elapsed();
    if(elapsed > timer.interval() * 0.5) {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
        this->render((float) elapsed * 0.0005f);
//        glDisableVertexAttribArray(GL_DEPTH_TEST);
        p.begin(m_device);
        p.setPen(Qt::yellow);
        p.setFont(QFont("Arial", 20));
        p.drawText(10, 30, QString::number((int) (1.0 / (elapsed * 0.001f))));
        p.end();
        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LESS);
        elapsed -= timer.interval();
        elapsedTimer.restart();
    }
}
//This function makes a pixmap which is based on icon, but has a number painted on it.
QPixmap BoxContainerItem::calcComplexPixmap(const QPixmap &icon, const QColor &fgColour, const QFont *font, const int count)
{
    QPixmap result(icon);
    QPixmap numberPixmap(icon.size());
    QImage iconImage(icon.convertToImage());
    QImage numberImage;
    QRgb *rgbline;
    QPainter p;

    //Make a transparent number; first make a white number on a black background.
    //This pixmap also is the base alpha-channel, the foreground colour is added later.
    numberPixmap.fill(Qt::black);
    p.begin(&numberPixmap, false);
    p.setPen(Qt::white);
    if(font)
        p.setFont(*font);
    p.drawText(icon.rect(), Qt::AlignCenter, QString::number(count));
    p.end();

    //Convert to image and add the alpha channel.
    numberImage = numberPixmap.convertToImage();
    if(numberImage.depth() != 32)   //Make sure depth is 32 (and thus can have an alpha channel)
        numberImage = numberImage.convertDepth(32);
    numberImage.setAlphaBuffer(true);   //Enable alpha channel
    for(int xx = 0; xx < numberImage.height(); ++xx)
    {
        rgbline = (QRgb *)numberImage.scanLine(xx);

        for(int yy = 0; yy < numberImage.width(); ++yy)
        {
            //Set colour and alpha channel
            rgbline[ yy ] = qRgba(fgColour.red(), fgColour.green(), fgColour.blue(), qRed(rgbline[ yy ]));
        }
    }

    //Merge icon and number and convert to result.
    KIconEffect::overlay(iconImage, numberImage);
    result.convertFromImage(iconImage);

    return result;
}
Beispiel #5
0
void AccumulateEnergy::DrawRulerDH(QPainter &painter)
{
    //下半部分的横坐标轴

    painter.save();
    painter.setFont(QFont(QObject::tr("WenQuanYi"),6));
    float x = draw_area_range.left();
    float y = draw_area_range.bottom();
    float step = draw_area_range.width() / days_;
    float hindex = 0;
    //int day = 0;
    while(hindex <= draw_area_range.width())
    {

        painter.drawLine(x + hindex,y,x+hindex,y+2);

        QString day_string = startdate_.toString("MM/dd");

        float width = painter.fontMetrics().width(day_string);
        float height = painter.fontMetrics().height();
        painter.drawText(QRectF(x + hindex - width/2,y + 4,width + 2,height),Qt::AlignTop|Qt::AlignLeft,day_string);
        //day += 1;
        startdate_ = startdate_.addDays(1);
        hindex += step;

        if (hindex < draw_area_range.width())
        {
            painter.save();
            QPen pen;
            pen.setStyle(Qt::DashLine);
            pen.setColor(QColor(Qt::gray));
            pen.setWidthF(1.2);
            painter.setPen(pen);
            painter.drawLine(x + hindex,y,x + hindex,y - dheight_);

            painter.restore();
        }
    }

    painter.restore();
}
void
TextField::DoPaint( const GUI::DrawContext& inDC,
                    RGBColor inTextColor,
                    RGBColor inBackgroundColor )
{
#if USE_QT

  QPainter* p = inDC.handle.painter;
  QRect rect(
    static_cast<int>( inDC.rect.left ),
    static_cast<int>( inDC.rect.top ),
    static_cast<int>( inDC.rect.right - inDC.rect.left ),
    static_cast<int>( inDC.rect.bottom - inDC.rect.top )
  );
  QBrush brush;
  brush.setStyle( Qt::SolidPattern );
  if( mColor != RGBColor( RGBColor::NullColor ) )
  {
    QColor backColor( mColor.R(), mColor.G(), mColor.B() );
    brush.setColor( backColor );
    p->fillRect( rect, brush );
  }

  QFont font;
  font.fromString( QString( "Arial" ) );
  font.setPixelSize( static_cast<int>( mTextHeight * ( inDC.rect.bottom - inDC.rect.top ) ) );
  font.setBold( true );
  QColor textColor( inTextColor.R(), inTextColor.G(), inTextColor.B() );
  QPen pen;
  brush.setColor( textColor );
  pen.setColor( textColor );
  p->setPen( pen );
  p->setBrush( brush );
  p->setFont( font );

  QString text = QString::fromLocal8Bit( mText.c_str() );
  text.append( " " ).prepend( " " );
  p->drawText( rect, Qt::AlignCenter, text );

#endif // USE_QT
}
Beispiel #7
0
void markupText::drawMarkup( QPainter& p )
{
    // Scale markup
    QRect scaledRect = rect;
    // Text is not scaled
    //double scale = getZoomScale();
    //scaledRect.moveTo( rect.x() * scale, rect.y() * scale );

    //scaledRect.setWidth( rect.width() * scale );
    //scaledRect.setHeight( rect.height() * scale );

    // Draw markup

    // Draw the text
    p.setFont( owner->legendFont );
    p.drawText( scaledRect, Qt::AlignLeft, text, &scaledRect );

    // Draw markup legend
    // never a legend for text drawLegend( p, ???, ABOVE_RIGHT );

}
Beispiel #8
0
/*! \brief The screen that is displayed when a Game Over occurs.
 * Precondition: Paint event is called and gameOver is true.
 * Postcondition: gameOverScreen is displayed.		
 * \param QT Qpainter object reference. */
void Game::gameOverScreen(QPainter &painter)
{
    	QFont font("Courier", 15, QFont::DemiBold);
	QFontMetrics fm(font);
	int textWidth = fm.width("Game Over");

	painter.setFont(font);
	int h = height();
	int w = width();

	painter.translate(QPoint(w/2, h/2));
	painter.drawText(-textWidth/2, -16, "Game Over");

	int textWidth2 = fm.width("Total Points: " + QString::number(points));
	painter.drawText(-textWidth2/2, 0, "Total Points: " + QString::number(points));

	int textWidth3 = fm.width("Press the Space Bar to Restart!");
	painter.drawText(-textWidth3/2, 16, "Press the Space Bar to Restart!");

	lastDir = ' '; // resets last direction to nothing
}
Beispiel #9
0
void TScale::pdraw(QPainter& p, const QRect& r)
{
	int y = r.y();
	int h = r.height();
	QColor colTimeLine = QColor(172,181,176);
	p.setPen(colTimeLine);
	//p.setFont(config.fonts[4]);
	p.setFont(QFont("fixed-width", 8, QFont::Bold));
	QString s;
	for (int i = 30000; i <= 250000; i += 10000)
	{
		int yy = mapy(280000 - i);
		if (yy < y)
			break;
		if (yy - 15 > y + h)
			continue;
		p.drawLine(0, yy, width(), yy);
		s.setNum(i / 1000);
		p.drawText(QRect(0, yy, width(), 15), s, QTextOption(Qt::AlignVCenter|Qt::AlignRight));
	}
}
Beispiel #10
0
void Field::draw()
{
  QPainter paint;
  paint.begin(pixmap);

  if(pattern) paint.drawImage(0,0,*pattern);

  if(label.length())
  {
    paint.setPen(white);
    paint.setFont(QFont(font().family(),10));
    paint.drawText(2,11,label);
  }

  if(picture) paint.drawImage(0,0,*picture);

  if(frame) paint.drawImage(0,0,*frame);

  paint.end();
  update();
}
Beispiel #11
0
void Game2D::drawLabels (QPainter &p){

    QFont font;
    font.setPixelSize(18);
    p.setFont(font);

    p.setPen (Qt::white);

    QString text;
    text.sprintf ("level: %d score: %d enemy: %d", level(), score (), evec_.size ());
    p.drawText(0, 0, width(), height (), Qt::AlignLeft, text);

    ////////////////
    int sec=time_/1000;
    int msec=time_%1000;
    int min=sec/60;
    sec=sec%60;

    text.sprintf ("%02d:%02d.%03d", min, sec, msec);
    p.drawText(0, 0, width(), height (), Qt::AlignRight, "time: " + text);
}
Beispiel #12
0
void NLabel::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    QPainter painter;
    QRect rect = contentsRect();

    if (painter.isActive())
        painter.setFont(font());

    if (m_enabled && m_shadowOffset != QPoint(0, 0)) {
        painter.begin(this);
        painter.setPen(QPen(m_shadowColor));
        painter.drawText(rect.translated(m_shadowOffset), alignment(), m_elidedText);
        painter.end();
    }

    painter.begin(this);
    painter.drawText(rect, alignment(), m_elidedText);
    painter.end();
}
Beispiel #13
0
void IntervalProgressDisplay::LinearPaintStrategy::drawPoint(qreal x, qreal y, qreal size, QPainter &painter, int value,
                                        const QBrush &bgPaint, bool small)
{
    painter.setBrush(bgPaint);
    painter.drawEllipse(QPointF(x, y), size/2, size/2);

    painter.setPen(Qt::NoPen);
    painter.drawEllipse(QPointF(x, y), size/2, size/2);

    bool drawText = !small;
    if (drawText) {
        QString valueString = QString::number(value);
        painter.setFont(font);
        QFontMetrics fontMetrics = painter.fontMetrics();
        QRect boundingRect = fontMetrics.tightBoundingRect(valueString);
        qreal textX = x - fontMetrics.width(valueString)/2.0;
        qreal textY = y + boundingRect.height()/2.0;
        painter.setPen(Qt::black);
        painter.drawText(QPointF(textX, textY), valueString);
    }
}
void QgsLayoutItemLabel::draw( QgsLayoutItemRenderContext &context )
{
  QPainter *painter = context.renderContext().painter();
  painter->save();

  // painter is scaled to dots, so scale back to layout units
  painter->scale( context.renderContext().scaleFactor(), context.renderContext().scaleFactor() );

  double penWidth = frameEnabled() ? ( pen().widthF() / 2.0 ) : 0;
  double xPenAdjust = mMarginX < 0 ? -penWidth : penWidth;
  double yPenAdjust = mMarginY < 0 ? -penWidth : penWidth;
  QRectF painterRect( xPenAdjust + mMarginX, yPenAdjust + mMarginY, rect().width() - 2 * xPenAdjust - 2 * mMarginX, rect().height() - 2 * yPenAdjust - 2 * mMarginY );

  switch ( mMode )
  {
    case ModeHtml:
    {
      if ( mFirstRender )
      {
        contentChanged();
        mFirstRender = false;
      }
      painter->scale( 1.0 / mHtmlUnitsToLayoutUnits / 10.0, 1.0 / mHtmlUnitsToLayoutUnits / 10.0 );
      mWebPage->setViewportSize( QSize( painterRect.width() * mHtmlUnitsToLayoutUnits * 10.0, painterRect.height() * mHtmlUnitsToLayoutUnits * 10.0 ) );
      mWebPage->settings()->setUserStyleSheetUrl( createStylesheetUrl() );
      mWebPage->mainFrame()->render( painter );
      break;
    }

    case ModeFont:
    {
      const QString textToDraw = currentText();
      painter->setFont( mFont );
      QgsLayoutUtils::drawText( painter, painterRect, textToDraw, mFont, mFontColor, mHAlignment, mVAlignment, Qt::TextWordWrap );
      break;
    }
  }

  painter->restore();
}
Beispiel #15
0
void LoadingWidget::paintEvent(QPaintEvent *event)
{
    QPainter painter;
    painter.begin(this);
    painter.setRenderHint(QPainter::Antialiasing);

    painter.fillRect(event->rect(), background);
    painter.translate(event->rect().center());
    painter.save();
    painter.setPen(circlePen);
    painter.translate(-138, 65);

    int n = 7;
    for (int i = 0; i < n; i++) {
        qreal radius;
        if (i == step) {
            painter.setBrush(circleBrush);
            radius = 16;
        } else {
            painter.setBrush(background);
            if(abs(i - step) == 1)
                radius = 14;
            else if (abs(i - step) == 2)
                radius = 12;
            else
                radius = 10;
        }

        painter.drawEllipse(QRectF(5, -radius,
                                   radius*2, radius*2));
        painter.translate(40, 0);
    }
    painter.restore();

    painter.setPen(textPen);
    painter.setFont(textFont);
    painter.drawText(QRect(-140, -60, 280, 120), Qt::AlignCenter, text);

    painter.end();
}
Beispiel #16
0
void Layer::paintLabel(QPainter& painter, TimeLineCells* cells, int x, int y, int width, int height, bool selected, int allLayers)
{
    painter.setBrush(Qt::lightGray);
    painter.setPen(QPen(QBrush(QColor(100,100,100)), 1, Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin));
    painter.drawRect(x, y-1, width, height); // empty rectangle  by default

    if (visible)
    {
        if (allLayers==0)  painter.setBrush(Qt::NoBrush);
        if (allLayers==1)   painter.setBrush(Qt::darkGray);
        if ((allLayers==2) || selected)  painter.setBrush(Qt::black);
    }
    else
    {
        painter.setBrush(Qt::NoBrush);
    }
    painter.setPen(Qt::black);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.drawEllipse(x+6, y+4, 9, 9);
    painter.setRenderHint(QPainter::Antialiasing, false);
    /*if (selected) {
    	painter.setPen(Qt::NoPen);
    	painter.setBrush(QColor(0,0,0,80));
    	painter.drawRect(x, y-1, width, height);
    }*/
    if (selected)
    {
        paintSelection(painter, x, y, width, height);
    }

    if (type == BITMAP) painter.drawPixmap( QPoint(20, y+2), QPixmap(":/icons/layer-bitmap.png") );
    if (type == VECTOR) painter.drawPixmap( QPoint(20, y+2), QPixmap(":/icons/layer-vector.png") );
    if (type == SOUND) painter.drawPixmap( QPoint(21, y+2), QPixmap(":/icons/layer-sound.png") );
    if (type == CAMERA) painter.drawPixmap( QPoint(21, y+2), QPixmap(":/icons/layer-camera.png") );

    painter.setFont(QFont("helvetica", height/2));
    painter.setPen(Qt::black);
    painter.drawText(QPoint(45, y+(2*height)/3), name);

}
Beispiel #17
0
void ScaleBarOverlay::paintContent(QPainter &painter)
{
    double scale;
    {
        QMutexLocker lock(&mMutex);
        scale = mLastValue.toDouble();
    }
    if(mActive)
    {
        painter.setBrush(QColor(0,0,0, 160));
        painter.drawRect(mRect);
    }
    double scaleBarLen = mRect.width();
    double scaleValue = -1;
    if(scale > 0)
    {
        scaleValue = visibleScale(mRect.width() * scale);
        scaleBarLen = scaleValue /scale;
    }
    int barHeight = qMin(20, mRect.height()/2);
    QPointF p1(mRect.left(), mRect.bottom() - barHeight);
    QPointF p2(mRect.left()+scaleBarLen, mRect.bottom() - barHeight);
    painter.setPen(mPen);
    painter.drawLine(p1, p2);
    painter.drawLine(p1 + QPoint(0, barHeight), p1 - QPoint(0, barHeight));
    painter.drawLine(p2 + QPoint(0, barHeight), p2 - QPoint(0, barHeight));
    QRectF paintRect(p1 - QPoint(0,qMin(50, mRect.height()/2)), p2);
    mFont.setPixelSize(paintRect.height()*7/8);
    painter.setFont(mFont);
    QStringList unitNames = QStringList("m") <<  "mm" << "µm" << "nm";
    QString suffix = " "+ unitNames[0];
    for(int i=1; i<unitNames.size();i++)
    {
        if(scaleValue >= 1 || scaleValue < 0)
            break;
        scaleValue *= 1000;
        suffix = " "+unitNames[i];
    }
    painter.drawText(paintRect, Qt::AlignCenter, QString::number(scaleValue) + suffix);
}
QSize QColorTabWidget::calcTabSize( QPainter& p, const TabInfo& ti )
{
    p.setFont(m_fntTab);

    QRectF rectText(0,0,0,0);

    if( isHorzTab() )
    {
        rectText.setHeight((float)m_sizeTabHeader.height());
    }
    else
    {
        rectText.setWidth((float)m_sizeTabHeader.width());
    }

    QString strCaption = ti.strCaption;
    int flags = Qt::AlignLeft|Qt::AlignVCenter|Qt::TextSingleLine;

    QRectF rectBB = p.boundingRect( rectText, flags, strCaption );
    //p.drawText( rectText, flags, strCaption, &rectBB );

    float fImageOffset = 0.f;
    if( ti.pIconImage )
    {
        fImageOffset = ti.pIconImage->width() + 5.f;
    }

    if( isHorzTab() )
    {
        rectBB.setWidth( rectBB.width() + fImageOffset + 15.f );
    }
    else
    {
        rectBB.setWidth( rectBB.width() + fImageOffset );
        rectBB.setHeight( rectBB.height() + 15.f );
    }


    return QSize( (int)(rectBB.width() + .5f), (int)(rectBB.height() + .5f) );
}
Beispiel #19
0
void Number::drawShape( QPainter & p ) {
    Q_ASSERT( d );
    p.save();

    p.setBrush( d->m_brush );
    p.setPen( d->m_pen );
    p.drawRect( d->m_points );

    //Although reformatting was not required but this line is added at the
    //request of Patrick

    //used setNum to sprintf as it easier with base value to implement.
    d->m_input.setNum( iopins()["input"]->realNumberValue(), d->m_base );

    if( ! d->m_input.isEmpty() ) {
        p.setFont( d->m_font );
        p.setPen( d->m_color );
        p.drawText( d->m_input_pos, d->m_alignment, d->m_input );
    }

    p.restore();
}
Beispiel #20
0
void AccumulateEnergy::DrawAxeUPartText(QPainter &painter)
{
    painter.save();
    QPen pen;
    painter.setFont(QFont(QObject::tr("WenQuanYi"),10));


    QRect rect_y_text(0,draw_area_range.top(),draw_area_range.left(),uheight_);
    QRect rect_y_virtual(-rect_y_text.top(),rect_y_text.left(),-rect_y_text.height(),rect_y_text.width());
    QRect rect_y_text2(0,draw_area_range.top() + uheight_,draw_area_range.left(),dheight_);
    QRect rect_y_virtual2(-rect_y_text2.top(),rect_y_text2.left(),-rect_y_text2.height(),rect_y_text2.width());
    painter.setMatrix(QMatrix(0,-1,1,0,0,0));
    pen.setColor(Qt::black);
    painter.setPen(pen);
    //painter.drawRect(rect_y_virtual);
    painter.drawText(rect_y_virtual,Qt::AlignTop|Qt::AlignHCenter,STRING_GRAPHIC_ADVANCEMETER);
    pen.setColor(Qt::black);
    painter.setPen(pen);
    painter.drawText(rect_y_virtual2,Qt::AlignTop|Qt::AlignHCenter,STRING_GRAPHIC_EVNET_NUMBERS);
    painter.resetMatrix();
    painter.restore();
}
Beispiel #21
0
void EllipsisBox::paint(RenderObject::PaintInfo& i, int _tx, int _ty)
{
    QPainter* p = i.p;
    RenderStyle* _style = m_firstLine ? m_object->style(true) : m_object->style();
    if (_style->font() != p->font())
        p->setFont(_style->font());

    const Font* font = &_style->htmlFont();
    QColor textColor = _style->color();
    if (textColor != p->pen().color())
        p->setPen(textColor);
    /*
    bool setShadow = false;
    if (_style->textShadow()) {
        p->setShadow(_style->textShadow()->x, _style->textShadow()->y,
                     _style->textShadow()->blur, _style->textShadow()->color);
        setShadow = true;
    }*/

    const DOMString& str = m_str.string();
    font->drawText(p, m_x + _tx,
                      m_y + _ty + m_baseline,
                      (str.implementation())->s,
                      str.length(), 0, str.length(),
                      0,
                      QPainter::LTR, _style->visuallyOrdered());

    /*
    if (setShadow)
        p->clearShadow();
    */

    if (m_markupBox) {
        // Paint the markup box
        _tx += m_x + m_width - m_markupBox->xPos();
        _ty += m_y + m_baseline - (m_markupBox->yPos() + m_markupBox->baseline());
        m_markupBox->object()->paint(i, _tx, _ty);
    }
}
Beispiel #22
0
bool SequenceAreaRenderer::drawContent(QPainter &painter, const U2Region &region, const QList<int> &seqIdx, int xStart, int yStart)  const {
    CHECK(!region.isEmpty(), false);
    CHECK(!seqIdx.isEmpty(), false);

    MsaHighlightingScheme* highlightingScheme = seqAreaWgt->getCurrentHighlightingScheme();
    MaEditor* editor = seqAreaWgt->getEditor();

    painter.setPen(Qt::black);
    painter.setFont(editor->getFont());

    MultipleAlignmentObject* maObj = editor->getMaObject();
    SAFE_POINT(maObj != NULL, tr("Alignment object is NULL"), false);
    const MultipleAlignment ma = maObj->getMultipleAlignment();

    //Use dots to draw regions, which are similar to reference sequence
    highlightingScheme->setUseDots(seqAreaWgt->getUseDotsCheckedState());

    int rowHeight = 0;
    foreach (const int rowIndex, seqIdx) {
        rowHeight = drawRow(painter, ma, rowIndex, region, xStart, yStart);
        yStart += ui->getRowHeightController()->getRowHeight(rowIndex);
    }
Beispiel #23
0
void Kanagram::drawTextNew(QPainter &p, const QString &text, int textAlign, int xMargin, int yMargin, const QRect &rect, bool highlight, int fontSize)
{
	QRect r = innerRect(rect, xMargin, yMargin);
	QFont font = m_blackboardFont;
	font.setPointSize(fontSize);
	font.setBold(true);
	p.setFont(font);
	
	const bool withMargin = false;
	if (withMargin)
	{
		p.fillRect(r, m_fillColor);
		p.setPen(QPen(black, 3));
		p.drawRoundRect(r.left(), r.top(), r.width(), r.height(), 15, 15);
	}
	
	if (highlight)
		p.setPen(m_chalkHighlightColor);
	else
		p.setPen(m_chalkColor);
	p.drawText(r, textAlign, text);
}
Beispiel #24
0
void KisTextBrush::updateBrush()
{
    QFontMetrics metric(m_font);
    int w = metric.width(m_txt);
    int h = metric.height();

    // don't crash, if there is no text
    if (w==0) w=1;
    if (h==0) h=1;

    QPixmap px(w, h);
    QPainter p;
    p.begin(&px);
    p.setFont(m_font);
    p.fillRect(0, 0, w, h, Qt::white);
    p.setPen(Qt::black);
    p.drawText(0, metric.ascent(), m_txt);
    p.end();
    setImage(px.toImage());
    setValid(true);
    resetBoundary();
}
void QAdvancedCalibrationWidget::paintEvent(QPaintEvent *)
{
    QPainter painter;

    QRect rcClient( 0, 0, width()-1, height()-1 );

    painter.begin( this );

    switch( m_eCurrentPart )
    {
    case spDetectionRange:
        m_DetectionRange.draw( painter, rcClient );
        break;
    case spBent:
        m_BentAdjustment.draw( painter, rcClient );
        break;
    default:
        break;
    }

    QFont ft( font() );
    ft.setPixelSize( rcClient.height() / 30 );
    ft.setWeight(QFont::Black);

    painter.setFont( ft );
    QFontMetricsF fm( ft );
    qreal dW = fm.width( m_strEscapeMsg );
    qreal dH = fm.height();
    QRectF rcText( rcClient.center().x() - (dW / 2.f),
                  rcClient.height() / 4 - (dH / 2.f),
                  dW, dH );

    QPen penText( Qt::SolidLine );
    penText.setColor( QColor(160,160,160) );
    painter.setPen( penText );
    painter.drawText( rcText, m_strEscapeMsg, QTextOption(Qt::AlignCenter) );

    painter.end();
}
Beispiel #26
0
void KateTextAnimation::draw(QPainter & painter)
{
  // could happen in corner cases: timeLine emitted finished(), but this object
  // is not yet deleted. Therefore, draw() might be called in paintEvent().
  if (m_timeLine->state() == QTimeLine::NotRunning) {
    return;
  }

  // get current rect and fill background
  QRectF rect = rectForText();
  painter.fillRect(rect, m_attribute->background());

  // scale font with animation
  QFont f = m_view->view()->renderer()->currentFont();
  f.setBold(m_attribute->fontBold());
  f.setPointSizeF(f.pointSizeF() * (1.0 + 0.5 * m_value));
  painter.setFont(f);

  painter.setPen(m_attribute->foreground().color());
  // finally draw contents on the view
  painter.drawText(rect, m_text);
}
Beispiel #27
0
void Hello::paintEvent( QPaintEvent * )
{
    static int sin_tbl[16] = {
        0, 38, 71, 92, 100, 92, 71, 38,	0, -38, -71, -92, -100, -92, -71, -38};

    if ( t.isEmpty() )
        return;

    // 1: Compute some sizes, positions etc.
    QFontMetrics fm = fontMetrics();
    int w = fm.width(t) + 20;
    int h = fm.height() * 2;
    int pmx = width()/2 - w/2;
    int pmy = height()/2 - h/2;

    // 2: Create the pixmap and fill it with the widget's background
    QPixmap pm( w, h );
    pm.fill( this, pmx, pmy );

    // 3: Paint the pixmap. Cool wave effect
    QPainter p;
    int x = 10;
    int y = h/2 + fm.descent();
    int i = 0;
    p.begin( &pm );
    p.setFont( font() );
    while ( !t[i].isNull() ) {
        int i16 = (b+i) & 15;
        p.setPen( QColor((15-i16)*16,255,255,QColor::Hsv) );
        p.drawText( x, y-sin_tbl[i16]*h/800, t.mid(i,1), 1 );
        x += fm.width( t[i] );
        i++;
    }
    p.end();

    // 4: Copy the pixmap to the Hello widget
    bitBlt( this, pmx, pmy, &pm );
}
Beispiel #28
0
//! [0]
DragLabel::DragLabel(const QString &text, QWidget *parent)
    : QLabel(parent)
{
    QFontMetrics metric(font());
    QSize size = metric.size(Qt::TextSingleLine, text);

    QImage image(size.width() + 12, size.height() + 12,
                 QImage::Format_ARGB32_Premultiplied);
    image.fill(qRgba(0, 0, 0, 0));

    QFont font;
    font.setStyleStrategy(QFont::ForceOutline);
//! [0]

//! [1]
    QLinearGradient gradient(0, 0, 0, image.height()-1);
    gradient.setColorAt(0.0, Qt::white);
    gradient.setColorAt(0.2, QColor(200, 200, 255));
    gradient.setColorAt(0.8, QColor(200, 200, 255));
    gradient.setColorAt(1.0, QColor(127, 127, 200));

    QPainter painter;
    painter.begin(&image);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setBrush(gradient);
    painter.drawRoundedRect(QRectF(0.5, 0.5, image.width()-1, image.height()-1),
                            25, 25, Qt::RelativeSize);

    painter.setFont(font);
    painter.setBrush(Qt::black);
    painter.drawText(QRect(QPoint(6, 6), size), Qt::AlignCenter, text);
    painter.end();
//! [1]

//! [2]
    setPixmap(QPixmap::fromImage(image));
    m_labelText = text;
}
void kernelinfo::print()
{
    // ###### Rewrite to use QSimpleRichText to print here as well
    const int Margin = 10;
    int pageNo = 1;

    if ( printer->setup(this) ) {		// printer dialog
	statusBar()->message( tr("Printing...") );
	QPainter p;
	if( !p.begin( printer ) )               // paint on printer
	    return;

	p.setFont( e->font() );
	int yPos	= 0;			// y-position for each line
	QFontMetrics fm = p.fontMetrics();
	QPaintDeviceMetrics metrics( printer ); // need width/height
						// of printer surface
	for( int i = 0 ; i < e->lines() ; i++ ) {
	    if ( Margin + yPos > metrics.height() - Margin ) {
		QString msg( "Printing (page " );
		msg += QString::number( ++pageNo );
		msg += ")...";
		statusBar()->message( msg );
		printer->newPage();		// no more room on this page
		yPos = 0;			// back to top of page
	    }
	    p.drawText( Margin, Margin + yPos,
			metrics.width(), fm.lineSpacing(),
			ExpandTabs | DontClip,
			e->text( i ) );
	    yPos = yPos + fm.lineSpacing();
	}
	p.end();				// send job to printer
	statusBar()->message( tr("Printing completed"), 2000 );
    } else {
	statusBar()->message( tr("Printing aborted"), 2000 );
    }
}
Beispiel #30
-1
void PMenu::create_pixmap( QPixmap &buf, PMenuItem *item, QPopupMenu *menu)
{
  int w, h;
  QPainter p;
  QFontMetrics fm = menu->fontMetrics();   // size of font set for this widget

  w  = 2 + item->pixmap.width() + 4 + fm.width( item->text_name ) + 2;
  h = ( item->pixmap.height() > fm.height() ? item->pixmap.height() : fm.height() ) + 4; 
  
  buf.resize( w, h );                    // resize pixmap
  buf.fill( menu->backgroundColor() );   // clear it
  
  p.begin( &buf );
  p.drawPixmap( 2, 2, item->pixmap );              // use 2x2 border
  p.setFont( menu->font() );
  p.drawText( 2 + item->pixmap.width() + 4,        // center text in item
	      0, w, h,
	      AlignVCenter | ShowPrefix | DontClip | SingleLine,
	      item->text_name );
  p.end();
}