Example #1
0
    virtual void paintEvent( QPaintEvent *event )
    {
      bool hasAnnotations = false;
      for ( uint i = 0; i < m_document->pages(); ++i )
        if ( m_document->page( i )->hasAnnotations() ) {
          hasAnnotations = true;
          break;
        }
      if ( !hasAnnotations ) {
        QPainter p( viewport() );
        p.setRenderHint( QPainter::Antialiasing, true );
        p.setClipRect( event->rect() );

        QTextDocument document;
        document.setHtml( i18n( "<div align=center><h3>No annotations</h3>"
                                "To create new annotations press F6 or select <i>Tools -&gt; Review</i>"
                                " from the menu.</div>" ) );
        document.setTextWidth( width() - 50 );

        const uint w = document.size().width() + 20;
        const uint h = document.size().height() + 20;

        p.setBrush( palette().background() );
        p.translate( 0.5, 0.5 );
        p.drawRoundRect( 15, 15, w, h, (8*200)/w, (8*200)/h );
        p.translate( 20, 20 );
        document.drawContents( &p );

      } else {
        QTreeView::paintEvent( event );
      }
    }
Example #2
0
void
DelegateHelper::render_html2( QPainter * painter, const QStyleOptionViewItem& option, const QString& text )
{
    auto op = option;
    
    painter->save();

    QTextDocument document;

    document.setDefaultTextOption( QTextOption( Qt::AlignVCenter ) ); // hit to QTBUG 13467 -- valign is not taking in account ??
    document.setDefaultFont( op.font );
    document.setDefaultStyleSheet( "{ vertical-align: middle; }" );
    document.setHtml( text );

    op.displayAlignment |= Qt::AlignVCenter;
    op.text = "";
    op.widget->style()->drawControl( QStyle::CE_ItemViewItem, &op, painter, op.widget );

    QRect cbx = op.widget->style()->subElementRect( QStyle::SE_CheckBoxIndicator, &option, op.widget );
    QRect rc( option.rect );
    rc.setLeft( cbx.right() + 4 );

    painter->translate( cbx.right() + 4, option.rect.top() ); // workaround for VCenter
    document.drawContents( painter ); // rc.translated( -rc.topLeft() ) );

    painter->restore();
}
void RichTextPushButton::paintEvent(QPaintEvent *event)
{
    if (isRichText) {
        QStylePainter p(this);
 
        QRect buttonRect = rect();
        QPoint point;
 
        QTextDocument richTextLabel;
        richTextLabel.setHtml(htmlText);
 
        QPixmap richTextPixmap(richTextLabel.size().width(), richTextLabel.size().height());
        richTextPixmap.fill(Qt::transparent);
        QPainter richTextPainter(&richTextPixmap);
        richTextLabel.drawContents(&richTextPainter, richTextPixmap.rect());
 
        if (!icon().isNull())
            point = QPoint(buttonRect.x() + buttonRect.width() / 2 + iconSize().width() / 2 + 2, buttonRect.y() + buttonRect.height() / 2);
        else
            point = QPoint(buttonRect.x() + buttonRect.width() / 2 - 1, buttonRect.y() + buttonRect.height() / 2);
 
        buttonRect.translate(point.x() - richTextPixmap.width() / 2, point.y() - richTextPixmap.height() / 2);
 
        p.drawControl(QStyle::CE_PushButton, getStyleOption());
        p.drawPixmap(buttonRect.left(), buttonRect.top(), richTextPixmap.width(), richTextPixmap.height(),richTextPixmap);
    } else
        QPushButton::paintEvent(event);
}
Example #4
0
void
DelegateHelper::render_html( QPainter * painter, const QStyleOptionViewItem& option, const QString& text, const QString& css )
{
    painter->save();

    auto op = option;
    QTextDocument document;

    if ( !css.isEmpty() ) {
        document.setDefaultStyleSheet( css );
    } else {
        document.setDefaultTextOption( QTextOption( op.displayAlignment ) ); // QTBUG 13467 -- valign is not taking in account
        document.setDefaultFont( op.font );
    }
    document.setHtml( QString("<body>%1</body>").arg( text ) );

    op.displayAlignment |= Qt::AlignVCenter;
    op.text = "";
    op.widget->style()->drawControl( QStyle::CE_ItemViewItem, &op, painter );

    painter->translate( op.rect.topLeft() );
    // QRect clip( 0, 0, op.rect.width(), op.rect.height() );
    document.drawContents( painter ); //, clip );
    painter->restore();
}
void BackgroundItemDelegate::paint(QPainter *painter,
                                   const QStyleOptionViewItem &option,
                                   const QModelIndex &index) const
{
#if SHOW_DETAILS
    const QString title = index.model()->data(index, Qt::DisplayRole).toString();
    const QString author = index.model()->data(index, WallpaperModel::AuthorRole).toString();
    const QString resolution = index.model()->data(index, WallpaperModel::ResolutionRole).toString();
#endif
    const QPixmap pix = index.model()->data(index, Qt::DecorationRole).value<QPixmap>();

    // Highlight selected item
    QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &option, painter);

    // Draw wallpaper thumbnail
    if (pix.isNull())
        painter->fillRect(option.rect, option.palette.brush(QPalette::Base));
    else
        // Draw the actual thumbnail
        painter->drawPixmap(option.rect.center().x() - (m_maxSize.width() / 2),
                            option.rect.y() + kMargin, m_maxSize.width(),
                            m_maxSize.height(), pix);

