Example #1
0
void
PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
    PlayableItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
    Q_ASSERT( item );

    QTextOption textOption( Qt::AlignVCenter | (Qt::Alignment)index.data( Qt::TextAlignmentRole ).toUInt() );
    textOption.setWrapMode( QTextOption::NoWrap );

    QStyleOptionViewItemV4 opt = option;
    prepareStyleOption( &opt, index, item );
    opt.text.clear();
    qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );

    if ( m_view->hoveredIndex().row() == index.row() && m_view->hoveredIndex().column() == index.column() &&
       ( index.column() == PlayableModel::Artist || index.column() == PlayableModel::Album || index.column() == PlayableModel::Track ) )
    {
        opt.rect.setWidth( opt.rect.width() - 16 );
        QRect arrowRect( opt.rect.x() + opt.rect.width(), opt.rect.y() + 1, opt.rect.height() - 2, opt.rect.height() - 2 );

        QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, arrowRect.size() );
        painter->drawPixmap( arrowRect, infoIcon );
    }

    painter->save();

    if ( index.column() == PlayableModel::Score )
    {
        QColor barColor( 167, 183, 211 ); // This matches the sidebar (sourcetreeview.cpp:672)
        if ( opt.state & QStyle::State_Selected )
            painter->setPen( opt.palette.brightText().color() );
        else
            painter->setPen( barColor );

        QRect r = opt.rect.adjusted( 3, 3, -6, -4 );
        painter->drawRect( r );

        QRect fillR = r;
        int fillerWidth = (int)( index.data().toFloat() * (float)fillR.width() );
        fillR.adjust( 0, 0, -( fillR.width() - fillerWidth ), 0 );

        if ( opt.state & QStyle::State_Selected )
            painter->setBrush( opt.palette.brightText().color() );
        else
            painter->setBrush( barColor );

        painter->drawRect( fillR );
    }
    else if ( item->isPlaying() )
    {
        QRect r = opt.rect.adjusted( 3, 0, 0, 0 );

        // Paint Now Playing Speaker Icon
        if ( m_view->header()->visualIndex( index.column() ) == 0 )
        {
            r.adjust( 0, 0, 0, -3 );
            painter->drawPixmap( r.adjusted( 3, 1, 18 - r.width(), 1 ), TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker ) );
            r.adjust( 25, 0, 0, 3 );
        }

        painter->setPen( opt.palette.text().color() );
        QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 );
        painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, textOption );
    }
    else
    {
        painter->setPen( opt.palette.text().color() );
        QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, opt.rect.width() - 6 );
        painter->drawText( opt.rect.adjusted( 3, 1, -3, 0 ), text, textOption );
    }

    painter->restore();
}
void CWizCategoryViewItemBase::draw(QPainter* p, const QStyleOptionViewItemV4 *vopt) const
{
#if 0
    if (!vopt->icon.isNull()) {
        QRect iconRect = subElementRect(SE_ItemViewItemDecoration, vopt, view);

        if (vopt->state.testFlag(State_Selected)) {
            vopt->icon.paint(p, iconRect, Qt::AlignCenter, QIcon::Selected);
        } else {
            vopt->icon.paint(p, iconRect, Qt::AlignCenter, QIcon::Normal);
        }
    }

    // text should not empty
    if (vopt->text.isEmpty()) {
        Q_ASSERT(0);
        return;
    }

    // draw text little far from icon than the default
    QRect textRect = subElementRect(SE_ItemViewItemText, vopt, view);
    //textRect.adjust(8, 0, 0, 0);

    // draw the text
    QPalette::ColorGroup cg = vopt->state & QStyle::State_Enabled
            ? QPalette::Normal : QPalette::Disabled;
    if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
        cg = QPalette::Inactive;

    if (vopt->state & QStyle::State_Selected) {
        p->setPen(vopt->palette.color(cg, QPalette::HighlightedText));
    } else {
        p->setPen(vopt->palette.color(cg, QPalette::Text));
    }

    if (vopt->state & QStyle::State_Editing) {
        p->setPen(vopt->palette.color(cg, QPalette::Text));
        p->drawRect(textRect.adjusted(0, 0, -1, -1));
    }

    // compute document count string length and leave enough space for drawing
    QString strCount = pItem->countString;
    int nCountWidthMax;
    int nMargin = 3;
    QFont fontCount = p->font();
    fontCount.setPointSize(10);

    if (!strCount.isEmpty()) {
        QFont fontOld = p->font();
        p->setFont(fontCount);
        nCountWidthMax = p->fontMetrics().width(strCount) + nMargin;
        textRect.adjust(0, 0, -nCountWidthMax, 0);
        p->setFont(fontOld);
    }

    QFont f = p->font();
    f.setPixelSize(12);
    p->setFont(f);

    QColor colorText = vopt->state.testFlag(State_Selected) ?
                m_colorCategoryTextSelected : m_colorCategoryTextNormal;

    CString strText = vopt->text;
    int nWidth = ::WizDrawTextSingleLine(p, textRect, strText,
                                         Qt::TextSingleLine | Qt::AlignVCenter,
                                         colorText, true);

    // only draw document count if count string is not empty
    if (!strCount.isEmpty()) {
        p->setFont(fontCount);
        textRect.adjust(nWidth + nMargin, 0, nCountWidthMax, 0);
        QColor colorCount = vopt->state.testFlag(State_Selected) ? QColor(230, 230, 230) : QColor(150, 150, 150);
        CString strCount2(strCount);
        ::WizDrawTextSingleLine(p, textRect, strCount2,  Qt::TextSingleLine | Qt::AlignVCenter, colorCount, false);
    }

    p->restore();

#endif
}
...

QPrinter printer(QPrinter::HighResolution);
printer.setPageSize(QPrinter::A4);
QPainter painter(&printer);

// print, fitting the viewport contents into a full page
view.render(&painter);

// print the upper half of the viewport into the lower.
// half of the page.
QRect viewport = view.viewport()->rect();
view.render(&painter,
            QRectF(0, printer.height() / 2,
                   printer.width(), printer.height() / 2),
            viewport.adjusted(0, 0, 0, -viewport.height() / 2));

//! [4]


//! [5]
void CustomView::mousePressEvent(QMouseEvent *event)
{
    qDebug() << "There are" << items(event->pos()).size()
             << "items at position" << mapToScene(event->pos());
}
//! [5]


