summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/global/manifest-meta.qdocconf2
-rw-r--r--examples/gui/CMakeLists.txt1
-rw-r--r--examples/gui/analogclock/CMakeLists.txt40
-rw-r--r--examples/gui/analogclock/analogclock.pro10
-rw-r--r--examples/gui/analogclock/main.cpp123
-rw-r--r--examples/gui/doc/images/analogclock-window-example.pngbin14556 -> 0 bytes
-rw-r--r--examples/gui/doc/images/analogclockwindow-viewport.pngbin29668 -> 0 bytes
-rw-r--r--examples/gui/doc/src/analogclockwindow.qdoc114
-rw-r--r--examples/gui/gui.pro1
-rw-r--r--examples/widgets/widgets/analogclock/analogclock.cpp6
-rw-r--r--src/gui/doc/qtgui.qdocconf2
-rw-r--r--src/gui/doc/src/coordsys.qdoc35
12 files changed, 25 insertions, 309 deletions
diff --git a/doc/global/manifest-meta.qdocconf b/doc/global/manifest-meta.qdocconf
index 536f4ce8c5..649af2b561 100644
--- a/doc/global/manifest-meta.qdocconf
+++ b/doc/global/manifest-meta.qdocconf
@@ -44,7 +44,6 @@ manifestmeta.android.names = "Qt3D/Qt 3D: Basic Shapes C++ Example" \
"QtDataVisualization/Audiolevels Example" \
"QtDataVisualization/Qt Quick 2 Scatter Example" \
"QtDataVisualization/Qt Quick 2 Surface Multiseries Example" \
- "QtGui/Analog Clock Window Example" \
"QtGui/OpenGL Window Example" \
"QtGui/Raster Window Example" \
"QtLinguist/Arrow Pad Example" \
@@ -104,7 +103,6 @@ manifestmeta.android.tags = android
manifestmeta.ios.names = "QtCore/Contiguous Cache Example" \
"QtCore/Mandelbrot Example" \
"QtCore/Queued Custom Type Example" \
- "QtGui/Analog Clock Window Example" \
"QtGui/OpenGL Window Example" \
"QtGui/Raster Window Example" \
"QtNetwork/Loopback Example" \
diff --git a/examples/gui/CMakeLists.txt b/examples/gui/CMakeLists.txt
index 83faae6765..8eb3981a2f 100644
--- a/examples/gui/CMakeLists.txt
+++ b/examples/gui/CMakeLists.txt
@@ -4,5 +4,4 @@
if(NOT TARGET Qt6::Gui)
return()
endif()
-qt_internal_add_example(analogclock)
qt_internal_add_example(rasterwindow)
diff --git a/examples/gui/analogclock/CMakeLists.txt b/examples/gui/analogclock/CMakeLists.txt
deleted file mode 100644
index bae6083644..0000000000
--- a/examples/gui/analogclock/CMakeLists.txt
+++ /dev/null
@@ -1,40 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(analogclock LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/gui/gui_analogclock")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui)
-
-qt_standard_project_setup()
-
-qt_add_executable(gui_analogclock
- ../rasterwindow/rasterwindow.cpp ../rasterwindow/rasterwindow.h
- main.cpp
-)
-
-set_target_properties(gui_analogclock PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_include_directories(gui_analogclock PRIVATE
- ../rasterwindow
-)
-
-target_link_libraries(gui_analogclock PRIVATE
- Qt6::Core
- Qt6::Gui
-)
-
-install(TARGETS gui_analogclock
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/gui/analogclock/analogclock.pro b/examples/gui/analogclock/analogclock.pro
deleted file mode 100644
index eef17274f5..0000000000
--- a/examples/gui/analogclock/analogclock.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-include(../rasterwindow/rasterwindow.pri)
-
-# work-around for QTBUG-13496
-CONFIG += no_batch
-
-SOURCES += \
- main.cpp
-
-target.path = $$[QT_INSTALL_EXAMPLES]/gui/analogclock
-INSTALLS += target
diff --git a/examples/gui/analogclock/main.cpp b/examples/gui/analogclock/main.cpp
deleted file mode 100644
index 8e0a061057..0000000000
--- a/examples/gui/analogclock/main.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtGui>
-
-#include "rasterwindow.h"
-
-//! [5]
-class AnalogClockWindow : public RasterWindow
-{
-public:
- AnalogClockWindow();
-
-protected:
- void timerEvent(QTimerEvent *) override;
- void render(QPainter *p) override;
-
-private:
- int m_timerId;
-};
-//! [5]
-
-
-//! [6]
-AnalogClockWindow::AnalogClockWindow()
-{
- setTitle("Analog Clock");
- resize(200, 200);
-
- m_timerId = startTimer(1000);
-}
-//! [6]
-
-//! [7]
-void AnalogClockWindow::timerEvent(QTimerEvent *event)
-{
- if (event->timerId() == m_timerId)
- renderLater();
-}
-//! [7]
-
-//! [1] //! [14]
-void AnalogClockWindow::render(QPainter *p)
-{
-//! [14]
-//! [8]
- static const QPoint hourHand[3] = {
- QPoint(7, 8),
- QPoint(-7, 8),
- QPoint(0, -40)
- };
- static const QPoint minuteHand[3] = {
- QPoint(7, 8),
- QPoint(-7, 8),
- QPoint(0, -70)
- };
-
- QColor hourColor(127, 0, 127);
- QColor minuteColor(0, 127, 127, 191);
-//! [8]
-
-//! [9]
- p->setRenderHint(QPainter::Antialiasing);
-//! [9] //! [10]
- p->translate(width() / 2, height() / 2);
-
- int side = qMin(width(), height());
- p->scale(side / 200.0, side / 200.0);
-//! [1] //! [10]
-
-//! [11]
- p->setPen(Qt::NoPen);
- p->setBrush(hourColor);
-//! [11]
-
-//! [2]
- QTime time = QTime::currentTime();
-
- p->save();
- p->rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
- p->drawConvexPolygon(hourHand, 3);
- p->restore();
-//! [2]
-
-//! [12]
- p->setPen(hourColor);
-
- for (int i = 0; i < 12; ++i) {
- p->drawLine(88, 0, 96, 0);
- p->rotate(30.0);
- }
-//! [12] //! [13]
- p->setPen(Qt::NoPen);
- p->setBrush(minuteColor);
-//! [13]
-
-//! [3]
- p->save();
- p->rotate(6.0 * (time.minute() + time.second() / 60.0));
- p->drawConvexPolygon(minuteHand, 3);
- p->restore();
-//! [3]
-
-//! [4]
- p->setPen(minuteColor);
-
- for (int j = 0; j < 60; ++j) {
- if ((j % 5) != 0)
- p->drawLine(92, 0, 96, 0);
- p->rotate(6.0);
- }
-//! [4]
-}
-
-int main(int argc, char **argv)
-{
- QGuiApplication app(argc, argv);
-
- AnalogClockWindow clock;
- clock.show();
-
- return app.exec();
-}
diff --git a/examples/gui/doc/images/analogclock-window-example.png b/examples/gui/doc/images/analogclock-window-example.png
deleted file mode 100644
index f5e92e400a..0000000000
--- a/examples/gui/doc/images/analogclock-window-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/gui/doc/images/analogclockwindow-viewport.png b/examples/gui/doc/images/analogclockwindow-viewport.png
deleted file mode 100644
index 31ce0c3c6e..0000000000
--- a/examples/gui/doc/images/analogclockwindow-viewport.png
+++ /dev/null
Binary files differ
diff --git a/examples/gui/doc/src/analogclockwindow.qdoc b/examples/gui/doc/src/analogclockwindow.qdoc
deleted file mode 100644
index 7ae13821dd..0000000000
--- a/examples/gui/doc/src/analogclockwindow.qdoc
+++ /dev/null
@@ -1,114 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example analogclock
- \title Analog Clock Window Example
-
- \brief The Analog Clock Window example shows how to draw the contents of
- a custom window.
-
- \image analogclock-window-example.png Screenshot of the Analog
- Clock Window example
-
- This example demonstrates how the transformation and scaling
- features of QPainter can be used to make drawing easier.
-
- \section1 AnalogClockWindow Class Definition
-
- The \c AnalogClockWindow class provides a clock with hour and
- minute hands that is automatically updated every few seconds. We
- make use of the RasterWindow from the \l {Raster Window Example}
- and reimplement the \c render function to draw the clock face:
-
- \snippet analogclock/main.cpp 5
-
- \section1 AnalogClock Class Implementation
-
- \snippet analogclock/main.cpp 6
-
- We set a title on the window and resize to a reasonable size. Then
- we start a timer which we will use to redraw the clock every
- second.
-
- \snippet analogclock/main.cpp 7
-
- The timerEvent function is called every second as a result of
- our startTimer call. Making use of the convenience in the base
- class, we schedule the window to be repainted.
-
- Checking the timer's id is not strictly needed as we only have
- one active timer in this instance, but it is good practice to do
- so.
-
- \snippet analogclock/main.cpp 14
- \snippet analogclock/main.cpp 8
-
- Before we set up the painter and draw the clock, we first define
- two lists of \l {QPoint}s and two \l{QColor}s that will be used
- for the hour and minute hands. The minute hand's color has an
- alpha component of 191, meaning that it's 75% opaque.
-
- \snippet analogclock/main.cpp 9
-
- We call QPainter::setRenderHint() with QPainter::Antialiasing to
- turn on antialiasing. This makes drawing of diagonal lines much
- smoother.
-
- \snippet analogclock/main.cpp 10
-
- The translation moves the origin to the center of the window, and
- the scale operation ensures that the following drawing operations
- are scaled to fit within the window. We use a scale factor that
- let's us use x and y coordinates between -100 and 100, and that
- ensures that these lie within the length of the window's shortest
- side.
-
- To make our code simpler, we will draw a fixed size clock face that will
- be positioned and scaled so that it lies in the center of the window.
-
- We also determine the length of the window's shortest side so that we
- can fit the clock face inside the window.
-
- The painter takes care of all the transformations made during the
- rendering, and ensures that everything is drawn correctly. Letting
- the painter handle transformations is often easier than performing
- manual calculations.
-
- \image analogclockwindow-viewport.png
-
- We draw the hour hand first, using a formula that rotates the coordinate
- system counterclockwise by a number of degrees determined by the current
- hour and minute. This means that the hand will be shown rotated clockwise
- by the required amount.
-
- \snippet analogclock/main.cpp 11
-
- We set the pen to be Qt::NoPen because we don't want any outline,
- and we use a solid brush with the color appropriate for
- displaying hours. Brushes are used when filling in polygons and
- other geometric shapes.
-
- \snippet analogclock/main.cpp 2
-
- We save and restore the transformation matrix before and after the
- rotation because we want to place the minute hand without having to
- take into account any previous rotations.
-
- \snippet analogclock/main.cpp 12
-
- We draw markers around the edge of the clock for each hour. We
- draw each marker then rotate the coordinate system so that the
- painter is ready for the next one.
-
- \snippet analogclock/main.cpp 13
- \snippet analogclock/main.cpp 3
-
- The minute hand is rotated in a similar way to the hour hand.
-
- \snippet analogclock/main.cpp 4
-
- Again, we draw markers around the edge of the clock, but this
- time to indicate minutes. We skip multiples of 5 to avoid drawing
- minute markers on top of hour markers.
-*/
diff --git a/examples/gui/gui.pro b/examples/gui/gui.pro
index 275adc804d..2afb8bbfc7 100644
--- a/examples/gui/gui.pro
+++ b/examples/gui/gui.pro
@@ -4,5 +4,4 @@ TEMPLATE = subdirs
QT_FOR_CONFIG += gui
CONFIG += no_docs_target
-SUBDIRS += analogclock
SUBDIRS += rasterwindow
diff --git a/examples/widgets/widgets/analogclock/analogclock.cpp b/examples/widgets/widgets/analogclock/analogclock.cpp
index 34d135ed4a..ad94a16bab 100644
--- a/examples/widgets/widgets/analogclock/analogclock.cpp
+++ b/examples/widgets/widgets/analogclock/analogclock.cpp
@@ -46,7 +46,6 @@ void AnalogClock::paintEvent(QPaintEvent *)
QColor minuteColor(0, 127, 127, 191);
int side = qMin(width(), height());
- QTime time = QTime::currentTime();
//! [10]
//! [11]
@@ -64,8 +63,9 @@ void AnalogClock::paintEvent(QPaintEvent *)
//! [15] //! [16]
painter.setBrush(hourColor);
//! [16]
-
-//! [17] //! [18]
+//! [18]
+ QTime time = QTime::currentTime();
+//! [17]
painter.save();
//! [17] //! [19]
painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
diff --git a/src/gui/doc/qtgui.qdocconf b/src/gui/doc/qtgui.qdocconf
index 333a8d7449..00dc548d93 100644
--- a/src/gui/doc/qtgui.qdocconf
+++ b/src/gui/doc/qtgui.qdocconf
@@ -62,8 +62,6 @@ imagedirs += images \
excludefiles += ../kernel/qtestsupport_gui.cpp \
../painting/qdrawhelper_ssse3.cpp
-# manifestmeta.highlighted.names = "QtGui/Analog Clock Window Example"
-
navigation.landingpage = "Qt GUI"
navigation.cppclassespage = "Qt GUI C++ Classes"
diff --git a/src/gui/doc/src/coordsys.qdoc b/src/gui/doc/src/coordsys.qdoc
index eb39239e37..087916635b 100644
--- a/src/gui/doc/src/coordsys.qdoc
+++ b/src/gui/doc/src/coordsys.qdoc
@@ -213,11 +213,11 @@
\row
\li {2,1}
- \snippet analogclock/main.cpp 1
+ \snippet ../widgets/widgets/analogclock/analogclock.cpp 9
We translate the coordinate system so that point (0, 0) is in the
widget's center, instead of being at the top-left corner. We also
- scale the system by \c side / 100, where \c side is either the
+ scale the system by \c side / 200, where \c side is either the
widget's width or the height, whichever is shortest. We want the
clock to be square, even if the device isn't.
@@ -227,7 +227,7 @@
See also the \l {Window-Viewport Conversion} section.
- \snippet analogclock/main.cpp 2
+ \snippet ../widgets/widgets/analogclock/analogclock.cpp 18
We draw the clock's hour hand by rotating the coordinate system
and calling QPainter::drawConvexPolygon(). Thank's to the
@@ -235,26 +235,35 @@
The polygon is specified as an array of alternating \e x, \e y
values, stored in the \c hourHand static variable (defined at the
- beginning of the function), which corresponds to the four points
- (2, 0), (0, 2), (-2, 0), and (0, -25).
+ beginning of the function), which corresponds to the three points
+ (7, 8), (-7, 8), (0, -40).
The calls to QPainter::save() and QPainter::restore() surrounding
the code guarantees that the code that follows won't be disturbed
by the transformations we've used.
- \snippet analogclock/main.cpp 3
+ \snippet ../widgets/widgets/analogclock/analogclock.cpp 21
+
+ After that, we draw the hour markers for the clock face, which
+ consists of twelve short lines at 30-degree intervals. When that
+ loop is done, the painter has been rotated a full circle back to
+ its original state, so we don't need to save and restore the state.
+
+ \snippet ../widgets/widgets/analogclock/analogclock.cpp 24
We do the same for the clock's minute hand, which is defined by
- the four points (1, 0), (0, 1), (-1, 0), and (0, -40). These
+ the three points (7, 8), (-7, 8), (0, -70). These
coordinates specify a hand that is thinner and longer than the
minute hand.
- \snippet analogclock/main.cpp 4
+ \snippet ../widgets/widgets/analogclock/analogclock.cpp 27
- Finally, we draw the clock face, which consists of twelve short
- lines at 30-degree intervals. At the end of that, the painter is
- rotated in a way which isn't very useful, but we're done with
- painting so that doesn't matter.
+ Finally, we draw the minute markers for the clock face, which
+ consists of sixty short lines at 6-degree intervals. We skip every
+ fifth minute marker because we don't want to draw over the hour
+ markers. At the end of that, the painter is rotated in a way which
+ isn't very useful, but we're done with painting so that doesn't
+ matter.
\endtable
For more information about the transformation matrix, see the
@@ -422,5 +431,5 @@
\endtable
\endomit
- \sa {Analog Clock Window Example}
+ \sa {Analog Clock}
*/