From 879f98106d5974ef19c96cb228ca032701b94556 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 24 Aug 2017 11:19:21 +0200 Subject: Revamp QtWidgets/DragAndDrop examples to C++11 Introduce nullptr and replace foreach with new C++11 range based for loops. Minor fixups of signals, file dialog usage. Apply the same changes to the ItemViews/puzzle example since it shares parts of the code with DragAndDrop/puzzle. Make some changes to both examples to that the diff of the two becomes small for easier comparison. Task-number: QTBUG-60635 Change-Id: I8af824229ebac24d6ec151eae92176d227695490 Reviewed-by: Venugopal Shivashankar Reviewed-by: Gatis Paeglis --- examples/widgets/draganddrop/puzzle/puzzlewidget.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'examples/widgets/draganddrop/puzzle/puzzlewidget.h') diff --git a/examples/widgets/draganddrop/puzzle/puzzlewidget.h b/examples/widgets/draganddrop/puzzle/puzzlewidget.h index 7dcb7dd497..40dd654af6 100644 --- a/examples/widgets/draganddrop/puzzle/puzzlewidget.h +++ b/examples/widgets/draganddrop/puzzle/puzzlewidget.h @@ -51,9 +51,9 @@ #ifndef PUZZLEWIDGET_H #define PUZZLEWIDGET_H -#include #include #include +#include #include QT_BEGIN_NAMESPACE @@ -67,7 +67,7 @@ class PuzzleWidget : public QWidget Q_OBJECT public: - explicit PuzzleWidget(int imageSize, QWidget *parent = 0); + explicit PuzzleWidget(int imageSize, QWidget *parent = nullptr); void clear(); int pieceSize() const; @@ -85,11 +85,16 @@ protected: void paintEvent(QPaintEvent *event) override; private: + struct Piece { + QPixmap pixmap; + QRect rect; + QPoint location; + }; + + int findPiece(const QRect &pieceRect) const; const QRect targetSquare(const QPoint &position) const; - QList piecePixmaps; - QList pieceRects; - QList pieceLocations; + QVector pieces; QRect highlightedRect; int inPlace; int m_ImageSize; -- cgit v1.2.3