void AverageSceneItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); //set posistion this->setPos(75*m_qpChannelPosition.x(), -75*m_qpChannelPosition.y()); painter->setRenderHint(QPainter::Antialiasing, true); // //Plot bounding rect / drawing region of this item // painter->drawRect(this->boundingRect()); //Plot stim time painter->save(); paintStimLine(painter); painter->restore(); //Plot average data painter->save(); paintAveragePath(painter); painter->restore(); // Plot channel name QStaticText staticElectrodeName = QStaticText(m_sChannelName); QSizeF sizeText = staticElectrodeName.size(); painter->save(); QPen pen; pen.setColor(Qt::yellow); pen.setWidthF(5); painter->setPen(pen); painter->drawStaticText(boundingRect().x(), boundingRect().y(), staticElectrodeName); painter->restore(); }
void tst_QStaticText::richTextOverridesPen() { QFont font = QApplication::font(); font.setStyleStrategy(QFont::NoAntialias); QFontMetricsF fm(font); QPixmap image(qCeil(fm.width("XXXXX")), qCeil(fm.height())); image.fill(Qt::white); { QPainter p(&image); p.setFont(font); p.setPen(Qt::green); QStaticText staticText; staticText.setText("<html><body><font color=\"#ff0000\">XXXXX</font></body></html>"); staticText.setTextFormat(Qt::RichText); p.drawStaticText(0, 0, staticText); } QImage img = image.toImage(); for (int x=0; x<img.width(); ++x) { for (int y=0; y<img.height(); ++y) { QRgb pixel = img.pixel(x, y); QVERIFY(pixel == QColor(Qt::white).rgba() || pixel == QColor(Qt::red).rgba()); } } }
void koregui::FrameBufferStageItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { QBrush b; QPen p; QFont font("Arial"); QStaticText text; p.setStyle(Qt::PenStyle::NoPen); b.setColor((isSelected())?QColor(86,86,86):QColor(44,44,44)); b.setStyle(Qt::BrushStyle::SolidPattern); painter->setPen(p); painter->setBrush(b); painter->drawRect(0, 0, _bufferwidth, _bufferheight); font.setBold(true); font.setPointSize(12); painter->setFont(font); text.setText(_name.c_str()); p.setColor(QColor(255,255,255)); p.setStyle(Qt::PenStyle::SolidLine); painter->setPen(p); painter->drawStaticText(10,10, text); painter->drawImage(_bufferwidth - 26, 10, QImage("./assets/icons/gear.png")); }
void QGLView::prepareTextTexture(const QStaticText &staticText, QFont font) { if (m_textTextList.contains(staticText)) { return; } if (m_textTextureList.size() > 100) // maximum of 100 rendered texts TODO: make parameter { clearTextTextures(); } QPixmap pixmap(QSize(qCeil(staticText.size().width()), qCeil(staticText.size().height()))); pixmap.fill(QColor(Qt::transparent)); QPainter painter(&pixmap); painter.setPen(Qt::white); painter.setFont(font); painter.drawStaticText(0, 0, staticText); QOpenGLTexture *texture = new QOpenGLTexture(QOpenGLTexture::Target2D); float aspectRatio = staticText.size().width()/staticText.size().height(); m_textTextList.append(staticText); m_textTextureList.append(texture); m_textAspectRatioList.append(aspectRatio); m_textImageList.append(pixmap.toImage()); }
static PyObject *meth_QStaticText_setText(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { const QString* a0; int a0State = 0; QStaticText *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "BJ1", &sipSelf, sipType_QStaticText, &sipCpp, sipType_QString,&a0, &a0State)) { Py_BEGIN_ALLOW_THREADS sipCpp->setText(*a0); Py_END_ALLOW_THREADS sipReleaseType(const_cast<QString *>(a0),sipType_QString,a0State); Py_INCREF(Py_None); return Py_None; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QStaticText, sipName_setText, doc_QStaticText_setText); return NULL; }
void koregui::NodeItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { QBrush b; QPen p; QFont font("Arial"); QStaticText text; text.setText(_sceneNode->getName().c_str()); p.setStyle(Qt::PenStyle::NoPen); painter->setPen(p); b.setStyle(Qt::BrushStyle::SolidPattern); b.setColor((isSelected())?QColor(86,86,86):QColor(44,44,44)); painter->setBrush(b); painter->drawRect(0, 0, _nodewidth, _nodeheight); font.setBold(true); font.setPointSize(12); painter->setFont(font); p.setColor(QColor(255,255,255)); p.setStyle(Qt::PenStyle::SolidLine); painter->setPen(p); painter->drawStaticText(10,10, text); }
void B6PCalendarWidget::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const { QCalendarWidget::paintCell(painter, rect, date); PlanificacionDiaPtr planificacion = model->getByDay(date, false); if ((planificacion != PlanificacionDiaPtr()) && (rect.width() > 50) && (rect.height() > 50)) { // When the conditions are matched, passed QDate is drawn as we like. int hsPlanificadas = 0; int hsEstimadas = 0; QString estado = ""; //<b>" + QString::number(date.day()) + "</b>"; QString estimado = ""; QString planificado = ""; hsPlanificadas = planificacion->HorasPlanificadas(); EstimacionDiaPtr estimacion = planificacion->Estimacion(); if (estimacion != EstimacionDiaPtr()) { hsEstimadas = estimacion->EstimacionHoras().value(); } estado = planificacion->Estado(); estimado = QString("E:%1").arg(hsEstimadas); planificado = QString("P:%2").arg(hsPlanificadas); painter->save(); painter->setPen(QColor(64, 64, 64, 192)); QFont font = painter->font(); font.setPixelSize(12); painter->setFont(font); QTextOption option; option.setAlignment(Qt::AlignLeft | Qt::AlignTop); QStaticText text; text.setTextOption(option); text.setText(estado); painter->drawStaticText(rect.left(), rect.top(), text); option.setAlignment(Qt::AlignLeft | Qt::AlignBottom); text.setText(estimado); painter->drawStaticText(rect.left(), rect.bottom() - 13, text); option.setAlignment(Qt::AlignLeft | Qt::AlignBottom); text.setText(planificado); painter->drawStaticText(rect.right() - rect.width() / 2, rect.bottom() - 13, text); painter->restore(); } }
void TFPlotSceneItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); this->setPos(10*m_qpChannelPosition.x(), -10*m_qpChannelPosition.y()); if(m_tfImage->isNull()) { // Plot shadow painter->setPen(Qt::NoPen); painter->setBrush(Qt::darkGray); painter->drawEllipse(-12, -12, 30, 30); //Plot red if bad if(m_bIsBadChannel) { painter->setBrush(Qt::red); painter->drawEllipse(-15, -15, 30, 30); } else { painter->setBrush(m_cChannelColor); painter->drawEllipse(-15, -15, 30, 30); } //Plot selected item if(this->isSelected()){ //painter->setPen(QPen(QColor(255,84,22), 5)); painter->setPen(QPen(Qt::red, 5)); painter->drawEllipse(-15, -15, 30, 30); } // Plot electrode name painter->setPen(QPen(Qt::black, 1)); QStaticText staticElectrodeName = QStaticText(m_sChannelName); QSizeF sizeText = staticElectrodeName.size(); painter->drawStaticText(-15+((30-sizeText.width())/2), -32, staticElectrodeName); } else { painter->drawImage(QRectF(-30, -15, 60, 30), *m_tfImage); // Plot electrode name painter->setPen(QPen(Qt::black, 1)); QStaticText staticElectrodeName = QStaticText(m_sChannelName); QSizeF sizeText = staticElectrodeName.size(); painter->drawStaticText(-30+((60-sizeText.width())/2), -32, staticElectrodeName); } }
void koregui::ShaderPassItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { QBrush b; QPen p; QFont font("Arial"); QStaticText text; p.setStyle(Qt::PenStyle::NoPen); b.setColor((isSelected())?QColor(86,86,86):QColor(66,66,66)); b.setStyle(Qt::BrushStyle::SolidPattern); painter->setPen(p); painter->setBrush(b); painter->drawRect(0, 0, _shaderwidth, _shaderheight); font.setBold(true); font.setPointSize(12); painter->setFont(font); painter->drawImage(_shaderwidth - 26, 10, QImage("./assets/icons/gear.png")); text.setText(_name.c_str()); p.setColor(QColor(255,255,255)); p.setStyle(Qt::PenStyle::SolidLine); painter->setPen(p); painter->drawStaticText(10,10, text); font.setFamily("Consolas"); font.setPointSize(9); p.setColor(QColor(200,200,200)); painter->setPen(p); painter->setFont(font); int tmpheight = 40; for (uint i = 0; i<_attributes.size(); i++) { text.setText(_attributes[i]->getInput()->name.c_str()); painter->drawStaticText(12,tmpheight + 30 * i, text); } tmpheight += 30 * _attributes.size(); for (uint i = 0; i<_uniforms.size(); i++) { text.setText(_uniforms[i]->getInput()->name.c_str()); painter->drawStaticText(12,tmpheight + 30 * i, text); } }
void tst_QStaticText::plainTextVsRichText() { QPixmap imagePlainText(1000, 1000); imagePlainText.fill(Qt::white); { QPainter p(&imagePlainText); QStaticText staticText; staticText.setText("FOObar"); staticText.setTextFormat(Qt::PlainText); p.drawStaticText(10, 10, staticText); } QPixmap imageRichText(1000, 1000); imageRichText.fill(Qt::white); { QPainter p(&imageRichText); QStaticText staticText; staticText.setText("<html><body>FOObar</body></html>"); staticText.setTextFormat(Qt::RichText); p.drawStaticText(10, 10, staticText); } #if defined(DEBUG_SAVE_IMAGE) imagePlainText.save("plainTextVsRichText_imagePlainText.png"); imageRichText.save("plainTextVsRichText_imageRichText.png"); #endif QCOMPARE(imagePlainText, imageRichText); }
void tst_QStaticText::setFont() { QFont font = QApplication::font(); font.setBold(true); font.setPointSize(28); QPixmap imageDrawText(1000, 1000); imageDrawText.fill(Qt::white); { QPainter p(&imageDrawText); p.drawText(QRectF(0, 0, 1000, 1000), 0, "Lorem ipsum dolor sit amet, consectetur adipiscing elit."); p.setFont(font); p.drawText(QRectF(11, 120, 1000, 1000), 0, "Lorem ipsum dolor sit amet, consectetur adipiscing elit."); } QPixmap imageDrawStaticText(1000, 1000); imageDrawStaticText.fill(Qt::white); { QPainter p(&imageDrawStaticText); QStaticText text; text.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); text.setTextFormat(Qt::PlainText); p.drawStaticText(0, 0, text); p.setFont(font); p.drawStaticText(11, 120, text); } #if defined(DEBUG_SAVE_IMAGE) imageDrawText.save("setFont_imageDrawText.png"); imageDrawStaticText.save("setFont_imageDrawStaticText.png"); #endif QCOMPARE(imageDrawStaticText, imageDrawText); }
void text_display::paintEvent(QPaintEvent *event) { int offset = get_offset(); int end_offset = get_rows() * get_columns() + offset; QPainter painter(this); QColor text = palette().color(QPalette::WindowText); painter.setPen(text); painter.setFont(editor_font::get_font()); painter.setClipping(true); const bookmark_map *bookmarks = buffer->get_bookmark_map(); if(bookmarks){ for(const auto &bookmark : *bookmarks){ selection bookmark_selection = selection::create_selection( buffer->snes_to_pc(bookmark.address), bookmark.size); //non-sequential just skip if(bookmark_selection.get_end_byte() < offset || bookmark_selection.get_start_byte() > end_offset){ continue; } paint_selection(painter, bookmark_selection, bookmark.color); } } if(editor->is_comparing()){ auto diffs = editor->get_diff(); for(auto &diff : *diffs){ if(diff.get_end_byte() < offset){ continue; }else if(diff.get_start_byte() > end_offset){ //sequential, break early break; } paint_selection(painter, diff, diff_color); } } selection selection_area = get_selection(); selection_color.setAlpha(170); if(selection_area.is_active()){ paint_selection(painter, selection_area, selection_color); } painter.setClipRegion(event->region()); if(!selection_area.is_active()){ painter.setClipping(false); QPoint cursor_position = nibble_to_screen(get_cursor_nibble()); if(cursor_state && focusPolicy() != Qt::NoFocus){ painter.fillRect(cursor_position.x(), cursor_position.y(), cursor_width, editor_font::get_height(), text); } QRect active_line(0, cursor_position.y(), get_line_characters() * editor_font::get_width(), editor_font::get_height()); painter.fillRect(active_line, selection_color); } for(int i = offset, row = 0; i < end_offset; i += get_columns(), row++){ int real_row = i / get_columns(); if(!row_cache.contains(real_row)){ int line_end = i + get_columns(); if(line_end > buffer->size()){ line_end = buffer->size(); } QString line; QTextStream string_stream(&line); get_line(i, line_end, string_stream); QStaticText *text = new QStaticText(line); text->setTextFormat(Qt::PlainText); row_cache.insert(real_row, text); } if(row * editor_font::get_height() >= event->rect().y()){ painter.drawStaticText(0, row * editor_font::get_height(), *row_cache.object(real_row)); } } }
void DActionsListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { //QStyledItemDelegate::paint(painter, option, index); static const QPixmap deleteIconPixMap(":/icons/icons/delete-crosshair-icon.png"); static const QPixmap keepIconPixMap(":/icons/icons/keep-vgood-icon.png"); DItem item = index.data().value<DItem>(); DLS::FileProperty fprop = item.property; QString name; QString size; const QFontMetrics& metrics = option.fontMetrics; QRect rect_major = option.rect; rect_major.translate( 3, 3 ); //Need to trim... but hey!, translation alone serves us for now... QRect rect_minor = rect_major; const QPen originalPen = painter->pen(); if(option.state & QStyle::State_Selected) painter->fillRect( option.rect, QColor(250, 255, 180, 250)); else painter->fillRect( option.rect, QColor(255, 255, 255, 255) ); //aka WHITE QPen borderHighlightPen(originalPen); borderHighlightPen.setColor( QColor(Qt::red) ); painter->setPen( borderHighlightPen ); painter->drawRect( option.rect ); painter->setPen(originalPen); const QFont originalFont = painter->font(); QFont fnt = originalFont; fnt.setBold(true); if(item.isGroupHeader) { if(option.state & QStyle::State_Selected) { painter->fillRect( option.rect, QColor(130, 200, 130) ); groupHeaderSelected(index); } else painter->fillRect( option.rect, QColor(100, 100, 200, 100) ); name = item.header.topString(); int headerC = item.header.itemCount(); if(item.header.value()) size = fileSizeAsString( item.header.value() * headerC ) + " in total"; else size = "Not Available"; if(name.isEmpty()) return; const QString freeable( fileSizeAsString( (headerC - 1) * item.header.value()) + " can be freed" ); const QString fileCounts( QString::number( headerC ) + " Files :: " + QString::number( headerC - 1) + " duplicates" ); //qreal dx = rect_major.width() / 3.0; //painter->translate( dx, 0 ); painter->setFont( fnt ); painter->setPen( QColor(20, 40, 30) ); painter->drawText(rect_major, Qt::AlignLeft | Qt::AlignTop, name, &rect_minor); rect_minor.translate(0, rect_minor.height() ); painter->setPen( QColor(120, 50, 70) ); painter->drawText(rect_minor, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, size, &rect_major); painter->setFont( originalFont ); rect_major.translate( rect_major.width() + 10, 0); rect_major.setWidth( rect_major.width() + 600 ); painter->drawText(rect_major, Qt::AlignTop | Qt::AlignLeft, fileCounts, &rect_minor); rect_minor.translate( rect_minor.width() + 10, 0 ); rect_minor.setWidth( rect_minor.width() + 30 ); painter->drawText(rect_minor, Qt::AlignLeft | Qt::AlignTop, freeable); return; } name = fileNameAsString( fprop.getFilePath() ); size = fileSizeAsString( fprop.getSize() ); if(name.isEmpty()) return; const static QStaticText fileSizeStatic( "File Size: "); const static QStaticText fileNameStatic( "File Name: "); painter->drawStaticText(rect_major.topLeft(), fileNameStatic); rect_major.translate( metrics.width( fileNameStatic.text() ) , 0); rect_minor.translate( 0, metrics.height() ); painter->drawStaticText(rect_minor.topLeft(), fileSizeStatic); painter->setFont( fnt ); painter->setPen( QColor(20, 40, 30) ); QString elidedName = elidedText(metrics, (rect_major.width() - (rect_major.width() * 2.25/10)), Qt::ElideLeft, name ); painter->drawText(rect_major, Qt::AlignLeft | Qt::AlignTop, elidedName, &rect_minor); rect_minor.translate(0, rect_minor.height() ); painter->setPen( QColor(120, 50, 70) ); const static int k_align = Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap; painter->drawText(rect_minor, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, size, &rect_major); rect_major.setX( 200 ); rect_major.setWidth( rect_major.width() + 300 ); painter->setPen( QColor(Qt::red) ); QString keepingWeight("Keeping Weight: " + QString::number( item.keepingWeight ) ); QString deletionWeight("Deletion Weight " + QString::number( item.deletionWeight)); painter->drawText( rect_major, k_align, deletionWeight); rect_major.translate( 200, 0 ); painter->setPen( QColor(0, 220, 0) ); painter->drawText( rect_major, k_align, keepingWeight ); //drawPixMaps as necessary static const int dd = 20; int dx1 = option.rect.width() * 0.95; int dy1 = option.rect.height() * 0.2 + option.rect.top(); QRect checkedIconArea(dx1, dy1, dd, dd); if(item.isKeepChecked) painter->drawPixmap(checkedIconArea, keepIconPixMap); else if(item.isDeleteChecked) painter->drawPixmap(checkedIconArea, deleteIconPixMap); //restore original painter->setFont( originalFont ); painter->setPen( originalPen ); }