Example #1
1
void HtmlDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,const QModelIndex &index) const
{
    QStyleOptionViewItemV4 optionV4(option);
    initStyleOption(&optionV4, index);
    QStyle *style = optionV4.widget ? optionV4.widget->style() : QApplication::style();
    style->drawPrimitive(QStyle::PE_PanelItemViewItem, &optionV4, painter, optionV4.widget);

    QTextDocument doc;
    QString text = optionV4.text;
    doc.setHtml(text);
    doc.setPageSize( option.rect.size() );

    /// Painting item without text
    optionV4.text.clear();
    style->drawControl(QStyle::CE_ItemViewItem, &optionV4, painter);

    QAbstractTextDocumentLayout::PaintContext ctx;

    // Highlighting text if item is selected
    if (optionV4.state & QStyle::State_Selected)
        ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText));

    QRect textRect = option.rect;
    painter->save();
    painter->translate(textRect.topLeft());
    painter->setClipRect(textRect.translated(-textRect.topLeft()));
    doc.documentLayout()->draw(painter, ctx);
    painter->restore();
}
void QgsWelcomePageItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index ) const
{
  painter->save();

  QTextDocument doc;
  QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );

  QAbstractTextDocumentLayout::PaintContext ctx;
  QStyleOptionViewItemV4 optionV4 = option;

  QColor color;
  if ( option.state & QStyle::State_Selected && option.state & QStyle::State_HasFocus )
  {
    color = QColor( 255, 255, 255, 60 );
    ctx.palette.setColor( QPalette::Text, optionV4.palette.color( QPalette::Active, QPalette::HighlightedText ) );

    QStyle *style = QApplication::style();
    style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter, nullptr );
  }
  else if ( option.state & QStyle::State_Enabled )
  {
    color = QColor( 100, 100, 100, 30 );
    ctx.palette.setColor( QPalette::Text, optionV4.palette.color( QPalette::Active, QPalette::Text ) );

    QStyle *style = QApplication::style();
    style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter, nullptr );
  }
  else
  {
    color = QColor( 100, 100, 100, 30 );
    ctx.palette.setColor( QPalette::Text, optionV4.palette.color( QPalette::Disabled, QPalette::Text ) );
  }

  painter->setRenderHint( QPainter::Antialiasing );
  painter->setPen( QColor( 0, 0, 0, 0 ) );
  painter->setBrush( QBrush( color ) );
  painter->drawRoundedRect( option.rect.left() + 5, option.rect.top() + 5, option.rect.width() - 10, option.rect.height() - 10, 8, 8 );

  int titleSize = QApplication::fontMetrics().height() * 1.1;
  int textSize = titleSize * 0.85;

  doc.setHtml( QStringLiteral( "<div style='font-size:%1px;'><span style='font-size:%2px;font-weight:bold;'>%3</span><br>%4<br>%5</div>" ).arg( textSize ).arg( titleSize )
               .arg( index.data( QgsWelcomePageItemsModel::TitleRole ).toString(),
                     index.data( QgsWelcomePageItemsModel::PathRole ).toString(),
                     index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
  doc.setTextWidth( option.rect.width() - ( !icon.isNull() ? icon.width() + 35 : 35 ) );

  if ( !icon.isNull() )
  {
    painter->drawPixmap( option.rect.left() + 10, option.rect.top()  + 10, icon );
  }

  painter->translate( option.rect.left() + ( !icon.isNull() ? icon.width() + 25 : 15 ), option.rect.top() + 15 );
  ctx.clip = QRect( 0, 0, option.rect.width() - ( !icon.isNull() ? icon.width() - 35 : 25 ), option.rect.height() - 25 );
  doc.documentLayout()->draw( painter, ctx );

  painter->restore();
}
void
ConfigDelegateBase::drawCheckBox( QStyleOptionViewItemV4& opt, QPainter* p, const QWidget* w ) const
{
    QStyle* style = w ? w->style() : QApplication::style();
    opt.checkState == Qt::Checked ? opt.state |= QStyle::State_On : opt.state |= QStyle::State_Off;
    style->drawPrimitive( QStyle::PE_IndicatorViewItemCheck, &opt, p, w );
}
void KTp::ContactViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QStyle *style = QApplication::style();
    int textHeight = option.fontMetrics.height() * 2;

    style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);

    QRect avatarRect = option.rect.adjusted(0, 0, 0, -textHeight);
    QRect textRect = option.rect.adjusted(0, option.rect.height() - textHeight, 0, -3);

    QPixmap avatar;
    avatar.load(index.data(KTp::ContactAvatarPathRole).toString());
    if (avatar.isNull()) {
        avatar = QIcon::fromTheme(QStringLiteral("im-user-online")).pixmap(option.decorationSize);
    } else if (avatar.width() > option.decorationSize.width() || avatar.height() > option.decorationSize.height()) {
        //resize larger avatars if required
        avatar = avatar.scaled(option.decorationSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
        //draw leaving paddings on smaller (or non square) avatars
    }
    style->drawItemPixmap(painter, avatarRect, Qt::AlignCenter, avatar);


    QTextOption textOption;
    textOption.setAlignment(Qt::AlignCenter);
    textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
    painter->drawText(textRect, index.data().toString(), textOption);

}
Example #5
0
/**
 * @todo enable eliding (use QFontMetrics::elidedText() )
 */
void bicItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
  QStyleOptionViewItem opt = option;
  initStyleOption(&opt, index);

  // Background
  QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
  style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);

  const int margin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
  const QRect textArea = QRect(opt.rect.x() + margin, opt.rect.y() + margin, opt.rect.width() - 2 * margin, opt.rect.height() - 2 * margin);

  // Paint name
  painter->save();
  QFont smallFont = getSmallFont(opt);
  QFontMetrics metrics(opt.font);
  QFontMetrics smallMetrics(smallFont);
  QRect nameRect = style->alignedRect(opt.direction, Qt::AlignBottom, QSize(textArea.width(), smallMetrics.lineSpacing()), textArea);
  painter->setFont(smallFont);
  style->drawItemText(painter, nameRect, Qt::AlignBottom, QApplication::palette(), true, index.model()->data(index, bicModel::InstitutionNameRole).toString(), option.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Mid);
  painter->restore();

  // Paint BIC
  painter->save();
  QFont normal = painter->font();
  normal.setBold(true);
  painter->setFont(normal);
  QRect bicRect = style->alignedRect(opt.direction, Qt::AlignTop, QSize(textArea.width(), metrics.lineSpacing()), textArea);
  const QString bic = index.model()->data(index, Qt::DisplayRole).toString();
  style->drawItemText(painter, bicRect, Qt::AlignTop, QApplication::palette(), true, bic, option.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text);

  painter->restore();
}
bool RenderThemeQt::paintTextField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
    QStyle* style = 0;
    QPainter* painter = 0;
    QWidget* widget = 0;

    if (!getStylePainterAndWidgetFromPaintInfo(i, style, painter, widget))
        return true;

    QStyleOptionFrameV2 panel;
    
    panel.initFrom(widget);
    panel.rect = r;
    panel.state |= QStyle::State_Sunken;
    panel.features = QStyleOptionFrameV2::None;

    // Get the correct theme data for a button
    EAppearance appearance = applyTheme(panel, o);
    Q_ASSERT(appearance == TextFieldAppearance);

    // Now paint the text field.
    style->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, painter, widget);
    style->drawPrimitive(QStyle::PE_FrameLineEdit, &panel, painter, widget);
      
    return false;
}
Example #7
0
void RatingDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,const QModelIndex &index) const
{
    QStyleOptionViewItemV4 opt(option);
    QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
    style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);

    const int left = option.rect.left();
    const int top = option.rect.top();
    const int width = option.rect.width();
    const int height = option.rect.height();

    //Create base pixmap
    QPixmap pixmap(width, height);
    pixmap.fill(Qt::transparent);
    QPainter p(&pixmap);
    p.translate(-option.rect.topLeft());

    //Paint rating
    int rating = index.data(Qt::DisplayRole).toInt();
    StarRating starRating = StarRating(rating, StarRating::Medium);
    starRating.setRating(rating);
    QSize ratingSize = starRating.sizeHint();
    int ratingLeft = left + 2;
    int ratingTop = top + (height - ratingSize.height())/2;
    QRect ratingRect = QRect(QPoint(ratingLeft, ratingTop), ratingSize);
    starRating.setPoint(ratingRect.topLeft());
    starRating.paint(&p);

    p.end();

    //Draw finished pixmap
    painter->drawPixmap(option.rect.topLeft(), pixmap);
}
Example #8
0
void KisNodeDelegate::paint(QPainter *p, const QStyleOptionViewItem &o, const QModelIndex &index) const
{
    p->save();

    {
	QStyleOptionViewItemV4 option = getOptions(o, index);
        QStyle *style = option.widget ? option.widget->style() : QApplication::style();
        style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, p, option.widget);

        bool shouldGrayOut = index.data(KisNodeModel::ShouldGrayOutRole).toBool();
        if (shouldGrayOut) {
            option.state &= ~QStyle::State_Enabled;
        }

        p->setFont(option.font);

        drawColorLabel(p, option, index);
        drawFrame(p, option, index);
        drawThumbnail(p, option, index);
        drawText(p, option, index);
        drawIcons(p, option, index);
        drawVisibilityIconHijack(p, option, index);
        drawDecoration(p, option, index);
        drawExpandButton(p, option, index);

        drawProgressBar(p, option, index);
    }
    p->restore();
}
Example #9
0
void QItemDelegate::drawCheck(QPainter *painter,
                              const QStyleOptionViewItem &option,
                              const QRect &rect, Qt::CheckState state) const
{
    Q_D(const QItemDelegate);
    if (!rect.isValid())
        return;

    QStyleOptionViewItem opt(option);
    opt.rect = rect;
    opt.state = opt.state & ~QStyle::State_HasFocus;

    switch (state) {
    case Qt::Unchecked:
        opt.state |= QStyle::State_Off;
        break;
    case Qt::PartiallyChecked:
        opt.state |= QStyle::State_NoChange;
        break;
    case Qt::Checked:
        opt.state |= QStyle::State_On;
        break;
    }

    const QWidget *widget = d->widget(option);
    QStyle *style = widget ? widget->style() : QApplication::style();
    style->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &opt, painter, widget);
}
Example #10
0
void ChannelsDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt,
						  const QModelIndex &index) const
{
	QVariant data = index.data();
	if (data.canConvert<QTextDocument *>()) {
		QTextDocument *textDocument = data.value<QTextDocument *>();
		QStyleOptionViewItemV4 option(opt);
		QStyle *style = option.widget ? option.widget->style() : QApplication::style();
		painter->save();
		// Draw background.
		style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, option.widget);
		// Draw text using QTextDocument.
		int pad = 1;
		QRect textRect = option.rect.adjusted(pad, pad, -pad, -pad);
		QRect clipRect(0, 0, textRect.width(), textRect.height());
		painter->translate(textRect.x(), textRect.y());
		painter->setClipRect(clipRect);
		QAbstractTextDocumentLayout::PaintContext ctx;
		ctx.palette = option.palette;
		ctx.clip = QRect(clipRect);
		textDocument->documentLayout()->draw(painter, ctx);
		painter->restore();
	} else {
		QStyledItemDelegate::paint(painter, opt, index);
	}
}
	void ContactListDelegate::DrawAccount (QPainter *painter,
			QStyleOptionViewItemV4 o, const QModelIndex& index) const
	{
		QStyle *style = o.widget ?
				o.widget->style () :
				QApplication::style ();

		painter->save ();
		painter->setRenderHints (QPainter::HighQualityAntialiasing | QPainter::Antialiasing);

		style->drawPrimitive (QStyle::PE_PanelButtonCommand,
				&o, painter, o.widget);

		painter->restore ();

		o.font.setBold (true);

		QStyledItemDelegate::paint (painter, o, index);

		QObject *accObj = index.data (Core::CLRAccountObject).value<QObject*> ();
		IAccount *acc = qobject_cast<IAccount*> (accObj);
		IExtSelfInfoAccount *extAcc = qobject_cast<IExtSelfInfoAccount*> (accObj);

		QIcon accIcon = extAcc ? extAcc->GetAccountIcon () : QIcon ();
		if (accIcon.isNull ())
			accIcon = qobject_cast<IProtocol*> (acc->GetParentProtocol ())->GetProtocolIcon ();

		const QRect& r = o.rect;
		const int iconSize = r.height () - 2 * CPadding;

		QImage avatarImg;
		if (extAcc)
			avatarImg = extAcc->GetSelfAvatar ();
		if (avatarImg.isNull ())
			avatarImg = Core::Instance ().GetDefaultAvatar (iconSize);
		else
			avatarImg = avatarImg.scaled (iconSize, iconSize,
					Qt::KeepAspectRatio, Qt::SmoothTransformation);

		QPoint pxDraw = o.rect.topRight () - QPoint (CPadding, 0);

		if (!avatarImg.isNull ())
		{
			pxDraw.rx () -= avatarImg.width ();
			const QPoint& delta = QPoint (0, (iconSize - avatarImg.height ()) / 2);
			painter->drawPixmap (pxDraw + delta,
					QPixmap::fromImage (avatarImg));
			pxDraw.rx () -= CPadding;
		}

		if (!accIcon.isNull ())
		{
			const int size = std::min (16, iconSize);
			const QPixmap& px = accIcon.pixmap (size, size);
			pxDraw.rx () -= px.width ();
			const QPoint& delta = QPoint (0, (iconSize - px.height ()) / 2);
			painter->drawPixmap (pxDraw + delta, px);
		}
	}
