47 elapsedSec = timeoutSec;
48 progressActive =
false;
50 setToolTip(QString(
"Execute"));
52 if (resetColorTimer.isActive())
53 resetColorTimer.stop();
54 QColor color = failed ? QColor(Qt::red) : QColor(Qt::green);
55 this->originalStyle = styleSheet();
56 setStyleSheet(QString(
"background-color: %1").arg(color.name()));
58 resetColorTimer.setSingleShot(
true);
59 connect(&resetColorTimer, &QTimer::timeout,
this, [
this]() { setStyleSheet(originalStyle); });
60 resetColorTimer.start(1000);
81 QString fullText = text();
82 QFontMetrics metrics(font());
83 int textWidth = width() - 6;
84 QString elided = metrics.elidedText(fullText, Qt::ElideRight, textWidth);
88 QPushButton::paintEvent(event);
93 if (!progressActive || timeoutSec <= 0.0)
97 p.setRenderHint(QPainter::Antialiasing);
99 double percent = std::min(1.0, elapsedSec / timeoutSec);
101 int barHeight = height() * 0.25;
102 int barWidth =
static_cast<int>(width() * percent);
104 QRect barRect(0, height() - barHeight, barWidth, barHeight);
106 QLinearGradient grad(barRect.topLeft(), barRect.topRight());
107 grad.setColorAt(0.0, QColor(180, 40, 40));
108 grad.setColorAt(1.0, QColor(255, 80, 80));
110 p.fillRect(barRect, grad);