DtkWidget 5.6.0.2
DTK Widget module
dslider.h
1// SPDX-FileCopyrightText: 2011 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DSLIDER_H
6#define DSLIDER_H
7
8#include <QWidget>
9#include <QSlider>
10#include <QStyleOption>
11#include <QPainter>
12
13#include <dtkwidget_global.h>
14#include <dobject.h>
15
16DWIDGET_BEGIN_NAMESPACE
17
18class DSliderPrivate;
19class LIBDTKWIDGETSHARED_EXPORT DSlider : public QWidget, public DTK_CORE_NAMESPACE::DObject
20{
21 Q_OBJECT
22 Q_DISABLE_COPY(DSlider)
23 D_DECLARE_PRIVATE(DSlider)
24public:
25 enum SliderIcons {
26 LeftIcon,
27 RightIcon
28 };
29 DSlider(Qt::Orientation orientation = Qt::Horizontal, QWidget *parent = nullptr);
30
31 Qt::Orientation orientation() const;
32
33 QSlider *slider();
34
35 void setLeftIcon(const QIcon &left);
36 void setRightIcon(const QIcon &right);
37
38 void setIconSize(const QSize &size);
39
40 void setMinimum(int min);
41 int minimum() const;
42
43 void setValue(int value);
44 int value() const;
45
46 void setPageStep(int pageStep);
47 int pageStep() const;
48
49 void setMaximum(int max);
50 int maximum() const;
51
52 void setLeftTicks(const QStringList &info);
53 void setRightTicks(const QStringList &info);
54
55 void setAboveTicks(const QStringList &info);
56 void setBelowTicks(const QStringList &info);
57
58 void setMarkPositions(QList<int> list);
59
60 void setMouseWheelEnabled(bool enabled);
61
62 void setTipValue(const QString &value);
63
64 QSlider::TickPosition tickPosition() const;
65 QSize sizeHint() const override;
66
67 void setHandleVisible(bool b);
68 bool handleVisible() const;
69
70 void setEnabledAcrossStyle(bool enabled);
71
72Q_SIGNALS:
73 void valueChanged(int value);
74
75 void sliderPressed();
76 void sliderMoved(int position);
78
79 void rangeChanged(int min, int max);
80
81 void actionTriggered(int action);
82 void iconClicked(SliderIcons icon, bool checked);
83
84protected:
85 DSlider(DSliderPrivate &q, QWidget *parent);
86
87 bool event(QEvent *event) override;
88 bool eventFilter(QObject *watched, QEvent *event) override;
89};
90
91class SpecialSlider : public QSlider {
92public:
93 SpecialSlider(Qt::Orientation orientation, QWidget *parent = nullptr) : QSlider(orientation, parent) {
94 }
95
96 void paintEvent(QPaintEvent *ev) {
97 Q_UNUSED(ev)
98 QPainter p(this);
99 QStyleOptionSlider opt;
100 initStyleOption(&opt);
101
102 DSlider* dSlider = qobject_cast<DSlider *>(this->parent());
103
104 if (!dSlider)
105 return;
106
107 if (dSlider->handleVisible())
108 opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle;
109 else
110 opt.subControls = QStyle::SC_SliderGroove;
111
112 style()->drawComplexControl(QStyle::CC_Slider, &opt, &p, parentWidget());
113 }
114};
115
116DWIDGET_END_NAMESPACE
117
118#endif // DSLIDER_H
Definition: dslider_p.h:21
DSlider一个聚合 QSlider 的滑块.
Definition: dslider.h:20
void iconClicked(SliderIcons icon, bool checked)
信号会在左右 iconbutton 被点击时被发送.
void sliderReleased()
信号会在 slider 被松开时被发送.
void sliderMoved(int position)
信号会在 slider 拖动时被发送.
void rangeChanged(int min, int max)
信号会在 range 属性的值改变时被发送.
bool handleVisible() const
获取滑块是否显示的状态.
Definition: dslider.cpp:654
void actionTriggered(int action)
信号会在 slider action 触发时被发送
void valueChanged(int value)
信号会在 slider value 属性的值改变时被发送.
Definition: dslider.h:91
Orientation