//! [6]
void CustomView::mousePressEvent(QMouseEvent *event)
void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *option,
                                 QPainter *painter, const QWidget *widget) const
{
    if (!panelWidget(widget))
        return QProxyStyle::drawControl(element, option, painter, widget);

    switch (element) {
    case CE_Splitter:
        painter->fillRect(option->rect, Utils::StyleHelper::borderColor());
        break;

    case CE_TabBarTabShape:
        // Most styles draw a single dark outline. This looks rather ugly when combined with our
        // single pixel dark separator so we adjust the first tab to compensate for this

        if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) {
            QStyleOptionTabV3 adjustedTab = *tab;
            if (!hasProperty(widget, "noTabBarShapeAdjustment") &&
                tab->cornerWidgets == QStyleOptionTab::NoCornerWidgets && (
                    tab->position == QStyleOptionTab::Beginning ||
                    tab->position == QStyleOptionTab::OnlyOneTab))
            {
                if (option->direction == Qt::LeftToRight)
                    adjustedTab.rect = adjustedTab.rect.adjusted(-1, 0, 0, 0);
                else
                    adjustedTab.rect = adjustedTab.rect.adjusted(0, 0, 1 ,0);
            }
            QProxyStyle::drawControl(element, &adjustedTab, painter, widget);
            return;
        }
        break;

    case CE_MenuBarItem:
        painter->save();
        if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
            QColor highlightOutline = Utils::StyleHelper::borderColor().lighter(120);
            bool act = mbi->state & State_Sunken;
            bool dis = !(mbi->state & State_Enabled);
            Utils::StyleHelper::menuGradient(painter, option->rect, option->rect);
            QStyleOptionMenuItem item = *mbi;
            item.rect = mbi->rect;
            QPalette pal = mbi->palette;
            pal.setBrush(QPalette::ButtonText, dis ? Qt::gray : Qt::black);
            item.palette = pal;
            QCommonStyle::drawControl(element, &item, painter, widget);
            QRect r = option->rect;

            if (act) {
                // Fill|
                QColor baseColor = Utils::StyleHelper::baseColor();
                QLinearGradient grad(option->rect.topLeft(), option->rect.bottomLeft());
                grad.setColorAt(0, baseColor.lighter(120));
                grad.setColorAt(1, baseColor.lighter(130));
                painter->fillRect(option->rect.adjusted(1, 1, -1, 0), grad);

                // Outline
                painter->setPen(QPen(highlightOutline, 0));
                painter->drawLine(QPoint(r.left(), r.top() + 1), QPoint(r.left(), r.bottom()));
                painter->drawLine(QPoint(r.right(), r.top() + 1), QPoint(r.right(), r.bottom()));
                painter->drawLine(QPoint(r.left() + 1, r.top()), QPoint(r.right() - 1, r.top()));
                highlightOutline.setAlpha(60);
                painter->setPen(QPen(highlightOutline, 0));
                painter->drawPoint(r.topLeft());
                painter->drawPoint(r.topRight());

                QPalette pal = mbi->palette;
                uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
                if (!styleHint(SH_UnderlineShortcut, mbi, widget))
                    alignment |= Qt::TextHideMnemonic;
                pal.setBrush(QPalette::Text, dis ? Qt::gray : QColor(0, 0, 0, 60));
                drawItemText(painter, item.rect.translated(0, 1), alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text);
                pal.setBrush(QPalette::Text, dis ? Qt::gray : Qt::white);
                drawItemText(painter, item.rect, alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text);
            }
        }
        painter->restore();
        break;

    case CE_ComboBoxLabel:
        if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
            if (panelWidget(widget)) {
                painter->save();
                QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
                QPalette customPal = cb->palette;
                bool drawIcon = !(widget && widget->property("hideicon").toBool());

                if (!cb->currentIcon.isNull() && drawIcon) {
                    QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
                                                                 : QIcon::Disabled;
                    QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode);
                    QRect iconRect(editRect);
                    iconRect.setWidth(cb->iconSize.width() + 4);
                    iconRect = alignedRect(cb->direction,
                                           Qt::AlignLeft | Qt::AlignVCenter,
                                           iconRect.size(), editRect);
                    if (cb->editable)
                        painter->fillRect(iconRect, customPal.brush(QPalette::Base));
                    drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);

                    if (cb->direction == Qt::RightToLeft)
                        editRect.translate(-4 - cb->iconSize.width(), 0);
                    else
                        editRect.translate(cb->iconSize.width() + 4, 0);

                    // Reserve some space for the down-arrow
                    editRect.adjust(0, 0, -13, 0);
                }

                QString text = option->fontMetrics.elidedText(cb->currentText, Qt::ElideRight, editRect.width());
                if ((option->state & State_Enabled)) {
                    painter->setPen(QColor(0, 0, 0, 70));
                    painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, text);
                } else {
                    painter->setOpacity(0.8);
                }
                painter->setPen(Utils::StyleHelper::panelTextColor(lightColored(widget)));
                painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, text);

                painter->restore();
            } else {
                QProxyStyle::drawControl(element, option, painter, widget);
            }
        }
        break;

    case CE_SizeGrip: {
            painter->save();
            QColor dark = Qt::white;
            dark.setAlphaF(0.1);
            int x, y, w, h;
            option->rect.getRect(&x, &y, &w, &h);
            int sw = qMin(h, w);
            if (h > w)
                painter->translate(0, h - w);
            else
                painter->translate(w - h, 0);
            int sx = x;
            int sy = y;
            int s = 4;
            painter->setPen(dark);
            if (option->direction == Qt::RightToLeft) {
                sx = x + sw;
                for (int i = 0; i < 4; ++i) {
                    painter->drawLine(x, sy, sx, sw);
                    sx -= s;
                    sy += s;
                }
            } else {
                for (int i = 0; i < 4; ++i) {
                    painter->drawLine(sx, sw, sw, sy);
                    sx += s;
                    sy += s;
                }
            }
            painter->restore();
        }
        break;

    case CE_MenuBarEmptyArea: {
            Utils::StyleHelper::menuGradient(painter, option->rect, option->rect);
            painter->save();
            painter->setPen(Utils::StyleHelper::borderColor());
            painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
            painter->restore();
        }
        break;

    case CE_ToolBar:
        {
            QRect rect = option->rect;
            bool horizontal = option->state & State_Horizontal;
            rect = option->rect;

            // Map offset for global window gradient
            QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) -
                            widget->mapToGlobal(option->rect.topLeft());
            QRect gradientSpan;
            if (widget)
                gradientSpan = QRect(offset, widget->window()->size());

            bool drawLightColored = lightColored(widget);
            if (horizontal)
                Utils::StyleHelper::horizontalGradient(painter, gradientSpan, rect, drawLightColored);
            else
                Utils::StyleHelper::verticalGradient(painter, gradientSpan, rect, drawLightColored);

            if (!drawLightColored)
                painter->setPen(Utils::StyleHelper::borderColor());
            else
                painter->setPen(QColor(0x888888));

            if (horizontal) {
                // Note: This is a hack to determine if the
                // toolbar should draw the top or bottom outline
                // (needed for the find toolbar for instance)
                QColor lighter(Utils::StyleHelper::sidebarHighlight());
                if (drawLightColored)
                    lighter = QColor(255, 255, 255, 180);
                if (widget && widget->property("topBorder").toBool()) {
                    painter->drawLine(rect.topLeft(), rect.topRight());
                    painter->setPen(lighter);
                    painter->drawLine(rect.topLeft() + QPoint(0, 1), rect.topRight() + QPoint(0, 1));
                } else {
                    painter->drawLine(rect.bottomLeft(), rect.bottomRight());
                    painter->setPen(lighter);
                    painter->drawLine(rect.topLeft(), rect.topRight());
                }
            } else {
                painter->drawLine(rect.topLeft(), rect.bottomLeft());
                painter->drawLine(rect.topRight(), rect.bottomRight());
            }
        }
        break;

    default:
        QProxyStyle::drawControl(element, option, painter, widget);
        break;
    }
}
Example #5
0
//! [paint start]
bool MyDecoration::paint(QPainter *painter, const QWidget *widget,
                         int decorationRegion, DecorationState state)
{
    if (decorationRegion == None)
        return false;
    //! [paint start]

    //! [paint different regions]
    bool handled = false;

    QPalette palette = QApplication::palette();
    QHash<DecorationRegion, QPixmap> buttonPixmaps;

    if (widget->windowState() == Qt::WindowMaximized)
        buttonPixmaps = maximizedButtonPixmaps;
    else
        buttonPixmaps = normalButtonPixmaps;

    if (decorationRegion & Title) {
        QRect rect = QDecoration::region(widget, Title).boundingRect();
        painter->fillRect(rect, palette.brush(QPalette::Base));
        painter->save();
        painter->setPen(QPen(palette.color(QPalette::Text)));
        painter->drawText(rect, Qt::AlignCenter, widget->windowTitle());
        painter->restore();
        handled = true;
    }
    if (decorationRegion & Top) {
        QRect rect = QDecoration::region(widget, Top).boundingRect();
        painter->fillRect(rect, palette.brush(QPalette::Dark));
        handled = true;
    }
    if (decorationRegion & Left) {
        QRect rect = QDecoration::region(widget, Left).boundingRect();
        painter->fillRect(rect, palette.brush(QPalette::Dark));
        handled = true;
    }
    if (decorationRegion & Right) {
        QRect rect = QDecoration::region(widget, Right).boundingRect();
        painter->fillRect(rect, palette.brush(QPalette::Dark));
        handled = true;
    }
    if (decorationRegion & Bottom) {
        QRect rect = QDecoration::region(widget, Bottom).boundingRect();
        painter->fillRect(rect, palette.brush(QPalette::Dark));
        handled = true;
    }
    if (decorationRegion & TopLeft) {
        QRect rect = QDecoration::region(widget, TopLeft).boundingRect();
        painter->fillRect(rect, palette.brush(QPalette::Dark));
        handled = true;
    }
    if (decorationRegion & TopRight) {
        QRect rect = QDecoration::region(widget, TopRight).boundingRect();
        painter->fillRect(rect, palette.brush(QPalette::Dark));
        handled = true;
    }
    if (decorationRegion & BottomLeft) {
        QRect rect = QDecoration::region(widget, BottomLeft).boundingRect();
        painter->fillRect(rect, palette.brush(QPalette::Dark));
        handled = true;
    }
    if (decorationRegion & BottomRight) {
        QRect rect = QDecoration::region(widget, BottomRight).boundingRect();
        painter->fillRect(rect, palette.brush(QPalette::Dark));
        handled = true;
    }
    //! [paint different regions]

    //! [paint buttons]
    int margin = (titleHeight - 16) / 2;
    Qt::WindowFlags flags = widget->windowFlags();

    foreach (DecorationRegion testRegion, stateRegions) {
        if (decorationRegion & testRegion && flags & buttonHintMap.key(testRegion)) {
            QRect rect = QDecoration::region(
                widget, testRegion).boundingRect();
            painter->fillRect(rect, palette.brush(QPalette::Base));

            QRect buttonRect = rect.adjusted(0, margin, -buttonMargin - margin,
                                             -buttonMargin);
            painter->drawPixmap(buttonRect.topLeft(), buttonPixmaps[testRegion]);
            handled = true;
        }
    }
    //! [paint buttons]

    //! [paint end]
    return handled;
}
Example #6
0
void
PlayableCover::paintEvent( QPaintEvent* event )
{
    Q_UNUSED( event );

    QPainter painter( this );
    painter.setRenderHint( QPainter::Antialiasing );
    painter.drawPixmap( 0, 0, pixmap() );

    if ( !m_showText )
        return;

    QRect r = contentsRect().adjusted( margin(), margin(), -margin(), -margin() );
    QPixmap buffer( r.size() );
    buffer.fill( Qt::transparent );
    QPainter bufpainter( &buffer );
    bufpainter.setRenderHint( QPainter::Antialiasing );

    QTextOption to;
    to.setWrapMode( QTextOption::NoWrap );

    QColor c1;
    c1.setRgb( 0, 0, 0 );
    c1.setAlphaF( 0.00 );
    QColor c2;
    c2.setRgb( 0, 0, 0 );
    c2.setAlphaF( 0.88 );

    QString text;
    QFont font = QLabel::font();
    font.setPointSize( TomahawkUtils::defaultFontSize() );
    QFont boldFont = font;
    boldFont.setBold( true );
    boldFont.setPointSize( TomahawkUtils::defaultFontSize() + 5 );

    QString top, bottom;
    if ( m_artist )
    {
        top = m_artist->name();
    }
    else if ( m_album )
    {
        top = m_album->name();
        bottom = m_album->artist()->name();
    }
    else if ( m_query )
    {
        top = m_query->queryTrack()->track();
        bottom = m_query->queryTrack()->artist();
    }

    int bottomHeight = QFontMetrics( font ).boundingRect( bottom ).height();
    int topHeight = QFontMetrics( boldFont ).boundingRect( top ).height();
    int frameHeight = bottomHeight + topHeight + 4;

    QRect gradientRect = r.adjusted( 0, r.height() - frameHeight * 3, 0, 0 );
    QLinearGradient gradient( QPointF( 0, 0 ), QPointF( 0, 1 ) );
    gradient.setCoordinateMode( QGradient::ObjectBoundingMode );
    gradient.setColorAt( 0.0, c1 );
    gradient.setColorAt( 0.6, c2 );
    gradient.setColorAt( 1.0, c2 );

    bufpainter.save();
    bufpainter.setPen( Qt::transparent );
    bufpainter.setBrush( gradient );
    bufpainter.drawRect( gradientRect );
    bufpainter.restore();

    bufpainter.setPen( Qt::white );

    QRect textRect = r.adjusted( 8, r.height() - frameHeight - 16, -8, -16 );
    bool oneLiner = false;
    if ( bottom.isEmpty() )
        oneLiner = true;

    bufpainter.setFont( boldFont );
    if ( oneLiner )
    {
        bufpainter.save();
        QFont f = bufpainter.font();

        while ( f.pointSizeF() > 9 && bufpainter.fontMetrics().width( top ) > textRect.width() )
        {
            f.setPointSizeF( f.pointSizeF() - 0.2 );
            bufpainter.setFont( f );
        }

        to.setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
        text = bufpainter.fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 );
        bufpainter.drawText( textRect, text, to );

        bufpainter.restore();
    }
    else
    {
        to.setAlignment( Qt::AlignHCenter | Qt::AlignTop );
        text = bufpainter.fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 );
        bufpainter.drawText( textRect, text, to );

        bufpainter.setFont( font );

        QRect r = textRect;
        r.setTop( r.bottom() - bufpainter.fontMetrics().height() );
        r.adjust( 4, 0, -4, -1 );

        text = bufpainter.fontMetrics().elidedText( bottom, Qt::ElideRight, textRect.width() - 16 );
        int textWidth = bufpainter.fontMetrics().width( text );
        r.adjust( ( r.width() - textWidth ) / 2 - 6, 0, - ( ( r.width() - textWidth ) / 2 - 6 ), 0 );

        m_itemRects.clear();
        m_itemRects << r;

        if ( m_hoveredRect == r )
        {
            TomahawkUtils::drawQueryBackground( &bufpainter, r );
            bufpainter.setPen( TomahawkUtils::Colors::SELECTION_FOREGROUND );
        }

        to.setAlignment( Qt::AlignHCenter | Qt::AlignBottom );
        bufpainter.drawText( textRect.adjusted( 5, -1, -5, -1 ), text, to );
    }

    {
        QBrush brush( buffer );
        QPen pen;
        pen.setColor( Qt::transparent );
        pen.setJoinStyle( Qt::RoundJoin );

        float frameWidthPct = 0.20;
        painter.setBrush( brush );
        painter.setPen( pen );
        painter.drawRoundedRect( r, frameWidthPct * 100.0, frameWidthPct * 100.0, Qt::RelativeSize );
    }
}
void TimeTrackingView::paintEvent( QPaintEvent* e )
{
    m_activeFieldRects.clear();
    const int FieldHeight = m_cachedTotalsFieldRect.height();
    QPainter painter( this );
    // all attributes are determined in data(), we just paint the rects:
    for ( int row = 0; row < rowCount() - 1; ++row ) {
        for ( int column = 0; column < columnCount(); ++column ) {
            // get the rectangle of the field that will be drawn
            QRect fieldRect;
            const int y = row * FieldHeight;
            if ( column == columnCount() - 1 ) { // totals column
                fieldRect = QRect( width() - m_cachedTotalsFieldRect.width(), y,
                                   m_cachedTotalsFieldRect.width(), FieldHeight );
            } else if ( column == 0 ) { // task column
                fieldRect = QRect( 0, y, taskColumnWidth(), FieldHeight );
            } else if ( column > 0 ) { //  a task
                fieldRect = QRect( width() - m_cachedTotalsFieldRect.width()
                                   - 8 * m_cachedDayFieldRect.width()
                                   + column * m_cachedDayFieldRect.width(), y,
                                   m_cachedDayFieldRect.width(), FieldHeight );
            }
            // paint the field, if it is in the dirty region
            if( e->rect().contains( fieldRect ) ) {
                DataField field = m_defaultField;
                data( field, column, row );
                int alignment = Qt::AlignRight | Qt::AlignVCenter;
                if ( row == 0 ) {
                    alignment = Qt::AlignCenter | Qt::AlignVCenter;
                } else if ( column == 0 && row < rowCount() - 1 ) {
                    alignment = Qt::AlignLeft | Qt::AlignVCenter;
                }
                if( column == 0 ) { // task column
                    field.text = elidedText( field.text, field.font, fieldRect.width() - 2*Margin );
                }
                if ( field.storeAsActive ) m_activeFieldRects << fieldRect;
                const QRect textRect = fieldRect.adjusted( Margin, Margin, -Margin, -Margin );
                if ( field.hasHighlight ) {
                    painter.setBrush( field.highlight );
                    painter.setPen( Qt::NoPen );
                    painter.drawRect( fieldRect );
                } else {
                    painter.setBrush( field.background );
                    painter.setPen( Qt::NoPen );
                    painter.drawRect( fieldRect );
                }
                painter.setPen( palette().text().color() );
                painter.setFont( field.font );
                painter.drawText( textRect, alignment, field.text );
            }
        }
    }
    // paint the tracking row
    const int top = ( rowCount() - 1 ) * FieldHeight;
    const QRect fieldRect( 0, top, width(), height() - top );
    if ( e->rect().contains( fieldRect ) ) {
        DataField field = m_defaultField;
        data( field, 0, rowCount() - 1 );
        painter.setBrush( field.background );
        painter.setPen( Qt::NoPen );
        painter.drawRect( fieldRect );
    }
}
Example #8
0
	void ModeTabBar::paintEvent(QPaintEvent *event)
	{
		QPainter p(this);
		IconManager *iconManager = IconManager::instance();

		QLinearGradient bgGrad(rect().topLeft(), rect().topRight());
		bgGrad.setColorAt(0.5, palette().color(QPalette::Window));
		bgGrad.setColorAt(1.0, palette().color(QPalette::Midlight));
		p.fillRect(rect(), bgGrad);

		p.setPen(palette().color(QPalette::Shadow));
		p.drawLine(width() - 1, 0, width() - 1, height());

		for(int i = 0; i < count(); ++i) {
			p.save();

			QFont labelFont = font();
			labelFont.setBold(true);
			p.setFont(labelFont);

			QRect rect = tabRect(i);

			int textHeight = p.fontMetrics().boundingRect(QRect(0, 0, width(), height()), 0, tabLabel(i)).height();
			QRect labelRect(QPoint(rect.left() + tabPadding, rect.bottom() - textHeight - tabPadding), QSize(rect.width() - (tabPadding * 2), textHeight));

			int iconSize = rect.height() - textHeight - (3 * tabPadding);
			QRect iconRect(QPoint((rect.width() - iconSize) / 2, rect.top() + tabPadding), QSize(iconSize, iconSize));

			bool isSelected = (i == m_currentIndex);
			bool isEnabled = isTabEnabled(i);
			bool isHovered = (i == m_hoverIndex);

			if(isHovered && isEnabled) {
				p.fillRect(rect.adjusted(0, 0, -1, 0), QColor(0, 0, 0, 24));
			}

			if(isSelected) {
				p.save();

				p.setPen(palette().color(QPalette::Shadow));
				p.drawLine(rect.topLeft(), rect.topRight());
				p.drawLine(rect.bottomLeft(), rect.bottomRight());

				p.fillRect(rect.adjusted(0, 0, -1, 0), QColor(0, 0, 0, 32));
				p.translate(rect.width() - 6, rect.top() + (rect.height() / 2) - 12);

				QPolygon arrowPoly;
				arrowPoly.append(QPoint(7, 0));
				arrowPoly.append(QPoint(7, 24));
				arrowPoly.append(QPoint(0, 12));

				p.translate(0, 1);
				p.setBrush(palette().color(QPalette::Shadow));
				p.setPen(palette().color(QPalette::Shadow));
				p.setRenderHint(QPainter::Antialiasing);
				p.drawPolygon(arrowPoly);

				p.translate(0, -1);
				p.setBrush(palette().color(QPalette::Light));
				p.drawPolygon(arrowPoly);

				p.restore();
			}

			if(!isEnabled)
				p.setOpacity(0.6);

			QIcon icon(iconManager->icon(tabIcon(i)));
			QPixmap pixmap = icon.pixmap(iconSize, iconSize, isEnabled ? QIcon::Normal : QIcon::Disabled);

			p.drawPixmap(iconRect, pixmap);

			p.setPen(palette().color(QPalette::Text));
			p.drawText(labelRect, Qt::AlignCenter, tabLabel(i));
			p.restore();
		}
	}
