summaryrefslogtreecommitdiffstats
path: root/examples/widgets/widgets/shapedclock
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/widgets/shapedclock')
-rw-r--r--examples/widgets/widgets/shapedclock/CMakeLists.txt34
-rw-r--r--examples/widgets/widgets/shapedclock/shapedclock.cpp69
-rw-r--r--examples/widgets/widgets/shapedclock/shapedclock.h1
3 files changed, 56 insertions, 48 deletions
diff --git a/examples/widgets/widgets/shapedclock/CMakeLists.txt b/examples/widgets/widgets/shapedclock/CMakeLists.txt
index ac2446b8fb..dd8dc217ef 100644
--- a/examples/widgets/widgets/shapedclock/CMakeLists.txt
+++ b/examples/widgets/widgets/shapedclock/CMakeLists.txt
@@ -1,16 +1,13 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
cmake_minimum_required(VERSION 3.16)
project(shapedclock LANGUAGES CXX)
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/shapedclock")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
+qt_standard_project_setup()
+
qt_add_executable(shapedclock
main.cpp
shapedclock.cpp shapedclock.h
@@ -21,14 +18,21 @@ set_target_properties(shapedclock PROPERTIES
MACOSX_BUNDLE TRUE
)
-target_link_libraries(shapedclock PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Widgets
+target_link_libraries(shapedclock PRIVATE
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Widgets
)
install(TARGETS shapedclock
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET shapedclock
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/widgets/widgets/shapedclock/shapedclock.cpp b/examples/widgets/widgets/shapedclock/shapedclock.cpp
index 5cc4a54016..106b3454a6 100644
--- a/examples/widgets/widgets/shapedclock/shapedclock.cpp
+++ b/examples/widgets/widgets/shapedclock/shapedclock.cpp
@@ -54,23 +54,30 @@ void ShapedClock::mouseMoveEvent(QMouseEvent *event)
//! [3]
void ShapedClock::paintEvent(QPaintEvent *)
{
- static const QPoint hourHand[3] = {
- QPoint(7, 8),
- QPoint(-7, 8),
- QPoint(0, -40)
+ static const QPoint hourHand[4] = {
+ QPoint(5, 14),
+ QPoint(-5, 14),
+ QPoint(-4, -71),
+ QPoint(4, -71)
};
- static const QPoint minuteHand[3] = {
- QPoint(7, 8),
- QPoint(-7, 8),
- QPoint(0, -70)
+ static const QPoint minuteHand[4] = {
+ QPoint(4, 14),
+ QPoint(-4, 14),
+ 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);
- QColor minuteColor(0, 127, 127, 191);
+ const QColor hourColor(palette().color(QPalette::Text));
+ const QColor minuteColor(palette().color(QPalette::Text));
+ const QColor secondsColor(palette().color(QPalette::Accent));
int side = qMin(width(), height());
- QTime time = QTime::currentTime();
-
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.translate(width() / 2, height() / 2);
@@ -78,54 +85,52 @@ void ShapedClock::paintEvent(QPaintEvent *)
painter.setPen(Qt::NoPen);
painter.setBrush(palette().window());
+ painter.setOpacity(0.9);
painter.drawEllipse(QPoint(0, 0), 98, 98);
+ painter.setOpacity(1.0);
+ QTime time = QTime::currentTime();
painter.setPen(Qt::NoPen);
painter.setBrush(hourColor);
painter.save();
painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
- painter.drawConvexPolygon(hourHand, 3);
+ painter.drawConvexPolygon(hourHand, 4);
painter.restore();
- painter.setPen(hourColor);
-
for (int i = 0; i < 12; ++i) {
- painter.drawLine(88, 0, 96, 0);
+ painter.drawRect(73, -3, 16, 6);
painter.rotate(30.0);
}
- painter.setPen(Qt::NoPen);
painter.setBrush(minuteColor);
painter.save();
- painter.rotate(6.0 * (time.minute() + time.second() / 60.0));
- painter.drawConvexPolygon(minuteHand, 3);
+ painter.rotate(6.0 * time.minute());
+ 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.setPen(minuteColor);
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);
}
}
//! [3]
//! [4]
-void ShapedClock::resizeEvent(QResizeEvent * /* event */)
-{
- int side = qMin(width(), height());
- QRegion maskedRegion(width() / 2 - side / 2, height() / 2 - side / 2, side,
- side, QRegion::Ellipse);
- setMask(maskedRegion);
-}
-//! [4]
-
-//! [5]
QSize ShapedClock::sizeHint() const
{
return QSize(200, 200);
}
-//! [5]
+//! [4]
diff --git a/examples/widgets/widgets/shapedclock/shapedclock.h b/examples/widgets/widgets/shapedclock/shapedclock.h
index c359a3a083..3dec93cc74 100644
--- a/examples/widgets/widgets/shapedclock/shapedclock.h
+++ b/examples/widgets/widgets/shapedclock/shapedclock.h
@@ -19,7 +19,6 @@ protected:
void mouseMoveEvent(QMouseEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void paintEvent(QPaintEvent *event) override;
- void resizeEvent(QResizeEvent *event) override;
private:
QPoint dragPosition;