void GraphicsDImgView::drawForeground(QPainter* p, const QRectF& rect) { QGraphicsView::drawForeground(p, rect); if (!d->movingInProgress) { QString text = d->item->userLoadingHint(); if (text.isNull() || !d->showText) { return; } QRect viewportRect = viewport()->rect(); QRect fontRect = p->fontMetrics().boundingRect(viewportRect, 0, text); QPoint drawingPoint(viewportRect.topRight().x() - fontRect.width() - 10, viewportRect.topRight().y() + 5); QPointF sceneDrawingPoint = mapToScene(drawingPoint); QRectF sceneDrawingRect(sceneDrawingPoint, fontRect.size()); if (!rect.intersects(sceneDrawingRect)) { return; } drawText(p, sceneDrawingRect, text); } }
void AddPoint(const std::vector<std::string> & inputParts, std::vector<std::shared_ptr<CShape>> & figures, std::vector<std::shared_ptr<sf::Shape>> & shapes) { double x = std::stod(inputParts[1]); double y = std::stod(inputParts[2]); std::string outlineColor = inputParts[3]; CPoint point = CPoint(x, y, outlineColor); sf::RectangleShape drawingPoint(sf::Vector2f(1, 1)); drawingPoint.setPosition((float)x, (float)y); drawingPoint.setFillColor(ConvertHexToRgb(outlineColor)); figures.push_back(std::make_shared<CPoint>(point)); shapes.push_back(std::make_shared<sf::RectangleShape>(drawingPoint)); }
void QgsPointDisplacementRenderer::drawLabels( const QPointF& centerPoint, QgsSymbolV2RenderContext& context, const QList<QPointF>& labelShifts, const QStringList& labelList ) { QPainter* p = context.renderContext().painter(); if ( !p ) { return; } QPen labelPen( mLabelColor ); p->setPen( labelPen ); //scale font (for printing) QFont pixelSizeFont = mLabelFont; pixelSizeFont.setPixelSize( context.outputLineWidth( mLabelFont.pointSizeF() * 0.3527 ) ); QFont scaledFont = pixelSizeFont; scaledFont.setPixelSize( pixelSizeFont.pixelSize() * context.renderContext().rasterScaleFactor() ); p->setFont( scaledFont ); QFontMetricsF fontMetrics( pixelSizeFont ); QPointF currentLabelShift; //considers the signs to determine the label position QList<QPointF>::const_iterator labelPosIt = labelShifts.constBegin(); QStringList::const_iterator text_it = labelList.constBegin(); for ( ; labelPosIt != labelShifts.constEnd() && text_it != labelList.constEnd(); ++labelPosIt, ++text_it ) { currentLabelShift = *labelPosIt; if ( currentLabelShift.x() < 0 ) { currentLabelShift.setX( currentLabelShift.x() - fontMetrics.width( *text_it ) ); } if ( currentLabelShift.y() > 0 ) { currentLabelShift.setY( currentLabelShift.y() + fontMetrics.ascent() ); } QPointF drawingPoint( centerPoint + currentLabelShift ); p->save(); p->translate( drawingPoint.x(), drawingPoint.y() ); p->scale( 1.0 / context.renderContext().rasterScaleFactor(), 1.0 / context.renderContext().rasterScaleFactor() ); p->drawText( QPointF( 0, 0 ), *text_it ); p->restore(); } }
void TextWidget::Draw(double x, double y) const { if (pFont == NULL) { return; } Vector2 drawingPoint(x, y); if (vAlignment == VAlignmentTop) { } else if (vAlignment == VAlignmentCenter) { drawingPoint.SetY(y + (height - GetTextHeight()) / 2); } else if (vAlignment == VAlignmentBottom) { drawingPoint.SetY(y + (height - GetTextHeight())); } double lineHeight = pFont->GetLineHeight(); for (vector<pair<string::const_iterator, string::const_iterator> >::const_iterator it = lines.begin(); it != lines.end(); it++) { // TODO: add to MLIFont functions working with iterators to avoid string copying here string line(it->first, it->second); if (hAlignment == HAlignmentLeft) { drawingPoint.SetX(x); } else if (hAlignment == HAlignmentCenter) { drawingPoint.SetX(x + (width - pFont->GetWidth(line)) / 2); } else if (hAlignment == HAlignmentRight) { drawingPoint.SetX(x + (width - pFont->GetWidth(line))); } pFont->Draw(line, drawingPoint, textColor); drawingPoint.SetY(drawingPoint.GetY() + lineHeight); } }