void CWizNoteStyle::drawMultiLineListWidgetItem(const QStyleOptionViewItemV4 *vopt, QPainter *p, const CWizMultiLineListWidget *view) const
{
    bool imageAlignLeft = view->imageAlignLeft();
    int imageWidth = view->imageWidth();
    int lineCount = view->lineCount();
    int wrapTextLineText = view->wrapTextLineIndex();
    const QPixmap img = view->itemImage(vopt->index);

    p->save();
    p->setClipRect(vopt->rect);

    QRect textLine = vopt->rect;
    textLine.adjust(4, 0, -4, 0);
    p->setPen(Utils::StyleHelper::listViewItemSeperator());
    p->drawLine(textLine.bottomLeft(), textLine.bottomRight());

    QRect textRect = vopt->rect;
    //QRect textRect = subElementRect(SE_ItemViewItemText, vopt, view);

    // draw the background
    drawMultiLineItemBackground(vopt, p, view);

    if (!img.isNull() && img.width() > 0 && img.height() > 0)
    {
        QRect imageRect = textRect;
        if (imageAlignLeft)
        {
            imageRect.setRight(imageRect.left() + imageWidth + 16);
            imageRect.adjust(4, 4, -4, -4);
            textRect.setLeft(imageRect.right());
        }
        else
        {
            imageRect.setLeft(imageRect.right() - imageWidth + 16);
            imageRect.adjust(4, 4, -4, -4);
            textRect.setRight(imageRect.left());
        }

        if (img.width() > imageRect.width() || img.height() > imageRect.height())
        {
            double fRate = std::min<double>(double(imageRect.width()) / img.width(), double(imageRect.height()) / img.height());
            int newWidth = int(img.width() * fRate);
            int newHeight = int(img.height() * fRate);
            //
            int adjustX = (imageRect.width() - newWidth) / 2;
            int adjustY = (imageRect.height() - newHeight) / 2;
            imageRect.adjust(adjustX, adjustY, -adjustX, -adjustY);
        }
        else
        {
            int adjustX = (imageRect.width() - img.width()) / 2;
            int adjustY = (imageRect.height() - img.height()) / 2;
            imageRect.adjust(adjustX, adjustY, -adjustX, -adjustY);
        }
        p->drawPixmap(imageRect, img);
    }

    // draw the text
    QPalette::ColorGroup cg = vopt->state & QStyle::State_Enabled
                              ? QPalette::Normal : QPalette::Disabled;
    if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
        cg = QPalette::Inactive;

    if (vopt->state & QStyle::State_Selected) {
        p->setPen(vopt->palette.color(cg, QPalette::HighlightedText));
    } else {
        p->setPen(vopt->palette.color(cg, QPalette::Text));
    }
    if (vopt->state & QStyle::State_Editing) {
        p->setPen(vopt->palette.color(cg, QPalette::Text));
        p->drawRect(textRect.adjusted(0, 0, -1, -1));
    }

    textRect.adjust(8, 8, -8, -8);
    bool selected = vopt->state.testFlag(State_Selected);
    int lineHeight = vopt->fontMetrics.height() + 2;

    for (int line = 0; line < wrapTextLineText && line < lineCount; line++)
    {
        QColor color = (0 == line) ? Utils::StyleHelper::listViewMultiLineFirstLine(selected)
            : Utils::StyleHelper::listViewMultiLineOtherLine(selected);
        //
        CString strText = view->itemText(vopt->index, line);
        color = view->itemTextColor(vopt->index, line, selected, color);
        QRect rc = textRect;
        rc.setTop(rc.top() + line * lineHeight);
        rc.setHeight(lineHeight);
        ::WizDrawTextSingleLine(p, rc, strText,  Qt::TextSingleLine | Qt::AlignVCenter, color, true);
    }

    int line = wrapTextLineText;
    if (line < lineCount)
    {
        CString strText = view->itemText(vopt->index, line);
        for (; line < lineCount; line++)
        {
            QColor color = Utils::StyleHelper::listViewMultiLineOtherLine(selected);
            //
            color = view->itemTextColor(vopt->index, line, selected, color);
            QRect rc = textRect;
            rc.setTop(rc.top() + line * lineHeight);
            rc.setHeight(lineHeight);
            bool elidedText = (line == lineCount - 1);
            ::WizDrawTextSingleLine(p, rc, strText,  Qt::TextSingleLine | Qt::AlignVCenter, color, elidedText);
        }
    }

    // draw the focus rect
    if (vopt->state & QStyle::State_HasFocus) {
        QStyleOptionFocusRect o;
        o.QStyleOption::operator=(*vopt);
        o.rect = subElementRect(SE_ItemViewItemFocusRect, vopt, view);
        o.state |= QStyle::State_KeyboardFocusChange;
        o.state |= QStyle::State_Item;
        QPalette::ColorGroup cg = (vopt->state & QStyle::State_Enabled)
                                  ? QPalette::Normal : QPalette::Disabled;
        o.backgroundColor = vopt->palette.color(cg, (vopt->state & QStyle::State_Selected)
                                                ? QPalette::Highlight : QPalette::Window);
        proxy()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, p, view);
    }

    //draw extra image
    QRect rcExtra;
    QPixmap pixExtra;
    if (view->itemExtraImage(vopt->index, vopt->rect, rcExtra, pixExtra))
    {
        p->drawPixmap(rcExtra, pixExtra);
    }

    p->restore();
}
Example #10
0
void
PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
    TrackModelItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
    Q_ASSERT( item );

    QStyleOptionViewItemV4 opt = option;
    prepareStyleOption( &opt, index, item );
    opt.text.clear();
    qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );

    if ( m_view->hoveredIndex().row() == index.row() && m_view->hoveredIndex().column() == index.column() &&
       ( index.column() == TrackModel::Artist || index.column() == TrackModel::Album ) )
    {
        opt.rect.setWidth( opt.rect.width() - 16 );
        QRect arrowRect( opt.rect.x() + opt.rect.width(), opt.rect.y() + 1, opt.rect.height() - 2, opt.rect.height() - 2 );

        if ( m_arrowIcon.height() != arrowRect.height() )
            m_arrowIcon = m_arrowIcon.scaled( arrowRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation );
        painter->drawPixmap( arrowRect, m_arrowIcon );
    }

    painter->save();

    if ( index.column() == TrackModel::Score )
    {
        QColor barColor( 167, 183, 211 ); // This matches the sidebar (sourcetreeview.cpp:672)
        if ( opt.state & QStyle::State_Selected )
            painter->setPen( opt.palette.brightText().color() );
        else
            painter->setPen( barColor );

        QRect r = opt.rect.adjusted( 3, 3, -6, -4 );
        painter->drawRect( r );

        QRect fillR = r;
        int fillerWidth = (int)( index.data().toFloat() * (float)fillR.width() );
        fillR.adjust( 0, 0, -( fillR.width() - fillerWidth ), 0 );

        if ( opt.state & QStyle::State_Selected )
            painter->setBrush( opt.palette.brightText().color() );
        else
            painter->setBrush( barColor );

        painter->drawRect( fillR );
    }
    else if ( item->isPlaying() )
    {
        {
            QRect r = opt.rect.adjusted( 3, 0, 0, 0 );

            // Paint Now Playing Speaker Icon
            if ( m_view->header()->visualIndex( index.column() ) == 0 )
            {
                r.adjust( 0, 0, 0, -3 );
                painter->drawPixmap( r.adjusted( 3, 1, 18 - r.width(), 1 ), m_nowPlayingIcon );
                r.adjust( 25, 0, 0, 3 );
            }

            painter->setPen( opt.palette.text().color() );
            QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 );
            painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, m_centerOption );
        }
    }
    else
    {
        painter->setPen( opt.palette.text().color() );
        QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, opt.rect.width() - 3 );
        painter->drawText( opt.rect.adjusted( 3, 1, 0, 0 ), text, m_centerOption );
    }

    painter->restore();
}
Example #11
0
void ProgressBar::paintEvent(QPaintEvent *)
{
    // TODO move font into Utils::StyleHelper
    // TODO use Utils::StyleHelper white

    double range = maximum() - minimum();
    double percent = 0.;
    if (!qFuzzyIsNull(range))
        percent = qBound(0., (value() - minimum()) / range, 1.);

    if (finished())
        percent = 1;

    QPainter p(this);
    QFont fnt(titleFont());
    p.setFont(fnt);
    QFontMetrics fm(fnt);

    int titleHeight = m_titleVisible ? fm.height() : 0;

    // Draw separator
    int separatorHeight = m_separatorVisible ? SEPARATOR_HEIGHT : 0;
    if (m_separatorVisible) {
        QRectF innerRect = QRectF(this->rect()).adjusted(0.5, 0.5, -0.5, -0.5);
        p.setPen(StyleHelper::sidebarShadow());
        p.drawLine(innerRect.topLeft(), innerRect.topRight());

        if (creatorTheme()->flag(Theme::DrawToolBarHighlights)) {
            p.setPen(StyleHelper::sidebarHighlight());
            p.drawLine(innerRect.topLeft() + QPointF(1, 1), innerRect.topRight() + QPointF(0, 1));
        }
    }

    if (m_titleVisible) {
        QRect textBounds = fm.boundingRect(m_title);
        textBounds.moveCenter(rect().center());
        int alignment = Qt::AlignHCenter;

        int textSpace = rect().width() - 8;
        // If there is not enough room when centered, we left align and
        // elide the text
        QString elidedtitle  = fm.elidedText(m_title, Qt::ElideRight, textSpace);

        QRect textRect = rect().adjusted(3, separatorHeight - 1, -3, 0);
        textRect.setHeight(titleHeight+5);

        p.setPen(QColor(0, 0, 0, 120));
        p.drawText(textRect, alignment | Qt::AlignBottom, elidedtitle);
        p.translate(0, -1);
        p.setPen(creatorTheme()->color(Theme::ProgressBarTitleColor));
        p.drawText(textRect, alignment | Qt::AlignBottom, elidedtitle);
        p.translate(0, 1);
    }

    m_progressHeight = PROGRESSBAR_HEIGHT;
    m_progressHeight += ((m_progressHeight % 2) + 1) % 2; // make odd
    // draw outer rect
    const QRect rect(INDENT - 1, titleHeight + separatorHeight + (m_titleVisible ? 5 : 4),
                     size().width() - 2 * INDENT + 1, m_progressHeight);

    QRectF inner = rect.adjusted(2, 2, -2, -2);
    inner.adjust(0, 0, qRound((percent - 1) * inner.width()), 0);

    // Show at least a hint of progress. Non-flat needs more pixels due to the borders.
    inner.setWidth(qMax(qMin(3.0, qreal(rect.width())), inner.width()));

    Theme::Color themeColor = Theme::ProgressBarColorNormal;
    if (m_error)
        themeColor = Theme::ProgressBarColorError;
    else if (m_finished)
        themeColor = Theme::ProgressBarColorFinished;
    const QColor c = creatorTheme()->color(themeColor);

    //draw the progress bar
    if (creatorTheme()->flag(Theme::FlatToolBars)) {
        p.fillRect(rect.adjusted(2, 2, -2, -2),
                   creatorTheme()->color(Theme::ProgressBarBackgroundColor));
        p.fillRect(inner, c);
    } else {
        const static QImage bar(StyleHelper::dpiSpecificImageFile(
                                    QLatin1String(":/core/images/progressbar.png")));
        StyleHelper::drawCornerImage(bar, &p, rect, 3, 3, 3, 3);

        // Draw line and shadow after the gradient fill
        if (value() > 0 && value() < maximum()) {
            p.fillRect(QRect(inner.right(), inner.top(), 2, inner.height()), QColor(0, 0, 0, 20));
            p.fillRect(QRect(inner.right(), inner.top(), 1, inner.height()), QColor(0, 0, 0, 60));
        }

        QLinearGradient grad(inner.topLeft(), inner.bottomLeft());
        grad.setColorAt(0, c.lighter(130));
        grad.setColorAt(0.4, c.lighter(106));
        grad.setColorAt(0.41, c.darker(106));
        grad.setColorAt(1, c.darker(130));
        p.setPen(Qt::NoPen);
        p.setBrush(grad);
        p.drawRect(inner);
        p.setBrush(Qt::NoBrush);
        p.setPen(QPen(QColor(0, 0, 0, 30), 1));

        p.drawLine(inner.topLeft() + QPointF(0.5, 0.5), inner.topRight() + QPointF(-0.5, 0.5));
        p.drawLine(inner.topLeft() + QPointF(0.5, 0.5), inner.bottomLeft() + QPointF(0.5, -0.5));
        p.drawLine(inner.topRight() + QPointF(-0.5, 0.5), inner.bottomRight() + QPointF(-0.5, -0.5));
        p.drawLine(inner.bottomLeft() + QPointF(0.5, -0.5), inner.bottomRight() + QPointF(-0.5, -0.5));
    }

    if (m_cancelEnabled) {
        // Draw cancel button
        p.setOpacity(m_cancelButtonFader);

        if (value() < maximum() && !m_error) {
            m_cancelRect = QRect(rect.adjusted(rect.width() - CANCELBUTTON_WIDTH + 2, 1, 0, 0));
            const bool hover = m_cancelRect.contains(mapFromGlobal(QCursor::pos()));
            const QRectF cancelVisualRect(m_cancelRect.adjusted(0, 1, -2, -2));
            int intensity = hover ? 90 : 70;
            if (!creatorTheme()->flag(Theme::FlatToolBars)) {
                QLinearGradient grad(cancelVisualRect.topLeft(), cancelVisualRect.bottomLeft());
                QColor buttonColor(intensity, intensity, intensity, 255);
                grad.setColorAt(0, buttonColor.lighter(130));
                grad.setColorAt(1, buttonColor.darker(130));
                p.setPen(Qt::NoPen);
                p.setBrush(grad);
                p.drawRect(cancelVisualRect);

                p.setPen(QPen(QColor(0, 0, 0, 30)));
                p.drawLine(cancelVisualRect.topLeft() + QPointF(-0.5, 0.5), cancelVisualRect.bottomLeft() + QPointF(-0.5, -0.5));
                p.setPen(QPen(QColor(0, 0, 0, 120)));
                p.drawLine(cancelVisualRect.topLeft() + QPointF(0.5, 0.5), cancelVisualRect.bottomLeft() + QPointF(0.5, -0.5));
                p.setPen(QPen(QColor(255, 255, 255, 30)));
                p.drawLine(cancelVisualRect.topLeft() + QPointF(1.5, 0.5), cancelVisualRect.bottomLeft() + QPointF(1.5, -0.5));
            }
            p.setPen(QPen(hover ? StyleHelper::panelTextColor() : QColor(180, 180, 180), 1.2, Qt::SolidLine, Qt::FlatCap));
            p.setRenderHint(QPainter::Antialiasing, true);
            p.drawLine(cancelVisualRect.topLeft() + QPointF(4.0, 2.0), cancelVisualRect.bottomRight() + QPointF(-3.0, -2.0));
            p.drawLine(cancelVisualRect.bottomLeft() + QPointF(4.0, -2.0), cancelVisualRect.topRight() + QPointF(-3.0, 2.0));
        }
    }
}
Example #12
0
void
PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, bool useAvatars ) const
{
    TrackModelItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
    Q_ASSERT( item );

    QStyleOptionViewItemV4 opt = option;
    prepareStyleOption( &opt, index, item );
    opt.text.clear();

    qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );

    if ( m_view->header()->visualIndex( index.column() ) > 0 )
        return;

    QPixmap pixmap;
    QString artist, track, upperText, lowerText;
    source_ptr source = item->query()->playedBy().first;

    if ( item->query()->results().count() )
    {
        artist = item->query()->results().first()->artist()->name();
        track = item->query()->results().first()->track();
    }
    else
    {
        artist = item->query()->artist();
        track = item->query()->track();
    }

    if ( source.isNull() )
    {
        upperText = artist;
        lowerText = track;
    }
    else
    {
        upperText = QString( "%1 - %2" ).arg( artist ).arg( track );
        QString playtime = TomahawkUtils::ageToString( QDateTime::fromTime_t( item->query()->playedBy().second ) );

        if ( source == SourceList::instance()->getLocal() )
            lowerText = QString( "played %1 ago by you" ).arg( playtime );
        else
            lowerText = QString( "played %1 ago by %2" ).arg( playtime ).arg( source->friendlyName() );

        if ( useAvatars )
            pixmap = source->avatar( Source::FancyStyle );
    }

    if ( pixmap.isNull() && !useAvatars )
        pixmap = QPixmap( RESPATH "images/track-placeholder.png" );
    else if ( pixmap.isNull() && useAvatars )
        pixmap = m_defaultAvatar;

    painter->save();
    {
        QRect r = opt.rect.adjusted( 3, 6, 0, -6 );

        // Paint Now Playing Speaker Icon
        if ( item->isPlaying() )
        {
            r.adjust( 0, 0, 0, 0 );
            QRect npr = r.adjusted( 3, r.height() / 2 - m_nowPlayingIcon.height() / 2, 18 - r.width(), -r.height() / 2 + m_nowPlayingIcon.height() / 2  );
            painter->drawPixmap( npr, m_nowPlayingIcon );
            r.adjust( 22, 0, 0, 0 );
        }

        painter->setPen( opt.palette.text().color() );

        QRect ir = r.adjusted( 4, 0, -option.rect.width() + option.rect.height() - 8 + r.left(), 0 );

        QPixmap scover;
        if ( m_cache.contains( pixmap.cacheKey() ) )
        {
            scover = m_cache.value( pixmap.cacheKey() );
        }
        else
        {
            scover = pixmap.scaled( ir.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation );
            m_cache.insert( pixmap.cacheKey(), scover );
        }
        painter->drawPixmap( ir, scover );

        QFont boldFont = opt.font;
        boldFont.setBold( true );

        r.adjust( ir.width() + 12, 0, -12, 0 );
        painter->setFont( boldFont );
        QString text = painter->fontMetrics().elidedText( upperText, Qt::ElideRight, r.width() );
        painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, m_topOption );


        painter->setFont( opt.font);
        text = painter->fontMetrics().elidedText( lowerText, Qt::ElideRight, r.width() );
        painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, m_bottomOption );
    }
    painter->restore();
}
Example #13
0
void SymbolBox::init(bool showNoSymbol) {
  QPixmap icon = QPixmap(15, 15);
  QColor c = QColor(Qt::gray);
  icon.fill(c);
  const QRect r = QRect(1, 1, 14, 14);
  QPainter p(&icon);
  p.setRenderHint(QPainter::Antialiasing);
  QwtSymbol symb;
  p.setBrush(QBrush(QColor(Qt::white)));

  if (showNoSymbol)
    this->addItem(tr("No Symbol"));

  symb.setStyle(QwtSymbol::Ellipse);
  symb.draw(&p, r);
  this->addItem(icon, tr("Ellipse"));

  symb.setStyle(QwtSymbol::Rect);
  icon.fill(c);
  symb.draw(&p, r.adjusted(0, 0, -1, -1));
  this->addItem(icon, tr("Rectangle"));

  symb.setStyle(QwtSymbol::Diamond);
  icon.fill(c);
  symb.draw(&p, r);
  this->addItem(icon, tr("Diamond"));

  symb.setStyle(QwtSymbol::Triangle);
  icon.fill(c);
  symb.draw(&p, r);
  this->addItem(icon, tr("Triangle"));

  symb.setStyle(QwtSymbol::DTriangle);
  icon.fill(c);
  symb.draw(&p, r);
  this->addItem(icon, tr("Down Triangle"));

  symb.setStyle(QwtSymbol::UTriangle);
  icon.fill(c);
  symb.draw(&p, r);
  this->addItem(icon, tr("Up Triangle"));

  symb.setStyle(QwtSymbol::LTriangle);
  icon.fill(c);
  symb.draw(&p, r);
  this->addItem(icon, tr("Left Triangle"));

  symb.setStyle(QwtSymbol::RTriangle);
  icon.fill(c);
  symb.draw(&p, r);
  this->addItem(icon, tr("Right Triangle"));

  symb.setStyle(QwtSymbol::Cross);
  icon.fill(c);
  symb.draw(&p, r);
  this->addItem(icon, tr("Cross"));

  symb.setStyle(QwtSymbol::XCross);
  icon.fill(c);
  symb.draw(&p, r);
  this->addItem(icon, tr("Diagonal Cross"));

  symb.setStyle(QwtSymbol::HLine);
  icon.fill(c);
  symb.draw(&p, r);
  this->addItem(icon, tr("Horizontal Line"));

  symb.setStyle(QwtSymbol::VLine);
  p.eraseRect(r);
  symb.draw(&p, r);
  this->addItem(icon, tr("Vertical Line"));

  symb.setStyle(QwtSymbol::Star1);
  icon.fill(c);
  symb.draw(&p, r);
  this->addItem(icon, tr("Star 1"));

  symb.setStyle(QwtSymbol::Star2);
  icon.fill(c);
  symb.draw(&p, r);
  this->addItem(icon, tr("Star 2"));

  symb.setStyle(QwtSymbol::Hexagon);
  icon.fill(c);
  symb.draw(&p, r);
  this->addItem(icon, tr("Hexagon"));

  p.end();
}
Example #14
0
 QRect growRectFromRadius(const QRect &rc, int radius)
 {
     int halfSize = KisGaussianKernel::kernelSizeFromRadius(radius) / 2;
     return rc.adjusted(-halfSize, -halfSize, halfSize, halfSize);
 }
