Refurbish the shaped clock example

The shaped clock example has the appearance of the analog clock, which
was refurbished with 619ec1a640. This
change applies the refurbished design to the shaped clock.

Task: QTBUG-118871

Pick-to: 6.6
Change-Id: Ibcfc8e9fb239a1c6f7ea685f6cab1e50b2060a53
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Matthias Rauter 2023-11-13 10:46:00 +01:00
parent b3eb951d18
commit f6e7fdd4ad
3 changed files with 34 additions and 21 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 57 KiB

View File

@ -54,23 +54,30 @@ void ShapedClock::mouseMoveEvent(QMouseEvent *event)
//! [3] //! [3]
void ShapedClock::paintEvent(QPaintEvent *) void ShapedClock::paintEvent(QPaintEvent *)
{ {
static const QPoint hourHand[3] = { static const QPoint hourHand[4] = {
QPoint(7, 8), QPoint(5, 14),
QPoint(-7, 8), QPoint(-5, 14),
QPoint(0, -40) QPoint(-4, -71),
QPoint(4, -71)
}; };
static const QPoint minuteHand[3] = { static const QPoint minuteHand[4] = {
QPoint(7, 8), QPoint(4, 14),
QPoint(-7, 8), QPoint(-4, 14),
QPoint(0, -70) QPoint(-3, -89),
QPoint(3, -89)
};
static const QPoint secondsHand[4] = {
QPoint(1, 14),
QPoint(-1, 14),
QPoint(-1, -89),
QPoint(1, -89)
}; };
QColor hourColor(127, 0, 127); const QColor hourColor(palette().color(QPalette::Text));
QColor minuteColor(0, 127, 127, 191); const QColor minuteColor(palette().color(QPalette::Text));
const QColor secondsColor(palette().color(QPalette::Accent));
int side = qMin(width(), height()); int side = qMin(width(), height());
QTime time = QTime::currentTime();
QPainter painter(this); QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::Antialiasing);
painter.translate(width() / 2, height() / 2); painter.translate(width() / 2, height() / 2);
@ -82,34 +89,40 @@ void ShapedClock::paintEvent(QPaintEvent *)
painter.drawEllipse(QPoint(0, 0), 98, 98); painter.drawEllipse(QPoint(0, 0), 98, 98);
painter.setOpacity(1.0); painter.setOpacity(1.0);
QTime time = QTime::currentTime();
painter.setPen(Qt::NoPen); painter.setPen(Qt::NoPen);
painter.setBrush(hourColor); painter.setBrush(hourColor);
painter.save(); painter.save();
painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0))); painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
painter.drawConvexPolygon(hourHand, 3); painter.drawConvexPolygon(hourHand, 4);
painter.restore(); painter.restore();
painter.setPen(hourColor);
for (int i = 0; i < 12; ++i) { for (int i = 0; i < 12; ++i) {
painter.drawLine(88, 0, 96, 0); painter.drawRect(73, -3, 16, 6);
painter.rotate(30.0); painter.rotate(30.0);
} }
painter.setPen(Qt::NoPen);
painter.setBrush(minuteColor); painter.setBrush(minuteColor);
painter.save(); painter.save();
painter.rotate(6.0 * (time.minute() + time.second() / 60.0)); painter.rotate(6.0 * time.minute());
painter.drawConvexPolygon(minuteHand, 3); painter.drawConvexPolygon(minuteHand, 4);
painter.restore();
painter.setBrush(secondsColor);
painter.save();
painter.rotate(6.0 * time.second());
painter.drawConvexPolygon(secondsHand, 4);
painter.drawEllipse(-3, -3, 6, 6);
painter.drawEllipse(-5, -68, 10, 10);
painter.restore(); painter.restore();
painter.setPen(minuteColor); painter.setPen(minuteColor);
for (int j = 0; j < 60; ++j) { for (int j = 0; j < 60; ++j) {
if ((j % 5) != 0) painter.drawLine(92, 0, 96, 0);
painter.drawLine(92, 0, 96, 0);
painter.rotate(6.0); painter.rotate(6.0);
} }
} }