void HighlightingItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                                     const QModelIndex &index) const
{
    static const int iconSize = 16;

    painter->save();

    const QStyleOptionViewItem opt = setOptions(index, option);
    painter->setFont(opt.font);

    QItemDelegate::drawBackground(painter, opt, index);

    // ---- do the layout
    QRect checkRect;
    QRect pixmapRect;
    QRect textRect;

    // check mark
    const bool checkable = (index.model()->flags(index) & Qt::ItemIsUserCheckable);
    Qt::CheckState checkState = Qt::Unchecked;
    if (checkable) {
        QVariant checkStateData = index.data(Qt::CheckStateRole);
        checkState = static_cast<Qt::CheckState>(checkStateData.toInt());
        checkRect = doCheck(opt, opt.rect, checkStateData);
    }

    // icon
    const QIcon icon = index.model()->data(index, Qt::DecorationRole).value<QIcon>();
    if (!icon.isNull()) {
        const QSize size = icon.actualSize(QSize(iconSize, iconSize));
        pixmapRect = QRect(0, 0, size.width(), size.height());
    }

    // text
    textRect = opt.rect.adjusted(0, 0, checkRect.width() + pixmapRect.width(), 0);

    // do layout
    doLayout(opt, &checkRect, &pixmapRect, &textRect, false);
    // ---- draw the items
    // icon
    if (!icon.isNull())
        icon.paint(painter, pixmapRect, option.decorationAlignment);

    // line numbers
    const int lineNumberAreaWidth = drawLineNumber(painter, opt, textRect, index);
    textRect.adjust(lineNumberAreaWidth, 0, 0, 0);

    // text and focus/selection
    drawText(painter, opt, textRect, index);
    QItemDelegate::drawFocus(painter, opt, opt.rect);

    // check mark
    if (checkable)
        QItemDelegate::drawCheck(painter, opt, checkRect, checkState);

    painter->restore();
}
Ejemplo n.º 2
0
void TxViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                      const QModelIndex &index ) const
    {
        painter->save();

        QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
        QRect mainRect = option.rect;
        QRect decorationRect(mainRect.topLeft(), QSize(DECORATION_SIZE, DECORATION_SIZE));
        int xspace = DECORATION_SIZE + 8;
        int ypad = 6;
        int halfheight = (mainRect.height() - 2*ypad)/2;
        QRect amountRect(mainRect.left() + xspace, mainRect.top()+ypad, mainRect.width() - xspace, halfheight);
        QRect addressRect(mainRect.left() + xspace, mainRect.top()+ypad+halfheight, mainRect.width() - xspace, halfheight);
        icon.paint(painter, decorationRect);

        QDateTime date = index.data(TransactionTableModel::DateRole).toDateTime();
        QString address = index.data(Qt::DisplayRole).toString();
        qint64 amount = index.data(TransactionTableModel::AmountRole).toLongLong();
        bool confirmed = index.data(TransactionTableModel::ConfirmedRole).toBool();
        QVariant value = index.data(Qt::ForegroundRole);
        QColor foreground = option.palette.color(QPalette::Text);
        if(value.canConvert<QBrush>())
        {
            QBrush brush = qvariant_cast<QBrush>(value);
            foreground = brush.color();
        }

        painter->setPen(foreground);
        painter->drawText(addressRect, Qt::AlignLeft|Qt::AlignVCenter, address);

        if(amount < 0)
        {
            foreground = COLOR_NEGATIVE;
        }
        else if(!confirmed)
        {
            foreground = COLOR_UNCONFIRMED;
        }
        else
        {
            foreground = option.palette.color(QPalette::Text);
        }
        painter->setPen(foreground);
        QString amountText = ShillingUnits::formatWithUnit(unit, amount, true);
        if(!confirmed)
        {
            amountText = QString("[") + amountText + QString("]");
        }
        painter->drawText(amountRect, Qt::AlignRight|Qt::AlignVCenter, amountText);

        painter->setPen(option.palette.color(QPalette::Text));
        painter->drawText(amountRect, Qt::AlignLeft|Qt::AlignVCenter, GUIUtil::dateTimeStr(date));

        painter->restore();
}
QSizeF QgsLayerTreeModelLegendNode::drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const
{
    QIcon symbolIcon = data( Qt::DecorationRole ).value<QIcon>();
    if ( symbolIcon.isNull() )
        return QSizeF();

    if ( ctx )
        symbolIcon.paint( ctx->painter, ctx->point.x(), ctx->point.y() + ( itemHeight - settings.symbolSize().height() ) / 2,
                          settings.symbolSize().width(), settings.symbolSize().height() );
    return settings.symbolSize();
}
Ejemplo n.º 4
0
void ItemViewImageDelegate::drawPanelSideIcon(QPainter* p, bool left, bool right) const
{
    Q_D(const ItemViewImageDelegate);

    const int iconSize = qBound(16, d->rect.width() / 8 - 2, 48);

    if (left)
    {
        QRect r(3, d->rect.height()/2 - iconSize/2, iconSize, iconSize);
        QIcon icon = QIcon::fromTheme(QLatin1String("go-previous"));
        icon.paint(p, r);
    }

    if (right)
    {
        QRect r(d->rect.width() - 3 - iconSize, d->rect.height()/2 - iconSize/2, iconSize, iconSize);
        QIcon icon = QIcon::fromTheme(QLatin1String("go-next"));
        icon.paint(p, r);
    }
}
Ejemplo n.º 5
0
void ItemViewShowfotoDelegate::drawGeolocationIndicator(QPainter* p, const QRect& r) const
{
    if (!r.isNull())
    {
        QIcon icon = QIcon::fromTheme(QLatin1String("applications-internet"));
        qreal op   = p->opacity();
        p->setOpacity(0.5);
        icon.paint(p, r);
        p->setOpacity(op);
    }
}
Ejemplo n.º 6
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();
	}
