qt/LedOK/base/customprogressindicator.h

117 lines
2.9 KiB
C
Raw Normal View History

2022-01-04 18:11:48 +08:00
#ifndef CUSTOMPROGRESSINDICATOR_H
#define CUSTOMPROGRESSINDICATOR_H
#include <QWidget>
#include <QColor>
#include <QTimer>
/*
*
*
* 727057301@qq.com
* 201721016:26:48
* QT版本5.0.2
* CSDNhttp://blog.csdn.net/csnd_ayo
* **************************************
*
* 使QT.pro中加入 C++11
*
*
pIndicator = new CustomProgressIndicator(this);
pIndicator->setColor(Qt::red);
pIndicator->startAnimation();
*/
class CustomProgressIndicator : public QWidget
{
Q_OBJECT
Q_PROPERTY(int delay READ animationDelay WRITE setAnimationDelay)
Q_PROPERTY(bool displayedWhenStopped READ isDisplayedWhenStopped WRITE setDisplayedWhenStopped)
Q_PROPERTY(QColor color READ color WRITE setColor)
public:
CustomProgressIndicator(QWidget* parent = nullptr);
int animationDelay() const { return delay_; }
/* 动画是否正在进行中 */
bool isAnimated () const;
/* 动画完毕后,是否隐藏菊花转 */
bool isDisplayedWhenStopped() const;
/* 当前菊花转的颜色 */
const QColor & color() const { return color_; }
/* 虚函数:当前大小 */
virtual QSize sizeHint() const;
void setBackground(const QString& _icon) {
currentPix_ = QPixmap(_icon);
}
signals:
void Finished(void);
public slots:
/* 开始动画 */
void startAnimation();
/* 停止动画 */
void stopAnimation();
/* 设置停止菊花,显示圆圈加对号*/
void setDisplayStringInfo(QString strTip,QString strTiping);
void setDisplayModel(int iFlag);//iFlag 0:表示进度统计1表示strTiping提示结束后显示strTip
/* 设置菊花转的转速 */
void setAnimationDelay(int delay);
/* 动画完毕后,是否隐藏菊花转 */
void setDisplayedWhenStopped(bool state);
/* 设置菊花转颜色 */
void setColor(const QColor & color);
/*
*
* _progress 0 < _progress < 100
*/
void onProgress(QString msg, int _progress, bool done)
{
Q_UNUSED(msg)
progress_ = _progress;
if(done)
{
progress_=100;
}
}
protected:
/* 系统基类函数 */
virtual void timerEvent(QTimerEvent * event);
virtual void paintEvent(QPaintEvent * event);
void drawJuHua(QPainter *painter);
private:
/* 角度 */
unsigned int angle_;
/* 定时器ID */
int timerId_;
/* 转速 */
int delay_;
/* 是否隐藏 */
bool displayedWhenStopped_;
/* 菊花转颜色 */
QColor color_;
/* 进度 */
int progress_;
/* 背景图 */
QPixmap currentPix_;
/*显示圆圈中的字符串内容*/
QString m_strTip = "";
QString m_strTiping = "";
int m_iLoopBackFlag = 0;
};
#endif // CUSTOMPROGRESSINDICATOR_H