qwt_slider.h 3.61 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

// vim: expandtab

#ifndef QWT_SLIDER_H
#define QWT_SLIDER_H

#include "qwt_global.h"
#include "qwt_abstract_scale.h"
#include "qwt_abstract_slider.h"

class QwtScaleDraw;

/*!
  \brief The Slider Widget

  QwtSlider is a slider widget which operates on an interval
  of type double. QwtSlider supports different layouts as
  well as a scale.

  \image html sliders.png

  \sa QwtAbstractSlider and QwtAbstractScale for the descriptions
      of the inherited members.
*/

class QWT_EXPORT QwtSlider : public QwtAbstractSlider, public QwtAbstractScale
{
    Q_OBJECT
    Q_ENUMS( ScalePos )
    Q_ENUMS( BGSTYLE )
    Q_PROPERTY( ScalePos scalePosition READ scalePosition
40
                WRITE setScalePosition )
pixhawk's avatar
pixhawk committed
41 42 43 44
    Q_PROPERTY( BGSTYLE bgStyle READ bgStyle WRITE setBgStyle )
    Q_PROPERTY( int thumbLength READ thumbLength WRITE setThumbLength )
    Q_PROPERTY( int thumbWidth READ thumbWidth WRITE setThumbWidth )
    Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth )
45

pixhawk's avatar
pixhawk committed
46 47
public:

48
    /*!
pixhawk's avatar
pixhawk committed
49 50 51 52 53 54 55
      Scale position. QwtSlider tries to enforce valid combinations of its
      orientation and scale position:
      - Qt::Horizonal combines with NoScale, TopScale and BottomScale
      - Qt::Vertical combines with NoScale, LeftScale and RightScale

      \sa QwtSlider::QwtSlider
     */
56 57 58 59 60 61 62
    enum ScalePos {
        NoScale,

        LeftScale,
        RightScale,
        TopScale,
        BottomScale
pixhawk's avatar
pixhawk committed
63 64
    };

65
    /*!
pixhawk's avatar
pixhawk committed
66 67 68
      Background style.
      \sa QwtSlider::QwtSlider
     */
69 70 71
    enum BGSTYLE {
        BgTrough = 0x1,
        BgSlot = 0x2,
pixhawk's avatar
pixhawk committed
72 73 74 75
        BgBoth = BgTrough | BgSlot
    };

    explicit QwtSlider(QWidget *parent,
76 77
                       Qt::Orientation = Qt::Horizontal,
                       ScalePos = NoScale, BGSTYLE bgStyle = BgTrough);
pixhawk's avatar
pixhawk committed
78 79 80
#if QT_VERSION < 0x040000
    explicit QwtSlider(QWidget *parent, const char *name);
#endif
81

pixhawk's avatar
pixhawk committed
82 83
    virtual ~QwtSlider();

84
    virtual void setOrientation(Qt::Orientation);
pixhawk's avatar
pixhawk committed
85 86 87

    void setBgStyle(BGSTYLE);
    BGSTYLE bgStyle() const;
88

pixhawk's avatar
pixhawk committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102
    void setScalePosition(ScalePos s);
    ScalePos scalePosition() const;

    int thumbLength() const;
    int thumbWidth() const;
    int borderWidth() const;

    void setThumbLength(int l);
    void setThumbWidth(int w);
    void setBorderWidth(int bw);
    void setMargins(int x, int y);

    virtual QSize sizeHint() const;
    virtual QSize minimumSizeHint() const;
103

pixhawk's avatar
pixhawk committed
104 105 106 107 108
    void setScaleDraw(QwtScaleDraw *);
    const QwtScaleDraw *scaleDraw() const;

protected:
    virtual double getValue(const QPoint &p);
109 110
    virtual void getScrollMode(const QPoint &p,
                               int &scrollMode, int &direction);
pixhawk's avatar
pixhawk committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

    void draw(QPainter *p, const QRect& update_rect);
    virtual void drawSlider (QPainter *p, const QRect &r);
    virtual void drawThumb(QPainter *p, const QRect &, int pos);

    virtual void resizeEvent(QResizeEvent *e);
    virtual void paintEvent (QPaintEvent *e);

    virtual void valueChange();
    virtual void rangeChange();
    virtual void scaleChange();
    virtual void fontChange(const QFont &oldFont);

    void layoutSlider( bool update = true );
    int xyPosition(double v) const;

    QwtScaleDraw *scaleDraw();

private:
    void initSlider(Qt::Orientation, ScalePos scalePos, BGSTYLE bgStyle);

    class PrivateData;
    PrivateData *d_data;
};

#endif