Ejemplo n.º 7
0
void FourWinItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{

    if(option.state & QStyle::State_Selected){
        painter->fillRect(option.rect, option.palette.color(QPalette::Highlight));
    }

    QIcon ic = QIcon(qvariant_cast<QPixmap>(index.data(Qt::DecorationRole)));
    QString txt = index.data(Qt::DisplayRole).toString();
    QRect r = option.rect.adjusted(0, 0, 0, 0);
    ic.paint(painter, r, Qt::AlignVCenter|Qt::AlignLeft);
    r = r.adjusted(r.height()+20, 0, 0, 0);
    painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignVCenter|Qt::AlignLeft|Qt::TextWordWrap, txt, &r);
}
Ejemplo n.º 8
0
QPixmap AvatarButton::paintRoundBorder(QPixmap &userPicture, bool thumbnailMode, bool mouseIsHovered)
{
	// Paint round border for userpic
	QPixmap avatarMask;
	QIcon avatarBorder;
	QIcon userpic;

	if (thumbnailMode)
	{
		avatarMask.load(AVATAR_TRANSPARENCY_MASK_SMALL);
		if (mouseIsHovered)
			avatarBorder.addFile(AVATAR_HOVER_BORDER_SMALL);
		else
			avatarBorder.addFile(AVATAR_BORDER_SMALL);

		userpic.addPixmap(userPicture.scaled(USERPIC_SMALL_WIDTH - 4, USERPIC_SMALL_HEIGHT - 4, Qt::KeepAspectRatioByExpanding));
	}
	else
	{
		avatarMask.load(AVATAR_TRANSPARENCY_MASK_MAX);
		if (mouseIsHovered)
			avatarBorder.addFile(AVATAR_HOVER_BORDER_MAX);
		else
			avatarBorder.addFile(AVATAR_BORDER_MAX);

		userpic.addPixmap(userPicture.scaled(USERPIC_MAX_WIDTH - 2, USERPIC_MAX_HEIGHT - 2, Qt::KeepAspectRatioByExpanding));
	}
	
	QPainter imgPainter(&avatarMask);
	imgPainter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
	imgPainter.fillRect(avatarMask.rect(), QBrush(Qt::white));

	userpic.paint(&imgPainter, avatarMask.rect(), Qt::AlignCenter, QIcon::Normal);
	
	imgPainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
	avatarBorder.paint(&imgPainter, avatarMask.rect(), Qt::AlignCenter, QIcon::Normal);

	return avatarMask;
}
Ejemplo n.º 9
0
void ConnectionDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    if (index.column() == RemoteDesktopsModel::Favorite) {
        QVariant value = index.data(Qt::CheckStateRole);
        if (value.isValid()) {
            Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
            QIcon favIcon = QIcon::fromTheme(QLatin1String("bookmarks"));
            QIcon::Mode mode = (checkState == Qt::Checked) ? QIcon::Active : QIcon::Disabled;
            favIcon.paint(painter, option.rect, option.decorationAlignment, mode);

        }
    } else {
        QStyledItemDelegate::paint(painter, option, index);
    }
}
Ejemplo n.º 10
0
void IconChooserDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QStyleOptionViewItemV4 opt = option;
    initStyleOption(&opt, index);

    const QWidget* w = opt.widget;
    const QStyle* style = w ? w->style() : QApplication::style();

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

    // Draw icon
    QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
    icon.paint(painter, opt.rect);
}
Ejemplo n.º 11
0
void 
SeedDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
    painter->save();
    
    const QIcon icon = index.data( Qt::DecorationRole ).value<QIcon>();
    
    int flashValue = index.data( moose::HighlightRole ).isValid() ? index.data( moose::HighlightRole ).toInt() : 0;

    QRect iconRect = option.rect;
    iconRect.setSize( icon.actualSize( iconRect.size()));
    iconRect.translate( -(iconRect.width() - option.rect.width())/2, 0);
    
    QRect overlayRect = iconRect.adjusted( 1, 1, -1, -3 );
    
    QRect textRect = option.rect.adjusted( 0, iconRect.height(), 0, 0 );
    
    painter->setRenderHint(QPainter::SmoothPixmapTransform);
    
    icon.paint( painter, iconRect);
    
    if( option.state & QStyle::State_Selected &&
        index.data( moose::TypeRole ) != Seed::TagType)
    {
        painter->drawPixmap( overlayRect, m_selectedOverlay );
    }
    
    if( flashValue > 0 )
        painter->fillRect( option.rect, QColor( 0x0, 0x78, 0xff, ( 0xff * ((qreal)flashValue / 100.0f) )));
    
    painter->setPen( Qt::white );
    QFont f = painter->font();
    f.setPointSize( 10 );
    painter->setFont( f );
    
    
    QFontMetrics fm( f);
    QString text = fm.elidedText( index.data().toString(), Qt::ElideRight, textRect.width());
    textRect = fm.boundingRect(textRect, Qt::AlignCenter, text );
    
    if( option.state & QStyle::State_Selected )
        painter->fillRect( textRect, QColor( 0x056e99 ) );
    
    painter->setRenderHint( QPainter::Antialiasing );
    painter->drawText( textRect, Qt::AlignCenter, text );
    
    painter->restore();
}
Ejemplo n.º 12
0
void MainConfigurationWindow::setIconThemes()
{
    ConfigListWidget *iconThemes = static_cast<ConfigListWidget *>(widget()->widgetById("iconThemes"));
    iconThemes->clear();

    m_iconThemeManager->loadThemes();

    (void)QT_TRANSLATE_NOOP("@default", "default");

    QStringList values;
    QStringList captions;
    for (auto const &theme : m_iconThemeManager->themes())
    {
        values.append(theme.name());
        captions.append(QCoreApplication::translate("@default", theme.name().toUtf8().constData()));
    }

    iconThemes->setItems(values, captions);
    iconThemes->setCurrentItem(m_iconThemeManager->currentTheme().name());

    QStringList iconPaths;
    iconPaths << "protocols/xmpp/online"
              << "protocols/gadu-gadu/online"
              << "protocols/common/message"
              << "preferences-other";

    QList<QIcon> icons;
    for (auto const &theme : m_iconThemeManager->themes())
    {
        QPixmap combinedIcon(iconPaths.count() * 36, 36);
        combinedIcon.fill(Qt::transparent);

        QPainter iconPainter(&combinedIcon);

        for (int i = 0; i < iconPaths.count(); i++)
        {
            KaduIcon kaduIcon(iconPaths.at(i));
            kaduIcon.setThemePath(theme.path());
            QIcon icon = m_iconsManager->iconByPath(kaduIcon);
            icon.paint(&iconPainter, 2 + 36 * i, 2, 32, 32);
        }

        icons.append(QIcon(combinedIcon));
    }

    iconThemes->setIconSize(QSize(iconPaths.count() * 36, 36));
    iconThemes->setIcons(icons);
}
Ejemplo n.º 13
0
void FolderDelegate::drawDecoration(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QVariant &decoration) const
{
    if (!rect.isValid())
        return;

    // If we have an icon, we ignore the pixmap
    if (decoration.type() == QVariant::Icon) {
        QIcon icon = qvariant_cast<QIcon>(decoration);

        QIcon::Mode mode(QIcon::Normal);
        if (!(option.state & QStyle::State_Enabled)) 
            mode = QIcon::Disabled;

        QIcon::State state(option.state & QStyle::State_Open ? QIcon::On : QIcon::Off);
        icon.paint(painter, rect, option.decorationAlignment, mode, state);
    }
}
Ejemplo n.º 14
0
	void paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex & index) const 
	{
		QStyleOptionViewItem opt = option;
		if (opt.state & QStyle::State_Selected) {
			painter->fillRect(opt.rect, opt.palette.highlight());
		}

		QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
		QSize ds = opt.decorationSize;
		QRect decorationRect(opt.rect.x() + 4, opt.rect.top() + 4, opt.rect.width() - 8, ds.height());

		icon.paint(painter, decorationRect, Qt::AlignHCenter | Qt::AlignTop, opt.state & QStyle::State_Enabled ? ((opt.state & QStyle::State_Selected) && opt.showDecorationSelected ? QIcon::Selected : QIcon::Normal) : QIcon::Disabled);

		QString displayText = index.data(Qt::DisplayRole).toString();
		painter->setPen(opt.palette.color(option.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text));
		QRect displayRect = opt.rect.adjusted(2, ds.height() + 2, -2, -2);
		painter->drawText(displayRect, Qt::AlignHCenter | Qt::AlignBottom | Qt::TextWordWrap, opt.fontMetrics.elidedText(displayText, opt.textElideMode, displayRect.width()));
	}