Example #12
0
void UserDelegate::paint(QPainter * painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
	const QAbstractItemModel *m = index.model();
	const QModelIndex idxc1 = index.sibling(index.row(), 1);
	QVariant data = m->data(idxc1);
	QList<QVariant> ql = data.toList();

	painter->save();

	QStyleOptionViewItemV4 o = option;
	initStyleOption(&o, index);

	QStyle *style = o.widget->style();
	QIcon::Mode iconMode = QIcon::Normal;

	QPalette::ColorRole colorRole = ((o.state & QStyle::State_Selected) ? QPalette::HighlightedText : QPalette::Text);
#if defined(Q_OS_WIN)
	// Qt's Vista Style has the wrong highlight color for treeview items
	// We can't check for QStyleSheetStyle so we have to search the children list search for a QWindowsVistaStyle
	QList<QObject *> hierarchy = style->findChildren<QObject *>();
	hierarchy.insert(0, style);
	foreach (QObject *obj, hierarchy) {
		if (QString::fromUtf8(obj->metaObject()->className()) == QString::fromUtf8("QWindowsVistaStyle")) {
			colorRole = QPalette::Text;
			break;
		}
	}
#endif

	// draw background
	style->drawPrimitive(QStyle::PE_PanelItemViewItem, &o, painter, o.widget);

	// resize rect to exclude the flag icons
	o.rect = option.rect.adjusted(0, 0, -FLAG_DIMENSION * ql.count(), 0);

	// draw icon
	QRect decorationRect = style->subElementRect(QStyle::SE_ItemViewItemDecoration, &o, o.widget);
	o.icon.paint(painter, decorationRect, o.decorationAlignment, iconMode, QIcon::On);

	// draw text
	QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &o, o.widget);
	QString itemText = o.fontMetrics.elidedText(o.text, o.textElideMode, textRect.width());
	painter->setFont(o.font);
	style->drawItemText(painter, textRect, o.displayAlignment, o.palette, true, itemText, colorRole);

	// draw flag icons to original rect
	QRect ps = QRect(option.rect.right() - (ql.size() * FLAG_DIMENSION),
					 option.rect.y(), ql.size() * FLAG_DIMENSION,
					 option.rect.height());

	for (int i = 0; i < ql.size(); ++i) {
		QRect r = ps;
		r.setSize(QSize(FLAG_ICON_DIMENSION, FLAG_ICON_DIMENSION));
		r.translate(i * FLAG_DIMENSION + FLAG_ICON_PADDING, FLAG_ICON_PADDING);
		QRect p = QStyle::alignedRect(option.direction, option.decorationAlignment, r.size(), r);
		qvariant_cast<QIcon>(ql[i]).paint(painter, p, option.decorationAlignment, iconMode, QIcon::On);
	}

	painter->restore();
}
void RepoItemDelegate::paintRepoCategoryItem(QPainter *painter,
                                             const QStyleOptionViewItem& option,
                                             const RepoCategoryItem *item) const
{
    QBrush backBrush;
    QColor foreColor;
    bool hover = false;
    bool selected = false;

    if (option.state & (QStyle::State_HasFocus | QStyle::State_Selected)) {
        backBrush = option.palette.brush(QPalette::Highlight);
        foreColor = option.palette.color(QPalette::HighlightedText);
        selected = true;

    } else if (option.state & QStyle::State_MouseOver) {
        backBrush = option.palette.color(QPalette::Highlight).lighter(115);
        foreColor = option.palette.color(QPalette::HighlightedText);
        hover = true;

    } else {
        backBrush = option.palette.brush(QPalette::Base);
        foreColor = option.palette.color(QPalette::Text);
    }

    QStyle *style = QApplication::style();
    QStyleOptionViewItemV4 opt(option);
    opt.backgroundBrush = backBrush;
    painter->save();
    style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, 0);
    painter->restore();

    // Paint the expand/collapse indicator
    RepoTreeModel *model = (RepoTreeModel *)item->model();
    RepoTreeView *view = model->treeView();
    bool expanded = view->isExpanded(model->indexFromItem(item));

    QRect indicator_rect(option.rect.topLeft(),
                         option.rect.bottomLeft() + QPoint(option.rect.height(), 0));
    painter->save();
    painter->setPen(foreColor);
    painter->setFont(awesome->font(16));
    painter->drawText(indicator_rect,
                      Qt::AlignCenter,
                      QChar(expanded ? icon_caret_down : icon_caret_right),
                      &indicator_rect);
    painter->restore();

    // Paint category name
    painter->save();
    QPoint category_name_pos = indicator_rect.topRight() + QPoint(kMarginBetweenIndicatorAndName, 0);
    QRect category_name_rect(category_name_pos,
                             option.rect.bottomRight() - QPoint(kPadding, 0));
    painter->setPen(foreColor);
    painter->drawText(category_name_rect,
                      Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap,
                      fitTextToWidth(item->name() + QString().sprintf(" [%d]", item->rowCount()),
                                     option.font, category_name_rect.width()));
    painter->restore();
}
Example #14
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();
}
Example #15
0
void K3b::DeviceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& optionOrig, const QModelIndex& index ) const
{
    if ( index.data( K3b::DeviceModel::IsDevice ).toBool() ) {
        painter->save();
        painter->setRenderHint(QPainter::Antialiasing);

        // HACK: we erase the branch
        QStyleOptionViewItemV4 option( optionOrig );
        option.rect.setLeft( 0 );
        painter->fillRect( option.rect, option.palette.base() );

        QStyle* style = QApplication::style();
        const FontsAndMetrics fam( option.font );
        const QPalette::ColorRole textRole = (option.state & QStyle::State_Selected) ?
                                              QPalette::HighlightedText : QPalette::Text;
        
        const QRect itemRect( option.rect.left() + fam.margin, option.rect.top() + fam.margin,
                              option.rect.width() - 2*fam.margin, option.rect.height() - 2*fam.margin );
        const QSize iconSize( itemRect.height(), itemRect.height() );
        const QSize mediumSize( itemRect.width() - iconSize.width() - fam.margin,
                                itemRect.height() - fam.spacing - fam.deviceFontM.height() );
        const QSize devicemSize( itemRect.width() - iconSize.width() - fam.margin,
                                 itemRect.height() - fam.spacing - fam.mediumFontM.height() );
        const QRect iconRect = style->alignedRect( option.direction, Qt::AlignLeft | Qt::AlignVCenter, iconSize, itemRect );
        const QRect mediumRect = style->alignedRect( option.direction, Qt::AlignRight | Qt::AlignTop, mediumSize, itemRect );
        const QRect deviceRect = style->alignedRect( option.direction, Qt::AlignRight | Qt::AlignBottom, devicemSize, itemRect );
        
        // draw background
        style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter );

        // draw decoration
        QPixmap pixmap = decoration( option, index, iconSize );
        painter->drawPixmap( iconRect, pixmap );

        // draw medium text
        painter->setFont( fam.mediumFont );
        QString text = index.data( Qt::DisplayRole ).toString();
        style->drawItemText( painter, mediumRect, option.displayAlignment, option.palette,
                             option.state & QStyle::State_Enabled,
                             fam.mediumFontM.elidedText( text, option.textElideMode, mediumRect.width() ),
                             textRole );

        // draw fixed device text
        painter->setFont( fam.deviceFont );
        text = index.data( K3b::DeviceModel::Vendor ).toString() + " - " + index.data( K3b::DeviceModel::Description ).toString();
        style->drawItemText( painter, deviceRect, option.displayAlignment, option.palette,
                             option.state & QStyle::State_Enabled,
                             fam.deviceFontM.elidedText( text, option.textElideMode, deviceRect.width() ),
                             textRole );

        painter->restore();
    }
    else {
        KFileItemDelegate::paint( painter, optionOrig, index );
    }
}
Example #16
0
/** @todo elide texts */
void ibanBicItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
    QStyleOptionViewItem opt = option;
    initStyleOption(&opt, index);

    // Background
    QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
    style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);

    const int margin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
    const QRect textArea = QRect(opt.rect.x() + margin, opt.rect.y() + margin, opt.rect.width() - 2 * margin, opt.rect.height() - 2 * margin);

    // Do not paint text if the edit widget is shown
    const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(opt.widget);
    if (view && view->indexWidget(index))
        return;

    // Get data
    payeeIdentifierTyped<payeeIdentifiers::ibanBic> ibanBic = ibanBicByIndex(index);

    // Paint Bic
    painter->save();
    const QFont smallFont = painter->font();
    const QFontMetrics metrics(opt.font);
    const QFontMetrics smallMetrics(smallFont);
    const QRect bicRect = style->alignedRect((opt.direction  == Qt::RightToLeft) ? Qt::LeftToRight : Qt::RightToLeft, Qt::AlignTop, QSize(textArea.width(), smallMetrics.lineSpacing()),
                          QRect(textArea.left(), metrics.lineSpacing() + textArea.top(), textArea.width(), smallMetrics.lineSpacing())
                                            );
    painter->setFont(smallFont);
    style->drawItemText(painter, bicRect, Qt::AlignBottom | Qt::AlignRight, QApplication::palette(), true, ibanBic->storedBic(), opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text);
    painter->restore();

    // Paint Bank name
    painter->save();
    const QRect nameRect = style->alignedRect(opt.direction, Qt::AlignTop, QSize(textArea.width(), smallMetrics.lineSpacing()),
                           QRect(textArea.left(), metrics.lineSpacing() + textArea.top(), textArea.width(), smallMetrics.lineSpacing())
                                             );
    style->drawItemText(painter, nameRect, Qt::AlignBottom, QApplication::palette(), true, ibanBic->institutionName(), opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text);
    painter->restore();

    // Paint IBAN
    painter->save();
    QFont normal = painter->font();
    normal.setBold(true);
    painter->setFont(normal);
    const QRect ibanRect = style->alignedRect(opt.direction, Qt::AlignTop, QSize(textArea.width(), metrics.lineSpacing()), textArea);
    const QString bic = index.model()->data(index, Qt::DisplayRole).toString();
    style->drawItemText(painter, ibanRect, Qt::AlignTop, QApplication::palette(), true, ibanBic->paperformatIban(), opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text);
    painter->restore();

    // Paint type
    painter->save();
    QRect typeRect = style->alignedRect(opt.direction, Qt::AlignTop | Qt::AlignRight, QSize(textArea.width() / 5, metrics.lineSpacing()), textArea);
    style->drawItemText(painter, typeRect, Qt::AlignTop | Qt::AlignRight, QApplication::palette(), true, i18n("IBAN & BIC"), opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text);
    painter->restore();
}
void ProgressBarDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option,
 const QModelIndex &index ) const
{
    QStyle *style;

    QStyleOptionViewItemV4 opt = option;
    initStyleOption( &opt, index );

    style = opt.widget ? opt.widget->style() : QApplication::style();
    style->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter );

    if ( !( opt.state & QStyle::State_Editing ) ) {
        bool ok = false;
        (void) index.data().toInt(&ok);
        if ( ok ) {
            QStyleOptionProgressBar pbOption;
            pbOption.QStyleOption::operator=( option );
            initStyleOptionProgressBar( &pbOption, index );

            style->drawControl( QStyle::CE_ProgressBar, &pbOption, painter );
            // Draw focus, copied from qt
            if (opt.state & QStyle::State_HasFocus) {
                painter->save();
                QStyleOptionFocusRect o;
                o.QStyleOption::operator=( opt );
                o.rect = style->subElementRect( QStyle::SE_ItemViewItemFocusRect, &opt, opt.widget );
                o.state |= QStyle::State_KeyboardFocusChange;
                o.state |= QStyle::State_Item;
                QPalette::ColorGroup cg = ( opt.state & QStyle::State_Enabled )
                                ? QPalette::Normal : QPalette::Disabled;
                o.backgroundColor = opt.palette.color( cg, ( opt.state & QStyle::State_Selected )
                                                ? QPalette::Highlight : QPalette::Window );
                style->drawPrimitive( QStyle::PE_FrameFocusRect, &o, painter, opt.widget );
                //kDebug(planDbg())<<"Focus"<<o.rect<<opt.rect<<pbOption.rect;
                painter->restore();
            }
        } else {
            EnumDelegate del;
            del.paint( painter, option, index );
        }
    }
}
    void AccountDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
    {
        painter->save();

        if (const QStyleOptionViewItemV4 * itemOptionV4 = qstyleoption_cast< const QStyleOptionViewItemV4 * >(&option)) {
		    // Collect option information
            const QStyleOptionViewItemV3 * optionV3 = qstyleoption_cast< const QStyleOptionViewItemV3 * >(&option);
            const QWidget * widget = optionV3 ? optionV3->widget : 0;
            QStyle * style = widget ? widget->style() : QApplication::style();
			QStyleOptionViewItemV4 opt(option);
            initStyleOption(&opt, index);

            // Draw standard background
            style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, widget);

            QPalette::ColorGroup group = (option.state & QStyle::State_Active) ? QPalette::Active : QPalette::Inactive;
            if (option.state & QStyle::State_Selected) {
                painter->setPen(option.palette.color(group, QPalette::HighlightedText));
            } else {
                painter->setPen(index.data(Qt::ForegroundRole).value< QBrush >().color());
            }

            // Get textual information
            QString description(index.data(Qt::DisplayRole).toString());
            QString username = "******";
            if (static_cast< Qt::CheckState >(index.sibling(index.row(), 0).data(Qt::CheckStateRole).toInt()) == Qt::Checked) {
                username = index.sibling(index.row(), index.column() + 1).data(Qt::DisplayRole).toString();
            }

            // Draw textual information
            QFont smaller(option.font);
            smaller.setPointSizeF(smaller.pointSizeF() * 0.85);
            smaller.setItalic(true);
            QFontMetrics smallerMetrics(smaller);
            int height = row_height(option);
            int divider = height / 2 + (option.fontMetrics.height() - smallerMetrics.height()) / 2;
            painter->setBrush(Qt::NoBrush);

            QRect descriptionRect = option.rect;
            int flags = Qt::AlignLeft | Qt::AlignVCenter;
            if (!username.isEmpty()) {
                painter->setFont(smaller);
                painter->drawText(option.rect.adjusted(0, divider, 0, 0), (Qt::AlignLeft | Qt::AlignTop), username);
                descriptionRect = descriptionRect.adjusted(0, 0, 0, -divider);
                painter->setFont(option.font);
                flags &= ~Qt::AlignVCenter;
                flags |= Qt::AlignBottom;
            }
            painter->drawText(descriptionRect, flags, description);
        }

        painter->restore();
    }
