1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00

update progress bar

This commit is contained in:
AbelTian 2018-05-09 16:48:07 +08:00
parent 06e40a38af
commit 6015739058
2 changed files with 27 additions and 12 deletions

View File

@ -18,6 +18,7 @@ QQtCustomProgressBar::QQtCustomProgressBar ( QWidget* parent ) : QWidget ( paren
nullPosition = 0; nullPosition = 0;
lineWidth = 10; lineWidth = 10;
cornerRadius = 10; cornerRadius = 10;
lineCapStyle = Qt::RoundCap;
showPercent = true; showPercent = true;
showFree = false; showFree = false;
@ -162,7 +163,7 @@ void QQtCustomProgressBar::drawArc ( QPainter* painter, int radius )
pen.setWidthF ( lineWidth ); pen.setWidthF ( lineWidth );
/*这里可以更改画笔样式更换线条风格*/ /*这里可以更改画笔样式更换线条风格*/
pen.setCapStyle ( Qt::RoundCap ); pen.setCapStyle ( ( Qt::PenCapStyle ) lineCapStyle );
double arcLength = 360.0 / ( maxValue - minValue ) * ( value - minValue ); double arcLength = 360.0 / ( maxValue - minValue ) * ( value - minValue );
QRect rect ( -radius, -radius, radius * 2, radius * 2 ); QRect rect ( -radius, -radius, radius * 2, radius * 2 );
@ -591,6 +592,15 @@ void QQtCustomProgressBar::setLineWidth ( int lineWidth )
} }
} }
void QQtCustomProgressBar::setLineCapStyle ( int lineCapStyle )
{
if ( this->lineCapStyle != lineCapStyle )
{
this->lineCapStyle = lineCapStyle;
update();
}
}
void QQtCustomProgressBar::setShowPercent ( bool showPercent ) void QQtCustomProgressBar::setShowPercent ( bool showPercent )
{ {
if ( this->showPercent != showPercent ) if ( this->showPercent != showPercent )

View File

@ -55,6 +55,7 @@ class QQTSHARED_EXPORT QQtCustomProgressBar : public QWidget
Q_PROPERTY ( int nullPosition READ getNullPosition WRITE setNullPosition ) Q_PROPERTY ( int nullPosition READ getNullPosition WRITE setNullPosition )
Q_PROPERTY ( int lineWidth READ getLineWidth WRITE setLineWidth ) Q_PROPERTY ( int lineWidth READ getLineWidth WRITE setLineWidth )
Q_PROPERTY ( int cornerRadius READ getCornerRaduis WRITE setCornerRadius ) Q_PROPERTY ( int cornerRadius READ getCornerRaduis WRITE setCornerRadius )
Q_PROPERTY ( int lineCapStyle READ getLineCapStyle WRITE setLineCapStyle )
Q_PROPERTY ( bool showPercent READ getShowPercent WRITE setShowPercent ) Q_PROPERTY ( bool showPercent READ getShowPercent WRITE setShowPercent )
Q_PROPERTY ( bool showFree READ getShowFree WRITE setShowFree ) Q_PROPERTY ( bool showFree READ getShowFree WRITE setShowFree )
@ -112,11 +113,11 @@ public:
enum TextStyle enum TextStyle
{ {
TextStyle_None = 0, /*不显示*/ TextStyle_None = 0, /*不显示*/
TextStyle_Middle_Percent = 1, /*只在中央显示百分比*/ TextStyle_Middle_Percent = 1, /*只在中央显示百分比*/
TextStyle_Percent = 2, /*只显示百分比*/ TextStyle_Percent = 2, /*只在下部显示百分比*/
TextStyle_Text = 3, /*只显示文字*/ TextStyle_Text = 3, /*不在下部显示百分比,在中央显示文字*/
TextStyle_Percent_Text = 4, /*显示百分比和文字*/ TextStyle_Percent_Text = 4, /*和在下部显示百分比在中央显示文字*/
}; };
explicit QQtCustomProgressBar ( QWidget* parent = 0 ); explicit QQtCustomProgressBar ( QWidget* parent = 0 );
@ -130,6 +131,7 @@ public:
int getNullPosition() const; int getNullPosition() const;
int getLineWidth() const; int getLineWidth() const;
int getCornerRaduis() const { return cornerRadius; } int getCornerRaduis() const { return cornerRadius; }
int getLineCapStyle() const { return lineCapStyle; }
bool getShowPercent() const; bool getShowPercent() const;
bool getShowFree() const; bool getShowFree() const;
@ -176,6 +178,8 @@ public Q_SLOTS:
void setNullPosition ( int nullPosition ); void setNullPosition ( int nullPosition );
/*设置线条宽度*/ /*设置线条宽度*/
void setLineWidth ( int lineWidth ); void setLineWidth ( int lineWidth );
/*设置线条的帽子(线头)的样式 = Qt::PenCapStyle*/
void setLineCapStyle ( int lineCapStyle );
/*设置是否显示百分比*/ /*设置是否显示百分比*/
void setShowPercent ( bool showPercent ); void setShowPercent ( bool showPercent );
@ -231,13 +235,13 @@ signals:
public slots: public slots:
protected: protected:
void paintEvent ( QPaintEvent* ); virtual void paintEvent ( QPaintEvent* );
void drawBackground ( QPainter* painter, int radius ); virtual void drawBackground ( QPainter* painter, int radius );
void drawArc ( QPainter* painter, int radius ); virtual void drawArc ( QPainter* painter, int radius );
void drawPolo ( QPainter* painter, int radius ); virtual void drawPolo ( QPainter* painter, int radius );
void drawWave ( QPainter* painter, int radius ); virtual void drawWave ( QPainter* painter, int radius );
void drawText ( QPainter* painter, int radius ); virtual void drawText ( QPainter* painter, int radius );
void drawPercentText ( QPainter* painter, int radius ); virtual void drawPercentText ( QPainter* painter, int radius );
private: private:
int maxValue; /*最小值*/ int maxValue; /*最小值*/
@ -246,6 +250,7 @@ private:
int nullPosition; /*起始角度*/ int nullPosition; /*起始角度*/
int lineWidth; /*线条宽度*/ int lineWidth; /*线条宽度*/
int lineCapStyle; /*线条的帽子(线头)的样式*/
bool showPercent; /*是否显示百分比*/ bool showPercent; /*是否显示百分比*/
QString text; /*文字*/ QString text; /*文字*/