Ejemplo n.º 15
0
void QHorizontalTabBar::paintEvent(QPaintEvent *e)
{
	QList<QIcon> icons;
	QList<QSize> iconSizes;
	QList<QString> texts;
	for (int index = 0; index < count(); index++)
	{
		QStyleOptionTabV3 tab;
		initStyleOption(&tab, index);

		icons.append(tab.icon);
		iconSizes.append(tab.iconSize);
		texts.append(tab.text);

		// don't paint the icon and text
		setTabIcon(index, QIcon());
		setTabText(index, QString());
	}
	QTabBar::paintEvent(e);

	QFont font = QFont("Courier", 16);
	font.setFixedPitch(true);
	for (int index = 0; index < count(); index++)
	{
		QIcon icon = icons.at(index);
		QSize iconSize = iconSizes.at(index);
		QString text = texts.at(index);

		QRect tabrect = tabRect(index);
		tabrect.adjust(0, 40, 0, -40);

		// restore the icon and text
		setTabIcon(index, icon);
		setTabText(index, text);

		QPainter painter;
		painter.begin(this);
		painter.setFont(font);
		painter.setPen(Qt::white);
		painter.drawText(tabrect, Qt::AlignBottom | Qt::AlignHCenter, text);
		icon.paint(&painter, 16, tabrect.top(), iconSize.width(), iconSize.height(), Qt::AlignTop | Qt::AlignHCenter);    
		painter.end();
	}
}
Ejemplo n.º 16
0
void HtmlDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
    if (!index.isValid())
        return;

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

    painter->save();

    QTextDocument doc;
    doc.setHtml(options.text);
    QIcon icon = options.icon;

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

    // Draw icon ................................
    QSize iconSize = icon.actualSize(mIconSize);
    painter->translate(options.rect.left(), options.rect.top());
    QRect iconRect = QRect(4, 4, iconSize.width(), iconSize.height());

    icon.paint(painter, iconRect);

    doc.setTextWidth(options.rect.width() - iconRect.right() - 10);

    // shift text right to make icon visible
    painter->translate(iconRect.right() + 8, 0);
    QRect clip(0, 0, options.rect.width()-iconRect.right()- 10, options.rect.height());


    painter->setClipRect(clip);
    QAbstractTextDocumentLayout::PaintContext ctx;
    // set text color to red for selected item
    if (option.state & QStyle::State_Selected)
    {
        ctx.palette.setColor(QPalette::Text, option.palette.color(QPalette::HighlightedText));
    }
    ctx.clip = clip;
    doc.documentLayout()->draw(painter, ctx);

    painter->restore();
}
Ejemplo n.º 17
0
void FormViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                             const QModelIndex &index) const
{
    // Add the fancy button
    if (option.state & QStyle::State_MouseOver) {
        if ((QApplication::mouseButtons() & Qt::LeftButton) == 0)
            pressedIndex = QModelIndex();
        QBrush brush = option.palette.alternateBase();
        if (index == pressedIndex)
            brush = option.palette.dark();
        painter->fillRect(option.rect, brush);
    }

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

    // Draw fancy button
    if (index.column()==FormTreeModel::EmptyColumn1 &&
            (option.state & QStyle::State_MouseOver)) {
        QIcon icon;
        if (option.state & QStyle::State_Selected) {
            // test the form to be unique or multiple episode
            if (_formTreeModel->isUniqueEpisode(index))
                return;
            if (_formTreeModel->isNoEpisode(index))
                return;
            icon = theme()->icon(Core::Constants::ICONADDLIGHT);
        } else {
            // test the form to be unique or multiple episode
            if (_formTreeModel->isUniqueEpisode(index))
                return;
            if (_formTreeModel->isNoEpisode(index))
                return;
            icon = theme()->icon(Core::Constants::ICONADDDARK);
        }

        QRect iconRect(option.rect.right() - option.rect.height(),
                       option.rect.top(),
                       option.rect.height(),
                       option.rect.height());

        icon.paint(painter, iconRect, Qt::AlignRight | Qt::AlignVCenter);
    }
}
Ejemplo n.º 18
0
void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
						 const QModelIndex &index) const
{
	painter->save();
	if (option.state & QStyle::State_Selected)
	{
		painter->fillRect(option.rect, option.palette.highlight());
		painter->setPen(option.palette.color(QPalette::HighlightedText));
	}

	QRect iconRect = option.rect;
	iconRect.setWidth(32);
	iconRect.setHeight(32);

	int fontHeight = painter->fontMetrics().height();
	QRect shortRect = option.rect;
	shortRect.setLeft(shortRect.left() + 38);
	shortRect.setBottom(shortRect.top() + fontHeight);

	QRect longRect = option.rect;
	longRect.setLeft(longRect.left() + 50);
	longRect.setTop(longRect.top() + fontHeight);

    QString text = Catalog::decorateText(index.data(ROLE_SHORT).toString(), g_searchText);
	painter->drawText(shortRect, Qt::AlignTop | Qt::TextShowMnemonic, text);

	if (option.state & QStyle::State_Selected)
		painter->setPen(alternativesPath->palette().color(QPalette::HighlightedText));
	else
		painter->setPen(alternativesPath->palette().color(QPalette::WindowText));

	painter->setFont(alternativesPath->font());

	QString full = index.data(ROLE_FULL).toString();
	full = painter->fontMetrics().elidedText(full, option.textElideMode, longRect.width());
	painter->drawText(longRect, Qt::AlignTop, full);

	QIcon p = index.data(ROLE_ICON).value<QIcon>();
	p.paint(painter, iconRect);
	painter->restore();
}
Ejemplo n.º 19
0
const QIcon Flags::getIconWithText(const LayoutUnit& layoutUnit, const KeyboardConfig& keyboardConfig)
{
    QString keySuffix(getPixmapKey(keyboardConfig));
    QString key(layoutUnit.toString() + keySuffix);
    if( iconOrTextMap.contains(key) ) {
        return iconOrTextMap[ key ];
    }

    if( keyboardConfig.indicatorType == KeyboardConfig::SHOW_FLAG ) {
        QIcon icon = getIcon(layoutUnit.layout);
        if( ! icon.isNull() ) {
            iconOrTextMap[ key ] = icon;
            return icon;
        }
    }

    QString layoutText = Flags::getShortText(layoutUnit, keyboardConfig);

    const QSize TRAY_ICON_SIZE(21, 14);
    QPixmap pixmap = QPixmap(TRAY_ICON_SIZE);
    pixmap.fill(Qt::transparent);

    QPainter painter(&pixmap);
//	p.setRenderHint(QPainter::SmoothPixmapTransform);
//	p.setRenderHint(QPainter::Antialiasing);

    if( keyboardConfig.indicatorType == KeyboardConfig::SHOW_LABEL_ON_FLAG ) {
        QIcon iconf = createIcon(layoutUnit.layout);
        iconf.paint(&painter, painter.window(), Qt::AlignCenter);
    }

    drawLabel(painter, layoutText, keyboardConfig.isFlagShown());

    painter.end();

    QIcon icon(pixmap);
    iconOrTextMap[ key ] = icon;

    return icon;
}
Ejemplo n.º 20
0
void MyTabBar::paintEvent(QPaintEvent *)
{
    QStylePainter p(this);
    for (int index = 0; index < count(); index++)
    {
        QStyleOptionTabV3 tab;
        initStyleOption(&tab, index);
        QIcon tempIcon = tab.icon;
        QString tempText = tab.text;
        tab.icon = QIcon();
        tab.text = QString();
        p.drawControl(QStyle::CE_TabBarTab, tab);
        QPainter painter;
        painter.begin(this);
        QRect tabrect = tabRect(index);
        tabrect.adjust(0, 8, 0, -8);
        painter.drawText(tabrect, Qt::AlignBottom | Qt::AlignHCenter, tempText);
        tempIcon.paint(&painter, 0, tabrect.top(), tab.iconSize.width(), tab.iconSize.height(),
                       Qt::AlignTop | Qt::AlignHCenter);
        painter.end();
    }
}
Ejemplo n.º 21
0
void ItemViewImageDelegate::drawPickLabelIcon(QPainter* p, const QRect& r, int pickId) const
{
    // Draw Pick Label icon
    if (pickId != NoPickLabel)
    {
        QIcon icon;

        if (pickId == RejectedLabel)
        {
            icon = QIcon::fromTheme(QLatin1String("flag-red"));
        }
        else if (pickId == PendingLabel)
        {
            icon = QIcon::fromTheme(QLatin1String("flag-yellow"));
        }
        else if (pickId == AcceptedLabel)
        {
            icon = QIcon::fromTheme(QLatin1String("flag-green"));
        }

        icon.paint(p, r);
    }
}
Ejemplo n.º 22
0
void IndividualIcon::paint( QPainter * painter,
             const QStyleOptionGraphicsItem * option, QWidget * ){

    //QGraphicsPixmapItem::paint(painter, option, widget);

    QRectF b = boundingRect();
    QIcon ic = m_item.getActualIcon();
    QRect iconRect;
    iconRect.setTopLeft(b.topLeft().toPoint());
    iconRect.setWidth(UI_DEFAULT_MINI_ICON_SIZE);
    iconRect.setHeight(UI_DEFAULT_MINI_ICON_SIZE);

    ic.paint(painter, iconRect);
    painter->save();
    if(this->isSelected()){
        QBrush brush1(option->palette.highlight());
        brush1.setStyle(Qt::SolidPattern);
        painter->setBrush(brush1);
        painter->drawRect(b);
    }
    QFont fnt = m_item.getDisplayFont();
//    QFontMetrics fm(fnt);
//    int fnt_h = fm.height();
    QRect r(0,0,0,0);
    r.setTop(b.height());
    r.setBottom(b.bottom());
    r.setWidth(b.width());


    painter->setClipRect(r);

    //qDebug() << "test onto rect: " << r;
    drawHtmlLine(painter, fnt, r, m_item.formattedName());

    painter->restore();

}
Ejemplo n.º 23
0
void RefactorOverlay::paintMarker(const RefactorMarker& marker, QPainter *painter, const QRect &clip)
{
    QPointF offset = m_editor->contentOffset();
    QRectF geometry = m_editor->blockBoundingGeometry(marker.cursor.block()).translated(offset);

    if (geometry.top() > clip.bottom() + 10 || geometry.bottom() < clip.top() - 10)
        return; // marker not visible

    QTextCursor cursor = marker.cursor;

    QRect r = m_editor->cursorRect(cursor);

    QIcon icon = marker.icon;
    if (icon.isNull())
        icon = m_icon;

    QSize sz = icon.actualSize(QSize(m_editor->fontMetrics().width(QLatin1Char(' '))+2, r.height()));

    int x = r.right();
    marker.rect = QRect(x, r.top(), sz.width(), sz.height());

    icon.paint(painter, marker.rect);
    m_maxWidth = qMax((qreal)m_maxWidth, x + sz.width() - offset.x());
}
Ejemplo n.º 24
0
void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QRect r = option.rect;

    //Color: #C4C4C4
    QPen linePen(QColor::fromRgb(211,211,211), 1, Qt::SolidLine);

    //Color: #005A83
    QPen lineMarkedPen(QColor::fromRgb(0,90,131), 1, Qt::SolidLine);

    //Color: #333
    QPen fontPen(QColor::fromRgb(51,51,51), 1, Qt::SolidLine);

    //Color: #fff
    QPen fontMarkedPen(Qt::white, 1, Qt::SolidLine);

    if(option.state & QStyle::State_Selected)
    {
        QLinearGradient gradientSelected(r.left(),r.top(),r.left(),r.height()+r.top());
        gradientSelected.setColorAt(0.0, QColor::fromRgb(119,213,247));
        gradientSelected.setColorAt(0.9, QColor::fromRgb(27,134,183));
        gradientSelected.setColorAt(1.0, QColor::fromRgb(0,120,174));
        painter->setBrush(gradientSelected);
        painter->drawRect(r);

        //BORDER
        painter->setPen(lineMarkedPen);
        painter->drawLine(r.topLeft(),r.topRight());
        painter->drawLine(r.topRight(),r.bottomRight());
        painter->drawLine(r.bottomLeft(),r.bottomRight());
        painter->drawLine(r.topLeft(),r.bottomLeft());

        painter->setPen(fontMarkedPen);

    }
    else
    {
        //BACKGROUND
        //ALTERNATING COLORS
        painter->setBrush( (index.row() % 2) ? Qt::white : QColor(252,252,252) );
        painter->drawRect(r);

        //BORDER
        painter->setPen(linePen);
        painter->drawLine(r.topLeft(),r.topRight());
        painter->drawLine(r.topRight(),r.bottomRight());
        painter->drawLine(r.bottomLeft(),r.bottomRight());
        painter->drawLine(r.topLeft(),r.bottomLeft());

        painter->setPen(fontPen);
    }

    //GET TITLE, DESCRIPTION AND ICON
    QIcon icon = QIcon(qvariant_cast<QPixmap>(index.data(Qt::DecorationRole)));
    QString title = index.data(Qt::DisplayRole).toString();
    //QString description = index.data(Qt::UserRole + 1).toString();

    int imageSpace = 10;
    if (!icon.isNull())
    {
        //ICON
        QRect iconRect = option.rect.adjusted(4, 4, -4, -4);
        icon.paint(painter, iconRect, Qt::AlignVCenter|Qt::AlignCenter);
        imageSpace = 55;
    }

    //TITLE
    r = option.rect.adjusted(4, 0, 0, 0);
    painter->setFont( QFont( "Lucida Grande", 9, QFont::Normal ) );
    painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignBottom|Qt::AlignLeft, title, &r);

    /*QStyleOptionButton check_box_style_option;
    check_box_style_option.state |= QStyle::State_Enabled;
    check_box_style_option.rect = QRect(r.left(), r.top(), 32, 32);
    QApplication::style()->drawControl(QStyle::CE_PushButton, &check_box_style_option, painter);*/

    /*//DESCRIPTION
    r = option.rect.adjusted(imageSpace, 30, -10, 0);
    painter->setFont( QFont( "Lucida Grande", 9, QFont::Normal ) );
    painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignLeft, description, &r);*/
}
void QgsComposerLegend::drawLayerChildItems( QPainter* p, QStandardItem* layerItem, double& currentYCoord, double& maxXCoord, int layerOpacity )
{
  if ( !layerItem )
  {
    return;
  }

  //Draw all symbols first and the texts after (to find out the x coordinate to have the text aligned)
  QList<double> childYCoords;
  QList<double> realItemHeights;

  double textHeight = fontHeightCharacterMM( mItemFont, QChar( '0' ) );
  double itemHeight = qMax( mSymbolHeight, textHeight );

  double textAlignCoord = 0; //alignment for legend text

  QStandardItem* currentItem;

  int numChildren = layerItem->rowCount();

  for ( int i = 0; i < numChildren; ++i )
  {
    //real symbol height. Can be different from standard height in case of point symbols
    double realSymbolHeight;
    double realItemHeight = itemHeight; //will be adjusted if realSymbolHeight turns out to be larger

    currentYCoord += mSymbolSpace;
    double currentXCoord = mBoxSpace;

    currentItem = layerItem->child( i, 0 );

    if ( !currentItem )
    {
      continue;
    }

    QgsSymbol* symbol = 0;
    QgsComposerSymbolItem* symbolItem = dynamic_cast<QgsComposerSymbolItem*>( currentItem );
    if ( symbolItem )
    {
      symbol = symbolItem->symbol();
    }

    QgsSymbolV2* symbolNg = 0;
    QgsComposerSymbolV2Item* symbolV2Item = dynamic_cast<QgsComposerSymbolV2Item*>( currentItem );
    if ( symbolV2Item )
    {
      symbolNg = symbolV2Item->symbolV2();
    }
    QgsComposerRasterSymbolItem* rasterItem = dynamic_cast<QgsComposerRasterSymbolItem*>( currentItem );

    if ( symbol )  //item with symbol?
    {
      //draw symbol
      drawSymbol( p, symbol, currentYCoord + ( itemHeight - mSymbolHeight ) / 2, currentXCoord, realSymbolHeight, layerOpacity );
      realItemHeight = qMax( realSymbolHeight, itemHeight );
      currentXCoord += mIconLabelSpace;
    }
    else if ( symbolNg ) //item with symbol NG?
    {
      drawSymbolV2( p, symbolNg, currentYCoord + ( itemHeight - mSymbolHeight ) / 2, currentXCoord, realSymbolHeight, layerOpacity );
      realItemHeight = qMax( realSymbolHeight, itemHeight );
      currentXCoord += mIconLabelSpace;
    }
    else if ( rasterItem )
    {
      if ( p )
      {
        p->setBrush( rasterItem->color() );
        p->drawRect( QRectF( currentXCoord, currentYCoord + ( itemHeight - mSymbolHeight ) / 2, mSymbolWidth, mSymbolHeight ) );
      }
      currentXCoord += mSymbolWidth;
      currentXCoord += mIconLabelSpace;
    }
    else //item with icon?
    {
      QIcon symbolIcon = currentItem->icon();
      if ( !symbolIcon.isNull() && p )
      {
        symbolIcon.paint( p, currentXCoord, currentYCoord + ( itemHeight - mSymbolHeight ) / 2, mSymbolWidth, mSymbolHeight );
        currentXCoord += mSymbolWidth;
        currentXCoord += mIconLabelSpace;
      }
    }

    childYCoords.push_back( currentYCoord );
    realItemHeights.push_back( realItemHeight );
    currentYCoord += realItemHeight;
    textAlignCoord = qMax( currentXCoord, textAlignCoord );
  }

  maxXCoord = qMax( maxXCoord, textAlignCoord );
  for ( int i = 0; i < numChildren; ++i )
  {
    if ( p )
    {
      p->setPen( QColor( 0, 0, 0 ) );
      drawText( p, textAlignCoord, childYCoords.at( i ) + textHeight + ( realItemHeights.at( i ) - textHeight ) / 2, layerItem->child( i, 0 )->text(), mItemFont );
      maxXCoord = qMax( maxXCoord, textAlignCoord + mBoxSpace + textWidthMillimeters( mItemFont,  layerItem->child( i, 0 )->text() ) );
    }
  }
}
void CWizUserInfoWidgetBase::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    int nAvatarWidth = 32;
    int nArrawWidth = 10;
    int nMargin = 4;

    QStyleOptionToolButton opt;
    initStyleOption(&opt);

    QPainter p(this);
    p.setClipRect(opt.rect);

    // draw user avatar
    QRect rectIcon = opt.rect;
    rectIcon.setLeft(rectIcon.left());
    rectIcon.setRight(rectIcon.left() + nAvatarWidth);

    QPixmap pixmap = getAvatar(nAvatarWidth, nAvatarWidth);
    if (!pixmap.isNull())
    {
        p.drawPixmap(rectIcon, pixmap);
    }
    //if (!opt.icon.isNull()) {
    //    opt.icon.paint(&p, rectIcon);
    //}

    // draw vip indicator
    QRect rectVip = rectIcon;
    rectVip.setLeft(rectVip.right() + nMargin);
    rectVip.setRight(rectVip.left() + fontMetrics().width(opt.text));
    //rectVip.setBottom(rectVip.top() + rectVip.height()/2);
    //if (!m_iconVipIndicator.isNull()) {
    //    m_iconVipIndicator.paint(&p, rectVip, Qt::AlignLeft|Qt::AlignTop);
    //}

    // draw display name
    QRect rectText = rectVip;
    //rectText.setBottom(rectText.bottom() + rectVip.height());
    //rectText.setTop(rectText.bottom() - rectVip.height());
    if (!opt.text.isEmpty()) {
        if (opt.state & QStyle::State_MouseOver) {
            QFont font = p.font();
            font.setUnderline(true);
            p.setFont(font);
        }

        p.setPen("#787878"); // FIXME
        p.drawText(rectText, Qt::AlignLeft|Qt::AlignVCenter, opt.text);
    }

    // draw arraw
    QRect rectArrow = rectText;
    rectArrow.setLeft(rectArrow.right() + nMargin);
    rectArrow.setRight(rectArrow.left() + nArrawWidth);
    QIcon arrow = getArrow();
    if (!arrow.isNull()) {
        arrow.paint(&p, rectArrow, Qt::AlignVCenter, QIcon::Normal);
    }
}
Ejemplo n.º 27
0
void GroupDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
    QRect r = option.rect;
    QFont font = painter->font();
    QPen pen = painter->pen();

    if (!index.parent().isValid())
    {
        painter->setBrush(Qt::red);
        font.setPixelSize(14);
        font.setUnderline(false);
        painter->setFont(font);
        pen.setColor(grayFont);

        //painter->setBackground(Qt::gray);
        painter->fillRect(option.rect, grayBackground);
        if (index.column()==0)
        {
            //if (option.state & QStyle::State_Editing)
            QPixmap icon = tree->isExpanded(index)
                    ? QPixmap(":/Images/Visitors/icon_minus.png")
                    : QPixmap(":/Images/Visitors/icon_plus.png");
                painter->drawPixmap(r.x() + 8, r.y() + 6, 16, 16, icon);

        }        
        painter->setPen(pen);
        painter->setFont(font);
        painter->drawText(QPoint(r.x() + 32, r.y() + 18), index.data().toString());
    }
    else
    {
        if (option.state & QStyle::State_MouseOver)
        {
            painter->fillRect(option.rect, grayBackground);
        }
        QVariant value = index.data(Qt::DecorationRole);
        int adjust = index.column()==0 ? 24 : 0;
        if (value.isValid() && value.type() == QVariant::Icon)
        {
            QIcon icon = value.value<QIcon>();
            if (icon.availableSizes().count()>0)
            {
                int width = icon.availableSizes().at(0).width();
                icon.paint(painter, r.x()+8 + adjust, r.y(), width, 28);
                adjust += width + 8;
            }
        }

        font.setPixelSize(12);
        if (index.column() == 0 || index.column() == 10)
        {
            font.setUnderline(true);
            pen.setColor(hyperlink);
        }
        else
        {
            font.setUnderline(false);
            pen.setColor(grayFont);
        }
        painter->setPen(pen);
        painter->setFont(font);
        QTextOption textOptions(Qt::AlignLeft);
        textOptions.setWrapMode(QTextOption::NoWrap);
        painter->drawText(r.adjusted(8 + adjust,6,0,0), index.data().toString(), textOptions);
        //painter->drawText(QPoint(r.x() + 32, r.y() + r.height()/2 + font.pixelSize()/2 - 1), index.data().toString(), o);
    }
}
Ejemplo n.º 28
0
/*!
  \reimp
*/
void QAppointmentDelegate::paint(QPainter *painter, const QStyleOptionViewItem & option,
                                 const QModelIndex & index) const
{
    //  Prepare brush + pen and draw in background rectangle

    QRect border;
    QPen pen(option.palette.color(QPalette::Mid));
    if (option.state & QStyle::State_Selected) {
        painter->setBrush(option.palette.highlight());
        border = option.rect.adjusted(1, 1, -1, -1);
        pen.setWidth(2);
    } else {
        painter->setBrush(option.palette.button());
        border = option.rect.adjusted(0, 0, -1, -1);
    }

    painter->setPen(pen);
    painter->drawRect(border);

    QRect contentRect = option.rect.adjusted(2, 2, -2, -2);
    QRect textRect = contentRect;

    painter->save();
    painter->setClipRect(contentRect);

    // We try to align the text and the icons so that they are vertically
    // centered if that does not result in too much whitespace (being
    // defined as more than one font linespacing high)

    // In addition, we try to wrap the text to the leading boundary of the icons
    bool rtl = option.direction == Qt::RightToLeft;

    QString appText = index.model()->data(index, Qt::DisplayRole).toString();
    int fontHeight = QFontMetrics(option.font).lineSpacing();

    //  Draw in the relevant event icons (vertically centered), with a 2px margin
    // If the text is not vertically centered, we don't center the icons either.
    QList<QVariant> icons = index.model()->data( index, Qt::DecorationRole ).toList();
    if (icons.count() > 0) {
        // We use the height of the text as the desired icon size (-2 for the padding)
        int drawnIconSize = fontHeight - 2;
        if (drawnIconSize <= 0)
            drawnIconSize = 1;

        // number of rows of icons drawn
        int numRows = (contentRect.height() + 2) / (drawnIconSize + 2);
        if (numRows > icons.count())
            numRows = icons.count();

        // vertical offset, if any (if more than one line spare, we top align)
        int iconVOffset = (contentRect.height() + 2 - (numRows * (drawnIconSize + 2)) + 1) / 2;
        if (iconVOffset < 0 || iconVOffset >= contentRect.height() || iconVOffset > (drawnIconSize / 2))
            iconVOffset = 0;

        // Icon drawing position
        int iconY = iconVOffset;
        int iconX = rtl ? contentRect.left() : contentRect.right() - drawnIconSize;
        int iconDX = rtl ? (drawnIconSize + 2) : -(drawnIconSize + 2);

        // Now draw the icons, starting from top right, moving downwards and then leftwards
        for (QList<QVariant>::Iterator it = icons.begin(); it != icons.end(); ) {
            QIcon icon = qvariant_cast<QIcon>(*it);
            icon.paint(painter, iconX, contentRect.top() + iconY, drawnIconSize, drawnIconSize);

            // Calculate where the next icon should go
            ++it;
            if (it !=icons.end()) {
                if(contentRect.height() >= iconY + drawnIconSize + 2 + drawnIconSize)
                    iconY += drawnIconSize + 2;
                else {
                    iconY = iconVOffset;
                    iconX += iconDX;
                }
            }
        }

        if (rtl)
            textRect.setLeft(iconX + drawnIconSize + 2);
        else
            textRect.setRight(iconX - 2);
    }

    //  Prepare pen and draw in text
    if (option.state & QStyle::State_Selected)
        painter->setPen(option.palette.color(QPalette::HighlightedText));
    else
        painter->setPen(option.palette.color(QPalette::ButtonText));

    // Now see if we can fit our text in.
    int vertPos = 0;
    QRect textMetrics = painter->boundingRect(textRect, Qt::AlignLeft | Qt::TextWrapAnywhere, appText);

    if (textMetrics.height() < contentRect.height() && textMetrics.height() > (contentRect.height() - fontHeight))
        vertPos = (contentRect.height() - textMetrics.height() + 1) / 2;
    textRect.adjust(0, vertPos, 0, 0);
    painter->drawText(textRect, Qt::AlignLeft | Qt::TextWrapAnywhere, appText);
    painter->restore();
}
void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QStyleOptionViewItemV4 opt = option;
    initStyleOption(&opt, index);

    const QWidget* w = opt.widget;
    const QStyle* style = w ? w->style() : QApplication::style();

    const int height = opt.rect.height();
    const int center = height / 2 + opt.rect.top();

    // Prepare title font
    QFont titleFont = opt.font;
    titleFont.setPointSize(titleFont.pointSize() + 1);

    const QFontMetrics titleMetrics(titleFont);

    int leftPosition = m_padding * 2;
    int rightPosition = opt.rect.right() - m_padding;

    opt.state &= ~QStyle::State_MouseOver;

    if (m_view->hoveredIndex() == index) {
        opt.state |= QStyle::State_Selected;
    }
    else {
        opt.state &= ~QStyle::State_Selected;
    }

