//-------------------------------------------------------------------------------------------------- void ImageViewDialog::setKeyPointInstancesToDisplay( const std::vector<KeyPointInstanceData>& keyPointInstances ) { mKeyPointInstances = keyPointInstances; // Remove any existing graphic items used to display the key points for ( uint32_t itemIdx = 0; itemIdx < mKeyPointGraphicItems.size(); itemIdx++ ) { mpScene->removeItem( mKeyPointGraphicItems[ itemIdx ] ); } mKeyPointGraphicItems.clear(); const float KEYPOINT_SIDE_LENGTH = 4.0; for ( uint32_t keyPointIdx = 0; keyPointIdx < mKeyPointInstances.size(); keyPointIdx++ ) { const KeyPointInstanceData& instanceData = mKeyPointInstances[ keyPointIdx ]; float topLeftX = instanceData.mProjectedPosition[ 0 ] - KEYPOINT_SIDE_LENGTH/2.0; float topLeftY = instanceData.mProjectedPosition[ 1 ] - KEYPOINT_SIDE_LENGTH/2.0; QPen outlinePen( ( QBrush( QColor( 0, 0, 0 ) ), 1.0 ) ); QBrush fillBrush( QColor( instanceData.mR, instanceData.mG, instanceData.mB ) ); mKeyPointGraphicItems.push_back( mpScene->addEllipse( topLeftX, topLeftY, KEYPOINT_SIDE_LENGTH, KEYPOINT_SIDE_LENGTH, outlinePen, fillBrush ) ); } }
void nodeWidget::paint( QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * ) { QString title( "Hello" ); QList <QString> properties; properties << "Thing" << "lalala" << "bouind" << "hahaha"; QRectF originalRect( titlebarRect( painter->font() ) ); _titlePath = QPainterPath(); _titlePath.addRect( originalRect ); QRectF titleRect( originalRect ); titleRect.setHeight( titleRect.height() + ( ROUNDRADIUS * 2 + 1 ) ); QRectF contentsRect( titleRect ); contentsRect.setY( originalRect.height() ); contentsRect.setHeight( originalRect.height() + NODEPROPERTYHEIGHT*( properties.size() - 1 ) - 2*ROUNDRADIUS - 4 ); QPainterPath titleBar( makeRoundedPath( titleRect ) ); QPainterPath contents( makeRoundedPath( contentsRect ) ); QPen outlinePen( Qt::black, 3 ); if( isSelected() ) { outlinePen.setColor( SELECTED_COLOUR ); } QPainterPath globalLine( makeRoundedPath( titleRect.unite( contentsRect ) ) ); painter->setPen( outlinePen ); painter->drawPath( globalLine ); painter->fillPath( titleBar, titleGradient( titleRect ) ); painter->fillPath( contents, contentsBrush( contentsRect ) ); QColor separatingLineColor( Qt::black ); if( isSelected() ) { separatingLineColor = SELECTED_COLOUR; } separatingLineColor.setAlpha( 128 ); QPen separatingLinePen( separatingLineColor ); QPen whitePen( Qt::white ); painter->setPen( whitePen ); painter->drawText( originalRect, Qt::AlignCenter, title ); QRectF textRect( titleRect ); textRect.moveTop( textRect.top() + originalRect.height() - 2*ROUNDRADIUS - 2 ); FOREACH( properties, prop ) { painter->setPen( whitePen ); painter->drawText( textRect, Qt::AlignCenter, *prop ); if( &(*prop) != &(properties.back()) ) { painter->setPen( separatingLinePen ); painter->drawLine( titleRect.x(), textRect.y()+NODEPROPERTYHEIGHT+4, titleRect.x()+titleRect.width(), textRect.y()+NODEPROPERTYHEIGHT+4 ); } textRect.moveTop( textRect.top() + NODEPROPERTYHEIGHT ); }
void LocationBar::paintEvent(QPaintEvent* event) { LineEdit::paintEvent(event); // Show loading progress if (qzSettings->showLoadingProgress && m_progressVisible) { QStyleOptionFrame option; initStyleOption(&option); int lm, tm, rm, bm; getTextMargins(&lm, &tm, &rm, &bm); QRect contentsRect = style()->subElementRect(QStyle::SE_LineEditContents, &option, this); contentsRect.adjust(lm, tm, -rm, -bm); QColor bg = m_progressColor; if (!bg.isValid() || bg.alpha() == 0) { bg = Colors::mid(palette().color(QPalette::Base), palette().color(QPalette::Text), m_progressStyle > 0 ? 4 : 8, 1); } QPainter p(this); p.setBrush(QBrush(bg)); // We are painting over text, make sure the text stays visible p.setOpacity(0.5); QPen outlinePen(bg.darker(110), 0.8); p.setPen(outlinePen); switch (m_progressStyle) { case ProgressFilled: { QRect bar = contentsRect.adjusted(0, 1, 0, -1); bar.setWidth(bar.width() * m_loadProgress / 100); const int roundness = bar.height() / 4.0; p.drawRoundedRect(bar, roundness, roundness); break; } case ProgressBottom: { outlinePen.setWidthF(0.3); outlinePen.setColor(outlinePen.color().darker(130)); p.setPen(outlinePen); QRect bar(contentsRect.x(), contentsRect.bottom() - 3, contentsRect.width() * m_loadProgress / 100.0, 3); p.drawRoundedRect(bar, 1, 1); break; } case ProgressTop: { outlinePen.setWidthF(0.3); outlinePen.setColor(outlinePen.color().darker(130)); p.setPen(outlinePen); QRect bar(contentsRect.x(), contentsRect.top() + 1, contentsRect.width() * m_loadProgress / 100.0, 3); p.drawRoundedRect(bar, 1, 1); break; } default: break; } } }
void mogs_qt_video_scene::DrawRectangle() { if(rectangle_ready_) { QPen outlinePen(Qt::black); outlinePen.setWidth(1); if (pressed_point_.x() > 0 && pressed_point_.y()>0 && pressed_point_.x()< width_ && pressed_point_.y()< height_ && released_point_.x()>0 && released_point_.y()>0 && released_point_.x()< width_ && released_point_.y()< height_) rect = addRect(pressed_point_.x(), pressed_point_.y(), released_point_.x()-pressed_point_.x(),released_point_.y() -pressed_point_.y(), outlinePen); DrawPoint( (pressed_point_ + released_point_)/2,""); }else if (rectanle_in_progress_) { if (pressed_point_.x() > 0 && pressed_point_.y()>0 && pressed_point_.x()< width_ && pressed_point_.y()< height_ && moving_point_.x()>0 && moving_point_.y()>0 && moving_point_.x()< width_ && moving_point_.y()< height_) { QPen outlinePen(Qt::green); outlinePen.setWidth(1); rect = addRect(pressed_point_.x(), pressed_point_.y(), moving_point_.x()-pressed_point_.x(),moving_point_.y() -pressed_point_.y(), outlinePen); DrawPoint( (pressed_point_ + moving_point_)/2,""); } } }
//----------------------------------------------------------------------------- // Function: StickyNote::createGluedEdge() //----------------------------------------------------------------------------- void StickyNote::createGluedEdge() { QColor topColor = QColor("lemonChiffon").darker(103); QGraphicsRectItem* glueEdge = new QGraphicsRectItem(0, 0, DEFAULT_WIDTH, TOP_OFFSET); QPen outlinePen(Qt::black, 0, Qt::NoPen); glueEdge->setPen(outlinePen); glueEdge->setBrush(topColor); addToGroup(glueEdge); timeLabel_ = new QGraphicsSimpleTextItem(); timeLabel_->setBrush(Qt::gray); timeLabel_->setPos(5, TOP_OFFSET/2 - QFontMetrics(timeLabel_->font()).height()/2); addToGroup(timeLabel_); }
void mogs_qt_video_scene::DrawPoint( CvPoint in, QString name) { QPen outlinePen(Qt::red); outlinePen.setWidth(2); addEllipse(in.x, in.y, 5, 5,outlinePen); if (name != "") { QGraphicsTextItem * io = new QGraphicsTextItem; io->setDefaultTextColor(Qt::red); io->setPos(in.x -20,in.y); io->setPlainText(name); addItem(io); } }
//-------------------------------------------------------------------------------------------------- void ImageViewDialog::setDragRectangle( const QRectF& dragRectangle ) { mDragRectangle = dragRectangle; mbDragRectangleSet = true; if ( NULL != mpDragRectangleItem ) { mpDragRectangleItem->setRect( dragRectangle ); mpDragRectangleItem->setVisible( true ); } else { QPen outlinePen( QColor( 255, 255, 0 ) ); outlinePen.setWidth( 2 ); mpDragRectangleItem = mpScene->addRect( dragRectangle, outlinePen ); } this->btnSetFilter->setEnabled( true ); }
QImage RichTextRenderer::renderText() { // qDebug()<<itemName()<<"TextBoxWarmingThread::run(): htmlCode:"<<htmlCode; //qDebug() << "RichTextRenderer::renderText(): HTML:"<<html(); //qDebug() << "RichTextRenderer::update(): Update Start..."; //qDebug() << "RichTextRenderer::renderText(): \t in thread:"<<QThread::currentThreadId(); if(m_updateTimer.isActive()) m_updateTimer.stop(); QTime renderTime; renderTime.start(); QTextDocument doc; QTextDocument shadowDoc; if (Qt::mightBeRichText(html())) { doc.setHtml(html()); shadowDoc.setHtml(html()); } else { doc.setPlainText(html()); shadowDoc.setPlainText(html()); } int textWidth = m_textWidth; doc.setTextWidth(textWidth); shadowDoc.setTextWidth(textWidth); // Apply outline pen to the html QTextCursor cursor(&doc); cursor.select(QTextCursor::Document); QTextCharFormat format; QPen p(Qt::NoPen); if(outlineEnabled()) { p = outlinePen(); p.setJoinStyle(Qt::MiterJoin); } format.setTextOutline(p); //format.setForeground(fillEnabled() ? fillBrush() : Qt::NoBrush); //Qt::white); cursor.mergeCharFormat(format); // Setup the shadow text formatting if enabled if(shadowEnabled()) { if(shadowBlurRadius() <= 0.05) { QTextCursor cursor(&shadowDoc); cursor.select(QTextCursor::Document); QTextCharFormat format; format.setTextOutline(Qt::NoPen); format.setForeground(shadowBrush()); cursor.mergeCharFormat(format); } } QSizeF shadowSize = shadowEnabled() ? QSizeF(shadowOffsetX(),shadowOffsetY()) : QSizeF(0,0); QSizeF docSize = doc.size(); QSizeF padSize(12.,12.); QSizeF sumSize = (docSize + shadowSize + padSize);//.toSize(); QSizeF scaledSize = QSizeF(sumSize.width() * m_scaling.x(), sumSize.height() * m_scaling.y()); if(m_scaling.x() != 1. || m_scaling.y() != 1.) { //qDebug() << "RichTextRenderer::renderText(): Orig size:"<<sumSize<<", scaled size:"<<scaledSize<<", scaling:"<<m_scaling; m_rawSize = sumSize; } //qDebug() << "RichTextRenderer::update(): textWidth: "<<textWidth<<", shadowSize:"<<shadowSize<<", docSize:"<<docSize<<", sumSize:"<<sumSize; QImage cache(scaledSize.toSize(),QImage::Format_ARGB32); //_Premultiplied); memset(cache.scanLine(0),0,cache.byteCount()); double padSizeHalfX = padSize.width() / 2; double padSizeHalfY = padSize.height() / 2; QPainter textPainter(&cache); textPainter.scale(m_scaling.x(), m_scaling.y()); //textPainter.fillRect(cache.rect(),Qt::transparent); QAbstractTextDocumentLayout::PaintContext pCtx; //qDebug() << "RichTextRenderer::renderText(): shadowEnabled():"<<shadowEnabled()<<", shadowBlurRadius():"<<shadowBlurRadius(); if(shadowEnabled()) { if(shadowBlurRadius() <= 0.05) { // render a "cheap" version of the shadow using the shadow text document textPainter.save(); textPainter.translate(shadowOffsetX(),shadowOffsetY()); shadowDoc.documentLayout()->draw(&textPainter, pCtx); textPainter.restore(); } else { double radius = shadowBlurRadius(); // create temporary pixmap to hold a copy of the text QSizeF blurSize = ImageFilters::blurredSizeFor(doc.size(), (int)radius); QSizeF scaledBlurSize = QSize(blurSize.width() * m_scaling.x(), blurSize.height() * m_scaling.y()); //QSize docSize = doc.size(); //qDebug() << "RichTextRenderer::renderText(): [shadow] radius:"<<radius<<" blurSize:"<<blurSize<<", scaling:"<<m_scaling<<", scaledBlurSize:"<<scaledBlurSize; //qDebug() << "Blur size:"<<blurSize<<", doc:"<<doc.size()<<", radius:"<<radius; QImage tmpImage(scaledBlurSize.toSize(),QImage::Format_ARGB32_Premultiplied); memset(tmpImage.scanLine(0),0,tmpImage.byteCount()); // render the text QPainter tmpPainter(&tmpImage); tmpPainter.scale(m_scaling.x(), m_scaling.y()); tmpPainter.save(); tmpPainter.translate(radius + padSizeHalfX, radius + padSizeHalfY); doc.documentLayout()->draw(&tmpPainter, pCtx); tmpPainter.restore(); // blacken the text by applying a color to the copy using a QPainter::CompositionMode_DestinationIn operation. // This produces a homogeneously-colored pixmap. QRect rect = tmpImage.rect(); tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn); tmpPainter.fillRect(rect, shadowBrush().color()); tmpPainter.end(); // blur the colored text ImageFilters::blurImage(tmpImage, (int)radius); // render the blurred text at an offset into the cache textPainter.save(); textPainter.translate(shadowOffsetX() - radius, shadowOffsetY() - radius); textPainter.drawImage(0, 0, tmpImage); textPainter.restore(); } } textPainter.translate(padSizeHalfX, padSizeHalfY); doc.documentLayout()->draw(&textPainter, pCtx); textPainter.end(); m_image = cache.convertToFormat(QImage::Format_ARGB32); emit textRendered(m_image); //qDebug() << "RichTextRenderer::renderText(): Render finished, elapsed:"<<renderTime.elapsed()<<"ms"; //m_image.save("debug-text.png"); return m_image; }
void GraphicsItemNode::paint(QPainter * painter, const QStyleOptionGraphicsItem *, QWidget *) { QPainterPath outlinePath = shape(); //Fill the node's colour QBrush brush(m_colour); painter->fillPath(outlinePath, brush); //If the node contains a BLAST hit, draw that on top. if (g_settings->nodeColourScheme == BLAST_HITS_COLOUR) { std::vector<BlastHitPart> parts; if (g_settings->doubleMode) { if (m_deBruijnNode->thisNodeHasBlastHits()) parts = m_deBruijnNode->getBlastHitPartsForThisNode(); } else { if (m_deBruijnNode->thisNodeOrReverseComplementHasBlastHits()) parts = m_deBruijnNode->getBlastHitPartsForThisNodeOrReverseComplement(); } if (parts.size() > 0) { QPen partPen; partPen.setWidthF(m_width); partPen.setCapStyle(Qt::FlatCap); partPen.setJoinStyle(Qt::BevelJoin); for (size_t i = 0; i < parts.size(); ++i) { partPen.setColor(parts[i].m_colour); painter->setPen(partPen); painter->drawPath(makePartialPath(parts[i].m_nodeFractionStart, parts[i].m_nodeFractionEnd)); } } } //Draw the node outline QColor outlineColour = g_settings->outlineColour; double outlineThickness = g_settings->outlineThickness; if (isSelected()) { outlineColour = g_settings->selectionColour; outlineThickness = g_settings->selectionThickness; } if (outlineThickness > 0.0) { outlinePath = outlinePath.simplified(); QPen outlinePen(QBrush(outlineColour), outlineThickness, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin); painter->setPen(outlinePen); painter->drawPath(outlinePath); } //Draw text if there is any to display. if (g_settings->anyNodeDisplayText()) { //The text should always be displayed upright, so //counter the view's rotation here. painter->setRenderHint(QPainter::TextAntialiasing, true); painter->setFont(g_settings->labelFont); QString displayText = getNodeText(); QSize textSize = getNodeTextSize(displayText); double textWidth = textSize.width(); double textHeight = textSize.height(); //The text outline is made by drawing the text first in white at a slight offset //at many angles. The larger the text outline, the more angles are needed to //make the outline look nice. if (g_settings->textOutline) { int offsetSteps = 8; if (g_settings->textOutlineThickness > 0.5) offsetSteps = 16; if (g_settings->textOutlineThickness > 1.0) offsetSteps = 32; double offsetDistance = g_settings->textOutlineThickness; painter->translate(getCentre()); painter->rotate(-g_graphicsView->m_rotation); for (int i = 0; i < offsetSteps; ++i) { double offsetAngle = 6.2832 * (double(i) / offsetSteps); double xOffset = offsetDistance * cos(offsetAngle); double yOffset = offsetDistance * sin(offsetAngle); QRectF shadowTextRectangle(-textWidth / 2.0 + xOffset, -textHeight / 2.0 + yOffset, textWidth, textHeight); painter->setPen(Qt::white); painter->drawText(shadowTextRectangle, Qt::AlignCenter, displayText); } painter->rotate(g_graphicsView->m_rotation); painter->translate(-1.0 * getCentre()); } QRectF textRectangle(-textWidth / 2.0, -textHeight / 2.0, textWidth, textHeight); painter->setPen(g_settings->textColour); painter->translate(getCentre()); painter->rotate(-g_graphicsView->m_rotation); painter->drawText(textRectangle, Qt::AlignCenter, displayText); painter->rotate(g_graphicsView->m_rotation); painter->translate(-1.0 * getCentre()); } }