| 1 |
/* |
| 2 |
* Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co.,Ltd. |
| 3 |
* |
| 4 |
* Author: Ji XiangLong <[email protected]> |
| 5 |
* |
| 6 |
* Maintainer: WangYu <[email protected]> |
| 7 |
* |
| 8 |
* This program is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* This program is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef TOOLBUTTON_H |
| 23 |
#define TOOLBUTTON_H |
| 24 |
|
| 25 |
#include <QWidget> |
| 26 |
#include <DPushButton> |
| 27 |
#include <QSvgRenderer> |
| 28 |
|
| 29 |
DWIDGET_USE_NAMESPACE |
| 30 |
|
| 31 |
class ToolButton : public DPushButton |
| 32 |
{ |
| 33 |
Q_OBJECT |
| 34 |
public: |
| 35 |
|
| 36 |
/** |
| 37 |
* @description: ToolButton 构造函数 |
| 38 |
*/ |
| 39 |
explicit ToolButton(QWidget *parent = nullptr); |
| 40 |
|
| 41 |
/** |
| 42 |
* @description: setText 设置控件显示的文字 |
| 43 |
*/ |
| 44 |
void setText(const QString &text); |
| 45 |
|
| 46 |
/** |
| 47 |
* @description: setIcon 设置控件显示的图标 |
| 48 |
*/ |
| 49 |
void setLIcon(const QIcon &icon); |
| 50 |
void setRIcon(const QIcon &icon); |
| 51 |
void setRWIcon(const QString &path); |
| 52 |
|
| 53 |
|
| 54 |
QIcon lIcon() |
| 55 |
{ |
| 56 |
return m_Licon; |
| 57 |
} |
| 58 |
|
| 59 |
QIcon rIcon() |
| 60 |
{ |
| 61 |
return m_Ricon; |
| 62 |
} |
| 63 |
|
| 64 |
QString text() |
| 65 |
{ |
| 66 |
return m_text; |
| 67 |
} |
| 68 |
|
| 69 |
signals: |
| 70 |
void focusStatusChanged(bool); |
| 71 |
|
| 72 |
protected: |
| 73 |
/** |
| 74 |
* @description: paintEvent 重新绘制控件的样式 |
| 75 |
*/ |
| 76 |
void paintEvent(QPaintEvent *e) override; |
| 77 |
|
| 78 |
void focusInEvent(QFocusEvent *e) override; |
| 79 |
void focusOutEvent(QFocusEvent *e) override; |
| 80 |
|
| 81 |
private: |
| 82 |
//用于绘制的文字 |
| 83 |
QString m_text; |
| 84 |
|
| 85 |
//用于绘制的图片 |
| 86 |
QIcon m_Licon; |
| 87 |
QIcon m_Ricon; |
| 88 |
QIcon m_RiconWhite; |
| 89 |
}; |
| 90 |
|
| 91 |
#endif // TOOLBUTTON_H |