| 1 |
/* |
| 2 |
* libkysdk-qtwidgets's Library |
| 3 |
* |
| 4 |
* Copyright (C) 2023, KylinSoft Co., Ltd. |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 3 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
* Authors: Zhen Sun <[email protected]> |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifndef KSLIDER_H |
| 24 |
#define KSLIDER_H |
| 25 |
|
| 26 |
#include "gui_g.h" |
| 27 |
#include <QList> |
| 28 |
#include <QSlider> |
| 29 |
|
| 30 |
namespace kdk |
| 31 |
{ |
| 32 |
/** @defgroup SliderModule |
| 33 |
* @{ |
| 34 |
*/ |
| 35 |
|
| 36 |
enum KSliderType { |
| 37 |
SmoothSlider, |
| 38 |
StepSlider, |
| 39 |
NodeSlider, |
| 40 |
SingleSelectSlider |
| 41 |
}; |
| 42 |
|
| 43 |
class KSliderPrivate; |
| 44 |
|
| 45 |
/** |
| 46 |
* @brief 支持三种样式的滑动条 |
| 47 |
* 非步数关系:步数为1,可以在任意位置点击和拖拽 |
| 48 |
* 步数关系:步数为固定值,可根据步数值点击和拖拽 |
| 49 |
* 节点关系:步数为节点间隔,可根据节点间隔点击和拖拽 |
| 50 |
* @since 1.0.0 |
| 51 |
*/ |
| 52 |
class KSlider : public QSlider |
| 53 |
{ |
| 54 |
Q_OBJECT |
| 55 |
public: |
| 56 |
KSlider(QWidget *parent); |
| 57 |
KSlider(Qt::Orientation orientation, QWidget *parent = nullptr); |
| 58 |
|
| 59 |
/** |
| 60 |
* @brief 设置节点间隔 |
| 61 |
* @param interval |
| 62 |
*/ |
| 63 |
void setTickInterval(int interval); |
| 64 |
|
| 65 |
/** |
| 66 |
* @brief 设置滑动条类型 |
| 67 |
* @param type |
| 68 |
*/ |
| 69 |
void setSliderType(KSliderType type); |
| 70 |
|
| 71 |
/** |
| 72 |
* @brief 获取滑动条类型 |
| 73 |
* @return |
| 74 |
*/ |
| 75 |
KSliderType sliderType(); |
| 76 |
|
| 77 |
/** |
| 78 |
* @brief 获取节点间隔 |
| 79 |
* @return |
| 80 |
*/ |
| 81 |
int tickInterval() const; |
| 82 |
|
| 83 |
/** |
| 84 |
* @brief 设置值 |
| 85 |
*/ |
| 86 |
void setValue(int); |
| 87 |
|
| 88 |
/** |
| 89 |
* @brief 设置是否显示节点 |
| 90 |
* @return |
| 91 |
*/ |
| 92 |
void setNodeVisible(bool flag); |
| 93 |
|
| 94 |
/** |
| 95 |
* @brief 获取是否显示节点 |
| 96 |
* @return |
| 97 |
*/ |
| 98 |
bool nodeVisible(); |
| 99 |
|
| 100 |
/** |
| 101 |
* @brief 设置tooltip |
| 102 |
* @since 1.2.0 |
| 103 |
*/ |
| 104 |
void setToolTip(const QString &); |
| 105 |
|
| 106 |
/** |
| 107 |
* @brief 获取toolTip |
| 108 |
* @since 1.2.0 |
| 109 |
* @return |
| 110 |
*/ |
| 111 |
QString toolTip() const; |
| 112 |
|
| 113 |
/** |
| 114 |
* @brief 设置是否启用半透明效果 |
| 115 |
* @since 1.2.0 |
| 116 |
* @param flag |
| 117 |
*/ |
| 118 |
void setTranslucent(bool flag); |
| 119 |
|
| 120 |
/** |
| 121 |
* @brief 获取是否启用半透明效果 |
| 122 |
* @since 1.2.0 |
| 123 |
* @return flag |
| 124 |
*/ |
| 125 |
bool isTranslucent(); |
| 126 |
|
| 127 |
protected: |
| 128 |
void paintEvent(QPaintEvent *event); |
| 129 |
void resizeEvent(QResizeEvent *event); |
| 130 |
void mousePressEvent(QMouseEvent *event); |
| 131 |
void mouseReleaseEvent(QMouseEvent *event); |
| 132 |
void mouseMoveEvent(QMouseEvent *event); |
| 133 |
void wheelEvent(QWheelEvent *event); |
| 134 |
bool eventFilter(QObject *watched, QEvent *event); |
| 135 |
QSize sizeHint() const override; |
| 136 |
|
| 137 |
private: |
| 138 |
KSliderPrivate *const d_ptr; |
| 139 |
|
| 140 |
Q_DISABLE_COPY(KSlider) |
| 141 |
Q_DECLARE_PRIVATE(KSlider) |
| 142 |
}; |
| 143 |
|
| 144 |
} |
| 145 |
/** |
| 146 |
* @example testslider/widget.h |
| 147 |
* @example testslider/widget.cpp |
| 148 |
* @} |
| 149 |
*/ |
| 150 |
#endif // KSLIDER_H |