| 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 KTOOLBUTTON_H |
| 24 |
#define KTOOLBUTTON_H |
| 25 |
|
| 26 |
#include "gui_g.h" |
| 27 |
#include <QEvent> |
| 28 |
#include <QToolButton> |
| 29 |
#include <QWidget> |
| 30 |
|
| 31 |
namespace kdk |
| 32 |
{ |
| 33 |
|
| 34 |
/** @defgroup PushbuttonModule |
| 35 |
* @{ |
| 36 |
*/ |
| 37 |
|
| 38 |
/** |
| 39 |
* @brief 支持三种样式,暂不支持文字显示 |
| 40 |
* @since 1.0.0 |
| 41 |
*/ |
| 42 |
enum KToolButtonType { |
| 43 |
Flat, |
| 44 |
SemiFlat, |
| 45 |
Background, |
| 46 |
Frameless |
| 47 |
}; |
| 48 |
|
| 49 |
class KToolButtonPrivate; |
| 50 |
|
| 51 |
/** |
| 52 |
* @brief 提供了一个快速访问按钮,暂不支持显示文本 |
| 53 |
*/ |
| 54 |
class GUI_EXPORT KToolButton : public QToolButton |
| 55 |
{ |
| 56 |
Q_OBJECT |
| 57 |
|
| 58 |
public: |
| 59 |
KToolButton(QWidget *parent); |
| 60 |
|
| 61 |
/** |
| 62 |
* @brief 返回类型 |
| 63 |
* @return |
| 64 |
*/ |
| 65 |
KToolButtonType type(); |
| 66 |
|
| 67 |
/** |
| 68 |
* @brief 设置类型 |
| 69 |
* @param type |
| 70 |
*/ |
| 71 |
void setType(KToolButtonType type); |
| 72 |
|
| 73 |
/** |
| 74 |
* @brief 设置Icon |
| 75 |
* @param icon |
| 76 |
*/ |
| 77 |
void setIcon(const QIcon &icon); |
| 78 |
|
| 79 |
/** |
| 80 |
* @brief 设置正在加载状态,仅不带箭头的toolbuttuon支持该状态 |
| 81 |
* @param flag |
| 82 |
*/ |
| 83 |
void setLoading(bool flag); |
| 84 |
|
| 85 |
/** |
| 86 |
* @brief 返回是否正在加载 |
| 87 |
* @return |
| 88 |
*/ |
| 89 |
bool isLoading(); |
| 90 |
|
| 91 |
/** |
| 92 |
* @brief 获取Icon |
| 93 |
* @return |
| 94 |
*/ |
| 95 |
QIcon icon(); |
| 96 |
|
| 97 |
/** |
| 98 |
* @brief 设置是否显示向下箭头,默认不显示 |
| 99 |
* @param flag |
| 100 |
*/ |
| 101 |
void setArrow(bool flag); |
| 102 |
|
| 103 |
/** |
| 104 |
* @brief 返回是否显示箭头 |
| 105 |
* @return |
| 106 |
*/ |
| 107 |
bool hasArrow() const; |
| 108 |
|
| 109 |
/** |
| 110 |
* @brief 设置图标颜色 |
| 111 |
* @param flag |
| 112 |
* @param color |
| 113 |
* @since 2.4.1.0 |
| 114 |
*/ |
| 115 |
void setIconColor(bool flag, QColor color); |
| 116 |
|
| 117 |
/** |
| 118 |
* @brief setBorderRadius |
| 119 |
* @param bottomLeft |
| 120 |
* @param topLeft |
| 121 |
* @param topRight |
| 122 |
* @param bottomRight |
| 123 |
* @since 2.5.2.0 |
| 124 |
*/ |
| 125 |
void setBorderRadius(int bottomLeft, int topLeft, int topRight, int bottomRight); |
| 126 |
|
| 127 |
/** |
| 128 |
* @brief setBackgroundColorEnabled |
| 129 |
* @param flag |
| 130 |
* @since 2.5.2.0 |
| 131 |
*/ |
| 132 |
void setBackgroundColorEnabled(bool flag); |
| 133 |
|
| 134 |
/** |
| 135 |
* @brief backgroundColorEnabled |
| 136 |
* @return |
| 137 |
* @since 2.5.2.0 |
| 138 |
*/ |
| 139 |
bool backgroundColorEnabled(); |
| 140 |
|
| 141 |
Q_SIGNALS: |
| 142 |
void checkedChanged(bool checked); |
| 143 |
|
| 144 |
protected: |
| 145 |
bool eventFilter(QObject *watched, QEvent *event); |
| 146 |
QSize sizeHint() const; |
| 147 |
void paintEvent(QPaintEvent *event); |
| 148 |
|
| 149 |
private: |
| 150 |
Q_DECLARE_PRIVATE(KToolButton) |
| 151 |
KToolButtonPrivate *const d_ptr; |
| 152 |
}; |
| 153 |
} |
| 154 |
/** |
| 155 |
* @example testtoolbutton/widget.h |
| 156 |
* @example testtoolbutton/widget.cpp |
| 157 |
* @} |
| 158 |
*/ |
| 159 |
#endif // KTOOLBUTTON_H |