QString MomentumImageHelper::fromText(QString /*text*/)
{
    qDebug()<<qApp->font();

    bb::device::DisplayInfo displayInfo;
    //int w=displayInfo.pixelSize().width(), h=displayInfo.pixelSize().height();
    int w = 320, h = 100;

    QImage finalImage(w, h, QImage::Format_ARGB32_Premultiplied);

    QPainter textPainter;
    textPainter.begin(&finalImage);
    qDebug()<<"1";
    finalImage.fill(Qt::white);
    textPainter.setPen(QPen(Qt::red, 12, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
    qDebug()<<"Pen set";
    qDebug()<<textPainter.font();
    //qDebug()<<textPainter.fontInfo().family();
    //textPainter.drawLine(QPoint(0, 0), QPoint(320, 100));
    QFont arial("Arial", 10, 100, TRUE);
    textPainter.setFont(arial);
    qDebug()<<textPainter.font();

    //textPainter.drawText(QRectF(0, 0, 320, 100), Qt::AlignCenter, "I");
    qDebug()<<"2";

    finalImage.save(QDir::home().absoluteFilePath("image.png"), "png");

    return QDir::home().absoluteFilePath("image.png");
    //return bb::ImageData::fromPixels(finalImage.bits(), bb::PixelFormat::RGBA_Premultiplied, w, h, finalImage.bytesPerLine());
}
Example #2
0
void KColorCombo::slotActivated( int index )
{
	if ( index == 0 )
	{
	    if ( KColorDialog::getColor( customColor, this ) == QDialog::Accepted )
		{
			QPainter painter;
			QPen pen;
			QRect rect( 0, 0, width(), QFontMetrics(painter.font()).height()+4);
			QPixmap pixmap( rect.width(), rect.height() );

			if ( qGray( customColor.rgb() ) < 128 )
				pen.setColor( white );
			else
				pen.setColor( black );

			painter.begin( &pixmap );
			QBrush brush( customColor );
			painter.fillRect( rect, brush );
			painter.setPen( pen );
			painter.drawText( 2, QFontMetrics(painter.font()).ascent()+2, i18n("Custom...") );
			painter.end();

			changeItem( pixmap, 0 );
			pixmap.detach();
		}

		internalcolor = customColor;
	}
	else
		internalcolor = standardPalette[ index - 1 ];

	emit activated( internalcolor );
}
Example #3
0
void KColorCombo::addColors()
{
    QPainter painter;
    QPen pen;
    QRect rect(0, 0, width(), QFontMetrics(painter.font()).height() + 4);
    QPixmap pixmap(rect.width(), rect.height());
    int i;

    clear();
    if(d->showEmptyList)
        return;

    createStandardPalette();

    for(i = 0; i < STANDARD_PAL_SIZE; i++)
        if(standardPalette[i] == internalcolor)
            break;

    if(i == STANDARD_PAL_SIZE)
        customColor = internalcolor;

    if(qGray(customColor.rgb()) < 128)
        pen.setColor(white);
    else
        pen.setColor(black);

    painter.begin(&pixmap);
    QBrush brush(customColor);
    painter.fillRect(rect, brush);
    painter.setPen(pen);
    painter.drawText(2, QFontMetrics(painter.font()).ascent() + 2, i18n("Custom..."));
    painter.end();

    insertItem(pixmap);
    pixmap.detach();

    for(i = 0; i < STANDARD_PAL_SIZE; i++)
    {
        painter.begin(&pixmap);
        QBrush brush(standardPalette[i]);
        painter.fillRect(rect, brush);
        painter.end();

        insertItem(pixmap);
        pixmap.detach();

        if(standardPalette[i] == internalcolor)
            setCurrentItem(i + 1);
    }
}
Example #4
0
  void DrawCardLine( QPainter& painter, int x, int y, int width, int height, const QString& name, int count ) const {
    painter.save();
    painter.drawText( x, y, width, height, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextDontClip, name );

    if( count > 1 ) {
      int nameWidth = QFontMetrics( painter.font() ).width( name + " " );
      QString countString = QString( "x%1" ).arg( count );
      QFont font = painter.font();
      font.setBold( true );
      painter.setFont( font );
      painter.drawText( x + nameWidth, y, width - nameWidth, height, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextDontClip, countString );
    }
    painter.restore();
  }
Example #5
0
QImage TextToolDlg::image()
{
    QBitmap bitmap(1000, 100);
    QPainter painter;

    painter.begin(&bitmap);
    QFont font = painter.font();
    font.setFamily(m_font.family());
    font.setPixelSize(m_size);
    painter.setFont(font);
    painter.setPen(QPen(Qt::color0));
    QRect boundingRect = painter.boundingRect(0, 0, 1000, 100, Qt::AlignLeft | Qt::AlignTop, m_text);
    painter.end();

    int boundingWidth = boundingRect.width();
    int boundingHeight = boundingRect.height();
    bitmap = bitmap.copy(0, 0, boundingWidth, boundingHeight); // a resize
    painter.begin(&bitmap);
    painter.setFont(font);
    bitmap.fill(Qt::color0);
    painter.setPen(QPen(Qt::color1));
    painter.drawText(0, 0, boundingWidth, boundingHeight, Qt::AlignLeft | Qt::AlignTop, m_text);
    painter.end();

    QImage image = bitmap.toImage();

    return image;
}
void TalkingTreeView::paintEvent ( QPaintEvent * event )
{
    QTreeView::paintEvent(event);
    if (model()->rowCount()==0)
    {
        QPainter painter (this->viewport ());
        int w = this->viewport ()->width();
        int h = this->viewport ()->height();
        QFont f = painter.font();
        f.setItalic(true);
        painter.setFont(f);
        QFontMetrics fm(f);
        QString text = tr("Drag and drop one or more image\\n or video files here");
        QStringList list = text.split("\\n");
        if (list.size()<2)
            return ;
        text = list.at(0);
        QString text2 = list.at(1);
        int textWidth = fm.width(text);
        int textWidth2 = fm.width(text2);
        int posX = w/2 - (textWidth/2);
        int posY = h/2 - fm.height()/2;
        int posX2 = w/2 - (textWidth2/2);
        int posY2 = h/2 - fm.height()/2 +fm.height();

        painter.drawText (posX, posY, text);
        painter.drawText (posX2, posY2, text2);
    }
}
Example #7
0
//-----------------------------------------------------------------------------
//!
//-----------------------------------------------------------------------------
void tWindPlotGraph::DrawTimeLabelAndGridLine(QPainter& painter, QPen& gridPen, int timeIncrement)
{
    // Work out the Y position for the label and grid line
    int samplePosition;

    // Calculate the samplePosition
    samplePosition = timeIncrement * 60000;
    samplePosition /= tDigitalTimePlotDataManager::Instance()->GetSamplePeriod(m_TimePlotRange);

    qreal y = m_GraphConfig.originY + (samplePosition * m_GraphConfig.pixPerTime);

    QFontMetrics fm = QFontMetrics(painter.font());

    // Draw the label
    QString label = QString("%1").arg(timeIncrement);
    QRect boundingRect = fm.boundingRect( label );

    int w = contentsRect().width();

    QRectF textRect = QRectF((w - m_GraphConfig.centreMarginWidth) / 2, y - (boundingRect.height() / 2), m_GraphConfig.centreMarginWidth, boundingRect.height() );
    painter.drawText(textRect, Qt::AlignCenter, label );

    QPen savedPen = painter.pen();

    // draw grid lines
    if ( (samplePosition != 0) && (samplePosition != m_TimePlotData[0].GetMaxNumberOfSamples()) )
    {
        painter.setPen( gridPen );
        painter.drawLine( m_GraphConfig.originX[0], static_cast<int>(y), m_GraphConfig.originX[0] + m_GraphConfig.extentX[0], static_cast<int>(y) );
        painter.drawLine( m_GraphConfig.originX[1], static_cast<int>(y), m_GraphConfig.originX[1] + m_GraphConfig.extentX[1], static_cast<int>(y) );
    }

    painter.setPen(savedPen);
}
Example #8
0
//! [2]
QRect BasicToolsPlugin::mouseMove(const QString &brush, QPainter &painter,
                                  const QPoint &oldPos, const QPoint &newPos)
{
    painter.save();

    int rad = painter.pen().width() / 2;
    QRect boundingRect = QRect(oldPos, newPos).normalized()
                         .adjusted(-rad, -rad, +rad, +rad);
    QColor color = painter.pen().color();
    int thickness = painter.pen().width();
    QColor transparentColor(color.red(), color.green(), color.blue(), 0);
//! [2] //! [3]

    if (brush == tr("Pencil")) {
        painter.drawLine(oldPos, newPos);
    } else if (brush == tr("Air Brush")) {
        int numSteps = 2 + (newPos - oldPos).manhattanLength() / 2;

        painter.setBrush(QBrush(color, Qt::Dense6Pattern));
        painter.setPen(Qt::NoPen);

        for (int i = 0; i < numSteps; ++i) {
            int x = oldPos.x() + i * (newPos.x() - oldPos.x()) / (numSteps - 1);
            int y = oldPos.y() + i * (newPos.y() - oldPos.y()) / (numSteps - 1);

            painter.drawEllipse(x - (thickness / 2), y - (thickness / 2),
                                thickness, thickness);
        }
    } else if (brush == tr("Random Letters")) {
        QChar ch('A' + (qrand() % 26));

        QFont biggerFont = painter.font();
        biggerFont.setBold(true);
        biggerFont.setPointSize(biggerFont.pointSize() + thickness);
        painter.setFont(biggerFont);

        painter.drawText(newPos, QString(ch));

        QFontMetrics metrics(painter.font());
        boundingRect = metrics.boundingRect(ch);
        boundingRect.translate(newPos);
        boundingRect.adjust(-10, -10, +10, +10);
    }
    painter.restore();
    return boundingRect;
}
Example #9
0
// Build an icon for any attachments
QString NoteFormatter::findIcon(qint32 lid, Resource r, QString appl) {

    // First get the icon for this type of file
    QString fileName = global.fileManager.getDbaDirPath(QString::number(lid) +appl);
    QIcon icon = QFileIconProvider().icon(QFileInfo(fileName));

    // Build a string name for the display
    QString displayName;
    if (r.__isset.attributes && r.attributes.__isset.fileName)
        displayName = QString::fromStdString(r.attributes.fileName);
    else
        displayName =  appl.toUpper() +" " +QString(tr("File"));

    // Setup the painter
    QPainter p;

    // Setup the font
    QFont font=p.font() ;
    font.setPointSize ( 8 );
    font.setFamily("Arial");
    QFontMetrics fm(font);
    int width =  fm.width(displayName);
    if (width < 40)  // steup a minimum width
        width = 40;
    width=width+50;  // Add 10 px for padding & 40 for the icon

    // Start drawing a new pixmap for  the image in the note
    QPoint textPoint(40,15);
    QPoint sizePoint(40,29);
    QPixmap pixmap(width,37);
    pixmap.fill();

    p.begin(&pixmap);
    p.setFont(font);
    p.drawPixmap(QPoint(3,3), icon.pixmap(QSize(30,40)));

    // Write out the attributes of the file
    p.drawText(textPoint, displayName);

    QString unit = QString(tr("Bytes"));
    qint32 size = QFileInfo(fileName).size();
    if (size > 1024) {
        size = size/1024;
        unit = QString(tr("KB"));
    }
    if (size > 1024) {
        size = size/1024;
        unit= QString("MB");
    }
    p.drawText(sizePoint, QString::number(size).trimmed() +" " +unit);
    p.drawRect(0,0,width-1,37-1);   // Draw a rectangle around the image.
    p.end();

    // Now that it is drawn, we write it out to a temporary file
    QString tmpFile = global.fileManager.getTmpDirPath(QString::number(lid) + QString("_icon.png"));
    pixmap.save(tmpFile, "png");
    return tmpFile;
}
void ZoomableAssemblyOverview::drawCoordLabels(QPainter & p) {
    const static int xoffset = 4;
    const static int yoffset = 3;

    U2OpStatusImpl status;

    //Prepare text
    QString visibleStartText = QString::number(visibleRange.startPos);
    QString visibleEndText = QString::number(visibleRange.endPos());
    QString visibleDiffText = QString::number(visibleRange.length);
    insertSpaceSeparators(visibleStartText);
    insertSpaceSeparators(visibleEndText);
    insertSpaceSeparators(visibleDiffText);

    //Prepare font
    QFont font = p.font();
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
        font.setStyleHint(QFont::SansSerif, (QFont::StyleStrategy)(QFont::PreferAntialias | QFont::ForceIntegerMetrics));
#else
        font.setStyleHint(QFont::SansSerif, QFont::PreferAntialias);
#endif
    p.setFont(font);
    QFontMetrics fontMetrics(font, this);

    p.setPen(labelForegroundColor);

    //draw Visible Region
    QString visibleRegionText = tr("%1 to %2 (%3 bp)").arg(visibleStartText).arg(visibleEndText).arg(visibleDiffText);
    QRect grtRect = QRect(0, 0, fontMetrics.width(visibleRegionText), fontMetrics.height());
    grtRect.translate(xoffset, rect().height() - yoffset - grtRect.height());
    if(rect().contains(grtRect)) {
        p.fillRect(grtRect, labelBackgroundColor);
        p.drawText(grtRect, visibleRegionText);
    }

    //draw Selected Region
    qint64 from = browser->getXOffsetInAssembly();
    qint64 to = qMin(browser->getXOffsetInAssembly() + browser->basesCanBeVisible(), model->getModelLength(status));

    //prepare text
    QString fromText = QString::number(from + 1); // because of 1-based coords
    QString toText = QString::number(to);
    QString diff = QString::number(to - from);

    insertSpaceSeparators(fromText);
    insertSpaceSeparators(toText);
    insertSpaceSeparators(diff);

    //draw text
    QString selectedRegionText = tr("%1 to %2 (%3 bp)").arg(fromText, toText, diff);
    QRect srtRect = QRect(0, 0, fontMetrics.width(selectedRegionText), fontMetrics.height());
    srtRect.translate(rect().width() - srtRect.width() - xoffset, rect().height() - yoffset - grtRect.height());
    if(rect().contains(srtRect) && !srtRect.intersects(grtRect)) {
        p.fillRect(srtRect, labelBackgroundColor);
        p.drawText(srtRect, selectedRegionText);
    }
}
Example #11
0
void dslDial::paint(QPainter &p, QRectF dialRect, QColor dialColor, bool hover, bool inc)
{
    p.setRenderHint(QPainter::Antialiasing, true);
    p.setPen(dialColor);
    p.setBrush(dialColor);

    int dialStartAngle = 225 * 16;
    int dialSpanAngle = -270 * 16;

    // draw dial arc
    p.drawArc(dialRect, dialStartAngle, dialSpanAngle);
    // draw ticks
    p.save();
    p.translate(dialRect.center());
    p.rotate(45);
    for (uint64_t i = 0; i < _div; i++) {
        // draw major ticks
        p.drawLine(0, dialRect.width()/2+3, 0, dialRect.width()/2+8);
        // draw minor ticks
        for (uint64_t j = 0; (j < 5) && (i < _div - 1); j++) {
            p.drawLine(0, dialRect.width()/2+3, 0, dialRect.width()/2+5);
            p.rotate(54.0/(_div-1));
        }
    }
    // draw pointer
    p.rotate(90+270.0/(_div-1)*_sel);
    p.drawEllipse(-3, -3, 6, 6);
    p.drawLine(3, 0, 0, dialRect.width()/2-3);
    p.drawLine(-3, 0, 0, dialRect.width()/2-3);
    p.restore();
    // draw value
    uint64_t displayValue = _value[_sel]*_factor;
    uint64_t displayIndex = 0;
    while(displayValue / _step >= 1) {
        displayValue = displayValue / _step;
        displayIndex++;
    }
    QString pText = QString::number(displayValue) + _unit[displayIndex] + "/div";
    QFontMetrics fm(p.font());
    const QRectF valueRect = QRectF(dialRect.left(), dialRect.bottom()-dialRect.width()*0.3+fm.height()*0.5, dialRect.width(), fm.height());
    p.drawText(valueRect, Qt::AlignCenter, pText);

    // draw +/-
    if (hover) {
        const int arcInc = 15;
        const QRectF hoverRect = QRectF(dialRect.left()-arcInc, dialRect.top()-arcInc, dialRect.width()+arcInc*2, dialRect.height()+arcInc*2);
        const double arcSpan = hoverRect.width()/(2*sqrt(2));
        p.drawArc(hoverRect, 135 * 16, -90 * 16);
        if (inc)
            p.drawLine(hoverRect.center().x()+arcSpan, hoverRect.center().y()-arcSpan,
                       hoverRect.center().x()+arcSpan-4, hoverRect.center().y()-arcSpan-10);
        else
            p.drawLine(hoverRect.center().x()-arcSpan, hoverRect.center().y()-arcSpan,
                       hoverRect.center().x()-arcSpan+4, hoverRect.center().y()-arcSpan-10);
    }
}
Example #12
0
void SpeedGraph::drawNoData(QSize size, QPainter& painter)
{
	QFont font = painter.font();
	
	font.setPixelSize(20);
	
	painter.setFont(font);
	painter.setPen(Qt::gray);
	painter.drawText(QRect(QPoint(0,0), size), Qt::AlignHCenter | Qt::AlignVCenter, tr("NO DATA"));
}
QSliderTime::QSliderTime( QSlider *ksl, QWidget *parent, const char *name)
					: QWidget (parent,name)
{
kslider=ksl;

QPainter painter;
QFontMetrics qfmt(painter.font());
fontheight=qfmt.height();

}
void QtPrinterSymbolTextPainter::paint(const QPoint& aPoint, QPainter& aPainter, const QFont& aFontLower)
{
	Q_UNUSED(aFontLower)

	QPixmap* pixmap=pixmaps.value(aPainter.font().key());
	if(pixmap==NULL)
	{
		QPixmap fullResPixmap;
		fullResPixmap.load(QString(IMAGE_FILE_TYPE)+':'+ IMAGE_NAME);
		delete pixmap;
		QSize fullSize=aPainter.fontMetrics().boundingRect(PROTOTYPE_TEXT).size();
		QSize realSize(fullSize.width()*SIZE_FACTOR, fullSize.height()*SIZE_FACTOR);
		deltaX=(fullSize.width()-realSize.width())/2;
		deltaY=(fullSize.height()-realSize.height())/2;
		pixmap = new QPixmap(fullResPixmap.scaled(realSize));
		pixmaps.insert(aPainter.font().key(), pixmap);
	}
	aPainter.drawPixmap(QPoint(aPoint.x()+deltaX, aPoint.y()+deltaY), *pixmap);
}
Example #15
0
 //over ridden method
 //draws the text to the screen.
 void draw(QPainter& p) {
   QFont font = p.font();   
   font.setPointSize(textSize);
  p.setFont(font);
   QString qs = QString::fromStdString(text);  
   
  p.drawText((int)x,(int)y,qs);
  
  //std::cout << "drawing text: " << text << " | " << qs.toStdString() << std::endl;
 }
Example #16
0
const int TabbedWidget::drawButton(int position, QPainter& painter)
{
    /* Draws the tab buttons. */

    static int x = 0;
    QPixmap tmp_pixmap;

    areas[position] = 0;
    x = (!position) ? 0 : x;

    // Initialize the painter.
    painter.setPen(font_color);
    painter.setFont((position == current_position) ? selected_font : unselected_font);

    // Draw the left border.
    if (position == current_position)
        tmp_pixmap = selected_left_image;
    else if (position != current_position + 1)
        tmp_pixmap = separator_image;

    painter.drawPixmap(x, 0, tmp_pixmap);
    areas[position] += tmp_pixmap.width();
    x += tmp_pixmap.width();

    // Draw the main contents.
    int width;
    QFontMetrics metrics(painter.font());

    width = metrics.width(captions[position]) + 10;

    tmp_pixmap = (position == current_position) ? selected_image : unselected_image;
    painter.drawTiledPixmap(x, 0, width, height(), tmp_pixmap);

    painter.drawText(x, 0, width + 1, height() + 1,
                     Qt::AlignHCenter | Qt::AlignVCenter,  captions[position]);

    areas[position] += width;
    x += width;

    // Draw the right border if needed.
    if (position == current_position)
    {
        painter.drawPixmap(x, 0, selected_right_image);
        areas[position] += selected_right_image.width();
        x += selected_right_image.width();
    }
    else if (position == (int) items.count() - 1)
    {
        painter.drawPixmap(x, 0, separator_image);
        areas[position] += separator_image.width();
        x += separator_image.width();
    }

    return x;
}
Example #17
0
void MapEditorWidget::paintAxis(){
  QPainter p;
  p.begin(this);
  
  p.setRenderHint(QPainter::Antialiasing);

  p.setPen(QColor("#000000"));
  p.setBrush(QBrush());
  p.drawRect(plotArea);

  p.setPen(QColor("#000000"));
  
  QString maxY = QString::number(scaledPlotArea().bottomRight().y(),'g',4);
  QString minY = QString::number(scaledPlotArea().topLeft().y(),'g',4);
  QPointF pos = QPointF(plotArea.topLeft());
  QFontMetrics fm(p.font());
  pos.rx() -= fm.boundingRect(maxY).width()+5;
  pos.ry() += fm.boundingRect(maxY).height()/2;
  p.drawText(pos,maxY);

  pos = QPointF(plotArea.topLeft().x(),plotArea.bottomRight().y());
  pos.rx() -= fm.boundingRect(minY).width()+5;
  pos.ry() += fm.boundingRect(minY).height()/2-5;
  p.drawText(pos,minY);

  QString maxX = QString::number(scaledPlotArea().bottomRight().x(),'g',4);
  QString minX = QString::number(scaledPlotArea().topLeft().x(),'g',4);

  pos = QPointF(plotArea.topLeft().x(),plotArea.bottomRight().y());
  pos.rx() -= fm.boundingRect(minX).width()/2;
  pos.ry() += fm.boundingRect(minX).height();
  p.drawText(pos,minX);

  pos = QPointF(plotArea.bottomRight());
  pos.rx() -= fm.boundingRect(maxX).width();
  pos.ry() += fm.boundingRect(maxX).height();
  p.drawText(pos,maxX);

  if(!xLabel.isEmpty()){
    pos = QPointF(plotArea.bottomRight());
    pos.rx() -= fm.boundingRect(xLabel).width()/2+plotArea.width()/2;
    pos.ry() += fm.boundingRect(xLabel).height();
    p.drawText(pos,xLabel);
  }

  if(!yLabel.isEmpty()){
    pos = QPointF(-plotArea.topLeft().y(),plotArea.topLeft().x());
    p.rotate(-90);
    pos.ry() -= fm.boundingRect(yLabel).height()/2;
    pos.rx() -= fm.boundingRect(yLabel).width()/2+plotArea.height()/2;
    p.drawText(pos,yLabel);
  }

}
Example #18
0
int drv_painter(int drvid, void *a0, void* a1, void* a2, void* a3, void* a4, void* a5, void* a6, void* a7, void* a8, void* a9)
{
    handle_head* head = (handle_head*)a0;
    QPainter *self = (QPainter*)head->native;
    switch (drvid) {
    case PAINTER_INIT: {
        drvNewHead(a0,new QPainter);
        break;
    }
    case PAINTER_DESTROY: {
        drvDelObj(a0,self);
        break;
    }
    case PAINTER_BEGIN: {
        self->begin(drvGetWidget(a1));
        break;
    }
    case PAINTER_END: {
        self->end();
        break;
    }
    case PAINTER_SETFONT: {
        self->setFont(drvGetFont(a1));
        break;
    }
    case PAINTER_FONT: {
        drvSetFont(a1,self->font());
        break;
    }
    case PAINTER_DRAWPOINT: {
        self->drawPoint(drvGetPoint(a1));
        break;
    }
    case PAINTER_DRAWLINE: {
        self->drawLine(drvGetPoint(a1),drvGetPoint(a2));
        break;
    }
    case PAINTER_DRAWLINES: {
        self->drawLines(drvGetPoints(a1));
        break;
    }
    case PAINTER_DRAWPOLYLINE: {
        self->drawPolyline(drvGetPoints(a1));
        break;
    }
    case PAINTER_DRAWTEXT: {
        self->drawText(drvGetPoint(a1),drvGetString(a2));
        break;
    }
    default:
        return 0;
    }
    return 1;
}
Example #19
0
void tGauge::DrawText( QPainter& painter, const QRect& rect, const QString& text, int ptAdjust )
{
    if( m_OutlineText )
    {
        int fontSize = painter.font().pixelSize();
        Assert( fontSize > 0 );

        tTextStyleAttributes textStyle(
            (uchar)(fontSize + ptAdjust), painter.pen().color(), palette().base().color(),
            Fonts::CENTER_CENTER, painter.font().bold() );
        textStyle.m_halo = m_OutlineText;
        if (m_InvertedText)
            qSwap( textStyle.m_color, textStyle.m_bkgColor );
        tRenderText::renderString( text, painter.font().family(), textStyle, rect.center(), painter );
    }
    else
    {
        painter.drawText( rect, text );
    }
}
Example #20
0
void TWorldDisplay::DrawWaitingPlayers(QPainter& painter) {
    int x = 0.5 * WORLD_WIDTH * World->Scale + World->OffsetX;
    int y = 0.5 * WORLD_HEIGHT * World->Scale + World->OffsetY;
    QPen pen(Qt::white);
    painter.setPen(pen);
    painter.setFont(QFont("arial", 28));
    QString text = "Waiting for players...";
    QFontMetrics fm(painter.font());
    int textWidth = fm.width(text);
    painter.drawText(x - textWidth / 2, y, text);
}
Example #21
0
void MSAOverview::showWarning(QPainter& painter, QPaintEvent *e, const QString& warningMessage) {
    painter.fillRect(rect(), Qt::gray);

    QFontMetrics metrics(painter.font(), this);
    painter.drawText(rect(), Qt::AlignCenter, metrics.elidedText(
        warningMessage,
        Qt::ElideRight,
        rect().width()));

    QWidget::paintEvent(e);
    return;
}
Example #22
0
 //over ridden method
 //draws the text to the screen.
 void draw(QPainter& p) {
   //QColor qcolor(122,122,122);
   //p.setPen(Qt::black);
   QFont font = p.font();   
   font.setPointSize(textSize);
  p.setFont(font);
   QString qs = QString::fromStdString(text);  
   
  p.drawText((int)x,(int)y,qs);
  
  //std::cout << "drawing text: " << text << " | " << qs.toStdString() << std::endl;
 }
Example #23
0
void SamuLife::paintEvent ( QPaintEvent* )
{
  QPainter qpainter ( this );



  for ( int i {0}; i<gameOfLife->getH(); ++i )
    {
      for ( int j {0}; j<gameOfLife->getW(); ++j )
        {

          if ( lattice )
            {
              if ( lattice[i][j] )
                qpainter.fillRect ( j*movieCapWidth, i*movieCapHeight,
                                    movieCapWidth, movieCapHeight, Qt::black );
              else
                qpainter.fillRect ( j*movieCapWidth, i*movieCapHeight,
                                    movieCapWidth, movieCapHeight, Qt::white );
            }
          if ( prediction )
            {
              if ( prediction[i][j] )
                qpainter.fillRect ( gameOfLife->getW() *movieCapWidth + j*movieCapWidth, i*movieCapHeight,
                                    movieCapWidth, movieCapHeight, Qt::black );
              else
                qpainter.fillRect ( gameOfLife->getW() *movieCapWidth + j*movieCapWidth, i*movieCapHeight,
                                    movieCapWidth, movieCapHeight, Qt::white );
            }
          qpainter.setPen ( QPen ( Qt::red, 1 ) );

          qpainter.drawRect ( j*movieCapWidth, i*movieCapHeight,
                              movieCapWidth, movieCapHeight );

          qpainter.setPen ( QPen ( Qt::blue, 1 ) );

          qpainter.drawRect ( gameOfLife->getW() *movieCapWidth + j*movieCapWidth, i*movieCapHeight,
                              movieCapWidth, movieCapHeight );
        }
    }

  QFont font = qpainter.font() ;
  font.setPointSize ( 28 );
  qpainter.setFont ( font );
  qpainter.setPen ( QPen ( Qt::red, 1 ) );
  qpainter.drawText ( 40, 60, "Reality" );
  qpainter.setPen ( QPen ( Qt::blue, 1 ) );
  qpainter.drawText ( gameOfLife->getW() *movieCapWidth +40, 60, "Samu's prediction" );
  qpainter.setPen ( QPen ( Qt::gray, 1 ) );
  qpainter.drawText ( 40, gameOfLife->getH() *movieCapHeight - 30 , QString::number(gameOfLife->getT()) );

  qpainter.end();
}
Example #24
0
void MainWindow::paintEvent(QPaintEvent *e)
{
    QPainter *painter = new QPainter(this);

    // Applies soft edges
    painter->setRenderHint(QPainter::Antialiasing);

    // Pens and brushes
    QPen polygonPen(QColor(35,177,77));
    polygonPen.setWidth(5);
    QBrush polygonBrush(QColor(35,177,77));

    QPen rightCirclePen(QColor(35,177,77));
    rightCirclePen.setWidth(10);
    QBrush rightCircleBrush(QColor(35,177,77));

    QPen rectanglePen(QColor(127,127,127));
    rectanglePen.setWidth(10);
    QBrush rectangleBrush(QColor(136,0,22));

    QPen rectangle2Pen(QColor(35,177,77));
    rectangle2Pen.setWidth(5);
    QBrush rectangle2Brush(QColor(255,255,255,0));

    rectangle rect2(90, 80, 310, 280, rectangle2Pen, rectangle2Brush);
    rect2.draw(painter);

    // Draw rectangle
    rectangle rect(100, 100, 160, 160, rectanglePen, rectangleBrush);
    rect.draw(painter);

    // Draw right circle
    ellipse rightEl(movingCircleX, movingCircleY, 120, 120, rightCirclePen, rightCircleBrush);
    rightEl.draw(painter);


    plygon polygon(polygonPen, polygonBrush);
    polygon.addPoint(QPoint(100, 260));
    polygon.addPoint(QPoint(100, 340));
    polygon.addPoint(QPoint(220, 340));
    polygon.draw(painter);



    // Draw text
    painter->setPen(QColor(35,177,77));
    painter->setBrush(QColor(35,177,77));
    QFont font = painter->font() ;
    font.setPixelSize(36);
    painter->setFont(font);

    painter->drawText( 180, 310, "Тест");
}
Example #25
0
void ColorCombo::addColors()
{
	QPainter painter;
	QPen pen;
	QRect rect( 0, 0, width(), QFontMetrics( font() ).height()+4 );
	QPixmap pixmap( rect.width(), rect.height() );
	int i;

	clear();

	createPalettes();

	for ( i = 0; i < paletteSize[ m_colorScheme ]; i++ )
		if ( palette[ m_colorScheme ][i] == internalColor ) break;

	if ( i == paletteSize[ m_colorScheme ] )
		customColor = internalColor;

	if ( qGray( customColor.rgb() ) < 128 )
		pen.setColor( Qt::white );
	else
		pen.setColor( Qt::black );

	const bool isSuccess = painter.begin( &pixmap );
    if (!isSuccess) {
        qWarning() << Q_FUNC_INFO << " painter not active";
    }
	QBrush brush( customColor );
	painter.fillRect( rect, brush );
	painter.setPen( pen );
	painter.drawText( 2, QFontMetrics(painter.font()).ascent()+2, i18n("Custom...") );
	painter.end();

	insertItem( pixmap );
	pixmap.detach();

	for ( i = 0; i < paletteSize[ m_colorScheme ]; i++ )
	{
		painter.begin( &pixmap );
		QBrush brush( palette[ m_colorScheme ][i] );
		painter.fillRect( rect, brush );
		painter.end();

		insertItem( pixmap );
		pixmap.detach();

		if ( palette[ m_colorScheme ][i] == internalColor )
			setCurrentItem( i + 1 );
	}
}
Example #26
0
void KoTabBarPrivate::drawTab( QPainter& painter, QRect& rect, const QString& text, bool active )
{
    QPolygon polygon;
    
    if( !reverseLayout )
        polygon << QPoint( rect.x(), rect.y() )
           << QPoint( rect.x(), rect.bottom()-3 )
           << QPoint( rect.x()+2, rect.bottom() )
           << QPoint( rect.right()-4, rect.bottom() )
           << QPoint( rect.right()-2, rect.bottom()-2 )
           << QPoint( rect.right()+5, rect.top() );
    else      
        polygon << QPoint( rect.right(), rect.top() )
           << QPoint( rect.right(), rect.bottom()-3 )
           << QPoint( rect.right()-2, rect.bottom() )
           << QPoint( rect.x()+4, rect.bottom() )
           << QPoint( rect.x()+2, rect.bottom()-2 )
           << QPoint( rect.x()-5, rect.top() );

    painter.save();

    // fill it first  
    QBrush bg = tabbar->palette().background();
    if( active )
       bg = tabbar->palette().base();
    painter.setBrush( bg );
    painter.setPen( QPen( Qt::NoPen ) );
    painter.drawPolygon( polygon );

    // draw the lines
    painter.setPen( tabbar->palette().color( QPalette::Dark) );
    painter.setRenderHint( QPainter::Antialiasing );
    if( !active )
      painter.drawLine( rect.x() - (reverseLayout ? 5 : 0), rect.y(),
                                     rect.right() + (reverseLayout ? 0 : 5), rect.top() );

    painter.drawPolyline( polygon );

    painter.setPen( tabbar->palette().color( QPalette::ButtonText ) );
    QFont f = painter.font();
    if( active ) f.setBold( true );
    painter.setFont( f );
    QFontMetrics fm = painter.fontMetrics();
    int tx =  rect.x() + ( rect.width() - fm.width( text ) ) / 2;
    int ty =  rect.y() + ( rect.height() - fm.height() ) / 2 + fm.ascent();
    painter.drawText( tx, ty, text );

    painter.restore();
}
    TransparencyLayer(const QPainter& p, int width, int height)
    {
        pixmap = new QPixmap(width, height);

        painter = new QPainter(pixmap);
        painter->setPen(p.pen());
        painter->setBrush(p.brush());
        painter->setMatrix(p.matrix());
#if QT_VERSION >= 0x040200
        painter->setOpacity(p.opacity());
#endif
        painter->setFont(p.font());
        painter->setCompositionMode(p.compositionMode());
        painter->setClipPath(p.clipPath());
    }
Example #28
0
static void drawVertCmRuler(QPainter &painter, int x, int y1, int y2)
{
    painter.drawLine(x, y1, x, y2);
    const int dpI = painter.device()->logicalDpiY();
    const int dpCm = qRound(double(dpI) / 2.54);
    const int h = dpCm / 2;
    const QFontMetrics fm(painter.font());
    for (int cm = 0, y = y1; y < y2; y += dpCm, ++cm) {
        painter.drawLine(x, y, x + h, y);
        if (cm) {
            const QString n = QString::number(cm);
            const QRect br = fm.boundingRect(n);
            painter.drawText(x + h + 10, y + br.height() / 2, n);
        }
    }
}
Example #29
0
static void drawHorizCmRuler(QPainter &painter, int x1, int x2, int y)
{
    painter.drawLine(x1, y, x2, y);
    const int dpI = painter.device()->logicalDpiX();
    const int dpCm = qRound(double(dpI) / 2.54);
    const int h = dpCm / 2;
    const QFontMetrics fm(painter.font());
    for (int cm = 0, x = x1; x < x2; x += dpCm, ++cm) {
        painter.drawLine(x, y, x, y - h);
        if (cm) {
            const QString n = QString::number(cm);
            const QRect br = fm.boundingRect(n);
            painter.drawText(x - br.width() / 2, y - h - 10, n);
        }
    }
}
Example #30
0
void DSlider::paintEvent(QPaintEvent *event)
{
    Q_D(DSlider);

    QPainter painter;
    painter.begin(this);

    // draw tips
    QFont font = painter.font();
    font.setPixelSize(12);
    painter.setFont(font);

    QPen pen = painter.pen();
    pen.setColor(d->m_tipColor);
    painter.setPen(pen);

    QRect tmp = rect().adjusted(CustomDrawingLeftPadding - 5, 0, -CustomDrawingRightPadding + 5, 0);

    QTextOption leftBottomOption;
    leftBottomOption.setAlignment(Qt::AlignLeft | Qt::AlignBottom);
    painter.drawText(tmp, d->m_leftTip, leftBottomOption);

    QTextOption rightBottomOption;
    rightBottomOption.setAlignment(Qt::AlignRight | Qt::AlignBottom);
    painter.drawText(tmp, d->m_rightTip, rightBottomOption);

    // draw scales
    pen.setColor(d->m_scaleColor);
    painter.setPen(pen);

    foreach(int scale, d->m_scales) {
        int x = d->getScalePosition(scale);
        int y = height() - 8;
        painter.drawLine(x, y, x, y - CustomDrawingScaleHeight);
    }

    if (d->m_handleHovering && !d->m_hoverTimout) {
        QString str = QString::number(value());
        int x = d->getScalePosition(value()) - painter.fontMetrics().width(str) / 2.0;
        painter.setPen(d->m_hoverValueColor);
        painter.drawText(x, 10, str);
    }

    painter.end();

    QSlider::paintEvent(event);
}