Example #15
0
void SliderCustom::paintEvent(QPaintEvent *event)
{
	QPainter painter(this);

	//滑动块半径
	const int ellipseR = 5;		

	//绘制底色框
	const int offsetY = size().height() / 2 - 2;
	QRect rect = this->rect();
	QRect sliderRect = rect.adjusted(ellipseR, offsetY, -ellipseR, -offsetY);
	painter.fillRect(sliderRect, Qt::gray);

	//滑块数据
	const  double k = ((double)(value() - minimum())) / (maximum() - minimum());
	int xEllipse = (int)(sliderRect.width() * k) + ellipseR;
	//避免滑块绘制超出边界
	if (xEllipse + ellipseR > rect.width())
	{
		xEllipse -= 1;
	}


	//音量弹簧
	int scaledMag = int(( double)sliderRect.width() * mag + ellipseR);
	int scaledPeak = int(( double)sliderRect.width() * peak + ellipseR);
	//确保scaledMag、scaledPeak不超过滑块的点位
	scaledMag = scaledMag > xEllipse - ellipseR ? xEllipse - ellipseR : scaledMag;
	scaledPeak = scaledPeak > xEllipse - ellipseR ? xEllipse - ellipseR : scaledPeak;

	scaledMag = scaledMag < ellipseR ? ellipseR : scaledMag;
	scaledPeak = scaledPeak < ellipseR ? ellipseR : scaledPeak;

	QLinearGradient gradient;
	gradient.setStart(qreal(scaledMag), 0);
	gradient.setFinalStop(qreal(scaledPeak), 0);
	gradient.setColorAt(0, magColor);
	gradient.setColorAt(1, peakColor);

	// RMS
	painter.fillRect(sliderRect.x(), sliderRect.y(),
		scaledMag, sliderRect.height(),
		magColor);

	// RMS - Peak gradient
	painter.fillRect(scaledMag, sliderRect.y(),
		scaledPeak - scaledMag + 1, sliderRect.height(),
		QBrush(gradient));

	// Background
	painter.fillRect(scaledPeak, sliderRect.y(),
		sliderRect.width() - scaledPeak, sliderRect.height(),
		Qt::gray);

	//最后抗锯齿绘制滑块,抗锯齿会影响性能
	painter.setRenderHint(QPainter::Antialiasing, true);
	QPoint tickCenter(xEllipse, size().height() / 2);
	const QBrush oldBrush = painter.brush();
	const QPen oldPen = painter.pen();
	painter.setBrush(Qt::lightGray);
	painter.setPen(Qt::lightGray);
	painter.drawEllipse(tickCenter, ellipseR, ellipseR);
	painter.setBrush(oldBrush);
	painter.setPen(oldPen);
	painter.setRenderHint(QPainter::Antialiasing, false);
}
void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
                                        QPainter *painter, const QWidget *widget) const
{
    if (!panelWidget(widget))
         return     QProxyStyle::drawComplexControl(control, option, painter, widget);

    QRect rect = option->rect;
    switch (control) {
    case CC_ToolButton:
        if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
            bool reverse = option->direction == Qt::RightToLeft;
            bool drawborder = (widget && widget->property("showborder").toBool());

            if (drawborder)
                drawButtonSeparator(painter, rect, reverse);

            QRect button, menuarea;
            button = subControlRect(control, toolbutton, SC_ToolButton, widget);
            menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);

            State bflags = toolbutton->state;
            if (bflags & State_AutoRaise) {
                if (!(bflags & State_MouseOver))
                    bflags &= ~State_Raised;
            }

            State mflags = bflags;
            if (toolbutton->state & State_Sunken) {
                if (toolbutton->activeSubControls & SC_ToolButton)
                    bflags |= State_Sunken;
                if (toolbutton->activeSubControls & SC_ToolButtonMenu)
                    mflags |= State_Sunken;
            }

            QStyleOption tool(0);
            tool.palette = toolbutton->palette;
            if (toolbutton->subControls & SC_ToolButton) {
                tool.rect = button;
                tool.state = bflags;
                drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
            }

            QStyleOptionToolButton label = *toolbutton;

            label.palette = panelPalette(option->palette, lightColored(widget));
            if (widget && widget->property("highlightWidget").toBool())
                label.palette.setColor(QPalette::ButtonText, Qt::red);
            int fw = pixelMetric(PM_DefaultFrameWidth, option, widget);
            label.rect = button.adjusted(fw, fw, -fw, -fw);

            drawControl(CE_ToolButtonLabel, &label, painter, widget);

            if (toolbutton->subControls & SC_ToolButtonMenu) {
                tool.state = mflags;
                tool.rect = menuarea.adjusted(1, 1, -1, -1);
                if (mflags & (State_Sunken | State_On | State_Raised)) {
                    painter->setPen(Qt::gray);
                    painter->drawLine(tool.rect.topLeft(), tool.rect.bottomLeft());
                    if (mflags & (State_Sunken)) {
                        QColor shade(0, 0, 0, 50);
                        painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade);
                    } else if (!HostOsInfo::isMacHost() && (mflags & State_MouseOver)) {
                        QColor shade(255, 255, 255, 50);
                        painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade);
                    }
                }
                tool.rect = tool.rect.adjusted(2, 2, -2, -2);
                drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
            } else if (toolbutton->features & QStyleOptionToolButton::HasMenu
                       && widget && !widget->property("noArrow").toBool()) {
                int arrowSize = 6;
                QRect ir = toolbutton->rect.adjusted(1, 1, -1, -1);
                QStyleOptionToolButton newBtn = *toolbutton;
                newBtn.palette = panelPalette(option->palette);
                newBtn.rect = QRect(ir.right() - arrowSize - 1,
                                    ir.height() - arrowSize - 2, arrowSize, arrowSize);
                drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
            }
        }
        break;

    case CC_ComboBox:
        if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
            painter->save();
            bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull();
            bool reverse = option->direction == Qt::RightToLeft;
            bool drawborder = !(widget && widget->property("hideborder").toBool());
            bool drawleftborder = (widget && widget->property("drawleftborder").toBool());
            bool alignarrow = !(widget && widget->property("alignarrow").toBool());

            if (drawborder) {
                drawButtonSeparator(painter, rect, reverse);
                if (drawleftborder)
                    drawButtonSeparator(painter, rect.adjusted(0, 0, -rect.width() + 2, 0), reverse);
            }

            QStyleOption toolbutton = *option;
            if (isEmpty)
                toolbutton.state &= ~(State_Enabled | State_Sunken);
            painter->save();
            if (drawborder) {
                int leftClipAdjust = 0;
                if (drawleftborder)
                    leftClipAdjust = 2;
                painter->setClipRect(toolbutton.rect.adjusted(leftClipAdjust, 0, -2, 0));
            }
            drawPrimitive(PE_PanelButtonTool, &toolbutton, painter, widget);
            painter->restore();
            // Draw arrow
            int menuButtonWidth = 12;
            int left = !reverse ? rect.right() - menuButtonWidth : rect.left();
            int right = !reverse ? rect.right() : rect.left() + menuButtonWidth;
            QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), rect.center().y() - 3, 9, 9);

            if (!alignarrow) {
                int labelwidth = option->fontMetrics.width(cb->currentText);
                if (reverse)
                    arrowRect.moveLeft(qMax(rect.width() - labelwidth - menuButtonWidth - 2, 4));
                else
                    arrowRect.moveLeft(qMin(labelwidth + menuButtonWidth - 2, rect.width() - menuButtonWidth - 4));
            }
            if (option->state & State_On)
                arrowRect.translate(QProxyStyle::pixelMetric(PM_ButtonShiftHorizontal, option, widget),
                                    QProxyStyle::pixelMetric(PM_ButtonShiftVertical, option, widget));

            QStyleOption arrowOpt = *option;
            arrowOpt.rect = arrowRect;
            if (isEmpty)
                arrowOpt.state &= ~(State_Enabled | State_Sunken);

            if (styleHint(SH_ComboBox_Popup, option, widget)) {
                arrowOpt.rect.translate(0, -3);
                drawPrimitive(PE_IndicatorArrowUp, &arrowOpt, painter, widget);
                arrowOpt.rect.translate(0, 6);
                drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget);
            } else {
                drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget);
            }

            painter->restore();
        }
        break;

    default:
        QProxyStyle::drawComplexControl(control, option, painter, widget);
        break;
    }
}
Example #17
0
void
Style::drawComboBox(const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const
{
    ASSURE_OPTION(cmb, ComboBox);
    B_STATES
    if ( widget && widget->inherits("WebView") )
    {
        if (!(config.btn.backLightHover || cmb->editable))
        {   // paints hardcoded black text bypassing the style?! grrr...
            QStyleOptionComboBox *_cmb = const_cast<QStyleOptionComboBox*>(cmb);
            _cmb->palette.setColor(config.btn.std_role[Bg], QColor(230,230,230,255));
            _cmb->palette.setColor(config.btn.active_role[Bg], QColor(255,255,255,255));
        }
        widget = 0;
    }

    const int f1 = F(1), f2 = F(2);
    QRect ar;
    const QComboBox *combo = widget ? qobject_cast<const QComboBox*>(widget) : 0;
    QColor c = CONF_COLOR(btn.std, Bg);

    const bool listShown = combo && combo->view() && ((QWidget*)(combo->view()))->isVisible();
    if (listShown) // this messes up hover
        hover = hover || QRect(widget->mapToGlobal(RECT.topLeft()), RECT.size()).contains(QCursor::pos());

    if (isEnabled && (cmb->subControls & SC_ComboBoxArrow) && (!combo || combo->count() > 0))
    {   // do we have an arrow?
        ar = subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget);
        ar.setBottom(ar.bottom()-f2);
    }

    // the frame
    if ((cmb->subControls & SC_ComboBoxFrame) && cmb->frame)
    {
        if (cmb->editable)
            drawLineEdit(option, painter, widget, false);
        else
        {
            if (!ar.isNull())
            {
                animStep = (appType == GTK || !widget) ? 6*hover : Animator::Hover::step(widget);
                if (listShown)
                    animStep = 6;

                int btn_layer = config.btn.layer;
                Gradients::Type btn_grd = config.btn.gradient;
                config.btn.round = !config.btn.round;

                const bool comboNotSmallerThanTool = config.chooser.layer == Raised || config.chooser.layer == Inlay ||
                                                     config.btn.tool.frame == Sunken || config.btn.tool.frame == Relief;
                if (comboNotSmallerThanTool && widget && qobject_cast<QToolBar*>(widget->parentWidget()))
                {
                    GRAD(btn) = GRAD(btn.tool);
                    config.btn.layer = config.btn.tool.frame;
                }
                else
                {
                    GRAD(btn) = GRAD(chooser);
                    config.btn.layer = config.chooser.layer;
                }

                drawButtonFrame(option, painter, widget, animStep);

                config.btn.round = !config.btn.round;
                config.btn.layer = btn_layer;
                config.btn.gradient = btn_grd;
            }
            else
                shadows.sunken[!config.btn.round][isEnabled].render(RECT, painter);
        }
    }

    // the arrow
    if (!ar.isNull())
    {
        if (!(ar.width()%2) )
            ar.setWidth(ar.width()-1);
        const int dy = ar.height()/4;
        QRect rect = ar.adjusted(0, dy, 0, -dy);

        Navi::Direction dir = Navi::S;
        bool upDown = false;
        if (listShown)
            dir = (config.leftHanded) ? Navi::E : Navi::W;
        else if (combo)
        {
            if (combo->currentIndex() == 0)
                dir = Navi::S;
            else if (combo->currentIndex() == combo->count()-1)
                dir = Navi::N;
            else
                upDown = true;
        }

        painter->save();
        painter->setPen(Qt::NoPen);
        if (cmb->editable)
        {
            if (upDown || dir == Navi::N)
                dir = Navi::S;
            upDown = false; // shall never look like spinbox!
            hover = hover && (cmb->activeSubControls == SC_ComboBoxArrow);
            if (!sunken)
            {
                painter->setBrush(FCOLOR(Base).dark(105));
                rect.translate(0, f2);
                drawArrow(dir, rect, painter);
                rect.translate(0, -f2);
            }
            if (hover || listShown)
                painter->setBrush(FCOLOR(Highlight));
            else
                painter->setBrush( Colors::mid(FCOLOR(Base), FCOLOR(Text)) );
        }
        else if (config.btn.backLightHover)
            painter->setBrush(Colors::mid(c, CONF_COLOR(btn.std, Fg), 6-animStep, 3+animStep));
        else
        {
            c = Colors::mid(c, CONF_COLOR(btn.active, Bg));
            c = Colors::mid(c, CONF_COLOR(btn.active, Bg), 6-animStep, animStep);
            masks.rect[!config.btn.round].render(ar, painter, GRAD(chooser), ori[1], c, RECT.height()-f2, QPoint(0, ar.y() - RECT.y()) );
            painter->setBrush(Colors::mid(c, CONF_COLOR(btn.active, Fg), 1,2));
        }
        if (upDown)
        {
            rect.setBottom(rect.y() + rect.height()/2);
            rect.translate(0, -1);
            drawArrow(Navi::N, rect, painter);
            rect.translate(0, rect.height());
            drawArrow(Navi::S, rect, painter);
        }
        else
        {
            if (dir == Navi::N) // loooks unbalanced otherwise
                rect.translate(0, -f1);
            drawArrow(dir, rect, painter);
        }
        painter->restore();
    }
}
Example #18
0
void AreaDialog::paintEvent(QPaintEvent* e)
{
  Q_UNUSED(e);

  if (mGrabbing) // grabWindow() should just get the background
    return;

  QPainter painter(this);

  QPalette pal = palette();
  QFont font   = QToolTip::font();

  QColor handleColor(85, 160, 188, 220);
  QColor overlayColor(0, 0, 0, mOverlayAlpha);
  QColor textColor = pal.color(QPalette::Active, QPalette::Text);
  QColor textBackgroundColor = pal.color(QPalette::Active, QPalette::Base);
  painter.drawPixmap(0, 0, mScreenshot->pixmap());
  painter.setFont(font);

  QRect r = mSelection.normalized().adjusted(0, 0, -1, -1);

  QRegion grey(rect());
  grey = grey.subtracted(r);
  painter.setPen(handleColor);
  painter.setBrush(overlayColor);
  painter.setClipRegion(grey);
  painter.drawRect(-1, -1, rect().width() + 1, rect().height() + 1);
  painter.setClipRect(rect());
  painter.setBrush(Qt::NoBrush);
  painter.drawRect(r);

  if (mShowHelp) {
    //Drawing the explanatory text.
    QRect helpRect = qApp->desktop()->screenGeometry(qApp->desktop()->primaryScreen());
    QString helpTxt = tr("Lightscreen area mode:\nUse your mouse to draw a rectangle to capture.\nPress any key or right click to exit.");

    helpRect.setHeight(qRound((float)(helpRect.height() / 10))); // We get a decently sized rect where the text should be drawn (centered)

    // We draw the white contrasting background for the text, using the same text and options to get the boundingRect that the text will have.
    painter.setPen(QPen(Qt::white));
    painter.setBrush(QBrush(QColor(255, 255, 255, 180), Qt::SolidPattern));
    QRectF bRect = painter.boundingRect(helpRect, Qt::AlignCenter, helpTxt);

    // These four calls provide padding for the rect
    bRect.setWidth(bRect.width() + 12);
    bRect.setHeight(bRect.height() + 10);
    bRect.setX(bRect.x() - 12);
    bRect.setY(bRect.y() - 10);

    painter.drawRoundedRect(bRect, 8, 8);

    // Draw the text:
    painter.setPen(QPen(Qt::black));
    painter.drawText(helpRect, Qt::AlignCenter, helpTxt);
  }

  if (!mSelection.isNull()) {
    // The grabbed region is everything which is covered by the drawn
    // rectangles (border included). This means that there is no 0px
    // selection, since a 0px wide rectangle will always be drawn as a line.
    QString txt = QString("%1x%2").arg(mSelection.width() == 0 ? 2 : mSelection.width())
        .arg(mSelection.height() == 0 ? 2 : mSelection.height());
    QRect textRect = painter.boundingRect(rect(), Qt::AlignLeft, txt);
    QRect boundingRect = textRect.adjusted(-4, 0, 0, 0);

    if (textRect.width() < r.width() - 2*mHandleSize &&
       textRect.height() < r.height() - 2*mHandleSize &&
       (r.width() > 100 && r.height() > 100)) // center, unsuitable for small selections
    {
      boundingRect.moveCenter(r.center());
      textRect.moveCenter(r.center());
    }
    else if (r.y() - 3 > textRect.height() &&
      r.x() + textRect.width() < rect().right()) // on top, left aligned
    {
      boundingRect.moveBottomLeft(QPoint(r.x(), r.y() - 3));
      textRect.moveBottomLeft(QPoint(r.x() + 2, r.y() - 3));
    }
    else if (r.x() - 3 > textRect.width()) // left, top aligned
    {
      boundingRect.moveTopRight(QPoint(r.x() - 3, r.y()));
      textRect.moveTopRight(QPoint(r.x() - 5, r.y()));
    }
    else if (r.bottom() + 3 + textRect.height() < rect().bottom() &&
      r.right() > textRect.width()) // at bottom, right aligned
    {
      boundingRect.moveTopRight(QPoint(r.right(), r.bottom() + 3));
      textRect.moveTopRight(QPoint(r.right() - 2, r.bottom() + 3));
    }
    else if (r.right() + textRect.width() + 3 < rect().width()) // right, bottom aligned
    {
      boundingRect.moveBottomLeft(QPoint(r.right() + 3, r.bottom()));
      textRect.moveBottomLeft(QPoint(r.right() + 5, r.bottom()));
    }
    // if the above didn't catch it, you are running on a very tiny screen...
    painter.setPen(textColor);
    painter.setBrush(textBackgroundColor);
    painter.drawRect(boundingRect);
    painter.drawText(textRect, txt);

    if ((r.height() > mHandleSize*2 && r.width() > mHandleSize*2)
      || !mMouseDown)
    {
      updateHandles();
      painter.setPen(handleColor);
      handleColor.setAlpha(80);
      painter.setBrush(handleColor);
      painter.drawRects(handleMask().rects());
    }
  }

  if (!mScreenshot->options().magnify)
    return;

  // Drawing the magnified version
  QPoint magStart, magEnd, drawPosition;
  QRect newRect;

  QRect pixmapRect = mScreenshot->pixmap().rect();

  if (mMouseMagnifier) {
    drawPosition = mMousePos - QPoint(100, 100);

    magStart = mMousePos - QPoint(50, 50);
    magEnd = mMousePos + QPoint(50, 50);

    newRect = QRect(magStart, magEnd);
  }
  else {
    // So pretty.. oh so pretty.
    if (mMouseOverHandle == &mTLHandle)
      magStart = mSelection.topLeft();
    else if (mMouseOverHandle == &mTRHandle)
      magStart = mSelection.topRight();
    else if (mMouseOverHandle == &mBLHandle)
      magStart = mSelection.bottomLeft();
    else if (mMouseOverHandle == &mBRHandle)
      magStart = mSelection.bottomRight();
    else if (mMouseOverHandle == &mLHandle)
      magStart = QPoint(mSelection.left(), mSelection.center().y());
    else if (mMouseOverHandle == &mTHandle)
      magStart = QPoint(mSelection.center().x(), mSelection.top());
    else if (mMouseOverHandle == &mRHandle)
      magStart = QPoint(mSelection.right(), mSelection.center().y());
    else if (mMouseOverHandle == &mBHandle)
      magStart =  QPoint(mSelection.center().x(), mSelection.bottom());
    else if (mMouseOverHandle == 0)
      magStart = mMousePos;

    magEnd = magStart;
    drawPosition = mSelection.bottomRight();

    magStart -= QPoint(50, 50);
    magEnd   += QPoint(50, 50);

    newRect = QRect(magStart, magEnd);

    if ((drawPosition.x()+newRect.width()*2) > pixmapRect.width())
      drawPosition.setX(drawPosition.x()-newRect.width()*2);

    if ((drawPosition.y()+newRect.height()*2) > pixmapRect.height())
      drawPosition.setY(drawPosition.y()-newRect.height()*2);

    if (drawPosition.y() == mSelection.bottomRight().y()-newRect.height()*2
     && drawPosition.x() == mSelection.bottomRight().x()-newRect.width()*2)
      painter.setOpacity(0.7);
  }

  if (!pixmapRect.contains(newRect, true) || drawPosition.x() <= 0 || drawPosition.y() <= 0)  {
    return;
  }

  QPixmap magnified = mScreenshot->pixmap().copy(newRect).scaled(QSize(newRect.width()*2, newRect.height()*2));

  QPainter magPainter(&magnified);
  magPainter.setPen(QPen(QBrush(QColor(35, 35, 35)), 2)); // Same border pen
  magPainter.drawRect(magnified.rect());

  if (!mMouseMagnifier) {
    magPainter.drawText(magnified.rect().center()-QPoint(4, -4), "+"); //Center minus the 4 pixels wide and across of the "+" -- TODO: Test alternative DPI settings.
  }

  painter.drawPixmap(drawPosition, magnified);
}
void
PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
    TrackModelItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
    Q_ASSERT( item );

    QStyleOptionViewItemV4 opt = option;
    prepareStyleOption( &opt, index, item );
    opt.text.clear();

    qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );

    if ( m_view->header()->visualIndex( index.column() ) > 0 )
        return;

    QPixmap pixmap, avatar;
    QString artist, track, upperText, lowerText;
    unsigned int duration = 0;

    if ( item->query()->results().count() )
    {
        artist = item->query()->results().first()->artist()->name();
        track = item->query()->results().first()->track();
        duration = item->query()->results().first()->duration();
    }
    else
    {
        artist = item->query()->artist();
        track = item->query()->track();
    }

    painter->save();
    {
        QRect r = opt.rect.adjusted( 3, 6, 0, -6 );

        // Paint Now Playing Speaker Icon
        if ( item->isPlaying() )
        {
            QPixmap nowPlayingIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker );
            QRect npr = r.adjusted( 3, r.height() / 2 - nowPlayingIcon.height() / 2, 18 - r.width(), -r.height() / 2 + nowPlayingIcon.height() / 2 );
            nowPlayingIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker, TomahawkUtils::Original, npr.size() );
            painter->drawPixmap( npr, nowPlayingIcon );
            r.adjust( 22, 0, 0, 0 );
        }

        QFont figureFont = opt.font;
        figureFont.setPixelSize( 18 );
        figureFont.setWeight( 99 );

        QFont boldFont = opt.font;
        boldFont.setPixelSize( 15 );
        boldFont.setWeight( 99 );

        QFont smallBoldFont = opt.font;
        smallBoldFont.setPixelSize( 12 );
        smallBoldFont.setWeight( 80 );

        QFont durationFont = opt.font;
        durationFont.setPixelSize( 12 );
        durationFont.setWeight( 80 );

        if ( index.row() == 0 )
        {
            figureFont.setPixelSize( 36 );
            boldFont.setPixelSize( 26 );
            smallBoldFont.setPixelSize( 22 );
        }
        else if ( index.row() == 1 )
        {
            figureFont.setPixelSize( 30 );
            boldFont.setPixelSize( 22 );
            smallBoldFont.setPixelSize( 18 );
        }
        else if ( index.row() == 2 )
        {
            figureFont.setPixelSize( 24 );
            boldFont.setPixelSize( 18 );
            smallBoldFont.setPixelSize( 14 );
        }
        else if ( index.row() >= 10 )
        {
            boldFont.setPixelSize( 12 );
            smallBoldFont.setPixelSize( 11 );
        }

        QRect figureRect = r.adjusted( 0, 0, -option.rect.width() + 60 - 6 + r.left(), 0 );
        painter->setFont( figureFont );
        painter->setPen( option.palette.text().color().lighter( 450 ) );
        painter->drawText( figureRect, QString::number( index.row() + 1 ), m_centerOption );
        painter->setPen( opt.palette.text().color() );

        QRect pixmapRect = r.adjusted( figureRect.width() + 6, 0, -option.rect.width() + figureRect.width() + option.rect.height() - 6 + r.left(), 0 );
        pixmap = item->query()->cover( pixmapRect.size(), false );
        if ( !pixmap )
        {
            pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultTrackImage, TomahawkUtils::ScaledCover, pixmapRect.size() );
        }
        painter->drawPixmap( pixmapRect, pixmap );
        
        r.adjust( pixmapRect.width() + figureRect.width() + 18, 1, -28, 0 );
        QRect leftRect = r.adjusted( 0, 0, -48, 0 );
        QRect rightRect = r.adjusted( r.width() - 40, 0, 0, 0 );

        painter->setFont( boldFont );
        QString text = painter->fontMetrics().elidedText( artist, Qt::ElideRight, leftRect.width() );
        painter->drawText( leftRect, text, m_topOption );

        painter->setFont( smallBoldFont );
        text = painter->fontMetrics().elidedText( track, Qt::ElideRight, leftRect.width() );
        painter->drawText( index.row() >= 10 ? leftRect : leftRect.adjusted( 0, painter->fontMetrics().height() + 6, 0, 0 ), text, index.row() >= 10 ? m_bottomOption : m_topOption );

        if ( duration > 0 )
        {
            painter->setFont( durationFont );
            text = painter->fontMetrics().elidedText( TomahawkUtils::timeToString( duration ), Qt::ElideRight, rightRect.width() );
            painter->drawText( rightRect, text, m_centerRightOption );
        }
    }
    painter->restore();
}
Example #20
0
void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
{
    if (!validIndex(tabIndex)) {
        qWarning("invalid index");
        return;
    }
    painter->save();

    QRect rect = tabRect(tabIndex);
    bool selected = (tabIndex == m_currentIndex);
    bool enabled = isTabEnabled(tabIndex);

    if (selected) {
        //background
        painter->save();
        QLinearGradient grad(rect.topLeft(), rect.topRight());
        grad.setColorAt(0, QColor(255, 255, 255, 140));
        grad.setColorAt(1, QColor(255, 255, 255, 210));
//        grad.setColorAt(0, QColor(0, 0, 255, 140));
//        grad.setColorAt(1, QColor(255, 255, 255, 210));
        painter->fillRect(rect.adjusted(0, 0, 0, -1), grad);
        painter->restore();

        //shadows
        painter->setPen(QColor(0, 0, 0, 110));
        painter->drawLine(rect.topLeft() + QPoint(1,-1), rect.topRight() - QPoint(0,1));
        painter->drawLine(rect.bottomLeft(), rect.bottomRight());
        painter->setPen(QColor(0, 0, 0, 40));
        painter->drawLine(rect.topLeft(), rect.bottomLeft());

        //highlights
        painter->setPen(QColor(255, 255, 255, 50));
        painter->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0,2));
        painter->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0,1));
        painter->setPen(QColor(255, 255, 255, 40));
        painter->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight());
        painter->drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1));
        painter->drawLine(rect.bottomLeft() + QPoint(0,-1), rect.bottomRight()-QPoint(0,1));
    }

    QString tabText(this->tabText(tabIndex));
    QRect tabTextRect(tabRect(tabIndex));
    QRect tabIconRect(tabTextRect);
    tabTextRect.translate(0, -2);
    QFont boldFont(painter->font());
    boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
    boldFont.setBold(true);
    painter->setFont(boldFont);
    painter->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110));
    int textFlags = Qt::AlignCenter | Qt::AlignBottom | Qt::TextWordWrap;
    if (enabled) {
        painter->drawText(tabTextRect, textFlags, tabText);
        painter->setPen(selected ? QColor(60, 60, 60) : Utils::StyleHelper::panelTextColor());
    } else {
        painter->setPen(selected ? Utils::StyleHelper::panelTextColor() : QColor(255, 255, 255, 120));
    }
