MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / drawImage

Method drawImage

src/Gui/SoTextLabel.cpp:633–720  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

631}
632
633void SoFrameLabel::drawImage()
634{
635 const SbString* s = string.getValues(0);
636 int num = string.getNum();
637 if (num == 0) {
638 this->image = SoSFImage();
639 return;
640 }
641
642 QFont font(QString::fromLatin1(QByteArray(name.getValue())), size.getValue());
643 QFontMetrics fm(font);
644 int w = 0;
645 int h = fm.height() * num;
646 const SbColor& b = backgroundColor.getValue();
647 QColor backgroundBrush;
648 backgroundBrush.setRgbF(b[0], b[1], b[2]);
649 const SbColor& t = textColor.getValue();
650 QColor front;
651 front.setRgbF(t[0], t[1], t[2]);
652 const QPen borderPen(QColor(0, 0, 127), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
653
654 QStringList lines;
655 for (int i = 0; i < num; i++) {
656 QString line = QString::fromUtf8(s[i].getString());
657 w = std::max<int>(w, QtTools::horizontalAdvance(fm, line));
658 lines << line;
659 }
660
661 int padding = 5;
662
663 bool drawIcon = false;
664 QImage iconImg;
665 int widthIcon = 0;
666 int heightIcon = 0;
667 if (!iconPixmap.isNull()) {
668 drawIcon = true;
669 iconImg = iconPixmap.toImage();
670 widthIcon = iconImg.width() + 2 * padding;
671 heightIcon = iconImg.height() + 2 * padding;
672 }
673
674 int widthText = w + 2 * padding;
675 int heightText = h + 2 * padding;
676 int widthTotal = widthText + widthIcon;
677 int heightTotal = heightText > heightIcon ? heightText : heightIcon;
678 int paddingTextV = (heightTotal - h) / 2;
679 int paddingIconV = (heightTotal - iconImg.height()) / 2;
680
681 QImage image(widthTotal, heightTotal, QImage::Format_ARGB32_Premultiplied);
682 image.fill(0x00000000);
683 QPainter painter(&image);
684 painter.setRenderHint(QPainter::Antialiasing);
685
686 SbBool drawFrame = frame.getValue();
687 SbBool drawBorder = border.getValue();
688 if (drawFrame || drawBorder) {
689 painter.setPen(drawBorder ? borderPen : QPen(Qt::transparent));
690 painter.setBrush(QBrush(drawFrame ? backgroundBrush : Qt::transparent));

Callers 6

drawMethod · 0.45
savePictureMethod · 0.45
grabFramebufferMethod · 0.45
imageFromFramebufferMethod · 0.45
paintEventMethod · 0.45
printMethod · 0.45

Calls 15

SoSFImageClass · 0.85
horizontalAdvanceFunction · 0.85
getNumMethod · 0.80
heightMethod · 0.80
setPenMethod · 0.80
QByteArrayClass · 0.70
QPointClass · 0.70
QColorClass · 0.50
getValuesMethod · 0.45
getValueMethod · 0.45
getStringMethod · 0.45
isNullMethod · 0.45

Tested by

no test coverage detected