Public Types | Public Slots | Public Member Functions | Public Attributes | Friends

QxtSpanSliderPrivate Class Reference

#include <qxtspanslider_p.h>

Inheritance diagram for QxtSpanSliderPrivate:
Inheritance graph
[legend]
Collaboration diagram for QxtSpanSliderPrivate:
Collaboration graph
[legend]

List of all members.

Public Types

enum  SpanHandle { NoHandle, LowerHandle, UpperHandle }

Public Slots

void updateRange (int min, int max)
void movePressedHandle ()

Public Member Functions

 QxtSpanSliderPrivate ()
void initStyleOption (QStyleOptionSlider *option, SpanHandle handle=UpperHandle) const
int pick (const QPoint &pt) const
int pixelPosToRangeValue (int pos) const
void handleMousePress (const QPoint &pos, QStyle::SubControl &control, int value, SpanHandle handle)
void drawHandle (QStylePainter *painter, SpanHandle handle) const
void setupPainter (QPainter *painter, Qt::Orientation orientation, qreal x1, qreal y1, qreal x2, qreal y2) const
void drawSpan (QStylePainter *painter, const QRect &rect) const
void triggerAction (QAbstractSlider::SliderAction action, bool main)
void swapControls ()

Public Attributes

int lower
int upper
int lowerPos
int upperPos
int offset
int position
SpanHandle lastPressed
SpanHandle mainControl
QStyle::SubControl lowerPressed
QStyle::SubControl upperPressed
QxtSpanSlider::HandleMovementMode movement
bool firstMovement
bool blockTracking

Friends

class QxtSpanSlider

Detailed Description

Definition at line 36 of file qxtspanslider_p.h.


Member Enumeration Documentation

Enumerator:
NoHandle 
LowerHandle 
UpperHandle 

Definition at line 43 of file qxtspanslider_p.h.


Constructor & Destructor Documentation

QxtSpanSliderPrivate::QxtSpanSliderPrivate (  )

Definition at line 33 of file qxtspanslider.cpp.


Member Function Documentation

void QxtSpanSliderPrivate::drawHandle ( QStylePainter *  painter,
SpanHandle  handle 
) const

Definition at line 164 of file qxtspanslider.cpp.

References initStyleOption(), LowerHandle, lowerPressed, and upperPressed.

{
    QStyleOptionSlider opt;
    initStyleOption(&opt, handle);
    opt.subControls = QStyle::SC_SliderHandle;
    QStyle::SubControl pressed = (handle == LowerHandle ? lowerPressed : upperPressed);
    if (pressed == QStyle::SC_SliderHandle)
    {
        opt.activeSubControls = pressed;
        opt.state |= QStyle::State_Sunken;
    }
    painter->drawComplexControl(QStyle::CC_Slider, opt);
}
void QxtSpanSliderPrivate::drawSpan ( QStylePainter *  painter,
const QRect &  rect 
) const

Definition at line 136 of file qxtspanslider.cpp.

References initStyleOption(), QxtPrivate< QxtSpanSlider >::qxt_p(), and setupPainter().

{
    QStyleOptionSlider opt;
    initStyleOption(&opt);
    const QSlider* p = &qxt_p();

    // area
    QRect groove = p->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, p);
    if (opt.orientation == Qt::Horizontal)
        groove.adjust(0, 0, -1, 0);
    else
        groove.adjust(0, 0, 0, -1);

    // pen & brush
    painter->setPen(QPen(p->palette().color(QPalette::Dark).light(110), 0));
    if (opt.orientation == Qt::Horizontal)
        setupPainter(painter, opt.orientation, groove.center().x(), groove.top(), groove.center().x(), groove.bottom());
    else
        setupPainter(painter, opt.orientation, groove.left(), groove.center().y(), groove.right(), groove.center().y());

    // draw groove
#if QT_VERSION >= 0x040200
    painter->drawRect(rect.intersected(groove));
#else // QT_VERSION < 0x040200
    painter->drawRect(rect.intersect(groove));
#endif // QT_VERSION
}
void QxtSpanSliderPrivate::handleMousePress ( const QPoint &  pos,
QStyle::SubControl &  control,
int  value,
SpanHandle  handle 
)

Definition at line 103 of file qxtspanslider.cpp.

References initStyleOption(), lastPressed, offset, pick(), position, and QxtPrivate< QxtSpanSlider >::qxt_p().

{
    QStyleOptionSlider opt;
    initStyleOption(&opt, handle);
    QSlider* p = &qxt_p();
    const QStyle::SubControl oldControl = control;
    control = p->style()->hitTestComplexControl(QStyle::CC_Slider, &opt, pos, p);
    const QRect sr = p->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, p);
    if (control == QStyle::SC_SliderHandle)
    {
        position = value;
        offset = pick(pos - sr.topLeft());
        lastPressed = handle;
        p->setSliderDown(true);
    }
    if (control != oldControl)
        p->update(sr);
}
void QxtSpanSliderPrivate::initStyleOption ( QStyleOptionSlider *  option,
SpanHandle  handle = UpperHandle 
) const

