void
Style::drawSliderHandle(const QRect &handle, const QStyleOption *option, QPainter *painter, int step) const
{
    OPT_SUNKEN OPT_ENABLED OPT_FOCUS
    bool fullHover = config.scroll.fullHover && !config.btn.backLightHover;

    // shadow
    QPoint xy = handle.topLeft();
    if (step && config.btn.backLightHover)
        fillWithMask(painter, xy, Colors::mid(FCOLOR(Window), CCOLOR(scroll._, Fg), 6-step, step), lights.slider);
    if (sunken)
        xy += QPoint(F(1), 0);
    painter->drawPixmap(xy, shadows.slider[isEnabled][sunken]);

    // gradient
    xy += QPoint(sunken ? F(1) : F(2), F(1));

    QColor bc = hasFocus ? FCOLOR(Highlight) : CCOLOR(scroll._, Bg);
    if (fullHover)
        bc = Colors::mid(bc, CCOLOR(scroll._, Fg), 6-step, step);

    const QPixmap &fill = Gradients::pix(bc, masks.slider.height(), Qt::Vertical, isEnabled ? GRAD(scroll) : Gradients::None);
    fillWithMask(painter, xy, fill, masks.slider);
    if (!fullHover && isEnabled)
    {
        const QColor fc = Colors::mid(bc, hasFocus ? FCOLOR(HighlightedText) : CCOLOR(scroll._, Fg), 6-step, step+3);
        const QSize d = (masks.slider.size() - masks.notch.size())/2;
        xy += QPoint(d.width(), d.height());
        fillWithMask(painter, xy, fc, masks.notch);
    }
}
示例#2
0
static void
drawSBArrow(QStyle::SubControl sc, QPainter *painter, QStyleOptionSpinBox *option, const QWidget *widget, const QStyle *style)
{
    if (!(option->subControls & sc))
        return;

    option->subControls = sc;
    RECT = style->subControlRect(QStyle::CC_SpinBox, option, sc, widget);
    Navi::Direction dir = Navi::N;
    QAbstractSpinBox::StepEnabledFlag sef = QAbstractSpinBox::StepUpEnabled;
    const int dy = RECT.height()/2;
    if (sc == QStyle::SC_SpinBoxUp) {
        RECT.adjust(F(2), dy + F(1), -F(2), dy - F(1));
    }
    else {
        dir = Navi::S; sef = QAbstractSpinBox::StepDownEnabled;
        RECT.adjust(F(2), F(1)-dy, -F(2), -(dy + F(1))) ;
    }

    bool isEnabled = option->stepEnabled & sef;
    bool hover = isEnabled && (option->activeSubControls == (int)sc);
//     bool sunken = hover && (option->state & QStyle::State_Sunken);

    QColor c;
    if (hover)
        c = FCOLOR(Highlight);
    else if (isEnabled)
        c = FX::blend(FCOLOR(Base), FCOLOR(Text));
    else
        c = FX::blend(FCOLOR(Base), FCOLOR(QPalette::Text),5,1);

    painter->setBrush(c);
    Style::drawArrow(dir, RECT, painter);

}
示例#3
0
void
Style::drawLineEdit(const QStyleOption *option, QPainter *painter, const QWidget *widget, bool round) const
{
    // spinboxes and combos allready have a lineedit as global frame
    // TODO: exclude Q3Combo??
    QWidget *daddy = widget ? widget->parentWidget() : 0L;
    if (qstyleoption_cast<const QStyleOptionFrame*>(option) && static_cast<const QStyleOptionFrame *>(option)->lineWidth < 1)
    {
        if (appType == KDM || (daddy && ( qobject_cast<QComboBox*>(daddy) || daddy->inherits("QAbstractSpinBox"))))
            return;
        painter->fillRect(RECT, FCOLOR(Base));
        return;
    }
    if (Hacks::config.invertDolphinUrlBar && daddy && daddy->inherits("KUrlNavigator"))
        return;

    OPT_ENABLED OPT_FOCUS

//       round = true;
    isEnabled = isEnabled && !(option->state & State_ReadOnly);
    QRect r = RECT;
    QRect RECT2 = QRect( 1, 0, r.width()-1, r.height() );

    if (isEnabled)
    {
        const Tile::Set &mask = masks.rect[round && appType != GTK];
        r.setBottom(r.bottom() - F(2));
        if (PAL.brush(QPalette::Base).style() > 1 ) // pixmap, gradient, whatever
            { QPixmap *buffer = bgBuffer(PAL, r); mask.render(r, painter, *buffer); delete buffer; }
        else if (r.height() > 2*option->fontMetrics.height()) // no lineEdit... like some input frames in QWebKit
        {
            const QColor &c = FCOLOR(Base);
            mask.render(r, painter, (hasFocus && Colors::value(c) < 100) ? c.lighter(112) : c);
        }
        else
            mask.render(r, painter, Gradients::Sunken, Qt::Vertical, FCOLOR(Base));
        if (hasFocus)
            lights.glow[round].render(RECT, painter, FCOLOR(Highlight));
    }
    if (appType == GTK)
        shadows.fallback.render(RECT,painter);
    else
        shadows.sunken[round][isEnabled].render(RECT2, painter);


    painter->setPen( QColor( 0, 0, 0, 100 ) ); // Black color
    painter->drawRoundedRect( 1, 1, r.width()-3, r.height()-2, 3, 3 );
    painter->setPen( QColor( 220, 220, 220, 255 ) ); // White color
    painter->drawRoundedRect( 0, 0, r.width()-1, r.height(), 3, 3 );
    

    
}
static void
drawSBArrow(QStyle::SubControl sc, QPainter *painter, QStyleOptionSpinBox *option,
            const QWidget *widget, const QStyle *style)
{
    if (option->subControls & sc)
    {
        const int f2 = F(2);

        option->subControls = sc;
        RECT = style->subControlRect(QStyle::CC_SpinBox, option, sc, widget);

        Navi::Direction dir = Navi::N;
        QAbstractSpinBox::StepEnabledFlag sef = QAbstractSpinBox::StepUpEnabled;
        if (sc == QStyle::SC_SpinBoxUp)
            RECT.setTop(RECT.bottom() - 2*RECT.height()/3);
        else
        {
            dir = Navi::S; sef = QAbstractSpinBox::StepDownEnabled;
            RECT.setBottom(RECT.top() + 2*RECT.height()/3);
        }

        bool isEnabled = option->stepEnabled & sef;
        bool hover = isEnabled && (option->activeSubControls == (int)sc);
        bool sunken = hover && (option->state & QStyle::State_Sunken);


        if (!sunken)
        {
            painter->setBrush(FCOLOR(Base).dark(108));
            RECT.translate(0, f2);
            Style::drawArrow(dir, RECT, painter);
            RECT.translate(0, -f2);
        }

        QColor c;
        if (hover)
            c = FCOLOR(Highlight);
        else if (isEnabled)
            c = Colors::mid(FCOLOR(Base), FCOLOR(Text));
        else
            c = Colors::mid(FCOLOR(Base), PAL.color(QPalette::Disabled, QPalette::Text));

        painter->setBrush(c);
        Style::drawArrow(dir, RECT, painter);
    }
}
示例#5
0
void
Style::drawGroupBoxFrame(const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
    const QStyleOptionFrameV2 *groupBox = qstyleoption_cast<const QStyleOptionFrameV2 *>(option);

    if (groupBox && groupBox->features == QStyleOptionFrameV2::Flat)
    {
        const QRect r = (option->direction == Qt::LeftToRight) ?
                        RECT.adjusted(RECT.width()/2,0,0,0) : RECT.adjusted(0,0,-RECT.width()/2,0);
        shadows.line[0][Sunken].render(r, painter, Tile::Full, true);
//         Tile::setShape(Tile::Bottom);
//         shadows.relief[true][false].render(RECT, painter);
//         Tile::reset();
        return;
    }
    if (config.groupBoxMode)
    {
        QRect rect = RECT.adjusted(F(4), F(2), -F(4), 0);
        rect.setHeight(qMin(2*F(32), RECT.height()));
        Tile::setShape(Tile::Full & ~Tile::Bottom);
        if ( config.groupBoxMode != 3 )
            masks.rect[false].render(rect, painter, Gradients::light(rect.height()) );
        rect.setBottom(RECT.bottom()-F(32));
        Tile::setShape(Tile::Full);
        shadows.group.render(RECT, painter);
        Tile::reset();
    }
    else
    {
#if BESPIN_ARGB_WINDOWS
        if (config.bg.opacity != 0xff)
            masks.rect[false].render( RECT.adjusted(0,0,0,-F(2)), painter, QColor(0,0,0,48) );
        else
#endif
            if (config.bg.mode == Scanlines && !(widget && widget->window() && widget->window()->testAttribute(Qt::WA_MacBrushedMetal)))
            masks.rect[false].render( RECT.adjusted(0,0,0,-F(2)), painter,
                                      Gradients::structure(FCOLOR(Window).darker(108)),
                                      widget ? widget->mapTo(widget->window(), RECT.topLeft()) : QPoint() );
        else
            masks.rect[false].render( RECT.adjusted(0,0,0,-F(2)), painter, FCOLOR(Window).darker(105));
        shadows.sunken[false][true].render(RECT, painter);
    }
}
示例#6
0
void
Style::drawSliderHandle(const QRect &handle, const QStyleOption *option, QPainter *painter, int step) const
{
    OPT_FOCUS
    SAVE_PAINTER(Pen|Brush|Alias);

    painter->setPen(Qt::NoPen);
    painter->setRenderHint(QPainter::Antialiasing, true);
    painter->setBrush(FCOLOR(Window));
    painter->drawEllipse(handle);
    const int dx = handle.width() / THERMOMETER_FACTOR;
    const int dy = handle.height() / THERMOMETER_FACTOR;
    const QColor t = hasFocus ? FCOLOR(Highlight) : FCOLOR(WindowText);
    QColor c = FX::blend(FCOLOR(Window), t,4,5);
    c = FX::blend(c, t, 6-step, step);
    painter->setBrush(c);
    painter->drawEllipse(handle.adjusted(dx,dy,-dx,-dy));
    RESTORE_PAINTER
}
示例#7
0
void
Style::drawHeaderSection(const QStyleOption *option, QPainter *painter, const QWidget*) const
{
    OPT_SUNKEN OPT_HOVER
    const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option);
    const bool sorting = header && (header->sortIndicator != QStyleOptionHeader::None);

    Qt::Orientation o = Qt::Vertical; int s = RECT.height();
    if (header && header->orientation == Qt::Vertical)
    {
        o = Qt::Horizontal;
        s = RECT.width();
    }

    QColor c =  sorting ? COLOR(config.view.sortingHeader_role[Bg]) : COLOR(config.view.header_role[Bg]);

    if (Colors::value(c) < 50)
        { int h,s,v,a; c.getHsv(&h, &s, &v, &a); c.setHsv(h, s, 50, a); }

    if (appType == GTK)
        sunken = option->state & State_HasFocus;
    if (sunken)
    {
        const QPixmap &sunk = Gradients::pix(c, s, o, Gradients::Sunken);
        painter->drawTiledPixmap(RECT, sunk);
        return;
    }

    const Gradients::Type gt = sorting ? config.view.sortingHeaderGradient : config.view.headerGradient;

    if (hover)
        c = Colors::mid(c, sorting ? CCOLOR(view.sortingHeader, Fg) : CCOLOR(view.header, Fg),8,1);

    if (gt == Gradients::None)
        painter->fillRect(RECT, c);
    else
        painter->drawTiledPixmap(RECT, Gradients::pix(c, s, o, gt));

    if (o == Qt::Vertical)
    {
        if (!header || header->section < QStyleOptionHeader::End)
        {
            QRect r = RECT; r.setLeft(r.right() - F(1));
            painter->drawTiledPixmap(r, Gradients::pix(CCOLOR(view.header, Bg), s, o, Gradients::Sunken));
        }
        if (Colors::value(CCOLOR(view.header, Bg)) > 90) // not on dark elements - looks just stupid...
        {
            SAVE_PEN
            painter->setPen(Colors::mid(FCOLOR(Base), Qt::black, 6, 1));
            painter->drawLine(RECT.bottomLeft(), RECT.bottomRight());
            RESTORE_PEN
        }
    }
示例#8
0
void
Style::drawFocusFrame(const QStyleOption *option, QPainter *painter, const QWidget *w) const
{
    if (option->state & State_Selected || option->state & State_MouseOver)
        return; // looks crap...
    if ( w && w->style() != this && w->inherits("QAbstractButton"))
        return; // from QtCssStyle...

    painter->save();
    painter->setBrush(Qt::NoBrush);
    painter->setPen(FCOLOR(Highlight));
    painter->drawLine(RECT.bottomLeft(), RECT.bottomRight());
    painter->restore();
}
void
Style::drawLineEditFrame(const QStyleOption *option, QPainter *painter, const QWidget *) const
{
    // WARNING this is NOT used to draw lineedits - just the frame, see below!!
    OPT_ENABLED OPT_FOCUS

    QRect r = RECT;
    if (appType != GTK)
    {
        r.setBottom(r.bottom() - F(2));
        shadows.sunken[false][isEnabled].render(r, painter);
    }
    else
        shadows.fallback.render(RECT,painter);

    if (hasFocus)
        lights.glow[false].render(RECT, painter, FCOLOR(Highlight));
}
示例#10
0
void
Style::drawLineEditFrame(const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
    if (RECT.height() > qMax(32, F(4) + 2*painter->fontMetrics().height())) { // abuse for mass text, eg. by webkit
        drawFrame(option, painter, widget);
        return;
    }
    OPT_ENABLED OPT_FOCUS
    SAVE_PAINTER(Pen|Alias);
    QRectF r(RECT);
    r.adjust(F(1), F(1), -F(1), -F(1));
    QRectF r2(r);
    r2.setWidth(r2.height());
    r2.moveRight(r.right());
    QPainterPath path;
    path.moveTo(r.x() + config.frame.roundness, r.bottom()); // + config.frame.roundness to match aligned fames
    path.lineTo(r2.bottomLeft());
    path.arcTo(r2, -90, 180);
    path.lineTo(r.x() + 2*r.width()/3, r.y());
    QColor c;
    bool goodBad = false;
    if (widget && widget->testAttribute(Qt::WA_SetPalette)) {
        int r,g,b;
        FCOLOR(Base).getRgb(&r,&g,&b);
        if (goodBad = (r > g+b && qAbs(g-b) < qMax(qMin(g,b)/10,1))) // that's red
            c = FX::blend(Qt::red, LEF_COLOR, 1, 16-15*hasFocus);
        else if (goodBad = (g > r+b && qAbs(r-b) < qMax(qMin(r,b)/10,1))) // that's green
            c = FX::blend(Qt::green, LEF_COLOR, 1, 16-15*hasFocus);
        if (goodBad)
            painter->setPen(QPen(c, F(2) & ~1));
    }
    if (!goodBad)
        painter->setPen(hasFocus ? FOCUS_FRAME_PEN : FRAME_PEN);
    painter->setRenderHint(QPainter::Antialiasing, true);
    painter->drawPath(path);
    RESTORE_PAINTER
}
示例#11
0
void
Style::drawLineEdit(const QStyleOption *option, QPainter *painter, const QWidget *widget, bool /*round*/) const
{
    // spinboxes and combos allready have a lineedit as global frame
    QWidget *daddy = widget ? widget->parentWidget() : 0L;
    if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame*>(option))
    if (frame->lineWidth < 1) {
        if (appType == KDM || (daddy && ( qobject_cast<QComboBox*>(daddy) || daddy->inherits("QAbstractSpinBox"))))
            return;
        painter->fillRect(RECT, FCOLOR(Base));
        return;
    }

