chore: 格式化ElaWidgetTools代码
This commit is contained in:
@@ -10,32 +10,28 @@ Q_PROPERTY_CREATE_Q_CPP(ElaProgressRing, bool, IsTransparent)
|
||||
Q_PROPERTY_CREATE_Q_CPP(ElaProgressRing, bool, IsDisplayValue)
|
||||
Q_PROPERTY_CREATE_Q_CPP(ElaProgressRing, ElaProgressRingType::ValueDisplayMode, ValueDisplayMode)
|
||||
Q_PROPERTY_CREATE_Q_CPP(ElaProgressRing, int, ValuePixelSize)
|
||||
ElaProgressRing::ElaProgressRing(QWidget* parent)
|
||||
: QWidget(parent), d_ptr(new ElaProgressRingPrivate())
|
||||
{
|
||||
ElaProgressRing::ElaProgressRing(QWidget *parent) : QWidget(parent), d_ptr(new ElaProgressRingPrivate()) {
|
||||
Q_D(ElaProgressRing);
|
||||
d->q_ptr = this;
|
||||
d->_pIsDisplayValue = true;
|
||||
d->_pValuePixelSize = 17;
|
||||
d->_pValueDisplayMode = ElaProgressRingType::ValueDisplayMode::Actual;
|
||||
d->_pMinimum = 0;
|
||||
d->_pMaximum = 100;
|
||||
d->_pValue = 0;
|
||||
d->_pBusyIndex = 0xe100;
|
||||
d->q_ptr = this;
|
||||
d->_pIsDisplayValue = true;
|
||||
d->_pValuePixelSize = 17;
|
||||
d->_pValueDisplayMode = ElaProgressRingType::ValueDisplayMode::Actual;
|
||||
d->_pMinimum = 0;
|
||||
d->_pMaximum = 100;
|
||||
d->_pValue = 0;
|
||||
d->_pBusyIndex = 0xe100;
|
||||
d->_pBusyingDurationTime = 1000;
|
||||
d->_pBusyingWidth = 6;
|
||||
d->_pBusyStartDeg = 0;
|
||||
d->_pBusyContentDeg = 0;
|
||||
d->_pIsBusying = false;
|
||||
d->_pIsTransparent = false;
|
||||
d->_pBusyingWidth = 6;
|
||||
d->_pBusyStartDeg = 0;
|
||||
d->_pBusyContentDeg = 0;
|
||||
d->_pIsBusying = false;
|
||||
d->_pIsTransparent = false;
|
||||
setFixedSize(70, 70);
|
||||
setObjectName("ElaProgressRing");
|
||||
setStyleSheet("#ElaProgressRing{background-color:transparent;}");
|
||||
|
||||
d->_busyStartDegAnimation = new QPropertyAnimation(d, "pBusyStartDeg");
|
||||
connect(d->_busyStartDegAnimation, &QPropertyAnimation::valueChanged, this, [=]() {
|
||||
update();
|
||||
});
|
||||
connect(d->_busyStartDegAnimation, &QPropertyAnimation::valueChanged, this, [=]() { update(); });
|
||||
d->_busyStartDegAnimation->setEasingCurve(QEasingCurve::Linear);
|
||||
d->_busyStartDegAnimation->setDuration(1000);
|
||||
d->_busyStartDegAnimation->setStartValue(0);
|
||||
@@ -57,21 +53,15 @@ ElaProgressRing::ElaProgressRing(QWidget* parent)
|
||||
});
|
||||
}
|
||||
|
||||
ElaProgressRing::~ElaProgressRing()
|
||||
{
|
||||
}
|
||||
ElaProgressRing::~ElaProgressRing() {}
|
||||
|
||||
void ElaProgressRing::setIsBusying(bool isBusying)
|
||||
{
|
||||
void ElaProgressRing::setIsBusying(bool isBusying) {
|
||||
Q_D(ElaProgressRing);
|
||||
d->_pIsBusying = isBusying;
|
||||
if (isBusying)
|
||||
{
|
||||
if (isBusying) {
|
||||
d->_busyStartDegAnimation->start();
|
||||
d->_busyContentDegAnimation->start();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
d->_busyStartDegAnimation->stop();
|
||||
d->_busyContentDegAnimation->stop();
|
||||
}
|
||||
@@ -79,42 +69,36 @@ void ElaProgressRing::setIsBusying(bool isBusying)
|
||||
Q_EMIT pIsBusyingChanged();
|
||||
}
|
||||
|
||||
bool ElaProgressRing::getIsBusying() const
|
||||
{
|
||||
bool ElaProgressRing::getIsBusying() const {
|
||||
Q_D(const ElaProgressRing);
|
||||
return d->_pIsBusying;
|
||||
}
|
||||
|
||||
void ElaProgressRing::setBusyingWidth(int width)
|
||||
{
|
||||
void ElaProgressRing::setBusyingWidth(int width) {
|
||||
Q_D(ElaProgressRing);
|
||||
d->_pBusyingWidth = width;
|
||||
update();
|
||||
Q_EMIT pBusyingWidthChanged();
|
||||
}
|
||||
|
||||
int ElaProgressRing::getBusyingWidth() const
|
||||
{
|
||||
int ElaProgressRing::getBusyingWidth() const {
|
||||
Q_D(const ElaProgressRing);
|
||||
return d->_pBusyingWidth;
|
||||
}
|
||||
|
||||
void ElaProgressRing::setBusyingDurationTime(int busyingDurationTime)
|
||||
{
|
||||
void ElaProgressRing::setBusyingDurationTime(int busyingDurationTime) {
|
||||
Q_D(ElaProgressRing);
|
||||
d->_pBusyingDurationTime = busyingDurationTime;
|
||||
d->_busyStartDegAnimation->setDuration(d->_pBusyingDurationTime);
|
||||
Q_EMIT pBusyingDurationTimeChanged();
|
||||
}
|
||||
|
||||
int ElaProgressRing::getBusyingDurationTime() const
|
||||
{
|
||||
int ElaProgressRing::getBusyingDurationTime() const {
|
||||
Q_D(const ElaProgressRing);
|
||||
return d->_pBusyingDurationTime;
|
||||
}
|
||||
|
||||
void ElaProgressRing::setMinimum(int minimum)
|
||||
{
|
||||
void ElaProgressRing::setMinimum(int minimum) {
|
||||
Q_D(ElaProgressRing);
|
||||
d->_pMinimum = minimum;
|
||||
update();
|
||||
@@ -122,14 +106,12 @@ void ElaProgressRing::setMinimum(int minimum)
|
||||
Q_EMIT rangeChanged(d->_pMinimum, d->_pMaximum);
|
||||
}
|
||||
|
||||
int ElaProgressRing::getMinimum() const
|
||||
{
|
||||
int ElaProgressRing::getMinimum() const {
|
||||
Q_D(const ElaProgressRing);
|
||||
return d->_pMinimum;
|
||||
}
|
||||
|
||||
void ElaProgressRing::setMaximum(int maximum)
|
||||
{
|
||||
void ElaProgressRing::setMaximum(int maximum) {
|
||||
Q_D(ElaProgressRing);
|
||||
d->_pMaximum = maximum;
|
||||
update();
|
||||
@@ -137,17 +119,14 @@ void ElaProgressRing::setMaximum(int maximum)
|
||||
Q_EMIT rangeChanged(d->_pMinimum, d->_pMaximum);
|
||||
}
|
||||
|
||||
int ElaProgressRing::getMaximum() const
|
||||
{
|
||||
int ElaProgressRing::getMaximum() const {
|
||||
Q_D(const ElaProgressRing);
|
||||
return d->_pMaximum;
|
||||
}
|
||||
|
||||
void ElaProgressRing::setValue(int value)
|
||||
{
|
||||
void ElaProgressRing::setValue(int value) {
|
||||
Q_D(ElaProgressRing);
|
||||
if (value < d->_pMinimum || value > d->_pMaximum)
|
||||
{
|
||||
if (value < d->_pMinimum || value > d->_pMaximum) {
|
||||
return;
|
||||
}
|
||||
d->_pValue = value;
|
||||
@@ -155,17 +134,14 @@ void ElaProgressRing::setValue(int value)
|
||||
Q_EMIT pValueChanged();
|
||||
}
|
||||
|
||||
int ElaProgressRing::getValue() const
|
||||
{
|
||||
int ElaProgressRing::getValue() const {
|
||||
Q_D(const ElaProgressRing);
|
||||
return d->_pValue;
|
||||
}
|
||||
|
||||
void ElaProgressRing::setRange(int min, int max)
|
||||
{
|
||||
void ElaProgressRing::setRange(int min, int max) {
|
||||
Q_D(ElaProgressRing);
|
||||
if (min < 0 || max < 0 || min > max)
|
||||
{
|
||||
if (min < 0 || max < 0 || min > max) {
|
||||
return;
|
||||
}
|
||||
d->_pMinimum = min;
|
||||
@@ -176,23 +152,18 @@ void ElaProgressRing::setRange(int min, int max)
|
||||
Q_EMIT rangeChanged(min, max);
|
||||
}
|
||||
|
||||
void ElaProgressRing::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
void ElaProgressRing::paintEvent(QPaintEvent *event) {
|
||||
Q_D(ElaProgressRing);
|
||||
QPainter painter(this);
|
||||
painter.save();
|
||||
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing);
|
||||
// 文字绘制
|
||||
if (d->_pIsDisplayValue && !d->_pIsBusying)
|
||||
{
|
||||
if (d->_pIsDisplayValue && !d->_pIsBusying) {
|
||||
painter.setPen(ElaThemeColor(d->_themeMode, BasicText));
|
||||
QString valueText;
|
||||
if (d->_pValueDisplayMode == ElaProgressRingType::ValueDisplayMode::Actual)
|
||||
{
|
||||
if (d->_pValueDisplayMode == ElaProgressRingType::ValueDisplayMode::Actual) {
|
||||
valueText = QString::number(d->_pValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
valueText = QString::number(d->_pValue / (qreal)(d->_pMaximum - d->_pMinimum) * 100) + "%";
|
||||
}
|
||||
painter.drawText(rect(), Qt::AlignCenter | Qt::TextSingleLine, valueText);
|
||||
@@ -207,19 +178,15 @@ void ElaProgressRing::paintEvent(QPaintEvent* event)
|
||||
painter.setClipPath(basePath.subtracted(maskPath));
|
||||
painter.setPen(Qt::NoPen);
|
||||
// 底色
|
||||
if (!d->_pIsTransparent)
|
||||
{
|
||||
if (!d->_pIsTransparent) {
|
||||
painter.setBrush(ElaThemeColor(d->_themeMode, BasicBaseDeep));
|
||||
painter.drawEllipse(ringRect);
|
||||
}
|
||||
// 环
|
||||
painter.setBrush(ElaThemeColor(d->_themeMode, PrimaryNormal));
|
||||
if (d->_pIsBusying)
|
||||
{
|
||||
if (d->_pIsBusying) {
|
||||
painter.drawPie(ringRect, -d->_pBusyStartDeg * 16, d->_pBusyContentDeg * 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
qreal valueDeg = d->_pValue / (qreal)(d->_pMaximum - d->_pMinimum) * 360;
|
||||
painter.drawPie(ringRect, 90 * 16, -valueDeg * 16);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user