Example #1
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));
	}
}
Example #2
0
void BaseRender::resetOverlay(int width, int height)
{
    QString text = tr("Plexy Desk 1.0, Revolution Begins");
    QFontMetrics metrics = QFontMetrics(font());
    int border = qMax(4, metrics.leading());
    QRect rect =
         metrics.boundingRect(0, 0, width - 2 * border, int (height * 0.125),
         Qt::AlignCenter | Qt::TextWordWrap, text);
    d->image =
         QImage(width, rect.height() + 2 * border,
         QImage::Format_ARGB32_Premultiplied);
    d->image.fill(qRgba(0, 0, 0, 127));
    QPainter painter;
    painter.begin(&d->image);
    painter.setRenderHint(QPainter::TextAntialiasing);
    painter.setPen(Qt::white);
    painter.drawText((width - rect.width()) / 2, border,
         rect.width(), rect.height(),
         Qt::AlignCenter | Qt::TextWordWrap, text);
    painter.end();
}
Example #3
0
//Вызов диалога печати
void MainWindow::on_print_triggered()
{
    /// TODO:
    /// Добавь комменты!!!
    if (n!=0)
    {
        QString text =tabs[cur_tab]->toPlainText();
        QPrinter printer;
        QPrintDialog *dialog = new QPrintDialog(&printer);
        dialog->setWindowTitle("Print Document");
        if (dialog->exec() == QDialog::Accepted)
        {
            QPainter painter;
            painter.begin(&printer);
            painter.drawText(100, 100, 500, 500, Qt::AlignLeft|Qt::AlignTop, text);
            painter.end();
        }
    }
    else
        QMessageBox::warning(ui->tabWidget,"Error","Возможно вы не открыли/создали ни одного файла",QMessageBox::Yes,QMessageBox::Yes);
}
Example #4
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();
}
Example #5
0
void messageView::paintEvent(QPaintEvent * event)
{   Q_UNUSED(event);

    if(this->display){
        QString message = "Drawing ";
        switch(this->shape){
        case LINE:
            message+="Line ";
            break;
        case CIRCLE:
            message +="Circle ";
            break;
        default:
            break;
        }
        message+="from "+from+" to "+ to;
        QPainter* painter = new QPainter(this);
        painter->fillRect(0,0,500,50,QBrush(Qt::white));
        painter->drawText(this->x()+300,this->y()+10,message);
    }
}
Example #6
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);
    }
}
Example #7
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();
}
Example #8
0
void RegionSelect::drawRectSelection(QPainter &painter)
{
    painter.drawPixmap(selectRect, desktopPixmapClr, selectRect);
    painter.setPen(QPen(QBrush(QColor(0, 0, 0, 255)), 2));
    painter.drawRect(selectRect);

    QString txtSize = QApplication::tr("%1 x %2 pixels ").arg(selectRect.width()).arg(selectRect.height());
    painter.drawText(selectRect, Qt::AlignBottom | Qt::AlignRight, txtSize);

    if (!selEndPoint.isNull() && conf->getZoomAroundMouse() == true)
    {
        const quint8 zoomSide = 200;

        // create magnifer coords
        QPoint zoomStart = selEndPoint;
        zoomStart -= QPoint(zoomSide/5, zoomSide/5); // 40, 40

        QPoint zoomEnd = selEndPoint;
        zoomEnd += QPoint(zoomSide/5, zoomSide/5);

        // creating rect area for magnifer
        QRect zoomRect = QRect(zoomStart, zoomEnd);

        QPixmap zoomPixmap = desktopPixmapClr.copy(zoomRect).scaled(QSize(zoomSide, zoomSide), Qt::KeepAspectRatio);

        QPainter zoomPainer(&zoomPixmap); // create painter from pixmap maignifer
        zoomPainer.setPen(QPen(QBrush(QColor(255, 0, 0, 180)), 2));
        zoomPainer.drawRect(zoomPixmap.rect()); // draw
        zoomPainer.drawText(zoomPixmap.rect().center() - QPoint(4, -4), "+");

        // position for drawing preview
        QPoint zoomCenter = selectRect.bottomRight();

        if (zoomCenter.x() + zoomSide > desktopPixmapClr.rect().width() || zoomCenter.y() + zoomSide > desktopPixmapClr.rect().height())
        {
            zoomCenter -= QPoint(zoomSide, zoomSide);
        }
        painter.drawPixmap(zoomCenter, zoomPixmap);
    }
}
Example #9
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);

}
Example #10
0
void ApplicationWindow::print()
{
    printer->setFullPage( TRUE );
    if ( printer->setup(this) ) {		// printer dialog
        statusBar()->message( "Printing..." );
        QPainter p;
        if( !p.begin( printer ) ) {               // paint on printer
            statusBar()->message( "Printing aborted", 2000 );
            return;
        }

        QPaintDeviceMetrics metrics( p.device() );
        int dpiy = metrics.logicalDpiY();
        int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
        QRect view( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin );
        QSimpleRichText richText( QStyleSheet::convertFromPlainText(e->text()),
                                  QFont(),
                                  e->context(),
                                  e->styleSheet(),
                                  e->mimeSourceFactory(),
                                  view.height() );
        richText.setWidth( &p, view.width() );
        int page = 1;
        do {
            richText.draw( &p, margin, margin, view, colorGroup() );
            view.moveBy( 0, view.height() );
            p.translate( 0 , -view.height() );
            p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ),
                        view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) );
            if ( view.top() - margin >= richText.height() )
                break;
            printer->newPage();
            page++;
        } while (TRUE);

        statusBar()->message( "Printing completed", 2000 );
    } else {
        statusBar()->message( "Printing aborted", 2000 );
    }
}
Example #11
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);
}
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();
}
Example #13
0
void tileset::paintEvent(QPaintEvent *ev)
{
    QPainter painter;
    painter.begin(this);
    painter.fillRect(ev->rect(), Qt::white);

    if (highlightedRect.isValid()) {
        painter.setBrush(QColor("#ffcccc"));
        painter.setPen(Qt::NoPen);
        painter.drawRect(highlightedRect.adjusted(0, 0, -1, -1));
    }

    if(pieceRects.isEmpty()){
        painter.drawText(ev->rect(), Qt::AlignCenter, tr("Drag & Drop items to this box!\nRightclick to remove!"));
    }else{
        for (int i = 0; i < pieceRects.size(); ++i) {
            painter.drawPixmap(QRect(pieceRects[i].x(), pieceRects[i].y(), piecePixmaps[i].width(), piecePixmaps[i].height()), piecePixmaps[i]);
        }
    }

    painter.end();
}
Example #14
0
void BelowsPrg::paintEvent(QPaintEvent*)
{
   QPainter painter (this);
   QLinearGradient gradient(0,0, width(), height());
   float f = m_nProgress / (m_nMaxProgressValue * 1.0f);

   //gradient.setColorAt(f, Qt::black);
   gradient.setColorAt(0, Qt::blue);

   painter.fillRect(rect(), Qt::black);
   painter.setBrush(gradient);
   // painter.drawRect(0,0, (int)width() * f, height());
   // painter.drawRect(0,0, (int)height() * f, width());
   // painter.drawRect(width(), height(), -130, -(int)height() * f);   
   painter.drawRect(0, -height(), width(), -(int)height() * f);   
   painter.setPen(QPen(Qt::green));

   QString str = QString().setNum(m_nProgress) + "%";
   painter.drawText(rect(), Qt::AlignCenter, str);
   drawFrame(&painter);

}
Example #15
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);
}
void MaxFlowVisualizer::drawVertex(const VisableVertex &vertex, QPainter &painter) {
    VertexIndex vertexIndex = vertex.getVertexInGraphIndex();
    QPen pen(Qt::black, 2);
    // Если вершина была задействована в последнем шаге алгоритма
    // то выделяем ее красным цветом.
    if (((lastAlgoAction.getType() == AlgoAction::ACTION_SELECT
          || lastAlgoAction.getType() == AlgoAction::ACTION_RELABEL)
         && lastAlgoAction.getVertexInfo() == vertexIndex)) {
        pen.setColor(Qt::red);
    }
    if (((lastAlgoAction.getType() == AlgoAction::ACTION_PUSH)
         && (lastAlgoAction.getEdgeInfo().getFirstVertexIndex() == vertexIndex
             || lastAlgoAction.getEdgeInfo().getSecondVertexIndex() == vertexIndex))) {
        pen.setColor(Qt::red);
    }
    // Если в вершине есть избыток предпотока, то отметим ее синей заливкой.
    if (relabelToFrontAlgo.getVertexExcessFlow(vertexIndex) != 0) {
        painter.setBrush(QBrush(Qt::blue));
    }
    else {
        painter.setBrush(QBrush(Qt::lightGray));
    }
    // Исток заливаем зеленым, сток - красным.
    if (relabelToFrontAlgo.getNetwork().getSourceIndex() == vertexIndex) {
        painter.setBrush(QBrush(Qt::green));
    }
    if (relabelToFrontAlgo.getNetwork().getSinkIndex() == vertexIndex) {
        painter.setBrush(QBrush(Qt::red));
    }
    pen.setWidth(3);
    painter.setPen(pen);
    QPoint centerPoint(vertex.getCenterCoordX(), vertex.getCenterCoordY());
    painter.drawEllipse(centerPoint, vertex.getRadius(), vertex.getRadius());
    // В центре вершины выводим величину избыточного потока.
    std::string excessFlowStr = std::to_string(relabelToFrontAlgo.getVertexExcessFlow(vertexIndex));
    painter.drawText(vertex.getCenterCoordX() - vertex.getRadius() / 2,
                     vertex.getCenterCoordY() + vertex.getRadius() / 4,
                     excessFlowStr.c_str());
}
void AnimationViewerPanel::renderCelBox(QPainter& painter, const GLSprite* glSprite, QPoint spriteRenderPoint)
{
   KeyFrame::KeyFramePosition currentPosition = mpAnimationModel->getCurrentKeyFramePosition();

    if (!glSprite->isSelectable())
    {
        // unselectable cel
        painter.setPen(QColor(100, 100, 200));
        painter.setOpacity(0.5);
    }
    else if (glSprite->mID == currentPosition.mLineNo)
    {
        renderCenterPointSprite(glSprite, spriteRenderPoint, painter);
        // Cel selecte color
        painter.setPen(Qt::yellow);
        painter.setOpacity(1.0);
    }
    else
    {
        // unselected cel
        painter.setPen(Qt::white);
        painter.setOpacity(0.5);
    }

    // Draw image border rectanble
    // Calculate draw position and draw
    QRect rect = glSprite->getRect();
    rect.translate(spriteRenderPoint);
    painter.drawRect(rect);

    // Draw Text
    painter.drawText(QRect(
                            spriteRenderPoint.x() + (int)glSprite->mSpriteDescriptor.mPosition.mX,
                            spriteRenderPoint.y() + (int)glSprite->mSpriteDescriptor.mPosition.mY,
                            16,
                            16
                           ),
                     Qt::AlignCenter, QString("%0").arg(glSprite->mID + 1));
}
Example #18
0
void Card::drawCard(QPainter &painter, int vector, QRect rect, QString value)
{
    if(0 == vector || 2 == vector)//0 = draw pile, 2 == dead pile
    {
        changeImage("../Bucci-Source/Images/card_back.png");
        painter.drawPixmap(rect, *cardFace);
        painter.drawRect(rect);
    }
    else if(1 == vector)//discard pile
    {
        if(value.contains('S'))
        {
            changeImage("../Bucci-Source/Images/card_spade.png");
        }
        else if(value.contains('C'))
        {
            changeImage("../Bucci-Source/Images/card_club.png");
        }
        else if(value.contains('D'))
        {
            changeImage("../Bucci-Source/Images/card_diamond.png");
        }
        else if(value.contains('H'))
        {
            changeImage("../Bucci-Source/Images/card_heart.png");
        }
        else
        {
            changeImage("../Bucci-Source/Images/card_back.png");
        }

        QString val = value;
        val.truncate(val.indexOf(' '));
        val.insert(0,' ');
        painter.drawPixmap(rect, *cardFace);
        painter.drawRect(rect) ;
        painter.drawText(rect, val);
    }
}//end of drawCard overloaded method
Example #19
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);
}
void MyTabBar::paintEvent(QPaintEvent *)
{
    QStylePainter p(this);
    for (int index = 0; index < count(); index++)
    {
        QStyleOptionTabV3 tab;
        initStyleOption(&tab, index);
        QIcon tempIcon = tab.icon;
        QString tempText = tab.text;
        tab.icon = QIcon();
        tab.text = QString();
        p.drawControl(QStyle::CE_TabBarTab, tab);
        QPainter painter;
        painter.begin(this);
        QRect tabrect = tabRect(index);
        tabrect.adjust(0, 8, 0, -8);
        painter.drawText(tabrect, Qt::AlignBottom | Qt::AlignHCenter, tempText);
        tempIcon.paint(&painter, 0, tabrect.top(), tab.iconSize.width(), tab.iconSize.height(),
                       Qt::AlignTop | Qt::AlignHCenter);
        painter.end();
    }
}
Example #21
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();
}
Example #22
0
    void ScreenSetup::Item::paint(QPainter& _p)
    {
      int i = 0;
      for (auto& _subScreen : subScreens_)
      {
        bool _hover = i == hoverIndex_;
        _subScreen.paint(
            _hover,
            drop_ && _hover,
            dropColor_,
            _p);
        ++i;
      }

      if (subScreens_.size() > 1)
      {
        auto _rect = rect();
        // Resolution string
        QString _resStr = QString("%1 x %2").arg(screen_->size().width()).arg(screen_->size().height());
        _p.drawText(_rect,Qt::AlignHCenter,_resStr);
      }
    }