//     OPT_FOCUS
//     if (hasFocus) {
//         SAVE_PAINTER(Pen|Alias|Brush);
//         painter->setPen(Qt::NoPen);
//         painter->setBrush(FX::blend(FCOLOR(Base), FCOLOR(Highlight), 30, 1));
//         painter->setRenderHint(QPainter::Antialiasing, true);
//         painter->drawRoundedRect(RECT, config.frame.roundness, config.frame.roundness);
//         RESTORE_PAINTER
//     }
    drawLineEditFrame(option, painter, widget);
}
示例#12
0
void
Style::drawFrame(const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
    OPT_SUNKEN OPT_ENABLED OPT_FOCUS
    bool raised = option->state & State_Raised;

#if QT_VERSION >= 0x040500
    // lines via CE_ShapedFrame instead the ugly eventfilter override
    if HAVE_OPTION(v3frame, FrameV3)
    {
        if (v3frame->frameShape == QFrame::NoFrame)
            return;
        const bool v = (v3frame->frameShape == QFrame::VLine);
        if (v || v3frame->frameShape == QFrame::HLine)
        {
            shadows.line[v][sunken?Sunken:raised?Raised:Relief].render(RECT, painter);
            return;
        }
        if ( v3frame->frameShape == QFrame::Box )
            sunken = raised = false;
    }
#endif
    // all other frame kinds look the same
    if (!widget || (appType == GTK))
    {   // fallback, we cannot paint shaped frame contents
        if (sunken)
            shadows.fallback.render(RECT,painter);
        else if (raised)
            shadows.fallback.render(RECT,painter);
            // TODO !
//          shadows.raised.render(RECT,painter);
        else
        {
            //horizontal
            shadows.line[false][Sunken].render(RECT, painter, Tile::Full, false);
            shadows.line[false][Sunken].render(RECT, painter, Tile::Full, true);
            //vertical
            shadows.line[true][Sunken].render(RECT, painter, Tile::Full, false);
            shadows.line[true][Sunken].render(RECT, painter, Tile::Full, true);
        }
        return;
    }

    const QColor *brush = 0;
    QRect rect = RECT;
    bool fastFrame = false;
    if (qobject_cast<const QFrame*>(widget))
    {   // frame, can be killed unless...
        fastFrame = isSpecialFrame(widget);
        if (fastFrame)
        {   // ...TextEdit, ...
            if (const QAbstractItemView *view = qobject_cast<const QAbstractItemView*>(widget))
            if (view->viewport())
                brush = &view->viewport()->palette().color(view->viewport()->backgroundRole());
            if (!brush)
                brush = &PAL.color(QPalette::Base);
        }
        else
        {   // usually painted on visual frame, but...
            if (config.menu.shadow && widget->inherits("QComboBoxPrivateContainer"))
            {   // a decent combobox dropdown frame...
                SAVE_PEN;
                painter->setPen(Colors::mid(FCOLOR(Base),FCOLOR(Text),4,1));
                painter->drawRect(RECT.adjusted(0,0,-1,-1));
                RESTORE_PEN;
            }
            return;
        }
    }

    if (sunken)
        rect.setBottom(rect.bottom() - F(2));
    else if (raised)
        rect.adjust(F(2), F(1), -F(2), -F(4));
    else
        rect.adjust(F(2), F(2), -F(2), -F(2));

    const Tile::Set *mask = &masks.rect[false], *shadow = 0L;
    if (sunken)
        shadow = &shadows.sunken[false][isEnabled];
    else if (raised)
        shadow = &shadows.group;

    if (brush)
    {
        QRegion rgn = painter->clipRegion();
        bool hadClip = painter->hasClipping();
        painter->setClipRegion(QRegion(RECT) - RECT.adjusted(F(4),F(4),-F(4),-F(4)));
        mask->render(rect, painter, *brush);
        if (hadClip)
            painter->setClipRegion(rgn);
        else
            painter->setClipping(false);
    }
    if (shadow)
        shadow->render(RECT, painter);
    else
    {   // plain frame
        //horizontal
        shadows.line[0][Sunken].render(RECT, painter, Tile::Full, false);
        shadows.line[0][Sunken].render(RECT, painter, Tile::Full, true);
        //vertical
        shadows.line[1][Sunken].render(RECT, painter, Tile::Full, false);
        shadows.line[1][Sunken].render(RECT, painter, Tile::Full, true);
    }
    if (hasFocus)
    {
        rect = RECT;
        if (!fastFrame)
        if (const VisualFramePart* vfp = qobject_cast<const VisualFramePart*>(widget))
        {   // Looks somehow dull if a views header get's surrounded by the focus, ...but it
            // still should inside the frame: don't dare!
            Tile::setShape(Tile::Ring);
            QWidget *vHeader = 0, *hHeader = 0;
            if (const QTreeView* tv = qobject_cast<const QTreeView*>(vfp->frame()))
                hHeader = (QWidget*)tv->header();
            else if (const QTableView* table = qobject_cast<const QTableView*>(vfp->frame()))
            {
                hHeader = (QWidget*)table->horizontalHeader();
                vHeader = (QWidget*)table->verticalHeader();
            }
            if (vHeader && vHeader->isVisible())
            {
                Tile::setShape(Tile::shape() & ~Tile::Left);
                rect.setLeft(rect.left() + vHeader->width());
            }
            if (hHeader && hHeader->isVisible())
            {
                Tile::setShape(Tile::shape() & ~Tile::Top);
                rect.setTop(rect.top() + hHeader->height());
            }
        }
        lights.glow[false].render(rect, painter, FCOLOR(Highlight));
        Tile::reset();
    }
}
void
Style::drawDial(const QStyleOptionComplex *option, QPainter *painter, const QWidget *) const
{
    ASSURE_OPTION(dial, Slider);

    OPT_ENABLED OPT_HOVER OPT_FOCUS

    painter->save();
    QRect rect = RECT;
    if (rect.width() > rect.height())
    {
        rect.setLeft(rect.x()+(rect.width()-rect.height())/2);
        rect.setWidth(rect.height());
    }
    else
    {
        rect.setTop(rect.y()+(rect.height()-rect.width())/2);
        rect.setHeight(rect.width());
    }

    int d = qMin(2*rect.width()/5, Dpi::target.SliderThickness);
    int r;
    // angle calculation from qcommonstyle.cpp (c) Trolltech 1992-2007, ASA.
    float a;
    if (dial->maximum == dial->minimum)
        a = M_PI / 2;
    else if (dial->dialWrapping)
        a = M_PI * 3 / 2 - (dial->sliderValue - dial->minimum) * 2 * M_PI /
                                                                (dial->maximum - dial->minimum);
    else
        a = (M_PI * 8 - (dial->sliderValue - dial->minimum) * 10 * M_PI /
                                                                (dial->maximum - dial->minimum)) / 6;

    QPoint cp = rect.center();

    // fallback for small dials ============================
    bool small(rect.width() < 8*Dpi::target.SliderThickness/3);
    if ( small )
    {
        painter->setRenderHint( QPainter::Antialiasing );
        painter->setPen(Qt::NoPen);
        painter->setBrush(QColor(0,0,0,50));
        painter->drawEllipse(rect);
        rect.adjust(F(2), F(1), -F(2), -F(2));
        painter->setBrushOrigin(rect.topLeft());
        const QPixmap &fill = Gradients::pix(FCOLOR(Window), rect.height(), Qt::Vertical, GRAD(scroll));
        painter->setBrush(fill);
        painter->drawEllipse(rect);
        QColor c = hasFocus ? FCOLOR(Highlight) : FCOLOR(WindowText);
        if (!hover)
            c = Colors::mid(FCOLOR(Window), c, 1, 1+isEnabled);
        d = qMax(F(3), d/4);
        r = (rect.width()-d)/2;
        cp += QPoint((int)(r * cos(a)), -(int)(r * sin(a)));
        painter->setPen(QPen(c, d, Qt::SolidLine, Qt::RoundCap));
        painter->drawPoint(cp);
    }

    // the value ==============================================
    QFont fnt = painter->font();
    int h = rect.height()/2;
    h -= 2 * (h - qMin(h, painter->fontMetrics().xHeight())) / 3;
    fnt.setPixelSize( h );
    painter->setFont(fnt);
    painter->setBrush(Qt::NoBrush);
    painter->setPen(Colors::mid(PAL.background().color(), PAL.foreground().color(),!hasFocus,2));
    drawItemText(painter, rect,  Qt::AlignCenter, PAL, isEnabled, QString::number(dial->sliderValue));

    if (small)
        { painter->restore(); return; }

    r = (rect.width()-d)/2;
    cp += QPoint((int)(r * cos(a)), -(int)(r * sin(a)));

    // the huge ring =======================================
    r = d/2; rect.adjust(r,r,-r,-r);
    painter->setPen(FCOLOR(Window).dark(115));
    painter->setRenderHint( QPainter::Antialiasing );
    painter->drawEllipse(rect);
    rect.translate(0, 1);
    painter->setPen(FCOLOR(Window).light(108));
    painter->drawEllipse(rect);

    // the drop ===========================
    rect = QRect(0,0,d,d);
    rect.moveCenter(cp);
    drawSliderHandle(rect, option, painter, hover * 6);

    painter->restore();
}
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();
    }
}
示例#15
0
void
Style::drawSlider(const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const
{
    ASSURE_OPTION(slider, Slider);
    SAVE_PAINTER(Pen|Brush|Alias);

    OPT_SUNKEN OPT_ENABLED OPT_HOVER OPT_FOCUS

    QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
    QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, widget);

    isEnabled = isEnabled && (slider->maximum > slider->minimum);
    hover = isEnabled && (appType == GTK || (hover && (slider->activeSubControls & SC_SliderHandle)));
    sunken = sunken && (slider->activeSubControls & SC_SliderHandle);

    int radius;

    // groove
    if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {

        painter->setPen(Qt::NoPen);
        painter->setRenderHint(QPainter::Antialiasing, true);

        // thermometer
        if (slider->minimum > -1 && slider->sliderPosition != slider->minimum) {
            painter->setBrush(THERMOMETER_COLOR);
            QRect thermometer = groove;
            if (slider->orientation == Qt::Horizontal)
                thermometer.adjust(0, thermometer.height()/THERMOMETER_FACTOR, 0, -thermometer.height()/THERMOMETER_FACTOR);
            else
                thermometer.adjust(thermometer.width()/THERMOMETER_FACTOR, 0, -thermometer.width()/THERMOMETER_FACTOR, 0);
            radius = qMin(thermometer.width(), thermometer.height())/2;
            const QPoint c = handle.center();
            if ( slider->orientation == Qt::Horizontal ) {
                bool ltr = slider->direction == Qt::LeftToRight;
                if (slider->upsideDown) ltr = !ltr;
                if (ltr) {
                    groove.setLeft(c.x());
                    thermometer.setRight(c.x());
                } else {
                    groove.setRight(c.x());
                    thermometer.setLeft(handle.left());
                }
            }
            else {
                if (slider->upsideDown) {
                    groove.setBottom(c.y());
                    thermometer.setTop(c.y());
                } else {
                    groove.setTop(c.y());
                    thermometer.setBottom(handle.bottom());
                }
            }
            painter->drawRoundedRect(thermometer, radius, radius);
        }

        if (slider->sliderPosition != slider->maximum || slider->minimum < 0 ) {
            radius = qMin(groove.width(), groove.height())/2;
            painter->setBrush(GROOVE_COLOR);
            painter->drawRoundedRect(groove, radius, radius);
        }

        painter->setRenderHint(QPainter::Antialiasing, false);
    }

    // tickmarks - we paint a centered dotline, no stupid above/below/both nonsense
   if (isEnabled && (slider->subControls & SC_SliderTickmarks) && slider->tickPosition != QSlider::NoTicks) {
       int interval = slider->tickInterval;
       if (interval < 1)
           interval = slider->pageStep;
       if (interval > 0) {
           QPen oldPen = painter->pen();
           const qreal pw = F(1);
           QPen pen(FCOLOR(Window), pw);
           interval = (slider->maximum - slider->minimum) / interval;
           const int s = (slider->orientation == Qt::Horizontal) ? RECT.width() - handle.width() :  RECT.height() - handle.height();
           qreal space = s/(pw*interval) - 1.0f;
           pen.setDashPattern(QVector<qreal>() << 1.0f << space);
           space /= 2.0f;
           pen.setDashOffset(space - 0.5f + handle.width()*0.5f);
           painter->setPen(pen);
           QPoint c = groove.center();
           if (slider->orientation == Qt::Horizontal)
               painter->drawLine(RECT.x() + space, c.y(), RECT.right() - space, c.y());
           else
               painter->drawLine(c.x(), RECT.y() + space, c.x(), RECT.bottom() - space);
           painter->setPen(oldPen);
       }
   }

    // handle ======================================
    if (isEnabled && (slider->subControls & SC_SliderHandle)) {
        int step = 0;
        if (sunken)
            step = 6;
        else if (isEnabled) {
            const Animator::ComplexInfo *info = Animator::HoverComplex::info(widget, slider->activeSubControls & SC_SliderHandle);
            if (info && ( info->fades[Animator::In] & SC_SliderHandle || info->fades[Animator::Out] & SC_SliderHandle ))
                step = info->step(SC_SliderHandle);
            if (hover && !step)
                step = 6;
        }
        drawSliderHandle(handle, option, painter, step);
    }
    RESTORE_PAINTER
}
示例#16
0
void
Style::drawComboBox(const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const
{
    ASSURE_OPTION(cmb, ComboBox);
    OPT_ENABLED OPT_HOVER OPT_FOCUS
    SAVE_PAINTER(Pen|Brush|Alias);
    if ( widget && widget->inherits("WebView") ) {
        // paints hardcoded black text bypassing the style?! grrr...
        const_cast<QStyleOptionComboBox*>(cmb)->palette.setColor(QPalette::Window, QColor(230,230,230,255));
        widget = 0;
    }

    animStep = !widget ? MAX_STEPS*hover : Animator::Hover::step(widget);

    QRect ar;
    const QComboBox *combo = widget ? qobject_cast<const QComboBox*>(widget) : NULL;
    if ((cmb->subControls & SC_ComboBoxArrow) && (!combo || combo->count() > 0)) {   // do we have an arrow?
        ar = subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget);
        const int dx = (F(2) & ~1) / 2;
        ar.translate(cmb->direction == Qt::LeftToRight ? -dx : dx, 0);
    }

    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()); // TODO Qt5, avoid asking for the cursor pos
        animStep = MAX_STEPS;
    }

    QColor c = hasFocus ? FCOLOR(Highlight) : (cmb->editable ? FCOLOR(Text) : FCOLOR(WindowText));
    if (cmb->editable) {
        drawLineEditFrame(option, painter, widget);
        c = FX::blend(FCOLOR(Base), c, MAX_STEPS, 1 + 2*animStep);
    } else {
        const int icon = cmb->currentIcon.isNull() ? 0 : cmb->iconSize.width() + F(4);
        QFont fnt(painter->font());
        fnt.setBold(true);
        int text = QFontMetrics(fnt).width(cmb->currentText);
        if (text)
            text += F(4);

        if (!(text+icon)) // webkit etc.
            text = ar.left() - (F(16) + RECT.x());

        painter->setRenderHint(QPainter::Antialiasing, true);
        painter->setPen(QPen(hasFocus ? FCOLOR(Highlight) : FX::blend(FCOLOR(Window), c, 4, 1), FRAME_STROKE));
        painter->setBrush(Qt::NoBrush);

        const int y = ar.y() + ar.height()/2;
        const int da = animStep * 168 / MAX_STEPS;
        if (option->direction == Qt::LeftToRight) {
            DRAW_SEGMENT(ar, 16*(120 - da/2), 16*(192+da));
            painter->drawLine(RECT.x() + icon + text + F(6), y, ar.left()-F(2), y);
        } else {
            DRAW_SEGMENT(ar, 16*(30 + da/2), -16*(192+da));
            painter->drawLine(RECT.right() - (icon + text + F(6)), y, ar.right()+F(2), y);
        }
        c = FX::blend(FCOLOR(Window), FCOLOR(WindowText), MAX_STEPS - animStep, 1 + animStep);
    }

    if (!isEnabled) {
        RESTORE_PAINTER
        return;
    }