126 lines
2.6 KiB
C++
126 lines
2.6 KiB
C++
#ifndef WAITWIDGET_H
|
|
|
|
#define WAITWIDGET_H
|
|
#include <QEvent>
|
|
#include <QProgressBar>
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
/// <summary>
|
|
/// 环形进度条
|
|
/// </summary>
|
|
class CircularProgressDelegate;
|
|
class CircularProgress : public QProgressBar
|
|
{
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(qreal lineWidth WRITE setLineWidth READ lineWidth)
|
|
Q_PROPERTY(qreal size WRITE setSize READ size)
|
|
Q_PROPERTY(QColor color WRITE setColor READ color)
|
|
|
|
public:
|
|
explicit CircularProgress(QWidget* parent = nullptr);
|
|
~CircularProgress();
|
|
|
|
enum ProgressType {
|
|
DeterminateProgress, // 普通进度条
|
|
IndeterminateProgress // 等待进度条
|
|
};
|
|
|
|
void setProgressType(ProgressType type);
|
|
CircularProgress::ProgressType progressType() const;
|
|
|
|
void setUseThemeColors(bool value);
|
|
bool useThemeColors() const;
|
|
|
|
void setLineWidth(qreal width);
|
|
qreal lineWidth() const;
|
|
|
|
void setSize(int size);
|
|
int size() const;
|
|
|
|
void setColor(const QColor& color);
|
|
QColor color() const;
|
|
|
|
QSize sizeHint() const Q_DECL_OVERRIDE;
|
|
|
|
protected:
|
|
void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;
|
|
|
|
private:
|
|
void init();
|
|
|
|
private:
|
|
CircularProgressDelegate* m_delegate;
|
|
ProgressType m_progressType;
|
|
QColor m_color;
|
|
qreal m_penWidth;
|
|
int m_size;
|
|
bool m_useThemeColors;
|
|
};
|
|
|
|
class CircularProgressDelegate : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(qreal dashOffset WRITE setDashOffset READ dashOffset)
|
|
Q_PROPERTY(qreal dashLength WRITE setDashLength READ dashLength)
|
|
Q_PROPERTY(int angle WRITE setAngle READ angle)
|
|
|
|
public:
|
|
CircularProgressDelegate(CircularProgress* parent);
|
|
~CircularProgressDelegate();
|
|
|
|
void setDashOffset(qreal offset);
|
|
qreal dashOffset() const;
|
|
|
|
void setDashLength(qreal length);
|
|
qreal dashLength() const;
|
|
|
|
void setAngle(int angle);
|
|
int angle() const;
|
|
|
|
private:
|
|
Q_DISABLE_COPY(CircularProgressDelegate)
|
|
|
|
CircularProgress* const m_progress;
|
|
qreal m_dashOffset;
|
|
qreal m_dashLength;
|
|
int m_angle;
|
|
};
|
|
|
|
|
|
/// <summary>
|
|
/// 掩膜等待页面
|
|
/// </summary>
|
|
class WaitProgressWidget : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
WaitProgressWidget(QWidget* parent);
|
|
~WaitProgressWidget();
|
|
void setBgColor(QColor color);
|
|
|
|
void start(int msec = 60000);
|
|
void stop(bool isOk);
|
|
|
|
signals:
|
|
void sig_finished(bool isOk);
|
|
|
|
private:
|
|
void show();// 限制外部调用show hide
|
|
void hide();
|
|
|
|
protected:
|
|
bool eventFilter(QObject* obj, QEvent* ev);
|
|
void showEvent(QShowEvent* ev);
|
|
|
|
private:
|
|
CircularProgress* m_progress;
|
|
QWidget* m_parentWidget;
|
|
QTimer* m_timer;
|
|
};
|
|
|
|
|
|
#endif //WAITWIDGET_H
|