File indexing completed on 2024-05-12 15:27:42

0001 #ifndef QXTSPANSLIDER_H
0002 /****************************************************************************
0003 ** Copyright (c) 2006 - 2011, the LibQxt project.
0004 ** See the Qxt AUTHORS file for a list of authors and copyright holders.
0005 ** All rights reserved.
0006 **
0007 ** Redistribution and use in source and binary forms, with or without
0008 ** modification, are permitted provided that the following conditions are met:
0009 **     * Redistributions of source code must retain the above copyright
0010 **       notice, this list of conditions and the following disclaimer.
0011 **     * Redistributions in binary form must reproduce the above copyright
0012 **       notice, this list of conditions and the following disclaimer in the
0013 **       documentation and/or other materials provided with the distribution.
0014 **     * Neither the name of the LibQxt project nor the
0015 **       names of its contributors may be used to endorse or promote products
0016 **       derived from this software without specific prior written permission.
0017 **
0018 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
0019 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
0020 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0021 ** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
0022 ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
0023 ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
0024 ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0025 ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0026 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0027 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0028 **
0029 ** <http://libqxt.org>  <foundation@libqxt.org>
0030 *****************************************************************************/
0031 
0032 #define QXTSPANSLIDER_H
0033 
0034 #include <QSlider>
0035 #include "qxtnamespace.h"
0036 #include "qxtglobal.h"
0037 
0038 class QxtSpanSliderPrivate;
0039 
0040 class QxtSpanSlider : public QSlider {
0041     Q_OBJECT
0042     QXT_DECLARE_PRIVATE(QxtSpanSlider)
0043     Q_PROPERTY(int lowerValue READ lowerValue WRITE setLowerValue)
0044     Q_PROPERTY(int upperValue READ upperValue WRITE setUpperValue)
0045     Q_PROPERTY(int lowerPosition READ lowerPosition WRITE setLowerPosition)
0046     Q_PROPERTY(int upperPosition READ upperPosition WRITE setUpperPosition)
0047     Q_PROPERTY(HandleMovementMode handleMovementMode READ handleMovementMode WRITE setHandleMovementMode)
0048     Q_ENUMS(HandleMovementMode)
0049 
0050 public:
0051     explicit QxtSpanSlider(QWidget* parent = nullptr);
0052     explicit QxtSpanSlider(Qt::Orientation orientation, QWidget* parent = nullptr);
0053     ~QxtSpanSlider() override;
0054 
0055     enum HandleMovementMode {FreeMovement, NoCrossing, NoOverlapping};
0056     enum SpanHandle {NoHandle, LowerHandle, UpperHandle};
0057 
0058     HandleMovementMode handleMovementMode() const;
0059     void setHandleMovementMode(HandleMovementMode);
0060 
0061     int lowerValue() const;
0062     int upperValue() const;
0063 
0064     int lowerPosition() const;
0065     int upperPosition() const;
0066 
0067 public slots:
0068     void setLowerValue(int lower);
0069     void setUpperValue(int upper);
0070     void setSpan(int lower, int upper);
0071 
0072     void setLowerPosition(int lower);
0073     void setUpperPosition(int upper);
0074 
0075 signals:
0076     void spanChanged(int lower, int upper);
0077     void lowerValueChanged(int lower);
0078     void upperValueChanged(int upper);
0079 
0080     void lowerPositionChanged(int lower);
0081     void upperPositionChanged(int upper);
0082 
0083     void sliderPressed(QxtSpanSlider::SpanHandle);
0084 
0085 protected:
0086     void keyPressEvent(QKeyEvent*) override;
0087     void mousePressEvent(QMouseEvent*) override;
0088     void mouseMoveEvent(QMouseEvent*) override;
0089     void mouseReleaseEvent(QMouseEvent*) override;
0090     void paintEvent(QPaintEvent*) override;
0091 };
0092 
0093 #endif // QXTSPANSLIDER_H