/*! * \en * Print browser content. * \_en * \ru * Печатает содержимое браузера. * \_ru */ void aReportBrowser::print() { QPrinter printer; QPainter p; if (!printer.setup()) return; if ( p.begin( &printer ) ){ QPaintDeviceMetrics metrics( p.device() ); int dpiy = metrics.logicalDpiY(); int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins QRect body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin ); QSimpleRichText richText( textBrowser->text(), QFont(), textBrowser->context(), textBrowser->styleSheet(), textBrowser->mimeSourceFactory(), body.height() ); richText.setWidth( &p, body.width() ); QRect view( body ); int page = 1; do { richText.draw( &p, body.left(), body.top(), view, colorGroup() ); view.moveBy( 0, body.height() ); p.translate( 0 , -body.height() ); p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ), view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) ); if ( view.top() >= richText.height() ) break; printer.newPage(); page++; } while (TRUE); } }
QPixmap IDLabel::merge(const QPixmap *pix, const QString &txt) { QPainter p; QPixmap temp(1, 1); p.begin(&temp); p.setFont(font()); int strWidth = p.fontMetrics().width( txt ); int strHeight = p.fontMetrics().height(); p.end(); int pixWidth = pix->width(), pixExtra = (pixWidth << 1) / 3; int pixHeight = pix->height(); int maxHeight = (strHeight > pixHeight ? strHeight + 2 : pixHeight); QPixmap res(strWidth + pixExtra, maxHeight); // res.fill(Qt::white); res.fill(QColor(253, 230, 153, 255)); p.begin(&res); p.setFont(font()); p.drawText(QRect( 0, 2, strWidth, strHeight), 0, txt); p.drawPixmap(strWidth - (pixWidth - pixExtra), 0, *pix); p.end(); return res; }
void ColorPalette::drawTimeHistoryPannel(QPainter &painter) { painter.save(); float x = draw_erae_.left()+5; float y = draw_erae_.top()+5; float width = draw_erae_.width() - 10; float height = draw_erae_.height() - 10; QPen pen; pen.setColor(Qt::black); painter.setPen(pen); painter.setFont(QFont(QObject::tr("WenQuanYi"),8)); painter.drawRect(QRectF(x,y,draw_erae_.width() - 10,draw_erae_.height() - 10)); painter.fillRect(QRectF(x + 2,y + height*0.2,height*0.6,height*0.6),Qt::blue); painter.fillRect(QRectF(x + 2 + width/4,y + height*0.2,height*0.6,height*0.6),Qt::green); painter.fillRect(QRectF(x + 2 + width/2,y + height*0.2,height*0.6,height*0.6),Qt::yellow); painter.fillRect(QRectF(x + 2 + 3*width/4,y + height*0.2,height*0.6,height*0.6),Qt::red); // QString mag; // mag.sprintf("%0.1f",minmagnitude_); QString s1 = "<0.00";//QString(" < %1 ").arg(mag); float width2 = painter.fontMetrics().width(s1); float height2 = painter.fontMetrics().height(); QString s2 = ">=0.00"; float width3 = painter.fontMetrics().width(s2); QString s3 = ">=1.00"; QString s4 = ">=2.00"; painter.drawText(QRectF(x + 3 + height*0.6,y + height*0.2-1,width2,height2),s1); painter.drawText(QRectF(x + 3 +width/4+ height*0.6,y + height*0.2-1,width3,height2),s2); painter.drawText(QRectF(x + 3 +width/2+ height*0.6,y + height*0.2-1,width3,height2),s3); painter.drawText(QRectF(x + 3 +3*width/4+ height*0.6,y + height*0.2-1,width3,height2),s4); painter.restore(); }
void MapWidget::drawMarker(const MapMarker &marker, QPainter &painter, const QPointF &markerPosition, const QPointF &rectPosition) { QRectF markerRect = getMarkerRect(marker, rectPosition); QColor bgColor = getMarkerTextBackgroundColor(); painter.setBrush(QBrush(bgColor)); // drawing the line connector painter.setPen(bgColor); painter.setClipping(true); painter.setClipRegion(QRegion(rect()).subtracted(markerRect.toRect())); painter.drawLine(markerRect.center(), markerPosition); // drawing the transparent background painter.setClipping(false); painter.setPen(Qt::NoPen); painter.drawRect(markerRect); // drawing the player marker const static qreal markerSize = 1.6; painter.setBrush(getMarkerColor()); painter.drawEllipse(markerPosition, markerSize, markerSize); qreal hOffset = rectPosition.x() + TEXT_MARGIM; // left margin // draw the player name text QString playerName = marker.getPlayerName(); painter.setFont(userFont); QFontMetrics metrics = painter.fontMetrics(); qreal playerNameWidth = metrics.width(playerName); painter.setPen(getMarkerTextColor()); qreal textY = rectPosition.y() + TEXT_MARGIM + metrics.descent()/2.0; painter.drawText(hOffset, textY, playerName); hOffset += playerNameWidth + TEXT_MARGIM * 3; // draw the player country name painter.setFont(countryFont); metrics = painter.fontMetrics(); QColor countryNameColor(getMarkerTextColor()); countryNameColor.setAlpha(180); // country name is drawed using some alpha painter.setPen(countryNameColor); QString countryName = marker.getCountryName(); painter.drawText(hOffset, textY, countryName); hOffset += metrics.width(countryName); painter.setFont(userFont); //restore the normal font metrics = painter.fontMetrics(); // draw the player country flag const QImage &image = marker.getFlag(); qreal imageX = hOffset + TEXT_MARGIM; qreal imageY = rectPosition.y() - image.height()/2.0; painter.drawImage(QPointF(imageX, imageY), image); }
void IntervalProgressDisplay::EllipticalPaintStrategy::drawCurrentBeatValue(QPainter &p, const QRectF &rect, const PaintContext &context, const PaintColors &colors) { // draw current beat text in center p.setPen(QPen(colors.textColor, 1.0f)); font.setPointSizeF(context.fontSize); p.setFont(font); QString numberString(QString::number(context.currentBeat + 1) + " / " + QString::number(context.beatsPerInterval)); int strWidth = p.fontMetrics().width(numberString); p.drawText(rect.center().x() - strWidth / 2, rect.center().y() + p.fontMetrics().height()/2, numberString); }
int HeliCanvas::draw(QPainter &p, const QSize &size) { int tmp = _labelMargin; _labelMargin = p.fontMetrics().width("00:00-"); QSize oldSize = _size; resize(p.fontMetrics(), size); render(p); std::swap(_labelMargin, tmp); resize(p.fontMetrics(), oldSize); return tmp; }
void SignalPlot::buildBackground() { mBackground = QImage(this->size(), QImage::Format_RGB32); mBackground.fill(mBackgroundColor); QPainter painter; painter.begin(&mBackground); const int border = 4; int bottomLine = painter.fontMetrics().boundingRect("1s").height()+border*2; int leftLine = 0; // draw channel names for(int i=0; i<mChannels; ++i) { int width = painter.fontMetrics().boundingRect(mChannelNames[i]).width(); if(leftLine<width) leftLine = width; } leftLine+= border*2; mPlotArea = this->size()-QSize(leftLine,bottomLine); for(int i=0; i<mChannels; ++i) { int offset = mPlotArea.height()/mChannels/2*(i*2+1); painter.setPen(mBorderColor); painter.drawLine(leftLine-border/2, offset, leftLine, offset); painter.setPen(mTextColor); painter.drawText(border, offset + painter.fontMetrics().boundingRect(mChannelNames[i]).height()/3, mChannelNames[i]); } for(int i=0; i<mTimeInterval; ++i) { painter.drawText(leftLine+i*mPlotArea.width()/mTimeInterval, this->size().height()-border, QString::number(i+1)); } painter.setPen(mBorderColor); painter.drawLine(leftLine, 0, leftLine, this->size().height()); painter.drawLine(0, this->size().height()-bottomLine, this->size().width(), this->size().height()-bottomLine); painter.end(); }
void GLSubView::DrawString(QPainter &painter, const QString &s, QPoint p, TextAlignment alignment) { if(alignment == RIGHT_ALIGNED) { p -= QPoint(painter.fontMetrics().width(s), 0); } else if(alignment == CENTER_ALIGNED) { p -= QPoint(painter.fontMetrics().width(s) / 2, 0); } p.setY(-p.y()); painter.drawText(p, s); }
void desktopText( const char *s = "Troll Tech" ) { const int border = 20; QColor c1 = qApp->palette()->normal().background(); QColor c2 = c1.light(104); QColor c3 = c1.dark(106); QPixmap pm(10,10); QPainter p; p.begin( &pm ); QRect r = p.fontMetrics().boundingRect( s ); p.end(); int appWidth = qApp->desktop()->width(); int appHeight = qApp->desktop()->height(); if ( r.width() > appWidth - border*2 ) r.setWidth( appWidth - border*2 ); if ( r.height() > appHeight - border*2 ) r.setHeight( appHeight - border*2 ); pm.resize( r.size() + QSize( border*2, border*2 ) ); generateStone( &pm, c1, c2, c3 ); p.begin( &pm ); drawShadeText( &p, -r.x() + border, -r.y() + border, s, c2, c3 ); p.end(); qApp->desktop()->setBackgroundPixmap( pm ); }
void DecodeTrace::draw_range(const pv::data::decode::Annotation &a, QPainter &p, int h, double start, double end, int y, const ViewItemPaintParams &pp, int row_title_width) const { const double top = y + .5 - h / 2; const double bottom = y + .5 + h / 2; const vector<QString> annotations = a.annotations(); // If the two ends are within 1 pixel, draw a vertical line if (start + 1.0 > end) { p.drawLine(QPointF(start, top), QPointF(start, bottom)); return; } const double cap_width = min((end - start) / 4, EndCapWidth); QPointF pts[] = { QPointF(start, y + .5f), QPointF(start + cap_width, top), QPointF(end - cap_width, top), QPointF(end, y + .5f), QPointF(end - cap_width, bottom), QPointF(start + cap_width, bottom) }; p.drawConvexPolygon(pts, countof(pts)); if (annotations.empty()) return; const int ann_start = start + cap_width; const int ann_end = end - cap_width; const int real_start = std::max(ann_start, pp.left() + row_title_width); const int real_end = std::min(ann_end, pp.right()); const int real_width = real_end - real_start; QRectF rect(real_start, y - h / 2, real_width, h); if (rect.width() <= 4) return; p.setPen(Qt::black); // Try to find an annotation that will fit QString best_annotation; int best_width = 0; for (const QString &a : annotations) { const int w = p.boundingRect(QRectF(), 0, a).width(); if (w <= rect.width() && w > best_width) best_annotation = a, best_width = w; } if (best_annotation.isEmpty()) best_annotation = annotations.back(); // If not ellide the last in the list p.drawText(rect, Qt::AlignCenter, p.fontMetrics().elidedText( best_annotation, Qt::ElideRight, rect.width())); }
//------------------------------------------------------------------------------ // void QEAnalogIndicator::drawAxisText (QPainter & painter, QPoint & textCentre, QString & text, const int pointSize) { QFont pf (this->font ()); if (pointSize > 0) { pf.setPointSize (pointSize); } painter.setFont (pf); QFontMetrics fm = painter.fontMetrics (); QPen pen; int x; int y; // Centre text. For height, pointSize seems better than fm.height () // painter.drawText needs bottom left coordinates. // if (this->isLeftRight ()) { x = textCentre.x () - fm.width (text)/2; y = textCentre.y () + pf.pointSize (); } else { x = textCentre.x (); y = textCentre.y () + (pf.pointSize () + 1) / 2; } pen.setColor (this->getFontPaintColour ()); painter.setPen (pen); // If text too wide, then ensure we show most significant part. // painter.drawText (MAX (1, x), y, text); }
void BasicBlockItem::paintText(QPainter& p) { auto fm = p.fontMetrics(); static_cast<DisassemblyPrinter*>(m_pPrinter)->SetPainter(&p); Print(); static_cast<DisassemblyPrinter*>(m_pPrinter)->SetPainter(nullptr); }
void Editor::print() { #ifndef QT_NO_PRINTER if ( printer.setup(this) ) { // opens printer dialog printer.setFullPage(TRUE); // we'll set our own margins QPainter p; p.begin( &printer ); // paint on printer p.setFont( e->font() ); QFontMetrics fm = p.fontMetrics(); QPaintDeviceMetrics metrics( &printer ); // need width/height // of printer surface const int MARGIN = metrics.logicalDpiX() / 2; // half-inch margin int yPos = MARGIN; // y position for each line for( int i = 0 ; i < e->numLines() ; i++ ) { if ( printer.aborted() ) break; if ( yPos + fm.lineSpacing() > metrics.height() - MARGIN ) { // no more room on this page if ( !printer.newPage() ) // start new page break; // some error yPos = MARGIN; // back to top of page } p.drawText( MARGIN, yPos, metrics.width() - 2*MARGIN, fm.lineSpacing(), ExpandTabs, e->textLine( i ) ); yPos += fm.lineSpacing(); } p.end(); // send job to printer } #endif }
void TimelineVis::processVis() { proc_to_order = QMap<int, int>(); order_to_proc = QMap<int, int>(); for (int i = 0; i < trace->num_tasks; i++) { proc_to_order[i] = i; order_to_proc[i] = i; } // Determine needs for task labels int max_task = pow(10,ceil(log10(trace->num_tasks)) + 1) - 1; QPainter * painter = new QPainter(); painter->begin(this); painter->setPen(Qt::black); painter->setFont(QFont("Helvetica", 10)); QLocale systemlocale = QLocale::system(); QFontMetrics font_metrics = painter->fontMetrics(); QString testString = systemlocale.toString(max_task); labelWidth = font_metrics.width(testString); labelHeight = font_metrics.height(); labelDescent = font_metrics.descent(); painter->end(); delete painter; visProcessed = true; }
void Editor::print() { const int MARGIN = 10; if ( printer.setup(this) ) { // opens printer dialog QPainter p; p.begin( &printer ); // paint on printer 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->numLines() ; i++ ) { if ( MARGIN + yPos > metrics.height() - MARGIN ) { 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->textLine( i ) ); yPos = yPos + fm.lineSpacing(); } p.end(); // send job to printer } }
void paint_QTextLayout(QPainter &p, bool useCache) { static bool first = true; static QTextLayout *textLayout[lines]; if (first) { for (int i = 0; i < lines; ++i) { textLayout[i] = new QTextLayout(strings[i]); int leading = p.fontMetrics().leading(); qreal height = 0; qreal widthUsed = 0; textLayout[i]->setCacheEnabled(useCache); textLayout[i]->beginLayout(); while (1) { QTextLine line = textLayout[i]->createLine(); if (!line.isValid()) break; line.setLineWidth(lineWidth); height += leading; line.setPosition(QPointF(0, height)); height += line.height(); widthUsed = qMax(widthUsed, line.naturalTextWidth()); } textLayout[i]->endLayout(); } first = false; } for (int i = 0; i < count; ++i) { for (int j = 0; j < lines; ++j) { textLayout[j]->draw(&p, QPoint(0, j*spacing)); } } }
void Widget::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter painter; QPainterPath path; QPen pen(Qt::darkGray); painter.begin(this); pen.setWidth(3); pen.setCapStyle(Qt::RoundCap); pen.setJoinStyle(Qt::RoundJoin); painter.setBrush(Qt::darkGray); painter.drawRect(ui->crossBlock->x(),ui->crossBlock->y(),ui->crossBlock->width(),ui->crossBlock->height()); pen.setColor(Qt::black); painter.setPen(pen); painter.drawLine(ui->crossBlock->x()+1,ui->crossBlock->y()+1,ui->crossBlock->x()+ui->crossBlock->width(),ui->crossBlock->y()+ui->crossBlock->height()); painter.drawLine(ui->crossBlock->x()+1,ui->crossBlock->y()+ui->crossBlock->height(),ui->crossBlock->x()+ui->crossBlock->width(),ui->crossBlock->y()+1); pen.setColor(Qt::yellow); painter.setPen(pen); int mca_x = ui->mcaImage->x(); int mca_y = ui->mcaImage->y(); int mcb_x = ui->mcbImage->x(); int mcb_y = ui->mcbImage->y(); int mc_width = ui->mcaImage->width(); int mc_height = ui->mcaImage->height(); painter.setBrush(Qt::NoBrush); // painter.drawRoundedRect(mca_x,mca_y,mc_width,mc_height,5,5); // painter.drawRoundedRect(mcb_x,mcb_y,mc_width,mc_height,5,5); painter.drawRect(mca_x,mca_y,mc_width,mc_height); painter.drawRect(mcb_x,mcb_y,mc_width,mc_height); // painter.setPen(Qt::NoPen); painter.setBrush(Qt::NoBrush); painter.eraseRect(mca_x-5,mca_y-5,mc_width*0.1,mc_height*1.2); painter.eraseRect(mcb_x+mc_width*0.9+5,mcb_y-5,mc_width*0.1+2,mc_height*1.2); path.moveTo(mca_x+mc_width*0.1,mca_y); path.arcTo(QRectF(mca_x+mc_width*0.1-mc_height/2,mca_y,mc_height,mc_height),90,180); pen.setColor(Qt::yellow); painter.setPen(pen); painter.drawPath(path); path.moveTo(mcb_x+mc_width*0.8,mcb_y); path.arcTo(QRectF(mcb_x+mc_width*0.9-mc_height/2,mcb_y,mc_height,mc_height),90,-180); painter.drawPath(path); int smallRectWidth =mc_width/6; int smallRectHeight= mc_height/4; painter.setBrush(Qt::yellow); painter.drawRect(mca_x+mc_width*0.3-smallRectWidth,mca_y+smallRectHeight*0.3,smallRectWidth,smallRectHeight); painter.drawRect(mca_x+mc_width-smallRectWidth*0.5-smallRectWidth,mca_y+smallRectHeight*0.3,smallRectWidth,smallRectHeight); painter.drawRect(mca_x+mc_width*0.3-smallRectWidth,mca_y+mc_height-smallRectHeight*1.3,smallRectWidth,smallRectHeight); painter.drawRect(mca_x+mc_width-smallRectWidth*0.5-smallRectWidth,mca_y+mc_height-smallRectHeight*1.3,smallRectWidth,smallRectHeight); painter.drawRect(QRectF(mcb_x+smallRectWidth*0.5,mcb_y+smallRectHeight*0.3,smallRectWidth,smallRectHeight)); painter.drawRect(QRectF(mcb_x+smallRectWidth*0.5,mcb_y+mc_height-smallRectHeight*0.3-smallRectHeight,smallRectWidth,smallRectHeight)); painter.drawRect(QRectF(mcb_x+mc_width*0.7,mcb_y+smallRectHeight*0.3,smallRectWidth,smallRectHeight)); painter.drawRect(QRectF(mcb_x+mc_width*0.7,mcb_y+mc_height-smallRectHeight*0.3-smallRectHeight,smallRectWidth,smallRectHeight)); QSize Size = painter.fontMetrics().size(Qt::TextSingleLine, str); painter.setPen(Qt::white); painter.drawText(QPointF(mca_x+mc_width/2-Size.width()/2,mca_y+mc_height/2+Size.height()/2),str); painter.drawText(QPointF(mcb_x+mc_width/2-Size.width()/2,mcb_y+mc_height/2+Size.height()/2),str); painter.end(); }
void PageWidget::drawPageNumber(int page, QPainter &p, int x, int y) { const QString pagestr(QString::number(page + 1)); const QFontMetrics mtr(p.fontMetrics()); const int txtw(mtr.width(pagestr)); p.setPen(Qt::black); p.fillRect(x - txtw - 5, y - 2 - mtr.height(), txtw + 5, mtr.height() + 4, Qt::white); p.drawText(x - txtw - 4, y - 4, pagestr); }
void ApplicationWindow::print() { #ifndef QT_NO_PRINTER 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 body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin ); QSimpleRichText richText( QStyleSheet::convertFromPlainText(e->text()), QFont(), e->context(), e->styleSheet(), e->mimeSourceFactory(), body.height() ); richText.setWidth( &p, body.width() ); QRect view( body ); int page = 1; do { richText.draw( &p, body.left(), body.top(), view, colorGroup() ); view.moveBy( 0, body.height() ); p.translate( 0 , -body.height() ); p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ), view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) ); if ( view.top() >= richText.height() ) break; printer->newPage(); page++; } while (TRUE); statusBar()->message( "Printing completed", 2000 ); } else { statusBar()->message( "Printing aborted", 2000 ); } #endif }
void AccumulateEnergy::DrawRulerDV(QPainter &painter) { //根据数据中的最大事件数确定纵坐标范围 painter.setFont(QFont(QObject::tr("WenQuanYi"),8)); float x = draw_area_range.left(); float y = draw_area_range.bottom(); int tmaxeventnum = maxeventnum_; if (tmaxeventnum == 0) { tmaxeventnum = 1; } tmaxeventnum = std::pow(10,std::log10(tmaxeventnum)); float step = dheight_ / ENERGYDYRULERFACTORY; float diff = maxeventnum_ / ENERGYDYRULERFACTORY; float vindex = 0; float count = 0; while (vindex <= dheight_) { painter.drawLine(x,y - vindex + 1,x - 2,y - vindex + 1); float width = painter.fontMetrics().width(QString::number(count)); float height = painter.fontMetrics().height(); int p = std::floor(count); painter.drawText(QRectF(x-4 - width,y-vindex + 1 - height*0.5,width,height),Qt::AlignRight,QString::number(p)); vindex += step; if (vindex < dheight_) { painter.save(); QPen pen; pen.setStyle(Qt::DashLine); pen.setColor(QColor(Qt::gray)); pen.setWidthF(1.2); painter.setPen(pen); painter.drawLine(x,y - vindex + 1,x + draw_area_range.width(),y - vindex + 1); painter.restore(); } count +=diff; } }
int KstLabel::ascent(QPainter &p) { int Ascent = 0; QFont TextFont(FontName, fontSize(p), QFont::Normal, false); p.save(); p.setFont(TextFont); Ascent = p.fontMetrics().boundingRect("1234567890").height(); p.restore(); return Ascent; }
// FIXME: expensive - cache it? int KstLabel::lineSpacing(QPainter &p) { int LineSpacing = 0; QFont TextFont(FontName, fontSize(p), QFont::Normal, false); p.save(); p.setFont(TextFont); LineSpacing = p.fontMetrics().lineSpacing(); p.restore(); return LineSpacing; }
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 QCPBase::redrawPins(QPainter & painter) { if (cpOwner->resReading) return; realignPins(painter); QPen op=painter.pen(); QBrush ob=painter.brush(); QFont of=painter.font(); QPen penPin=QPen(pinColor); QBrush brshPin=QBrush(pinColor,Qt::SolidPattern); painter.setPen(penPin); painter.setBrush(brshPin); QFont n=of; n.setBold(false); painter.setFont(n); for (int i=0;i<fInputs.count();i++) { QCPInput* a=fInputs[i]; painter.fillRect(QRect( a->relCoord.x()-QCP_PINSIZE/2, a->relCoord.y()-QCP_PINSIZE/2, QCP_PINSIZE, QCP_PINSIZE),brshPin); painter.drawText(QPoint( a->relCoord.x()+QCP_PINSIZE/2+1, a->relCoord.y()+painter.fontMetrics().height()/4), a->pinName); } for (int i=0;i<fOutputs.count();i++) { QCPOutput* a=fOutputs[i]; painter.fillRect(QRect( a->relCoord.x()-QCP_PINSIZE/2, a->relCoord.y()-QCP_PINSIZE/2, QCP_PINSIZE, QCP_PINSIZE),brshPin); painter.drawText(QPoint( a->relCoord.x()-QCP_PINSIZE/2-1 - painter.fontMetrics().width(a->pinName), a->relCoord.y()+painter.fontMetrics().height()/4), a->pinName); } painter.setFont(of); painter.setBrush(ob); painter.setPen(op); }
void BaseTrackView::drawFaderDbValue(QPainter &p) { p.setPen(DB_TEXT_COLOR); double poweredGain = Utils::linearGainToPower(levelSlider->value()/100.0); double faderDb = Utils::linearToDb(poweredGain); int precision = narrowed ? 0 : 1; QString text = QString::number(faderDb, 'f', precision); QPoint textPosition = getDbValuePosition(text, p.fontMetrics()); p.drawText(textPosition.x(), textPosition.y(), text); }
void StelQGLRenderer::drawTextGravityHelper (const TextParams& params, QPainter& painter, const int baseX, const int baseY, StelProjectorP projector) { const Vec2f viewportCenter = projector->getViewportCenterAbsolute(); const float dx = baseX - viewportCenter[0]; const float dy = baseY - viewportCenter[1]; const float d = std::sqrt(dx * dx + dy * dy); // Cull the text if it's too far away to be visible in the screen. if (d > qMax(projector->getViewportXywh()[3], projector->getViewportXywh()[2]) * 2) { return; } const QString string = params.string_; const int charCount = string.length(); const float charWidth = painter.fontMetrics().width(string) / charCount; float theta = std::atan2(dy - 1, dx); const float psi = qMin(5.0, std::atan2(charWidth, d + 1) * 180.0f / M_PI); const float xVc = viewportCenter[0] + params.xShift_; const float yVc = viewportCenter[1] + params.yShift_; const QString lang = StelApp::getInstance().getLocaleMgr().getAppLanguage(); const bool leftToRight = !QString("ar fa ur he yi ckb").contains(lang); // Draw each character separately for (int i = 0; i < charCount; ++i) { const int charIndex = leftToRight ? i : charCount - 1 - i; const float x = d * std::cos(theta) + xVc; const float y = d * std::sin(theta) + yVc; const float angle = 90.0f + theta * 180.0f / M_PI; drawText(TextParams(x, y, string[charIndex]).angleDegrees(angle)); // Compute how much the character contributes to the angle const float width = painter.fontMetrics().width(string[charIndex]); theta += psi * M_PI / 180.0 * (1 + (width - charWidth) / charWidth); } }
void ChartBase::draw_tooltip(QPainter& painter, const QPoint& mouse_position) const { size_t point_index; if (!on_chart(mouse_position, point_index)) return; const int ShiftX = 2; const int ShiftY = 2; const int MarginX = 8; const int MarginY = 5; const int FrameMargin = 3; const qreal CornerRadius = 2.0; const int Opacity = 180; const QColor TextColor(210, 210, 210, Opacity); const QColor BorderColor(40, 40, 40, Opacity); const QColor BackgroundColor(80, 80, 80, Opacity); if (m_tooltip_formatter.get() == 0) return; const Vector2d& point = m_original_points[point_index]; const QString text = m_tooltip_formatter->format(point); const QRect text_rect = painter.fontMetrics().boundingRect(QRect(), Qt::AlignCenter, text); QRect tooltip_rect( mouse_position.x() + ShiftX, mouse_position.y() - text_rect.height() - 2 * MarginY - ShiftY, text_rect.width() + 2 * MarginX, text_rect.height() + 2 * MarginY); if (tooltip_rect.left() < FrameMargin) tooltip_rect.moveLeft(FrameMargin); if (tooltip_rect.top() < FrameMargin) tooltip_rect.moveTop(FrameMargin); const int MaxRight = painter.window().right() - FrameMargin; if (tooltip_rect.right() > MaxRight) tooltip_rect.moveRight(MaxRight); const int MaxBottom = painter.window().bottom() - FrameMargin; if (tooltip_rect.bottom() > MaxBottom) tooltip_rect.moveBottom(MaxBottom); painter.setPen(BorderColor); painter.setBrush(QBrush(BackgroundColor)); painter.drawRoundedRect(tooltip_rect, CornerRadius, CornerRadius); painter.setPen(TextColor); painter.drawText(tooltip_rect, Qt::AlignCenter, text); }
void TabBarPrivate::drawTab(QPainter& painter, QRect& rect, const QString& text, bool active) { QPolygon polygon; if (tabbar->isLeftToRight()) 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) { const bool reverseLayout = tabbar->isRightToLeft(); 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 = font(active); 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(); }
/* calling the QPainter stuff. */ void ColorMapWidget::paintEvent(QPaintEvent *) { QFont f(QApplication::font()); double res; QPainter p; QString tmpDisplayedText; int i,h,yoff,ysub,cidx; int lscale; double scale; lscale = (int) floor(log10(dmax)); scale = pow(10,lscale); f.setPixelSize(11); p.begin(this); p.setFont(f); QFontMetrics fm(p.fontMetrics()); yoff = fm.lineSpacing(); ysub = fm.ascent()/2; tmpDisplayedText.sprintf("x 1 e %i",lscale); p.setPen(Qt::white); p.drawText(10,yoff,tmpDisplayedText); h = height()-3*yoff; h = h/CBAR_STEP*CBAR_STEP; yoff *= 2; if (cmap_len != h) { free_colormap(colormap); cmap_len = h; if (colorState == HSV) colormap = colormap_hsv(cmap_len); else if (colorState == GRAYSCALE) colormap = colormap_gs(cmap_len); else fprintf(stderr, "Invalid color space specified\n"); doHistogram(scaleState); } p.drawText(40, yoff+ysub, tmpDisplayedText.sprintf( "%.3f",dmax/scale)); for(i=0; i<N_LABELS-1; i++) { res = dmax - (i+1)*(dmax - dmin)/(double)(N_LABELS-1); p.drawText(40, yoff+ysub+(int)((i+1)*(h/(double)(N_LABELS-1))), tmpDisplayedText.sprintf( "%.3f",res/scale)); } for(i=0; i<cmap_len; i++) { cidx = cmap_len-1-i; p.setPen(QColor((int)(255*colormap[cidx][0]), (int)(255*colormap[cidx][1]), (int)(255*colormap[cidx][2]))); p.drawLine(10, yoff+i, 10+histogram[cidx/CBAR_STEP], yoff+i); } p.end(); }
void FractionPainter::paintWidget(QPainter & paint) { // our x position, we paint from left to right; // we don't want to start directly on the border, so add the margin int old_x = _MARGIN_X; int old_y = 0; // ratios and operation signs are painted with the same font m_font.setPointSize(24); m_font.setBold(true); paint.setFont(m_font); // set the pen for painting QPen pen(Qt::SolidLine); pen.setWidth(0); paint.setPen(pen); // get the font height; the font height doesn't change while painting QFontMetrics fm(paint.fontMetrics()); // now we can correctly set the height of the widget setMinimumHeight(2 * fm.lineSpacing() + 10); setMaximumHeight(2 * fm.lineSpacing() + 10); // get the current ratio and paint it paintRatio(paint, Ratio(leftRatio.numerator() * leftMult, leftRatio.denominator() * leftMult, false), old_x, old_y, fm); if (leftRatio.denominator() * leftMult < 10) old_x += 40; else old_x += 25; // paint the operation paintMiddle(paint, str_operation, old_x, old_y, fm, m_colorOperation); if (rightRatio.denominator() * rightMult < 10) old_x += 40; else old_x += 25; // get the current ratio and paint it paintRatio(paint, Ratio(rightRatio.numerator() * rightMult, rightRatio.denominator() * rightMult, false), old_x, old_y, fm); // stop the painter paint.end(); // the space we needed for painting is the minimum width of the widget setMinimumWidth(old_x); }