DtkWidget 5.6.0.2
DTK Widget module
dsegmentedcontrol.h
1// SPDX-FileCopyrightText: 2015 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DSEGMENTEDCONTROL_H
6#define DSEGMENTEDCONTROL_H
7
8#include <QFrame>
9#include <QHBoxLayout>
10#include <QToolButton>
11#include <QPropertyAnimation>
12#include <QList>
13#include <QEasingCurve>
14
15#include <dtkwidget_global.h>
16#include <DObject>
17
18DWIDGET_BEGIN_NAMESPACE
19
20class LIBDTKWIDGETSHARED_EXPORT D_DECL_DEPRECATED DSegmentedHighlight : public QToolButton
21{
22 Q_OBJECT
23
24public:
25 explicit DSegmentedHighlight(QWidget *parent = 0);
26};
27
29class LIBDTKWIDGETSHARED_EXPORT D_DECL_DEPRECATED_X("Use DButtonBox") DSegmentedControl : public QWidget, public DCORE_NAMESPACE::DObject
30{
31 Q_OBJECT
32 D_DECLARE_PRIVATE(DSegmentedControl)
33
34 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged)
35 Q_PROPERTY(int count READ count)
36 Q_PROPERTY(int animationDuration READ animationDuration WRITE setAnimationDuration)
37 Q_PROPERTY(QEasingCurve::Type animationType READ animationType WRITE setAnimationType)
38public:
39 explicit DSegmentedControl(QWidget *parent = 0);
40
41 int count() const;
42 const DSegmentedHighlight *highlight() const;
43 int currentIndex() const;
44 QToolButton *at(int index) const;
45 QString getText(int index) const;
46 QIcon getIcon(int index) const;
47 int animationDuration() const;
48 int indexByTitle(const QString &title) const;
49
50 QEasingCurve::Type animationType() const;
51
52public Q_SLOTS:
53 int addSegmented(const QString &title);
54 int addSegmented(const QIcon &icon, const QString &title);
55 void addSegmented(const QStringList &titleList);
56 void addSegmented(const QList<QIcon> &iconList, const QStringList &titleList);
57 void insertSegmented(int index, const QString &title);
58 void insertSegmented(int index, const QIcon &icon, const QString &title);
59 void removeSegmented(int index);
60 void clear();
61 bool setCurrentIndex(int currentIndex);
62 bool setCurrentIndexByTitle(const QString &title);
63 void setText(int index, const QString &title);
64 void setIcon(int index, const QIcon &icon);
65 void setAnimationDuration(int animationDuration);
66 void setAnimationType(QEasingCurve::Type animationType);
67
68private Q_SLOTS:
69 void updateHighlightGeometry(bool animation = true);
70 void buttonClicked();
71
72Q_SIGNALS:
73 void currentChanged(int index);
75 void animationDurationChanged(int animationDuration);
76
77protected:
78 bool eventFilter(QObject *, QEvent *) override;
79 void resizeEvent(QResizeEvent *event) override;
80};
81
82DWIDGET_END_NAMESPACE
83#endif // DSEGMENTEDCONTROL_H
DButtonBox 类似于 QButtonGroup 的类.
Definition: dbuttonbox.h:54
Definition: dsegmentedcontrol.cpp:20
DSegmentedControl 类提供了一种类似标签页的控件.
Definition: dsegmentedcontrol.h:30
void currentChanged(int index)
信号在当前选中(高亮)的 Segment 发生改变时触发.
void animationDurationChanged(int animationDuration)
信号在高亮动画的动画周期发生改变时触发.
void currentTitleChanged(QString title)
信号在当前选中(高亮)的 Segment 发生改变时触发.
DSegmentedHighlight 类代表了 DSegmentedControl 中当前选中(即高亮)的部分.
Definition: dsegmentedcontrol.h:21