Doc: Compile image snippets
Fix minor issues (e.g. whitespace, missing semi-colon) in passing. Update documentation to use same snippet to avoid duplication of snippets across snippet files. Remove offending snippet. Done-with: Nico Vertriest <nico.vertriest@qt.io> Task-number: QTBUG-81486 Change-Id: Ia45549d50e8f4e22ce72667a19c38132306d38b3 Reviewed-by: Topi Reiniö <topi.reinio@qt.io>bb10
parent
186eb6d50f
commit
ebabbd0264
|
|
@ -5,4 +5,11 @@ QT += core gui widgets
|
|||
SOURCES = \
|
||||
doc_src_coordsys.cpp \
|
||||
doc_src_richtext.cpp \
|
||||
src_gui_accessible_qaccessible.cpp
|
||||
src_gui_accessible_qaccessible.cpp \
|
||||
src_gui_image_qicon.cpp \
|
||||
src_gui_image_qimage.cpp \
|
||||
src_gui_image_qimagereader.cpp \
|
||||
src_gui_image_qimagewriter.cpp \
|
||||
src_gui_image_qmovie.cpp \
|
||||
src_gui_image_qpixmapcache.cpp \
|
||||
src_gui_image_qpixmap.cpp
|
||||
|
|
|
|||
|
|
@ -47,6 +47,20 @@
|
|||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
#include <QIcon>
|
||||
#include <QPainter>
|
||||
#include <QToolButton>
|
||||
|
||||
namespace src_gui_image_qicon {
|
||||
|
||||
struct MyWidget : public QWidget
|
||||
{
|
||||
void drawIcon(QPainter *painter, QPoint pos);
|
||||
bool isChecked() { return true; }
|
||||
QIcon icon;
|
||||
};
|
||||
|
||||
void wrapper0() {
|
||||
|
||||
//! [0]
|
||||
QToolButton *button = new QToolButton;
|
||||
|
|
@ -58,6 +72,8 @@ button->setIcon(QIcon("open.xpm"));
|
|||
button->setIcon(QIcon());
|
||||
//! [1]
|
||||
|
||||
} // wrapper0
|
||||
|
||||
|
||||
//! [2]
|
||||
void MyWidget::drawIcon(QPainter *painter, QPoint pos)
|
||||
|
|
@ -71,14 +87,25 @@ void MyWidget::drawIcon(QPainter *painter, QPoint pos)
|
|||
}
|
||||
//! [2]
|
||||
|
||||
|
||||
void wrapper1() {
|
||||
|
||||
//! [3]
|
||||
QIcon undoicon = QIcon::fromTheme("edit-undo");
|
||||
QIcon undoicon = QIcon::fromTheme("edit-undo");
|
||||
//! [3]
|
||||
|
||||
} // wrapper1
|
||||
|
||||
|
||||
//! [4]
|
||||
QIcon undoicon = QIcon::fromTheme("edit-undo", QIcon(":/undo.png"));
|
||||
QIcon undoicon = QIcon::fromTheme("edit-undo", QIcon(":/undo.png"));
|
||||
//! [4]
|
||||
|
||||
|
||||
void wrapper2(){
|
||||
//! [5]
|
||||
QIcon::setFallbackSearchPaths(QIcon::fallbackSearchPaths() << "my/search/path");
|
||||
QIcon::setFallbackSearchPaths(QIcon::fallbackSearchPaths() << "my/search/path");
|
||||
//! [5]
|
||||
|
||||
} // wrapper2
|
||||
} // src_gui_image_qicon
|
||||
|
|
|
|||
|
|
@ -47,7 +47,11 @@
|
|||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
#include <QImage>
|
||||
#include <QRgb>
|
||||
|
||||
namespace src_gui_image_qimage {
|
||||
void wrapper0() {
|
||||
//! [0]
|
||||
QImage image(3, 3, QImage::Format_RGB32);
|
||||
QRgb value;
|
||||
|
|
@ -63,6 +67,9 @@ value = qRgb(237, 187, 51); // 0xffedba31
|
|||
image.setPixel(2, 1, value);
|
||||
//! [0]
|
||||
|
||||
} // wrapper0
|
||||
void wrapper1() {
|
||||
|
||||
|
||||
//! [1]
|
||||
QImage image(3, 3, QImage::Format_Indexed8);
|
||||
|
|
@ -88,5 +95,10 @@ image.setPixel(2, 1, 1);
|
|||
static const char * const start_xpm[] = {
|
||||
"16 15 8 1",
|
||||
"a c #cec6bd",
|
||||
....
|
||||
// etc.
|
||||
};
|
||||
//! [2]
|
||||
|
||||
Q_UNUSED(start_xpm);
|
||||
} // wrapper1
|
||||
} // src_gui_image_qimage
|
||||
|
|
|
|||
|
|
@ -47,12 +47,19 @@
|
|||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
#include <QImage>
|
||||
#include <QImageReader>
|
||||
|
||||
namespace src_gui_image_qimagereader {
|
||||
void wrapper0() {
|
||||
|
||||
//! [0]
|
||||
QImageReader reader;
|
||||
reader.setFormat("png"); // same as reader.setFormat("PNG");
|
||||
//! [0]
|
||||
|
||||
} // wrapper0
|
||||
|
||||
|
||||
//! [1]
|
||||
QImageReader reader("image.png");
|
||||
|
|
@ -60,6 +67,8 @@ QImageReader reader("image.png");
|
|||
//! [1]
|
||||
|
||||
|
||||
void wrapper1() {
|
||||
|
||||
//! [2]
|
||||
QImage icon(64, 64, QImage::Format_RGB32);
|
||||
QImageReader reader("icon_64x64.bmp");
|
||||
|
|
@ -68,9 +77,16 @@ if (reader.read(&icon)) {
|
|||
}
|
||||
//! [2]
|
||||
|
||||
} // wrapper1
|
||||
|
||||
|
||||
void wrapper2() {
|
||||
|
||||
//! [3]
|
||||
QImageReader reader(":/image.png");
|
||||
if (reader.supportsOption(QImageIOHandler::Size))
|
||||
qDebug() << "Size:" << reader.size();
|
||||
//! [3]
|
||||
|
||||
} // wrapper2
|
||||
} // src_gui_image_qimagereader
|
||||
|
|
|
|||
|
|
@ -47,12 +47,22 @@
|
|||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
#include <QImage>
|
||||
#include <QImageWriter>
|
||||
|
||||
namespace src_gui_image_qimagewriter {
|
||||
|
||||
void wrapper0() {
|
||||
|
||||
//! [0]
|
||||
QImageWriter writer;
|
||||
writer.setFormat("png"); // same as writer.setFormat("PNG");
|
||||
//! [0]
|
||||
|
||||
} // wrapper0
|
||||
|
||||
|
||||
void wrapper1() {
|
||||
|
||||
//! [1]
|
||||
QImage image("some/image.jpeg");
|
||||
|
|
@ -61,6 +71,11 @@ writer.setText("Author", "John Smith");
|
|||
writer.write(image);
|
||||
//! [1]
|
||||
|
||||
} // wrapper1
|
||||
|
||||
|
||||
void wrapper2() {
|
||||
QString fileName;
|
||||
|
||||
//! [2]
|
||||
QImageWriter writer(fileName);
|
||||
|
|
@ -68,9 +83,18 @@ if (writer.supportsOption(QImageIOHandler::Description))
|
|||
writer.setText("Author", "John Smith");
|
||||
//! [2]
|
||||
|
||||
} // wrapper 2
|
||||
|
||||
|
||||
void wrapper3() {
|
||||
QImage image;
|
||||
|
||||
//! [3]
|
||||
QImageWriter writer("some/image.dds");
|
||||
if (writer.supportsOption(QImageIOHandler::SubType))
|
||||
writer.setSubType("A8R8G8B8");
|
||||
writer.write(image);
|
||||
//! [3]
|
||||
|
||||
} // wrapper3
|
||||
} // src_gui_image_qimagewriter
|
||||
|
|
|
|||
|
|
@ -47,6 +47,13 @@
|
|||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
#include <QLabel>
|
||||
#include <QMovie>
|
||||
|
||||
namespace src_gui_image_qmovie {
|
||||
|
||||
void wrapper0() {
|
||||
|
||||
|
||||
//! [0]
|
||||
QLabel label;
|
||||
|
|
@ -56,8 +63,15 @@ label.setMovie(movie);
|
|||
movie->start();
|
||||
//! [0]
|
||||
|
||||
} // wrapper0
|
||||
|
||||
|
||||
void wrapper1() {
|
||||
|
||||
//! [1]
|
||||
QMovie movie("racecar.gif");
|
||||
movie.setSpeed(200); // 2x speed
|
||||
//! [1]
|
||||
|
||||
} // wrapper1
|
||||
} // src_gui_image_qmovie
|
||||
|
|
|
|||
|
|
@ -47,22 +47,28 @@
|
|||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
#include <QBitmap>
|
||||
#include <QPixmap>
|
||||
|
||||
//! [0]
|
||||
static const char * const start_xpm[]={
|
||||
"16 15 8 1",
|
||||
"a c #cec6bd",
|
||||
....
|
||||
//! [0]
|
||||
namespace src_gui_image_qpixmap {
|
||||
|
||||
void wrapper0() {
|
||||
|
||||
//! [1]
|
||||
QPixmap myPixmap;
|
||||
myPixmap.setMask(myPixmap.createHeuristicMask());
|
||||
//! [1]
|
||||
|
||||
} // wrapper0
|
||||
|
||||
|
||||
void wrapper1() {
|
||||
|
||||
//! [2]
|
||||
QPixmap pixmap("background.png");
|
||||
QRegion exposed;
|
||||
pixmap.scroll(10, 10, pixmap.rect(), &exposed);
|
||||
//! [2]
|
||||
|
||||
} // wrapper1
|
||||
} // src_gui_image_qpixmap
|
||||
|
|
|
|||
|
|
@ -53,9 +53,7 @@
|
|||
|
||||
namespace src_gui_image_qpixmapcache {
|
||||
|
||||
void wrapper0() {
|
||||
QPainter *painter = nullptr;
|
||||
|
||||
void wrapper0(QPainter *painter) {
|
||||
//! [1]
|
||||
QPixmap pm;
|
||||
if (!QPixmapCache::find("my_big_image", &pm)) {
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ QPixmap::QPixmap(const QPixmap &pixmap)
|
|||
Note that it's possible to squeeze the XPM variable a little bit
|
||||
by using an unusual declaration:
|
||||
|
||||
\snippet code/src_gui_image_qpixmap.cpp 0
|
||||
\snippet code/src_gui_image_qimage.cpp 2
|
||||
|
||||
The extra \c const makes the entire definition read-only, which is
|
||||
slightly more efficient (for example, when the code is in a shared
|
||||
|
|
|
|||
Loading…
Reference in New Issue