Example #19
0
	// reimplemented
	virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
	{
		QStyleOptionViewItemV4 opt(option);
		opt.showDecorationSelected = true;
		opt.rect.adjust(0, 0, 0, -1);

		painter->save();
		QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
		style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);

		QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
		QSize iconSize;
#if 0
		if (icon.availableSizes().isEmpty())
			iconSize = icon.availableSizes().first();
		else
#endif
			int s = PsiIconset::instance()->system().iconSize();
			iconSize = QSize(s,s);
		QRect iconRect = opt.rect;
		iconRect.setLeft(4);
		iconRect.setWidth(iconSize.width());
		icon.paint(painter, iconRect, Qt::AlignCenter, QIcon::Normal, QIcon::On);

		QRect textRect = opt.rect;
		textRect.setLeft(iconRect.right() + 8);
		QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
		                          ? QPalette::Normal : QPalette::Disabled;
		if (cg == QPalette::Normal && !(option.state & QStyle::State_Active)) {
			cg = QPalette::Inactive;
		}
		if (option.state & QStyle::State_Selected) {
			painter->setPen(option.palette.color(cg, QPalette::HighlightedText));
		}
		else {
			painter->setPen(option.palette.color(cg, QPalette::Text));
		}
		painter->drawText(textRect, index.data(Qt::DisplayRole).toString(), Qt::AlignLeft | Qt::AlignVCenter);
		drawFocus(painter, option, option.rect); // not opt, because drawFocus() expects normal rect
		painter->restore();

		painter->save();
		QPen pen(QColor(0xE0, 0xE0, 0xE0));
		QVector<qreal> dashes;
		dashes << 1.0 << 1.0;
		pen.setCapStyle(Qt::FlatCap);
		pen.setDashPattern(dashes);

		painter->setPen(pen);
		painter->drawLine(option.rect.left(), option.rect.bottom(), option.rect.right(), option.rect.bottom());
		painter->restore();
	}
    void paintEvent( QPaintEvent* /*pPaintEvent*/ )
    {
        if( m_Selected )
        {
            QStyle* style = this->style();

            QStyleOptionFocusRect option;
            option.initFrom( this );
            option.rect.adjust( 2, 2, -2, -2 );

            QPainter painter( this );
            style->drawPrimitive( QStyle::PE_FrameFocusRect, &option, &painter, this );
        }
    }
