summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Wicking <paul.wicking@qt.io>2020-08-31 14:09:05 +0200
committerPaul Wicking <paul.wicking@qt.io>2020-09-01 06:13:14 +0200
commitfd8132b8ae10436ef84ae44e21077d414a648c4f (patch)
treeadfc704441c86b8ba0a40a0401ce7bdb2bb9dd4f
parent65fb72d3026d476371a2c4006dac47bc9ce57b1a (diff)
Doc: compile image snippets
Done-with: Nico Vertriest <nico.vertriest@qt.io> Task-number: 81486 Change-Id: I9860217a80cf94d27542d7e7836fe60fcd60897e Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
-rw-r--r--src/gui/doc/snippets/image/image.cpp78
-rw-r--r--src/gui/doc/snippets/image/image.pro8
-rw-r--r--src/gui/doc/snippets/image/supportedformat.cpp7
-rw-r--r--src/gui/doc/snippets/snippets.pro1
4 files changed, 36 insertions, 58 deletions
diff --git a/src/gui/doc/snippets/image/image.cpp b/src/gui/doc/snippets/image/image.cpp
index c3b9abc364..3f2e7371e0 100644
--- a/src/gui/doc/snippets/image/image.cpp
+++ b/src/gui/doc/snippets/image/image.cpp
@@ -47,68 +47,38 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-
#include <QtGui>
+namespace image {
+void wrapper0() {
-int main()
-{
- int x, y;
- {
- // BIT ACCESS
- QImage image;
- // sets bit at (x, y) to 1
- if (image.format() == QImage::Format_MonoLSB)
- image.scanLine(y)[x >> 3] |= 1 << (x & 7);
- else
- image.scanLine(y)[x >> 3] |= 1 << (7 - (x & 7));
- }
+//! [0]
+QImage image;
+QByteArray ba;
+QBuffer buffer(&ba);
+buffer.open(QIODevice::WriteOnly);
+image.save(&buffer, "PNG"); // writes image into ba in PNG format
+//! [0]
- {
- // 8-BIT ACCESS
- QImage image;
- // set entry 19 in the color table to yellow
- image.setColor(19, qRgb(255, 255, 0));
+} // wrapper0
- // set 8 bit pixel at (x,y) to value yellow (in color table)
- image.scanLine(y)[x] = 19;
- }
- {
- // 32-BIT
- QImage image;
- // sets 32 bit pixel at (x,y) to yellow.
- uint *ptr = reinterpret_cast<uint *>(image.scanLine(y)) + x;
- *ptr = qRgb(255, 255, 0);
- }
+void wrapper1() {
- {
- // SAVE
-//! [0]
- QImage image;
- QByteArray ba;
- QBuffer buffer(&ba);
- buffer.open(QIODevice::WriteOnly);
- image.save(&buffer, "PNG"); // writes image into ba in PNG format
-//! [0]
- }
-
- {
- // PIX SAVE
//! [1]
- QPixmap pixmap;
- QByteArray bytes;
- QBuffer buffer(&bytes);
- buffer.open(QIODevice::WriteOnly);
- pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format
+QPixmap pixmap;
+QByteArray bytes;
+QBuffer buffer(&bytes);
+buffer.open(QIODevice::WriteOnly);
+pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format
//! [1]
- }
- {
- // MASK
+
//! [2]
- QPixmap alpha("image-with-alpha.png");
- QPixmap alphacopy = alpha;
- alphacopy.setMask(alphacopy.mask());
+QPixmap alpha("image-with-alpha.png");
+QPixmap alphacopy = alpha;
+alphacopy.setMask(alphacopy.mask());
//! [2]
- }
-}
+
+} // wrapper1
+
+} // image
diff --git a/src/gui/doc/snippets/image/image.pro b/src/gui/doc/snippets/image/image.pro
new file mode 100644
index 0000000000..c9b5e30cd1
--- /dev/null
+++ b/src/gui/doc/snippets/image/image.pro
@@ -0,0 +1,8 @@
+TEMPLATE = lib
+TARGET = image_snippets
+QT += core gui widgets
+
+SOURCES = \
+ image.cpp \
+ supportedformat.cpp
+
diff --git a/src/gui/doc/snippets/image/supportedformat.cpp b/src/gui/doc/snippets/image/supportedformat.cpp
index a537d2cdc3..c6a9779ac9 100644
--- a/src/gui/doc/snippets/image/supportedformat.cpp
+++ b/src/gui/doc/snippets/image/supportedformat.cpp
@@ -50,13 +50,12 @@
#include <QtGui>
-int main(int argv, char **args)
-{
+void wrapper() {
//! [0]
QImageWriter writer;
writer.setFormat("png");
if (writer.supportsOption(QImageIOHandler::Description))
qDebug() << "Png supports embedded text";
//! [0]
- return 0;
-}
+
+} // wrapper
diff --git a/src/gui/doc/snippets/snippets.pro b/src/gui/doc/snippets/snippets.pro
index d0a619c7e3..088a400751 100644
--- a/src/gui/doc/snippets/snippets.pro
+++ b/src/gui/doc/snippets/snippets.pro
@@ -10,6 +10,7 @@ contains(QT_BUILD_PARTS, tests) {
droparea \
dropevents \
droprectangle \
+ image \
qfontdatabase \
textblock-formats \
textblock-fragments \