#ifdef Q_OS_WIN
    const QPalette::ColorRole colorRole = QPalette::Text;
    const QPalette::ColorRole colorLinkRole = QPalette::Link;
#else
    const QPalette::ColorRole colorRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text;
    const QPalette::ColorRole colorLinkRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Link;
#endif

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

    // Draw icon
    const int iconSize = 16;
    const int iconYPos = center - (iconSize / 2);
    QRect iconRect(leftPosition, iconYPos, iconSize, iconSize);
    QPixmap pixmap = index.data(Qt::DecorationRole).value<QIcon>().pixmap(iconSize);
    painter->drawPixmap(iconRect, pixmap);
    leftPosition = iconRect.right() + m_padding * 2;

    // Draw star to bookmark items
    int starPixmapWidth = 0;
    if (index.data(LocationCompleterModel::BookmarkRole).toBool()) {
        const QIcon icon = IconProvider::instance()->bookmarkIcon();
        const QSize starSize(16, 16);
        starPixmapWidth = starSize.width();
        QPoint pos(rightPosition - starPixmapWidth, center - starSize.height() / 2);
        QRect starRect(pos, starSize);
        painter->drawPixmap(starRect, icon.pixmap(starSize));
    }

    const QString searchText = index.data(LocationCompleterModel::SearchStringRole).toString();

    // Draw title
    const int leftTitleEdge = leftPosition + 2;
    // RTL Support: remove conflicting of right-aligned text and starpixmap!
    const int rightTitleEdge = rightPosition - m_padding - starPixmapWidth;
    QRect titleRect(leftTitleEdge, opt.rect.top() + m_padding, rightTitleEdge - leftTitleEdge, titleMetrics.height());
    QString title = index.data(LocationCompleterModel::TitleRole).toString();
    painter->setFont(titleFont);

    viewItemDrawText(painter, &opt, titleRect, title, colorRole, searchText);

    // Draw link
    const int infoYPos = titleRect.bottom() + opt.fontMetrics.leading() + 2;
    QRect linkRect(titleRect.x(), infoYPos, titleRect.width(), opt.fontMetrics.height());
    const QByteArray linkArray = index.data(Qt::DisplayRole).toByteArray();

    // Let's assume that more than 500 characters won't fit in line on any display...
    // Fixes performance when trying to get elidedText for a really long
    // (length() > 1000000) urls - data: urls can get that long

    QString link;
    if (!linkArray.startsWith("data") && !linkArray.startsWith("javascript")) {
        link = QString::fromUtf8(QByteArray::fromPercentEncoding(linkArray)).left(500);
    }
    else {
        link = QString::fromLatin1(linkArray.left(500));
    }

    painter->setFont(opt.font);

    // Draw url (or switch to tab)
    int tabPos = index.data(LocationCompleterModel::TabPositionTabRole).toInt();

    if (drawSwitchToTab() && tabPos != -1) {
        const QIcon tabIcon = QIcon(QSL(":icons/menu/tab.png"));
        QRect iconRect(linkRect);
        iconRect.setWidth(m_padding + 16 + m_padding);
        tabIcon.paint(painter, iconRect);

        QRect textRect(linkRect);
        textRect.setX(textRect.x() + m_padding + 16 + m_padding);
        viewItemDrawText(painter, &opt, textRect, LocationCompleterView::tr("Switch to tab"), colorLinkRole);
    }
    else {
        viewItemDrawText(painter, &opt, linkRect, link, colorLinkRole, searchText);
    }

    // Draw line at the very bottom of item if the item is not highlighted
    if (!(opt.state & QStyle::State_Selected)) {
        QRect lineRect(opt.rect.left(), opt.rect.bottom(), opt.rect.width(), 1);
        painter->fillRect(lineRect, opt.palette.color(QPalette::AlternateBase));
    }
}
Ejemplo n.º 30
0
void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QStyleOptionViewItemV4 opt = option;
    initStyleOption(&opt, index);

    const QWidget* w = opt.widget;
    const QStyle* style = w ? w->style() : QApplication::style();

    const int height = opt.rect.height();
    const int center = height / 2 + opt.rect.top();

    // Prepare title font
    QFont titleFont = opt.font;
    titleFont.setPointSize(titleFont.pointSize() + 1);

    const QFontMetrics titleMetrics(titleFont);

    int leftPosition = m_padding * 2;
    int rightPosition = opt.rect.right() - m_padding;

    opt.state &= ~QStyle::State_MouseOver;

    if (m_view->hoveredIndex() == index) {
        opt.state |= QStyle::State_Selected;
    }
    else {
        opt.state &= ~QStyle::State_Selected;
    }