Definition at line 51 of file qxtspanslider.cpp.

References lower, LowerHandle, lowerPos, QxtPrivate< QxtSpanSlider >::qxt_p(), upper, and upperPos.

Referenced by drawHandle(), drawSpan(), handleMousePress(), and pixelPosToRangeValue().

{
    if (!option)
        return;

    const QSlider* p = &qxt_p();
    option->initFrom(p);
    option->subControls = QStyle::SC_None;
    option->activeSubControls = QStyle::SC_None;
    option->orientation = p->orientation();
    option->maximum = p->maximum();
    option->minimum = p->minimum();
    option->tickPosition = p->tickPosition();
    option->tickInterval = p->tickInterval();
    option->upsideDown = (p->orientation() == Qt::Horizontal) ?
                         (p->invertedAppearance() != (option->direction == Qt::RightToLeft)) : (!p->invertedAppearance());
    option->direction = Qt::LeftToRight; // we use the upsideDown option instead
    option->sliderPosition = (handle == LowerHandle ? lowerPos : upperPos);
    option->sliderValue = (handle == LowerHandle ? lower : upper);
    option->singleStep = p->singleStep();
    option->pageStep = p->pageStep();
    if (p->orientation() == Qt::Horizontal)
        option->state |= QStyle::State_Horizontal;
}
void QxtSpanSliderPrivate::movePressedHandle (  ) [slot]

Definition at line 286 of file qxtspanslider.cpp.

References lastPressed, lower, LowerHandle, lowerPos, main(), mainControl, triggerAction(), upper, UpperHandle, and upperPos.

{
    switch (lastPressed)
    {
        case QxtSpanSliderPrivate::LowerHandle:
            if (lowerPos != lower)
            {
                bool main = (mainControl == QxtSpanSliderPrivate::LowerHandle);
                triggerAction(QAbstractSlider::SliderMove, main);
            }
            break;
        case QxtSpanSliderPrivate::UpperHandle:
            if (upperPos != upper)
            {
                bool main = (mainControl == QxtSpanSliderPrivate::UpperHandle);
                triggerAction(QAbstractSlider::SliderMove, main);
            }
            break;
        default:
            break;
    }
}
int QxtSpanSliderPrivate::pick ( const QPoint &  pt ) const [inline]

Definition at line 52 of file qxtspanslider_p.h.

Referenced by handleMousePress().

    {
        return qxt_p().orientation() == Qt::Horizontal ? pt.x() : pt.y();
    }
int QxtSpanSliderPrivate::pixelPosToRangeValue ( int  pos ) const

Definition at line 76 of file qxtspanslider.cpp.

References initStyleOption(), and QxtPrivate< QxtSpanSlider >::qxt_p().

{
    QStyleOptionSlider opt;
    initStyleOption(&opt);

    int sliderMin = 0;
    int sliderMax = 0;
    int sliderLength = 0;
    const QSlider* p = &qxt_p();
    const QRect gr = p->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, p);
    const QRect sr = p->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, p);
    if (p->orientation() == Qt::Horizontal)
    {
        sliderLength = sr.width();
        sliderMin = gr.x();
        sliderMax = gr.right() - sliderLength + 1;
    }
    else
    {
        sliderLength = sr.height();
        sliderMin = gr.y();
        sliderMax = gr.bottom() - sliderLength + 1;
    }
    return QStyle::sliderValueFromPosition(p->minimum(), p->maximum(), pos - sliderMin,
                                           sliderMax - sliderMin, opt.upsideDown);
}
void QxtSpanSliderPrivate::setupPainter ( QPainter *  painter,
Qt::Orientation  orientation,
qreal  x1,
qreal  y1,
qreal  x2,
qreal  y2 
) const

Definition at line 122 of file qxtspanslider.cpp.

References QxtPrivate< QxtSpanSlider >::qxt_p().

Referenced by drawSpan().

{
    QColor highlight = qxt_p().palette().color(QPalette::Highlight);
    QLinearGradient gradient(x1, y1, x2, y2);
    gradient.setColorAt(0, highlight.dark(120));
    gradient.setColorAt(1, highlight.light(108));
    painter->setBrush(gradient);

    if (orientation == Qt::Horizontal)
        painter->setPen(QPen(highlight.dark(130), 0));
    else
        painter->setPen(QPen(highlight.dark(150), 0));
}
void QxtSpanSliderPrivate::swapControls (  )
void QxtSpanSliderPrivate::triggerAction ( QAbstractSlider::SliderAction  action,
bool  main 
)

Definition at line 178 of file qxtspanslider.cpp.