/*! \reimp */
void QToolBar::paintEvent(QPaintEvent *)
{
    Q_D(QToolBar);

    QPainter p(this);
    QStyle *style = this->style();
    QStyleOptionToolBar opt;
    initStyleOption(&opt);

    if (d->layout->expanded || d->layout->animating || isWindow()) {
        //if the toolbar is expended, we need to fill the background with the window color
        //because some styles may expects that.
        p.fillRect(opt.rect, palette().background());
        style->drawControl(QStyle::CE_ToolBar, &opt, &p, this);
        style->drawPrimitive(QStyle::PE_FrameMenu, &opt, &p, this);
    } else {
        style->drawControl(QStyle::CE_ToolBar, &opt, &p, this);
    }

    opt.rect = style->subElementRect(QStyle::SE_ToolBarHandle, &opt, this);
    if (opt.rect.isValid())
        style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &opt, &p, this);
}
Example #22
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 #23
0
void RazorPanelPluginPrivate::paintEvent(QPaintEvent* event)
{
    Q_Q(RazorPanelPlugin);

    if (mMovable)
    {
        QPainter p(q);
        QStyle *style = q->style();
        QStyleOptionToolBar opt;
        initStyleOption(&opt);

        opt.rect = style->subElementRect(QStyle::SE_ToolBarHandle, &opt, q);
        if (opt.rect.isValid())
            style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &opt, &p, q);
    }
}
Example #24
0
	void PlaylistDelegate::PaintAlbum (QPainter *painter,
			const QStyleOptionViewItem& optionOld, const QModelIndex& index) const
	{
		QStyleOptionViewItemV4 option = optionOld;
		const auto& info = index.data (Player::Role::Info).value<MediaInfo> ();

		QStyle *style = option.widget ?
				option.widget->style () :
				QApplication::style ();

		style->drawPrimitive (QStyle::PE_PanelItemViewItem, &option, painter, option.widget);
		const int maxIconHeight = option.rect.height () - Padding * 2;
		QPixmap px = index.data (Player::Role::AlbumArt).value<QPixmap> ();
		px = px.scaled (maxIconHeight, maxIconHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
		painter->drawPixmap (option.rect.left () + Padding, option.rect.top () + Padding, px);

		const QFont& font = option.font;
		QFont bold = font;
		bold.setBold (true);
		QFont italic = font;
		italic.setItalic (true);
		QFont boldItalic = bold;
		boldItalic.setItalic (true);

		int x = option.rect.left () + maxIconHeight + 3 * Padding;
		int y = option.rect.top ();
		painter->save ();

		auto append = [&x, &y, painter] (const QString& text, const QFont& font)
		{
			painter->setFont (font);
			y += QFontMetrics (font).boundingRect (text).height ();
			painter->drawText (x, y, text);
		};
		append (info.Album_, bold);
		append (info.Artist_, boldItalic);
		append (info.Genres_.join (" / "), italic);
		append (QString::number (info.Year_), font);

		const int length = index.data (Player::Role::AlbumLength).toInt ();
		auto lengthStr = Util::MakeTimeFromLong (length);
		if (lengthStr.startsWith ("00:"))
			lengthStr = lengthStr.mid (3);
		painter->drawText (option.rect.adjusted (Padding, Padding, -Padding, -Padding), Qt::AlignRight, lengthStr);

		painter->restore ();
	}
Example #25
0
void LabeledSection::updateIndicator()
{
   if (mpSectionWidget != NULL)
   {
      bool bVisible = mpSectionWidget->isVisible();

      // Show the indicator
      mpExpandLabel->show();

      // Update the indicator pixmap
      QStyle* pStyle = style();
      if (pStyle != NULL)
      {
         QPixmap labelPixmap(9, 9);
         labelPixmap.fill(Qt::white);

         QStyleOption option;
         option.rect = labelPixmap.rect();
         option.state = QStyle::State_Children;
         if (bVisible == true)
         {
            option.state |= QStyle::State_Open;
         }

         QPainter pixmapPainter(&labelPixmap);
         pStyle->drawPrimitive(QStyle::PE_IndicatorBranch, &option, &pixmapPainter);

         mpExpandLabel->setPixmap(labelPixmap);
      }

      // Emit the signal
      if (bVisible == true)
      {
         emit expanded();
      }
      else
      {
         emit collapsed();
      }
   }
   else
   {
      // Hide the indicator
      mpExpandLabel->hide();
   }
}
Example #26
0
void KPageListViewDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
  if ( !index.isValid() )
    return;

  QStyleOptionViewItemV4 opt(option);
  opt.showDecorationSelected = true;
  QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();

  int iconSize = style->pixelMetric(QStyle::PM_IconViewIconSize);
  const QString text = index.model()->data( index, Qt::DisplayRole ).toString();
  const QIcon icon = index.model()->data( index, Qt::DecorationRole ).value<QIcon>();
  const QPixmap pixmap = icon.pixmap( iconSize, iconSize );

  QFontMetrics fm = painter->fontMetrics();
  int wp = pixmap.width();
  int hp = pixmap.height();

  QTextLayout iconTextLayout( text, option.font );
  QTextOption textOption( Qt::AlignHCenter );
  iconTextLayout.setTextOption( textOption );
  int maxWidth = qMax( 3 * wp, 8 * fm.height() );
  layoutText( &iconTextLayout, maxWidth );

  QPen pen = painter->pen();
  QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
                            ? QPalette::Normal : QPalette::Disabled;
  if ( cg == QPalette::Normal && !(option.state & QStyle::State_Active) )
    cg = QPalette::Inactive;

  style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
  if ( option.state & QStyle::State_Selected ) {
    painter->setPen( option.palette.color( cg, QPalette::HighlightedText ) );
  } else {
    painter->setPen( option.palette.color( cg, QPalette::Text ) );
  }

  painter->drawPixmap( option.rect.x() + (option.rect.width()/2)-(wp/2), option.rect.y() + 5, pixmap );
  if ( !text.isEmpty() )
    iconTextLayout.draw( painter, QPoint( option.rect.x() + (option.rect.width()/2)-(maxWidth/2), option.rect.y() + hp+7 ) );

  painter->setPen( pen );

  drawFocus( painter, option, option.rect );
}
void KoDocumentSectionDelegate::paint(QPainter *p, const QStyleOptionViewItem &o, const QModelIndex &index) const
{
    p->save();
    {
        QStyleOptionViewItemV4 option = getOptions(o, index);
        QStyle *style = option.widget ? option.widget->style() : QApplication::style();
        style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, p, option.widget);

        p->setFont(option.font);

        drawText(p, option, index);
        drawIcons(p, option, index);
        drawThumbnail(p, option, index);
        drawDecoration(p, option, index);
        drawProgressBar(p, option, index);
    }
    p->restore();
}
Example #28
0
void QgsWelcomePageItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index ) const
{
  painter->save();

  QTextDocument doc;
  QAbstractTextDocumentLayout::PaintContext ctx;

  QColor color;
  if ( option.state & QStyle::State_Selected )
  {
    color = QColor( 255, 255, 255, 60 );
    QStyle *style = QApplication::style();
    style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter, NULL );
  }
  else if ( option.state & QStyle::State_Enabled )
  {
    color = QColor( 100, 100, 100, 30 );
  }
  else
  {
    color = QColor( 100, 100, 100, 30 );
    ctx.palette.setColor( QPalette::Text, QColor( 150, 150, 150, 255 ) );
  }

  painter->setRenderHint( QPainter::Antialiasing );
  painter->setPen( QColor( 0, 0, 0, 0 ) );
  painter->setBrush( QBrush( color ) );
  painter->drawRoundedRect( option.rect.left() + 5, option.rect.top() + 5, option.rect.width() - 10, option.rect.height() - 10, 8, 8 );

  doc.setHtml( QString( "<span style='font-size:18px;font-weight:bold;'>%1</span><br>%2<br>%3" ).arg( index.data( QgsWelcomePageItemsModel::TitleRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::PathRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
  doc.setTextWidth( 800 );

  QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );
  if ( !icon.isNull() )
  {
    painter->drawPixmap( option.rect.left() + 10, option.rect.top()  + 10, icon );
  }

  painter->translate( option.rect.left() + ( !icon.isNull() ? icon.width() + 25 : 15 ), option.rect.top() + 15 );
  ctx.clip = QRect( 0, 0, option.rect.width() - ( !icon.isNull() ? icon.width() - 35 : 25 ), option.rect.height() - 25 );
  doc.documentLayout()->draw( painter, ctx );

  painter->restore();
}
Example #29
0
void AnnotatedItemDelegate::paint(QPainter *painter,
                                  const QStyleOptionViewItem &option,
                                  const QModelIndex &index) const
{
    auto opt = option;
    initStyleOption(&opt, index);

    QStyle *style = QApplication::style();
    style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
    style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget);

    QString annotation = index.data(m_annotationRole).toString();
    if (!annotation.isEmpty()) {

        int newlinePos = annotation.indexOf(QLatin1Char('\n'));
        if (newlinePos != -1) {
            // print first line with '...' at end
            const QChar ellipsisChar(0x2026);
            annotation = annotation.left(newlinePos) + ellipsisChar;
        }

        QPalette disabled(opt.palette);
        disabled.setCurrentColorGroup(QPalette::Disabled);

        painter->save();
        painter->setPen(disabled.color(QPalette::WindowText));

        static int extra = opt.fontMetrics.width(m_delimiter) + 10;
        const QPixmap &pixmap = opt.icon.pixmap(opt.decorationSize);
        const QRect &iconRect = style->itemPixmapRect(opt.rect, opt.decorationAlignment, pixmap);
        const QRect &displayRect = style->itemTextRect(opt.fontMetrics, opt.rect,
            opt.displayAlignment, true, index.data(Qt::DisplayRole).toString());
        QRect annotationRect = style->itemTextRect(opt.fontMetrics, opt.rect,
            opt.displayAlignment, true, annotation);
        annotationRect.adjust(iconRect.width() + displayRect.width() + extra, 0,
                              iconRect.width() + displayRect.width() + extra, 0);

        QApplication::style()->drawItemText(painter, annotationRect,
            Qt::AlignLeft | Qt::AlignBottom, disabled, true, annotation);

        painter->restore();
    }
}
// draws the preview
void ItemsViewDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& /* index */ ) const
{
    int margin = option.fontMetrics.height() / 2;

    QStyle* style = QApplication::style();
    style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter, 0 );

    painter->save();

    if( option.state & QStyle::State_Selected )
    {
        painter->setPen( QPen( option.palette.highlightedText().color() ) );
    }
    else
    {
        painter->setPen( QPen( option.palette.text().color() ) );
    }

    // const GluonPlayer::GameItemsModel* realmodel = qobject_cast<const GluonPlayer::GameItemsModel*>(index.model());

    // if (realmodel->hasPreviewImages()) {
    int height = option.rect.height();
    QPoint point( option.rect.left() + margin, option.rect.top() + ( ( height - PreviewHeight ) / 2 ) );

    QImage image = KIcon( "gluon-cretor" ).pixmap( 32, 32 ).toImage();
    if( !image.isNull() )
    {
        point.setX( ( PreviewWidth - image.width() ) / 2 + 5 );
        point.setY( option.rect.top() + ( ( height - image.height() ) / 2 ) );
        painter->drawImage( point, image );

        QPoint framePoint( point.x() - 5, point.y() - 5 );
        painter->drawPixmap( framePoint, KIcon( "gluon-creator" ).pixmap( 32, 32 ).scaled( image.width() + 10, image.height() + 10 ) );
    }
    else
    {
        QRect rect( point, QSize( PreviewWidth, PreviewHeight ) );
        painter->drawText( rect, Qt::AlignCenter | Qt::TextWordWrap, i18n( "Loading Preview" ) );
    }
    // }
    painter->restore();
}