#ifdef Q_OS_WIN
    const QPalette::ColorRole colorRole = QPalette::Text;
    const QPalette::ColorRole colorLinkRole = QPalette::Link;
#else
    const QPalette::ColorRole colorRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text;
    const QPalette::ColorRole colorLinkRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Link;
#endif

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

    // Draw icon
    const int iconSize = 16;
    const int iconYPos = center - (iconSize / 2);
    QRect iconRect(leftPosition, iconYPos, iconSize, iconSize);
    QPixmap pixmap = index.data(Qt::DecorationRole).value<QIcon>().pixmap(iconSize);
    painter->drawPixmap(iconRect, pixmap);
    leftPosition = iconRect.right() + m_padding * 2;

    // Draw star to bookmark items
    int starPixmapWidth = 0;
    if (index.data(LocationCompleterModel::BookmarkRole).toBool()) {
        const QPixmap starPixmap = qIconProvider->bookmarkIcon();
        QSize starSize = starPixmap.size();
        //new
        starPixmapWidth = starSize.width();
        QPoint pos(rightPosition - starPixmapWidth, opt.rect.top() + m_padding);
        QRect starRect(pos, starSize);
        painter->drawPixmap(starRect, starPixmap);
    }

    const QString &searchText = index.data(LocationCompleterModel::SearchStringRole).toString();

    // Draw title
    const int leftTitleEdge = leftPosition + 2;
    // RTL Support: remove conflicting of right-aligned text and starpixmap!
    const int rightTitleEdge = rightPosition - m_padding - starPixmapWidth;
    QRect titleRect(leftTitleEdge, opt.rect.top() + m_padding, rightTitleEdge - leftTitleEdge, titleMetrics.height());
    QString title(titleMetrics.elidedText(index.data(LocationCompleterModel::TitleRole).toString(), Qt::ElideRight, titleRect.width()));
    painter->setFont(titleFont);

    drawHighlightedTextLine(titleRect, title, searchText, painter, style, opt, colorRole);

    // Draw link
    const int infoYPos = titleRect.bottom() + opt.fontMetrics.leading() + 2;
    QRect linkRect(titleRect.x(), infoYPos, titleRect.width(), opt.fontMetrics.height());
    QString link(opt.fontMetrics.elidedText(index.data(Qt::DisplayRole).toString(), Qt::ElideRight, linkRect.width()));
    painter->setFont(opt.font);
    TabPosition pos = index.data(LocationCompleterModel::TabPositionRole).value<TabPosition>();
    if (m_drawSwitchToTab && pos.windowIndex != -1) {
        const QIcon tabIcon = QIcon(":icons/menu/tab.png");
        QRect iconRect(linkRect);
        iconRect.setWidth(m_padding + 16 + m_padding);
        tabIcon.paint(painter, iconRect);

        QRect textRect(linkRect);
        textRect.setX(textRect.x() + m_padding + 16 + m_padding);
        drawTextLine(textRect, LocationCompleterView::tr("Switch to tab"), painter, style, opt, colorLinkRole);
    }
    else {
        drawHighlightedTextLine(linkRect, link, searchText, painter, style, opt, colorLinkRole);
    }

    // Draw line at the very bottom of item if the item is not highlighted
    if (!(opt.state & QStyle::State_Selected)) {
        QRect lineRect(opt.rect.left(), opt.rect.bottom(), opt.rect.width(), 1);
        painter->fillRect(lineRect, opt.palette.color(QPalette::AlternateBase));
    }
}