/****************************************************************************
**
** Copyright (C) 1992-2004 Trolltech AS. All rights reserved.
**
** This file is part of the widgets module of the Qt Toolkit.
**
** Licensees holding valid Qt Preview licenses may use this file in
** accordance with the Qt Preview License Agreement provided with the
** Software.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/

#ifndef QABSTRACTSLIDER_H
#define QABSTRACTSLIDER_H

#include "qwidget.h"

class QAbstractSliderPrivate;

class Q_GUI_EXPORT QAbstractSlider : public QWidget
{
    Q_OBJECT
    Q_DECLARE_PRIVATE(QAbstractSlider)

    Q_PROPERTY(int minimum READ minimum WRITE setMinimum)
    Q_PROPERTY(int maximum READ maximum WRITE setMaximum)
    Q_PROPERTY(int singleStep READ singleStep WRITE setSingleStep)
    Q_PROPERTY(int pageStep READ pageStep WRITE setPageStep)
    Q_PROPERTY(int value READ value WRITE setValue)
    Q_PROPERTY(bool tracking READ hasTracking WRITE setTracking)
    Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
    Q_PROPERTY(bool invertedAppearance READ invertedAppearance WRITE setInvertedAppearance)
    Q_PROPERTY(bool invertedControls READ invertedControls WRITE setInvertedControls)
    QDOC_PROPERTY(bool sliderDown READ isSliderDown WRITE setSliderDown)

public:
    QAbstractSlider(QWidget *parent=0);
    ~QAbstractSlider();

    void setOrientation(Qt::Orientation);
    Qt::Orientation orientation() const;

    void setMinimum(int);
    int minimum() const;

    void setMaximum(int);
    int maximum() const;

    void setRange(int min, int max);

    void setSingleStep(int);
    int singleStep() const;

    void setPageStep(int);
    int pageStep() const;

    void setTracking(bool enable);
    bool hasTracking() const;

    void setSliderDown(bool);
    bool isSliderDown() const;

    void setSliderPosition(int);
    int sliderPosition() const;

    void setInvertedAppearance(bool);
    bool invertedAppearance() const;

    void setInvertedControls(bool);
    bool invertedControls() const;

    enum SliderAction {
        SliderNoAction,
        SliderSingleStepAdd,
        SliderSingleStepSub,
        SliderPageStepAdd,
        SliderPageStepSub,
        SliderToMinimum,
        SliderToMaximum,
        SliderMove
    };

    int value() const;

    void triggerAction(SliderAction action);

public slots:
    void setValue(int);

signals:
    void valueChanged(int value);

    void sliderPressed();
    void sliderMoved(int position);
    void sliderReleased();

    void rangeChanged(int min, int max);

    void actionTriggered(int action);

protected:
    void setRepeatAction(SliderAction action, int thresholdTime = 500, int repeatTime = 50);
    SliderAction repeatAction() const;

    enum SliderChange {
        SliderRangeChange,
        SliderOrientationChange,
        SliderStepsChange,
        SliderValueChange
    };
    virtual void sliderChange(SliderChange change);

    void keyPressEvent(QKeyEvent *ev);
    void timerEvent(QTimerEvent *);
    void wheelEvent(QWheelEvent *e);

protected:
    QAbstractSlider(QAbstractSliderPrivate &dd, QWidget *parent);

#ifdef QT_COMPAT
public:
    inline QT_COMPAT int minValue() const { return minimum(); }
    inline QT_COMPAT int maxValue() const { return maximum(); }
    inline QT_COMPAT int lineStep() const { return singleStep(); }
    inline QT_COMPAT void setMinValue(int v) { setMinimum(v); }
    inline QT_COMPAT void setMaxValue(int v) { setMaximum(v); }
    inline QT_COMPAT void setLineStep(int v) { setSingleStep(v); }
    inline QT_COMPAT void setSteps(int single, int page) { setSingleStep(single); setPageStep(page); }
    inline QT_COMPAT void addPage() { triggerAction(SliderPageStepAdd); }
    inline QT_COMPAT void subtractPage() { triggerAction(SliderPageStepSub); }
    inline QT_COMPAT void addLine() { triggerAction(SliderSingleStepAdd); }
    inline QT_COMPAT void subtractLine() { triggerAction(SliderSingleStepSub); }
#endif

private:
    Q_DISABLE_COPY(QAbstractSlider)
};

#endif // QABSTRACTSLIDER_H