References blockTracking, QxtSpanSlider::FreeMovement, lower, LowerHandle, lowerPos, mainControl, QuadProgPP::max(), min, movement, QxtSpanSlider::NoCrossing, QxtSpanSlider::NoOverlapping, QxtPrivate< QxtSpanSlider >::qxt_p(), QxtSpanSlider::setLowerPosition(), QxtSpanSlider::setLowerValue(), QxtSpanSlider::setUpperPosition(), QxtSpanSlider::setUpperValue(), swapControls(), upper, UpperHandle, and upperPos.

Referenced by movePressedHandle().

{
    int value = 0;
    bool no = false;
    bool up = false;
    const int min = qxt_p().minimum();
    const int max = qxt_p().maximum();
    const SpanHandle altControl = (mainControl == LowerHandle ? UpperHandle : LowerHandle);

    blockTracking = true;

    switch (action)
    {
    case QAbstractSlider::SliderSingleStepAdd:
        if ((main && mainControl == UpperHandle) || (!main && altControl == UpperHandle))
        {
            value = qBound(min, upper + qxt_p().singleStep(), max);
            up = true;
            break;
        }
        value = qBound(min, lower + qxt_p().singleStep(), max);
        break;
    case QAbstractSlider::SliderSingleStepSub:
        if ((main && mainControl == UpperHandle) || (!main && altControl == UpperHandle))
        {
            value = qBound(min, upper - qxt_p().singleStep(), max);
            up = true;
            break;
        }
        value = qBound(min, lower - qxt_p().singleStep(), max);
        break;
    case QAbstractSlider::SliderToMinimum:
        value = min;
        if ((main && mainControl == UpperHandle) || (!main && altControl == UpperHandle))
            up = true;
        break;
    case QAbstractSlider::SliderToMaximum:
        value = max;
        if ((main && mainControl == UpperHandle) || (!main && altControl == UpperHandle))
            up = true;
        break;
    case QAbstractSlider::SliderMove:
        if ((main && mainControl == UpperHandle) || (!main && altControl == UpperHandle))
            up = true;
    case QAbstractSlider::SliderNoAction:
        no = true;
        break;
    default:
        qWarning("QxtSpanSliderPrivate::triggerAction: Unknown action");
        break;
    }

    if (!no && !up)
    {
        if (movement == QxtSpanSlider::NoCrossing)
            value = qMin(value, upper);
        else if (movement == QxtSpanSlider::NoOverlapping)
            value = qMin(value, upper - 1);

        if (movement == QxtSpanSlider::FreeMovement && value > upper)
        {
            swapControls();
            qxt_p().setUpperPosition(value);
        }
        else
        {
            qxt_p().setLowerPosition(value);
        }
    }
    else if (!no)
    {
        if (movement == QxtSpanSlider::NoCrossing)
            value = qMax(value, lower);
        else if (movement == QxtSpanSlider::NoOverlapping)
            value = qMax(value, lower + 1);

        if (movement == QxtSpanSlider::FreeMovement && value < lower)
        {
            swapControls();
            qxt_p().setLowerPosition(value);
        }
        else
        {
            qxt_p().setUpperPosition(value);
        }
    }

    blockTracking = false;
    qxt_p().setLowerValue(lowerPos);
    qxt_p().setUpperValue(upperPos);
}
void QxtSpanSliderPrivate::updateRange ( int  min,
int  max 
) [slot]

Definition at line 278 of file qxtspanslider.cpp.

References lower, QxtPrivate< QxtSpanSlider >::qxt_p(), QxtSpanSlider::setSpan(), and upper.

{
    Q_UNUSED(min);
    Q_UNUSED(max);
    // setSpan() takes care of keeping span in range
    qxt_p().setSpan(lower, upper);
}

Friends And Related Function Documentation

friend class QxtSpanSlider [friend]

Definition at line 41 of file qxtspanslider_p.h.


Member Data Documentation

Definition at line 76 of file qxtspanslider_p.h.

Referenced by triggerAction().

Definition at line 75 of file qxtspanslider_p.h.

Definition at line 70 of file qxtspanslider_p.h.

Referenced by handleMousePress(), movePressedHandle(), and swapControls().

Definition at line 66 of file qxtspanslider_p.h.

Referenced by initStyleOption(), movePressedHandle(), and triggerAction().

Definition at line 72 of file qxtspanslider_p.h.

Referenced by drawHandle(), and swapControls().

Definition at line 71 of file qxtspanslider_p.h.

Referenced by movePressedHandle(), swapControls(), and triggerAction().

Definition at line 74 of file qxtspanslider_p.h.

Referenced by triggerAction().

Definition at line 68 of file qxtspanslider_p.h.

Referenced by handleMousePress().

Definition at line 69 of file qxtspanslider_p.h.

Referenced by handleMousePress().

Definition at line 67 of file qxtspanslider_p.h.

Referenced by initStyleOption(), movePressedHandle(), and triggerAction().

Definition at line 73 of file qxtspanslider_p.h.

Referenced by drawHandle(), and swapControls().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines