Moved gui example documentation to the proper location.
Gui example documentation should be in examples/gui/doc/ Change-Id: I3cd196a2bb5d76b6e275f336b29a2ad1811159dd Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com>
This commit is contained in:
parent
3d04e4965e
commit
65f5909df2
@ -45,17 +45,17 @@
|
|||||||
make use of the RasterWindow from the \l {Raster Window Example}
|
make use of the RasterWindow from the \l {Raster Window Example}
|
||||||
and reimplement the \c render function to draw the clock face:
|
and reimplement the \c render function to draw the clock face:
|
||||||
|
|
||||||
\snippet gui/analogclock/main.cpp 5
|
\snippet analogclock/main.cpp 5
|
||||||
|
|
||||||
\section1 AnalogClock Class Implementation
|
\section1 AnalogClock Class Implementation
|
||||||
|
|
||||||
\snippet gui/analogclock/main.cpp 6
|
\snippet analogclock/main.cpp 6
|
||||||
|
|
||||||
We set a title on the window and resize to a reasonable size. Then
|
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
|
we start a timer which we will use to redraw the clock every
|
||||||
second.
|
second.
|
||||||
|
|
||||||
\snippet gui/analogclock/main.cpp 7
|
\snippet analogclock/main.cpp 7
|
||||||
|
|
||||||
The timerEvent function is called every second as a result of
|
The timerEvent function is called every second as a result of
|
||||||
our startTimer call. Making use of the convenience in the base
|
our startTimer call. Making use of the convenience in the base
|
||||||
@ -65,21 +65,21 @@
|
|||||||
one active timer in this instance, but it is good practice to do
|
one active timer in this instance, but it is good practice to do
|
||||||
so.
|
so.
|
||||||
|
|
||||||
\snippet gui/analogclock/main.cpp 14
|
\snippet analogclock/main.cpp 14
|
||||||
\snippet gui/analogclock/main.cpp 8
|
\snippet analogclock/main.cpp 8
|
||||||
|
|
||||||
Before we set up the painter and draw the clock, we first define
|
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
|
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
|
for the hour and minute hands. The minute hand's color has an
|
||||||
alpha component of 191, meaning that it's 75% opaque.
|
alpha component of 191, meaning that it's 75% opaque.
|
||||||
|
|
||||||
\snippet gui/analogclock/main.cpp 9
|
\snippet analogclock/main.cpp 9
|
||||||
|
|
||||||
We call QPainter::setRenderHint() with QPainter::Antialiasing to
|
We call QPainter::setRenderHint() with QPainter::Antialiasing to
|
||||||
turn on antialiasing. This makes drawing of diagonal lines much
|
turn on antialiasing. This makes drawing of diagonal lines much
|
||||||
smoother.
|
smoother.
|
||||||
|
|
||||||
\snippet gui/analogclock/main.cpp 10
|
\snippet analogclock/main.cpp 10
|
||||||
|
|
||||||
The translation moves the origin to the center of the window, and
|
The translation moves the origin to the center of the window, and
|
||||||
the scale operation ensures that the following drawing operations
|
the scale operation ensures that the following drawing operations
|
||||||
@ -106,31 +106,31 @@
|
|||||||
hour and minute. This means that the hand will be shown rotated clockwise
|
hour and minute. This means that the hand will be shown rotated clockwise
|
||||||
by the required amount.
|
by the required amount.
|
||||||
|
|
||||||
\snippet gui/analogclock/main.cpp 11
|
\snippet analogclock/main.cpp 11
|
||||||
|
|
||||||
We set the pen to be Qt::NoPen because we don't want any outline,
|
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
|
and we use a solid brush with the color appropriate for
|
||||||
displaying hours. Brushes are used when filling in polygons and
|
displaying hours. Brushes are used when filling in polygons and
|
||||||
other geometric shapes.
|
other geometric shapes.
|
||||||
|
|
||||||
\snippet gui/analogclock/main.cpp 2
|
\snippet analogclock/main.cpp 2
|
||||||
|
|
||||||
We save and restore the transformation matrix before and after the
|
We save and restore the transformation matrix before and after the
|
||||||
rotation because we want to place the minute hand without having to
|
rotation because we want to place the minute hand without having to
|
||||||
take into account any previous rotations.
|
take into account any previous rotations.
|
||||||
|
|
||||||
\snippet gui/analogclock/main.cpp 12
|
\snippet analogclock/main.cpp 12
|
||||||
|
|
||||||
We draw markers around the edge of the clock for each hour. We
|
We draw markers around the edge of the clock for each hour. We
|
||||||
draw each marker then rotate the coordinate system so that the
|
draw each marker then rotate the coordinate system so that the
|
||||||
painter is ready for the next one.
|
painter is ready for the next one.
|
||||||
|
|
||||||
\snippet gui/analogclock/main.cpp 13
|
\snippet analogclock/main.cpp 13
|
||||||
\snippet gui/analogclock/main.cpp 3
|
\snippet analogclock/main.cpp 3
|
||||||
|
|
||||||
The minute hand is rotated in a similar way to the hour hand.
|
The minute hand is rotated in a similar way to the hour hand.
|
||||||
|
|
||||||
\snippet gui/analogclock/main.cpp 4
|
\snippet analogclock/main.cpp 4
|
||||||
|
|
||||||
Again, we draw markers around the edge of the clock, but this
|
Again, we draw markers around the edge of the clock, but this
|
||||||
time to indicate minutes. We skip multiples of 5 to avoid drawing
|
time to indicate minutes. We skip multiples of 5 to avoid drawing
|
@ -53,13 +53,13 @@
|
|||||||
you will not have to worry about resolving those functions if you want your
|
you will not have to worry about resolving those functions if you want your
|
||||||
application to work with OpenGL as well as OpenGL ES 2.0.
|
application to work with OpenGL as well as OpenGL ES 2.0.
|
||||||
|
|
||||||
\snippet gui/openglwindow/openglwindow.h 1
|
\snippet openglwindow/openglwindow.h 1
|
||||||
|
|
||||||
The window's surface type must be set to QSurface::OpenGLSurface to
|
The window's surface type must be set to QSurface::OpenGLSurface to
|
||||||
indicate that the window is to be used for OpenGL rendering and not for
|
indicate that the window is to be used for OpenGL rendering and not for
|
||||||
rendering raster content with QPainter using a QBackingStore.
|
rendering raster content with QPainter using a QBackingStore.
|
||||||
|
|
||||||
\snippet gui/openglwindow/openglwindow.cpp 1
|
\snippet openglwindow/openglwindow.cpp 1
|
||||||
|
|
||||||
Any OpenGL initialization needed can be done by overriding the initialize()
|
Any OpenGL initialization needed can be done by overriding the initialize()
|
||||||
function, which is called once before the first call to render(), with a
|
function, which is called once before the first call to render(), with a
|
||||||
@ -68,7 +68,7 @@
|
|||||||
whereas the default render() implementation initializes a
|
whereas the default render() implementation initializes a
|
||||||
QOpenGLPaintDevice and then calls into render(QPainter *).
|
QOpenGLPaintDevice and then calls into render(QPainter *).
|
||||||
|
|
||||||
\snippet gui/openglwindow/openglwindow.cpp 2
|
\snippet openglwindow/openglwindow.cpp 2
|
||||||
|
|
||||||
The renderLater() function simply puts an update request event on
|
The renderLater() function simply puts an update request event on
|
||||||
the event loop, which leads to renderNow() being called once the event
|
the event loop, which leads to renderNow() being called once the event
|
||||||
@ -83,7 +83,7 @@
|
|||||||
size might be unknown, and in addition what is rendered might not even end
|
size might be unknown, and in addition what is rendered might not even end
|
||||||
up on the screen.
|
up on the screen.
|
||||||
|
|
||||||
\snippet gui/openglwindow/openglwindow.cpp 3
|
\snippet openglwindow/openglwindow.cpp 3
|
||||||
|
|
||||||
In renderNow() we return if we are not currently exposed, in which case
|
In renderNow() we return if we are not currently exposed, in which case
|
||||||
rendering is delayed until we actually get an expose event. If we have not
|
rendering is delayed until we actually get an expose event. If we have not
|
||||||
@ -111,12 +111,12 @@
|
|||||||
If animation has been enabled with OpenGLWindow::setAnimating(true), we
|
If animation has been enabled with OpenGLWindow::setAnimating(true), we
|
||||||
call renderLater() to put another update request on the event loop.
|
call renderLater() to put another update request on the event loop.
|
||||||
|
|
||||||
\snippet gui/openglwindow/openglwindow.cpp 4
|
\snippet openglwindow/openglwindow.cpp 4
|
||||||
|
|
||||||
Enabling animation also triggers an update request as shown in the
|
Enabling animation also triggers an update request as shown in the
|
||||||
following code snippet.
|
following code snippet.
|
||||||
|
|
||||||
\snippet gui/openglwindow/openglwindow.cpp 5
|
\snippet openglwindow/openglwindow.cpp 5
|
||||||
|
|
||||||
\section1 Example OpenGL rendering sub class
|
\section1 Example OpenGL rendering sub class
|
||||||
|
|
||||||
@ -124,7 +124,7 @@
|
|||||||
rotating triangle. By indirectly sub classing QOpenGLFunctions we gain
|
rotating triangle. By indirectly sub classing QOpenGLFunctions we gain
|
||||||
access to all OpenGL ES 2.0 level functionality.
|
access to all OpenGL ES 2.0 level functionality.
|
||||||
|
|
||||||
\snippet gui/openglwindow/main.cpp 1
|
\snippet openglwindow/main.cpp 1
|
||||||
|
|
||||||
In our main function we initialize QGuiApplication and instantiate our
|
In our main function we initialize QGuiApplication and instantiate our
|
||||||
TriangleOpenGLWindow. We give it a QSurfaceFormat specifying that we want
|
TriangleOpenGLWindow. We give it a QSurfaceFormat specifying that we want
|
||||||
@ -132,13 +132,13 @@
|
|||||||
Since we want to have animation we call the above mentioned setAnimating()
|
Since we want to have animation we call the above mentioned setAnimating()
|
||||||
function with an argument of true.
|
function with an argument of true.
|
||||||
|
|
||||||
\snippet gui/openglwindow/main.cpp 2
|
\snippet openglwindow/main.cpp 2
|
||||||
|
|
||||||
The following code snippet shows the OpenGL shader program used in this
|
The following code snippet shows the OpenGL shader program used in this
|
||||||
example. The vertex and fragment shaders are relatively simple, doing
|
example. The vertex and fragment shaders are relatively simple, doing
|
||||||
vertex transformation and interpolated vertex coloring.
|
vertex transformation and interpolated vertex coloring.
|
||||||
|
|
||||||
\snippet gui/openglwindow/main.cpp 3
|
\snippet openglwindow/main.cpp 3
|
||||||
|
|
||||||
Here is the code that loads the shaders and initializes the shader program
|
Here is the code that loads the shaders and initializes the shader program
|
||||||
By using QOpenGLShaderProgram instead of raw OpenGL we get the convenience
|
By using QOpenGLShaderProgram instead of raw OpenGL we get the convenience
|
||||||
@ -147,10 +147,10 @@
|
|||||||
locations in member variables to avoid having to do the location lookup
|
locations in member variables to avoid having to do the location lookup
|
||||||
each frame.
|
each frame.
|
||||||
|
|
||||||
\snippet gui/openglwindow/main.cpp 4
|
\snippet openglwindow/main.cpp 4
|
||||||
|
|
||||||
Finally, here is our render() function, where we use OpenGL to set up the
|
Finally, here is our render() function, where we use OpenGL to set up the
|
||||||
viewport, clear the background, and render a rotating triangle.
|
viewport, clear the background, and render a rotating triangle.
|
||||||
|
|
||||||
\snippet gui/openglwindow/main.cpp 5
|
\snippet openglwindow/main.cpp 5
|
||||||
*/
|
*/
|
@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
\section1 Application Entry Point
|
\section1 Application Entry Point
|
||||||
|
|
||||||
\snippet gui/rasterwindow/main.cpp 1
|
\snippet rasterwindow/main.cpp 1
|
||||||
|
|
||||||
The entry point for a QWindow based application is the \l
|
The entry point for a QWindow based application is the \l
|
||||||
QGuiApplication class. It manages the GUI application's control
|
QGuiApplication class. It manages the GUI application's control
|
||||||
@ -52,7 +52,7 @@
|
|||||||
|
|
||||||
\section1 RasterWindow Declaration
|
\section1 RasterWindow Declaration
|
||||||
|
|
||||||
\snippet gui/rasterwindow/rasterwindow.h 1
|
\snippet rasterwindow/rasterwindow.h 1
|
||||||
|
|
||||||
We first start by including the the QtGui headers. This means we
|
We first start by including the the QtGui headers. This means we
|
||||||
can use all classes in the Qt GUI module. Classes can also be
|
can use all classes in the Qt GUI module. Classes can also be
|
||||||
@ -72,7 +72,7 @@
|
|||||||
|
|
||||||
\section1 RasterWindow Implementation
|
\section1 RasterWindow Implementation
|
||||||
|
|
||||||
\snippet gui/rasterwindow/rasterwindow.cpp 1
|
\snippet rasterwindow/rasterwindow.cpp 1
|
||||||
|
|
||||||
The constructor first of all calls \l QWindow::create(). This will
|
The constructor first of all calls \l QWindow::create(). This will
|
||||||
create the window in the windowing system. Without calling create,
|
create the window in the windowing system. Without calling create,
|
||||||
@ -83,7 +83,7 @@
|
|||||||
Then we create the backingstore and pass it the window instance it
|
Then we create the backingstore and pass it the window instance it
|
||||||
is supposed to manage.
|
is supposed to manage.
|
||||||
|
|
||||||
\snippet gui/rasterwindow/rasterwindow.cpp 2
|
\snippet rasterwindow/rasterwindow.cpp 2
|
||||||
|
|
||||||
Shortly after calling \l QWindow::show() on a created window, the
|
Shortly after calling \l QWindow::show() on a created window, the
|
||||||
virtual function \l QWindow::exposeEvent() will be called to
|
virtual function \l QWindow::exposeEvent() will be called to
|
||||||
@ -100,7 +100,7 @@
|
|||||||
system with some visual content.
|
system with some visual content.
|
||||||
|
|
||||||
|
|
||||||
\snippet gui/rasterwindow/rasterwindow.cpp 5
|
\snippet rasterwindow/rasterwindow.cpp 5
|
||||||
|
|
||||||
The resize event is guaranteed to be called prior to the window
|
The resize event is guaranteed to be called prior to the window
|
||||||
being shown on screen and will also be called whenever the window
|
being shown on screen and will also be called whenever the window
|
||||||
@ -108,7 +108,7 @@
|
|||||||
and call renderNow() if we are visible to immediately update the
|
and call renderNow() if we are visible to immediately update the
|
||||||
visual representation of the window on screen.
|
visual representation of the window on screen.
|
||||||
|
|
||||||
\snippet gui/rasterwindow/rasterwindow.cpp 3
|
\snippet rasterwindow/rasterwindow.cpp 3
|
||||||
|
|
||||||
The renderNow function sets up what is needed for a \l QWindow to
|
The renderNow function sets up what is needed for a \l QWindow to
|
||||||
render its content using QPainter. As obscured windows have will
|
render its content using QPainter. As obscured windows have will
|
||||||
@ -130,7 +130,7 @@
|
|||||||
using \l QBackingStore::flush().
|
using \l QBackingStore::flush().
|
||||||
|
|
||||||
|
|
||||||
\snippet gui/rasterwindow/rasterwindow.cpp 4
|
\snippet rasterwindow/rasterwindow.cpp 4
|
||||||
|
|
||||||
The render function contains the drawing code for the window. In
|
The render function contains the drawing code for the window. In
|
||||||
this minial example, we only draw the string "QWindow" in the
|
this minial example, we only draw the string "QWindow" in the
|
||||||
@ -140,7 +140,7 @@
|
|||||||
\section1 Rendering Asynchronously
|
\section1 Rendering Asynchronously
|
||||||
|
|
||||||
|
|
||||||
\snippet gui/rasterwindow/rasterwindow.cpp 6
|
\snippet rasterwindow/rasterwindow.cpp 6
|
||||||
|
|
||||||
We went through a few places where the window needed to repainted
|
We went through a few places where the window needed to repainted
|
||||||
immediately. There are some cases where this is not desierable,
|
immediately. There are some cases where this is not desierable,
|
||||||
@ -151,7 +151,7 @@
|
|||||||
is already pending, we store this state in the \c m_update_pending
|
is already pending, we store this state in the \c m_update_pending
|
||||||
variable.
|
variable.
|
||||||
|
|
||||||
\snippet gui/rasterwindow/rasterwindow.cpp 7
|
\snippet rasterwindow/rasterwindow.cpp 7
|
||||||
|
|
||||||
We reimplement the virtual \l QObject::event() function to handle
|
We reimplement the virtual \l QObject::event() function to handle
|
||||||
the update event we posted to ourselves. When the event comes in
|
the update event we posted to ourselves. When the event comes in
|
@ -1,4 +1,5 @@
|
|||||||
TEMPLATE = subdirs
|
TEMPLATE = subdirs
|
||||||
|
CONFIG += no_docs_target
|
||||||
|
|
||||||
SUBDIRS += analogclock
|
SUBDIRS += analogclock
|
||||||
SUBDIRS += rasterwindow
|
SUBDIRS += rasterwindow
|
||||||
|
@ -71,12 +71,16 @@ depends += qtcore
|
|||||||
|
|
||||||
headerdirs += ..
|
headerdirs += ..
|
||||||
|
|
||||||
sourcedirs += ..
|
sourcedirs += .. \
|
||||||
|
../../../examples/gui/doc
|
||||||
|
|
||||||
exampledirs += ../../../examples \
|
exampledirs += ../../../examples/gui \
|
||||||
|
../../../doc/src/snippets \
|
||||||
../ \
|
../ \
|
||||||
snippets
|
snippets
|
||||||
|
|
||||||
excludedirs += ../../../examples/widgets/doc
|
excludedirs += snippets
|
||||||
|
|
||||||
imagedirs += images
|
imagedirs += images \
|
||||||
|
../../../doc/src/images \
|
||||||
|
../../../examples/gui/doc/images
|
||||||
|
Loading…
Reference in New Issue
Block a user