| 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 KSWITCHBUTTON_H |
| 24 |
#define KSWITCHBUTTON_H |
| 25 |
|
| 26 |
#include "gui_g.h" |
| 27 |
#include <QGSettings/QGSettings> |
| 28 |
#include <QPainter> |
| 29 |
#include <QPushButton> |
| 30 |
#include <QTimer> |
| 31 |
|
| 32 |
namespace kdk |
| 33 |
{ |
| 34 |
|
| 35 |
/** @defgroup PushbuttonModule |
| 36 |
* @{ |
| 37 |
*/ |
| 38 |
|
| 39 |
class KSwitchButtonPrivate; |
| 40 |
|
| 41 |
/** |
| 42 |
* @brief 指示打开/关闭两种状态 |
| 43 |
* @since 1.0.0 |
| 44 |
*/ |
| 45 |
class GUI_EXPORT KSwitchButton : public QPushButton |
| 46 |
{ |
| 47 |
Q_OBJECT |
| 48 |
|
| 49 |
public: |
| 50 |
KSwitchButton(QWidget *parent = 0); |
| 51 |
~KSwitchButton(); |
| 52 |
|
| 53 |
/** |
| 54 |
* @brief 设置是否可选中 |
| 55 |
*/ |
| 56 |
void setCheckable(bool); |
| 57 |
|
| 58 |
/** |
| 59 |
* @brief 返回是否可选中 |
| 60 |
* @return |
| 61 |
*/ |
| 62 |
bool isCheckable() const; |
| 63 |
|
| 64 |
/** |
| 65 |
* @brief 返回是否选中 |
| 66 |
* @return |
| 67 |
*/ |
| 68 |
bool isChecked() const; |
| 69 |
|
| 70 |
/** |
| 71 |
* @brief 设置是否选中 |
| 72 |
* @return |
| 73 |
*/ |
| 74 |
void setChecked(bool); |
| 75 |
|
| 76 |
/** |
| 77 |
* @brief 设置是否启用半透明效果 |
| 78 |
* @since 1.2.0 |
| 79 |
* @param flag |
| 80 |
*/ |
| 81 |
void setTranslucent(bool flag); |
| 82 |
|
| 83 |
/** |
| 84 |
* @brief 获取是否启用半透明效果 |
| 85 |
* @since 1.2.0 |
| 86 |
* @return flag |
| 87 |
*/ |
| 88 |
bool isTranslucent(); |
| 89 |
|
| 90 |
Q_SIGNALS: |
| 91 |
/** |
| 92 |
* @brief 当选中状态发生变化时,发出此信号 |
| 93 |
*/ |
| 94 |
void stateChanged(bool); |
| 95 |
|
| 96 |
protected: |
| 97 |
void paintEvent(QPaintEvent *event) override; |
| 98 |
void resizeEvent(QResizeEvent *event) override; |
| 99 |
QSize sizeHint() const; |
| 100 |
|
| 101 |
private: |
| 102 |
Q_DECLARE_PRIVATE(KSwitchButton) |
| 103 |
KSwitchButtonPrivate *const d_ptr; |
| 104 |
}; |
| 105 |
|
| 106 |
} |
| 107 |
/** |
| 108 |
* @example testSwitchbutton/widget.h |
| 109 |
* @example testSwitchbutton/widget.cpp |
| 110 |
* @} |
| 111 |
*/ |
| 112 |
#endif // KSWITCHBUTTON_H |