#if SHOW_DETAILS
    // Use a QTextDocument to layout the text
    QTextDocument document;
    QString html = QString("<strong>%1</strong>").arg(title);

    if (!author.isEmpty()) {
        QString authorCaption = tr("<span style=\"font-size: 9pt\">by %1</span>").arg(author);
        html += QString("<br />%1").arg(authorCaption);
    }

    if (!resolution.isEmpty())
        html += QString("<br /><em style=\"font-size: 8pt\">%1</em>").arg(resolution);

    // Set the text color according to the item state
    QColor color;
    if (option.state & QStyle::State_Selected)
        color = QApplication::palette().brush(QPalette::HighlightedText).color();
    else
        color = QApplication::palette().brush(QPalette::Text).color();
    html = QString("<div style=\"color: %1\" align=\"center\">%2</div>").arg(color.name()).arg(html);

    // Set contents and word-wrap
    document.setHtml(html);
    document.setTextWidth(m_maxSize.width());

    // Calculate positioning
    int x = option.rect.left() + kMargin;
    int y = option.rect.top() + m_maxSize.height() + kMargin * 2;

    // Draw text
    painter->save();
    painter->translate(x, y);
    document.drawContents(painter, QRect(QPoint(0, 0), option.rect.size() -
                                         QSize(0, m_maxSize.height() + kMargin * 2)));
    painter->restore();