Example #23
0
inline void LineDrawer::draw( QPainter& painter,
        int xPos, int yPos, int line_width, const QString& line )
{
    QFontMetrics fm = painter.fontMetrics();
    const int fontHeight = fm.height();
    const int fontAscent = fm.ascent();

    foreach ( Chunk chunk, list ) {
        // Draw each chunk
        // LOG(logDEBUG) << "Chunk: " << chunk.start() << " " << chunk.length();
        QString cutline = line.mid( chunk.start(), chunk.length() );
        // Note that fm.width is not the same as len * maxWidth due to
        // bearings.  We could use the latter and take bearings into account,
        // but perhaps the font metics already makes width() efficient for
        // fixed width fonts.
        const int chunk_width = fm.width( cutline );
        painter.fillRect( xPos, yPos, chunk_width,
                fontHeight, chunk.backColor() );
        painter.setPen( chunk.foreColor() );
        painter.drawText( xPos, yPos + fontAscent, cutline );
        xPos += chunk_width;
    }
Example #24
0
void ProgView::paintProgrammes(QPainter& painter, QPaintEvent *event) {
	for (int i = 0; i < programmes.size(); i++) {
		Programme *prog = programmes.at(i);
		QDateTime start = getRelTime(prog->getStart());
		QDateTime stop = getRelTime(prog->getStop());
		QString channel = prog->getChannel();
		int s = getY(start);
		int min = getKey(CHANNELBAR_HEIGHT).toInt();
		s = s < min ? min : s;
		int index = channelIds.indexOf(channel);
		if (index < 0) {
			continue;
		}
		int c = getX(index);
		QRect full(c, s, getKey(CHANNEL_WIDTH).toInt(), getY(stop) - s);
		QRect rect = full.adjusted(5, 5, -5, -5);
		painter.setBrush(Qt::NoBrush);
		painter.setPen(Qt::black);
		painter.drawRect(rect);
		painter.drawText(rect, prog->getTitleList().at(0)->getValue());
	}
}
void GraphicsWidget::drawDiagnosticText(QPainter &painter, int top,
	const QString &labelText, const QString &valueText)
{
	int labelLeft = 5;
	int labelWidth = 140;
	int valueLeft = labelLeft + labelWidth + 5;
	int valueWidth = 100;

	if (!staticText.contains(labelText))
	{
		QStaticText t(labelText);
		t.setPerformanceHint(QStaticText::AggressiveCaching);
		t.setTextFormat(Qt::PlainText);
		t.setTextWidth(labelWidth);
		t.setTextOption(QTextOption(Qt::AlignRight));

		staticText.insert(labelText, t);
	}

	painter.drawStaticText(labelLeft, top, staticText.value(labelText));
	painter.drawText(QRect(valueLeft, top, valueWidth, 20), valueText, QTextOption(Qt::AlignRight));
}
Example #26
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();
}
Example #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 );
}
Example #28
-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();
}
Example #29
-1
void KTagComboBox::paintEvent( QPaintEvent * ev)
{
  QComboBox::paintEvent(ev);

  QPainter p (this);

  // Text
  QRect clip(2, 2, width() - 4, height() - 4);
#if 0
  if ( hasFocus() && style().guiStyle() != MotifStyle )
    p.setPen( colorGroup().highlightedText() );
#endif
  p.drawText(clip, AlignCenter | SingleLine, popup->text( current ));

  // Icon
  QIcon *icon = popup->iconSet( this->current );
  if (icon) {
    QPixmap pm = icon->pixmap();
    p.drawPixmap( 4, (height()-pm.height())/2, pm );
  }
}
Example #30
-1
void QHexEditPrivate::drawAscii(QPainter &painter, QFontMetrics &fm, const QColor &bc, const QColor &fc, uchar b, int &x, int y)
{
	int w;
	QString s;

	if(QChar(b).isPrint())
	{
		w = fm.width(b);
		s = QString(b);
	}
	else
	{
		w = fm.width(QHexEditPrivate::UNPRINTABLE_CHAR);
		s = QHexEditPrivate::UNPRINTABLE_CHAR;
	}

	QRect r(x, y, w, this->_charheight);
	painter.fillRect(r, bc);
	painter.setPen(fc);
	painter.drawText(r, Qt::AlignLeft | Qt::AlignTop, s);
	x += w;
}