Example #1
0
/*!
  \brief Determine scrolling mode and direction
  \param p point
  \param scrollMode Scrolling mode
  \param direction Direction
*/
void QwtSlider::getScrollMode(const QPoint &p, 
    int &scrollMode, int &direction )
{
    if (!d_data->sliderRect.contains(p))
    {
        scrollMode = ScrNone;
        direction = 0;
        return;
    }

    const int pos = ( orientation() == Qt::Horizontal ) ? p.x() : p.y();
    const int markerPos = xyPosition(value());

    if ((pos > markerPos - d_data->thumbLength / 2)
        && (pos < markerPos + d_data->thumbLength / 2))
    {
        scrollMode = ScrMouse;
        direction = 0;
        return;
    }

    scrollMode = ScrPage;
    direction = (pos > markerPos) ? 1 : -1;

    if ( scaleDraw()->map().p1() > scaleDraw()->map().p2() )
        direction = -direction;
}
Example #2
0
//! Draw the slider into the specified rectangle.
void QwtSlider::drawSlider(QPainter *p, const QRect &r)
{
    QRect cr(r);

    if (d_bgStyle & BgTrough)
    {
        qDrawShadePanel(p, r.x(), r.y(),
            r.width(), r.height(),
            colorGroup(), TRUE, d_borderWidth,0);

        cr.setRect(r.x() + d_borderWidth,
            r.y() + d_borderWidth,
            r.width() - 2 * d_borderWidth,
            r.height() - 2 * d_borderWidth);

        p->fillRect(cr.x(), cr.y(), cr.width(), cr.height(), 
            colorGroup().brush(QColorGroup::Mid));
    }

    if ( d_bgStyle & BgSlot)
    {
        int ws = 4;
        int ds = d_thumbLength / 2 - 4;
        if ( ds < 1 )
            ds = 1;

        QRect rSlot;
        if (orientation() == Qt::Horizontal)
        {
            if ( cr.height() & 1 )
                ws++;
            rSlot = QRect(cr.x() + ds, 
                    cr.y() + (cr.height() - ws) / 2,
                    cr.width() - 2 * ds, ws);
        }
        else
        {
            if ( cr.width() & 1 )
                ws++;
            rSlot = QRect(cr.x() + (cr.width() - ws) / 2, 
                    cr.y() + ds,
                    ws, cr.height() - 2 * ds);
        }
        p->fillRect(rSlot.x(), rSlot.y(), rSlot.width(), rSlot.height(),
            colorGroup().brush(QColorGroup::Dark));
        qDrawShadePanel(p, rSlot.x(), rSlot.y(),
            rSlot.width(), rSlot.height(), colorGroup(), TRUE, 1 ,0);

    }

    if ( isValid() )
        drawThumb(p, cr, xyPosition(value()));
}
/*! 
   Draw the slider into the specified rectangle.

   \param painter Painter
   \param r Rectangle
*/
void QwtSlider::drawSlider(QPainter *painter, const QRect &r)
{
    QRect cr(r);

    if (d_data->bgStyle & BgTrough)
    {
        qDrawShadePanel(painter, r.x(), r.y(),
            r.width(), r.height(),
#if QT_VERSION < 0x040000
            colorGroup(), 
#else
            palette(), 
#endif
            true, d_data->borderWidth,0);

        cr.setRect(r.x() + d_data->borderWidth,
            r.y() + d_data->borderWidth,
            r.width() - 2 * d_data->borderWidth,
            r.height() - 2 * d_data->borderWidth);

        painter->fillRect(cr.x(), cr.y(), cr.width(), cr.height(), 
#if QT_VERSION < 0x040000
            colorGroup().brush(QColorGroup::Mid)
#else
            palette().brush(QPalette::Mid)
#endif
        );
    }

    if ( d_data->bgStyle & BgSlot)
    {
        int ws = 4;
        int ds = d_data->thumbLength / 2 - 4;
        if ( ds < 1 )
            ds = 1;

        QRect rSlot;
        if (orientation() == Qt::Horizontal)
        {
            if ( cr.height() & 1 )
                ws++;
            rSlot = QRect(cr.x() + ds, 
                    cr.y() + (cr.height() - ws) / 2,
                    cr.width() - 2 * ds, ws);
        }
        else
        {
            if ( cr.width() & 1 )
                ws++;
            rSlot = QRect(cr.x() + (cr.width() - ws) / 2, 
                    cr.y() + ds,
                    ws, cr.height() - 2 * ds);
        }
        painter->fillRect(rSlot.x(), rSlot.y(), rSlot.width(), rSlot.height(),
#if QT_VERSION < 0x040000
            colorGroup().brush(QColorGroup::Dark)
#else
            palette().brush(QPalette::Dark)
#endif
        );
        qDrawShadePanel(painter, rSlot.x(), rSlot.y(),
            rSlot.width(), rSlot.height(), 
#if QT_VERSION < 0x040000
            colorGroup(), 
#else
            palette(), 
#endif
            true, 1 ,0);

    }

    if ( isValid() )
        drawThumb(painter, cr, xyPosition(value()));
}