#endif
}
void SoftwareColumnItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    painter->save();

    QString softwareName = index.model()->data(index.model()->index(index.row(), UpdaterDialog::Columns::SoftwareComponent)).toString();
    QString websiteURL   = index.model()->data(index.model()->index(index.row(), UpdaterDialog::Columns::WebsiteURL)).toString();

    QString link = "<img src=\":/home.png\"><a href=\"" + websiteURL + "\">"+softwareName+"</a>";

    QTextDocument document;

    if (option.state & QStyle::State_MouseOver) {
        // draw stuff which appears on mouse over
        document.setDefaultStyleSheet("a { text-decoration: none; color: darkblue; }");
    } else {
        // draw stuff that appears when mouse is not over control
        document.setDefaultStyleSheet("a { text-decoration: none; color: black; }");
    }

    document.setTextWidth(option.rect.width());
    document.setHtml(link);
    painter->translate(option.rect.topLeft());
    document.drawContents(painter);

    painter->restore();
    return;
}
void LS3SelectionDisplayModelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
    QVariant data=index.data(Qt::DisplayRole).toString();
    if (data.type()==QVariant::String) {
        //drawBackground(painter, option, index);
        QString pre, post;
        pre="<font color=\""+option.palette.text().color().name()+"\">";
        post="</font>";
        if (option.state & QStyle::State_Selected) {
            painter->fillRect(option.rect, option.palette.highlight());
            pre="<font color=\""+option.palette.highlightedText().color().name()+"\">";
            post="</font>";
        }

        QTextDocument doc;
        //std::cout<<"drawing "<<QString(pre+data.toString()+post).toStdString()<<std::endl;
        doc.setHtml(pre+data.toString()+post);
        painter->save();

        painter->translate(option.rect.topLeft());
        QRect r(QPoint(0, 0), option.rect.size());

        doc.drawContents(painter, r);

        painter->restore();
    } else {
        QStyledItemDelegate::paint(painter, option, index);
    }

    if (index.column()==0) {
        painter->drawPixmap(option.rect.topRight()+QPoint(-selDeleteImage.width(), (double)(option.rect.height()-selDeleteImage.height())/2.0), selDeleteImage);
    }
}
Example #8
0
void drawHtmlLine(QPainter *painter, const QFont font, QRect rect, QString text, bool multiline,
                  bool leftAligned) {
    if(!painter){return;}

    painter->save();

    QTextDocument displayDoc;
    setUpDisplayDoc(displayDoc, font);
    if(!leftAligned){
        text = QString("<div align=\"right\">") + text + "</div>";

    }

    displayDoc.setHtml(text);
    //multiline == false - Normally
    if(multiline){
        displayDoc.setTextWidth(rect.width());
    } else {displayDoc.setTextWidth(-1);}


    painter->translate(rect.topLeft());

    if(multiline){ displayDoc.adjustSize(); }

    rect.moveTopLeft(QPoint(0,0));
    displayDoc.drawContents(painter, rect);

    painter->restore();

}
Example #9
0
void
PeakMethodDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    if ( index.column() == c_value ) {
        if ( index.row() == r_pharmacopoeia ) {
            int value = index.data().toInt();
            QString text;
            switch ( value ) {
            case adcontrols::chromatography::ePHARMACOPOEIA_NotSpcified: text = "Not specified"; break;
            case adcontrols::chromatography::ePHARMACOPOEIA_EP:          text = "EP"; break;
            case adcontrols::chromatography::ePHARMACOPOEIA_JP:          text = "JP"; break;
            case adcontrols::chromatography::ePHARMACOPOEIA_USP:         text = "USP"; break;
            }
            drawDisplay( painter, option, option.rect, text );
        } else {
            drawDisplay( painter, option, option.rect, ( boost::format( "%.3lf" ) % index.data().toDouble() ).str().c_str() );
        }
    } else if ( index.column() == c_header ) {
        QStyleOptionViewItem op = option;
        painter->save();

        QTextDocument doc;
        doc.setHtml( index.data().toString() );
        op.widget->style()->drawControl( QStyle::CE_ItemViewItem, &op, painter );
        painter->translate( op.rect.left(), op.rect.top() );
        QRect clip( 0, 0, op.rect.width(), op.rect.height() );
        doc.drawContents( painter, clip );

        painter->restore();
    } else {
        QItemDelegate::paint( painter, option, index );
    }
}
Example #10
0
/*!
    Draw the contents of the splash screen using painter \a painter.
    The default implementation draws the message passed by showMessage().
    Reimplement this function if you want to do your own drawing on
    the splash screen.
*/
void QSplashScreen::drawContents(QPainter *painter)
{
    Q_D(QSplashScreen);
    painter->setPen(d->currColor);
    QRect r = rect().adjusted(5, 5, -5, -5);
    if (Qt::mightBeRichText(d->currStatus)) {
        QTextDocument doc;
#ifdef QT_NO_TEXTHTMLPARSER
        doc.setPlainText(d->currStatus);
#else
        doc.setHtml(d->currStatus);
#endif
        doc.setTextWidth(r.width());
        QTextCursor cursor(&doc);
        cursor.select(QTextCursor::Document);
        QTextBlockFormat fmt;
        fmt.setAlignment(Qt::Alignment(d->currAlign));
        cursor.mergeBlockFormat(fmt);
        painter->save();
        painter->translate(r.topLeft());
        doc.drawContents(painter);
        painter->restore();
    } else {
        painter->drawText(r, d->currAlign, d->currStatus);
    }
}
Example #11
0
 void paintSection( QPainter * painter, const QRect& rect, int logicalIndex ) const override {
     
     if ( rect.isValid() ) {
         if ( logicalIndex > 0 ) {
             QStyleOptionHeader op;
             initStyleOption(&op);
             op.text = "";
             op.rect = rect;
             op.textAlignment = Qt::AlignVCenter | Qt::AlignHCenter;
             // draw the section
             style()->drawControl( QStyle::CE_Header, &op, painter, this );
             // html painting
             painter->save();
             QRect textRect = style()->subElementRect( QStyle::SE_HeaderLabel, &op, this );
             painter->translate( textRect.topLeft() );
             QTextDocument doc;
             doc.setTextWidth( textRect.width() );
             doc.setDefaultTextOption( QTextOption( Qt::AlignHCenter ) );
             doc.setDocumentMargin(0);
             doc.setHtml( model()->headerData( logicalIndex, Qt::Horizontal ).toString() );
             doc.drawContents( painter, QRect( QPoint( 0, 0 ), textRect.size() ) );
             painter->restore();
         } else {
             QHeaderView::paintSection( painter, rect, logicalIndex );
         }
     }
 }
Example #12
0
void NoteItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
    QStyle* style = KApplication::style();
    style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);

    QRect rect = option.rect;
    rect.adjust( m_margin, m_margin, -m_margin, -m_margin );

    Nepomuk2::Resource res = index.data( Nepomuk2::Utils::SimpleResourceModel::ResourceRole ).value<Nepomuk2::Resource>();

    QString plainTextContent = res.property( NIE::plainTextContent() ).toString();
    QDateTime creationDate = res.property( NAO::created() ).toDateTime();

    //TODO: Find a way to convert this date into "4 hours ago" format
    QString dateString = creationDate.toLocalTime().toString();

    painter->save();
    QFont f = painter->font();
    f.setBold( true );
    painter->setFont( f );
    style->drawItemText( painter, rect, Qt::AlignLeft | Qt::AlignTop, option.palette, true, dateString );
    painter->restore();

    rect.setY( rect.y() + QFontMetrics(f).height()/* + m_margin */);

    //
    // Draw the excerpt
    //
    QTextDocument textDocument;
    textDocument.setTextWidth( rect.width() );

    QFont font = textDocument.defaultFont();
    font.setItalic( true );
    textDocument.setDefaultFont( font );

    QFontMetrics fm( font );
    int numLines = rect.height() / fm.height();
    int charPerLine = rect.width() / fm.averageCharWidth();

    int l = (numLines-2) * charPerLine; // one line less for ending, and one line for padding
    QString text;
    // FIXME: There may be a case where some part of the text gets repeated before and after the ...
    if( l < plainTextContent.length() ) {
        text = plainTextContent.left( l );
        text += QLatin1String(" .... ");
        text += plainTextContent.right( charPerLine-10 );
    }
    else {
        text = plainTextContent;
    }

    textDocument.setPlainText( text.simplified() );

    painter->save();
    painter->translate( rect.topLeft() );
    textDocument.drawContents( painter );
    painter->restore();
}
void KviTalIconAndRichTextItemDelegate::paint(QPainter * pPainter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
	pPainter->save();
	QStyleOptionViewItem opt = option;
	initStyleOption(&opt, index);

	if(opt.state & QStyle::State_Selected)
		QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, pPainter);

	QString szText = index.data(Qt::DisplayRole).toString();
	QPixmap pixmap;
	QRect decorationRect;
	QVariant value = index.data(Qt::DecorationRole);

	QIcon ico;

	QPixmap pix;

	if(value.canConvert<QIcon>())
	{
		ico = QIcon(value.value<QIcon>());
		if(!ico.isNull())
			pix = ico.pixmap(m_oIconSize);
		else
			pix = m_oDefaultPix;
	}
	else
	{
		pix = m_oDefaultPix;
	}

	if(!pix.isNull())
	{
		int x = opt.rect.x() + LVI_BORDER;
		int y = opt.rect.y() + LVI_BORDER;
		int w = m_oIconSize.width();

		pPainter->drawPixmap(
		    x + ((w - pix.width()) / 2),
		    y,
		    pix);
	}

	QTextDocument doc;
	doc.setHtml(szText);
	doc.setDefaultFont(opt.font);

	int iIconAndSpace = LVI_BORDER + m_oIconSize.width() + LVI_SPACING;

	pPainter->translate(opt.rect.x() + iIconAndSpace, opt.rect.y() + LVI_BORDER);
	doc.setTextWidth(opt.rect.width() - iIconAndSpace - LVI_BORDER);
	QRect cliprect = QRect(QPoint(0, 0), QSize(opt.rect.width() - iIconAndSpace, opt.rect.height()));
	doc.drawContents(pPainter, cliprect);
	pPainter->restore();
}
Example #14
0
  void paintEvent(QPaintEvent *)
  {
    QPainter p(this);
#if 1
    QTextDocument document;
    document.setHtml("<br>T<br>e<br>s<br>t<br>");
    document.drawContents(&p);
#else
    drawRotatedText(&p, 90, width() / 2, height() / 2, "The vertical text");
#endif
  }
void QgsDecorationCopyright::render( QPainter * theQPainter )
{
  //Large IF statement to enable/disable copyright label
  if ( enabled() )
  {
    // need width/height of paint device
    int myHeight = theQPainter->device()->height();
    int myWidth = theQPainter->device()->width();

    QTextDocument text;
    text.setDefaultFont( mQFont );
    // To set the text color in a QTextDocument we use a CSS style
    QString style = "<style type=\"text/css\"> p {color: " +
                    mLabelQColor.name() + "}</style>";
    text.setHtml( style + "<p>" + mLabelQString + "</p>" );
    QSizeF size = text.size();

    float myXOffset( 0 ), myYOffset( 0 );
    //Determine placement of label from form combo box
    switch ( mPlacementIndex )
    {
      case 0: // Bottom Left
        //Define bottom left hand corner start point
        myYOffset = myHeight - ( size.height() + 5 );
        myXOffset = 5;
        break;
      case 1: // Top left
        //Define top left hand corner start point
        myYOffset = 0;;
        myXOffset = 5;
        break;
      case 2: // Top Right
        //Define top right hand corner start point
        myYOffset = 0;
        myXOffset = myWidth - ( size.width() + 5 );
        break;
      case 3: // Bottom Right
        //Define bottom right hand corner start point
        myYOffset = myHeight - ( size.height() + 5 );
        myXOffset = myWidth - ( size.width() + 5 );
        break;
      default:
        QgsDebugMsg( QString( "Unknown placement index of %1" ).arg( mPlacementIndex ) );
    }

    //Paint label to canvas
    QMatrix worldMatrix = theQPainter->worldMatrix();
    theQPainter->translate( myXOffset, myYOffset );
    text.drawContents( theQPainter );
    // Put things back how they were
    theQPainter->setWorldMatrix( worldMatrix );
  }
}
Example #16
0
void DanmakuMove::drawStandBy_(){

	if (startPaintDMIndex_ <= dmCreater_->totalDMCount_) {
		return;
	}

	if (!isNeedUpdateStandBy_)
		return;
	else
		isNeedUpdateStandBy_ = false;

	QFont font;
	font.setBold(true);
	font.setFamily(QString("Microsoft YaHei"));
	font.setPixelSize(25);

	QString styleStr = QString(
		"<p>"
		"<span style = \" font-size:%1px; color:#FF9DCB; \">%2< / span>"
		"</p>");
	QString standByStr = styleStr.arg(font.pixelSize()).arg(tr("Stand By"));

	QTextDocument td;
	td.setDefaultFont(font);
	td.setDocumentMargin(10);

	QTextOption op = td.defaultTextOption();
	op.setAlignment(Qt::AlignHCenter);
	td.setDefaultTextOption( op );
	td.setHtml(standByStr);
	td.setTextWidth(dmSideWidSize_.width());
	QSize s = td.size().toSize();

	if (standByPix_)
		delete standByPix_;
	standByPix_ = new QPixmap(QSize(dmSideWidSize_.width(), 60));
	standByPix_->fill(Qt::transparent);
	QPainter p(standByPix_);
	p.setPen(QPen(QColor(0x49545A)));
	p.setBrush(QBrush(QColor(0x49545A), Qt::SolidPattern));
	p.setFont(font);

	int border = 1;
	QRect r(0, 0, standByPix_->width(), standByPix_->height());
	p.setOpacity(0.6);
	p.drawRoundedRect(r.adjusted(border, border, -border, -border), 3, 3);

	td.drawContents(&p);

	dmSideWidBKPixCache_->fill(Qt::transparent);
	QPainter pSideDM(dmSideWidBKPixCache_);
	pSideDM.drawPixmap(QPoint(0, dmSideWidBKPixCache_->height()-standByPix_->height()+border), *standByPix_);
}
void SidarHTMLRender::sidarPaint(const SidarLabel &pSidar)
{
    QPainter pnt((QPaintDevice*)&pSidar);

    QTextDocument html;
    html.setHtml(QString("<body>"
                         "<h3 style='color:red;'> Hello HTML </h3>"
                         "<br/>"
                         "<img src='/home/ilian/projects/qt-paint-label/assets/globe_64.jpg' width='64' height='64'/>"
                         "</body>"));

    html.drawContents(&pnt);
}
Example #18
0
void HexViewWidget::generatePixmap()
{
    m_pixmap = new QPixmap(sizeHint());
    m_pixmap->fill(Qt::white);

    QPainter painter(m_pixmap);

    if (!m_decoder->bitString()) {
        return;
    }

    QTextDocument doc;
    doc.setHtml(QString("<pre>") + m_decoder->toHTML().c_str() + "</pre>");
    doc.drawContents(&painter, QRect(0, 0, m_pixmap->width(), m_pixmap->height()));

    painter.drawLine(
        QPoint(m_decoder->LineWidth() + 4, 0),
        QPoint(m_decoder->LineWidth() + 4, m_decoder->lines() * m_decoder->LineHeight() + 2));

    doc.setHtml(QString("<pre>") + m_decoder2->toHTML().c_str() + "</pre>");
    painter.translate(m_decoder->LineWidth() + 6, 0);
    doc.drawContents(&painter, QRect(0, 0, m_pixmap->width(), m_pixmap->height()));
}
 virtual void drawDisplay ( QPainter * painter, const QStyleOptionViewItem & option, const QRect & rect, const QString & text ) const
 {
     QTextDocument doc;
     doc.setHtml(text);
     QPixmap pix(rect.size());
     QPainter p(&pix);
     p.setPen(Qt::NoPen);
     if (option.state & QStyle::State_Selected)
         p.setBrush(option.palette.highlight());
     else p.setBrush(option.palette.base());
     p.fillRect (pix.rect(), p.brush());
     doc.drawContents(&p, pix.rect());
     painter->drawPixmap(rect.x(), rect.y(), pix);
 }
Example #20
0
void ListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
	QString title = index.data(ListItem::ItemTitle).toString();
	QString description = index.data(ListItem::ItemDescription).toString();
	QIcon icon = QIcon::fromTheme(index.data(ListItem::ItemIcon).toString());
// 	QVariant data = index.data(ListItem::ItemData);

	painter->save();
	QPalette p;
	painter->fillRect(option.rect, p.brush((index.row() % 2 ) ? QPalette::Base : QPalette::AlternateBase));
	QStyle *style = QApplication::style();
	style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);
	
		QTextDocument doc;
		painter->translate(option.rect.topLeft());
		if (option.state & QStyle::State_Selected)
		{
		  painter->setPen(option.palette.color(QPalette::Normal, QPalette::HighlightedText));
		  doc.setDefaultStyleSheet("* { color: "+option.palette.color(QPalette::HighlightedText).name()+"; }");
		}
		else
		{
		  painter->setPen(option.palette.color(QPalette::Normal, QPalette::Text));
		  doc.setDefaultStyleSheet("* { color: "+option.palette.color(QPalette::Text).name()+"; }");
		}
		
		if(!icon.isNull())
		{
		  painter->drawPixmap(5,5,64,64, icon.pixmap(QSize(64,64)));
		}
		
		QFont f = painter->font();
		f.setBold(true);
		painter->setFont(f);
		painter->drawText(74,20, title);
		f.setBold(false);
		
		doc.setUndoRedoEnabled(false);
		doc.setDocumentMargin(0);
		doc.setTextWidth(option.rect.width()-79);
		doc.setUseDesignMetrics(true);
		doc.setHtml("<p>"+description+"</p>");
		QRectF rect = QRectF(QPoint(0,0),doc.size());
		painter->translate(74,20+QFontMetrics(f).height());
		doc.drawContents(painter, rect);
		painter->translate(-74,-20-QFontMetrics(f).height());

	painter->restore();
}
Example #21
0
void Annotation::paint(QPainter *painter, const QRectF &paintrect) const
{
	painter->save();
	painter->translate(paintrect.topLeft());

	const QRectF rect0(QPointF(), paintrect.size());

	painter->fillRect(rect0, background);

	QTextDocument doc;
	doc.setHtml(text);
	doc.setTextWidth(rect0.width());
	doc.drawContents(painter, rect0);

	painter->restore();
}
Example #22
0
void HTMLDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index) const
{
	paintRect(painter, option, index);
	QStyleOptionViewItemV4 options = option;
	initStyleOption(&options, index);
	painter->save();
	QTextDocument doc;
	doc.setHtml(options.text);
	doc.setTextWidth(options.rect.width());
	doc.setDefaultFont(options.font);
	options.text.clear();
	options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter);
	painter->translate(options.rect.left(), options.rect.top());
	QRect clip(0, 0, options.rect.width(), options.rect.height());
	doc.drawContents(painter, clip);
	painter->restore();
}
Example #23
0
//------------------------------------------------------------------------------
// Name: drawLabel
// Desc:
//------------------------------------------------------------------------------
void GraphNode::drawLabel(const QString &text) {

	QPainter painter(&picture_);
	painter.setBrush(QBrush(color_));
	painter.setPen(TextColor);

	// Since I always just take the points from graph_ and pass them to Qt
	// as pixel I also have to set the pixel size of the font.
	QFont font(NodeFont);
	font.setPixelSize(LabelFontSize);

	if(!font.exactMatch()) {
		QFontInfo fontinfo(font);
		qWarning("replacing font '%s' by font '%s'", qPrintable(font.family()), qPrintable(fontinfo.family()));
	}

	painter.setFont(font);
	
	// just to calculate the proper bounding box
	QRectF textBoundingRect;
	painter.drawText(QRectF(), Qt::AlignLeft | Qt::AlignTop, text, &textBoundingRect);
	
	// set some reasonable minimums
	if(textBoundingRect.width() < NodeWidth) {
		textBoundingRect.setWidth(NodeWidth);
	}
	
	if(textBoundingRect.height() < NodeHeight) {
		textBoundingRect.setHeight(NodeHeight);
	}

	// set the bounding box and then really draw it
	picture_.setBoundingRect(textBoundingRect.adjusted(-2, -2, +2, +2).toRect());
		
#if 1
	QTextDocument doc;
	doc.setDefaultFont(font);
	doc.setDocumentMargin(0);
	doc.setPlainText(text);
	auto highligher = new SyntaxHighlighter(&doc);
	doc.drawContents(&painter, textBoundingRect);
#else
	painter.drawText(textBoundingRect.adjusted(-2, -2, +2, +2), Qt::AlignLeft | Qt::AlignTop, text);
#endif
}
Example #24
0
void KsirkChatItem::paint(QPainter* p, 
                const QStyleOptionViewItem &option, int row)
{
//   kError() << "KsirkChatItem::paint";
  Q_UNUSED(row);

  QTextDocument fake; // used to allow to compute lines height
  fake.setHtml("gpl");
  fake.setDefaultFont(option.font);
  fake.adjustSize();
  fake.setTextWidth ( -1 );
  
  qreal h = fake.size().height();
  unsigned int x = 0;
  for (int i = 0 ; i < m_order.size(); i++)
  {
    QTextDocument rt;
    rt.setHtml(m_strings[i]);
    rt.setDefaultFont(option.font);
    rt.adjustSize();
    rt.setTextWidth ( -1 );
    QPixmap px(rt.size().toSize());
    px.fill();
    QPainter pa(&px);
    rt.drawContents(&pa);
    switch (m_order[i])
    {
    case Text:
//       kDebug() << "  paint string '" << m_strings[i] << "' at " << x << ", " << row*h << endl;
      p->drawPixmap(option.rect.x()+x,option.rect.y(),px);
      x += px.width();
    break;
    case Pixmap:
      if (! m_pixmaps[i].isNull())
      {
//         kDebug() << "  paint pixmap at " << x << ", " << row*h << endl;
        QPixmap scaled = m_pixmaps[i].scaledToHeight((int)h);
        p->drawPixmap(option.rect.x()+x,option.rect.y(),scaled);
        x+= scaled.width();
      }
    break;
    default: ;
    }
  }
}
Example #25
0
void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QListWidget *eventlist = (QListWidget*) this->parent();
    bool isFocusedList = true;
    if (eventlist)
        isFocusedList = eventlist->hasFocus();

    bool isSelectedItem = option.state & QStyle::State_Selected;
    QString text = index.data(Qt::DisplayRole).toString();
    text = getHtmlWithColours(text, isSelectedItem, isFocusedList);
    QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
    QSize iconSize = icon.actualSize(QSize(option.rect.size().height() * 2, option.rect.size().height()));
    QRect iconRect = QRect(option.rect.x() + EVENT_ITEM_ICON_MARGIN, option.rect.y() + EVENT_ITEM_ICON_MARGIN, iconSize.width(), iconSize.height());
    QPixmap iconPixmap = icon.pixmap(iconSize);
    QPoint textTopLeft = QPoint(iconRect.x() + iconSize.width() + EVENT_ITEM_ICON_MARGIN + EVENT_ITEM_TEXT_MARGIN, option.rect.y() + EVENT_ITEM_ICON_MARGIN + EVENT_ITEM_TEXT_MARGIN);
    QSize textSize = QSize(option.rect.width() - textTopLeft.x(), option.rect.height() - textTopLeft.y());
    QRect textRect = QRect(textTopLeft, textSize);
    QTextDocument document;
    document.setUndoRedoEnabled(false);

    if (isSelectedItem)
    {
        const QPalette::ColorRole color = (isFocusedList) ? QPalette::Highlight : QPalette::Window;
        painter->resetTransform();
        painter->fillRect(option.rect, option.palette.color(color));
    }

    //painter->save();
    //painter->restore();
    painter->resetTransform();

    document.setHtml(text);
    painter->drawPixmap(iconRect, iconPixmap);

    //painter->save();
    //painter->restore();
    painter->resetTransform();
    painter->translate(textRect.topLeft());
    painter->setRenderHint(QPainter::Antialiasing, true);

    document.drawContents(painter);

    //painter->save();
    //painter->restore();
}
Example #26
0
            void render_sequence( QPainter * painter, const QStyleOptionViewItem& option, const QString& text ) const {
                painter->save();
                QStyleOptionViewItemV4 op = option;
                QTextDocument document;
                QTextOption to;
                to.setWrapMode( QTextOption::WrapAtWordBoundaryOrAnywhere );
                document.setDefaultTextOption( to );
				QFont font;
				font.setFamily( "Consolas" );
				document.setDefaultFont( font );
				document.setTextWidth( op.rect.width() );
                document.setHtml( text );
                op.widget->style()->drawControl( QStyle::CE_ItemViewItem, &op, painter );
                painter->translate( op.rect.topLeft() );
                QRect clip( 0, 0, op.rect.width(), op.rect.height() );
                document.drawContents( painter, clip );
                painter->restore();
            }
void HTMLTextDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
    QStyleOptionViewItem options = option;
    initStyleOption(&options, index);

    painter->save();

    QTextDocument doc;
    doc.setHtml(options.text);

    options.text = QStringLiteral("");
    options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &option, painter);

    painter->translate(options.rect.left(), options.rect.top());
    QRect clip(0, 0, options.rect.width(), options.rect.height());
    doc.drawContents(painter, clip);

    painter->restore();
}
void RichTextDelegate::paint(QPainter* p, const QStyleOptionViewItem& o,
                             const QModelIndex& index) const
{
  QStyleOptionViewItemV4 ov4 = o;
  initStyleOption(&ov4, index);

  p->save();

  QTextDocument doc;
  doc.setHtml(ov4.text);

  ov4.text = "";
  ov4.widget->style()->drawControl(QStyle::CE_ItemViewItem, &ov4, p);

  p->translate(ov4.rect.left(), ov4.rect.top());
  QRect clip(0, 0, ov4.rect.width(), ov4.rect.height());
  doc.drawContents(p, clip);
  p->restore();
}
Example #29
0
void AppClassTreeDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index) const
{
    QStyleOptionViewItemV4 options = option;
    initStyleOption(&options, index);

    painter->save();

    QTextDocument doc;
    doc.setHtml(options.text);

    /* Call this to get the focus rect and selection background. */
    options.text = "";
    options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter);

    /* Draw using our rich text document. */
    painter->translate(options.rect.left(), options.rect.top());
    QRect clip(0, 0, options.rect.width(), options.rect.height());
    doc.drawContents(painter, clip);

    painter->restore();
}
Example #30
0
void TabWidget::paintEvent(QPaintEvent* e) {
	QTabWidget::paintEvent(e);
	QPainter p(this);
	if(isActive) {
		p.fillRect(e->rect(), QColor(32, 128, 255, 96));
	}

	float width = e->rect().size().width()/2;
	QTextDocument doc;

	doc.documentLayout()->setPaintDevice(p.device());
	doc.setHtml("<center><font size='10'><b><u>Open a document<u></b></font></center><font size='6'><ul><li>File menu > Open (Ctrl + O)</li><li>Drag and drop files here</li><li>If any, selecting file from the open documents list</li><li>Selecting file from the drop box in the header.</li></ul></font>");
	//doc.setTextWidth(width/2);
	p.setPen(palette().foreground().color());

	QRectF rct = e->rect();
	rct.setWidth(width);
	p.translate(rct.size().width()/2, rct.size().height()/2);
	doc.drawContents(&p, rct);

}