summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAlexandru Croitor <[email protected]>2019-10-11 16:16:29 +0200
committerAlexandru Croitor <[email protected]>2019-10-11 16:23:19 +0200
commitf4b4c4f79b629498f3cddbbc10df8c1b4d6020d9 (patch)
tree4119707660438ff58bd51f9cbe0f9e2a33f4b806 /examples
parent9bd6cec74dbbc5aece55dc0c8808494db29b9963 (diff)
parent93f2f33a49f6c96a4f94f344edf03164ed944d02 (diff)
Merge remote-tracking branch 'origin/wip/qt6' into wip/cmake
Diffstat (limited to 'examples')
-rw-r--r--examples/corelib/threads/doc/src/mandelbrot.qdoc4
-rw-r--r--examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp2
-rw-r--r--examples/widgets/animation/easing/window.cpp7
-rw-r--r--examples/widgets/animation/stickman/animation.cpp18
-rw-r--r--examples/widgets/animation/stickman/animation.h4
-rw-r--r--examples/widgets/animation/stickman/graphicsview.cpp12
-rw-r--r--examples/widgets/animation/stickman/graphicsview.h12
-rw-r--r--examples/widgets/animation/stickman/lifecycle.cpp19
-rw-r--r--examples/widgets/animation/stickman/lifecycle.h11
-rw-r--r--examples/widgets/animation/stickman/node.h4
-rw-r--r--examples/widgets/animation/stickman/rectbutton.cpp7
-rw-r--r--examples/widgets/animation/stickman/rectbutton.h8
-rw-r--r--examples/widgets/animation/stickman/stickman.cpp29
-rw-r--r--examples/widgets/animation/stickman/stickman.h13
-rw-r--r--examples/widgets/animation/sub-attaq/animationmanager.cpp17
-rw-r--r--examples/widgets/animation/sub-attaq/animationmanager.h10
-rw-r--r--examples/widgets/animation/sub-attaq/boat.cpp19
-rw-r--r--examples/widgets/animation/sub-attaq/boat.h7
-rw-r--r--examples/widgets/animation/sub-attaq/boat_p.h20
-rw-r--r--examples/widgets/animation/sub-attaq/bomb.cpp19
-rw-r--r--examples/widgets/animation/sub-attaq/bomb.h6
-rw-r--r--examples/widgets/animation/sub-attaq/graphicsscene.cpp73
-rw-r--r--examples/widgets/animation/sub-attaq/graphicsscene.h21
-rw-r--r--examples/widgets/animation/sub-attaq/mainwindow.cpp7
-rw-r--r--examples/widgets/animation/sub-attaq/mainwindow.h8
-rw-r--r--examples/widgets/animation/sub-attaq/pixmapitem.cpp5
-rw-r--r--examples/widgets/animation/sub-attaq/pixmapitem.h8
-rw-r--r--examples/widgets/animation/sub-attaq/progressitem.cpp7
-rw-r--r--examples/widgets/animation/sub-attaq/progressitem.h8
-rw-r--r--examples/widgets/animation/sub-attaq/qanimationstate.cpp4
-rw-r--r--examples/widgets/animation/sub-attaq/qanimationstate.h10
-rw-r--r--examples/widgets/animation/sub-attaq/states.cpp28
-rw-r--r--examples/widgets/animation/sub-attaq/states.h24
-rw-r--r--examples/widgets/animation/sub-attaq/submarine.cpp26
-rw-r--r--examples/widgets/animation/sub-attaq/submarine.h11
-rw-r--r--examples/widgets/animation/sub-attaq/submarine_p.h9
-rw-r--r--examples/widgets/animation/sub-attaq/textinformationitem.cpp9
-rw-r--r--examples/widgets/animation/sub-attaq/textinformationitem.h6
-rw-r--r--examples/widgets/animation/sub-attaq/torpedo.cpp23
-rw-r--r--examples/widgets/animation/sub-attaq/torpedo.h6
-rw-r--r--examples/widgets/graphicsview/boxes/scene.cpp4
-rw-r--r--examples/widgets/graphicsview/chip/view.cpp2
-rw-r--r--examples/widgets/graphicsview/elasticnodes/graphwidget.cpp2
-rw-r--r--examples/widgets/itemviews/dirview/main.cpp8
-rw-r--r--examples/widgets/painting/affine/xform.cpp2
-rw-r--r--examples/widgets/tools/codecs/encodingdialog.cpp2
-rw-r--r--examples/widgets/tools/i18n/languagechooser.cpp10
-rw-r--r--examples/widgets/widgets/mousebuttons/buttontester.cpp11
48 files changed, 263 insertions, 319 deletions
diff --git a/examples/corelib/threads/doc/src/mandelbrot.qdoc b/examples/corelib/threads/doc/src/mandelbrot.qdoc
index 274874632eb..9e3fdc1dfe0 100644
--- a/examples/corelib/threads/doc/src/mandelbrot.qdoc
+++ b/examples/corelib/threads/doc/src/mandelbrot.qdoc
@@ -304,8 +304,8 @@
\snippet threads/mandelbrot/mandelbrotwidget.cpp 12
The wheel event handler is reimplemented to make the mouse wheel
- control the zoom level. QWheelEvent::delta() returns the angle of
- the wheel mouse movement, in eights of a degree. For most mice,
+ control the zoom level. QWheelEvent::angleDelta() returns the angle
+ of the wheel mouse movement, in eighths of a degree. For most mice,
one wheel step corresponds to 15 degrees. We find out how many
mouse steps we have and determine the resulting zoom factor.
For example, if we have two wheel steps in the positive direction
diff --git a/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp b/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp
index 71d0abb09f2..822791533b0 100644
--- a/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp
+++ b/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp
@@ -176,7 +176,7 @@ void MandelbrotWidget::keyPressEvent(QKeyEvent *event)
//! [12]
void MandelbrotWidget::wheelEvent(QWheelEvent *event)
{
- int numDegrees = event->delta() / 8;
+ int numDegrees = event->angleDelta().y() / 8;
double numSteps = numDegrees / 15.0f;
zoom(pow(ZoomInFactor, numSteps));
}
diff --git a/examples/widgets/animation/easing/window.cpp b/examples/widgets/animation/easing/window.cpp
index aa121473880..d1d63483618 100644
--- a/examples/widgets/animation/easing/window.cpp
+++ b/examples/widgets/animation/easing/window.cpp
@@ -55,11 +55,10 @@ Window::Window(QWidget *parent)
m_iconSize(64, 64)
{
m_ui.setupUi(this);
- QButtonGroup *buttonGroup = findChild<QButtonGroup *>(); // ### workaround for uic in 4.4
m_ui.easingCurvePicker->setIconSize(m_iconSize);
m_ui.easingCurvePicker->setMinimumHeight(m_iconSize.height() + 50);
- buttonGroup->setId(m_ui.lineRadio, 0);
- buttonGroup->setId(m_ui.circleRadio, 1);
+ m_ui.buttonGroup->setId(m_ui.lineRadio, 0);
+ m_ui.buttonGroup->setId(m_ui.circleRadio, 1);
QEasingCurve dummy;
m_ui.periodSpinBox->setValue(dummy.period());
@@ -68,7 +67,7 @@ Window::Window(QWidget *parent)
connect(m_ui.easingCurvePicker, &QListWidget::currentRowChanged,
this, &Window::curveChanged);
- connect(buttonGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
+ connect(m_ui.buttonGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
this, &Window::pathChanged);
connect(m_ui.periodSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this, &Window::periodChanged);
diff --git a/examples/widgets/animation/stickman/animation.cpp b/examples/widgets/animation/stickman/animation.cpp
index 5c2d1682af4..73d79adc840 100644
--- a/examples/widgets/animation/stickman/animation.cpp
+++ b/examples/widgets/animation/stickman/animation.cpp
@@ -50,16 +50,13 @@
#include "animation.h"
-#include <QPointF>
-#include <QVector>
#include <QIODevice>
#include <QDataStream>
class Frame
{
public:
- Frame() {
- }
+ Frame() = default;
int nodeCount() const
{
@@ -85,9 +82,8 @@ private:
QVector<QPointF> m_nodePositions;
};
-Animation::Animation()
+Animation::Animation() : m_currentFrame(0)
{
- m_currentFrame = 0;
m_frames.append(new Frame);
}
@@ -103,6 +99,8 @@ void Animation::setTotalFrames(int totalFrames)
while (totalFrames < m_frames.size())
delete m_frames.takeLast();
+
+ setCurrentFrame(m_currentFrame);
}
int Animation::totalFrames() const
@@ -112,7 +110,7 @@ int Animation::totalFrames() const
void Animation::setCurrentFrame(int currentFrame)
{
- m_currentFrame = qMax(qMin(currentFrame, totalFrames()-1), 0);
+ m_currentFrame = qBound(0, currentFrame, totalFrames() - 1);
}
int Animation::currentFrame() const
@@ -177,18 +175,16 @@ void Animation::load(QIODevice *device)
int frameCount;
stream >> frameCount;
- for (int i=0; i<frameCount; ++i) {
-
+ for (int i = 0; i < frameCount; ++i) {
int nodeCount;
stream >> nodeCount;
Frame *frame = new Frame;
frame->setNodeCount(nodeCount);
- for (int j=0; j<nodeCount; ++j) {
+ for (int j = 0; j < nodeCount; ++j) {
QPointF pos;
stream >> pos;
-
frame->setNodePos(j, pos);
}
diff --git a/examples/widgets/animation/stickman/animation.h b/examples/widgets/animation/stickman/animation.h
index e57847aeaa6..5cc1133ac06 100644
--- a/examples/widgets/animation/stickman/animation.h
+++ b/examples/widgets/animation/stickman/animation.h
@@ -52,8 +52,8 @@
#define ANIMATION_H
#include <QPointF>
-#include <QList>
#include <QString>
+#include <QVector>
class Frame;
QT_BEGIN_NAMESPACE
@@ -85,7 +85,7 @@ public:
private:
QString m_name;
- QList<Frame *> m_frames;
+ QVector<Frame *> m_frames;
int m_currentFrame;
};
diff --git a/examples/widgets/animation/stickman/graphicsview.cpp b/examples/widgets/animation/stickman/graphicsview.cpp
index 7058e153453..0f5800cff3a 100644
--- a/examples/widgets/animation/stickman/graphicsview.cpp
+++ b/examples/widgets/animation/stickman/graphicsview.cpp
@@ -51,13 +51,8 @@
#include "graphicsview.h"
#include "stickman.h"
-#include <QtGui/QKeyEvent>
-#include <QtWidgets/QGraphicsScene>
-#include <QtWidgets/QGraphicsView>
-
-GraphicsView::GraphicsView(QWidget *parent)
- : QGraphicsView(parent), m_editor(nullptr)
-{}
+#include <QKeyEvent>
+#include <QGraphicsScene>
void GraphicsView::keyPressEvent(QKeyEvent *e)
{
@@ -66,7 +61,8 @@ void GraphicsView::keyPressEvent(QKeyEvent *e)
emit keyPressed(Qt::Key(e->key()));
}
-void GraphicsView::resizeEvent(QResizeEvent *)
+void GraphicsView::resizeEvent(QResizeEvent *e)
{
fitInView(scene()->sceneRect());
+ QGraphicsView::resizeEvent(e);
}
diff --git a/examples/widgets/animation/stickman/graphicsview.h b/examples/widgets/animation/stickman/graphicsview.h
index 361fee219d7..29f4c6237e8 100644
--- a/examples/widgets/animation/stickman/graphicsview.h
+++ b/examples/widgets/animation/stickman/graphicsview.h
@@ -51,24 +51,20 @@
#ifndef GRAPHICSVIEW_H
#define GRAPHICSVIEW_H
-#include <QtWidgets/QGraphicsView>
+#include <QGraphicsView>
-class MainWindow;
class GraphicsView: public QGraphicsView
{
Q_OBJECT
public:
- GraphicsView(QWidget *parent = nullptr);
+ using QGraphicsView::QGraphicsView;
protected:
- void resizeEvent(QResizeEvent *event) override;
- void keyPressEvent(QKeyEvent *) override;
+ void resizeEvent(QResizeEvent *e) override;
+ void keyPressEvent(QKeyEvent *e) override;
signals:
void keyPressed(int key);
-
-private:
- MainWindow *m_editor;
};
#endif
diff --git a/examples/widgets/animation/stickman/lifecycle.cpp b/examples/widgets/animation/stickman/lifecycle.cpp
index 046e3f4cd17..5ad284c590e 100644
--- a/examples/widgets/animation/stickman/lifecycle.cpp
+++ b/examples/widgets/animation/stickman/lifecycle.cpp
@@ -54,8 +54,15 @@
#include "animation.h"
#include "graphicsview.h"
-#include <QtCore>
-#include <QtWidgets>
+#include <QEventTransition>
+#include <QFile>
+#include <QParallelAnimationGroup>
+#include <QPropertyAnimation>
+#include <QRandomGenerator>
+#include <QSignalTransition>
+#include <QState>
+#include <QStateMachine>
+#include <QTimer>
class KeyPressTransition: public QSignalTransition
{
@@ -107,7 +114,7 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
// Create animation group to be used for all transitions
m_animationGroup = new QParallelAnimationGroup();
const int stickManNodeCount = m_stickMan->nodeCount();
- for (int i=0; i<stickManNodeCount; ++i) {
+ for (int i = 0; i < stickManNodeCount; ++i) {
QPropertyAnimation *pa = new QPropertyAnimation(m_stickMan->node(i), "pos");
m_animationGroup->addAnimation(pa);
}
@@ -175,7 +182,7 @@ void LifeCycle::addActivity(const QString &fileName, Qt::Key key, QObject *sende
QState *state = makeState(m_alive, fileName);
m_alive->addTransition(new KeyPressTransition(m_keyReceiver, key, state));
- if (sender || signal)
+ if (sender && signal)
m_alive->addTransition(sender, signal, state);
}
@@ -192,13 +199,13 @@ QState *LifeCycle::makeState(QState *parentState, const QString &animationFileNa
const int frameCount = animation.totalFrames();
QState *previousState = nullptr;
- for (int i=0; i<frameCount; ++i) {
+ for (int i = 0; i < frameCount; ++i) {
animation.setCurrentFrame(i);
//! [1]
QState *frameState = new QState(topLevel);
const int nodeCount = animation.nodeCount();
- for (int j=0; j<nodeCount; ++j)
+ for (int j = 0; j < nodeCount; ++j)
frameState->assignProperty(m_stickMan->node(j), "pos", animation.nodePos(j));
//! [1]
diff --git a/examples/widgets/animation/stickman/lifecycle.h b/examples/widgets/animation/stickman/lifecycle.h
index e3f98766768..21ab99276d8 100644
--- a/examples/widgets/animation/stickman/lifecycle.h
+++ b/examples/widgets/animation/stickman/lifecycle.h
@@ -53,16 +53,16 @@
#include <Qt>
-class StickMan;
QT_BEGIN_NAMESPACE
-class QStateMachine;
-class QAnimationGroup;
-class QState;
class QAbstractState;
class QAbstractTransition;
+class QAnimationGroup;
class QObject;
+class QState;
+class QStateMachine;
QT_END_NAMESPACE
class GraphicsView;
+class StickMan;
class LifeCycle
{
public:
@@ -70,7 +70,8 @@ public:
~LifeCycle();
void setDeathAnimation(const QString &fileName);
- void addActivity(const QString &fileName, Qt::Key key, QObject *sender = NULL, const char *signal = NULL);
+ void addActivity(const QString &fileName, Qt::Key key,
+ QObject *sender = nullptr, const char *signal = nullptr);
void start();
diff --git a/examples/widgets/animation/stickman/node.h b/examples/widgets/animation/stickman/node.h
index 679999b7e87..2b393c60c10 100644
--- a/examples/widgets/animation/stickman/node.h
+++ b/examples/widgets/animation/stickman/node.h
@@ -51,13 +51,13 @@
#ifndef NODE_H
#define NODE_H
-#include <QGraphicsItem>
+#include <QGraphicsObject>
class Node: public QGraphicsObject
{
Q_OBJECT
public:
- explicit Node(const QPointF &pos, QGraphicsItem *parent = 0);
+ explicit Node(const QPointF &pos, QGraphicsItem *parent = nullptr);
~Node();
QRectF boundingRect() const override;
diff --git a/examples/widgets/animation/stickman/rectbutton.cpp b/examples/widgets/animation/stickman/rectbutton.cpp
index 7eea94ae6fe..5174d0aeaf7 100644
--- a/examples/widgets/animation/stickman/rectbutton.cpp
+++ b/examples/widgets/animation/stickman/rectbutton.cpp
@@ -51,12 +51,7 @@
#include "rectbutton.h"
#include <QPainter>
-RectButton::RectButton(QString buttonText) : m_ButtonText(buttonText)
-{
-}
-
-
-RectButton::~RectButton()
+RectButton::RectButton(const QString &buttonText) : m_ButtonText(buttonText)
{
}
diff --git a/examples/widgets/animation/stickman/rectbutton.h b/examples/widgets/animation/stickman/rectbutton.h
index ab47bad0f75..ee6cd3f5309 100644
--- a/examples/widgets/animation/stickman/rectbutton.h
+++ b/examples/widgets/animation/stickman/rectbutton.h
@@ -57,19 +57,19 @@ class RectButton : public QGraphicsObject
{
Q_OBJECT
public:
- RectButton(QString buttonText);
- ~RectButton();
+ RectButton(const QString &buttonText);
QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
protected:
- QString m_ButtonText;
-
void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
signals:
void clicked();
+
+private:
+ QString m_ButtonText;
};
#endif // RECTBUTTON_H
diff --git a/examples/widgets/animation/stickman/stickman.cpp b/examples/widgets/animation/stickman/stickman.cpp
index 5725f64eec2..3f373b6b52f 100644
--- a/examples/widgets/animation/stickman/stickman.cpp
+++ b/examples/widgets/animation/stickman/stickman.cpp
@@ -52,10 +52,9 @@
#include "node.h"
#include <QPainter>
-#include <QTimer>
-#include <qmath.h>
+#include <QtMath>
-static const qreal Coords[NodeCount * 2] = {
+static constexpr qreal Coords[NodeCount * 2] = {
0.0, -150.0, // head, #0
0.0, -100.0, // body pentagon, top->bottom, left->right, #1 - 5
@@ -81,7 +80,7 @@ static const qreal Coords[NodeCount * 2] = {
};
-static const int Bones[BoneCount * 2] = {
+static constexpr int Bones[BoneCount * 2] = {
0, 1, // neck
1, 2, // body
@@ -117,19 +116,13 @@ static const int Bones[BoneCount * 2] = {
StickMan::StickMan()
{
- m_sticks = true;
- m_isDead = false;
- m_pixmap = QPixmap("images/head.png");
- m_penColor = Qt::white;
- m_fillColor = Qt::black;
-
// Set up start position of limbs
- for (int i=0; i<NodeCount; ++i) {
+ for (int i = 0; i < NodeCount; ++i) {
m_nodes[i] = new Node(QPointF(Coords[i * 2], Coords[i * 2 + 1]), this);
connect(m_nodes[i], &Node::positionChanged, this, &StickMan::childPositionChanged);
}
- for (int i=0; i<BoneCount; ++i) {
+ for (int i = 0; i < BoneCount; ++i) {
int n1 = Bones[i * 2];
int n2 = Bones[i * 2 + 1];
@@ -137,16 +130,12 @@ StickMan::StickMan()
Node *node2 = m_nodes[n2];
QPointF dist = node1->pos() - node2->pos();
- m_perfectBoneLengths[i] = sqrt(pow(dist.x(),2) + pow(dist.y(),2));
+ m_perfectBoneLengths[i] = sqrt(pow(dist.x(), 2) + pow(dist.y(), 2));
}
startTimer(10);
}
-StickMan::~StickMan()
-{
-}
-
void StickMan::childPositionChanged()
{
prepareGeometryChange();
@@ -155,7 +144,7 @@ void StickMan::childPositionChanged()
void StickMan::setDrawSticks(bool on)
{
m_sticks = on;
- for (int i=0;i<nodeCount();++i) {
+ for (int i = 0; i < nodeCount(); ++i) {
Node *node = m_nodes[i];
node->setVisible(on);
}
@@ -188,7 +177,7 @@ void StickMan::stabilize()
{
static const qreal threshold = 0.001;
- for (int i=0; i<BoneCount; ++i) {
+ for (int i = 0; i < BoneCount; ++i) {
int n1 = Bones[i * 2];
int n2 = Bones[i * 2 + 1];
@@ -236,7 +225,7 @@ void StickMan::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge
stabilize();
if (m_sticks) {
painter->setPen(Qt::white);
- for (int i=0; i<BoneCount; ++i) {
+ for (int i = 0; i < BoneCount; ++i) {
int n1 = Bones[i * 2];
int n2 = Bones[i * 2 + 1];
diff --git a/examples/widgets/animation/stickman/stickman.h b/examples/widgets/animation/stickman/stickman.h
index f2311a0358b..63c02abc8ff 100644
--- a/examples/widgets/animation/stickman/stickman.h
+++ b/examples/widgets/animation/stickman/stickman.h
@@ -57,8 +57,6 @@ static const int NodeCount = 16;
static const int BoneCount = 24;
class Node;
-QT_BEGIN_NAMESPACE
-QT_END_NAMESPACE
class StickMan: public QGraphicsObject
{
Q_OBJECT
@@ -67,7 +65,6 @@ class StickMan: public QGraphicsObject
Q_PROPERTY(bool isDead WRITE setIsDead READ isDead)
public:
StickMan();
- ~StickMan();
QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
@@ -101,13 +98,11 @@ private:
Node *m_nodes[NodeCount];
qreal m_perfectBoneLengths[BoneCount];
- uint m_sticks : 1;
- uint m_isDead : 1;
- uint m_reserved : 30;
+ bool m_sticks = true;
+ bool m_isDead = false;
- QPixmap m_pixmap;
- QColor m_penColor;
- QColor m_fillColor;
+ QColor m_penColor = Qt::white;
+ QColor m_fillColor = Qt::black;
};
#endif // STICKMAN_H
diff --git a/examples/widgets/animation/sub-attaq/animationmanager.cpp b/examples/widgets/animation/sub-attaq/animationmanager.cpp
index a611641613f..261cbd1e1cd 100644
--- a/examples/widgets/animation/sub-attaq/animationmanager.cpp
+++ b/examples/widgets/animation/sub-attaq/animationmanager.cpp
@@ -51,22 +51,13 @@
//Own
#include "animationmanager.h"
-//Qt
-#include <QtCore/QAbstractAnimation>
-#include <QtCore/QDebug>
-
-// the universe's only animation manager
-AnimationManager *AnimationManager::instance = nullptr;
-
-AnimationManager::AnimationManager()
-{
-}
+#include <QAbstractAnimation>
AnimationManager *AnimationManager::self()
{
- if (!instance)
- instance = new AnimationManager;
- return instance;
+ // the universe's only animation manager
+ static AnimationManager s_instance;
+ return &s_instance;
}
void AnimationManager::registerAnimation(QAbstractAnimation *anim)
diff --git a/examples/widgets/animation/sub-attaq/animationmanager.h b/examples/widgets/animation/sub-attaq/animationmanager.h
index 9365fa1f1ef..5ddea66e80f 100644
--- a/examples/widgets/animation/sub-attaq/animationmanager.h
+++ b/examples/widgets/animation/sub-attaq/animationmanager.h
@@ -51,7 +51,7 @@
#ifndef ANIMATIONMANAGER_H
#define ANIMATIONMANAGER_H
-#include <QtCore/QObject>
+#include <QObject>
QT_BEGIN_NAMESPACE
class QAbstractAnimation;
@@ -59,9 +59,10 @@ QT_END_NAMESPACE
class AnimationManager : public QObject
{
-Q_OBJECT
+ Q_OBJECT
+ AnimationManager() = default;
+ ~AnimationManager() = default;
public:
- AnimationManager();
void registerAnimation(QAbstractAnimation *anim);
void unregisterAnimation(QAbstractAnimation *anim);
void unregisterAllAnimations();
@@ -75,8 +76,7 @@ private slots:
void unregisterAnimation_helper(QObject *obj);
private:
- static AnimationManager *instance;
- QList<QAbstractAnimation *> animations;
+ QVector<QAbstractAnimation *> animations;
};
#endif // ANIMATIONMANAGER_H
diff --git a/examples/widgets/animation/sub-attaq/boat.cpp b/examples/widgets/animation/sub-attaq/boat.cpp
index 9037d548785..d5fa314b600 100644
--- a/examples/widgets/animation/sub-attaq/boat.cpp
+++ b/examples/widgets/animation/sub-attaq/boat.cpp
@@ -52,18 +52,17 @@
#include "boat.h"
#include "boat_p.h"
#include "bomb.h"
-#include "pixmapitem.h"
#include "graphicsscene.h"
#include "animationmanager.h"
#include "qanimationstate.h"
//Qt
-#include <QtCore/QPropertyAnimation>
-#include <QtCore/QStateMachine>
-#include <QtCore/QHistoryState>
-#include <QtCore/QFinalState>
-#include <QtCore/QState>
-#include <QtCore/QSequentialAnimationGroup>
+#include <QFinalState>
+#include <QHistoryState>
+#include <QPropertyAnimation>
+#include <QSequentialAnimationGroup>
+#include <QState>
+#include <QStateMachine>
static QAbstractAnimation *setupDestroyAnimation(Boat *boat)
{
@@ -181,7 +180,7 @@ Boat::Boat()
launchStateLeft->addTransition(historyState);
launchStateRight->addTransition(historyState);
- QFinalState *final = new QFinalState(machine);
+ QFinalState *finalState = new QFinalState(machine);
//This state play the destroyed animation
QAnimationState *destroyedState = new QAnimationState(machine);
@@ -191,10 +190,10 @@ Boat::Boat()
moving->addTransition(this, &Boat::boatDestroyed, destroyedState);
//Transition to final state when the destroyed animation is finished
- destroyedState->addTransition(destroyedState, &QAnimationState::animationFinished, final);
+ destroyedState->addTransition(destroyedState, &QAnimationState::animationFinished, finalState);
//The machine has finished to be executed, then the boat is dead
- connect(machine,&QState::finished, this, &Boat::boatExecutionFinished);
+ connect(machine, &QState::finished, this, &Boat::boatExecutionFinished);
}
diff --git a/examples/widgets/animation/sub-attaq/boat.h b/examples/widgets/animation/sub-attaq/boat.h
index a75e2b14745..22f2f0f7c17 100644
--- a/examples/widgets/animation/sub-attaq/boat.h
+++ b/examples/widgets/animation/sub-attaq/boat.h
@@ -48,12 +48,11 @@
**
****************************************************************************/
-#ifndef __BOAT__H__
-#define __BOAT__H__
+#ifndef BOAT_H
+#define BOAT_H
#include "pixmapitem.h"
-class Bomb;
QT_BEGIN_NAMESPACE
class QVariantAnimation;
class QAbstractAnimation;
@@ -101,4 +100,4 @@ private:
QStateMachine *machine;
};
-#endif //__BOAT__H__
+#endif // BOAT_H
diff --git a/examples/widgets/animation/sub-attaq/boat_p.h b/examples/widgets/animation/sub-attaq/boat_p.h
index 8ebfeb27f55..bb1a783392e 100644
--- a/examples/widgets/animation/sub-attaq/boat_p.h
+++ b/examples/widgets/animation/sub-attaq/boat_p.h
@@ -67,7 +67,9 @@
#include "graphicsscene.h"
// Qt
-#include <QtWidgets/QKeyEventTransition>
+#include <QGraphicsRotation>
+#include <QKeyEventTransition>
+#include <QState>
static const int MAX_BOMB = 5;
@@ -88,7 +90,7 @@ protected:
return (boat->currentSpeed() == 1);
}
private:
- Boat * boat;
+ Boat *boat;
};
//These transtion test if we have to move the boat (i.e current speed was 0 or another value)
@@ -118,7 +120,7 @@ protected:
boat->updateBoatMovement();
}
private:
- Boat * boat;
+ Boat *boat;
int key;
};
@@ -139,7 +141,7 @@ protected:
return (boat->bombsLaunched() < MAX_BOMB);
}
private:
- Boat * boat;
+ Boat *boat;
};
//This state is describing when the boat is moving right
@@ -157,7 +159,7 @@ protected:
boat->updateBoatMovement();
}
private:
- Boat * boat;
+ Boat *boat;
};
//This state is describing when the boat is moving left
@@ -175,7 +177,7 @@ protected:
boat->updateBoatMovement();
}
private:
- Boat * boat;
+ Boat *boat;
};
//This state is describing when the boat is in a stand by position
@@ -194,7 +196,7 @@ protected:
boat->updateBoatMovement();
}
private:
- Boat * boat;
+ Boat *boat;
};
//This state is describing the launch of the torpedo on the right
@@ -216,7 +218,7 @@ protected:
boat->setBombsLaunched(boat->bombsLaunched() + 1);
}
private:
- Boat * boat;
+ Boat *boat;
};
//This state is describing the launch of the torpedo on the left
@@ -238,7 +240,7 @@ protected:
boat->setBombsLaunched(boat->bombsLaunched() + 1);
}
private:
- Boat * boat;
+ Boat *boat;
};
#endif // BOAT_P_H
diff --git a/examples/widgets/animation/sub-attaq/bomb.cpp b/examples/widgets/animation/sub-attaq/bomb.cpp
index 2b865137dd5..0b9c3656623 100644
--- a/examples/widgets/animation/sub-attaq/bomb.cpp
+++ b/examples/widgets/animation/sub-attaq/bomb.cpp
@@ -51,15 +51,14 @@
//Own
#include "bomb.h"
#include "submarine.h"
-#include "pixmapitem.h"
#include "animationmanager.h"
#include "qanimationstate.h"
//Qt
-#include <QtCore/QSequentialAnimationGroup>
-#include <QtCore/QPropertyAnimation>
-#include <QtCore/QStateMachine>
-#include <QtCore/QFinalState>
+#include <QFinalState>
+#include <QPropertyAnimation>
+#include <QSequentialAnimationGroup>
+#include <QStateMachine>
Bomb::Bomb() : PixmapItem(QString("bomb"), GraphicsScene::Big)
{
@@ -83,7 +82,7 @@ void Bomb::launch(Bomb::Direction direction)
anim->setEndValue(QPointF(x() + delta*2,scene()->height()));
anim->setDuration(y()/2*60);
launchAnimation->addAnimation(anim);
- connect(anim,&QVariantAnimation::valueChanged,this,&Bomb::onAnimationLaunchValueChanged);
+ connect(anim, &QVariantAnimation::valueChanged, this, &Bomb::onAnimationLaunchValueChanged);
connect(this, &Bomb::bombExploded, launchAnimation, &QAbstractAnimation::stop);
//We setup the state machine of the bomb
QStateMachine *machine = new QStateMachine(this);
@@ -93,18 +92,18 @@ void Bomb::launch(Bomb::Direction direction)
launched->setAnimation(launchAnimation);
//End
- QFinalState *final = new QFinalState(machine);
+ QFinalState *finalState = new QFinalState(machine);
machine->setInitialState(launched);
//### Add a nice animation when the bomb is destroyed
- launched->addTransition(this, &Bomb::bombExploded,final);
+ launched->addTransition(this, &Bomb::bombExploded, finalState);
//If the animation is finished, then we move to the final state
- launched->addTransition(launched, &QAnimationState::animationFinished, final);
+ launched->addTransition(launched, &QAnimationState::animationFinished, finalState);
//The machine has finished to be executed, then the boat is dead
- connect(machine,&QState::finished,this, &Bomb::bombExecutionFinished);
+ connect(machine,&QState::finished, this, &Bomb::bombExecutionFinished);
machine->start();
diff --git a/examples/widgets/animation/sub-attaq/bomb.h b/examples/widgets/animation/sub-attaq/bomb.h
index 8e893f81e34..9ae54b4d819 100644
--- a/examples/widgets/animation/sub-attaq/bomb.h
+++ b/examples/widgets/animation/sub-attaq/bomb.h
@@ -48,8 +48,8 @@
**
****************************************************************************/
-#ifndef __BOMB__H__
-#define __BOMB__H__
+#ifndef BOMB_H
+#define BOMB_H
#include "pixmapitem.h"
@@ -73,4 +73,4 @@ private slots:
void onAnimationLaunchValueChanged(const QVariant &);
};
-#endif //__BOMB__H__
+#endif // BOMB_H
diff --git a/examples/widgets/animation/sub-attaq/graphicsscene.cpp b/examples/widgets/animation/sub-attaq/graphicsscene.cpp
index 8f0dfc1357b..c7e2d269c88 100644
--- a/examples/widgets/animation/sub-attaq/graphicsscene.cpp
+++ b/examples/widgets/animation/sub-attaq/graphicsscene.cpp
@@ -55,38 +55,33 @@
#include "submarine.h"
#include "torpedo.h"
#include "bomb.h"
-#include "pixmapitem.h"
#include "animationmanager.h"
#include "qanimationstate.h"
#include "progressitem.h"
#include "textinformationitem.h"
//Qt
-#include <QtCore/QPropertyAnimation>
-#include <QtCore/QSequentialAnimationGroup>
-#include <QtCore/QParallelAnimationGroup>
-#include <QtCore/QStateMachine>
-#include <QtCore/QFinalState>
-#include <QtCore/QPauseAnimation>
-#include <QtWidgets/QAction>
-#include <QtCore/QDir>
-#include <QtWidgets/QApplication>
-#include <QtWidgets/QMessageBox>
-#include <QtWidgets/QGraphicsView>
-#include <QtWidgets/QGraphicsSceneMouseEvent>
-#include <QtCore/QXmlStreamReader>
-
-GraphicsScene::GraphicsScene(int x, int y, int width, int height, Mode mode)
- : QGraphicsScene(x , y, width, height), mode(mode), boat(new Boat)
+#include <QAction>
+#include <QApplication>
+#include <QFile>
+#include <QFinalState>
+#include <QParallelAnimationGroup>
+#include <QPropertyAnimation>
+#include <QSequentialAnimationGroup>
+#include <QStateMachine>
+#include <QXmlStreamReader>
+
+GraphicsScene::GraphicsScene(int x, int y, int width, int height, Mode mode, QObject *parent)
+ : QGraphicsScene(x, y, width, height, parent), mode(mode), boat(new Boat)
{
- PixmapItem *backgroundItem = new PixmapItem(QString("background"),mode);
+ PixmapItem *backgroundItem = new PixmapItem(QStringLiteral("background"), mode);
backgroundItem->setZValue(1);
backgroundItem->setPos(0,0);
addItem(backgroundItem);
- PixmapItem *surfaceItem = new PixmapItem(QString("surface"),mode);
+ PixmapItem *surfaceItem = new PixmapItem(QStringLiteral("surface"), mode);
surfaceItem->setZValue(3);
- surfaceItem->setPos(0,sealLevel() - surfaceItem->boundingRect().height()/2);
+ surfaceItem->setPos(0, sealLevel() - surfaceItem->boundingRect().height() / 2);
addItem(surfaceItem);
//The item that display score and level
@@ -137,8 +132,8 @@ qreal GraphicsScene::sealLevel() const
void GraphicsScene::setupScene(QAction *newAction, QAction *quitAction)
{
- static const int nLetters = 10;
- static struct {
+ static constexpr int nLetters = 10;
+ static constexpr struct {
char const *pix;
qreal initX, initY;
qreal destX, destY;
@@ -154,8 +149,8 @@ void GraphicsScene::setupScene(QAction *newAction, QAction *quitAction)
{"q", 200, 2000, 510, 250 },
{"excl", 0, 2000, 570, 220 } };
- QSequentialAnimationGroup * lettersGroupMoving = new QSequentialAnimationGroup(this);
- QParallelAnimationGroup * lettersGroupFading = new QParallelAnimationGroup(this);
+ QSequentialAnimationGroup *lettersGroupMoving = new QSequentialAnimationGroup(this);
+ QParallelAnimationGroup *lettersGroupFading = new QParallelAnimationGroup(this);
for (int i = 0; i < nLetters; ++i) {
PixmapItem *logo = new PixmapItem(QLatin1String(":/logo-") + logoData[i].pix, this);
@@ -180,7 +175,7 @@ void GraphicsScene::setupScene(QAction *newAction, QAction *quitAction)
PlayState *gameState = new PlayState(this, machine);
//Final state
- QFinalState *final = new QFinalState(machine);
+ QFinalState *finalState = new QFinalState(machine);
//Animation when the player enter in the game
QAnimationState *lettersMovingState = new QAnimationState(machine);
@@ -198,8 +193,8 @@ void GraphicsScene::setupScene(QAction *newAction, QAction *quitAction)
gameState->addTransition(newAction, &QAction::triggered, gameState);
//Wanna quit, then connect to CTRL+Q
- gameState->addTransition(quitAction, &QAction::triggered, final);
- lettersMovingState->addTransition(quitAction, &QAction::triggered, final);
+ gameState->addTransition(quitAction, &QAction::triggered, finalState);
+ lettersMovingState->addTransition(quitAction, &QAction::triggered, finalState);
//Welcome screen is the initial state
machine->setInitialState(lettersMovingState);
@@ -213,21 +208,24 @@ void GraphicsScene::setupScene(QAction *newAction, QAction *quitAction)
void GraphicsScene::addItem(Bomb *bomb)
{
bombs.insert(bomb);
- connect(bomb,&Bomb::bombExecutionFinished,this, &GraphicsScene::onBombExecutionFinished);
+ connect(bomb, &Bomb::bombExecutionFinished,
+ this, &GraphicsScene::onBombExecutionFinished);
QGraphicsScene::addItem(bomb);
}
void GraphicsScene::addItem(Torpedo *torpedo)
{
torpedos.insert(torpedo);
- connect(torpedo,&Torpedo::torpedoExecutionFinished,this, &GraphicsScene::onTorpedoExecutionFinished);
+ connect(torpedo, &Torpedo::torpedoExecutionFinished,
+ this, &GraphicsScene::onTorpedoExecutionFinished);
QGraphicsScene::addItem(torpedo);
}
void GraphicsScene::addItem(SubMarine *submarine)
{
submarines.insert(submarine);
- connect(submarine,&SubMarine::subMarineExecutionFinished,this, &GraphicsScene::onSubMarineExecutionFinished);
+ connect(submarine, &SubMarine::subMarineExecutionFinished,
+ this, &GraphicsScene::onSubMarineExecutionFinished);
QGraphicsScene::addItem(submarine);
}
@@ -239,15 +237,18 @@ void GraphicsScene::addItem(QGraphicsItem *item)
void GraphicsScene::onBombExecutionFinished()
{
Bomb *bomb = qobject_cast<Bomb *>(sender());
+ if (!bomb)
+ return;
bombs.remove(bomb);
bomb->deleteLater();
- if (boat)
- boat->setBombsLaunched(boat->bombsLaunched() - 1);
+ boat->setBombsLaunched(boat->bombsLaunched() - 1);
}
void GraphicsScene::onTorpedoExecutionFinished()
{
Torpedo *torpedo = qobject_cast<Torpedo *>(sender());
+ if (!torpedo)
+ return;
torpedos.remove(torpedo);
torpedo->deleteLater();
}
@@ -255,6 +256,8 @@ void GraphicsScene::onTorpedoExecutionFinished()
void GraphicsScene::onSubMarineExecutionFinished()
{
SubMarine *submarine = qobject_cast<SubMarine *>(sender());
+ if (!submarine)
+ return;
submarines.remove(submarine);
if (submarines.count() == 0)
emit allSubMarineDestroyed(submarine->points());
@@ -266,16 +269,22 @@ void GraphicsScene::onSubMarineExecutionFinished()
void GraphicsScene::clearScene()
{
for (SubMarine *sub : qAsConst(submarines)) {
+ // make sure to not go into onSubMarineExecutionFinished
+ sub->disconnect(this);
sub->destroy();
sub->deleteLater();
}
for (Torpedo *torpedo : qAsConst(torpedos)) {
+ // make sure to not go into onTorpedoExecutionFinished
+ torpedo->disconnect(this);
torpedo->destroy();
torpedo->deleteLater();
}
for (Bomb *bomb : qAsConst(bombs)) {
+ // make sure to not go into onBombExecutionFinished
+ bomb->disconnect(this);
bomb->destroy();
bomb->deleteLater();
}
diff --git a/examples/widgets/animation/sub-attaq/graphicsscene.h b/examples/widgets/animation/sub-attaq/graphicsscene.h
index 86c3414bbb3..dd3719bc100 100644
--- a/examples/widgets/animation/sub-attaq/graphicsscene.h
+++ b/examples/widgets/animation/sub-attaq/graphicsscene.h
@@ -48,13 +48,12 @@
**
****************************************************************************/
-#ifndef __GRAPHICSSCENE__H__
-#define __GRAPHICSSCENE__H__
+#ifndef GRAPHICSSCENE_H
+#define GRAPHICSSCENE_H
//Qt
-#include <QtWidgets/QGraphicsScene>
-#include <QtCore/QSet>
-#include <QtCore/QState>
+#include <QGraphicsScene>
+#include <QSet>
class Boat;
@@ -78,18 +77,18 @@ public:
};
struct SubmarineDescription {
- int type;
- int points;
+ int type = 0;
+ int points = 0;
QString name;
};
struct LevelDescription {
- int id;
+ int id = 0;
QString name;
- QList<QPair<int,int> > submarines;
+ QVector<QPair<int, int>> submarines;
};
- GraphicsScene(int x, int y, int width, int height, Mode mode = Big);
+ GraphicsScene(int x, int y, int width, int height, Mode mode, QObject *parent = nullptr);
qreal sealLevel() const;
void setupScene(QAction *newAction, QAction *quitAction);
void addItem(Bomb *bomb);
@@ -127,5 +126,5 @@ private:
friend class UpdateScoreTransition;
};
-#endif //__GRAPHICSSCENE__H__
+#endif // GRAPHICSSCENE_H
diff --git a/examples/widgets/animation/sub-attaq/mainwindow.cpp b/examples/widgets/animation/sub-attaq/mainwindow.cpp
index a4bb15b383e..8f545ecebdf 100644
--- a/examples/widgets/animation/sub-attaq/mainwindow.cpp
+++ b/examples/widgets/animation/sub-attaq/mainwindow.cpp
@@ -56,11 +56,10 @@
#include <QGraphicsView>
#include <QApplication>
#include <QMenu>
-#include <QMenuBar>
#include <QLayout>
#ifndef QT_NO_OPENGL
-# include <QtOpenGL/QtOpenGL>
+# include <QtOpenGL>
#endif
MainWindow::MainWindow(QWidget *parent)
@@ -74,10 +73,10 @@ MainWindow::MainWindow(QWidget *parent)
quitAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q));
if (QApplication::arguments().contains("-fullscreen")) {
- scene = new GraphicsScene(0, 0, 750, 400, GraphicsScene::Small);
+ scene = new GraphicsScene(0, 0, 750, 400, GraphicsScene::Small, this);
setWindowState(Qt::WindowFullScreen);
} else {
- scene = new GraphicsScene(0, 0, 880, 630);
+ scene = new GraphicsScene(0, 0, 880, 630, GraphicsScene::Big, this);
layout()->setSizeConstraint(QLayout::SetFixedSize);
}
diff --git a/examples/widgets/animation/sub-attaq/mainwindow.h b/examples/widgets/animation/sub-attaq/mainwindow.h
index c4fb9d324d3..660acfaa0ad 100644
--- a/examples/widgets/animation/sub-attaq/mainwindow.h
+++ b/examples/widgets/animation/sub-attaq/mainwindow.h
@@ -48,11 +48,11 @@
**
****************************************************************************/
-#ifndef __MAINWINDOW__H__
-#define __MAINWINDOW__H__
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
//Qt
-#include <QtWidgets/QMainWindow>
+#include <QMainWindow>
class GraphicsScene;
QT_BEGIN_NAMESPACE
class QGraphicsView;
@@ -69,4 +69,4 @@ private:
QGraphicsView *view;
};
-#endif //__MAINWINDOW__H__
+#endif // MAINWINDOW_H
diff --git a/examples/widgets/animation/sub-attaq/pixmapitem.cpp b/examples/widgets/animation/sub-attaq/pixmapitem.cpp
index 9475d5c3f83..a8581d881a9 100644
--- a/examples/widgets/animation/sub-attaq/pixmapitem.cpp
+++ b/examples/widgets/animation/sub-attaq/pixmapitem.cpp
@@ -54,7 +54,7 @@
//Qt
#include <QPainter>
-PixmapItem::PixmapItem(const QString &fileName,GraphicsScene::Mode mode, QGraphicsItem * parent)
+PixmapItem::PixmapItem(const QString &fileName, GraphicsScene::Mode mode, QGraphicsItem *parent)
: QGraphicsObject(parent)
{
if (mode == GraphicsScene::Big)
@@ -63,7 +63,8 @@ PixmapItem::PixmapItem(const QString &fileName,GraphicsScene::Mode mode, QGraphi
pix = QPixmap(QStringLiteral(":/small/") + fileName);
}
-PixmapItem::PixmapItem(const QString &fileName, QGraphicsScene *scene) : QGraphicsObject(), pix(fileName)
+PixmapItem::PixmapItem(const QString &fileName, QGraphicsScene *scene)
+ : QGraphicsObject(), pix(fileName)
{
scene->addItem(this);
}
diff --git a/examples/widgets/animation/sub-attaq/pixmapitem.h b/examples/widgets/animation/sub-attaq/pixmapitem.h
index ec5c01857fc..45e2ca806f1 100644
--- a/examples/widgets/animation/sub-attaq/pixmapitem.h
+++ b/examples/widgets/animation/sub-attaq/pixmapitem.h
@@ -48,14 +48,14 @@
**
****************************************************************************/
-#ifndef __PIXMAPITEM__H__
-#define __PIXMAPITEM__H__
+#ifndef PIXMAPITEM_H
+#define PIXMAPITEM_H
//Own
#include "graphicsscene.h"
//Qt
-#include <QtWidgets/QGraphicsObject>
+#include <QGraphicsObject>
class PixmapItem : public QGraphicsObject
{
@@ -69,4 +69,4 @@ private:
QPixmap pix;
};
-#endif //__PIXMAPITEM__H__
+#endif // PIXMAPITEM_H
diff --git a/examples/widgets/animation/sub-attaq/progressitem.cpp b/examples/widgets/animation/sub-attaq/progressitem.cpp
index 8b6b367710c..350dbb7bbd9 100644
--- a/examples/widgets/animation/sub-attaq/progressitem.cpp
+++ b/examples/widgets/animation/sub-attaq/progressitem.cpp
@@ -49,10 +49,11 @@
****************************************************************************/
#include "progressitem.h"
-#include "pixmapitem.h"
-ProgressItem::ProgressItem (QGraphicsItem * parent)
- : QGraphicsTextItem(parent), currentLevel(1), currentScore(0)
+#include <QFont>
+
+ProgressItem::ProgressItem(QGraphicsItem *parent)
+ : QGraphicsTextItem(parent)
{
setFont(QFont("Comic Sans MS"));
setPos(parentItem()->boundingRect().topRight() - QPointF(180, -5));
diff --git a/examples/widgets/animation/sub-attaq/progressitem.h b/examples/widgets/animation/sub-attaq/progressitem.h
index 23f54079780..f76b1681513 100644
--- a/examples/widgets/animation/sub-attaq/progressitem.h
+++ b/examples/widgets/animation/sub-attaq/progressitem.h
@@ -52,19 +52,19 @@
#define PROGRESSITEM_H
//Qt
-#include <QtWidgets/QGraphicsTextItem>
+#include <QGraphicsTextItem>
class ProgressItem : public QGraphicsTextItem
{
public:
- ProgressItem(QGraphicsItem * parent = 0);
+ ProgressItem(QGraphicsItem *parent = nullptr);
void setLevel(int level);
void setScore(int score);
private:
void updateProgress();
- int currentLevel;
- int currentScore;
+ int currentLevel = 1;
+ int currentScore = 0;
};
#endif // PROGRESSITEM_H
diff --git a/examples/widgets/animation/sub-attaq/qanimationstate.cpp b/examples/widgets/animation/sub-attaq/qanimationstate.cpp
index ce99f9080db..6da085561b2 100644
--- a/examples/widgets/animation/sub-attaq/qanimationstate.cpp
+++ b/examples/widgets/animation/sub-attaq/qanimationstate.cpp
@@ -50,7 +50,7 @@
#include "qanimationstate.h"
-#include <QtCore/qstate.h>
+#include <QAbstractAnimation>
QT_BEGIN_NAMESPACE
@@ -106,7 +106,7 @@ void QAnimationState::setAnimation(QAbstractAnimation *animation)
return;
//Disconnect from the previous animation if exist
- if(m_animation)
+ if (m_animation)
disconnect(m_animation, &QAbstractAnimation::finished, this, &QAnimationState::animationFinished);
m_animation = animation;
diff --git a/examples/widgets/animation/sub-attaq/qanimationstate.h b/examples/widgets/animation/sub-attaq/qanimationstate.h
index 063b119058a..24759851baf 100644
--- a/examples/widgets/animation/sub-attaq/qanimationstate.h
+++ b/examples/widgets/animation/sub-attaq/qanimationstate.h
@@ -51,13 +51,7 @@
#ifndef QANIMATIONSTATE_H
#define QANIMATIONSTATE_H
-#ifndef QT_STATEMACHINE_SOLUTION
-# include <QtCore/qstate.h>
-# include <QtCore/qabstractanimation.h>
-#else
-# include "qstate.h"
-# include "qabstractanimation.h"
-#endif
+#include <QState>
QT_BEGIN_NAMESPACE
@@ -67,7 +61,7 @@ class QAnimationState : public QState
{
Q_OBJECT
public:
- QAnimationState(QState *parent = 0);
+ QAnimationState(QState *parent = nullptr);
~QAnimationState();
void setAnimation(QAbstractAnimation *animation);
diff --git a/examples/widgets/animation/sub-attaq/states.cpp b/examples/widgets/animation/sub-attaq/states.cpp
index cda10ccdaf6..c7e2738aad2 100644
--- a/examples/widgets/animation/sub-attaq/states.cpp
+++ b/examples/widgets/animation/sub-attaq/states.cpp
@@ -59,12 +59,12 @@
#include "textinformationitem.h"
//Qt
-#include <QtWidgets/QMessageBox>
-#include <QtWidgets/QGraphicsView>
-#include <QtCore/QStateMachine>
-#include <QtWidgets/QKeyEventTransition>
-#include <QtCore/QFinalState>
-#include <QtCore/QRandomGenerator>
+#include <QFinalState>
+#include <QGraphicsView>
+#include <QKeyEventTransition>
+#include <QMessageBox>
+#include <QRandomGenerator>
+#include <QStateMachine>
PlayState::PlayState(GraphicsScene *scene, QState *parent)
: QState(parent), scene(scene), machine(nullptr),
@@ -146,7 +146,7 @@ void PlayState::onEntry(QEvent *)
machine->setInitialState(levelState);
//Final state
- QFinalState *final = new QFinalState(machine);
+ QFinalState *finalState = new QFinalState(machine);
//This transition is triggered when the player press space after completing a level
CustomSpaceTransition *spaceTransition = new CustomSpaceTransition(scene->views().at(0), this, QEvent::KeyPress, Qt::Key_Space);
@@ -154,7 +154,7 @@ void PlayState::onEntry(QEvent *)
winState->addTransition(spaceTransition);
//We lost we should reach the final state
- lostState->addTransition(lostState, &QState::finished, final);
+ lostState->addTransition(lostState, &QState::finished, finalState);
machine->start();
}
@@ -181,11 +181,9 @@ void LevelState::initializeLevel()
scene->progressItem->setScore(game->score);
scene->progressItem->setLevel(game->currentLevel + 1);
- GraphicsScene::LevelDescription currentLevelDescription = scene->levelsData.value(game->currentLevel);
+ const GraphicsScene::LevelDescription currentLevelDescription = scene->levelsData.value(game->currentLevel);
+ for (const QPair<int,int> &subContent : currentLevelDescription.submarines) {
- for (int i = 0; i < currentLevelDescription.submarines.size(); ++i ) {
-
- QPair<int,int> subContent = currentLevelDescription.submarines.at(i);
GraphicsScene::SubmarineDescription submarineDesc = scene->submarinesData.at(subContent.first);
for (int j = 0; j < subContent.second; ++j ) {
@@ -202,9 +200,10 @@ void LevelState::initializeLevel()
}
/** Pause State */
-PauseState::PauseState(GraphicsScene *scene, QState *parent) : QState(parent),scene(scene)
+PauseState::PauseState(GraphicsScene *scene, QState *parent) : QState(parent), scene(scene)
{
}
+
void PauseState::onEntry(QEvent *)
{
AnimationManager::self()->pauseAll();
@@ -324,8 +323,7 @@ bool WinTransition::eventTest(QEvent *event)
/** Space transition */
CustomSpaceTransition::CustomSpaceTransition(QWidget *widget, PlayState *game, QEvent::Type type, int key)
- : QKeyEventTransition(widget, type, key),
- game(game)
+ : QKeyEventTransition(widget, type, key), game(game)
{
}
diff --git a/examples/widgets/animation/sub-attaq/states.h b/examples/widgets/animation/sub-attaq/states.h
index cd68e319c23..b3651e1c821 100644
--- a/examples/widgets/animation/sub-attaq/states.h
+++ b/examples/widgets/animation/sub-attaq/states.h
@@ -52,15 +52,11 @@
#define STATES_H
//Qt
-#include <QtCore/QState>
-#include <QtCore/QSignalTransition>
-#include <QtCore/QPropertyAnimation>
-#include <QtWidgets/QKeyEventTransition>
-#include <QtCore/QSet>
+#include <QKeyEventTransition>
+#include <QSignalTransition>
+#include <QState>
class GraphicsScene;
-class Boat;
-class SubMarine;
QT_BEGIN_NAMESPACE
class QStateMachine;
QT_END_NAMESPACE
@@ -68,7 +64,7 @@ QT_END_NAMESPACE
class PlayState : public QState
{
public:
- explicit PlayState(GraphicsScene *scene, QState *parent = 0);
+ explicit PlayState(GraphicsScene *scene, QState *parent = nullptr);
~PlayState();
protected:
@@ -92,7 +88,7 @@ private :
class LevelState : public QState
{
public:
- LevelState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
+ LevelState(GraphicsScene *scene, PlayState *game, QState *parent = nullptr);
protected:
void onEntry(QEvent *) override;
private :
@@ -104,7 +100,7 @@ private :
class PauseState : public QState
{
public:
- explicit PauseState(GraphicsScene *scene, QState *parent = 0);
+ explicit PauseState(GraphicsScene *scene, QState *parent = nullptr);
protected:
void onEntry(QEvent *) override;
@@ -116,7 +112,7 @@ private :
class LostState : public QState
{
public:
- LostState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
+ LostState(GraphicsScene *scene, PlayState *game, QState *parent = nullptr);
protected:
void onEntry(QEvent *) override;
@@ -129,7 +125,7 @@ private :
class WinState : public QState
{
public:
- WinState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
+ WinState(GraphicsScene *scene, PlayState *game, QState *parent = nullptr);
protected:
void onEntry(QEvent *) override;
@@ -154,7 +150,7 @@ public:
protected:
bool eventTest(QEvent *event) override;
private:
- PlayState * game;
+ PlayState *game;
GraphicsScene *scene;
};
@@ -166,7 +162,7 @@ public:
protected:
bool eventTest(QEvent *event) override;
private:
- PlayState * game;
+ PlayState *game;
GraphicsScene *scene;
};
diff --git a/examples/widgets/animation/sub-attaq/submarine.cpp b/examples/widgets/animation/sub-attaq/submarine.cpp
index 775e75ceed4..a4ca3760454 100644
--- a/examples/widgets/animation/sub-attaq/submarine.cpp
+++ b/examples/widgets/animation/sub-attaq/submarine.cpp
@@ -52,15 +52,14 @@
#include "submarine.h"
#include "submarine_p.h"
#include "torpedo.h"
-#include "pixmapitem.h"
#include "graphicsscene.h"
#include "animationmanager.h"
#include "qanimationstate.h"
-#include <QtCore/QPropertyAnimation>
-#include <QtCore/QStateMachine>
-#include <QtCore/QFinalState>
-#include <QtCore/QSequentialAnimationGroup>
+#include <QFinalState>
+#include <QPropertyAnimation>
+#include <QStateMachine>
+#include <QSequentialAnimationGroup>
static QAbstractAnimation *setupDestroyAnimation(SubMarine *sub)
{
@@ -86,9 +85,8 @@ SubMarine::SubMarine(int type, const QString &name, int points) : PixmapItem(QSt
graphicsRotation = new QGraphicsRotation(this);
graphicsRotation->setAxis(Qt::YAxis);
- graphicsRotation->setOrigin(QVector3D(size().width()/2, size().height()/2, 0));
- QList<QGraphicsTransform *> r;
- r.append(graphicsRotation);
+ graphicsRotation->setOrigin(QVector3D(size().width() / 2, size().height() / 2, 0));
+ QList<QGraphicsTransform *> r({graphicsRotation});
setTransformations(r);
//We setup the state machine of the submarine
@@ -112,7 +110,7 @@ SubMarine::SubMarine(int type, const QString &name, int points) : PixmapItem(QSt
machine->setInitialState(moving);
//End
- QFinalState *final = new QFinalState(machine);
+ QFinalState *finalState = new QFinalState(machine);
//If the moving animation is finished we move to the return state
movement->addTransition(movement, &QAnimationState::animationFinished, rotation);
@@ -128,7 +126,7 @@ SubMarine::SubMarine(int type, const QString &name, int points) : PixmapItem(QSt
moving->addTransition(this, &SubMarine::subMarineDestroyed, destroyedState);
//Transition to final state when the destroyed animation is finished
- destroyedState->addTransition(destroyedState, &QAnimationState::animationFinished, final);
+ destroyedState->addTransition(destroyedState, &QAnimationState::animationFinished, finalState);
//The machine has finished to be executed, then the submarine is dead
connect(machine,&QState::finished,this, &SubMarine::subMarineExecutionFinished);
@@ -145,9 +143,8 @@ void SubMarine::setCurrentDirection(SubMarine::Movement direction)
{
if (this->direction == direction)
return;
- if (direction == SubMarine::Right && this->direction == SubMarine::None) {
+ if (direction == SubMarine::Right && this->direction == SubMarine::None)
graphicsRotation->setAngle(180);
- }
this->direction = direction;
}
@@ -158,9 +155,8 @@ enum SubMarine::Movement SubMarine::currentDirection() const
void SubMarine::setCurrentSpeed(int speed)
{
- if (speed < 0 || speed > 3) {
+ if (speed < 0 || speed > 3)
qWarning("SubMarine::setCurrentSpeed : The speed is invalid");
- }
this->speed = speed;
emit subMarineStateChanged();
}
@@ -172,7 +168,7 @@ int SubMarine::currentSpeed() const
void SubMarine::launchTorpedo(int speed)
{
- Torpedo * torp = new Torpedo();
+ Torpedo *torp = new Torpedo;
GraphicsScene *scene = static_cast<GraphicsScene *>(this->scene());
scene->addItem(torp);
torp->setPos(pos());
diff --git a/examples/widgets/animation/sub-attaq/submarine.h b/examples/widgets/animation/sub-attaq/submarine.h
index d145c9cbee7..256683ec706 100644
--- a/examples/widgets/animation/sub-attaq/submarine.h
+++ b/examples/widgets/animation/sub-attaq/submarine.h
@@ -48,15 +48,12 @@
**
****************************************************************************/
-#ifndef __SUBMARINE__H__
-#define __SUBMARINE__H__
-
-//Qt
-#include <QtWidgets/QGraphicsTransform>
+#ifndef SUBMARINE_H
+#define SUBMARINE_H
#include "pixmapitem.h"
-class Torpedo;
+#include <QGraphicsRotation>
class SubMarine : public PixmapItem
{
@@ -99,4 +96,4 @@ private:
QGraphicsRotation *graphicsRotation;
};
-#endif //__SUBMARINE__H__
+#endif // SUBMARINE_H
diff --git a/examples/widgets/animation/sub-attaq/submarine_p.h b/examples/widgets/animation/sub-attaq/submarine_p.h
index 1c2cb7ceac4..36807dade31 100644
--- a/examples/widgets/animation/sub-attaq/submarine_p.h
+++ b/examples/widgets/animation/sub-attaq/submarine_p.h
@@ -68,16 +68,15 @@
#include "qanimationstate.h"
//Qt
-#include <QtCore/QPropertyAnimation>
-#include <QtCore/QRandomGenerator>
-#include <QtWidgets/QGraphicsScene>
+#include <QPropertyAnimation>
+#include <QRandomGenerator>
//This state is describing when the boat is moving right
class MovementState : public QAnimationState
{
Q_OBJECT
public:
- explicit MovementState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent)
+ explicit MovementState(SubMarine *submarine, QState *parent = nullptr) : QAnimationState(parent)
{
movementAnimation = new QPropertyAnimation(submarine, "pos");
connect(movementAnimation, &QPropertyAnimation::valueChanged,
@@ -117,7 +116,7 @@ private:
class ReturnState : public QAnimationState
{
public:
- explicit ReturnState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent)
+ explicit ReturnState(SubMarine *submarine, QState *parent = nullptr) : QAnimationState(parent)
{
returnAnimation = new QPropertyAnimation(submarine->rotation(), "angle");
returnAnimation->setDuration(500);
diff --git a/examples/widgets/animation/sub-attaq/textinformationitem.cpp b/examples/widgets/animation/sub-attaq/textinformationitem.cpp
index 16f787125d1..4d4934f63d0 100644
--- a/examples/widgets/animation/sub-attaq/textinformationitem.cpp
+++ b/examples/widgets/animation/sub-attaq/textinformationitem.cpp
@@ -50,14 +50,15 @@
#include "textinformationitem.h"
#include "pixmapitem.h"
-TextInformationItem::TextInformationItem (QGraphicsItem * parent)
+TextInformationItem::TextInformationItem (QGraphicsItem *parent)
: QGraphicsTextItem(parent)
{
setFont(QFont("Comic Sans MS", 15));
}
-#include <QDebug>
-void TextInformationItem::setMessage(const QString& text)
+
+void TextInformationItem::setMessage(const QString &text)
{
setHtml(text);
- setPos(parentItem()->boundingRect().center().x() - boundingRect().size().width()/2 , parentItem()->boundingRect().center().y());
+ setPos(parentItem()->boundingRect().center().x() - boundingRect().size().width() / 2,
+ parentItem()->boundingRect().center().y());
}
diff --git a/examples/widgets/animation/sub-attaq/textinformationitem.h b/examples/widgets/animation/sub-attaq/textinformationitem.h
index aa6f913e486..0a0b618460c 100644
--- a/examples/widgets/animation/sub-attaq/textinformationitem.h
+++ b/examples/widgets/animation/sub-attaq/textinformationitem.h
@@ -52,13 +52,13 @@
#define TEXTINFORMATIONITEM_H
//Qt
-#include <QtWidgets/QGraphicsTextItem>
+#include <QGraphicsTextItem>
class TextInformationItem : public QGraphicsTextItem
{
public:
- TextInformationItem(QGraphicsItem * parent = 0);
- void setMessage(const QString& text);
+ TextInformationItem(QGraphicsItem *parent = nullptr);
+ void setMessage(const QString &text);
};
#endif // TEXTINFORMATIONITEM_H
diff --git a/examples/widgets/animation/sub-attaq/torpedo.cpp b/examples/widgets/animation/sub-attaq/torpedo.cpp
index 92a38334520..7395aa39ac1 100644
--- a/examples/widgets/animation/sub-attaq/torpedo.cpp
+++ b/examples/widgets/animation/sub-attaq/torpedo.cpp
@@ -50,15 +50,14 @@
//Own
#include "torpedo.h"
-#include "pixmapitem.h"
#include "boat.h"
#include "graphicsscene.h"
#include "animationmanager.h"
#include "qanimationstate.h"
-#include <QtCore/QPropertyAnimation>
-#include <QtCore/QStateMachine>
-#include <QtCore/QFinalState>
+#include <QPropertyAnimation>
+#include <QStateMachine>
+#include <QFinalState>
Torpedo::Torpedo() : PixmapItem(QString::fromLatin1("torpedo"),GraphicsScene::Big),
currentSpeed(0)
@@ -70,11 +69,11 @@ void Torpedo::launch()
{
QPropertyAnimation *launchAnimation = new QPropertyAnimation(this, "pos");
AnimationManager::self()->registerAnimation(launchAnimation);
- launchAnimation->setEndValue(QPointF(x(),qobject_cast<GraphicsScene *>(scene())->sealLevel() - 15));
+ launchAnimation->setEndValue(QPointF(x(), qobject_cast<GraphicsScene *>(scene())->sealLevel() - 15));
launchAnimation->setEasingCurve(QEasingCurve::InQuad);
- launchAnimation->setDuration(y()/currentSpeed*10);
- connect(launchAnimation,&QVariantAnimation::valueChanged,this,&Torpedo::onAnimationLaunchValueChanged);
- connect(this,&Torpedo::torpedoExploded, launchAnimation, &QAbstractAnimation::stop);
+ launchAnimation->setDuration(y() / currentSpeed * 10);
+ connect(launchAnimation, &QVariantAnimation::valueChanged, this, &Torpedo::onAnimationLaunchValueChanged);
+ connect(this, &Torpedo::torpedoExploded, launchAnimation, &QAbstractAnimation::stop);
//We setup the state machine of the torpedo
QStateMachine *machine = new QStateMachine(this);
@@ -84,18 +83,18 @@ void Torpedo::launch()
launched->setAnimation(launchAnimation);
//End
- QFinalState *final = new QFinalState(machine);
+ QFinalState *finalState = new QFinalState(machine);
machine->setInitialState(launched);
//### Add a nice animation when the torpedo is destroyed
- launched->addTransition(this, &Torpedo::torpedoExploded,final);
+ launched->addTransition(this, &Torpedo::torpedoExploded, finalState);
//If the animation is finished, then we move to the final state
- launched->addTransition(launched, &QAnimationState::animationFinished, final);
+ launched->addTransition(launched, &QAnimationState::animationFinished, finalState);
//The machine has finished to be executed, then the boat is dead
- connect(machine,&QState::finished,this, &Torpedo::torpedoExecutionFinished);
+ connect(machine, &QState::finished, this, &Torpedo::torpedoExecutionFinished);
machine->start();
}
diff --git a/examples/widgets/animation/sub-attaq/torpedo.h b/examples/widgets/animation/sub-attaq/torpedo.h
index bd04bd79aa2..7ac853d4e95 100644
--- a/examples/widgets/animation/sub-attaq/torpedo.h
+++ b/examples/widgets/animation/sub-attaq/torpedo.h
@@ -48,8 +48,8 @@
**
****************************************************************************/
-#ifndef __TORPEDO__H__
-#define __TORPEDO__H__
+#ifndef TORPEDO_H
+#define TORPEDO_H
#include "pixmapitem.h"
@@ -73,4 +73,4 @@ private:
int currentSpeed;
};
-#endif //__TORPEDO__H__
+#endif // TORPEDO_H
diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp
index d51124aed7a..a9995efa270 100644
--- a/examples/widgets/graphicsview/boxes/scene.cpp
+++ b/examples/widgets/graphicsview/boxes/scene.cpp
@@ -128,10 +128,6 @@ void ColorEdit::mousePressEvent(QMouseEvent *event)
QColor color(m_color);
QColorDialog dialog(color, 0);
dialog.setOption(QColorDialog::ShowAlphaChannel, true);
-// The ifdef block is a workaround for the beta, TODO: remove when bug 238525 is fixed
-#if 0 // Used to be included in Qt4 for Q_WS_MAC
- dialog.setOption(QColorDialog::DontUseNativeDialog, true);
-#endif
dialog.move(280, 120);
if (dialog.exec() == QDialog::Rejected)
return;
diff --git a/examples/widgets/graphicsview/chip/view.cpp b/examples/widgets/graphicsview/chip/view.cpp
index 9676c13ff7b..7d5fd699a41 100644
--- a/examples/widgets/graphicsview/chip/view.cpp
+++ b/examples/widgets/graphicsview/chip/view.cpp
@@ -68,7 +68,7 @@
void GraphicsView::wheelEvent(QWheelEvent *e)
{
if (e->modifiers() & Qt::ControlModifier) {
- if (e->delta() > 0)
+ if (e->angleDelta().y() > 0)
view->zoomIn(6);
else
view->zoomOut(6);
diff --git a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
index 6b817b2a216..9341d77f8db 100644
--- a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
+++ b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
@@ -190,7 +190,7 @@ void GraphWidget::timerEvent(QTimerEvent *event)
//! [5]
void GraphWidget::wheelEvent(QWheelEvent *event)
{
- scaleView(pow((double)2, -event->delta() / 240.0));
+ scaleView(pow((double)2, -event->angleDelta().y() / 240.0));
}
//! [5]
#endif
diff --git a/examples/widgets/itemviews/dirview/main.cpp b/examples/widgets/itemviews/dirview/main.cpp
index eefea657f69..9fecffda400 100644
--- a/examples/widgets/itemviews/dirview/main.cpp
+++ b/examples/widgets/itemviews/dirview/main.cpp
@@ -65,8 +65,10 @@ int main(int argc, char *argv[])
parser.setApplicationDescription("Qt Dir View Example");
parser.addHelpOption();
parser.addVersionOption();
- QCommandLineOption dontUseCustomDirectoryIconsOption("c", "Set QFileIconProvider::DontUseCustomDirectoryIcons");
+ QCommandLineOption dontUseCustomDirectoryIconsOption("c", "Set QFileSystemModel::DontUseCustomDirectoryIcons");
parser.addOption(dontUseCustomDirectoryIconsOption);
+ QCommandLineOption dontWatchOption("w", "Set QFileSystemModel::DontWatch");
+ parser.addOption(dontWatchOption);
parser.addPositionalArgument("directory", "The directory to start in.");
parser.process(app);
const QString rootPath = parser.positionalArguments().isEmpty()
@@ -75,7 +77,9 @@ int main(int argc, char *argv[])
QFileSystemModel model;
model.setRootPath("");
if (parser.isSet(dontUseCustomDirectoryIconsOption))
- model.iconProvider()->setOptions(QFileIconProvider::DontUseCustomDirectoryIcons);
+ model.setOption(QFileSystemModel::DontUseCustomDirectoryIcons);
+ if (parser.isSet(dontWatchOption))
+ model.setOption(QFileSystemModel::DontWatchForChanges);
QTreeView tree;
tree.setModel(&model);
if (!rootPath.isEmpty()) {
diff --git a/examples/widgets/painting/affine/xform.cpp b/examples/widgets/painting/affine/xform.cpp
index 482e0f3268f..50acf0f814c 100644
--- a/examples/widgets/painting/affine/xform.cpp
+++ b/examples/widgets/painting/affine/xform.cpp
@@ -260,7 +260,7 @@ void XFormView::timerEvent(QTimerEvent *e)
#if QT_CONFIG(wheelevent)
void XFormView::wheelEvent(QWheelEvent *e)
{
- m_scale += e->delta() / qreal(600);
+ m_scale += e->angleDelta().y() / qreal(600);
m_scale = qMax(qreal(0.1), qMin(qreal(4), m_scale));
emit scaleChanged(int(m_scale*1000));
}
diff --git a/examples/widgets/tools/codecs/encodingdialog.cpp b/examples/widgets/tools/codecs/encodingdialog.cpp
index ca4b56db9e9..aa57d47dc74 100644
--- a/examples/widgets/tools/codecs/encodingdialog.cpp
+++ b/examples/widgets/tools/codecs/encodingdialog.cpp
@@ -248,7 +248,7 @@ static const char *encodingToolTips[]
{
QT_TRANSLATE_NOOP("EncodingDialog", "Unicode points for use with any encoding (C++, Python)"),
QT_TRANSLATE_NOOP("EncodingDialog", "QString::fromUtf8()"),
- QT_TRANSLATE_NOOP("EncodingDialog", "QStringViewLiteral(), wchar_t on Windows"),
+ QT_TRANSLATE_NOOP("EncodingDialog", "wchar_t on Windows, char16_t everywhere"),
QT_TRANSLATE_NOOP("EncodingDialog", "wchar_t on Unix (Ucs4)"),
QT_TRANSLATE_NOOP("EncodingDialog", "QLatin1String")
};
diff --git a/examples/widgets/tools/i18n/languagechooser.cpp b/examples/widgets/tools/i18n/languagechooser.cpp
index 963165ff814..e61e4432e4d 100644
--- a/examples/widgets/tools/i18n/languagechooser.cpp
+++ b/examples/widgets/tools/i18n/languagechooser.cpp
@@ -53,12 +53,6 @@
#include "languagechooser.h"
#include "mainwindow.h"
-#if 0 // Used to be included in Qt4 for Q_WS_MAC
-QT_BEGIN_NAMESPACE
-extern void qt_mac_set_menubar_merge(bool merge);
-QT_END_NAMESPACE
-#endif
-
LanguageChooser::LanguageChooser(const QString& defaultLang, QWidget *parent)
: QDialog(parent, Qt::WindowStaysOnTopHint)
{
@@ -95,10 +89,6 @@ LanguageChooser::LanguageChooser(const QString& defaultLang, QWidget *parent)
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
-#if 0 // Used to be included in Qt4 for Q_WS_MAC
- qt_mac_set_menubar_merge(false);
-#endif
-
setWindowTitle("I18N");
}
diff --git a/examples/widgets/widgets/mousebuttons/buttontester.cpp b/examples/widgets/widgets/mousebuttons/buttontester.cpp
index 66532216982..88dbbeda455 100644
--- a/examples/widgets/widgets/mousebuttons/buttontester.cpp
+++ b/examples/widgets/widgets/mousebuttons/buttontester.cpp
@@ -93,15 +93,16 @@ void ButtonTester::mouseDoubleClickEvent(QMouseEvent *e)
void ButtonTester::wheelEvent (QWheelEvent *e)
{
QString result;
- if (e->delta() > 0) {
-
- if (e->orientation() == Qt::Vertical) {
+ const bool vertical = qAbs(e->angleDelta().y()) >= qAbs(e->angleDelta().x());
+ const int delta = vertical ? e->angleDelta().y() : e->angleDelta().x();
+ if (delta > 0) {
+ if (vertical) {
result = "Mouse Wheel Event: UP";
} else {
result = "Mouse Wheel Event: LEFT";
}
- } else if (e->delta() < 0) {
- if (e->orientation() == Qt::Vertical) {
+ } else if (delta < 0) {
+ if (vertical) {
result = "Mouse Wheel Event: DOWN";
} else {
result = "Mouse Wheel Event: RIGHT";