diff options
author | Paul Wicking <paul.wicking@qt.io> | 2020-08-26 14:15:26 +0200 |
---|---|---|
committer | Paul Wicking <paul.wicking@qt.io> | 2020-08-28 12:32:22 +0200 |
commit | 4853cff109d51661b088269c4be3210846f396e4 (patch) | |
tree | 8c6562a66d68fe8e2eb7c3fe232cfbf5d6ae1d9e /src/gui/doc/snippets/code | |
parent | 176e7d4d8c634972c201b2d01a87536e182c1793 (diff) |
Doc: Compile painting snippets
Fix minor issues (e.g. whitespace, missing semi-colon) in passing.
Change-Id: I223cb257539d2ac4cb0a1ea209f0c3cebddb3d54
Done-with: Nico Vertriest <nico.vertriest@qt.io>
Task-number: QTBUG-81486
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'src/gui/doc/snippets/code')
9 files changed, 274 insertions, 12 deletions
diff --git a/src/gui/doc/snippets/code/code.pro b/src/gui/doc/snippets/code/code.pro index a5498f38a3..4e0e68554a 100644 --- a/src/gui/doc/snippets/code/code.pro +++ b/src/gui/doc/snippets/code/code.pro @@ -24,4 +24,12 @@ SOURCES = \ src_gui_math3d_qquaternion.cpp \ src_gui_opengl_qopenglbuffer.cpp \ src_gui_opengl_qopengldebug.cpp \ - src_gui_opengl_qopenglfunctions.cpp + src_gui_opengl_qopenglfunctions.cpp \ + src_gui_painting_qbrush.cpp \ + src_gui_painting_qcolor.cpp \ + src_gui_painting_qpainter.cpp \ + src_gui_painting_qpainterpath.cpp \ + src_gui_painting_qpen.cpp \ + src_gui_painting_qregion.cpp \ + src_gui_painting_qregion_unix.cpp \ + src_gui_painting_qtransform.cpp diff --git a/src/gui/doc/snippets/code/src_gui_painting_qbrush.cpp b/src/gui/doc/snippets/code/src_gui_painting_qbrush.cpp index 786d6ca183..842a547f83 100644 --- a/src/gui/doc/snippets/code/src_gui_painting_qbrush.cpp +++ b/src/gui/doc/snippets/code/src_gui_painting_qbrush.cpp @@ -47,6 +47,15 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QPainter> + +namespace src_gui_painting_qbrush { + +struct Wrapper : public QPaintDevice { + void wrapper(); +}; +void Wrapper::wrapper() { + //! [0] QPainter painter(this); @@ -59,3 +68,7 @@ painter.setBrush(Qt::NoBrush); painter.setPen(Qt::darkGreen); painter.drawRect(40, 40, 100, 100); //! [0] + + +} // Wrapper::wrapper +} // src_gui_painting_qbrush diff --git a/src/gui/doc/snippets/code/src_gui_painting_qcolor.cpp b/src/gui/doc/snippets/code/src_gui_painting_qcolor.cpp index 5285a19a0a..fa3d7c9733 100644 --- a/src/gui/doc/snippets/code/src_gui_painting_qcolor.cpp +++ b/src/gui/doc/snippets/code/src_gui_painting_qcolor.cpp @@ -47,13 +47,25 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QPainter> + +namespace src_gui_painting_qcolor { +int width() { return 1; }; +int height() { return 1; }; +QPainter painter; +void wrapper() { + //! [0] // Specify semi-transparent red painter.setBrush(QColor(255, 0, 0, 127)); -painter.drawRect(0, 0, width()/2, height()); +painter.drawRect(0, 0, width() / 2, height()); // Specify semi-transparent blue painter.setBrush(QColor(0, 0, 255, 127)); -painter.drawRect(0, 0, width(), height()/2); +painter.drawRect(0, 0, width(), height() / 2); //! [0] + + +} // wrapper +} // src_gui_painting_qcolor diff --git a/src/gui/doc/snippets/code/src_gui_painting_qpainter.cpp b/src/gui/doc/snippets/code/src_gui_painting_qpainter.cpp index d1ee6bbdea..3a72c2aed8 100644 --- a/src/gui/doc/snippets/code/src_gui_painting_qpainter.cpp +++ b/src/gui/doc/snippets/code/src_gui_painting_qpainter.cpp @@ -47,6 +47,26 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QOpenGLFunctions> +#include <QPaintEvent> +#include <QPainter> +#include <QPainterPath> +#include <QPicture> +#include <QRectF> +#include <QWidget> + + +namespace src_gui_painting_qpainter { +struct SimpleExampleWidget : public QPaintDevice { + void paintEvent(QPaintEvent *); + QRect rect(); +}; +struct MyWidget : public QWidget +{ + void paintEvent(QPaintEvent *); +}; +QLine drawingCode; + //! [0] void SimpleExampleWidget::paintEvent(QPaintEvent *) @@ -64,21 +84,48 @@ void MyWidget::paintEvent(QPaintEvent *) { QPainter p; p.begin(this); - p.drawLine(...); // drawing code + p.drawLine(drawingCode); // drawing code p.end(); } //! [1] +} // src_gui_painting_qpainter +namespace src_gui_painting_qpainter2 { +struct MyWidget : public QWidget +{ + void paintEvent(QPaintEvent *); + int background() { return 0; } + void wrapper1(); + void wrapper2(); + void wrapper3(); + void wrapper4(); + void wrapper5(); + void wrapper6(); + void wrapper7(); + void wrapper8(); + void wrapper9(); + void wrapper10(); + void wrapper11(); + void wrapper12(); + void wrapper13(); + void wrapper14(); + void wrapper15(); +}; +QLine drawingCode; //! [2] void MyWidget::paintEvent(QPaintEvent *) { QPainter p(this); - p.drawLine(...); // drawing code + p.drawLine(drawingCode); // drawing code } //! [2] +void wrapper0() { +QPainter *painter = nullptr; +QPainter *painter2 = nullptr; +QPaintDevice *myWidget = nullptr; //! [3] painter->begin(0); // impossible - paint device cannot be 0 @@ -89,6 +136,13 @@ painter->begin(myWidget); painter2->begin(myWidget); // impossible - only one painter at a time //! [3] +} // wrapper0 + +namespace QPainterWrapper { +struct QPainter { + void rotate(qreal angle); + void setWorldTransform(QTransform matrix, bool); +}; //! [4] void QPainter::rotate(qreal angle) @@ -99,7 +153,9 @@ void QPainter::rotate(qreal angle) } //! [4] +} // QPainterWrapper +void MyWidget::wrapper1() { //! [5] QPainterPath path; path.moveTo(20, 80); @@ -117,8 +173,11 @@ QLineF line(10.0, 80.0, 90.0, 20.0); QPainter(this); painter.drawLine(line); //! [6] +} // MyWidget::wrapper1() +void MyWidget::wrapper2() { + //! [7] QRectF rectangle(10.0, 20.0, 80.0, 60.0); @@ -126,6 +185,10 @@ QPainter painter(this); painter.drawRect(rectangle); //! [7] +} // MyWidget::wrapper2 + + +void MyWidget::wrapper3() { //! [8] QRectF rectangle(10.0, 20.0, 80.0, 60.0); @@ -134,6 +197,10 @@ QPainter painter(this); painter.drawRoundedRect(rectangle, 20.0, 15.0); //! [8] +} // MyWidget::wrapper3 + + +void MyWidget::wrapper4() { //! [9] QRectF rectangle(10.0, 20.0, 80.0, 60.0); @@ -142,6 +209,10 @@ QPainter painter(this); painter.drawEllipse(rectangle); //! [9] +} // MyWidget::wrapper4 + + +void MyWidget::wrapper5() { //! [10] QRectF rectangle(10.0, 20.0, 80.0, 60.0); @@ -152,6 +223,10 @@ QPainter painter(this); painter.drawArc(rectangle, startAngle, spanAngle); //! [10] +} // MyWidget::wrapper5 + + +void MyWidget::wrapper6() { //! [11] QRectF rectangle(10.0, 20.0, 80.0, 60.0); @@ -162,6 +237,11 @@ QPainter painter(this); painter.drawPie(rectangle, startAngle, spanAngle); //! [11] +} // MyWidget::wrapper6 + + +void MyWidget::wrapper7() { +QRect rect; //! [12] QRectF rectangle(10.0, 20.0, 80.0, 60.0); @@ -171,8 +251,12 @@ int spanAngle = 120 * 16; QPainter painter(this); painter.drawChord(rect, startAngle, spanAngle); //! [12] +Q_UNUSED(rectangle); +} // MyWidget::wrapper7 +void MyWidget::wrapper8() { + //! [13] static const QPointF points[3] = { QPointF(10.0, 80.0), @@ -184,7 +268,10 @@ QPainter painter(this); painter.drawPolyline(points, 3); //! [13] +} // MyWidget::wrapper8 + +void MyWidget::wrapper9() { //! [14] static const QPointF points[4] = { QPointF(10.0, 80.0), @@ -197,6 +284,10 @@ QPainter painter(this); painter.drawPolygon(points, 4); //! [14] +} // MyWidget::wrapper9 + + +void MyWidget::wrapper10() { //! [15] static const QPointF points[4] = { @@ -220,27 +311,48 @@ QPainter(this); painter.drawPixmap(target, pixmap, source); //! [16] +} // MyWidget::wrapper10 + + +void MyWidget::wrapper11() { +QRect rect; //! [17] QPainter painter(this); painter.drawText(rect, Qt::AlignCenter, tr("Qt\nProject")); //! [17] +} // MyWidget::wrapper11 + + +QRectF fillRect(QRect rect, int background) { + Q_UNUSED(rect); + Q_UNUSED(background); + return QRectF(); +}; +void MyWidget::wrapper12() { +QRect rectangle; //! [18] QPicture picture; -QPointF point(10.0, 20.0) +QPointF point(10.0, 20.0); picture.load("drawing.pic"); QPainter painter(this); painter.drawPicture(0, 0, picture); //! [18] +Q_UNUSED(point); + //! [19] -fillRect(rectangle, background()). +fillRect(rectangle, background()); //! [19] +} // MyWidget::wrapper12 + + +void MyWidget::wrapper13() { //! [20] QRectF target(10.0, 20.0, 80.0, 60.0); @@ -251,6 +363,10 @@ QPainter painter(this); painter.drawImage(target, image, source); //! [20] +} // MyWidget::wrapper13 + + +void MyWidget::wrapper14() { //! [21] QPainter painter(this); @@ -268,6 +384,11 @@ glDisable(GL_SCISSOR_TEST); painter.endNativePainting(); //! [21] +} // MyWidget::wrapper14 + + +void MyWidget::wrapper15() { + //! [drawText] QPainter painter(this); QFont font = painter.font(); @@ -287,3 +408,7 @@ pen.setStyle(Qt::DashLine); painter.setPen(pen); painter.drawRect(rectangle.adjusted(0, 0, -pen.width(), -pen.width())); //! [drawText] + + +} // MyWidget::wrapper15 +} // src_gui_painting_qpainter2 diff --git a/src/gui/doc/snippets/code/src_gui_painting_qpainterpath.cpp b/src/gui/doc/snippets/code/src_gui_painting_qpainterpath.cpp index e6d72fce12..f11b6f59c5 100644 --- a/src/gui/doc/snippets/code/src_gui_painting_qpainterpath.cpp +++ b/src/gui/doc/snippets/code/src_gui_painting_qpainterpath.cpp @@ -47,6 +47,27 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QLinearGradient> +#include <QPainter> +#include <QPainterPath> +#include <QPen> + +namespace src_gui_painting_qpainterpath { +struct Wrapper : QPaintDevice +{ + Q_OBJECT + + void wrapper0(); + void wrapper1(); + void wrapper2(); + void wrapper3(); + void wrapper4(); + void wrapper5(); + void wrapper6(); + void wrapper7(); +}; + +void Wrapper::wrapper0() { //! [0] QPainterPath path; @@ -65,6 +86,13 @@ painter.setBrush(QColor(122, 163, 39)); painter.drawPath(path); //! [0] +} // Wrapper::wrapper0 + + +void Wrapper::wrapper1() { +const QPointF c1; +const QPointF c2; +const QPointF endPoint; //! [1] QLinearGradient myGradient; @@ -79,13 +107,17 @@ painter.setPen(myPen); painter.drawPath(myPath); //! [1] +} // Wrapper::wrapper1 -//! [2] + +void Wrapper::wrapper2() { +const QRectF boundingRect; +qreal startAngle = 0; +qreal sweepLength = 0; +QPointF center; QLinearGradient myGradient; QPen myPen; - -QPointF center, startPoint; - +//! [2] QPainterPath myPath; myPath.moveTo(center); myPath.arcTo(boundingRect, startAngle, @@ -97,6 +129,10 @@ painter.setPen(myPen); painter.drawPath(myPath); //! [2] +} // Wrapper::wrapper2 + + +void Wrapper::wrapper3() { //! [3] QLinearGradient myGradient; @@ -112,6 +148,10 @@ painter.setPen(myPen); painter.drawPath(myPath); //! [3] +} // Wrapper::wrapper3 + + +void Wrapper::wrapper4() { //! [4] QLinearGradient myGradient; @@ -127,6 +167,10 @@ painter.setPen(myPen); painter.drawPath(myPath); //! [4] +} // Wrapper::wrapper4 + + +void Wrapper::wrapper5() { //! [5] QLinearGradient myGradient; @@ -142,6 +186,12 @@ painter.setPen(myPen); painter.drawPath(myPath); //! [5] +} // Wrapper::wrapper5 + + +void Wrapper::wrapper6() { +qreal x = 0; +qreal y = 0; //! [6] QLinearGradient myGradient; @@ -157,3 +207,7 @@ painter.setBrush(myGradient); painter.setPen(myPen); painter.drawPath(myPath); //! [6] + + +} // Wrapper::wrapper6 +} // src_gui_painting_qpainterpath diff --git a/src/gui/doc/snippets/code/src_gui_painting_qpen.cpp b/src/gui/doc/snippets/code/src_gui_painting_qpen.cpp index a1c4463edc..973037cf42 100644 --- a/src/gui/doc/snippets/code/src_gui_painting_qpen.cpp +++ b/src/gui/doc/snippets/code/src_gui_painting_qpen.cpp @@ -47,6 +47,19 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QPainter> +#include <QPen> + +namespace src_gui_painting_qpen { +struct Wrapper : QPaintDevice +{ + void wrapper0(); + void wrapper1(); + void wrapper2(); + void wrapper3(); +}; + +void Wrapper::wrapper0() { //! [0] QPainter painter(this); @@ -54,6 +67,10 @@ QPen pen(Qt::green, 3, Qt::DashDotLine, Qt::RoundCap, Qt::RoundJoin); painter.setPen(pen); //! [0] +} // Wrapper::wrapper0 + + +void Wrapper::wrapper1() { //! [1] QPainter painter(this); @@ -68,6 +85,10 @@ pen.setJoinStyle(Qt::RoundJoin); painter.setPen(pen); //! [1] +} // Wrapper::wrapper1 + + +void Wrapper::wrapper2() { //! [2] QPen pen; @@ -80,7 +101,10 @@ dashes << 1 << space << 3 << space << 9 << space pen.setDashPattern(dashes); //! [2] +} // Wrapper::wrapper2 + +void Wrapper::wrapper3() { //! [3] QPen pen; QList<qreal> dashes; @@ -89,3 +113,6 @@ dashes << 1 << space << 3 << space << 9 << space << 27 << space << 9 << space; pen.setDashPattern(dashes); //! [3] + +} // Wrapper::wrapper3 +} // src_gui_painting_qpen diff --git a/src/gui/doc/snippets/code/src_gui_painting_qregion.cpp b/src/gui/doc/snippets/code/src_gui_painting_qregion.cpp index 496791dc0f..a1123564aa 100644 --- a/src/gui/doc/snippets/code/src_gui_painting_qregion.cpp +++ b/src/gui/doc/snippets/code/src_gui_painting_qregion.cpp @@ -47,6 +47,14 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QPaintEvent> +#include <QPainter> + +namespace src_gui_painting_qregion { +struct MyWidget : public QPaintDevice +{ + void paintEvent(QPaintEvent *); +}; //! [0] void MyWidget::paintEvent(QPaintEvent *) @@ -58,6 +66,8 @@ void MyWidget::paintEvent(QPaintEvent *) QPainter painter(this); painter.setClipRegion(r3); - ... // paint clipped graphics + // ... // paint clipped graphics } //! [0] + +} // src_gui_painting_qregion diff --git a/src/gui/doc/snippets/code/src_gui_painting_qregion_unix.cpp b/src/gui/doc/snippets/code/src_gui_painting_qregion_unix.cpp index ab22507c4f..d45521a791 100644 --- a/src/gui/doc/snippets/code/src_gui_painting_qregion_unix.cpp +++ b/src/gui/doc/snippets/code/src_gui_painting_qregion_unix.cpp @@ -47,7 +47,11 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QRegion> +namespace src_gui_painting_qregion_unix { + +void wrapper() { //! [0] QRegion r1(10, 10, 20, 20); r1.isEmpty(); // false @@ -62,3 +66,6 @@ r3.isEmpty(); // true r3 = r1.united(r2); // r3: union of r1 and r2 r3.isEmpty(); // false //! [0] + +} // wrapper +} // src_gui_painting_qregion_unix diff --git a/src/gui/doc/snippets/code/src_gui_painting_qtransform.cpp b/src/gui/doc/snippets/code/src_gui_painting_qtransform.cpp index 4acc2f12b7..23d55febfe 100644 --- a/src/gui/doc/snippets/code/src_gui_painting_qtransform.cpp +++ b/src/gui/doc/snippets/code/src_gui_painting_qtransform.cpp @@ -48,6 +48,9 @@ ** ****************************************************************************/ +namespace src_gui_painting_qtransform { +/* wrap non-code snippets + //! [0] x' = m11*x + m21*y + dx y' = m22*y + m12*x + dy @@ -90,3 +93,6 @@ if (is not affine) { y' /= w' } //! [3] + +*/ // wrap non-code snippets +} // src_gui_painting_qtransform |