#ifndef Q_WS_MAC
    if (!selected && enabled) {
        painter->save();
        int fader = int(m_tabs[tabIndex]->fader());
        QLinearGradient grad(rect.topLeft(), rect.topRight());
        grad.setColorAt(0, Qt::transparent);
        grad.setColorAt(0.5, QColor(255, 255, 255, fader));
        grad.setColorAt(1, Qt::transparent);
        painter->fillRect(rect, grad);
        painter->setPen(QPen(grad, 1.0));
        painter->drawLine(rect.topLeft(), rect.topRight());
        painter->drawLine(rect.bottomLeft(), rect.bottomRight());
        painter->restore();
    }
#endif

    if (!enabled)
        painter->setOpacity(0.7);

    int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height();
    tabIconRect.adjust(0, 4, 0, -textHeight);
    Utils::StyleHelper::drawIconWithShadow(tabIcon(tabIndex), tabIconRect, painter, enabled ? QIcon::Normal : QIcon::Disabled);

    painter->translate(0, -1);
    painter->drawText(tabTextRect, textFlags, tabText);
    painter->restore();
}
Example #21
0
inline static QRect toLayoutItemRect(QWidgetPrivate *priv, const QRect &rect)
{
    return rect.adjusted(-priv->leftLayoutItemMargin, -priv->topLayoutItemMargin,
                         priv->rightLayoutItemMargin, priv->bottomLayoutItemMargin);
}
Example #22
0
void WindowsModernStyle::drawControl( ControlElement element, const QStyleOption* option,
                                      QPainter* painter, const QWidget* widget ) const
{
    switch ( element ) {
    case CE_MenuBarEmptyArea:
        return;

    case CE_MenuBarItem:
        if ( option->state & QStyle::State_Sunken && option->state & QStyle::State_Enabled ) {
            painter->setPen( m_colorMenuBorder );
            QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() );
            gradient.setColorAt( 0.0, m_colorMenuTitleBegin );
            gradient.setColorAt( 1.0, m_colorMenuTitleEnd );
            painter->setBrush( gradient );
            painter->drawRect( option->rect.adjusted( 0, 0, -1, 0 ) );
        } else if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled ) {
            painter->setPen( m_colorItemBorder );
            QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() );
            gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
            gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
            painter->setBrush( gradient );
            painter->drawRect( option->rect.adjusted( 0, 0, -1, -1 ) );
        }
        if ( const QStyleOptionMenuItem* optionItem = qstyleoption_cast<const QStyleOptionMenuItem*>( option ) ) {
            int flags = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
            if ( !styleHint( SH_UnderlineShortcut, option, widget ) )
                flags |= Qt::TextHideMnemonic;
            if ( !optionItem->icon.isNull() ) {
                QPixmap pixmap = optionItem->icon.pixmap( pixelMetric( PM_SmallIconSize, option, widget ), QIcon::Normal );
                drawItemPixmap( painter, option->rect, flags, pixmap );
            } else {
                drawItemText( painter, option->rect, flags, option->palette, true, optionItem->text, QPalette::Text );
            }
        }
        return;

    case CE_MenuEmptyArea:
        painter->fillRect( option->rect, m_colorMenuBackground );
        return;

    case CE_MenuItem: {
        if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled ) {
            painter->setPen( m_colorItemBorder );
            painter->setBrush( m_colorItemBackgroundBegin );
            painter->drawRect( option->rect.adjusted( 1, 0, -3, -1 ) );
        } else {
            QLinearGradient gradient( QPoint( 0, 0 ), QPoint( 25, 0 ) );
            gradient.setColorAt( 0.0, m_colorBarBegin );
            gradient.setColorAt( 1.0, m_colorBarEnd );
            QRect margin = option->rect;
            margin.setWidth( 25 );
            painter->fillRect( margin, gradient );
            QRect background = option->rect;
            background.setLeft( margin.right() + 1 );
            painter->fillRect( background, m_colorMenuBackground );
        }
        if ( const QStyleOptionMenuItem* optionItem = qstyleoption_cast<const QStyleOptionMenuItem*>( option ) ) {
            if ( optionItem->menuItemType == QStyleOptionMenuItem::Separator ) {
                painter->setPen( m_colorSeparator );
                painter->drawLine( option->rect.left() + 32, ( option->rect.top() + option->rect.bottom() ) / 2,
                                   option->rect.right(), ( option->rect.top() + option->rect.bottom() ) / 2 );
                return;
            }
            QRect checkRect = option->rect.adjusted( 2, 1, -2, -2 );
            checkRect.setWidth( 20 );
            if ( optionItem->checked && option->state & QStyle::State_Enabled ) {
                painter->setPen( m_colorItemBorder );
                if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled )
                    painter->setBrush( m_colorItemSunkenBegin );
                else
                    painter->setBrush( m_colorItemCheckedBegin );
                painter->drawRect( checkRect );
            }
            if ( !optionItem->icon.isNull() ) {
                QIcon::Mode mode;
                if ( optionItem->state & State_Enabled )
                    mode = ( optionItem->state & State_Selected ) ? QIcon::Active : QIcon::Normal;
                else
                    mode = QIcon::Disabled;
                QIcon::State state = optionItem->checked ? QIcon::On : QIcon::Off;
                QPixmap pixmap = optionItem->icon.pixmap( pixelMetric( PM_SmallIconSize, option, widget ), mode, state );
                QRect rect = pixmap.rect();
                rect.moveCenter( checkRect.center() );
                painter->drawPixmap( rect.topLeft(), pixmap );
            } else if ( optionItem->checked ) {
                QStyleOption optionCheckMark;
                optionCheckMark.initFrom( widget );
                optionCheckMark.rect = checkRect;
                if ( !( option->state & State_Enabled ) )
                    optionCheckMark.palette.setBrush( QPalette::Text, optionCheckMark.palette.brush( QPalette::Disabled, QPalette::Text ) );
                drawPrimitive( PE_IndicatorMenuCheckMark, &optionCheckMark, painter, widget );
            }
            QRect textRect = option->rect.adjusted( 32, 1, -16, -1 );
            int flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
            if ( !styleHint( SH_UnderlineShortcut, option, widget ) )
                flags |= Qt::TextHideMnemonic;
            QString text = optionItem->text;
            int pos = text.indexOf( '\t' );
            if ( pos >= 0 ) {
                drawItemText( painter, textRect, flags | Qt::AlignRight, option->palette, option->state & State_Enabled,
                              text.mid( pos + 1 ), QPalette::Text );
                text = text.left( pos );
            }
            drawItemText( painter, textRect, flags, option->palette, option->state & State_Enabled, text, QPalette::Text );
            if ( optionItem->menuItemType == QStyleOptionMenuItem::SubMenu ) {
                QStyleOption optionArrow;
                optionArrow.initFrom( widget );
                optionArrow.rect = option->rect.adjusted( 0, 4, -4, -4 );
                optionArrow.rect.setLeft( option->rect.right() - 12 );
                optionArrow.state = option->state & State_Enabled;
                drawPrimitive( PE_IndicatorArrowRight, &optionArrow, painter, widget );
            }
        }
        return;
    }

    case CE_ToolBar: {
        QRect rect = option->rect;
        bool vertical = false;
        if ( const QToolBar* toolBar = qobject_cast<const QToolBar*>( widget ) ) {
            vertical = ( toolBar->orientation() == Qt::Vertical );
            if ( vertical )
                rect.setBottom( toolBar->childrenRect().bottom() + 2 );
            else
                rect.setRight( toolBar->childrenRect().right() + 2 );
        }
        painter->save();
        QRegion region = rect.adjusted( 2, 0, -2, 0 );
        region += rect.adjusted( 0, 2, 0, -2 );
        region += rect.adjusted( 1, 1, -1, -1 );
        painter->setClipRegion( region );
        QLinearGradient gradient;
        if ( vertical )
            gradient = QLinearGradient( rect.topLeft(), rect.topRight() );
        else
            gradient = QLinearGradient( rect.topLeft(), rect.bottomLeft() );
        gradient.setColorAt( 0.0, m_colorBarBegin );
        gradient.setColorAt( 0.4, m_colorBarMiddle );
        gradient.setColorAt( 0.6, m_colorBarMiddle );
        gradient.setColorAt( 1.0, m_colorBarEnd );
        painter->fillRect( rect, gradient );

        painter->setPen( vertical ? m_colorBorderLight : m_colorBorder );
        painter->drawLine( rect.bottomLeft() + QPoint( 2, 0 ), rect.bottomRight() - QPoint( 2, 0 ) );
        painter->setPen( vertical ? m_colorBorder : m_colorBorderLight );
        painter->drawLine( rect.topRight() + QPoint( 0, 2 ), rect.bottomRight() - QPoint( 0, 2 ) );
        painter->setPen( m_colorBorderLight );
        painter->drawPoint( rect.bottomRight() - QPoint( 1, 1 ) );
        painter->restore();
        return;
    }

    case CE_DockWidgetTitle: {
        QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() );
        gradient.setColorAt( 0.0, m_colorBarBegin );
        gradient.setColorAt( 1.0, m_colorBarEnd );
        painter->fillRect( option->rect, gradient );
        if ( const QStyleOptionDockWidget* optionDockWidget = qstyleoption_cast<const QStyleOptionDockWidget*>( option ) ) {
            QRect rect = option->rect.adjusted( 6, 0, -4, 0 );
            if ( optionDockWidget->closable )
                rect.adjust( 0, 0, -16, 0 );
            if ( optionDockWidget->floatable )
                rect.adjust( 0, 0, -16, 0 );
            QString text = painter->fontMetrics().elidedText( optionDockWidget->title, Qt::ElideRight, rect.width() );
            drawItemText( painter, rect, Qt::AlignLeft | Qt::AlignVCenter, option->palette,
                          option->state & State_Enabled, text, QPalette::WindowText );
        }
        return;
    }

    case CE_TabBarTabShape:
        if ( isStyledTabBar( widget ) ) {
            bool firstTab = false;
            bool lastTab = false;
            bool bottom = false;
            if ( const QStyleOptionTab* optionTab = qstyleoption_cast<const QStyleOptionTab*>( option ) ) {
                if ( optionTab->position == QStyleOptionTab::Beginning )
                    firstTab = true;
                else if ( optionTab->position == QStyleOptionTab::End )
                    lastTab = true;
                else if ( optionTab->position == QStyleOptionTab::OnlyOneTab )
                    firstTab = lastTab = true;
                if ( optionTab->shape == QTabBar::RoundedSouth )
                    bottom = true;
            }
            QRect rect = option->rect;
            painter->save();
            if ( option->state & State_Selected ) {
                if ( bottom )
                    rect.adjust( firstTab ? 0 : -2, -1, lastTab ? -1 : 1, -1 );
                else
                    rect.adjust( firstTab ? 0 : -2, 0, lastTab ? -1 : 1, 1 );
            } else {
                if ( bottom ) {
                    rect.adjust( 0, -1, lastTab ? -1 : 0, -2 );
                    painter->setClipRect( rect.adjusted( 0, 1, 1, 1 ) );
                } else {
                    rect.adjust( 0, 1, lastTab ? -1 : 0, 0 );
                    painter->setClipRect( rect.adjusted( 0, 0, 1, 0 ) );
                }
            }
            QLinearGradient gradient;
            if ( bottom )
                gradient = QLinearGradient( rect.bottomLeft(), rect.topLeft() );
            else
                gradient = QLinearGradient( rect.topLeft(), rect.bottomLeft() );
            if ( option->state & State_Selected ) {
                gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
                gradient.setColorAt( 1.0, option->palette.window().color() );
                painter->setPen( m_colorBorder );
            } else if ( option->state & State_MouseOver && option->state & State_Enabled ) {
                gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
                gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
                painter->setPen( m_colorBorderLight );
            } else {
                gradient.setColorAt( 0.0, m_colorBarMiddle );
                gradient.setColorAt( 1.0, m_colorBarEnd );
                painter->setPen( m_colorBorderLight );
            }
            painter->setBrush( gradient );
            painter->drawRect( rect );
            painter->restore();
            return;
        }
        break;

    case CE_ToolBoxTabShape: {
        QRect rect = option->rect.adjusted( 0, 0, -1, -1 );
        QLinearGradient gradient( rect.topLeft(), rect.bottomLeft() );
        if ( option->state & QStyle::State_Sunken ) {
            gradient.setColorAt( 0.0, m_colorItemSunkenBegin );
            gradient.setColorAt( 1.0, m_colorItemSunkenEnd );
            painter->setPen( m_colorBorder );
        } else if ( option->state & State_MouseOver && option->state & State_Enabled ) {
            gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
            gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
            painter->setPen( m_colorBorder );
        } else {
            gradient.setColorAt( 0.0, m_colorBarMiddle );
            gradient.setColorAt( 1.0, m_colorBarEnd );
            painter->setPen( m_colorBorderLight );
        }
        painter->setBrush( gradient );
        painter->drawRect( rect );
        return;
    }

    case CE_Splitter:
        if ( qobject_cast<const QMainWindow*>( widget->window() ) )
            return;
        break;

    default:
        break;
    }

    if ( useVista() )
        QWindowsVistaStyle::drawControl( element, option, painter, widget );
    else
        QWindowsXPStyle::drawControl( element, option, painter, widget );
}
Example #23
0
void PrettyItemDelegate::paintDownloadInfo( QPainter* painter,
                                            const QStyleOptionViewItem& option,
                                            const QModelIndex& index ) const {

    // get the video metadata
    const DownloadItemPointer downloadItemPointer = index.data(DownloadItemRole).value<DownloadItemPointer>();
    const DownloadItem *downloadItem = downloadItemPointer.data();

    painter->save();

    const QRect line(0, 0, option.rect.width() / 2, option.rect.height());

    painter->translate(option.rect.topLeft());
    painter->translate(line.width(), 0);

    QString message;
    DownloadItemStatus status = downloadItem->status();

    if (status == Downloading) {
        QString downloaded = DownloadItem::formattedFilesize(downloadItem->bytesReceived());
        QString total = DownloadItem::formattedFilesize(downloadItem->bytesTotal());
        QString speed = DownloadItem::formattedSpeed(downloadItem->currentSpeed());
        QString eta = DownloadItem::formattedTime(downloadItem->remainingTime());

        message = tr("%1 of %2 (%3) — %4").arg(
                downloaded,
                total,
                speed,
                eta
                );
    } else if (status == Starting) {
        message = tr("Preparing");
    } else if (status == Failed) {
        message = tr("Failed") + " — " + downloadItem->errorMessage();
    } else if (status == Finished) {
        message = tr("Completed");
    } else if (status == Idle) {
        message = tr("Stopped");
    }

    // progressBar->setPalette(option.palette);
    if (status == Finished) {
        progressBar->setValue(100);
        progressBar->setEnabled(true);
    } else if (status == Downloading) {
        progressBar->setValue(downloadItem->currentPercent());
        progressBar->setEnabled(true);
    } else {
        progressBar->setValue(0);
        progressBar->setEnabled(false);
    }

    int progressBarWidth = line.width() - PADDING*4 - 16;
    progressBar->setMaximumWidth(progressBarWidth);
    progressBar->setMinimumWidth(progressBarWidth);
    painter->save();
    painter->translate(PADDING, PADDING);
    progressBar->render(painter);
    painter->restore();

    bool downloadButtonHovered = false;
    bool downloadButtonPressed = false;
    const bool isHovered = index.data(HoveredItemRole).toBool();
    if (isHovered) {
        downloadButtonHovered = index.data(DownloadButtonHoveredRole).toBool();
        downloadButtonPressed = index.data(DownloadButtonPressedRole).toBool();
    }
    QIcon::Mode iconMode;
    if (downloadButtonPressed) iconMode = QIcon::Selected;
    else if (downloadButtonHovered) iconMode = QIcon::Active;
    else iconMode = QIcon::Normal;

    if (status != Finished && status != Failed && status != Idle) {
        if (downloadButtonHovered) message = tr("Stop downloading");
        painter->save();
        QIcon closeIcon = QtIconLoader::icon("window-close");
        painter->drawPixmap(downloadButtonRect(line), closeIcon.pixmap(16, 16, iconMode));
        painter->restore();
    }

    else if (status == Finished) {
        if (downloadButtonHovered)
#ifdef APP_MAC
        message = tr("Show in %1").arg("Finder");
#else
        message = tr("Open parent folder");
#endif
        painter->save();
        QIcon searchIcon = QtIconLoader::icon("system-search");
        painter->drawPixmap(downloadButtonRect(line), searchIcon.pixmap(16, 16, iconMode));
        painter->restore();
    }

    else if (status == Failed || status == Idle) {
        if (downloadButtonHovered) message = tr("Restart downloading");
        painter->save();
        QIcon searchIcon = QtIconLoader::icon("view-refresh");
        painter->drawPixmap(downloadButtonRect(line), searchIcon.pixmap(16, 16, iconMode));
        painter->restore();
    }

    QRectF textBox = line.adjusted(PADDING, PADDING*2 + progressBar->sizeHint().height(), -2 * PADDING, -PADDING);
    textBox = painter->boundingRect( textBox, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, message);
    painter->drawText(textBox, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, message);

    painter->restore();

}
Example #24
0
void WindowsModernStyle::drawComplexControl( ComplexControl control, const QStyleOptionComplex* option,
        QPainter* painter, const QWidget* widget ) const
{
    switch ( control ) {
    case CC_ToolButton: {
        QToolBar* toolBar;
        if ( widget && ( toolBar = qobject_cast<QToolBar*>( widget->parentWidget() ) ) ) {
            if ( const QStyleOptionToolButton* optionToolButton = qstyleoption_cast<const QStyleOptionToolButton*>( option ) ) {
                QRect buttonRect = subControlRect( control, option, SC_ToolButton, widget );
                QStyle::State buttonState = option->state & ~State_Sunken;
                if ( option->state & State_Sunken ) {
                    if ( optionToolButton->activeSubControls & SC_ToolButton )
                        buttonState |= State_Sunken;
                    else if ( optionToolButton->activeSubControls & SC_ToolButtonMenu )
                        buttonState |= State_MouseOver;
                }
                bool selected = buttonState & State_MouseOver && option->state & State_Enabled;
                bool checked = buttonState & State_On;
                bool sunken = buttonState & State_Sunken;
                if ( selected || checked || sunken ) {
                    QRect rect = buttonRect.adjusted( 0, 0, -1, -1 );
                    painter->setPen( m_colorItemBorder );
                    QLinearGradient gradient;
                    if ( toolBar->orientation() == Qt::Vertical )
                        gradient = QLinearGradient( rect.topLeft(), rect.topRight() );
                    else
                        gradient = QLinearGradient( rect.topLeft(), rect.bottomLeft() );
                    if ( sunken || (selected && checked) ) {
                        gradient.setColorAt( 0.0, m_colorItemSunkenBegin );
                        gradient.setColorAt( 0.5, m_colorItemSunkenMiddle );
                        gradient.setColorAt( 1.0, m_colorItemSunkenEnd );
                    } else if ( checked ) {
                        gradient.setColorAt( 0.0, m_colorItemCheckedBegin );
                        gradient.setColorAt( 0.5, m_colorItemCheckedMiddle );
                        gradient.setColorAt( 1.0, m_colorItemCheckedEnd );
                    } else {
                        gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
                        gradient.setColorAt( 0.5, m_colorItemBackgroundMiddle );
                        gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
                    }
                    painter->setBrush( gradient );
                    painter->drawRect( rect );
                }
                QStyleOptionToolButton optionLabel = *optionToolButton;
                int fw = pixelMetric( PM_DefaultFrameWidth, option, widget );
                optionLabel.rect = buttonRect.adjusted( fw, fw, -fw, -fw );
                drawControl( CE_ToolButtonLabel, &optionLabel, painter, widget );
                if ( optionToolButton->subControls & SC_ToolButtonMenu ) {
                    QStyleOption optionMenu = *optionToolButton;
                    optionMenu.rect = subControlRect( control, option, SC_ToolButtonMenu, widget );
                    optionMenu.state = optionToolButton->state & ~State_Sunken;
                    if ( optionToolButton->state & State_Sunken ) {
                        if ( optionToolButton->activeSubControls & SC_ToolButton )
                            optionMenu.state |= State_MouseOver | State_Sunken;
                        else if ( optionToolButton->activeSubControls & SC_ToolButtonMenu )
                            optionMenu.state |= State_Sunken;
                    }
                    drawPrimitive( PE_IndicatorButtonDropDown, &optionMenu, painter, widget );
                } else if ( optionToolButton->features & QStyleOptionToolButton::HasMenu ) {
                    int size = pixelMetric( PM_MenuButtonIndicator, option, widget );
                    QRect rect = optionToolButton->rect;
                    QStyleOptionToolButton optionArrow = *optionToolButton;
                    optionArrow.rect = QRect( rect.right() + 4 - size, rect.height() - size + 4, size - 5, size - 5 );
                    drawPrimitive( PE_IndicatorArrowDown, &optionArrow, painter, widget );
                }
                return;
            }
        }
        break;
    }

    default:
        break;
    }

    if ( useVista() )
        QWindowsVistaStyle::drawComplexControl( control, option, painter, widget );
    else
        QWindowsXPStyle::drawComplexControl( control, option, painter, widget );
}
void WBWebTrapWebView::highliteElementAtPos ( const QPoint& pos)
{
    mCurrentContentType = Unknown;

    if(page() && page()->currentFrame())
    {
        QWebHitTestResult htr = page()->currentFrame()->hitTestContent (pos);
        QRect pageHtr = htr.boundingRect().translated(htr.frame()->pos());

        QRect updateRect = mWebViewElementRect.united(pageHtr);
        updateRect = updateRect.adjusted(-8, -8, 8, 8);

        mDomElementRect = htr.boundingRect();

        if (!htr.pixmap().isNull())
        {
            mCurrentContentType = Image;
            qDebug() << "found pixmap at " << htr.boundingRect();
        }
        else
        {
            QWebElement element = htr.element();
            QString tagName = element.tagName().toLower();

            if (tagName == "object"
                || tagName == "embed")
            {
                mCurrentContentType = ObjectOrEmbed;
            }
            else if ((tagName == "input") || (tagName == "textarea"))
            {
                QString ec = potentialEmbedCodeAtPos(pos);

                if (ec.length() > 0)
                {
                    qDebug() << "found input data \n\n" << ec;
                    mCurrentContentType = Input;
                }
            }
            else
            {
                QString tagName = htr.element().tagName();
                QString id =  htr.element().attribute("id", "");
                QWebElement el = htr.element();

                QString idSelector = tagName + "#" + id;
                bool idSuccess = (el == el.document().findFirst(idSelector));

                if (idSuccess)
                {
                    mElementQuery = idSelector;
                    mCurrentContentType = ElementByQuery;
                }
                else
                {
                    //bool isValid = true;

                    QWebElement elParent = el.parent();
                    QWebElement currentEl = el;
                    QString path = tagName;
                    QStringList pathElements;

                    do
                    {
                        QWebElement someSibling = elParent.firstChild();

                        int index = 0;
                        bool foundIndex = false;

                        do
                        {
                            if (someSibling.tagName() == currentEl.tagName())
                            {
                                if (someSibling == currentEl)
                                {
                                    foundIndex = true;
                                }
                                else
                                    index++;
                            }

                            someSibling = someSibling.nextSibling();
                        }
                        while(!someSibling.isNull() && !foundIndex);

                        QString part;

                        if (index > 0)
                            part = QString("%1:nth-child(%2)").arg(currentEl.tagName()).arg(index);
                        else
                            part = currentEl.tagName();

                        pathElements.insert(0, part);

                        currentEl = elParent;
                        elParent = elParent.parent();

                    } while(!elParent.isNull());

                    //QString idSelector = tagName + "#" + id;
                    QString treeSelector =  pathElements.join(" > ");

                    mElementQuery = treeSelector;
                    mCurrentContentType = ElementByQuery;

                    //bool treeSuccess = (el == el.document().findFirst(treeSelector));

                    //qDebug() << "----------------------------";
                    //qDebug() << idSuccess << idSelector;
                    //qDebug() << treeSuccess << treeSelector;
                }
            }
        }

        update(updateRect);
    }
}
Example #26
0
QRect SkinStyle::subControlRect(ComplexControl control, const QStyleOptionComplex * option,
                                SubControl subControl, const QWidget * widget) const {

    QRect rect = SystemStyle::subControlRect(control, option, subControl, widget);

    switch (control) {
    case CC_Slider:
        if (const QStyleOptionSlider * slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
            if (subControl == SC_SliderHandle) {
                int tickOffset = pixelMetric(PM_SliderTickmarkOffset, option, widget);
                int thickness = pixelMetric(PM_SliderControlThickness, option, widget);
                bool horizontal = slider->orientation == Qt::Horizontal;
                int len = pixelMetric(PM_SliderLength, option, widget) + 8;	//size of handle / 2
                int motifBorder = pixelMetric(PM_DefaultFrameWidth);
                int sliderPos = sliderPositionFromValue(slider->minimum, slider->maximum, slider->sliderPosition,
                                                        horizontal ? slider->rect.width() - len - 2 * motifBorder : slider->rect.height() - len - 2 * motifBorder,
                                                        slider->upsideDown);

                if (horizontal) {
                    rect = visualRect(slider->direction, slider->rect,
                                      QRect(sliderPos + motifBorder, tickOffset + motifBorder,
                                            len, thickness - 2 * motifBorder));
                } else {
                    rect = visualRect(slider->direction, slider->rect,
                                      QRect(tickOffset + motifBorder, sliderPos + motifBorder,
                                            thickness - 2 * motifBorder, len));
                }
            }
        }
        break;

    case CC_ScrollBar:
        if (const QStyleOptionSlider * scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
            QRect scrollBarRect = scrollbar->rect;

            int grooveMargin = pixelMetric(PM_ButtonDefaultIndicator, scrollbar, widget);

            int scrollBarExtent = pixelMetric(PM_ScrollBarExtent, scrollbar, widget);
            int sliderMaxLength = ((scrollbar->orientation == Qt::Horizontal) ?
                                   scrollbar->rect.width() + grooveMargin : scrollbar->rect.height()) - 2 * (_arrowUpWidth);

            int sliderLength = _scrollbarHandleHeight;
            int sliderStart = _arrowUpWidth + sliderPositionFromValue(scrollbar->minimum,
                              scrollbar->maximum, scrollbar->sliderPosition,
                              sliderMaxLength - sliderLength, scrollbar->upsideDown);

            switch (subControl) {
            case SC_ScrollBarSlider:	//Handle
                if (scrollbar->orientation == Qt::Horizontal) {
                    rect.setRect(sliderStart, 0, sliderLength, scrollBarExtent);
                } else {
                    rect.setRect(0, sliderStart, scrollBarExtent, sliderLength);
                }
                break;

            case SC_ScrollBarSubLine:	//Top/left button
                if (scrollbar->orientation == Qt::Horizontal) {
                    rect.setRect(scrollBarRect.left(), scrollBarRect.top(), _arrowUpWidth, scrollBarExtent);
                } else {
                    rect.setRect(scrollBarRect.left(), scrollBarRect.top(), scrollBarExtent, _arrowUpHeight);
                }
                break;

            case SC_ScrollBarAddLine:	//Bottom/right button
                if (scrollbar->orientation == Qt::Horizontal) {
                    rect.setRect(scrollBarRect.right() - _arrowUpWidth + grooveMargin, scrollBarRect.top(),
                                 _arrowUpWidth, _arrowUpHeight);
                } else {
                    rect.setRect(scrollBarRect.left(), scrollBarRect.bottom() - _arrowUpWidth + grooveMargin,
                                 _arrowUpWidth, _arrowUpHeight);
                }
                break;

            case SC_ScrollBarGroove:
                if (scrollbar->orientation == Qt::Horizontal) {
                    rect = scrollBarRect.adjusted(_arrowUpWidth, - 2 * grooveMargin, - _arrowUpWidth + grooveMargin, 0);
                } else {
                    rect = scrollBarRect.adjusted(-grooveMargin, _arrowUpWidth, 0, - _arrowUpWidth + grooveMargin);
                }
                break;

            default:
                break;
            }
            rect = visualRect(scrollbar->direction, scrollBarRect, rect);
        }
        break;

    default:
        break;
    }

    return rect;
}
Example #27
0
QRect PlasmaFrame::frameRect(const QRect & contentsRect) const
{
    return contentsRect.adjusted(-d->padL, -d->padT, d->padR, d->padB);
}
Example #28
0
void QItemDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &option,
                                const QRect &rect, const QString &text) const
{
    Q_D(const QItemDelegate);

    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->fillRect(rect, option.palette.brush(cg, QPalette::Highlight));
        painter->setPen(option.palette.color(cg, QPalette::HighlightedText));
    } else {
        painter->setPen(option.palette.color(cg, QPalette::Text));
    }

    if (text.isEmpty())
        return;

    if (option.state & QStyle::State_Editing) {
        painter->save();
        painter->setPen(option.palette.color(cg, QPalette::Text));
        painter->drawRect(rect.adjusted(0, 0, -1, -1));
        painter->restore();
    }

    const QStyleOptionViewItem opt = option;

    const QWidget *widget = d->widget(option);
    QStyle *style = widget ? widget->style() : QApplication::style();
    const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1;
    QRect textRect = rect.adjusted(textMargin, 0, -textMargin, 0); // remove width padding
    const bool wrapText = opt.features & QStyleOptionViewItem::WrapText;
    d->textOption.setWrapMode(wrapText ? QTextOption::WordWrap : QTextOption::ManualWrap);
    d->textOption.setTextDirection(option.direction);
    d->textOption.setAlignment(QStyle::visualAlignment(option.direction, option.displayAlignment));
    d->textLayout.setTextOption(d->textOption);
    d->textLayout.setFont(option.font);
    d->textLayout.setText(QItemDelegatePrivate::replaceNewLine(text));

    QSizeF textLayoutSize = d->doTextLayout(textRect.width());

    if (textRect.width() < textLayoutSize.width()
        || textRect.height() < textLayoutSize.height()) {
        QString elided;
        int start = 0;
        int end = text.indexOf(QChar::LineSeparator, start);
        if (end == -1) {
            elided += option.fontMetrics.elidedText(text, option.textElideMode, textRect.width());
        } else {
            while (end != -1) {
                elided += option.fontMetrics.elidedText(text.mid(start, end - start),
                                                        option.textElideMode, textRect.width());
                elided += QChar::LineSeparator;
                start = end + 1;
                end = text.indexOf(QChar::LineSeparator, start);
            }
            //let's add the last line (after the last QChar::LineSeparator)
            elided += option.fontMetrics.elidedText(text.mid(start),
                                                    option.textElideMode, textRect.width());
        }
        d->textLayout.setText(elided);
        textLayoutSize = d->doTextLayout(textRect.width());
    }

    const QSize layoutSize(textRect.width(), int(textLayoutSize.height()));
    const QRect layoutRect = QStyle::alignedRect(option.direction, option.displayAlignment,
                                                  layoutSize, textRect);
    // if we still overflow even after eliding the text, enable clipping
    if (!hasClipping() && (textRect.width() < textLayoutSize.width()
                           || textRect.height() < textLayoutSize.height())) {
        painter->save();
        painter->setClipRect(layoutRect);
        d->textLayout.draw(painter, layoutRect.topLeft(), QVector<QTextLayout::FormatRange>(), layoutRect);
        painter->restore();
    } else {
        d->textLayout.draw(painter, layoutRect.topLeft(), QVector<QTextLayout::FormatRange>(), layoutRect);
    }
}
Example #29
0
void
TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
    PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) );
    if ( !item )
        return;

    QTextOption textOption( Qt::AlignVCenter | (Qt::Alignment)index.data( Qt::TextAlignmentRole ).toUInt() );
    textOption.setWrapMode( QTextOption::NoWrap );

    QString text;
    if ( !item->artist().isNull() )
    {
        text = item->artist()->name();
    }
    else if ( !item->album().isNull() )
    {
        text = item->album()->name();
    }
    else if ( !item->result().isNull() || !item->query().isNull() )
    {
        float opacity = item->result().isNull() ? 0.0 : item->result()->score();
        opacity = qMax( (float)0.3, opacity );
        QColor textColor = TomahawkUtils::alphaBlend( option.palette.color( QPalette::Foreground ), option.palette.color( QPalette::Background ), opacity );

        {
            QStyleOptionViewItemV4 o = option;
            initStyleOption( &o, QModelIndex() );

            painter->save();
            o.palette.setColor( QPalette::Text, textColor );

            if ( o.state & QStyle::State_Selected && o.state & QStyle::State_Active )
            {
                o.palette.setColor( QPalette::Text, o.palette.color( QPalette::HighlightedText ) );
            }

            if ( item->isPlaying() )
            {
                o.palette.setColor( QPalette::Highlight, o.palette.color( QPalette::Mid ) );
                if ( o.state & QStyle::State_Selected )
                    o.palette.setColor( QPalette::Text, textColor );
                o.state |= QStyle::State_Selected;
            }

            int oldX = 0;
            if ( m_view->header()->visualIndex( index.column() ) == 0 )
            {
                oldX = o.rect.x();
                o.rect.setX( 0 );
            }
            qApp->style()->drawControl( QStyle::CE_ItemViewItem, &o, painter );
            if ( oldX > 0 )
                o.rect.setX( oldX );

            if ( m_view->hoveredIndex().row() == index.row() && m_view->hoveredIndex().column() == index.column() &&
               ( index.column() == 0 ) )
            {
                o.rect.setWidth( o.rect.width() - 16 );
                QRect arrowRect( o.rect.x() + o.rect.width(), o.rect.y() + 1, o.rect.height() - 2, o.rect.height() - 2 );

                QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, arrowRect.size() );
                painter->drawPixmap( arrowRect, infoIcon );
            }

            {
                QRect r = o.rect.adjusted( 3, 0, 0, 0 );

                // Paint Now Playing Speaker Icon
                if ( item->isPlaying() && m_view->header()->visualIndex( index.column() ) == 0 )
                {
                    r.adjust( 0, 0, 0, -3 );
                    QRect npr = r.adjusted( 3, 1, 18 - r.width(), 1 );
                    painter->drawPixmap( npr, TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker, TomahawkUtils::Original, npr.size() ) );
                    r.adjust( 25, 0, 0, 3 );
                }

                painter->setPen( o.palette.text().color() );

                QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 );
                painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, textOption );
            }
            painter->restore();
        }

        return;
    }
    else
        return;

    if ( text.trimmed().isEmpty() )
        text = tr( "Unknown" );

    QStyleOptionViewItemV4 opt = option;
    initStyleOption( &opt, QModelIndex() );
    qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );

    if ( option.state & QStyle::State_Selected )
    {
        opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) );
    }

    if ( index.column() > 0 )
        return;

    painter->save();
    painter->setRenderHint( QPainter::Antialiasing );
    painter->setPen( opt.palette.color( QPalette::Text ) );

    QRect r = option.rect.adjusted( 4, 4, -option.rect.width() + option.rect.height() - 4, -4 );
//    painter->drawPixmap( r, QPixmap( RESPATH "images/cover-shadow.png" ) );

    if ( !m_pixmaps.contains( index ) )
    {
        if ( !item->album().isNull() )
        {
            m_pixmaps.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->album(), r.size(), TomahawkUtils::ScaledCover, false ) ) );
            _detail::Closure* closure = NewClosure( m_pixmaps[ index ], SIGNAL( repaintRequest() ), const_cast<TreeItemDelegate*>(this), SLOT( doUpdateIndex( const QPersistentModelIndex& ) ), QPersistentModelIndex( index ) );
            closure->setAutoDelete( false );
        }
        else if ( !item->artist().isNull() )
Example #30
0
void
PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, bool useAvatars ) const
{
    PlayableItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
    Q_ASSERT( item );

    QStyleOptionViewItemV4 opt = option;
    prepareStyleOption( &opt, index, item );
    opt.text.clear();

    qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );

    if ( m_view->header()->visualIndex( index.column() ) > 0 )
        return;

    const query_ptr q = item->query()->displayQuery();
    QString artist = q->artist();
    QString track = q->track();
    QPixmap pixmap;
    QString upperText, lowerText;
    source_ptr source = item->query()->playedBy().first;

    if ( source.isNull() )
    {
        upperText = track;
        lowerText = artist;
    }
    else
    {
        upperText = QString( "%1 - %2" ).arg( artist ).arg( track );
        QString playtime = TomahawkUtils::ageToString( QDateTime::fromTime_t( item->query()->playedBy().second ), true );

        if ( source == SourceList::instance()->getLocal() )
            lowerText = QString( tr( "played %1 by you" ) ).arg( playtime );
        else
            lowerText = QString( tr( "played %1 by %2" ) ).arg( playtime ).arg( source->friendlyName() );
    }

    painter->save();
    {
        QRect r = opt.rect.adjusted( 3, 6, 0, -6 );

        // Paint Now Playing Speaker Icon
        if ( item->isPlaying() )
        {
            QPixmap nowPlayingIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker );
            QRect npr = r.adjusted( 3, r.height() / 2 - nowPlayingIcon.height() / 2, 18 - r.width(), -r.height() / 2 + nowPlayingIcon.height() / 2  );
            nowPlayingIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker, TomahawkUtils::Original, npr.size() );
            painter->drawPixmap( npr, nowPlayingIcon );
            r.adjust( 22, 0, 0, 0 );
        }

        painter->setPen( opt.palette.text().color() );

        QRect ir = r.adjusted( 4, 0, -option.rect.width() + option.rect.height() - 8 + r.left(), 0 );

        if ( useAvatars )
        {
            if ( !source.isNull() )
                pixmap = source->avatar( Source::FancyStyle, ir.size() );
        }
        else
            pixmap = item->query()->cover( ir.size(), false );

        if ( pixmap.isNull() )
        {
            if ( !useAvatars )
                pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultTrackImage, TomahawkUtils::ScaledCover, ir.size() );
            else
                pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultSourceAvatar, TomahawkUtils::AvatarInFrame, ir.size() );
        }

        painter->drawPixmap( ir, pixmap );

        QFont boldFont = opt.font;
        boldFont.setBold( true );

        r.adjust( ir.width() + 12, 0, -12, 0 );
        painter->setFont( boldFont );
        QString text = painter->fontMetrics().elidedText( upperText, Qt::ElideRight, r.width() );
        painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, m_topOption );

        painter->setFont( opt.font );
        painter->setPen( Qt::gray );
        text = painter->fontMetrics().elidedText( lowerText, Qt::ElideRight, r.width() );
        painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, m_bottomOption );
    }
    painter->restore();
}