summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/animation/animatedtiles/main.cpp19
-rw-r--r--examples/widgets/animation/animation.pro1
-rw-r--r--examples/widgets/animation/appchooser/accessories-dictionary.pngbin5396 -> 0 bytes
-rw-r--r--examples/widgets/animation/appchooser/akregator.pngbin4873 -> 0 bytes
-rw-r--r--examples/widgets/animation/appchooser/appchooser.pro8
-rw-r--r--examples/widgets/animation/appchooser/appchooser.qrc8
-rw-r--r--examples/widgets/animation/appchooser/digikam.pngbin3334 -> 0 bytes
-rw-r--r--examples/widgets/animation/appchooser/k3b.pngbin8220 -> 0 bytes
-rw-r--r--examples/widgets/animation/appchooser/main.cpp183
-rw-r--r--examples/widgets/animation/easing/easing.pro1
-rw-r--r--examples/widgets/animation/easing/images/qt-logo.pngbin1495 -> 1165 bytes
-rw-r--r--examples/widgets/animation/moveblocks/main.cpp4
-rw-r--r--examples/widgets/animation/stickman/lifecycle.cpp3
-rw-r--r--examples/widgets/animation/stickman/stickman.cpp10
-rw-r--r--examples/widgets/animation/sub-attaq/main.cpp2
-rw-r--r--examples/widgets/animation/sub-attaq/states.cpp7
-rw-r--r--examples/widgets/animation/sub-attaq/submarine_p.h5
-rw-r--r--examples/widgets/desktop/screenshot/screenshot.pro1
-rw-r--r--examples/widgets/desktop/systray/systray.pro1
-rw-r--r--examples/widgets/dialogs/configdialog/configdialog.cpp124
-rw-r--r--examples/widgets/dialogs/configdialog/configdialog.pro12
-rw-r--r--examples/widgets/dialogs/configdialog/configdialog.qrc7
-rw-r--r--examples/widgets/dialogs/configdialog/images/config.pngbin6758 -> 0 bytes
-rw-r--r--examples/widgets/dialogs/configdialog/images/query.pngbin2116 -> 0 bytes
-rw-r--r--examples/widgets/dialogs/configdialog/images/update.pngbin7890 -> 0 bytes
-rw-r--r--examples/widgets/dialogs/configdialog/pages.cpp161
-rw-r--r--examples/widgets/dialogs/configdialog/pages.h74
-rw-r--r--examples/widgets/dialogs/dialogs.pro2
-rw-r--r--examples/widgets/dialogs/findfiles/findfiles.pro1
-rw-r--r--examples/widgets/dialogs/findfiles/window.cpp57
-rw-r--r--examples/widgets/dialogs/findfiles/window.h2
-rw-r--r--examples/widgets/dialogs/standarddialogs/standarddialogs.pro1
-rw-r--r--examples/widgets/dialogs/tabdialog/tabdialog.pro1
-rw-r--r--examples/widgets/doc/images/addressbook-editdialog.pngbin8669 -> 11374 bytes
-rw-r--r--examples/widgets/doc/images/addressbook-example.pngbin12388 -> 20047 bytes
-rw-r--r--examples/widgets/doc/images/addressbook-newaddresstab.pngbin12556 -> 17413 bytes
-rw-r--r--examples/widgets/doc/images/graphicssimpleanchorlayout-example.pngbin16743 -> 11301 bytes
-rw-r--r--examples/widgets/doc/images/itemviews-editabletreemodel.pngbin32534 -> 30556 bytes
-rw-r--r--examples/widgets/doc/images/notepad.pngbin0 -> 12418 bytes
-rw-r--r--examples/widgets/doc/images/notepad1.pngbin0 -> 12418 bytes
-rw-r--r--examples/widgets/doc/images/notepad2.pngbin0 -> 22700 bytes
-rw-r--r--examples/widgets/doc/images/notepad3.pngbin0 -> 40584 bytes
-rw-r--r--examples/widgets/doc/images/notepad4.pngbin0 -> 9494 bytes
-rw-r--r--examples/widgets/doc/images/notepad_menu.pngbin0 -> 8657 bytes
-rw-r--r--examples/widgets/doc/images/stylesheet-pagefold.pngbin15989 -> 29118 bytes
-rw-r--r--examples/widgets/doc/src/addressbook.qdoc43
-rw-r--r--examples/widgets/doc/src/appchooser.qdoc38
-rw-r--r--examples/widgets/doc/src/basiclayouts.qdoc6
-rw-r--r--examples/widgets/doc/src/blurpicker.qdoc9
-rw-r--r--examples/widgets/doc/src/calendarwidget.qdoc10
-rw-r--r--examples/widgets/doc/src/collidingmice-example.qdoc10
-rw-r--r--examples/widgets/doc/src/configdialog.qdoc37
-rw-r--r--examples/widgets/doc/src/customsortfiltermodel.qdoc6
-rw-r--r--examples/widgets/doc/src/dragdroprobot.qdoc2
-rw-r--r--examples/widgets/doc/src/draggabletext.qdoc1
-rw-r--r--examples/widgets/doc/src/easing.qdoc3
-rw-r--r--examples/widgets/doc/src/elasticnodes.qdoc9
-rw-r--r--examples/widgets/doc/src/findfiles.qdoc41
-rw-r--r--examples/widgets/doc/src/graphicsview-anchorlayout.qdoc43
-rw-r--r--examples/widgets/doc/src/graphicsview-simpleanchorlayout.qdoc46
-rw-r--r--examples/widgets/doc/src/lighting.qdoc35
-rw-r--r--examples/widgets/doc/src/painterpaths.qdoc11
-rw-r--r--examples/widgets/doc/src/stardelegate.qdoc16
-rw-r--r--examples/widgets/doc/src/stylesheet.qdoc51
-rw-r--r--examples/widgets/doc/src/tablet.qdoc13
-rw-r--r--examples/widgets/doc/src/validators.qdoc2
-rw-r--r--examples/widgets/draganddrop/draggableicons/dragwidget.h2
-rw-r--r--examples/widgets/draganddrop/draggabletext/dragwidget.cpp4
-rw-r--r--examples/widgets/draganddrop/draggabletext/dragwidget.h2
-rw-r--r--examples/widgets/draganddrop/dropsite/droparea.h4
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsite.pro1
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsitewindow.cpp6
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp2
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/dragwidget.h2
-rw-r--r--examples/widgets/draganddrop/puzzle/main.cpp4
-rw-r--r--examples/widgets/draganddrop/puzzle/mainwindow.cpp27
-rw-r--r--examples/widgets/draganddrop/puzzle/mainwindow.h4
-rw-r--r--examples/widgets/draganddrop/puzzle/pieceslist.cpp2
-rw-r--r--examples/widgets/draganddrop/puzzle/pieceslist.h4
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzle.pro1
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzlewidget.cpp65
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzlewidget.h15
-rw-r--r--examples/widgets/effects/blurpicker/blurpicker.cpp9
-rw-r--r--examples/widgets/effects/effects.pro1
-rw-r--r--examples/widgets/effects/lighting/lighting.cpp150
-rw-r--r--examples/widgets/effects/lighting/lighting.h80
-rw-r--r--examples/widgets/effects/lighting/lighting.pro8
-rw-r--r--examples/widgets/effects/lighting/main.cpp65
-rw-r--r--examples/widgets/gestures/imagegestures/imagegestures.pro1
-rw-r--r--examples/widgets/graphicsview/boxes/boxes.pro1
-rw-r--r--examples/widgets/graphicsview/boxes/glbuffers.cpp4
-rw-r--r--examples/widgets/graphicsview/boxes/qtbox.cpp2
-rw-r--r--examples/widgets/graphicsview/boxes/scene.cpp15
-rw-r--r--examples/widgets/graphicsview/boxes/scene.h2
-rw-r--r--examples/widgets/graphicsview/boxes/trackball.cpp8
-rw-r--r--examples/widgets/graphicsview/collidingmice/main.cpp1
-rw-r--r--examples/widgets/graphicsview/collidingmice/mouse.cpp30
-rw-r--r--examples/widgets/graphicsview/diagramscene/arrow.cpp17
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramscene.pro1
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/coloritem.cpp4
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/main.cpp1
-rw-r--r--examples/widgets/graphicsview/elasticnodes/edge.cpp28
-rw-r--r--examples/widgets/graphicsview/elasticnodes/graphwidget.cpp3
-rw-r--r--examples/widgets/graphicsview/elasticnodes/main.cpp1
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro1
-rw-r--r--examples/widgets/graphicsview/padnavigator/padnavigator.pro1
-rw-r--r--examples/widgets/itemviews/addressbook/addressbook.pro1
-rw-r--r--examples/widgets/itemviews/addressbook/addresswidget.cpp26
-rw-r--r--examples/widgets/itemviews/addressbook/tablemodel.cpp37
-rw-r--r--examples/widgets/itemviews/addressbook/tablemodel.h29
-rw-r--r--examples/widgets/itemviews/basicsortfiltermodel/basicsortfiltermodel.pro1
-rw-r--r--examples/widgets/itemviews/chart/chart.pro1
-rw-r--r--examples/widgets/itemviews/chart/pieview.cpp12
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro1
-rw-r--r--examples/widgets/itemviews/combowidgetmapper/combowidgetmapper.pro1
-rw-r--r--examples/widgets/itemviews/customsortfiltermodel/customsortfiltermodel.pro1
-rw-r--r--examples/widgets/itemviews/dirview/dirview.pro1
-rw-r--r--examples/widgets/itemviews/editabletreemodel/editabletreemodel.pro1
-rw-r--r--examples/widgets/itemviews/fetchmore/fetchmore.pro1
-rw-r--r--examples/widgets/itemviews/frozencolumn/frozencolumn.pro1
-rw-r--r--examples/widgets/itemviews/interview/interview.pro1
-rw-r--r--examples/widgets/itemviews/pixelator/pixelator.pro1
-rw-r--r--examples/widgets/itemviews/puzzle/main.cpp2
-rw-r--r--examples/widgets/itemviews/puzzle/mainwindow.cpp33
-rw-r--r--examples/widgets/itemviews/puzzle/mainwindow.h2
-rw-r--r--examples/widgets/itemviews/puzzle/piecesmodel.cpp3
-rw-r--r--examples/widgets/itemviews/puzzle/puzzle.pro1
-rw-r--r--examples/widgets/itemviews/puzzle/puzzlewidget.cpp57
-rw-r--r--examples/widgets/itemviews/puzzle/puzzlewidget.h16
-rw-r--r--examples/widgets/itemviews/simpledommodel/simpledommodel.pro1
-rw-r--r--examples/widgets/itemviews/simpletreemodel/simpletreemodel.pro1
-rw-r--r--examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.pro1
-rw-r--r--examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.pro1
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheet.pro1
-rw-r--r--examples/widgets/itemviews/stardelegate/stardelegate.pro1
-rw-r--r--examples/widgets/itemviews/storageview/main.cpp10
-rw-r--r--examples/widgets/itemviews/storageview/storagemodel.cpp79
-rw-r--r--examples/widgets/itemviews/storageview/storagemodel.h14
-rw-r--r--examples/widgets/itemviews/storageview/storageview.pro1
-rw-r--r--examples/widgets/layouts/basiclayouts/basiclayouts.pro1
-rw-r--r--examples/widgets/layouts/dynamiclayouts/dynamiclayouts.pro1
-rw-r--r--examples/widgets/mainwindows/application/application.pro1
-rw-r--r--examples/widgets/mainwindows/dockwidgets/dockwidgets.pro1
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.cpp1
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.pro1
-rw-r--r--examples/widgets/mainwindows/mainwindow/toolbar.cpp4
-rw-r--r--examples/widgets/mainwindows/mdi/mdi.pro1
-rw-r--r--examples/widgets/mainwindows/sdi/sdi.pro1
-rw-r--r--examples/widgets/painting/affine/xform.cpp48
-rw-r--r--examples/widgets/painting/basicdrawing/basicdrawing.pro1
-rw-r--r--examples/widgets/painting/composition/composition.cpp2
-rw-r--r--examples/widgets/painting/fontsampler/fontsampler.pro1
-rw-r--r--examples/widgets/painting/imagecomposition/imagecomposition.pro1
-rw-r--r--examples/widgets/painting/painterpaths/painterpaths.pro1
-rw-r--r--examples/widgets/painting/painterpaths/window.cpp10
-rw-r--r--examples/widgets/painting/transformations/transformations.pro1
-rw-r--r--examples/widgets/richtext/calendar/calendar.pro1
-rw-r--r--examples/widgets/richtext/orderform/orderform.pro1
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.pro1
-rw-r--r--examples/widgets/richtext/textedit/textedit.pro1
-rw-r--r--examples/widgets/statemachine/rogue/window.cpp4
-rw-r--r--examples/widgets/tools/codecs/codecs.pro1
-rw-r--r--examples/widgets/tools/completer/completer.pro1
-rw-r--r--examples/widgets/tools/customcompleter/customcompleter.pro1
-rw-r--r--examples/widgets/tools/i18n/i18n.pro1
-rw-r--r--examples/widgets/tools/plugandpaint/plugandpaint.pro3
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp10
-rw-r--r--examples/widgets/tools/regexp/regexp.pro1
-rw-r--r--examples/widgets/tools/regularexpression/regularexpression.pro1
-rw-r--r--examples/widgets/tools/settingseditor/settingseditor.pro1
-rw-r--r--examples/widgets/tools/treemodelcompleter/treemodelcompleter.pro1
-rw-r--r--examples/widgets/tools/undo/mainwindow.cpp11
-rw-r--r--examples/widgets/tools/undo/undo.pro1
-rw-r--r--examples/widgets/tools/undoframework/diagramitem.cpp3
-rw-r--r--examples/widgets/tools/undoframework/undoframework.pro1
-rw-r--r--examples/widgets/tutorials/addressbook/part6/part6.pro1
-rw-r--r--examples/widgets/tutorials/addressbook/part7/part7.pro1
-rw-r--r--examples/widgets/tutorials/gettingStarted/gsQt/part5/part5.pro2
-rw-r--r--examples/widgets/tutorials/gettingstartedqt.qdoc559
-rw-r--r--examples/widgets/tutorials/modelview/1_readonly/1_readonly.pro1
-rw-r--r--examples/widgets/tutorials/modelview/2_formatting/2_formatting.pro1
-rw-r--r--examples/widgets/tutorials/modelview/3_changingmodel/3_changingmodel.pro1
-rw-r--r--examples/widgets/tutorials/modelview/4_headers/4_headers.pro1
-rw-r--r--examples/widgets/tutorials/modelview/5_edit/5_edit.pro1
-rw-r--r--examples/widgets/tutorials/modelview/6_treeview/6_treeview.pro1
-rw-r--r--examples/widgets/tutorials/modelview/7_selections/7_selections.pro1
-rw-r--r--examples/widgets/tutorials/notepad/images/copy.pngbin0 -> 1633 bytes
-rw-r--r--examples/widgets/tutorials/notepad/images/create.pngbin0 -> 459 bytes
-rw-r--r--examples/widgets/tutorials/notepad/images/cut.pngbin0 -> 9554 bytes
-rw-r--r--examples/widgets/tutorials/notepad/images/edit_redo.pngbin0 -> 7463 bytes
-rw-r--r--examples/widgets/tutorials/notepad/images/edit_undo.pngbin0 -> 8424 bytes
-rw-r--r--examples/widgets/tutorials/notepad/images/exit.pngbin0 -> 379 bytes
-rw-r--r--examples/widgets/tutorials/notepad/images/font.pngbin0 -> 6983 bytes
-rw-r--r--examples/widgets/tutorials/notepad/images/info.pngbin0 -> 557 bytes
-rw-r--r--examples/widgets/tutorials/notepad/images/new.pngbin0 -> 7422 bytes
-rw-r--r--examples/widgets/tutorials/notepad/images/open.pngbin0 -> 5437 bytes
-rw-r--r--examples/widgets/tutorials/notepad/images/paste.pngbin0 -> 3597 bytes
-rw-r--r--examples/widgets/tutorials/notepad/images/pencil.pngbin0 -> 3780 bytes
-rw-r--r--examples/widgets/tutorials/notepad/images/print.pngbin0 -> 331 bytes
-rw-r--r--examples/widgets/tutorials/notepad/images/save.pngbin0 -> 2699 bytes
-rw-r--r--examples/widgets/tutorials/notepad/images/save_as.pngbin0 -> 8209 bytes
-rw-r--r--examples/widgets/tutorials/notepad/main.cpp (renamed from examples/widgets/dialogs/configdialog/main.cpp)16
-rw-r--r--examples/widgets/tutorials/notepad/notepad.cpp193
-rw-r--r--examples/widgets/tutorials/notepad/notepad.h (renamed from examples/widgets/dialogs/configdialog/configdialog.h)69
-rw-r--r--examples/widgets/tutorials/notepad/notepad.pro21
-rw-r--r--examples/widgets/tutorials/notepad/notepad.qrc19
-rw-r--r--examples/widgets/tutorials/notepad/notepad.ui196
-rw-r--r--examples/widgets/tutorials/tutorials.pro2
-rw-r--r--examples/widgets/tutorials/widgets/nestedlayouts/nestedlayouts.pro1
-rw-r--r--examples/widgets/widgets/calendarwidget/calendarwidget.pro1
-rw-r--r--examples/widgets/widgets/charactermap/charactermap.pro1
-rw-r--r--examples/widgets/widgets/elidedlabel/elidedlabel.pro1
-rw-r--r--examples/widgets/widgets/icons/icons.pro1
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.pro1
-rw-r--r--examples/widgets/widgets/lineedits/lineedits.pro1
-rw-r--r--examples/widgets/widgets/movie/movie.pro1
-rw-r--r--examples/widgets/widgets/scribble/scribble.pro1
-rw-r--r--examples/widgets/widgets/sliders/sliders.pro1
-rw-r--r--examples/widgets/widgets/spinboxes/spinboxes.pro1
-rw-r--r--examples/widgets/widgets/styles/styles.pro1
-rw-r--r--examples/widgets/widgets/stylesheet/stylesheet.pro1
-rw-r--r--examples/widgets/widgets/tablet/mainwindow.cpp10
-rw-r--r--examples/widgets/widgets/tablet/mainwindow.h1
-rw-r--r--examples/widgets/widgets/tablet/tablet.pro1
-rw-r--r--examples/widgets/widgets/tablet/tabletcanvas.cpp52
-rw-r--r--examples/widgets/widgets/tablet/tabletcanvas.h2
-rw-r--r--examples/widgets/widgets/tetrix/main.cpp1
-rw-r--r--examples/widgets/widgets/tetrix/tetrixpiece.cpp2
-rw-r--r--examples/widgets/widgets/tooltips/main.cpp1
-rw-r--r--examples/widgets/widgets/tooltips/sortingbox.cpp4
-rw-r--r--examples/widgets/widgets/validators/validators.pro1
231 files changed, 1823 insertions, 1519 deletions
diff --git a/examples/widgets/animation/animatedtiles/main.cpp b/examples/widgets/animation/animatedtiles/main.cpp
index 0511fe8162..8edd64e482 100644
--- a/examples/widgets/animation/animatedtiles/main.cpp
+++ b/examples/widgets/animation/animatedtiles/main.cpp
@@ -48,8 +48,9 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QtWidgets/QtWidgets>
#include <QtCore/qmath.h>
+#include <QtCore/qrandom.h>
#include <QtCore/qstate.h>
class Pixmap : public QObject, public QGraphicsPixmapItem
@@ -202,8 +203,8 @@ int main(int argc, char **argv)
// Random
randomState->assignProperty(item, "pos",
- QPointF(-250 + qrand() % 500,
- -250 + qrand() % 500));
+ QPointF(-250 + QRandomGenerator::global()->bounded(500),
+ -250 + QRandomGenerator::global()->bounded(500)));
// Tiled
tiledState->assignProperty(item, "pos",
@@ -235,25 +236,25 @@ int main(int argc, char **argv)
anim->setEasingCurve(QEasingCurve::InOutBack);
group->addAnimation(anim);
}
- QAbstractTransition *trans = rootState->addTransition(ellipseButton, SIGNAL(pressed()), ellipseState);
+ QAbstractTransition *trans = rootState->addTransition(ellipseButton, &Button::pressed, ellipseState);
trans->addAnimation(group);
- trans = rootState->addTransition(figure8Button, SIGNAL(pressed()), figure8State);
+ trans = rootState->addTransition(figure8Button, &Button::pressed, figure8State);
trans->addAnimation(group);
- trans = rootState->addTransition(randomButton, SIGNAL(pressed()), randomState);
+ trans = rootState->addTransition(randomButton, &Button::pressed, randomState);
trans->addAnimation(group);
- trans = rootState->addTransition(tiledButton, SIGNAL(pressed()), tiledState);
+ trans = rootState->addTransition(tiledButton, &Button::pressed, tiledState);
trans->addAnimation(group);
- trans = rootState->addTransition(centeredButton, SIGNAL(pressed()), centeredState);
+ trans = rootState->addTransition(centeredButton, &Button::pressed, centeredState);
trans->addAnimation(group);
QTimer timer;
timer.start(125);
timer.setSingleShot(true);
- trans = rootState->addTransition(&timer, SIGNAL(timeout()), ellipseState);
+ trans = rootState->addTransition(&timer, &QTimer::timeout, ellipseState);
trans->addAnimation(group);
states.start();
diff --git a/examples/widgets/animation/animation.pro b/examples/widgets/animation/animation.pro
index a13f8bb65a..19b79caf15 100644
--- a/examples/widgets/animation/animation.pro
+++ b/examples/widgets/animation/animation.pro
@@ -2,7 +2,6 @@ TEMPLATE = \
subdirs
SUBDIRS += \
animatedtiles \
- appchooser \
easing \
moveblocks \
states \
diff --git a/examples/widgets/animation/appchooser/accessories-dictionary.png b/examples/widgets/animation/appchooser/accessories-dictionary.png
deleted file mode 100644
index e9bd55d918..0000000000
--- a/examples/widgets/animation/appchooser/accessories-dictionary.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/animation/appchooser/akregator.png b/examples/widgets/animation/appchooser/akregator.png
deleted file mode 100644
index a086f45ab6..0000000000
--- a/examples/widgets/animation/appchooser/akregator.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/animation/appchooser/appchooser.pro b/examples/widgets/animation/appchooser/appchooser.pro
deleted file mode 100644
index 674e623b2d..0000000000
--- a/examples/widgets/animation/appchooser/appchooser.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-QT += widgets
-
-SOURCES = main.cpp
-RESOURCES = appchooser.qrc
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/animation/appchooser
-INSTALLS += target
diff --git a/examples/widgets/animation/appchooser/appchooser.qrc b/examples/widgets/animation/appchooser/appchooser.qrc
deleted file mode 100644
index 28a3e1c4c1..0000000000
--- a/examples/widgets/animation/appchooser/appchooser.qrc
+++ /dev/null
@@ -1,8 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>accessories-dictionary.png</file>
- <file>akregator.png</file>
- <file>digikam.png</file>
- <file>k3b.png</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/animation/appchooser/digikam.png b/examples/widgets/animation/appchooser/digikam.png
deleted file mode 100644
index 9de9fb2f80..0000000000
--- a/examples/widgets/animation/appchooser/digikam.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/animation/appchooser/k3b.png b/examples/widgets/animation/appchooser/k3b.png
deleted file mode 100644
index bbcafcfba1..0000000000
--- a/examples/widgets/animation/appchooser/k3b.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/animation/appchooser/main.cpp b/examples/widgets/animation/appchooser/main.cpp
deleted file mode 100644
index 71c869f6a2..0000000000
--- a/examples/widgets/animation/appchooser/main.cpp
+++ /dev/null
@@ -1,183 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore>
-#include <QtWidgets>
-
-
-class Pixmap : public QGraphicsWidget
-{
- Q_OBJECT
-
-public:
- Pixmap(const QPixmap &pix, QGraphicsItem *parent = 0)
- : QGraphicsWidget(parent), orig(pix), p(pix)
- {
- }
-
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
- {
- painter->drawPixmap(QPointF(), p);
- }
-
- void mousePressEvent(QGraphicsSceneMouseEvent *) override
- {
- emit clicked();
- }
-
- void setGeometry(const QRectF &rect) override
- {
- QGraphicsWidget::setGeometry(rect);
-
- if (rect.size().width() > orig.size().width())
- p = orig.scaled(rect.size().toSize());
- else
- p = orig;
- }
-
-Q_SIGNALS:
- void clicked();
-
-private:
- QPixmap orig;
- QPixmap p;
-};
-
-class GraphicsView : public QGraphicsView
-{
- Q_OBJECT
-public:
- GraphicsView(QGraphicsScene *scene, QWidget *parent = 0) : QGraphicsView(scene, parent)
- {
- }
-
- void resizeEvent(QResizeEvent *) override
- {
- fitInView(sceneRect(), Qt::KeepAspectRatio);
- }
-};
-
-
-void createStates(const QObjectList &objects,
- const QRect &selectedRect, QState *parent)
-{
- for (int i = 0; i < objects.size(); ++i) {
- QState *state = new QState(parent);
- state->assignProperty(objects.at(i), "geometry", selectedRect);
- parent->addTransition(objects.at(i), SIGNAL(clicked()), state);
- }
-}
-
-void createAnimations(const QObjectList &objects, QStateMachine *machine)
-{
- for (int i=0; i<objects.size(); ++i)
- machine->addDefaultAnimation(new QPropertyAnimation(objects.at(i), "geometry"));
-}
-
-int main(int argc, char **argv)
-{
- Q_INIT_RESOURCE(appchooser);
-
- QApplication app(argc, argv);
-
- Pixmap *p1 = new Pixmap(QPixmap(":/digikam.png"));
- Pixmap *p2 = new Pixmap(QPixmap(":/akregator.png"));
- Pixmap *p3 = new Pixmap(QPixmap(":/accessories-dictionary.png"));
- Pixmap *p4 = new Pixmap(QPixmap(":/k3b.png"));
-
- p1->setObjectName("p1");
- p2->setObjectName("p2");
- p3->setObjectName("p3");
- p4->setObjectName("p4");
-
- p1->setGeometry(QRectF( 0.0, 0.0, 64.0, 64.0));
- p2->setGeometry(QRectF(236.0, 0.0, 64.0, 64.0));
- p3->setGeometry(QRectF(236.0, 236.0, 64.0, 64.0));
- p4->setGeometry(QRectF( 0.0, 236.0, 64.0, 64.0));
-
- QGraphicsScene scene(0, 0, 300, 300);
- scene.setBackgroundBrush(Qt::white);
- scene.addItem(p1);
- scene.addItem(p2);
- scene.addItem(p3);
- scene.addItem(p4);
-
- GraphicsView window(&scene);
- window.setFrameStyle(0);
- window.setAlignment(Qt::AlignLeft | Qt::AlignTop);
- window.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- window.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-
- QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::RestoreProperties);
-
- QState *group = new QState(&machine);
- group->setObjectName("group");
-
- QRect selectedRect(86, 86, 128, 128);
-
- QState *idleState = new QState(group);
- group->setInitialState(idleState);
-
- QObjectList objects;
- objects << p1 << p2 << p3 << p4;
- createStates(objects, selectedRect, group);
- createAnimations(objects, &machine);
-
- machine.setInitialState(group);
- machine.start();
-
- window.resize(300, 300);
- window.show();
-
- return app.exec();
-}
-
-#include "main.moc"
diff --git a/examples/widgets/animation/easing/easing.pro b/examples/widgets/animation/easing/easing.pro
index 498180c0bb..097e232c2f 100644
--- a/examples/widgets/animation/easing/easing.pro
+++ b/examples/widgets/animation/easing/easing.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(listwidget))
HEADERS = window.h \
animation.h
diff --git a/examples/widgets/animation/easing/images/qt-logo.png b/examples/widgets/animation/easing/images/qt-logo.png
index 6b72d5fb72..d10bd0bdf9 100644
--- a/examples/widgets/animation/easing/images/qt-logo.png
+++ b/examples/widgets/animation/easing/images/qt-logo.png
Binary files differ
diff --git a/examples/widgets/animation/moveblocks/main.cpp b/examples/widgets/animation/moveblocks/main.cpp
index a9b95808a5..6d17696108 100644
--- a/examples/widgets/animation/moveblocks/main.cpp
+++ b/examples/widgets/animation/moveblocks/main.cpp
@@ -125,7 +125,7 @@ public:
void onEntry(QEvent *) override
{
int n;
- while ((n = (qrand() % m_stateCount + 1)) == m_lastIndex)
+ while ((n = QRandomGenerator::global()->bounded(m_stateCount) + 1) == m_lastIndex)
{ }
m_lastIndex = n;
machine()->postEvent(new StateSwitchEvent(n));
@@ -323,8 +323,6 @@ int main(int argc, char **argv)
window.resize(300, 300);
window.show();
- qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
-
return app.exec();
}
diff --git a/examples/widgets/animation/stickman/lifecycle.cpp b/examples/widgets/animation/stickman/lifecycle.cpp
index 253af22b2d..dbe9a299b4 100644
--- a/examples/widgets/animation/stickman/lifecycle.cpp
+++ b/examples/widgets/animation/stickman/lifecycle.cpp
@@ -91,13 +91,12 @@ public:
: QEventTransition(this, QEvent::Timer)
{
setTargetState(target);
- qsrand((uint)QDateTime::currentSecsSinceEpoch());
startTimer(1000);
}
bool eventTest(QEvent *e) override
{
- return QEventTransition::eventTest(e) && ((qrand() % 50) == 0);
+ return QEventTransition::eventTest(e) && QRandomGenerator::global()->bounded(50) == 0;
}
};
//! [4]
diff --git a/examples/widgets/animation/stickman/stickman.cpp b/examples/widgets/animation/stickman/stickman.cpp
index 7a4629c4d2..b7a2d87ada 100644
--- a/examples/widgets/animation/stickman/stickman.cpp
+++ b/examples/widgets/animation/stickman/stickman.cpp
@@ -53,13 +53,7 @@
#include <QPainter>
#include <QTimer>
-
-#define _USE_MATH_DEFINES
-#include <math.h>
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
+#include <qmath.h>
static const qreal Coords[NodeCount * 2] = {
0.0, -150.0, // head, #0
@@ -300,7 +294,7 @@ void StickMan::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge
QPointF dist = node2->pos() - node1->pos();
qreal sinAngle = dist.x() / sqrt(pow(dist.x(), 2) + pow(dist.y(), 2));
- qreal angle = asin(sinAngle) * 180.0 / M_PI;
+ qreal angle = qRadiansToDegrees(asin(sinAngle));
QPointF headPos = node1->pos();
painter->translate(headPos);
diff --git a/examples/widgets/animation/sub-attaq/main.cpp b/examples/widgets/animation/sub-attaq/main.cpp
index f65ca7be18..9b28d8c40f 100644
--- a/examples/widgets/animation/sub-attaq/main.cpp
+++ b/examples/widgets/animation/sub-attaq/main.cpp
@@ -57,8 +57,6 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
Q_INIT_RESOURCE(subattaq);
- qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
-
MainWindow w;
w.show();
diff --git a/examples/widgets/animation/sub-attaq/states.cpp b/examples/widgets/animation/sub-attaq/states.cpp
index 21cff048e7..e19704db7b 100644
--- a/examples/widgets/animation/sub-attaq/states.cpp
+++ b/examples/widgets/animation/sub-attaq/states.cpp
@@ -64,6 +64,7 @@
#include <QtCore/QStateMachine>
#include <QtWidgets/QKeyEventTransition>
#include <QtCore/QFinalState>
+#include <QtCore/QRandomGenerator>
PlayState::PlayState(GraphicsScene *scene, QState *parent)
: QState(parent),
@@ -193,12 +194,12 @@ void LevelState::initializeLevel()
for (int j = 0; j < subContent.second; ++j ) {
SubMarine *sub = new SubMarine(submarineDesc.type, submarineDesc.name, submarineDesc.points);
scene->addItem(sub);
- int random = (qrand() % 15 + 1);
+ int random = QRandomGenerator::global()->bounded(15) + 1;
qreal x = random == 13 || random == 5 ? 0 : scene->width() - sub->size().width();
- qreal y = scene->height() -(qrand() % 150 + 1) - sub->size().height();
+ qreal y = scene->height() -(QRandomGenerator::global()->bounded(150) + 1) - sub->size().height();
sub->setPos(x,y);
sub->setCurrentDirection(x == 0 ? SubMarine::Right : SubMarine::Left);
- sub->setCurrentSpeed(qrand() % 3 + 1);
+ sub->setCurrentSpeed(QRandomGenerator::global()->bounded(3) + 1);
}
}
}
diff --git a/examples/widgets/animation/sub-attaq/submarine_p.h b/examples/widgets/animation/sub-attaq/submarine_p.h
index b8d5532962..698b4b494f 100644
--- a/examples/widgets/animation/sub-attaq/submarine_p.h
+++ b/examples/widgets/animation/sub-attaq/submarine_p.h
@@ -69,6 +69,7 @@
//Qt
#include <QtCore/QPropertyAnimation>
+#include <QtCore/QRandomGenerator>
#include <QtWidgets/QGraphicsScene>
//This state is describing when the boat is moving right
@@ -88,8 +89,8 @@ public:
protected slots:
void onAnimationMovementValueChanged(const QVariant &)
{
- if (qrand() % 200 + 1 == 3)
- submarine->launchTorpedo(qrand() % 3 + 1);
+ if (QRandomGenerator::global()->bounded(200) + 1 == 3)
+ submarine->launchTorpedo(QRandomGenerator::global()->bounded(3) + 1);
}
protected:
diff --git a/examples/widgets/desktop/screenshot/screenshot.pro b/examples/widgets/desktop/screenshot/screenshot.pro
index d179833cbd..37108503de 100644
--- a/examples/widgets/desktop/screenshot/screenshot.pro
+++ b/examples/widgets/desktop/screenshot/screenshot.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
HEADERS = screenshot.h
SOURCES = main.cpp \
diff --git a/examples/widgets/desktop/systray/systray.pro b/examples/widgets/desktop/systray/systray.pro
index 1d4fdc7843..e0708ea832 100644
--- a/examples/widgets/desktop/systray/systray.pro
+++ b/examples/widgets/desktop/systray/systray.pro
@@ -4,6 +4,7 @@ SOURCES = main.cpp \
RESOURCES = systray.qrc
QT += widgets
+requires(qtConfig(combobox))
# install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/desktop/systray
diff --git a/examples/widgets/dialogs/configdialog/configdialog.cpp b/examples/widgets/dialogs/configdialog/configdialog.cpp
deleted file mode 100644
index 5a0fb1c3bc..0000000000
--- a/examples/widgets/dialogs/configdialog/configdialog.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtWidgets>
-
-#include "configdialog.h"
-#include "pages.h"
-
-ConfigDialog::ConfigDialog()
-{
- contentsWidget = new QListWidget;
- contentsWidget->setViewMode(QListView::IconMode);
- contentsWidget->setIconSize(QSize(96, 84));
- contentsWidget->setMovement(QListView::Static);
- contentsWidget->setMaximumWidth(128);
- contentsWidget->setSpacing(12);
-
- pagesWidget = new QStackedWidget;
- pagesWidget->addWidget(new ConfigurationPage);
- pagesWidget->addWidget(new UpdatePage);
- pagesWidget->addWidget(new QueryPage);
-
- QPushButton *closeButton = new QPushButton(tr("Close"));
-
- createIcons();
- contentsWidget->setCurrentRow(0);
-
- connect(closeButton, &QAbstractButton::clicked, this, &QWidget::close);
-
- QHBoxLayout *horizontalLayout = new QHBoxLayout;
- horizontalLayout->addWidget(contentsWidget);
- horizontalLayout->addWidget(pagesWidget, 1);
-
- QHBoxLayout *buttonsLayout = new QHBoxLayout;
- buttonsLayout->addStretch(1);
- buttonsLayout->addWidget(closeButton);
-
- QVBoxLayout *mainLayout = new QVBoxLayout;
- mainLayout->addLayout(horizontalLayout);
- mainLayout->addStretch(1);
- mainLayout->addSpacing(12);
- mainLayout->addLayout(buttonsLayout);
- setLayout(mainLayout);
-
- setWindowTitle(tr("Config Dialog"));
-}
-
-void ConfigDialog::createIcons()
-{
- QListWidgetItem *configButton = new QListWidgetItem(contentsWidget);
- configButton->setIcon(QIcon(":/images/config.png"));
- configButton->setText(tr("Configuration"));
- configButton->setTextAlignment(Qt::AlignHCenter);
- configButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
-
- QListWidgetItem *updateButton = new QListWidgetItem(contentsWidget);
- updateButton->setIcon(QIcon(":/images/update.png"));
- updateButton->setText(tr("Update"));
- updateButton->setTextAlignment(Qt::AlignHCenter);
- updateButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
-
- QListWidgetItem *queryButton = new QListWidgetItem(contentsWidget);
- queryButton->setIcon(QIcon(":/images/query.png"));
- queryButton->setText(tr("Query"));
- queryButton->setTextAlignment(Qt::AlignHCenter);
- queryButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
-
- connect(contentsWidget, &QListWidget::currentItemChanged, this, &ConfigDialog::changePage);
-}
-
-void ConfigDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
-{
- if (!current)
- current = previous;
-
- pagesWidget->setCurrentIndex(contentsWidget->row(current));
-}
diff --git a/examples/widgets/dialogs/configdialog/configdialog.pro b/examples/widgets/dialogs/configdialog/configdialog.pro
deleted file mode 100644
index 8ba55becad..0000000000
--- a/examples/widgets/dialogs/configdialog/configdialog.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-QT += widgets
-
-HEADERS = configdialog.h \
- pages.h
-SOURCES = configdialog.cpp \
- main.cpp \
- pages.cpp
-RESOURCES += configdialog.qrc
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/dialogs/configdialog
-INSTALLS += target
diff --git a/examples/widgets/dialogs/configdialog/configdialog.qrc b/examples/widgets/dialogs/configdialog/configdialog.qrc
deleted file mode 100644
index 31d0d49666..0000000000
--- a/examples/widgets/dialogs/configdialog/configdialog.qrc
+++ /dev/null
@@ -1,7 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>images/config.png</file>
- <file>images/query.png</file>
- <file>images/update.png</file>
-</qresource>
-</RCC>
diff --git a/examples/widgets/dialogs/configdialog/images/config.png b/examples/widgets/dialogs/configdialog/images/config.png
deleted file mode 100644
index 5c14d5f470..0000000000
--- a/examples/widgets/dialogs/configdialog/images/config.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/dialogs/configdialog/images/query.png b/examples/widgets/dialogs/configdialog/images/query.png
deleted file mode 100644
index ea9e291eeb..0000000000
--- a/examples/widgets/dialogs/configdialog/images/query.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/dialogs/configdialog/images/update.png b/examples/widgets/dialogs/configdialog/images/update.png
deleted file mode 100644
index 3cb8ba6c77..0000000000
--- a/examples/widgets/dialogs/configdialog/images/update.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/dialogs/configdialog/pages.cpp b/examples/widgets/dialogs/configdialog/pages.cpp
deleted file mode 100644
index 0c7762f029..0000000000
--- a/examples/widgets/dialogs/configdialog/pages.cpp
+++ /dev/null
@@ -1,161 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtWidgets>
-
-#include "pages.h"
-
-ConfigurationPage::ConfigurationPage(QWidget *parent)
- : QWidget(parent)
-{
- QGroupBox *configGroup = new QGroupBox(tr("Server configuration"));
-
- QLabel *serverLabel = new QLabel(tr("Server:"));
- QComboBox *serverCombo = new QComboBox;
- serverCombo->addItem(tr("Qt (Australia)"));
- serverCombo->addItem(tr("Qt (Germany)"));
- serverCombo->addItem(tr("Qt (Norway)"));
- serverCombo->addItem(tr("Qt (People's Republic of China)"));
- serverCombo->addItem(tr("Qt (USA)"));
-
- QHBoxLayout *serverLayout = new QHBoxLayout;
- serverLayout->addWidget(serverLabel);
- serverLayout->addWidget(serverCombo);
-
- QVBoxLayout *configLayout = new QVBoxLayout;
- configLayout->addLayout(serverLayout);
- configGroup->setLayout(configLayout);
-
- QVBoxLayout *mainLayout = new QVBoxLayout;
- mainLayout->addWidget(configGroup);
- mainLayout->addStretch(1);
- setLayout(mainLayout);
-}
-
-UpdatePage::UpdatePage(QWidget *parent)
- : QWidget(parent)
-{
- QGroupBox *updateGroup = new QGroupBox(tr("Package selection"));
- QCheckBox *systemCheckBox = new QCheckBox(tr("Update system"));
- QCheckBox *appsCheckBox = new QCheckBox(tr("Update applications"));
- QCheckBox *docsCheckBox = new QCheckBox(tr("Update documentation"));
-
- QGroupBox *packageGroup = new QGroupBox(tr("Existing packages"));
-
- QListWidget *packageList = new QListWidget;
- QListWidgetItem *qtItem = new QListWidgetItem(packageList);
- qtItem->setText(tr("Qt"));
- QListWidgetItem *qsaItem = new QListWidgetItem(packageList);
- qsaItem->setText(tr("QSA"));
- QListWidgetItem *teamBuilderItem = new QListWidgetItem(packageList);
- teamBuilderItem->setText(tr("Teambuilder"));
-
- QPushButton *startUpdateButton = new QPushButton(tr("Start update"));
-
- QVBoxLayout *updateLayout = new QVBoxLayout;
- updateLayout->addWidget(systemCheckBox);
- updateLayout->addWidget(appsCheckBox);
- updateLayout->addWidget(docsCheckBox);
- updateGroup->setLayout(updateLayout);
-
- QVBoxLayout *packageLayout = new QVBoxLayout;
- packageLayout->addWidget(packageList);
- packageGroup->setLayout(packageLayout);
-
- QVBoxLayout *mainLayout = new QVBoxLayout;
- mainLayout->addWidget(updateGroup);
- mainLayout->addWidget(packageGroup);
- mainLayout->addSpacing(12);
- mainLayout->addWidget(startUpdateButton);
- mainLayout->addStretch(1);
- setLayout(mainLayout);
-}
-
-QueryPage::QueryPage(QWidget *parent)
- : QWidget(parent)
-{
- QGroupBox *packagesGroup = new QGroupBox(tr("Look for packages"));
-
- QLabel *nameLabel = new QLabel(tr("Name:"));
- QLineEdit *nameEdit = new QLineEdit;
-
- QLabel *dateLabel = new QLabel(tr("Released after:"));
- QDateTimeEdit *dateEdit = new QDateTimeEdit(QDate::currentDate());
-
- QCheckBox *releasesCheckBox = new QCheckBox(tr("Releases"));
- QCheckBox *upgradesCheckBox = new QCheckBox(tr("Upgrades"));
-
- QSpinBox *hitsSpinBox = new QSpinBox;
- hitsSpinBox->setPrefix(tr("Return up to "));
- hitsSpinBox->setSuffix(tr(" results"));
- hitsSpinBox->setSpecialValueText(tr("Return only the first result"));
- hitsSpinBox->setMinimum(1);
- hitsSpinBox->setMaximum(100);
- hitsSpinBox->setSingleStep(10);
-
- QPushButton *startQueryButton = new QPushButton(tr("Start query"));
-
- QGridLayout *packagesLayout = new QGridLayout;
- packagesLayout->addWidget(nameLabel, 0, 0);
- packagesLayout->addWidget(nameEdit, 0, 1);
- packagesLayout->addWidget(dateLabel, 1, 0);
- packagesLayout->addWidget(dateEdit, 1, 1);
- packagesLayout->addWidget(releasesCheckBox, 2, 0);
- packagesLayout->addWidget(upgradesCheckBox, 3, 0);
- packagesLayout->addWidget(hitsSpinBox, 4, 0, 1, 2);
- packagesGroup->setLayout(packagesLayout);
-
- QVBoxLayout *mainLayout = new QVBoxLayout;
- mainLayout->addWidget(packagesGroup);
- mainLayout->addSpacing(12);
- mainLayout->addWidget(startQueryButton);
- mainLayout->addStretch(1);
- setLayout(mainLayout);
-}
diff --git a/examples/widgets/dialogs/configdialog/pages.h b/examples/widgets/dialogs/configdialog/pages.h
deleted file mode 100644
index beb7f86ae0..0000000000
--- a/examples/widgets/dialogs/configdialog/pages.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef PAGES_H
-#define PAGES_H
-
-#include <QWidget>
-
-class ConfigurationPage : public QWidget
-{
-public:
- ConfigurationPage(QWidget *parent = 0);
-};
-
-class QueryPage : public QWidget
-{
-public:
- QueryPage(QWidget *parent = 0);
-};
-
-class UpdatePage : public QWidget
-{
-public:
- UpdatePage(QWidget *parent = 0);
-};
-
-#endif
diff --git a/examples/widgets/dialogs/dialogs.pro b/examples/widgets/dialogs/dialogs.pro
index 82e814dcb0..753308fc55 100644
--- a/examples/widgets/dialogs/dialogs.pro
+++ b/examples/widgets/dialogs/dialogs.pro
@@ -2,7 +2,6 @@ QT_FOR_CONFIG += widgets
TEMPLATE = subdirs
SUBDIRS = classwizard \
- configdialog \
extension \
findfiles \
licensewizard \
@@ -14,4 +13,3 @@ SUBDIRS = classwizard \
!qtConfig(wizard) {
SUBDIRS -= trivialwizard licensewizard classwizard
}
-wince: SUBDIRS += sipdialog
diff --git a/examples/widgets/dialogs/findfiles/findfiles.pro b/examples/widgets/dialogs/findfiles/findfiles.pro
index 2dd058ac5c..4fb77f0dd7 100644
--- a/examples/widgets/dialogs/findfiles/findfiles.pro
+++ b/examples/widgets/dialogs/findfiles/findfiles.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
HEADERS = window.h
SOURCES = main.cpp \
diff --git a/examples/widgets/dialogs/findfiles/window.cpp b/examples/widgets/dialogs/findfiles/window.cpp
index f2ce853d99..1b16cdcd35 100644
--- a/examples/widgets/dialogs/findfiles/window.cpp
+++ b/examples/widgets/dialogs/findfiles/window.cpp
@@ -74,6 +74,7 @@ static inline void openFile(const QString &fileName)
Window::Window(QWidget *parent)
: QWidget(parent)
{
+ setWindowTitle(tr("Find Files"));
QPushButton *browseButton = new QPushButton(tr("&Browse..."), this);
connect(browseButton, &QAbstractButton::clicked, this, &Window::browse);
findButton = new QPushButton(tr("&Find"), this);
@@ -92,9 +93,7 @@ Window::Window(QWidget *parent)
filesFoundLabel = new QLabel;
createFilesTable();
-//! [0]
-//! [1]
QGridLayout *mainLayout = new QGridLayout(this);
mainLayout->addWidget(new QLabel(tr("Named:")), 0, 0);
mainLayout->addWidget(fileComboBox, 0, 1, 1, 2);
@@ -106,12 +105,13 @@ Window::Window(QWidget *parent)
mainLayout->addWidget(filesTable, 3, 0, 1, 3);
mainLayout->addWidget(filesFoundLabel, 4, 0, 1, 2);
mainLayout->addWidget(findButton, 4, 2);
+//! [0]
- setWindowTitle(tr("Find Files"));
- const QRect screenGeometry = QApplication::desktop()->screenGeometry(this);
- resize(screenGeometry.width() / 2, screenGeometry.height() / 3);
-}
//! [1]
+ connect(new QShortcut(QKeySequence::Quit, this), &QShortcut::activated,
+ qApp, &QApplication::quit);
+//! [1]
+}
//! [2]
void Window::browse()
@@ -133,21 +133,7 @@ static void updateComboBox(QComboBox *comboBox)
comboBox->addItem(comboBox->currentText());
}
-//! [13]
-
-static void findRecursion(const QString &path, const QString &pattern, QStringList *result)
-{
- QDir currentDir(path);
- const QString prefix = path + QLatin1Char('/');
- foreach (const QString &match, currentDir.entryList(QStringList(pattern), QDir::Files | QDir::NoSymLinks))
- result->append(prefix + match);
- foreach (const QString &dir, currentDir.entryList(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot))
- findRecursion(prefix + dir, pattern, result);
-}
-
-//! [13]
//! [3]
-
void Window::find()
{
filesTable->setRowCount(0);
@@ -155,6 +141,7 @@ void Window::find()
QString fileName = fileComboBox->currentText();
QString text = textComboBox->currentText();
QString path = QDir::cleanPath(directoryComboBox->currentText());
+ currentDir = QDir(path);
//! [3]
updateComboBox(fileComboBox);
@@ -162,12 +149,16 @@ void Window::find()
updateComboBox(directoryComboBox);
//! [4]
-
- currentDir = QDir(path);
+ QStringList filter;
+ if (!fileName.isEmpty())
+ filter << fileName;
+ QDirIterator it(path, filter, QDir::AllEntries | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
QStringList files;
- findRecursion(path, fileName.isEmpty() ? QStringLiteral("*") : fileName, &files);
+ while (it.hasNext())
+ files << it.next();
if (!text.isEmpty())
files = findFiles(files, text);
+ files.sort();
showFiles(files);
}
//! [4]
@@ -225,20 +216,18 @@ QStringList Window::findFiles(const QStringList &files, const QString &text)
//! [7]
//! [8]
-void Window::showFiles(const QStringList &files)
+void Window::showFiles(const QStringList &paths)
{
- for (int i = 0; i < files.size(); ++i) {
- const QString &fileName = files.at(i);
- const QString toolTip = QDir::toNativeSeparators(fileName);
- const QString relativePath = QDir::toNativeSeparators(currentDir.relativeFilePath(fileName));
- const qint64 size = QFileInfo(fileName).size();
+ for (const QString &filePath : paths) {
+ const QString toolTip = QDir::toNativeSeparators(filePath);
+ const QString relativePath = QDir::toNativeSeparators(currentDir.relativeFilePath(filePath));
+ const qint64 size = QFileInfo(filePath).size();
QTableWidgetItem *fileNameItem = new QTableWidgetItem(relativePath);
- fileNameItem->setData(absoluteFileNameRole, QVariant(fileName));
+ fileNameItem->setData(absoluteFileNameRole, QVariant(filePath));
fileNameItem->setToolTip(toolTip);
fileNameItem->setFlags(fileNameItem->flags() ^ Qt::ItemIsEditable);
- QTableWidgetItem *sizeItem = new QTableWidgetItem(tr("%1 KB")
- .arg(int((size + 1023) / 1024)));
- sizeItem->setData(absoluteFileNameRole, QVariant(fileName));
+ QTableWidgetItem *sizeItem = new QTableWidgetItem(QLocale().formattedDataSize(size));
+ sizeItem->setData(absoluteFileNameRole, QVariant(filePath));
sizeItem->setToolTip(toolTip);
sizeItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
sizeItem->setFlags(sizeItem->flags() ^ Qt::ItemIsEditable);
@@ -248,7 +237,7 @@ void Window::showFiles(const QStringList &files)
filesTable->setItem(row, 0, fileNameItem);
filesTable->setItem(row, 1, sizeItem);
}
- filesFoundLabel->setText(tr("%n file(s) found (Double click on a file to open it)", 0, files.size()));
+ filesFoundLabel->setText(tr("%n file(s) found (Double click on a file to open it)", 0, paths.size()));
filesFoundLabel->setWordWrap(true);
}
//! [8]
diff --git a/examples/widgets/dialogs/findfiles/window.h b/examples/widgets/dialogs/findfiles/window.h
index fe217381e2..949df704bb 100644
--- a/examples/widgets/dialogs/findfiles/window.h
+++ b/examples/widgets/dialogs/findfiles/window.h
@@ -79,7 +79,7 @@ private slots:
private:
QStringList findFiles(const QStringList &files, const QString &text);
- void showFiles(const QStringList &files);
+ void showFiles(const QStringList &paths);
QComboBox *createComboBox(const QString &text = QString());
void createFilesTable();
diff --git a/examples/widgets/dialogs/standarddialogs/standarddialogs.pro b/examples/widgets/dialogs/standarddialogs/standarddialogs.pro
index d2e9e19771..95396db022 100644
--- a/examples/widgets/dialogs/standarddialogs/standarddialogs.pro
+++ b/examples/widgets/dialogs/standarddialogs/standarddialogs.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
HEADERS = dialog.h
SOURCES = dialog.cpp \
diff --git a/examples/widgets/dialogs/tabdialog/tabdialog.pro b/examples/widgets/dialogs/tabdialog/tabdialog.pro
index 8a686b4f5c..00f1815ca8 100644
--- a/examples/widgets/dialogs/tabdialog/tabdialog.pro
+++ b/examples/widgets/dialogs/tabdialog/tabdialog.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(listwidget))
HEADERS = tabdialog.h
SOURCES = main.cpp \
diff --git a/examples/widgets/doc/images/addressbook-editdialog.png b/examples/widgets/doc/images/addressbook-editdialog.png
index fd41ee63f7..7434aa44ef 100644
--- a/examples/widgets/doc/images/addressbook-editdialog.png
+++ b/examples/widgets/doc/images/addressbook-editdialog.png
Binary files differ
diff --git a/examples/widgets/doc/images/addressbook-example.png b/examples/widgets/doc/images/addressbook-example.png
index b743c166da..eebe97a718 100644
--- a/examples/widgets/doc/images/addressbook-example.png
+++ b/examples/widgets/doc/images/addressbook-example.png
Binary files differ
diff --git a/examples/widgets/doc/images/addressbook-newaddresstab.png b/examples/widgets/doc/images/addressbook-newaddresstab.png
index ff215a4b20..6b60ee08e9 100644
--- a/examples/widgets/doc/images/addressbook-newaddresstab.png
+++ b/examples/widgets/doc/images/addressbook-newaddresstab.png
Binary files differ
diff --git a/examples/widgets/doc/images/graphicssimpleanchorlayout-example.png b/examples/widgets/doc/images/graphicssimpleanchorlayout-example.png
index 543670e05c..e4bed44edf 100644
--- a/examples/widgets/doc/images/graphicssimpleanchorlayout-example.png
+++ b/examples/widgets/doc/images/graphicssimpleanchorlayout-example.png
Binary files differ
diff --git a/examples/widgets/doc/images/itemviews-editabletreemodel.png b/examples/widgets/doc/images/itemviews-editabletreemodel.png
index a151ea857f..ff6cf637a1 100644
--- a/examples/widgets/doc/images/itemviews-editabletreemodel.png
+++ b/examples/widgets/doc/images/itemviews-editabletreemodel.png
Binary files differ
diff --git a/examples/widgets/doc/images/notepad.png b/examples/widgets/doc/images/notepad.png
new file mode 100644
index 0000000000..40d13269b9
--- /dev/null
+++ b/examples/widgets/doc/images/notepad.png
Binary files differ
diff --git a/examples/widgets/doc/images/notepad1.png b/examples/widgets/doc/images/notepad1.png
new file mode 100644
index 0000000000..40d13269b9
--- /dev/null
+++ b/examples/widgets/doc/images/notepad1.png
Binary files differ
diff --git a/examples/widgets/doc/images/notepad2.png b/examples/widgets/doc/images/notepad2.png
new file mode 100644
index 0000000000..9cec1f9a58
--- /dev/null
+++ b/examples/widgets/doc/images/notepad2.png
Binary files differ
diff --git a/examples/widgets/doc/images/notepad3.png b/examples/widgets/doc/images/notepad3.png
new file mode 100644
index 0000000000..426861ab06
--- /dev/null
+++ b/examples/widgets/doc/images/notepad3.png
Binary files differ
diff --git a/examples/widgets/doc/images/notepad4.png b/examples/widgets/doc/images/notepad4.png
new file mode 100644
index 0000000000..fc08eab204
--- /dev/null
+++ b/examples/widgets/doc/images/notepad4.png
Binary files differ
diff --git a/examples/widgets/doc/images/notepad_menu.png b/examples/widgets/doc/images/notepad_menu.png
new file mode 100644
index 0000000000..2dd771111a
--- /dev/null
+++ b/examples/widgets/doc/images/notepad_menu.png
Binary files differ
diff --git a/examples/widgets/doc/images/stylesheet-pagefold.png b/examples/widgets/doc/images/stylesheet-pagefold.png
index 5ccb4edbc9..d1358f326b 100644
--- a/examples/widgets/doc/images/stylesheet-pagefold.png
+++ b/examples/widgets/doc/images/stylesheet-pagefold.png
Binary files differ
diff --git a/examples/widgets/doc/src/addressbook.qdoc b/examples/widgets/doc/src/addressbook.qdoc
index b9bcae21aa..1fa0bfa9d4 100644
--- a/examples/widgets/doc/src/addressbook.qdoc
+++ b/examples/widgets/doc/src/addressbook.qdoc
@@ -60,8 +60,8 @@
the address book.
\c TableModel is a subclass of QAbstractTableModel that provides
- the standard model/view API to access data. It also holds a
- QList of \l{QPair}s corresponding to the contacts added.
+ the standard model/view API to access data. It holds a list of
+ added contacts.
However, this data is not all visible in a single tab. Instead,
QTableView is used to provide 9 different views of the same
data, according to the alphabet groups.
@@ -80,7 +80,7 @@
\section1 TableModel Class Definition
The \c TableModel class provides standard API to access data in
- its QList of \l{QPair}s by subclassing QAbstractTableModel. The
+ its list of contacts by subclassing QAbstractTableModel. The
basic functions that must be implemented in order to do so are:
\c rowCount(), \c columnCount(), \c data(), \c headerData().
For TableModel to be editable, it has to provide implementations
@@ -90,15 +90,14 @@
\snippet itemviews/addressbook/tablemodel.h 0
Two constructors are used, a default constructor which uses
- \c TableModel's own \c {QList<QPair<QString, QString>>} and one
- that takes \c {QList<QPair<QString, QString>} as an argument,
- for convenience.
+ \c TableModel's own \c {QList<Contact>} and one that takes
+ \c {QList<Contact>} as an argument, for convenience.
\section1 TableModel Class Implementation
We implement the two constructors as defined in the header file.
- The second constructor initializes the list of pairs in the
+ The second constructor initializes the list of contacts in the
model, with the parameter value.
\snippet itemviews/addressbook/tablemodel.cpp 0
@@ -117,7 +116,7 @@
The \c data() function returns either a \b Name or
\b {Address}, based on the contents of the model index
supplied. The row number stored in the model index is used to
- reference an item in the list of pairs. Selection is handled
+ reference an item in the list of contacts. Selection is handled
by the QItemSelectionModel, which will be explained with
\c AddressWidget.
@@ -164,12 +163,11 @@
use the editing features of the QTableView object, we enable
them here so that we can reuse the model in other programs.
- The last function in \c {TableModel}, \c getList() returns the
- QList<QPair<QString, QString>> object that holds all the
- contacts in the address book. We use this function later to
- obtain the list of contacts to check for existing entries, write
- the contacts to a file and read them back. Further explanation is
- given with \c AddressWidget.
+ The last function in \c {TableModel}, \c getContacts() returns the
+ QList<Contact> object that holds all the contacts in the address
+ book. We use this function later to obtain the list of contacts to
+ check for existing entries, write the contacts to a file and read
+ them back. Further explanation is given with \c AddressWidget.
\snippet itemviews/addressbook/tablemodel.cpp 8
@@ -222,11 +220,12 @@
The QItemSelectionModel class provides a
\l{QItemSelectionModel::selectionChanged()}{selectionChanged}
signal that is connected to \c{AddressWidget}'s
- \c selectionChanged() signal. This signal to signal connection
- is necessary to enable the \uicontrol{Edit Entry...} and
- \uicontrol{Remove Entry} actions in \c MainWindow's Tools menu. This
- connection is further explained in \c MainWindow's
- implementation.
+ \c selectionChanged() signal. We also connect
+ QTabWidget::currentChanged() signal to the lambda expression which
+ emits \c{AddressWidget}'s \c selectionChanged() as well. These
+ connections are necessary to enable the \uicontrol{Edit Entry...} and
+ \uicontrol{Remove Entry} actions in \c MainWindow's Tools menu.
+ It is further explained in \c MainWindow's implementation.
Each table view in the address book is added as a tab to the
QTabWidget with the relevant label, obtained from the QStringList
@@ -250,7 +249,7 @@
Basic validation is done in the second \c addEntry() function to
prevent duplicate entries in the address book. As mentioned with
\c TableModel, this is part of the reason why we require the
- getter method \c getList().
+ getter method \c getContacts().
\snippet itemviews/addressbook/addresswidget.cpp 3
@@ -292,7 +291,7 @@
The \c writeToFile() function is used to save a file containing
all the contacts in the address book. The file is saved in a
- custom \c{.dat} format. The contents of the QList of \l{QPair}s
+ custom \c{.dat} format. The contents of the list of contacts
are written to \c file using QDataStream. If the file cannot be
opened, a QMessageBox is displayed with the related error message.
@@ -301,7 +300,7 @@
The \c readFromFile() function loads a file containing all the
contacts in the address book, previously saved using
\c writeToFile(). QDataStream is used to read the contents of a
- \c{.dat} file into a list of pairs and each of these is added
+ \c{.dat} file into a list of contacts and each of these is added
using \c addEntry().
\snippet itemviews/addressbook/addresswidget.cpp 7
diff --git a/examples/widgets/doc/src/appchooser.qdoc b/examples/widgets/doc/src/appchooser.qdoc
deleted file mode 100644
index e74860214a..0000000000
--- a/examples/widgets/doc/src/appchooser.qdoc
+++ /dev/null
@@ -1,38 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \example animation/appchooser
- \title Application Chooser Example
-
- \brief The Application Chooser example shows how to use the Qt state
- machine and the animation framework to select between
- applications.
-
- \image appchooser-example.png
-
-*/
diff --git a/examples/widgets/doc/src/basiclayouts.qdoc b/examples/widgets/doc/src/basiclayouts.qdoc
index 01bcaa8c1a..e9d7cea21b 100644
--- a/examples/widgets/doc/src/basiclayouts.qdoc
+++ b/examples/widgets/doc/src/basiclayouts.qdoc
@@ -67,11 +67,11 @@
In the constructor, we first use the \c createMenu() function to
create and populate a menu bar and the \c createHorizontalGroupBox()
function to create a group box containing four buttons with a
- horizontal layout. Next we use the \c createGridGroupBox() function
+ horizontal layout. Next, we use the \c createGridGroupBox() function
to create a group box containing several line edits and a small text
editor which are displayed in a grid layout. Finally, we use the
\c createFormGroupBox() function to create a group box with
- three labels and three input fields: a line edit, a combo box and
+ three labels and three input fields: a line edit, a combo box, and
a spin box.
\snippet layouts/basiclayouts/dialog.cpp 1
@@ -111,7 +111,7 @@
\snippet layouts/basiclayouts/dialog.cpp 4
We use the QBoxLayout::addWidget() function to add the widgets to
- the end of layout. Each widget will get at least its minimum size
+ the end of the layout. Each widget will get at least its minimum size
and at most its maximum size. It is possible to specify a stretch
factor in the \l {QBoxLayout::addWidget()}{addWidget()} function,
and any excess space is shared according to these stretch
diff --git a/examples/widgets/doc/src/blurpicker.qdoc b/examples/widgets/doc/src/blurpicker.qdoc
index f12184e4c9..87f36389e7 100644
--- a/examples/widgets/doc/src/blurpicker.qdoc
+++ b/examples/widgets/doc/src/blurpicker.qdoc
@@ -32,4 +32,13 @@
\brief Demonstrates how to apply graphical effects on items in the view
\image blurpickereffect-example.png
+
+ The Blur Picker example displays a circle of application icons.
+ All icons are blurred, except the one on the bottom left side of
+ the screen, which is the one in focus.
+ Clicking anywhere on the left side of the screen moves the icon
+ circle clockwise to the next icon
+ Clicking on the right side advances the circle counterclockwise.
+
+ \sa QGraphicsBlurEffect
*/
diff --git a/examples/widgets/doc/src/calendarwidget.qdoc b/examples/widgets/doc/src/calendarwidget.qdoc
index eaf8f547da..c04fab1fc7 100644
--- a/examples/widgets/doc/src/calendarwidget.qdoc
+++ b/examples/widgets/doc/src/calendarwidget.qdoc
@@ -110,8 +110,8 @@
size hints of its contents widgets.
To ensure that the window isn't automatically resized every time
- we change a property of the QCalendarWidget (e.g., hiding the
- navigation bar, trhe vertical header, or the grid), we set the
+ we change a property of the QCalendarWidget (for example, hiding the
+ navigation bar, the vertical header, or the grid), we set the
minimum height of row 0 and the minimum width of column 0 to the
initial size of the QCalendarWidget.
@@ -126,8 +126,8 @@
the formatting specified by the user.
The \c createGeneralOptionsGroupBox() function is somewhat large
- and several widgets are set up the same way; we look at parts of
- its implementation here and skip the rest:
+ and several widgets are set up in the same way. We will look at
+ parts of its implementation here and skip the rest:
\snippet widgets/calendarwidget/window.cpp 10
\dots
@@ -146,7 +146,7 @@
\snippet widgets/calendarwidget/window.cpp 11
\dots
- After creating the widgets, we connect the signals and slots. We
+ After having created the widgets, we connect the signals and slots. We
connect the comboboxes to private slots of \c Window or to
public slots provided by QComboBox.
diff --git a/examples/widgets/doc/src/collidingmice-example.qdoc b/examples/widgets/doc/src/collidingmice-example.qdoc
index 02417ba521..535057bb6a 100644
--- a/examples/widgets/doc/src/collidingmice-example.qdoc
+++ b/examples/widgets/doc/src/collidingmice-example.qdoc
@@ -80,8 +80,7 @@
\snippet graphicsview/collidingmice/mouse.cpp 0
To calculate the various components of the mouse's color, we use
- the global qrand() function which is a thread-safe version of the
- standard C++ rand() function.
+ \l QRandomGenerator.
Then we call the \l {QGraphicsItem::setRotation()}{setRotation()} function
inherited from QGraphicsItem. Items live in their own local
@@ -178,12 +177,7 @@
\snippet graphicsview/collidingmice/main.cpp 0
- First, we create an application object and call the global
- qsrand() function to specify the seed used to generate a new
- random number sequence of pseudo random integers with the
- previously mentioned qrand() function.
-
- Then it is time to create the scene:
+ First, we create an application object and create the scene:
\snippet graphicsview/collidingmice/main.cpp 1
diff --git a/examples/widgets/doc/src/configdialog.qdoc b/examples/widgets/doc/src/configdialog.qdoc
deleted file mode 100644
index 9f2cc21adb..0000000000
--- a/examples/widgets/doc/src/configdialog.qdoc
+++ /dev/null
@@ -1,37 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \example dialogs/configdialog
- \title Config Dialog Example
- \ingroup examples-dialogs
-
- \brief The Config Dialog examples shows how a configuration dialog can be created by
- using an icon view with a stacked widget.
-
- \image configdialog-example.png
-*/
diff --git a/examples/widgets/doc/src/customsortfiltermodel.qdoc b/examples/widgets/doc/src/customsortfiltermodel.qdoc
index 0eb6560e10..6eab846e89 100644
--- a/examples/widgets/doc/src/customsortfiltermodel.qdoc
+++ b/examples/widgets/doc/src/customsortfiltermodel.qdoc
@@ -75,7 +75,7 @@
QSortFilterProxyModel's default implementations of functions are
written so that they call the equivalent functions in the relevant
source model. This simple proxying mechanism may need to be
- overridden for source models with more complex behavior; in this
+ overridden for source models with more complex behavior. In this
example we derive from the QSortFilterProxyModel class to ensure
that our filter can recognize a valid range of dates, and to
control the sorting behavior.
@@ -170,7 +170,7 @@
We implement two private slots, \c textFilterChanged() and \c
dateFilterChanged(), to respond to the user changing the filter
- pattern, case sensitivity or any of the dates. In addition, we
+ pattern, case sensitivity, or any of the dates. In addition, we
implement a public \c setSourceModel() convenience function to set
up the model/ view relation.
@@ -197,7 +197,7 @@
\snippet itemviews/customsortfiltermodel/window.cpp 1
The QTreeView class provides a default model/view implementation
- of a tree view; our view implements a tree representation of items
+ of a tree view. Our view implements a tree representation of items
in the application's source model.
\snippet itemviews/customsortfiltermodel/window.cpp 2
diff --git a/examples/widgets/doc/src/dragdroprobot.qdoc b/examples/widgets/doc/src/dragdroprobot.qdoc
index ac221ec5f9..f74b898e1b 100644
--- a/examples/widgets/doc/src/dragdroprobot.qdoc
+++ b/examples/widgets/doc/src/dragdroprobot.qdoc
@@ -257,7 +257,7 @@
\snippet graphicsview/dragdroprobot/coloritem.cpp 0
\c ColorItem's constructor assigns an opaque random color to its color
- member by making use of qrand(). For improved usability, it assigns a
+ member by making use of \l QRandomGenerator. For improved usability, it assigns a
tooltip that provides a useful hint to the user, and it also sets a
suitable cursor. This ensures that the cursor will chance to
Qt::OpenHandCursor when the mouse pointer hovers over the item.
diff --git a/examples/widgets/doc/src/draggabletext.qdoc b/examples/widgets/doc/src/draggabletext.qdoc
index c4a694028b..97b2f036bd 100644
--- a/examples/widgets/doc/src/draggabletext.qdoc
+++ b/examples/widgets/doc/src/draggabletext.qdoc
@@ -28,6 +28,7 @@
/*!
\example draganddrop/draggabletext
\title Draggable Text Example
+ \brief Illustrates how to drag and drop text between widgets
\brief The Draggable Text example shows how to drag and drop textual data between widgets
in the same application, and between different applications.
diff --git a/examples/widgets/doc/src/easing.qdoc b/examples/widgets/doc/src/easing.qdoc
index 3a9727d393..807dd72e93 100644
--- a/examples/widgets/doc/src/easing.qdoc
+++ b/examples/widgets/doc/src/easing.qdoc
@@ -34,4 +34,7 @@
\image easing-example.png
+ See \l QEasingCurve for a detailed description on how to use the class's
+ functionalities.
+
*/
diff --git a/examples/widgets/doc/src/elasticnodes.qdoc b/examples/widgets/doc/src/elasticnodes.qdoc
index 09ac891b24..65e1195121 100644
--- a/examples/widgets/doc/src/elasticnodes.qdoc
+++ b/examples/widgets/doc/src/elasticnodes.qdoc
@@ -424,9 +424,8 @@
\section1 The main() Function
In contrast to the complexity of the rest of this example, the \c main()
- function is very simple: We create a QApplication instance, seed the
- randomizer using qsrand(), and then create and show an instance of \c
- GraphWidget. Because all nodes in the grid are moved initially, the \c
- GraphWidget timer will start immediately after control has returned to the
- event loop.
+ function is very simple: We create a QApplication instance, then create and
+ show an instance of \c GraphWidget. Because all nodes in the grid are moved
+ initially, the \c GraphWidget timer will start immediately after control
+ has returned to the event loop.
*/
diff --git a/examples/widgets/doc/src/findfiles.qdoc b/examples/widgets/doc/src/findfiles.qdoc
index b8363dc698..a2eb326519 100644
--- a/examples/widgets/doc/src/findfiles.qdoc
+++ b/examples/widgets/doc/src/findfiles.qdoc
@@ -74,19 +74,23 @@
\snippet dialogs/findfiles/window.cpp 0
- We create the application's buttons using the private \c
- createButton() function. Then we create the comboboxes associated
- with the search specifications, using the private \c
- createComboBox() function. We also create the application's labels
- before we use the private \c createFilesTable() function to create
- the table displaying the search results.
+ We create the widgets to build up the UI, and we add them to a main layout
+ using QGridLayout. We have, however, put the \c Find and \c Quit buttons
+ and a stretchable space in a separate \l QHBoxLayout first, to make the
+ buttons appear in the \c Window widget's bottom right corner.
+
+ Alternatively, we could have used Qt Designer to construct a UI file,
+ and \l {uic} to generate this code.
\snippet dialogs/findfiles/window.cpp 1
- Then we add all the widgets to a main layout using QGridLayout. We
- have, however, put the \c Find and \c Quit buttons and a
- stretchable space in a separate QHBoxLayout first, to make the
- buttons appear in the \c Window widget's bottom right corner.
+ We did not create a \l QMenuBar with a \uicontrol Quit menu item; but we
+ would still like to have a keyboard shortcut for quitting. Since we
+ construct a \l QShortcut with \l QKeySequence::Quit, and connect it to
+ \l QApplication::quit(), on most platforms it will be possible to press
+ Control-Q to quit (or whichever standard Quit key is configured on that platform).
+ (On \macos, this is redundant, because every application gets a
+ \uicontrol Quit menu item automatically; but it helps to make the application portable.)
\snippet dialogs/findfiles/window.cpp 2
@@ -122,18 +126,16 @@
We use the directory's path to create a QDir; the QDir class
provides access to directory structures and their contents.
- \snippet dialogs/findfiles/window.cpp 13
-
- We recursively create a list of the files (contained in the newl
- created QDir) that match the specified file name.
+ We use QDirIterator to iterate over the files that match the
+ specified file name and build a QStringList of paths.
Then we search through all the files in the list, using the private
- \c findFiles() function, eliminating the ones that don't contain
- the specified text. And finally, we display the results using the
- private \c showFiles() function.
+ \c findFiles() function, eliminating the ones that don't contain the
+ specified text. We sort them (because QDirIterator did not). And finally,
+ we display the results using the private \c showFiles() function.
If the user didn't specify any text, there is no reason to search
- through the files, and we display the results immediately.
+ through the files, so we sort and display the results immediately.
\image findfiles_progress_dialog.png Screenshot of the Progress Dialog
@@ -196,7 +198,8 @@
the \c find() slot. In the \c showFiles() function we run through
the provided list of file names, adding each relative file name to the
first column in the table widget and retrieving the file's size using
- QFileInfo for the second column. For later use, we set
+ QFileInfo for the second column. We use \l QLocale::formattedDataSize()
+ to format the file size in a human-readable form. For later use, we set
the absolute path as a data on the QTableWidget using the
the role absoluteFileNameRole defined to be Qt::UserRole + 1.
diff --git a/examples/widgets/doc/src/graphicsview-anchorlayout.qdoc b/examples/widgets/doc/src/graphicsview-anchorlayout.qdoc
index 95717340d1..bd27a0dc4f 100644
--- a/examples/widgets/doc/src/graphicsview-anchorlayout.qdoc
+++ b/examples/widgets/doc/src/graphicsview-anchorlayout.qdoc
@@ -35,4 +35,47 @@
class.
\image graphicsanchorlayout-example.png
+
+ The basic steps of this example are:
+ \list
+ \li Create a QGraphicsScene
+ \li Create widgets
+ \li Create a QGraphicsAnchorLayout
+ \li Create a QGraphicsWidget
+ \li Add vertical and horizontal anchors between the widgets
+ \li View the scene with a QGraphicsView object
+ \endlist
+
+ \section1 Creating a QGraphicsScene
+
+ \quotefromfile graphicsview/anchorlayout/main.cpp
+ \skipto QGraphicsScene
+ \printuntil setSceneRect
+
+ \section1 Creating Widgets
+
+ \skipto QGraphicsProxyWidget
+ \printuntil *g
+
+ \section1 Creating a Layout
+
+ \skipto QGraphicsAnchorLayout
+ \printuntil l->setSpacing
+
+ \section1 Creating a QGraphicsWidget
+
+ \skipto QGraphicsWidget
+ \printuntil setLayout(l)
+
+ \section1 Adding Anchors
+
+ \skipto vertical
+ \printuntil l->addAnchor(f, Qt::AnchorRight
+
+ \section1 Viewing the Scene with QGraphicsView
+
+ \skipto scene.addItem
+ \printuntil view.show
+
+ \sa {Simple Anchor Layout Example}
*/
diff --git a/examples/widgets/doc/src/graphicsview-simpleanchorlayout.qdoc b/examples/widgets/doc/src/graphicsview-simpleanchorlayout.qdoc
index 866dac442b..fd0427fdc0 100644
--- a/examples/widgets/doc/src/graphicsview-simpleanchorlayout.qdoc
+++ b/examples/widgets/doc/src/graphicsview-simpleanchorlayout.qdoc
@@ -35,4 +35,50 @@
QGraphicsAnchorLayout class.
\image graphicssimpleanchorlayout-example.png
+
+ The example starts by creating a QGraphicsScene (\c scene), 3 widgets
+ (\c a, \c b, and \c c), and a QGraphicsAnchorlayout (\c layout).
+
+ \quotefromfile graphicsview/simpleanchorlayout/main.cpp
+ \skipto QGraphicsScene
+ \printuntil QGraphicsAnchorLayout
+
+ First it anchors the top left corner of item \c a to the top left
+ corner of \c layout. This can be done in two steps:
+
+ \skipto layout->addAnchor(a
+ \printto adding
+
+ Or in one step:
+
+ \skipuntil [adding a corner anchor]
+ \printline layout->addCornerAnchors(a, Qt::T
+
+ Then the right anchor of \c a is anchored to the left anchor of
+ \c b, and the top of item \c b is anchored to the bottom of \c a.
+
+ \skipuntil [adding anchors]
+ \printto adding anchors
+
+ Place a third widget \c c under widget \c b:
+
+ \skipuntil third widget
+ \printline AnchorBottom
+
+ Items \c b and \c c are anchored to each other horizontally:
+
+ \skipto Qt::Horizontal
+ \printline Qt::Horizontal
+
+ Item c is anchored to the bottom right point of \c layout
+
+ \skipuntil corner of the layout
+ \printline Qt::BottomRightCorner
+
+ Finally, QGraphicsWidget \c w is displayed in QGraphicsView \c view.
+
+ \skipto QGraphicsWidget
+ \printuntil app.exec()
+
+ \sa {Anchor Layout Example}
*/
diff --git a/examples/widgets/doc/src/lighting.qdoc b/examples/widgets/doc/src/lighting.qdoc
deleted file mode 100644
index 994172cf5d..0000000000
--- a/examples/widgets/doc/src/lighting.qdoc
+++ /dev/null
@@ -1,35 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \example effects/lighting
- \title Lighting Effect Example
- \ingroup examples-graphicsview-graphicseffects
- \brief Demonstrates how to apply effects on items in the view
-
- \image lightingeffect-example.png
-*/
diff --git a/examples/widgets/doc/src/painterpaths.qdoc b/examples/widgets/doc/src/painterpaths.qdoc
index 2cc5ff410a..bd821ac1bf 100644
--- a/examples/widgets/doc/src/painterpaths.qdoc
+++ b/examples/widgets/doc/src/painterpaths.qdoc
@@ -98,14 +98,9 @@
\section1 Window Class Implementation
- In the implementation of the \c Window class we first declare the
- constant \c Pi with six significant figures:
-
- \snippet painting/painterpaths/window.cpp 0
-
- In the constructor, we then define the various painter paths and
- create corresponding \c RenderArea widgets which will render the
- graphical shapes:
+ In the \c Window constructor, we define the various painter paths
+ and create corresponding \c RenderArea widgets which will render
+ the graphical shapes:
\snippet painting/painterpaths/window.cpp 1
diff --git a/examples/widgets/doc/src/stardelegate.qdoc b/examples/widgets/doc/src/stardelegate.qdoc
index dcc7080456..44d17662ca 100644
--- a/examples/widgets/doc/src/stardelegate.qdoc
+++ b/examples/widgets/doc/src/stardelegate.qdoc
@@ -37,7 +37,7 @@
When displaying data in a QListView, QTableView, or QTreeView,
the individual items are drawn by a
\l{Delegate Classes}{delegate}. Also, when the user starts
- editing an item (e.g., by double-clicking the item), the delegate
+ editing an item (for example, by double-clicking the item), the delegate
provides an editor widget that is placed on top of the item while
editing takes place.
@@ -96,9 +96,9 @@
QItemDelegate paint it for us. This ensures that the \c
StarDelegate can handle the most common data types.
- In the case where the item is a \c StarRating, we draw the
- background if the item is selected, and we draw the item using \c
- StarRating::paint(), which we will review later.
+ If the item is a \c StarRating, we draw the background if the
+ item is selected, and we draw the item using \c StarRating::paint(),
+ which we will review later.
\c{StartRating}s can be stored in a QVariant thanks to the
Q_DECLARE_METATYPE() macro appearing in \c starrating.h. More on
@@ -133,8 +133,8 @@
We simply call \c setStarRating() on the editor.
The \l{QAbstractItemDelegate::}{setModelData()} function is
- called when editing is finished, to commit data from the editor
- to the model:
+ called to commit data from the editor to the model when editing
+ is finished:
\snippet itemviews/stardelegate/stardelegate.cpp 4
@@ -210,7 +210,7 @@
current rating, and \c myMaxStarCount stores the highest possible
rating (typically 5).
- The Q_DECLARE_METATYPE() macro makes the type \c StarRating known
+ The \c Q_DECLARE_METATYPE() macro makes the type \c StarRating known
to QVariant, making it possible to store \c StarRating values in
QVariant.
@@ -283,7 +283,7 @@
\list
\li It is possible to open editors programmatically by calling
QAbstractItemView::edit(), instead of relying on edit
- triggers. This could be use to support other edit triggers
+ triggers. This could be used to support other edit triggers
than those offered by the QAbstractItemView::EditTrigger enum.
For example, in the Star Delegate example, hovering over an
item with the mouse might make sense as a way to pop up an
diff --git a/examples/widgets/doc/src/stylesheet.qdoc b/examples/widgets/doc/src/stylesheet.qdoc
index 0016836f0d..a86b697059 100644
--- a/examples/widgets/doc/src/stylesheet.qdoc
+++ b/examples/widgets/doc/src/stylesheet.qdoc
@@ -33,5 +33,56 @@
\borderedimage stylesheet-pagefold.png
\caption Screen Shot of the Pagefold style sheet
+
+ The Style Sheet example shows how widgets can be styled using Qt Style Sheets.
+ You can open the style editor by selecting \uicontrol File > \uicontrol Edit Style Sheet,
+ to select an existing style sheet or design your own style and load it.
+
+ The Style Sheet example consists of 2 classes:
+ \list
+ \li \c MainWindow
+ \li \c StyleSheetEditor
+ \endlist
+
+
+ \section1 MainWindow Class
+
+ \c MainWindow inherits QWidget, and is the application's main window defined in
+ \c mainwindow.ui. The style of \c MainWindow can be modified with \l StyleSheetEditor.
+
+
+ \section1 StyleSheetEditor Class
+
+ \c StyleSheetEditor enables you to open an editor where you can load an existing style sheet.
+ It is also possible to define a new stylesheet and load it. Its layout is defined in
+ \c stylesheeteditor.ui.
+
+ \quotefromfile widgets/stylesheet/stylesheeteditor.cpp
+ \skipto on_styleCombo_activated
+ \printline on_styleCombo_activated
+
+ Sets the specified \a styleName and grays the \c applyButton.
+
+ \skipto on_styleSheetCombo_activated
+ \printline on_styleSheetCombo_activated
+
+ Loads the stylesheet from \c styleSheetName.
+
+ \skipto on_styleTextEdit_textChanged()
+ \printline on_styleTextEdit_textChanged()
+
+ Enables the \c applyButton when the text in the buffer has changed.
+
+ \skipto on_applyButton_clicked()
+ \printline on_applyButton_clicked()
+
+ Sets the stylesheet properties in \l qApp and disables the \c applyButton.
+
+ \skipto loadStyleSheet(const QString &sheetName)
+ \printline loadStyleSheet(const QString &sheetName)
+
+ Loads the specified \a sheetName, and sets its properties in
+ \l qApp.
+
*/
diff --git a/examples/widgets/doc/src/tablet.qdoc b/examples/widgets/doc/src/tablet.qdoc
index 88fdefa68f..2b11020c07 100644
--- a/examples/widgets/doc/src/tablet.qdoc
+++ b/examples/widgets/doc/src/tablet.qdoc
@@ -206,8 +206,7 @@
\snippet widgets/tablet/tabletcanvas.cpp 0
- In the constructor we initialize our class variables. We need
- to draw the background of our pixmap, as the default is gray.
+ In the constructor we initialize most of our class variables.
Here is the implementation of \c saveImage():
@@ -247,7 +246,15 @@
\snippet widgets/tablet/tabletcanvas.cpp 4
- We simply draw the pixmap to the top left of the widget.
+ The first time Qt calls paintEvent(), m_pixmap is default-constructed, so
+ QPixmap::isNull() returns \c true. Now that we know which screen we will be
+ rendering to, we can create a pixmap with the appropriate resolution.
+ The size of the pixmap with which we fill the window depends on the screen
+ resolution, as the example does not support zoom; and it may be that one
+ screen is \l {High DPI Displays}{high DPI} while another is not. We need to
+ draw the background too, as the default is gray.
+
+ After that, we simply draw the pixmap to the top left of the widget.
Here is the implementation of \c paintPixmap():
diff --git a/examples/widgets/doc/src/validators.qdoc b/examples/widgets/doc/src/validators.qdoc
index f3f4dc5e63..bbb2e5f7b6 100644
--- a/examples/widgets/doc/src/validators.qdoc
+++ b/examples/widgets/doc/src/validators.qdoc
@@ -31,4 +31,6 @@
\ingroup examples-widgets
\brief The Validators example shows the signal emission behavior of input
validators.
+
+ \borderedimage validators.png
*/
diff --git a/examples/widgets/draganddrop/draggableicons/dragwidget.h b/examples/widgets/draganddrop/draggableicons/dragwidget.h
index 18be074b61..98e623a5e3 100644
--- a/examples/widgets/draganddrop/draggableicons/dragwidget.h
+++ b/examples/widgets/draganddrop/draggableicons/dragwidget.h
@@ -62,7 +62,7 @@ QT_END_NAMESPACE
class DragWidget : public QFrame
{
public:
- DragWidget(QWidget *parent = 0);
+ explicit DragWidget(QWidget *parent = nullptr);
protected:
void dragEnterEvent(QDragEnterEvent *event) override;
diff --git a/examples/widgets/draganddrop/draggabletext/dragwidget.cpp b/examples/widgets/draganddrop/draggabletext/dragwidget.cpp
index fb169b953b..2135ba2ef9 100644
--- a/examples/widgets/draganddrop/draggabletext/dragwidget.cpp
+++ b/examples/widgets/draganddrop/draggabletext/dragwidget.cpp
@@ -123,7 +123,7 @@ void DragWidget::dropEvent(QDropEvent *event)
hotSpot.setY(hotSpotPos.last().toInt());
}
- foreach (const QString &piece, pieces) {
+ for (const QString &piece : pieces) {
QLabel *newLabel = createDragLabel(piece, this);
newLabel->move(position - hotSpot);
newLabel->show();
@@ -141,7 +141,7 @@ void DragWidget::dropEvent(QDropEvent *event)
} else {
event->ignore();
}
- foreach (QWidget *widget, findChildren<QWidget *>()) {
+ for (QWidget *widget : findChildren<QWidget *>()) {
if (!widget->isVisible())
widget->deleteLater();
}
diff --git a/examples/widgets/draganddrop/draggabletext/dragwidget.h b/examples/widgets/draganddrop/draggabletext/dragwidget.h
index 24d1f6f5c7..38abb0ceb8 100644
--- a/examples/widgets/draganddrop/draggabletext/dragwidget.h
+++ b/examples/widgets/draganddrop/draggabletext/dragwidget.h
@@ -61,7 +61,7 @@ QT_END_NAMESPACE
class DragWidget : public QWidget
{
public:
- DragWidget(QWidget *parent = 0);
+ explicit DragWidget(QWidget *parent = nullptr);
protected:
void dragEnterEvent(QDragEnterEvent *event) override;
diff --git a/examples/widgets/draganddrop/dropsite/droparea.h b/examples/widgets/draganddrop/dropsite/droparea.h
index 5b6e209dfa..ab1de8ea44 100644
--- a/examples/widgets/draganddrop/dropsite/droparea.h
+++ b/examples/widgets/draganddrop/dropsite/droparea.h
@@ -63,13 +63,13 @@ class DropArea : public QLabel
Q_OBJECT
public:
- DropArea(QWidget *parent = 0);
+ explicit DropArea(QWidget *parent = nullptr);
public slots:
void clear();
signals:
- void changed(const QMimeData *mimeData = 0);
+ void changed(const QMimeData *mimeData = nullptr);
//! [DropArea header part1]
//! [DropArea header part2]
diff --git a/examples/widgets/draganddrop/dropsite/dropsite.pro b/examples/widgets/draganddrop/dropsite/dropsite.pro
index 606b0c266d..41455a46dc 100644
--- a/examples/widgets/draganddrop/dropsite/dropsite.pro
+++ b/examples/widgets/draganddrop/dropsite/dropsite.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(tablewidget))
HEADERS = droparea.h \
dropsitewindow.h
diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
index dc865ac171..28a42ee614 100644
--- a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
+++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
@@ -88,8 +88,8 @@ DropSiteWindow::DropSiteWindow()
buttonBox->addButton(clearButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
- connect(quitButton, &QAbstractButton::pressed, this, &QWidget::close);
- connect(clearButton, &QAbstractButton::pressed, dropArea, &DropArea::clear);
+ connect(quitButton, &QAbstractButton::clicked, this, &QWidget::close);
+ connect(clearButton, &QAbstractButton::clicked, dropArea, &DropArea::clear);
//! [constructor part4]
//! [constructor part5]
@@ -113,7 +113,7 @@ void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData)
//! [updateFormatsTable() part1]
//! [updateFormatsTable() part2]
- foreach (QString format, mimeData->formats()) {
+ for (const QString &format : mimeData->formats()) {
QTableWidgetItem *formatItem = new QTableWidgetItem(format);
formatItem->setFlags(Qt::ItemIsEnabled);
formatItem->setTextAlignment(Qt::AlignTop | Qt::AlignLeft);
diff --git a/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp b/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp
index b185b2900d..451b53f623 100644
--- a/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp
+++ b/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp
@@ -167,7 +167,7 @@ void DragWidget::dropEvent(QDropEvent *event)
QString::SkipEmptyParts);
QPoint position = event->pos();
- foreach (const QString &piece, pieces) {
+ for (const QString &piece : pieces) {
DragLabel *newLabel = new DragLabel(piece, this);
newLabel->move(position);
newLabel->show();
diff --git a/examples/widgets/draganddrop/fridgemagnets/dragwidget.h b/examples/widgets/draganddrop/fridgemagnets/dragwidget.h
index 104e500134..ff513a33d8 100644
--- a/examples/widgets/draganddrop/fridgemagnets/dragwidget.h
+++ b/examples/widgets/draganddrop/fridgemagnets/dragwidget.h
@@ -62,7 +62,7 @@ QT_END_NAMESPACE
class DragWidget : public QWidget
{
public:
- DragWidget(QWidget *parent = 0);
+ explicit DragWidget(QWidget *parent = nullptr);
protected:
void dragEnterEvent(QDragEnterEvent *event) override;
diff --git a/examples/widgets/draganddrop/puzzle/main.cpp b/examples/widgets/draganddrop/puzzle/main.cpp
index 0bf65a89c5..d013bf078d 100644
--- a/examples/widgets/draganddrop/puzzle/main.cpp
+++ b/examples/widgets/draganddrop/puzzle/main.cpp
@@ -48,10 +48,10 @@
**
****************************************************************************/
-#include <QApplication>
-
#include "mainwindow.h"
+#include <QApplication>
+
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(puzzle);
diff --git a/examples/widgets/draganddrop/puzzle/mainwindow.cpp b/examples/widgets/draganddrop/puzzle/mainwindow.cpp
index 806133583a..98a7cd4265 100644
--- a/examples/widgets/draganddrop/puzzle/mainwindow.cpp
+++ b/examples/widgets/draganddrop/puzzle/mainwindow.cpp
@@ -67,12 +67,19 @@ MainWindow::MainWindow(QWidget *parent)
void MainWindow::openImage()
{
- const QString fileName =
- QFileDialog::getOpenFileName(this, tr("Open Image"), QString(),
- tr("Image Files (*.png *.jpg *.bmp)"));
-
- if (!fileName.isEmpty())
- loadImage(fileName);
+ const QString directory =
+ QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).value(0, QDir::homePath());
+ QFileDialog dialog(this, tr("Open Image"), directory);
+ dialog.setAcceptMode(QFileDialog::AcceptOpen);
+ dialog.setFileMode(QFileDialog::ExistingFile);
+ QStringList mimeTypeFilters;
+ for (const QByteArray &mimeTypeName : QImageReader::supportedMimeTypes())
+ mimeTypeFilters.append(mimeTypeName);
+ mimeTypeFilters.sort();
+ dialog.setMimeTypeFilters(mimeTypeFilters);
+ dialog.selectMimeTypeFilter("image/jpeg");
+ if (dialog.exec() == QDialog::Accepted)
+ loadImage(dialog.selectedFiles().constFirst());
}
void MainWindow::loadImage(const QString &fileName)
@@ -101,8 +108,8 @@ void MainWindow::setCompleted()
void MainWindow::setupPuzzle()
{
int size = qMin(puzzleImage.width(), puzzleImage.height());
- puzzleImage = puzzleImage.copy((puzzleImage.width() - size)/2,
- (puzzleImage.height() - size)/2, size, size).scaled(puzzleWidget->width(),
+ puzzleImage = puzzleImage.copy((puzzleImage.width() - size) / 2,
+ (puzzleImage.height() - size) / 2, size, size).scaled(puzzleWidget->width(),
puzzleWidget->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
piecesList->clear();
@@ -115,10 +122,8 @@ void MainWindow::setupPuzzle()
}
}
- qsrand(QCursor::pos().x() ^ QCursor::pos().y());
-
for (int i = 0; i < piecesList->count(); ++i) {
- if (int(2.0*qrand()/(RAND_MAX+1.0)) == 1) {
+ if (QRandomGenerator::global()->bounded(2) == 1) {
QListWidgetItem *item = piecesList->takeItem(i);
piecesList->insertItem(0, item);
}
diff --git a/examples/widgets/draganddrop/puzzle/mainwindow.h b/examples/widgets/draganddrop/puzzle/mainwindow.h
index e43f52cab8..626612ebe8 100644
--- a/examples/widgets/draganddrop/puzzle/mainwindow.h
+++ b/examples/widgets/draganddrop/puzzle/mainwindow.h
@@ -51,8 +51,8 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
-#include <QPixmap>
#include <QMainWindow>
+#include <QPixmap>
class PiecesList;
class PuzzleWidget;
@@ -65,7 +65,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow(QWidget *parent = 0);
+ explicit MainWindow(QWidget *parent = nullptr);
void loadImage(const QString &path);
public slots:
diff --git a/examples/widgets/draganddrop/puzzle/pieceslist.cpp b/examples/widgets/draganddrop/puzzle/pieceslist.cpp
index 30890ecf9b..7846d37ed2 100644
--- a/examples/widgets/draganddrop/puzzle/pieceslist.cpp
+++ b/examples/widgets/draganddrop/puzzle/pieceslist.cpp
@@ -101,7 +101,7 @@ void PiecesList::dropEvent(QDropEvent *event)
}
}
-void PiecesList::addPiece(QPixmap pixmap, QPoint location)
+void PiecesList::addPiece(const QPixmap &pixmap, const QPoint &location)
{
QListWidgetItem *pieceItem = new QListWidgetItem(this);
pieceItem->setIcon(QIcon(pixmap));
diff --git a/examples/widgets/draganddrop/puzzle/pieceslist.h b/examples/widgets/draganddrop/puzzle/pieceslist.h
index b67d2bdaf7..a508d17d72 100644
--- a/examples/widgets/draganddrop/puzzle/pieceslist.h
+++ b/examples/widgets/draganddrop/puzzle/pieceslist.h
@@ -58,8 +58,8 @@ class PiecesList : public QListWidget
Q_OBJECT
public:
- explicit PiecesList(int pieceSize, QWidget *parent = 0);
- void addPiece(QPixmap pixmap, QPoint location);
+ explicit PiecesList(int pieceSize, QWidget *parent = nullptr);
+ void addPiece(const QPixmap &pixmap, const QPoint &location);
static QString puzzleMimeType() { return QStringLiteral("image/x-puzzle-piece"); }
diff --git a/examples/widgets/draganddrop/puzzle/puzzle.pro b/examples/widgets/draganddrop/puzzle/puzzle.pro
index 97e7206682..c462ba1bb8 100644
--- a/examples/widgets/draganddrop/puzzle/puzzle.pro
+++ b/examples/widgets/draganddrop/puzzle/puzzle.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
HEADERS = mainwindow.h \
pieceslist.h \
diff --git a/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp b/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp
index 2093d7820c..72f2662bce 100644
--- a/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp
+++ b/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp
@@ -66,9 +66,7 @@ PuzzleWidget::PuzzleWidget(int imageSize, QWidget *parent)
void PuzzleWidget::clear()
{
- pieceLocations.clear();
- piecePixmaps.clear();
- pieceRects.clear();
+ pieces.clear();
highlightedRect = QRect();
inPlace = 0;
update();
@@ -95,7 +93,7 @@ void PuzzleWidget::dragMoveEvent(QDragMoveEvent *event)
QRect updateRect = highlightedRect.united(targetSquare(event->pos()));
if (event->mimeData()->hasFormat(PiecesList::puzzleMimeType())
- && pieceRects.indexOf(targetSquare(event->pos())) == -1) {
+ && findPiece(targetSquare(event->pos())) == -1) {
highlightedRect = targetSquare(event->pos());
event->setDropAction(Qt::MoveAction);
@@ -111,26 +109,23 @@ void PuzzleWidget::dragMoveEvent(QDragMoveEvent *event)
void PuzzleWidget::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasFormat(PiecesList::puzzleMimeType())
- && pieceRects.indexOf(targetSquare(event->pos())) == -1) {
+ && findPiece(targetSquare(event->pos())) == -1) {
QByteArray pieceData = event->mimeData()->data(PiecesList::puzzleMimeType());
QDataStream dataStream(&pieceData, QIODevice::ReadOnly);
- QRect square = targetSquare(event->pos());
- QPixmap pixmap;
- QPoint location;
- dataStream >> pixmap >> location;
+ Piece piece;
+ piece.rect = targetSquare(event->pos());
+ dataStream >> piece.pixmap >> piece.location;
- pieceLocations.append(location);
- piecePixmaps.append(pixmap);
- pieceRects.append(square);
+ pieces.append(piece);
highlightedRect = QRect();
- update(square);
+ update(piece.rect);
event->setDropAction(Qt::MoveAction);
event->accept();
- if (location == QPoint(square.x()/pieceSize(), square.y()/pieceSize())) {
+ if (piece.location == piece.rect.topLeft() / pieceSize()) {
inPlace++;
if (inPlace == 25)
emit puzzleCompleted();
@@ -141,21 +136,26 @@ void PuzzleWidget::dropEvent(QDropEvent *event)
}
}
+int PuzzleWidget::findPiece(const QRect &pieceRect) const
+{
+ for (int i = 0, size = pieces.size(); i < size; ++i) {
+ if (pieces.at(i).rect == pieceRect)
+ return i;
+ }
+ return -1;
+}
+
void PuzzleWidget::mousePressEvent(QMouseEvent *event)
{
QRect square = targetSquare(event->pos());
- int found = pieceRects.indexOf(square);
+ const int found = findPiece(square);
if (found == -1)
return;
- QPoint location = pieceLocations[found];
- QPixmap pixmap = piecePixmaps[found];
- pieceLocations.removeAt(found);
- piecePixmaps.removeAt(found);
- pieceRects.removeAt(found);
+ Piece piece = pieces.takeAt(found);
- if (location == QPoint(square.x()/pieceSize(), square.y()/pieceSize()))
+ if (piece.location == square.topLeft() / pieceSize())
inPlace--;
update(square);
@@ -163,7 +163,7 @@ void PuzzleWidget::mousePressEvent(QMouseEvent *event)
QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
- dataStream << pixmap << location;
+ dataStream << piece.pixmap << piece.location;
QMimeData *mimeData = new QMimeData;
mimeData->setData(PiecesList::puzzleMimeType(), itemData);
@@ -171,23 +171,20 @@ void PuzzleWidget::mousePressEvent(QMouseEvent *event)
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setHotSpot(event->pos() - square.topLeft());
- drag->setPixmap(pixmap);
+ drag->setPixmap(piece.pixmap);
- if (!(drag->exec(Qt::MoveAction) == Qt::MoveAction)) {
- pieceLocations.insert(found, location);
- piecePixmaps.insert(found, pixmap);
- pieceRects.insert(found, square);
+ if (drag->exec(Qt::MoveAction) != Qt::MoveAction) {
+ pieces.insert(found, piece);
update(targetSquare(event->pos()));
- if (location == QPoint(square.x()/pieceSize(), square.y()/pieceSize()))
+ if (piece.location == square.topLeft() / pieceSize())
inPlace++;
}
}
void PuzzleWidget::paintEvent(QPaintEvent *event)
{
- QPainter painter;
- painter.begin(this);
+ QPainter painter(this);
painter.fillRect(event->rect(), Qt::white);
if (highlightedRect.isValid()) {
@@ -196,14 +193,14 @@ void PuzzleWidget::paintEvent(QPaintEvent *event)
painter.drawRect(highlightedRect.adjusted(0, 0, -1, -1));
}
- for (int i = 0; i < pieceRects.size(); ++i)
- painter.drawPixmap(pieceRects[i], piecePixmaps[i]);
- painter.end();
+ for (const Piece &piece : pieces)
+ painter.drawPixmap(piece.rect, piece.pixmap);
}
const QRect PuzzleWidget::targetSquare(const QPoint &position) const
{
- return QRect(position.x()/pieceSize() * pieceSize(), position.y()/pieceSize() * pieceSize(), pieceSize(), pieceSize());
+ return QRect(position / pieceSize() * pieceSize(),
+ QSize(pieceSize(), pieceSize()));
}
int PuzzleWidget::pieceSize() const
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 <QList>
#include <QPoint>
#include <QPixmap>
+#include <QVector>
#include <QWidget>
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<QPixmap> piecePixmaps;
- QList<QRect> pieceRects;
- QList<QPoint> pieceLocations;
+ QVector<Piece> pieces;
QRect highlightedRect;
int inPlace;
int m_ImageSize;
diff --git a/examples/widgets/effects/blurpicker/blurpicker.cpp b/examples/widgets/effects/blurpicker/blurpicker.cpp
index 43823bed30..a00af2144a 100644
--- a/examples/widgets/effects/blurpicker/blurpicker.cpp
+++ b/examples/widgets/effects/blurpicker/blurpicker.cpp
@@ -52,13 +52,9 @@
#include <QtWidgets>
#include <QtCore/qmath.h>
-
+#include <qmath.h>
#include "blureffect.h"
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
BlurPicker::BlurPicker(QWidget *parent): QGraphicsView(parent), m_index(0.0), m_animation(this, "index")
{
setBackgroundBrush(QPixmap(":/images/background.jpg"));
@@ -84,9 +80,10 @@ void BlurPicker::setIndex(qreal index)
m_index = index;
qreal baseline = 0;
+ const qreal iconAngle = 2 * M_PI / m_icons.count();
for (int i = 0; i < m_icons.count(); ++i) {
QGraphicsItem *icon = m_icons[i];
- qreal a = ((i + m_index) * 2 * M_PI) / m_icons.count();
+ qreal a = (i + m_index) * iconAngle;
qreal xs = 170 * qSin(a);
qreal ys = 100 * qCos(a);
QPointF pos(xs, ys);
diff --git a/examples/widgets/effects/effects.pro b/examples/widgets/effects/effects.pro
index 795e0508ac..05911979b9 100644
--- a/examples/widgets/effects/effects.pro
+++ b/examples/widgets/effects/effects.pro
@@ -2,5 +2,4 @@ TEMPLATE = \
subdirs
SUBDIRS = \
blurpicker \
- lighting \
fademessage
diff --git a/examples/widgets/effects/lighting/lighting.cpp b/examples/widgets/effects/lighting/lighting.cpp
deleted file mode 100644
index 68350f32b7..0000000000
--- a/examples/widgets/effects/lighting/lighting.cpp
+++ /dev/null
@@ -1,150 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "lighting.h"
-
-#include <QtWidgets>
-#include <QtCore/qmath.h>
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
-Lighting::Lighting(QWidget *parent): QGraphicsView(parent), angle(0.0)
-{
- setScene(&m_scene);
-
- setupScene();
-
- QTimer *timer = new QTimer(this);
- connect(timer, SIGNAL(timeout()), SLOT(animate()));
- timer->setInterval(30);
- timer->start();
-
- setRenderHint(QPainter::Antialiasing, true);
- setFrameStyle(QFrame::NoFrame);
-}
-
-void Lighting::setupScene()
-{
- m_scene.setSceneRect(-300, -200, 600, 460);
-
- QLinearGradient linearGrad(QPointF(-100, -100), QPointF(100, 100));
- linearGrad.setColorAt(0, QColor(255, 255, 255));
- linearGrad.setColorAt(1, QColor(192, 192, 255));
- setBackgroundBrush(linearGrad);
-
- QRadialGradient radialGrad(30, 30, 30);
- radialGrad.setColorAt(0, Qt::yellow);
- radialGrad.setColorAt(0.2, Qt::yellow);
- radialGrad.setColorAt(1, Qt::transparent);
- QPixmap pixmap(60, 60);
- pixmap.fill(Qt::transparent);
- QPainter painter(&pixmap);
- painter.setPen(Qt::NoPen);
- painter.setBrush(radialGrad);
- painter.drawEllipse(0, 0, 60, 60);
- painter.end();
-
- m_lightSource = m_scene.addPixmap(pixmap);
- m_lightSource->setZValue(2);
-
- for (int i = -2; i < 3; ++i)
- for (int j = -2; j < 3; ++j) {
- QAbstractGraphicsShapeItem *item;
- if ((i + j) & 1)
- item = new QGraphicsEllipseItem(0, 0, 50, 50);
- else
- item = new QGraphicsRectItem(0, 0, 50, 50);
-
- item->setPen(QPen(Qt::black, 1));
- item->setBrush(QBrush(Qt::white));
- QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
- effect->setBlurRadius(8);
- item->setGraphicsEffect(effect);
- item->setZValue(1);
- item->setPos(i * 80, j * 80);
- m_scene.addItem(item);
- m_items << item;
- }
-
-
-}
-
-void Lighting::animate()
-{
- angle += (M_PI / 30);
- qreal xs = 200 * qSin(angle) - 40 + 25;
- qreal ys = 200 * qCos(angle) - 40 + 25;
- m_lightSource->setPos(xs, ys);
-
- for (int i = 0; i < m_items.size(); ++i) {
- QGraphicsItem *item = m_items.at(i);
- Q_ASSERT(item);
- QGraphicsDropShadowEffect *effect = static_cast<QGraphicsDropShadowEffect *>(item->graphicsEffect());
- Q_ASSERT(effect);
-
- QPointF delta(item->x() - xs, item->y() - ys);
- effect->setOffset(delta.toPoint() / 30);
-
- qreal dx = delta.x();
- qreal dy = delta.y();
- qreal dd = qSqrt(dx * dx + dy * dy);
- QColor color = effect->color();
- color.setAlphaF(qBound(0.4, 1 - dd / 200.0, 0.7));
- effect->setColor(color);
- }
-
- m_scene.update();
-}
-
-void Lighting::resizeEvent(QResizeEvent * /* event */)
-{
-}
diff --git a/examples/widgets/effects/lighting/lighting.h b/examples/widgets/effects/lighting/lighting.h
deleted file mode 100644
index 615824d46f..0000000000
--- a/examples/widgets/effects/lighting/lighting.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef LIGHTING_H
-#define LIGHTING_H
-
-#include <QGraphicsEffect>
-#include <QGraphicsView>
-
-class Lighting: public QGraphicsView
-{
- Q_OBJECT
-
-public:
- Lighting(QWidget *parent = 0);
-
-private slots:
- void animate();
-
-private:
- void setupScene();
-
-protected:
- void resizeEvent(QResizeEvent *event) override;
-
-private:
- qreal angle;
- QGraphicsScene m_scene;
- QGraphicsItem *m_lightSource;
- QList<QGraphicsItem*> m_items;
-};
-
-#endif // LIGHTING_H
diff --git a/examples/widgets/effects/lighting/lighting.pro b/examples/widgets/effects/lighting/lighting.pro
deleted file mode 100644
index 0a3b397de5..0000000000
--- a/examples/widgets/effects/lighting/lighting.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-QT += widgets
-
-SOURCES += main.cpp lighting.cpp
-HEADERS += lighting.h
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/effects/lighting
-INSTALLS += target
diff --git a/examples/widgets/effects/lighting/main.cpp b/examples/widgets/effects/lighting/main.cpp
deleted file mode 100644
index 22e55c0985..0000000000
--- a/examples/widgets/effects/lighting/main.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "lighting.h"
-#include <QApplication>
-
-int main(int argc, char **argv)
-{
- QApplication app(argc, argv);
-
- Lighting lighting;
- lighting.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Lighting and Shadows"));
-
- lighting.resize(640, 480);
- lighting.show();
-
- return app.exec();
-}
diff --git a/examples/widgets/gestures/imagegestures/imagegestures.pro b/examples/widgets/gestures/imagegestures/imagegestures.pro
index 0d5b2f286c..9563e5fcc3 100644
--- a/examples/widgets/gestures/imagegestures/imagegestures.pro
+++ b/examples/widgets/gestures/imagegestures/imagegestures.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
HEADERS = imagewidget.h \
mainwidget.h
diff --git a/examples/widgets/graphicsview/boxes/boxes.pro b/examples/widgets/graphicsview/boxes/boxes.pro
index afdca816b1..601edd6883 100644
--- a/examples/widgets/graphicsview/boxes/boxes.pro
+++ b/examples/widgets/graphicsview/boxes/boxes.pro
@@ -1,4 +1,5 @@
QT += opengl widgets
+requires(qtConfig(combobox))
qtConfig(opengles.|angle|dynamicgl): error("This example requires Qt to be configured with -opengl desktop")
diff --git a/examples/widgets/graphicsview/boxes/glbuffers.cpp b/examples/widgets/graphicsview/boxes/glbuffers.cpp
index 1481292e76..851cd17796 100644
--- a/examples/widgets/graphicsview/boxes/glbuffers.cpp
+++ b/examples/widgets/graphicsview/boxes/glbuffers.cpp
@@ -50,11 +50,11 @@
#include "glbuffers.h"
#include <QtGui/qmatrix4x4.h>
-
+#include <QtCore/qmath.h>
void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
{
- const GLdouble ymax = zNear * tan(fovy * M_PI / 360.0);
+ const GLdouble ymax = zNear * tan(qDegreesToRadians(fovy) / 2.0);
const GLdouble ymin = -ymax;
const GLdouble xmin = ymin * aspect;
const GLdouble xmax = ymax * aspect;
diff --git a/examples/widgets/graphicsview/boxes/qtbox.cpp b/examples/widgets/graphicsview/boxes/qtbox.cpp
index 9a19985fac..3a184dd0b6 100644
--- a/examples/widgets/graphicsview/boxes/qtbox.cpp
+++ b/examples/widgets/graphicsview/boxes/qtbox.cpp
@@ -414,7 +414,7 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
CircleItem::CircleItem(int size, int x, int y) : ItemBase(size, x, y)
{
- m_color = QColor::fromHsv(rand() % 360, 255, 255);
+ m_color = QColor::fromHsv(QRandomGenerator::global()->bounded(360), 255, 255);
}
void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp
index 9ac429c667..f51cad99ac 100644
--- a/examples/widgets/graphicsview/boxes/scene.cpp
+++ b/examples/widgets/graphicsview/boxes/scene.cpp
@@ -50,9 +50,10 @@
#include <QDebug>
#include "scene.h"
+#include <QtCore/QRandomGenerator>
#include <QtGui/qmatrix4x4.h>
#include <QtGui/qvector3d.h>
-#include <cmath>
+#include <qmath.h>
#include "3rdparty/fbm.h"
@@ -868,11 +869,12 @@ void Scene::renderCubemaps()
QVector3D center;
+ const float eachAngle = 2 * M_PI / m_cubemaps.size();
for (int i = m_frame % N; i < m_cubemaps.size(); i += N) {
if (0 == m_cubemaps[i])
continue;
- float angle = 2.0f * PI * i / m_cubemaps.size();
+ float angle = i * eachAngle;
center = m_trackBalls[1].rotation().rotatedVector(QVector3D(std::cos(angle), std::sin(angle), 0.0f));
@@ -1071,13 +1073,16 @@ void Scene::newItem(ItemDialog::ItemType type)
QSize size = sceneRect().size().toSize();
switch (type) {
case ItemDialog::QtBoxItem:
- addItem(new QtBox(64, rand() % (size.width() - 64) + 32, rand() % (size.height() - 64) + 32));
+ addItem(new QtBox(64, QRandomGenerator::global()->bounded(size.width() - 64) + 32,
+ QRandomGenerator::global()->bounded(size.height() - 64) + 32));
break;
case ItemDialog::CircleItem:
- addItem(new CircleItem(64, rand() % (size.width() - 64) + 32, rand() % (size.height() - 64) + 32));
+ addItem(new CircleItem(64, QRandomGenerator::global()->bounded(size.width() - 64) + 32,
+ QRandomGenerator::global()->bounded(size.height() - 64) + 32));
break;
case ItemDialog::SquareItem:
- addItem(new SquareItem(64, rand() % (size.width() - 64) + 32, rand() % (size.height() - 64) + 32));
+ addItem(new SquareItem(64, QRandomGenerator::global()->bounded(size.width() - 64) + 32,
+ QRandomGenerator::global()->bounded(size.height() - 64) + 32));
break;
default:
break;
diff --git a/examples/widgets/graphicsview/boxes/scene.h b/examples/widgets/graphicsview/boxes/scene.h
index a2ba1d0b5a..ccb6f368cd 100644
--- a/examples/widgets/graphicsview/boxes/scene.h
+++ b/examples/widgets/graphicsview/boxes/scene.h
@@ -63,8 +63,6 @@
#include "glbuffers.h"
#include "qtbox.h"
-#define PI 3.14159265358979
-
QT_BEGIN_NAMESPACE
class QMatrix4x4;
QT_END_NAMESPACE
diff --git a/examples/widgets/graphicsview/boxes/trackball.cpp b/examples/widgets/graphicsview/boxes/trackball.cpp
index 15f3af77d1..794ce7ac37 100644
--- a/examples/widgets/graphicsview/boxes/trackball.cpp
+++ b/examples/widgets/graphicsview/boxes/trackball.cpp
@@ -50,6 +50,7 @@
#include "trackball.h"
#include "scene.h"
+#include <qmath.h>
#include <cmath>
//============================================================================//
@@ -101,10 +102,11 @@ void TrackBall::move(const QPointF& p, const QQuaternion &transformation)
case Plane:
{
QLineF delta(m_lastPos, p);
- m_angularVelocity = 180*delta.length() / (PI*msecs);
+ const float angleDelta = qRadiansToDegrees(float(delta.length()));
+ m_angularVelocity = angleDelta / msecs;
m_axis = QVector3D(-delta.dy(), delta.dx(), 0.0f).normalized();
m_axis = transformation.rotatedVector(m_axis);
- m_rotation = QQuaternion::fromAxisAndAngle(m_axis, 180 / PI * delta.length()) * m_rotation;
+ m_rotation = QQuaternion::fromAxisAndAngle(m_axis, angleDelta) * m_rotation;
}
break;
case Sphere:
@@ -124,7 +126,7 @@ void TrackBall::move(const QPointF& p, const QQuaternion &transformation)
currentPos3D.normalize();
m_axis = QVector3D::crossProduct(lastPos3D, currentPos3D);
- float angle = 180 / PI * std::asin(std::sqrt(QVector3D::dotProduct(m_axis, m_axis)));
+ float angle = qRadiansToDegrees(std::asin(m_axis.length()));
m_angularVelocity = angle / msecs;
m_axis.normalize();
diff --git a/examples/widgets/graphicsview/collidingmice/main.cpp b/examples/widgets/graphicsview/collidingmice/main.cpp
index a0659b9bc1..91aee70b86 100644
--- a/examples/widgets/graphicsview/collidingmice/main.cpp
+++ b/examples/widgets/graphicsview/collidingmice/main.cpp
@@ -60,7 +60,6 @@ static const int MouseCount = 7;
int main(int argc, char **argv)
{
QApplication app(argc, argv);
- qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
//! [0]
//! [1]
diff --git a/examples/widgets/graphicsview/collidingmice/mouse.cpp b/examples/widgets/graphicsview/collidingmice/mouse.cpp
index b94c650c18..14f887f6e3 100644
--- a/examples/widgets/graphicsview/collidingmice/mouse.cpp
+++ b/examples/widgets/graphicsview/collidingmice/mouse.cpp
@@ -52,12 +52,12 @@
#include <QGraphicsScene>
#include <QPainter>
+#include <QRandomGenerator>
#include <QStyleOption>
+#include <qmath.h>
-#include <math.h>
-
-static const double Pi = 3.14159265358979323846264338327950288419717;
-static double TwoPi = 2.0 * Pi;
+const qreal Pi = M_PI;
+const qreal TwoPi = 2 * M_PI;
static qreal normalizeAngle(qreal angle)
{
@@ -71,9 +71,9 @@ static qreal normalizeAngle(qreal angle)
//! [0]
Mouse::Mouse()
: angle(0), speed(0), mouseEyeDirection(0),
- color(qrand() % 256, qrand() % 256, qrand() % 256)
+ color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
{
- setRotation(qrand() % (360 * 16));
+ setRotation(QRandomGenerator::global()->bounded(360 * 16));
}
//! [0]
@@ -140,9 +140,7 @@ void Mouse::advance(int step)
//! [5]
QLineF lineToCenter(QPointF(0, 0), mapFromScene(0, 0));
if (lineToCenter.length() > 150) {
- qreal angleToCenter = ::acos(lineToCenter.dx() / lineToCenter.length());
- if (lineToCenter.dy() < 0)
- angleToCenter = TwoPi - angleToCenter;
+ qreal angleToCenter = std::atan2(lineToCenter.dy(), lineToCenter.dx());
angleToCenter = normalizeAngle((Pi - angleToCenter) + Pi / 2);
if (angleToCenter < Pi && angleToCenter > Pi / 4) {
@@ -171,9 +169,7 @@ void Mouse::advance(int step)
continue;
QLineF lineToMouse(QPointF(0, 0), mapFromItem(item, 0, 0));
- qreal angleToMouse = ::acos(lineToMouse.dx() / lineToMouse.length());
- if (lineToMouse.dy() < 0)
- angleToMouse = TwoPi - angleToMouse;
+ qreal angleToMouse = std::atan2(lineToMouse.dy(), lineToMouse.dx());
angleToMouse = normalizeAngle((Pi - angleToMouse) + Pi / 2);
if (angleToMouse >= 0 && angleToMouse < Pi / 2) {
@@ -190,16 +186,16 @@ void Mouse::advance(int step)
// Add some random movement
//! [10]
- if (dangerMice.size() > 1 && (qrand() % 10) == 0) {
- if (qrand() % 1)
- angle += (qrand() % 100) / 500.0;
+ if (dangerMice.size() > 1 && QRandomGenerator::global()->bounded(10) == 0) {
+ if (QRandomGenerator::global()->bounded(1))
+ angle += QRandomGenerator::global()->bounded(1 / 500.0);
else
- angle -= (qrand() % 100) / 500.0;
+ angle -= QRandomGenerator::global()->bounded(1 / 500.0);
}
//! [10]
//! [11]
- speed += (-50 + qrand() % 100) / 100.0;
+ speed += (-50 + QRandomGenerator::global()->bounded(100)) / 100.0;
qreal dx = ::sin(angle) * 10;
mouseEyeDirection = (qAbs(dx / 5) < 1) ? 0 : dx / 5;
diff --git a/examples/widgets/graphicsview/diagramscene/arrow.cpp b/examples/widgets/graphicsview/diagramscene/arrow.cpp
index 012b9ea2ed..88160d9399 100644
--- a/examples/widgets/graphicsview/diagramscene/arrow.cpp
+++ b/examples/widgets/graphicsview/diagramscene/arrow.cpp
@@ -51,13 +51,10 @@
#include "arrow.h"
-#include <math.h>
-
+#include <qmath.h>
#include <QPen>
#include <QPainter>
-const qreal Pi = 3.14;
-
//! [0]
Arrow::Arrow(DiagramItem *startItem, DiagramItem *endItem, QGraphicsItem *parent)
: QGraphicsLineItem(parent)
@@ -132,14 +129,12 @@ void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
setLine(QLineF(intersectPoint, myStartItem->pos()));
//! [5] //! [6]
- double angle = ::acos(line().dx() / line().length());
- if (line().dy() >= 0)
- angle = (Pi * 2) - angle;
+ double angle = std::atan2(-line().dy(), line().dx());
- QPointF arrowP1 = line().p1() + QPointF(sin(angle + Pi / 3) * arrowSize,
- cos(angle + Pi / 3) * arrowSize);
- QPointF arrowP2 = line().p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize,
- cos(angle + Pi - Pi / 3) * arrowSize);
+ QPointF arrowP1 = line().p1() + QPointF(sin(angle + M_PI / 3) * arrowSize,
+ cos(angle + M_PI / 3) * arrowSize);
+ QPointF arrowP2 = line().p1() + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize,
+ cos(angle + M_PI - M_PI / 3) * arrowSize);
arrowHead.clear();
arrowHead << line().p1() << arrowP1 << arrowP2;
diff --git a/examples/widgets/graphicsview/diagramscene/diagramscene.pro b/examples/widgets/graphicsview/diagramscene/diagramscene.pro
index 7045f41d03..c19dcff3a9 100644
--- a/examples/widgets/graphicsview/diagramscene/diagramscene.pro
+++ b/examples/widgets/graphicsview/diagramscene/diagramscene.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(fontcombobox))
HEADERS = mainwindow.h \
diagramitem.h \
diff --git a/examples/widgets/graphicsview/dragdroprobot/coloritem.cpp b/examples/widgets/graphicsview/dragdroprobot/coloritem.cpp
index 64a715d31f..262e18a317 100644
--- a/examples/widgets/graphicsview/dragdroprobot/coloritem.cpp
+++ b/examples/widgets/graphicsview/dragdroprobot/coloritem.cpp
@@ -54,7 +54,7 @@
//! [0]
ColorItem::ColorItem()
- : color(qrand() % 256, qrand() % 256, qrand() % 256)
+ : color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
{
setToolTip(QString("QColor(%1, %2, %3)\n%4")
.arg(color.red()).arg(color.green()).arg(color.blue())
@@ -107,7 +107,7 @@ void ColorItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
//! [6]
static int n = 0;
- if (n++ > 2 && (qrand() % 3) == 0) {
+ if (n++ > 2 && QRandomGenerator::global()->bounded(3) == 0) {
QImage image(":/images/head.png");
mime->setImageData(image);
diff --git a/examples/widgets/graphicsview/dragdroprobot/main.cpp b/examples/widgets/graphicsview/dragdroprobot/main.cpp
index 20cec92d26..045e184569 100644
--- a/examples/widgets/graphicsview/dragdroprobot/main.cpp
+++ b/examples/widgets/graphicsview/dragdroprobot/main.cpp
@@ -73,7 +73,6 @@ int main(int argc, char **argv)
{
QApplication app(argc, argv);
- qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
//! [0]
//! [1]
QGraphicsScene scene(-200, -200, 400, 400);
diff --git a/examples/widgets/graphicsview/elasticnodes/edge.cpp b/examples/widgets/graphicsview/elasticnodes/edge.cpp
index e794e803cf..aec12b4225 100644
--- a/examples/widgets/graphicsview/elasticnodes/edge.cpp
+++ b/examples/widgets/graphicsview/elasticnodes/edge.cpp
@@ -51,13 +51,9 @@
#include "edge.h"
#include "node.h"
-#include <math.h>
-
+#include <qmath.h>
#include <QPainter>
-static const double Pi = 3.14159265358979323846264338327950288419717;
-static double TwoPi = 2.0 * Pi;
-
//! [0]
Edge::Edge(Node *sourceNode, Node *destNode)
: arrowSize(10)
@@ -139,18 +135,16 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
//! [6]
// Draw the arrows
- double angle = ::acos(line.dx() / line.length());
- if (line.dy() >= 0)
- angle = TwoPi - angle;
-
- QPointF sourceArrowP1 = sourcePoint + QPointF(sin(angle + Pi / 3) * arrowSize,
- cos(angle + Pi / 3) * arrowSize);
- QPointF sourceArrowP2 = sourcePoint + QPointF(sin(angle + Pi - Pi / 3) * arrowSize,
- cos(angle + Pi - Pi / 3) * arrowSize);
- QPointF destArrowP1 = destPoint + QPointF(sin(angle - Pi / 3) * arrowSize,
- cos(angle - Pi / 3) * arrowSize);
- QPointF destArrowP2 = destPoint + QPointF(sin(angle - Pi + Pi / 3) * arrowSize,
- cos(angle - Pi + Pi / 3) * arrowSize);
+ double angle = std::atan2(-line.dy(), line.dx());
+
+ QPointF sourceArrowP1 = sourcePoint + QPointF(sin(angle + M_PI / 3) * arrowSize,
+ cos(angle + M_PI / 3) * arrowSize);
+ QPointF sourceArrowP2 = sourcePoint + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize,
+ cos(angle + M_PI - M_PI / 3) * arrowSize);
+ QPointF destArrowP1 = destPoint + QPointF(sin(angle - M_PI / 3) * arrowSize,
+ cos(angle - M_PI / 3) * arrowSize);
+ QPointF destArrowP2 = destPoint + QPointF(sin(angle - M_PI + M_PI / 3) * arrowSize,
+ cos(angle - M_PI + M_PI / 3) * arrowSize);
painter->setBrush(Qt::black);
painter->drawPolygon(QPolygonF() << line.p1() << sourceArrowP1 << sourceArrowP2);
diff --git a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
index 844c8f8aac..4259aab803 100644
--- a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
+++ b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
@@ -55,6 +55,7 @@
#include <math.h>
#include <QKeyEvent>
+#include <QRandomGenerator>
//! [0]
GraphWidget::GraphWidget(QWidget *parent)
@@ -247,7 +248,7 @@ void GraphWidget::shuffle()
{
foreach (QGraphicsItem *item, scene()->items()) {
if (qgraphicsitem_cast<Node *>(item))
- item->setPos(-150 + qrand() % 300, -150 + qrand() % 300);
+ item->setPos(-150 + QRandomGenerator::global()->bounded(300), -150 + QRandomGenerator::global()->bounded(300));
}
}
diff --git a/examples/widgets/graphicsview/elasticnodes/main.cpp b/examples/widgets/graphicsview/elasticnodes/main.cpp
index 75cc4b0f69..1e372a9f6d 100644
--- a/examples/widgets/graphicsview/elasticnodes/main.cpp
+++ b/examples/widgets/graphicsview/elasticnodes/main.cpp
@@ -57,7 +57,6 @@
int main(int argc, char **argv)
{
QApplication app(argc, argv);
- qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
GraphWidget *widget = new GraphWidget;
diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro
index 993a5f22b7..60c507fc3d 100644
--- a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro
+++ b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(fontcombobox))
SOURCES += main.cpp
SOURCES += customproxy.cpp embeddeddialog.cpp
diff --git a/examples/widgets/graphicsview/padnavigator/padnavigator.pro b/examples/widgets/graphicsview/padnavigator/padnavigator.pro
index c2bc79b5cc..53a57c85d7 100644
--- a/examples/widgets/graphicsview/padnavigator/padnavigator.pro
+++ b/examples/widgets/graphicsview/padnavigator/padnavigator.pro
@@ -17,6 +17,7 @@ FORMS += \
form.ui
QT += widgets
+requires(qtConfig(treewidget))
qtHaveModule(opengl): QT += opengl
# install
diff --git a/examples/widgets/itemviews/addressbook/addressbook.pro b/examples/widgets/itemviews/addressbook/addressbook.pro
index 5e2f1bcbbc..498b2574ce 100644
--- a/examples/widgets/itemviews/addressbook/addressbook.pro
+++ b/examples/widgets/itemviews/addressbook/addressbook.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(listview))
SOURCES = adddialog.cpp \
addresswidget.cpp \
diff --git a/examples/widgets/itemviews/addressbook/addresswidget.cpp b/examples/widgets/itemviews/addressbook/addresswidget.cpp
index cff35ad78f..143f6266dd 100644
--- a/examples/widgets/itemviews/addressbook/addresswidget.cpp
+++ b/examples/widgets/itemviews/addressbook/addresswidget.cpp
@@ -85,10 +85,7 @@ void AddressWidget::showAddEntryDialog()
//! [3]
void AddressWidget::addEntry(QString name, QString address)
{
- QList<QPair<QString, QString> >list = table->getList();
- QPair<QString, QString> pair(name, address);
-
- if (!list.contains(pair)) {
+ if (!table->getContacts().contains({ name, address })) {
table->insertRows(0, 1, QModelIndex());
QModelIndex index = table->index(0, 0, QModelIndex());
@@ -195,6 +192,12 @@ void AddressWidget::setupTabs()
&QItemSelectionModel::selectionChanged,
this, &AddressWidget::selectionChanged);
+ connect(this, &QTabWidget::currentChanged, this, [this](int tabIndex) {
+ auto *tableView = qobject_cast<QTableView *>(widget(tabIndex));
+ if (tableView)
+ emit selectionChanged(tableView->selectionModel()->selection());
+ });
+
addTab(tableView, str);
}
}
@@ -211,18 +214,16 @@ void AddressWidget::readFromFile(const QString &fileName)
return;
}
- QList<QPair<QString, QString> > pairs = table->getList();
+ QList<Contact> contacts;
QDataStream in(&file);
- in >> pairs;
+ in >> contacts;
- if (pairs.isEmpty()) {
+ if (contacts.isEmpty()) {
QMessageBox::information(this, tr("No contacts in file"),
tr("The file you are attempting to open contains no contacts."));
} else {
- for (int i=0; i<pairs.size(); ++i) {
- QPair<QString, QString> p = pairs.at(i);
- addEntry(p.first, p.second);
- }
+ for (const auto &contact: qAsConst(contacts))
+ addEntry(contact.name, contact.address);
}
}
//! [7]
@@ -237,8 +238,7 @@ void AddressWidget::writeToFile(const QString &fileName)
return;
}
- QList<QPair<QString, QString> > pairs = table->getList();
QDataStream out(&file);
- out << pairs;
+ out << table->getContacts();
}
//! [6]
diff --git a/examples/widgets/itemviews/addressbook/tablemodel.cpp b/examples/widgets/itemviews/addressbook/tablemodel.cpp
index d701ef3223..674e312753 100644
--- a/examples/widgets/itemviews/addressbook/tablemodel.cpp
+++ b/examples/widgets/itemviews/addressbook/tablemodel.cpp
@@ -56,10 +56,10 @@ TableModel::TableModel(QObject *parent)
{
}
-TableModel::TableModel(QList<QPair<QString, QString> > pairs, QObject *parent)
+TableModel::TableModel(QList<Contact> contacts, QObject *parent)
: QAbstractTableModel(parent)
+ , contacts(contacts)
{
- listOfPairs = pairs;
}
//! [0]
@@ -67,7 +67,7 @@ TableModel::TableModel(QList<QPair<QString, QString> > pairs, QObject *parent)
int TableModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
- return listOfPairs.size();
+ return contacts.size();
}
int TableModel::columnCount(const QModelIndex &parent) const
@@ -83,16 +83,16 @@ QVariant TableModel::data(const QModelIndex &index, int role) const
if (!index.isValid())
return QVariant();
- if (index.row() >= listOfPairs.size() || index.row() < 0)
+ if (index.row() >= contacts.size() || index.row() < 0)
return QVariant();
if (role == Qt::DisplayRole) {
- QPair<QString, QString> pair = listOfPairs.at(index.row());
+ const auto &contact = contacts.at(index.row());
if (index.column() == 0)
- return pair.first;
+ return contact.name;
else if (index.column() == 1)
- return pair.second;
+ return contact.address;
}
return QVariant();
}
@@ -126,10 +126,8 @@ bool TableModel::insertRows(int position, int rows, const QModelIndex &index)
Q_UNUSED(index);
beginInsertRows(QModelIndex(), position, position + rows - 1);
- for (int row = 0; row < rows; ++row) {
- QPair<QString, QString> pair(" ", " ");
- listOfPairs.insert(position, pair);
- }
+ for (int row = 0; row < rows; ++row)
+ contacts.insert(position, { QString(), QString() });
endInsertRows();
return true;
@@ -142,9 +140,8 @@ bool TableModel::removeRows(int position, int rows, const QModelIndex &index)
Q_UNUSED(index);
beginRemoveRows(QModelIndex(), position, position + rows - 1);
- for (int row = 0; row < rows; ++row) {
- listOfPairs.removeAt(position);
- }
+ for (int row = 0; row < rows; ++row)
+ contacts.removeAt(position);
endRemoveRows();
return true;
@@ -157,16 +154,16 @@ bool TableModel::setData(const QModelIndex &index, const QVariant &value, int ro
if (index.isValid() && role == Qt::EditRole) {
int row = index.row();
- QPair<QString, QString> p = listOfPairs.value(row);
+ auto contact = contacts.value(row);
if (index.column() == 0)
- p.first = value.toString();
+ contact.name = value.toString();
else if (index.column() == 1)
- p.second = value.toString();
+ contact.address = value.toString();
else
return false;
- listOfPairs.replace(row, p);
+ contacts.replace(row, contact);
emit(dataChanged(index, index));
return true;
@@ -187,8 +184,8 @@ Qt::ItemFlags TableModel::flags(const QModelIndex &index) const
//! [7]
//! [8]
-QList< QPair<QString, QString> > TableModel::getList()
+QList<Contact> TableModel::getContacts() const
{
- return listOfPairs;
+ return contacts;
}
//! [8]
diff --git a/examples/widgets/itemviews/addressbook/tablemodel.h b/examples/widgets/itemviews/addressbook/tablemodel.h
index 9a669c508d..1004a35d31 100644
--- a/examples/widgets/itemviews/addressbook/tablemodel.h
+++ b/examples/widgets/itemviews/addressbook/tablemodel.h
@@ -53,16 +53,37 @@
#include <QAbstractTableModel>
#include <QList>
-#include <QPair>
//! [0]
+
+struct Contact
+{
+ QString name;
+ QString address;
+
+ bool operator==(const Contact &other) const
+ {
+ return name == other.name && address == other.address;
+ }
+};
+
+inline QDataStream &operator<<(QDataStream &stream, const Contact &contact)
+{
+ return stream << contact.name << contact.address;
+}
+
+inline QDataStream &operator>>(QDataStream &stream, Contact &contact)
+{
+ return stream >> contact.name >> contact.address;
+}
+
class TableModel : public QAbstractTableModel
{
Q_OBJECT
public:
TableModel(QObject *parent = 0);
- TableModel(QList<QPair<QString, QString> > listofPairs, QObject *parent = 0);
+ TableModel(QList<Contact> contacts, QObject *parent = 0);
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
@@ -72,10 +93,10 @@ public:
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()) override;
bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()) override;
- QList<QPair<QString, QString> > getList();
+ QList<Contact> getContacts() const;
private:
- QList<QPair<QString, QString> > listOfPairs;
+ QList<Contact> contacts;
};
//! [0]
diff --git a/examples/widgets/itemviews/basicsortfiltermodel/basicsortfiltermodel.pro b/examples/widgets/itemviews/basicsortfiltermodel/basicsortfiltermodel.pro
index 2469a4ef20..c8087666fe 100644
--- a/examples/widgets/itemviews/basicsortfiltermodel/basicsortfiltermodel.pro
+++ b/examples/widgets/itemviews/basicsortfiltermodel/basicsortfiltermodel.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = window.h
SOURCES = main.cpp \
diff --git a/examples/widgets/itemviews/chart/chart.pro b/examples/widgets/itemviews/chart/chart.pro
index 4b64b01e8a..323f6202e4 100644
--- a/examples/widgets/itemviews/chart/chart.pro
+++ b/examples/widgets/itemviews/chart/chart.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
HEADERS = mainwindow.h \
pieview.h
diff --git a/examples/widgets/itemviews/chart/pieview.cpp b/examples/widgets/itemviews/chart/pieview.cpp
index fb439fae67..3f85e397ee 100644
--- a/examples/widgets/itemviews/chart/pieview.cpp
+++ b/examples/widgets/itemviews/chart/pieview.cpp
@@ -49,12 +49,8 @@
****************************************************************************/
#include <QtWidgets>
+#include <qmath.h>
#include <cmath>
-
-#ifndef M_PI
-#define M_PI 3.1415927
-#endif
-
#include "pieview.h"
PieView::PieView(QWidget *parent)
@@ -125,9 +121,9 @@ QModelIndex PieView::indexAt(const QPoint &point) const
return QModelIndex();
// Determine the angle of the point.
- double angle = (180 / M_PI) * std::acos(cx / d);
- if (cy < 0)
- angle = 360 - angle;
+ double angle = qRadiansToDegrees(std::atan2(cy, cx));
+ if (angle < 0)
+ angle = 360 + angle;
// Find the relevant slice of the pie.
double startAngle = 0.0;
diff --git a/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro b/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro
index 82cb264ddd..2d16ab5e2b 100644
--- a/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro
+++ b/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = colorlisteditor.h \
window.h
diff --git a/examples/widgets/itemviews/combowidgetmapper/combowidgetmapper.pro b/examples/widgets/itemviews/combowidgetmapper/combowidgetmapper.pro
index 37f82fa5ae..a5bbc2abe0 100644
--- a/examples/widgets/itemviews/combowidgetmapper/combowidgetmapper.pro
+++ b/examples/widgets/itemviews/combowidgetmapper/combowidgetmapper.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = window.h
SOURCES = main.cpp \
diff --git a/examples/widgets/itemviews/customsortfiltermodel/customsortfiltermodel.pro b/examples/widgets/itemviews/customsortfiltermodel/customsortfiltermodel.pro
index 630beddcb8..60fd94103d 100644
--- a/examples/widgets/itemviews/customsortfiltermodel/customsortfiltermodel.pro
+++ b/examples/widgets/itemviews/customsortfiltermodel/customsortfiltermodel.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(treeview))
HEADERS = mysortfilterproxymodel.h \
window.h \
diff --git a/examples/widgets/itemviews/dirview/dirview.pro b/examples/widgets/itemviews/dirview/dirview.pro
index 511ec0ed98..981a64a7d6 100644
--- a/examples/widgets/itemviews/dirview/dirview.pro
+++ b/examples/widgets/itemviews/dirview/dirview.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(treeview))
SOURCES = main.cpp
diff --git a/examples/widgets/itemviews/editabletreemodel/editabletreemodel.pro b/examples/widgets/itemviews/editabletreemodel/editabletreemodel.pro
index a6c1e5563f..a157a90761 100644
--- a/examples/widgets/itemviews/editabletreemodel/editabletreemodel.pro
+++ b/examples/widgets/itemviews/editabletreemodel/editabletreemodel.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(treeview))
FORMS = mainwindow.ui
HEADERS = mainwindow.h \
diff --git a/examples/widgets/itemviews/fetchmore/fetchmore.pro b/examples/widgets/itemviews/fetchmore/fetchmore.pro
index eb4275da19..164033f0a2 100644
--- a/examples/widgets/itemviews/fetchmore/fetchmore.pro
+++ b/examples/widgets/itemviews/fetchmore/fetchmore.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(listview))
HEADERS = filelistmodel.h \
window.h
diff --git a/examples/widgets/itemviews/frozencolumn/frozencolumn.pro b/examples/widgets/itemviews/frozencolumn/frozencolumn.pro
index 717ba40a9d..cf7a9eecac 100644
--- a/examples/widgets/itemviews/frozencolumn/frozencolumn.pro
+++ b/examples/widgets/itemviews/frozencolumn/frozencolumn.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(tableview))
HEADERS += freezetablewidget.h
SOURCES += main.cpp freezetablewidget.cpp
diff --git a/examples/widgets/itemviews/interview/interview.pro b/examples/widgets/itemviews/interview/interview.pro
index 0e480e939c..6d64f23eb9 100644
--- a/examples/widgets/itemviews/interview/interview.pro
+++ b/examples/widgets/itemviews/interview/interview.pro
@@ -1,5 +1,6 @@
TEMPLATE = app
QT += widgets
+requires(qtConfig(treeview))
HEADERS += model.h
SOURCES += model.cpp main.cpp
diff --git a/examples/widgets/itemviews/pixelator/pixelator.pro b/examples/widgets/itemviews/pixelator/pixelator.pro
index 35176a6026..421f626e28 100644
--- a/examples/widgets/itemviews/pixelator/pixelator.pro
+++ b/examples/widgets/itemviews/pixelator/pixelator.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(tableview))
qtHaveModule(printsupport): QT += printsupport
HEADERS = imagemodel.h \
diff --git a/examples/widgets/itemviews/puzzle/main.cpp b/examples/widgets/itemviews/puzzle/main.cpp
index 1f5e7ee9b2..d013bf078d 100644
--- a/examples/widgets/itemviews/puzzle/main.cpp
+++ b/examples/widgets/itemviews/puzzle/main.cpp
@@ -58,7 +58,7 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
MainWindow window;
- window.loadImage(":/images/example.jpg");
+ window.loadImage(QStringLiteral(":/images/example.jpg"));
window.show();
return app.exec();
}
diff --git a/examples/widgets/itemviews/puzzle/mainwindow.cpp b/examples/widgets/itemviews/puzzle/mainwindow.cpp
index 282a7b477b..d598dc9017 100644
--- a/examples/widgets/itemviews/puzzle/mainwindow.cpp
+++ b/examples/widgets/itemviews/puzzle/mainwindow.cpp
@@ -69,12 +69,19 @@ MainWindow::MainWindow(QWidget *parent)
void MainWindow::openImage()
{
- const QString fileName =
- QFileDialog::getOpenFileName(this,
- tr("Open Image"), QString(),
- tr("Image Files (*.png *.jpg *.bmp)"));
- if (!fileName.isEmpty())
- loadImage(fileName);
+ const QString directory =
+ QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).value(0, QDir::homePath());
+ QFileDialog dialog(this, tr("Open Image"), directory);
+ dialog.setAcceptMode(QFileDialog::AcceptOpen);
+ dialog.setFileMode(QFileDialog::ExistingFile);
+ QStringList mimeTypeFilters;
+ for (const QByteArray &mimeTypeName : QImageReader::supportedMimeTypes())
+ mimeTypeFilters.append(mimeTypeName);
+ mimeTypeFilters.sort();
+ dialog.setMimeTypeFilters(mimeTypeFilters);
+ dialog.selectMimeTypeFilter("image/jpeg");
+ if (dialog.exec() == QDialog::Accepted)
+ loadImage(dialog.selectedFiles().constFirst());
}
void MainWindow::loadImage(const QString &fileName)
@@ -83,7 +90,7 @@ void MainWindow::loadImage(const QString &fileName)
if (!newImage.load(fileName)) {
QMessageBox::warning(this, tr("Open Image"),
tr("The image file could not be loaded."),
- QMessageBox::Cancel);
+ QMessageBox::Close);
return;
}
puzzleImage = newImage;
@@ -107,8 +114,6 @@ void MainWindow::setupPuzzle()
(puzzleImage.height() - size) / 2, size, size).scaled(puzzleWidget->imageSize(),
puzzleWidget->imageSize(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
- qsrand(QCursor::pos().x() ^ QCursor::pos().y());
-
model->addPieces(puzzleImage);
puzzleWidget->clear();
}
@@ -117,19 +122,15 @@ void MainWindow::setupMenus()
{
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
- QAction *openAction = fileMenu->addAction(tr("&Open..."));
+ QAction *openAction = fileMenu->addAction(tr("&Open..."), this, &MainWindow::openImage);
openAction->setShortcuts(QKeySequence::Open);
- QAction *exitAction = fileMenu->addAction(tr("E&xit"));
+ QAction *exitAction = fileMenu->addAction(tr("E&xit"), qApp, &QCoreApplication::quit);
exitAction->setShortcuts(QKeySequence::Quit);
QMenu *gameMenu = menuBar()->addMenu(tr("&Game"));
- QAction *restartAction = gameMenu->addAction(tr("&Restart"));
-
- connect(openAction, &QAction::triggered, this, &MainWindow::openImage);
- connect(exitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
- connect(restartAction, &QAction::triggered, this, &MainWindow::setupPuzzle);
+ gameMenu->addAction(tr("&Restart"), this, &MainWindow::setupPuzzle);
}
void MainWindow::setupWidgets()
diff --git a/examples/widgets/itemviews/puzzle/mainwindow.h b/examples/widgets/itemviews/puzzle/mainwindow.h
index 7e27dc6f3a..208d3a5281 100644
--- a/examples/widgets/itemviews/puzzle/mainwindow.h
+++ b/examples/widgets/itemviews/puzzle/mainwindow.h
@@ -65,7 +65,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow(QWidget *parent = 0);
+ explicit MainWindow(QWidget *parent = nullptr);
public slots:
void openImage();
diff --git a/examples/widgets/itemviews/puzzle/piecesmodel.cpp b/examples/widgets/itemviews/puzzle/piecesmodel.cpp
index 0fbf0cdcc2..f0649d3776 100644
--- a/examples/widgets/itemviews/puzzle/piecesmodel.cpp
+++ b/examples/widgets/itemviews/puzzle/piecesmodel.cpp
@@ -52,6 +52,7 @@
#include <QIcon>
#include <QMimeData>
+#include <QRandomGenerator>
PiecesModel::PiecesModel(int pieceSize, QObject *parent)
: QAbstractListModel(parent), m_PieceSize(pieceSize)
@@ -77,7 +78,7 @@ QVariant PiecesModel::data(const QModelIndex &index, int role) const
void PiecesModel::addPiece(const QPixmap &pixmap, const QPoint &location)
{
int row;
- if (int(2.0 * qrand() / (RAND_MAX + 1.0)) == 1)
+ if (QRandomGenerator::global()->bounded(2) == 1)
row = 0;
else
row = pixmaps.size();
diff --git a/examples/widgets/itemviews/puzzle/puzzle.pro b/examples/widgets/itemviews/puzzle/puzzle.pro
index 55f1d7e709..dcc27aae6a 100644
--- a/examples/widgets/itemviews/puzzle/puzzle.pro
+++ b/examples/widgets/itemviews/puzzle/puzzle.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(listview))
HEADERS = mainwindow.h \
piecesmodel.h \
diff --git a/examples/widgets/itemviews/puzzle/puzzlewidget.cpp b/examples/widgets/itemviews/puzzle/puzzlewidget.cpp
index 78931a95a3..06968da80f 100644
--- a/examples/widgets/itemviews/puzzle/puzzlewidget.cpp
+++ b/examples/widgets/itemviews/puzzle/puzzlewidget.cpp
@@ -62,9 +62,7 @@ PuzzleWidget::PuzzleWidget(int imageSize, QWidget *parent)
void PuzzleWidget::clear()
{
- pieceLocations.clear();
- piecePixmaps.clear();
- pieceRects.clear();
+ pieces.clear();
highlightedRect = QRect();
inPlace = 0;
update();
@@ -110,23 +108,20 @@ void PuzzleWidget::dropEvent(QDropEvent *event)
&& findPiece(targetSquare(event->pos())) == -1) {
QByteArray pieceData = event->mimeData()->data("image/x-puzzle-piece");
- QDataStream stream(&pieceData, QIODevice::ReadOnly);
- QRect square = targetSquare(event->pos());
- QPixmap pixmap;
- QPoint location;
- stream >> pixmap >> location;
+ QDataStream dataStream(&pieceData, QIODevice::ReadOnly);
+ Piece piece;
+ piece.rect = targetSquare(event->pos());
+ dataStream >> piece.pixmap >> piece.location;
- pieceLocations.append(location);
- piecePixmaps.append(pixmap);
- pieceRects.append(square);
+ pieces.append(piece);
highlightedRect = QRect();
- update(square);
+ update(piece.rect);
event->setDropAction(Qt::MoveAction);
event->accept();
- if (location == QPoint(square.x()/pieceSize(), square.y()/pieceSize())) {
+ if (piece.location == piece.rect.topLeft() / pieceSize()) {
inPlace++;
if (inPlace == 25)
emit puzzleCompleted();
@@ -139,8 +134,8 @@ void PuzzleWidget::dropEvent(QDropEvent *event)
int PuzzleWidget::findPiece(const QRect &pieceRect) const
{
- for (int i = 0; i < pieceRects.size(); ++i) {
- if (pieceRect == pieceRects[i])
+ for (int i = 0, size = pieces.size(); i < size; ++i) {
+ if (pieces.at(i).rect == pieceRect)
return i;
}
return -1;
@@ -154,13 +149,9 @@ void PuzzleWidget::mousePressEvent(QMouseEvent *event)
if (found == -1)
return;
- QPoint location = pieceLocations[found];
- QPixmap pixmap = piecePixmaps[found];
- pieceLocations.removeAt(found);
- piecePixmaps.removeAt(found);
- pieceRects.removeAt(found);
+ Piece piece = pieces.takeAt(found);
- if (location == QPoint(square.x()/pieceSize(), square.y()/pieceSize()))
+ if (piece.location == square.topLeft() / pieceSize())
inPlace--;
update(square);
@@ -168,7 +159,7 @@ void PuzzleWidget::mousePressEvent(QMouseEvent *event)
QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
- dataStream << pixmap << location;
+ dataStream << piece.pixmap << piece.location;
QMimeData *mimeData = new QMimeData;
mimeData->setData("image/x-puzzle-piece", itemData);
@@ -176,23 +167,20 @@ void PuzzleWidget::mousePressEvent(QMouseEvent *event)
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setHotSpot(event->pos() - square.topLeft());
- drag->setPixmap(pixmap);
+ drag->setPixmap(piece.pixmap);
- if (drag->start(Qt::MoveAction) == 0) {
- pieceLocations.insert(found, location);
- piecePixmaps.insert(found, pixmap);
- pieceRects.insert(found, square);
+ if (drag->start(Qt::MoveAction) == Qt::IgnoreAction) {
+ pieces.insert(found, piece);
update(targetSquare(event->pos()));
- if (location == QPoint(square.x()/pieceSize(), square.y()/pieceSize()))
+ if (piece.location == QPoint(square.x() / pieceSize(), square.y() / pieceSize()))
inPlace++;
}
}
void PuzzleWidget::paintEvent(QPaintEvent *event)
{
- QPainter painter;
- painter.begin(this);
+ QPainter painter(this);
painter.fillRect(event->rect(), Qt::white);
if (highlightedRect.isValid()) {
@@ -201,15 +189,14 @@ void PuzzleWidget::paintEvent(QPaintEvent *event)
painter.drawRect(highlightedRect.adjusted(0, 0, -1, -1));
}
- for (int i = 0; i < pieceRects.size(); ++i) {
- painter.drawPixmap(pieceRects[i], piecePixmaps[i]);
- }
- painter.end();
+ for (const Piece &piece : pieces)
+ painter.drawPixmap(piece.rect, piece.pixmap);
}
const QRect PuzzleWidget::targetSquare(const QPoint &position) const
{
- return QRect(position.x()/pieceSize() * pieceSize(), position.y()/pieceSize() * pieceSize(), pieceSize(), pieceSize());
+ return QRect(position / pieceSize() * pieceSize(),
+ QSize(pieceSize(), pieceSize()));
}
int PuzzleWidget::pieceSize() const
diff --git a/examples/widgets/itemviews/puzzle/puzzlewidget.h b/examples/widgets/itemviews/puzzle/puzzlewidget.h
index 137e0b7162..40dd654af6 100644
--- a/examples/widgets/itemviews/puzzle/puzzlewidget.h
+++ b/examples/widgets/itemviews/puzzle/puzzlewidget.h
@@ -51,9 +51,9 @@
#ifndef PUZZLEWIDGET_H
#define PUZZLEWIDGET_H
-#include <QList>
-#include <QPixmap>
#include <QPoint>
+#include <QPixmap>
+#include <QVector>
#include <QWidget>
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,12 +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<QPixmap> piecePixmaps;
- QList<QRect> pieceRects;
- QList<QPoint> pieceLocations;
+ QVector<Piece> pieces;
QRect highlightedRect;
int inPlace;
int m_ImageSize;
diff --git a/examples/widgets/itemviews/simpledommodel/simpledommodel.pro b/examples/widgets/itemviews/simpledommodel/simpledommodel.pro
index db15632ba9..3d45920e36 100644
--- a/examples/widgets/itemviews/simpledommodel/simpledommodel.pro
+++ b/examples/widgets/itemviews/simpledommodel/simpledommodel.pro
@@ -6,6 +6,7 @@ SOURCES = domitem.cpp \
main.cpp \
mainwindow.cpp
QT += xml widgets
+requires(qtConfig(filedialog))
# install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/simpledommodel
diff --git a/examples/widgets/itemviews/simpletreemodel/simpletreemodel.pro b/examples/widgets/itemviews/simpletreemodel/simpletreemodel.pro
index 82484c9971..41afb54382 100644
--- a/examples/widgets/itemviews/simpletreemodel/simpletreemodel.pro
+++ b/examples/widgets/itemviews/simpletreemodel/simpletreemodel.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(treeview))
HEADERS = treeitem.h \
treemodel.h
diff --git a/examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.pro b/examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.pro
index 1d5cca3f01..f86a16bd3f 100644
--- a/examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.pro
+++ b/examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(datawidgetmapper))
HEADERS = window.h
SOURCES = main.cpp \
diff --git a/examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.pro b/examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.pro
index d0430d8470..2a6fed223a 100644
--- a/examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.pro
+++ b/examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(tableview))
HEADERS = delegate.h
SOURCES = delegate.cpp \
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheet.pro b/examples/widgets/itemviews/spreadsheet/spreadsheet.pro
index 56f7424a93..afdf9d9d7a 100644
--- a/examples/widgets/itemviews/spreadsheet/spreadsheet.pro
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheet.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(treeview))
qtHaveModule(printsupport): QT += printsupport
#unix:qtHaveModule(dbus): QT += dbus widgets
diff --git a/examples/widgets/itemviews/stardelegate/stardelegate.pro b/examples/widgets/itemviews/stardelegate/stardelegate.pro
index 95d1367fbb..7e8f252e16 100644
--- a/examples/widgets/itemviews/stardelegate/stardelegate.pro
+++ b/examples/widgets/itemviews/stardelegate/stardelegate.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(tablewidget))
HEADERS = stardelegate.h \
stareditor.h \
diff --git a/examples/widgets/itemviews/storageview/main.cpp b/examples/widgets/itemviews/storageview/main.cpp
index c8057186fc..f349e58fad 100644
--- a/examples/widgets/itemviews/storageview/main.cpp
+++ b/examples/widgets/itemviews/storageview/main.cpp
@@ -51,6 +51,7 @@
#include <QtWidgets/QApplication>
#include <QtWidgets/QHeaderView>
+#include <QtWidgets/QShortcut>
#include <QtWidgets/QTreeView>
#include "storagemodel.h"
@@ -60,9 +61,16 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);
QTreeView view;
- view.setModel(new StorageModel(&view));
view.resize(640, 480);
+ view.setWindowTitle("Storage View");
view.setSelectionBehavior(QAbstractItemView::SelectRows);
+
+ StorageModel *model = new StorageModel(&view);
+ model->refresh();
+ QShortcut *refreshShortcut = new QShortcut(Qt::CTRL + Qt::Key_R, &view);
+ QObject::connect(refreshShortcut, &QShortcut::activated, model, &StorageModel::refresh);
+ view.setModel(model);
+
int columnCount = view.model()->columnCount();
for (int c = 0; c < columnCount; ++c)
view.resizeColumnToContents(c);
diff --git a/examples/widgets/itemviews/storageview/storagemodel.cpp b/examples/widgets/itemviews/storageview/storagemodel.cpp
index b7c594f8f7..063f126d86 100644
--- a/examples/widgets/itemviews/storageview/storagemodel.cpp
+++ b/examples/widgets/itemviews/storageview/storagemodel.cpp
@@ -52,29 +52,27 @@
#include "storagemodel.h"
#include <QDir>
+#include <QLocale>
#include <qmath.h>
+#include <algorithm>
#include <cmath>
-static QString sizeToString(qint64 size)
+StorageModel::StorageModel(QObject *parent) :
+ QAbstractTableModel(parent)
{
- static const char *const strings[] = { "b", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
-
- if (size <= 0)
- return StorageModel::tr("0 b");
-
- double power = std::log((double)size)/std::log(1024.0);
- int intPower = (int)power;
- intPower = intPower >= 8 ? 8 - 1 : intPower;
-
- double normSize = size / std::pow(1024.0, intPower);
- //: this should expand to "1.23 GB"
- return StorageModel::tr("%1 %2").arg(normSize, 0, 'f', intPower > 0 ? 2 : 0).arg(strings[intPower]);
}
-StorageModel::StorageModel(QObject *parent) :
- QAbstractTableModel(parent),
- m_volumes(QStorageInfo::mountedVolumes())
+void StorageModel::refresh()
{
+ beginResetModel();
+ m_volumes = QStorageInfo::mountedVolumes();
+ std::sort(m_volumes.begin(), m_volumes.end(),
+ [](const QStorageInfo &st1, const QStorageInfo &st2) {
+ static const QString rootSortString = QStringLiteral(" ");
+ return (st1.isRoot() ? rootSortString : st1.rootPath())
+ < (st2.isRoot() ? rootSortString : st2.rootPath());
+ });
+ endResetModel();
}
int StorageModel::columnCount(const QModelIndex &/*parent*/) const
@@ -89,6 +87,22 @@ int StorageModel::rowCount(const QModelIndex &parent) const
return m_volumes.count();
}
+Qt::ItemFlags StorageModel::flags(const QModelIndex &index) const
+{
+ Qt::ItemFlags result = QAbstractTableModel::flags(index);
+ switch (index.column()) {
+ case ColumnAvailable:
+ case ColumnIsReady:
+ case ColumnIsReadOnly:
+ case ColumnIsValid:
+ result |= Qt::ItemIsUserCheckable;
+ break;
+ default:
+ break;
+ }
+ return result;
+}
+
QVariant StorageModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
@@ -106,11 +120,17 @@ QVariant StorageModel::data(const QModelIndex &index, int role) const
case ColumnFileSystemName:
return volume.fileSystemType();
case ColumnTotal:
- return sizeToString(volume.bytesTotal());
+ return QLocale().formattedDataSize(volume.bytesTotal());
case ColumnFree:
- return sizeToString(volume.bytesFree());
+ return QLocale().formattedDataSize(volume.bytesFree());
case ColumnAvailable:
- return sizeToString(volume.bytesAvailable());
+ return QLocale().formattedDataSize(volume.bytesAvailable());
+ default:
+ break;
+ }
+ } else if (role == Qt::CheckStateRole) {
+ const QStorageInfo &volume = m_volumes.at(index.row());
+ switch (index.column()) {
case ColumnIsReady:
return volume.isReady();
case ColumnIsReadOnly:
@@ -120,7 +140,18 @@ QVariant StorageModel::data(const QModelIndex &index, int role) const
default:
break;
}
+ } else if (role == Qt::TextAlignmentRole) {
+ switch (index.column()) {
+ case ColumnTotal:
+ case ColumnFree:
+ case ColumnAvailable:
+ return Qt::AlignTrailing;
+ default:
+ break;
+ }
+ return Qt::AlignLeading;
} else if (role == Qt::ToolTipRole) {
+ QLocale locale;
const QStorageInfo &volume = m_volumes.at(index.row());
return tr("Root path : %1\n"
"Name: %2\n"
@@ -140,9 +171,9 @@ QVariant StorageModel::data(const QModelIndex &index, int role) const
arg(volume.displayName()).
arg(QString::fromUtf8(volume.device())).
arg(QString::fromUtf8(volume.fileSystemType())).
- arg(sizeToString(volume.bytesTotal())).
- arg(sizeToString(volume.bytesFree())).
- arg(sizeToString(volume.bytesAvailable())).
+ arg(locale.formattedDataSize(volume.bytesTotal())).
+ arg(locale.formattedDataSize(volume.bytesFree())).
+ arg(locale.formattedDataSize(volume.bytesAvailable())).
arg(volume.isReady() ? tr("true") : tr("false")).
arg(volume.isReadOnly() ? tr("true") : tr("false")).
arg(volume.isValid() ? tr("true") : tr("false")).
@@ -161,13 +192,13 @@ QVariant StorageModel::headerData(int section, Qt::Orientation orientation, int
switch (section) {
case ColumnRootPath:
- return tr("Root path");
+ return tr("Root Path");
case ColumnName:
return tr("Volume Name");
case ColumnDevice:
return tr("Device");
case ColumnFileSystemName:
- return tr("File system");
+ return tr("File System");
case ColumnTotal:
return tr("Total");
case ColumnFree:
diff --git a/examples/widgets/itemviews/storageview/storagemodel.h b/examples/widgets/itemviews/storageview/storagemodel.h
index 2b37414d8d..787b2f04de 100644
--- a/examples/widgets/itemviews/storageview/storagemodel.h
+++ b/examples/widgets/itemviews/storageview/storagemodel.h
@@ -74,13 +74,17 @@ public:
ColumnCount
};
- explicit StorageModel(QObject *parent = 0);
+ explicit StorageModel(QObject *parent = nullptr);
- int columnCount(const QModelIndex &parent) const;
- int rowCount(const QModelIndex &parent) const;
+ int columnCount(const QModelIndex &parent) const override;
+ int rowCount(const QModelIndex &parent) const override;
- QVariant data(const QModelIndex &index, int role) const;
- QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+ QVariant data(const QModelIndex &index, int role) const override;
+ Qt::ItemFlags flags(const QModelIndex &index) const override;
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
+
+public slots:
+ void refresh();
private:
QList<QStorageInfo> m_volumes;
diff --git a/examples/widgets/itemviews/storageview/storageview.pro b/examples/widgets/itemviews/storageview/storageview.pro
index 07e7fb5145..2fdb78e7b8 100644
--- a/examples/widgets/itemviews/storageview/storageview.pro
+++ b/examples/widgets/itemviews/storageview/storageview.pro
@@ -1,4 +1,5 @@
QT += core gui widgets
+requires(qtConfig(treeview))
TARGET = storageview
TEMPLATE = app
SOURCES += storagemodel.cpp \
diff --git a/examples/widgets/layouts/basiclayouts/basiclayouts.pro b/examples/widgets/layouts/basiclayouts/basiclayouts.pro
index 0ff1347743..3df4a63b20 100644
--- a/examples/widgets/layouts/basiclayouts/basiclayouts.pro
+++ b/examples/widgets/layouts/basiclayouts/basiclayouts.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = dialog.h
SOURCES = dialog.cpp \
diff --git a/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.pro b/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.pro
index c2ca53546c..dcd4288698 100644
--- a/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.pro
+++ b/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = dialog.h
SOURCES = dialog.cpp \
diff --git a/examples/widgets/mainwindows/application/application.pro b/examples/widgets/mainwindows/application/application.pro
index 0f451754f2..e55655a934 100644
--- a/examples/widgets/mainwindows/application/application.pro
+++ b/examples/widgets/mainwindows/application/application.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
HEADERS = mainwindow.h
SOURCES = main.cpp \
diff --git a/examples/widgets/mainwindows/dockwidgets/dockwidgets.pro b/examples/widgets/mainwindows/dockwidgets/dockwidgets.pro
index 9cd3128a66..3acded5ed3 100644
--- a/examples/widgets/mainwindows/dockwidgets/dockwidgets.pro
+++ b/examples/widgets/mainwindows/dockwidgets/dockwidgets.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(listwidget))
qtHaveModule(printsupport): QT += printsupport
HEADERS = mainwindow.h
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.cpp b/examples/widgets/mainwindows/mainwindow/mainwindow.cpp
index 10e3dd045a..afceddfca1 100644
--- a/examples/widgets/mainwindows/mainwindow/mainwindow.cpp
+++ b/examples/widgets/mainwindows/mainwindow/mainwindow.cpp
@@ -63,7 +63,6 @@
#include <QFileDialog>
#include <QDialogButtonBox>
#include <QMessageBox>
-#include <QSignalMapper>
#include <QApplication>
#include <QPainter>
#include <QMouseEvent>
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.pro b/examples/widgets/mainwindows/mainwindow/mainwindow.pro
index bf92d0e3ca..446d07ee6e 100644
--- a/examples/widgets/mainwindows/mainwindow/mainwindow.pro
+++ b/examples/widgets/mainwindows/mainwindow/mainwindow.pro
@@ -1,5 +1,6 @@
TEMPLATE = app
QT += widgets
+requires(qtConfig(combobox))
HEADERS += colorswatch.h mainwindow.h toolbar.h
SOURCES += colorswatch.cpp mainwindow.cpp toolbar.cpp main.cpp
diff --git a/examples/widgets/mainwindows/mainwindow/toolbar.cpp b/examples/widgets/mainwindows/mainwindow/toolbar.cpp
index 97152a64a3..814cfc7f4d 100644
--- a/examples/widgets/mainwindows/mainwindow/toolbar.cpp
+++ b/examples/widgets/mainwindows/mainwindow/toolbar.cpp
@@ -50,6 +50,8 @@
#include "toolbar.h"
+#include <QRandomGenerator>
+
#include <QMainWindow>
#include <QMenu>
#include <QPainter>
@@ -257,7 +259,7 @@ void ToolBar::randomize()
QList<QAction *> randomized;
QList<QAction *> actions = this->actions();
while (!actions.isEmpty()) {
- QAction *action = actions.takeAt(rand() % actions.size());
+ QAction *action = actions.takeAt(QRandomGenerator::global()->bounded(actions.size()));
randomized.append(action);
}
clear();
diff --git a/examples/widgets/mainwindows/mdi/mdi.pro b/examples/widgets/mainwindows/mdi/mdi.pro
index 2e3c232a56..f2c236f7e2 100644
--- a/examples/widgets/mainwindows/mdi/mdi.pro
+++ b/examples/widgets/mainwindows/mdi/mdi.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
HEADERS = mainwindow.h \
mdichild.h
diff --git a/examples/widgets/mainwindows/sdi/sdi.pro b/examples/widgets/mainwindows/sdi/sdi.pro
index 83f1c0f805..30d07b0665 100644
--- a/examples/widgets/mainwindows/sdi/sdi.pro
+++ b/examples/widgets/mainwindows/sdi/sdi.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
HEADERS = mainwindow.h
SOURCES = main.cpp \
diff --git a/examples/widgets/painting/affine/xform.cpp b/examples/widgets/painting/affine/xform.cpp
index e47bc9d251..20f6eb3c6d 100644
--- a/examples/widgets/painting/affine/xform.cpp
+++ b/examples/widgets/painting/affine/xform.cpp
@@ -77,8 +77,8 @@ XFormView::XFormView(QWidget *parent)
pts->setBoundingRect(QRectF(0, 0, 500, 500));
ctrlPoints << QPointF(250, 250) << QPointF(350, 250);
pts->setPoints(ctrlPoints);
- connect(pts, SIGNAL(pointsChanged(QPolygonF)),
- this, SLOT(updateCtrlPoints(QPolygonF)));
+ connect(pts, &HoverPoints::pointsChanged,
+ this,&XFormView::updateCtrlPoints);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}
@@ -876,29 +876,29 @@ XFormWidget::XFormWidget(QWidget *parent)
#endif
mainGroupLayout->addWidget(whatsThisButton);
- connect(rotateSlider, SIGNAL(valueChanged(int)), view, SLOT(changeRotation(int)));
- connect(shearSlider, SIGNAL(valueChanged(int)), view, SLOT(changeShear(int)));
- connect(scaleSlider, SIGNAL(valueChanged(int)), view, SLOT(changeScale(int)));
-
- connect(vectorType, SIGNAL(clicked()), view, SLOT(setVectorType()));
- connect(pixmapType, SIGNAL(clicked()), view, SLOT(setPixmapType()));
- connect(textType, SIGNAL(clicked()), view, SLOT(setTextType()));
- connect(textType, SIGNAL(toggled(bool)), textEditor, SLOT(setEnabled(bool)));
- connect(textEditor, SIGNAL(textChanged(QString)), view, SLOT(setText(QString)));
-
- connect(view, SIGNAL(rotationChanged(int)), rotateSlider, SLOT(setValue(int)));
- connect(view, SIGNAL(scaleChanged(int)), scaleSlider, SLOT(setValue(int)));
- connect(view, SIGNAL(shearChanged(int)), shearSlider, SLOT(setValue(int)));
-
- connect(resetButton, SIGNAL(clicked()), view, SLOT(reset()));
- connect(animateButton, SIGNAL(clicked(bool)), view, SLOT(setAnimation(bool)));
- connect(whatsThisButton, SIGNAL(clicked(bool)), view, SLOT(setDescriptionEnabled(bool)));
- connect(whatsThisButton, SIGNAL(clicked(bool)), view->hoverPoints(), SLOT(setDisabled(bool)));
- connect(view, SIGNAL(descriptionEnabledChanged(bool)), view->hoverPoints(), SLOT(setDisabled(bool)));
- connect(view, SIGNAL(descriptionEnabledChanged(bool)), whatsThisButton, SLOT(setChecked(bool)));
- connect(showSourceButton, SIGNAL(clicked()), view, SLOT(showSource()));
+ connect(rotateSlider, &QSlider::valueChanged, view, &XFormView::changeRotation);
+ connect(shearSlider, &QSlider::valueChanged, view, &XFormView::changeShear);
+ connect(scaleSlider, &QSlider::valueChanged, view, &XFormView::changeScale);
+
+ connect(vectorType, &QRadioButton::clicked, view, &XFormView::setVectorType);
+ connect(pixmapType, &QRadioButton::clicked, view, &XFormView::setPixmapType);
+ connect(textType, &QRadioButton::clicked, view, &XFormView::setTextType);
+ connect(textType, &QRadioButton::toggled, textEditor, &XFormView::setEnabled);
+ connect(textEditor, &QLineEdit::textChanged, view, &XFormView::setText);
+
+ connect(view, &XFormView::rotationChanged, rotateSlider, &QSlider::setValue);
+ connect(view, &XFormView::scaleChanged, scaleSlider, &QAbstractSlider::setValue);
+ connect(view, &XFormView::shearChanged, shearSlider, &QAbstractSlider::setValue);
+
+ connect(resetButton, &QPushButton::clicked, view, &XFormView::reset);
+ connect(animateButton, &QPushButton::clicked, view, &XFormView::setAnimation);
+ connect(whatsThisButton, &QPushButton::clicked, view, &ArthurFrame::setDescriptionEnabled);
+ connect(whatsThisButton, &QPushButton::clicked, view->hoverPoints(), &HoverPoints::setDisabled);
+ connect(view, &XFormView::descriptionEnabledChanged, view->hoverPoints(), &HoverPoints::setDisabled);
+ connect(view, &XFormView::descriptionEnabledChanged, whatsThisButton, &QPushButton::setChecked);
+ connect(showSourceButton, &QPushButton::clicked, view, &XFormView::showSource);
#ifdef QT_OPENGL_SUPPORT
- connect(enableOpenGLButton, SIGNAL(clicked(bool)), view, SLOT(enableOpenGL(bool)));
+ connect(enableOpenGLButton, &QPushButton::clicked, view, &XFormView::enableOpenGL);
#endif
view->loadSourceFile(":res/affine/xform.cpp");
view->loadDescription(":res/affine/xform.html");
diff --git a/examples/widgets/painting/basicdrawing/basicdrawing.pro b/examples/widgets/painting/basicdrawing/basicdrawing.pro
index a7b3cff9cd..aba62a3683 100644
--- a/examples/widgets/painting/basicdrawing/basicdrawing.pro
+++ b/examples/widgets/painting/basicdrawing/basicdrawing.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = renderarea.h \
window.h
diff --git a/examples/widgets/painting/composition/composition.cpp b/examples/widgets/painting/composition/composition.cpp
index d5d674fd83..0b57d3c7d3 100644
--- a/examples/widgets/painting/composition/composition.cpp
+++ b/examples/widgets/painting/composition/composition.cpp
@@ -464,7 +464,7 @@ void CompositionRenderer::paint(QPainter *painter)
drawBase(p);
}
- memcpy(m_buffer.bits(), m_base_buffer.bits(), m_buffer.byteCount());
+ memcpy(m_buffer.bits(), m_base_buffer.bits(), m_buffer.sizeInBytes());
{
QPainter p(&m_buffer);
diff --git a/examples/widgets/painting/fontsampler/fontsampler.pro b/examples/widgets/painting/fontsampler/fontsampler.pro
index 08dd07bc08..5d3461f4b8 100644
--- a/examples/widgets/painting/fontsampler/fontsampler.pro
+++ b/examples/widgets/painting/fontsampler/fontsampler.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
qtHaveModule(printsupport): QT += printsupport
FORMS = mainwindowbase.ui
diff --git a/examples/widgets/painting/imagecomposition/imagecomposition.pro b/examples/widgets/painting/imagecomposition/imagecomposition.pro
index 42c70471c1..3b7275c4f1 100644
--- a/examples/widgets/painting/imagecomposition/imagecomposition.pro
+++ b/examples/widgets/painting/imagecomposition/imagecomposition.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = imagecomposer.h
SOURCES = imagecomposer.cpp \
diff --git a/examples/widgets/painting/painterpaths/painterpaths.pro b/examples/widgets/painting/painterpaths/painterpaths.pro
index dfff238dd1..ab238434e6 100644
--- a/examples/widgets/painting/painterpaths/painterpaths.pro
+++ b/examples/widgets/painting/painterpaths/painterpaths.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = renderarea.h \
window.h
diff --git a/examples/widgets/painting/painterpaths/window.cpp b/examples/widgets/painting/painterpaths/window.cpp
index 7122411a6c..a987937b39 100644
--- a/examples/widgets/painting/painterpaths/window.cpp
+++ b/examples/widgets/painting/painterpaths/window.cpp
@@ -53,11 +53,7 @@
#include <QtWidgets>
-#include <cmath>
-
-//! [0]
-const float Pi = 3.14159f;
-//! [0]
+#include <qmath.h>
//! [1]
Window::Window()
@@ -133,8 +129,8 @@ Window::Window()
QPainterPath starPath;
starPath.moveTo(90, 50);
for (int i = 1; i < 5; ++i) {
- starPath.lineTo(50 + 40 * std::cos(0.8 * i * Pi),
- 50 + 40 * std::sin(0.8 * i * Pi));
+ starPath.lineTo(50 + 40 * std::cos(0.8 * i * M_PI),
+ 50 + 40 * std::sin(0.8 * i * M_PI));
}
starPath.closeSubpath();
//! [9]
diff --git a/examples/widgets/painting/transformations/transformations.pro b/examples/widgets/painting/transformations/transformations.pro
index 3f5398a228..e97dc87145 100644
--- a/examples/widgets/painting/transformations/transformations.pro
+++ b/examples/widgets/painting/transformations/transformations.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = renderarea.h \
window.h
diff --git a/examples/widgets/richtext/calendar/calendar.pro b/examples/widgets/richtext/calendar/calendar.pro
index 5adb99aac3..199c1dbb8d 100644
--- a/examples/widgets/richtext/calendar/calendar.pro
+++ b/examples/widgets/richtext/calendar/calendar.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = mainwindow.h
SOURCES = main.cpp \
diff --git a/examples/widgets/richtext/orderform/orderform.pro b/examples/widgets/richtext/orderform/orderform.pro
index 0eb9da3ae1..a24ac495cd 100644
--- a/examples/widgets/richtext/orderform/orderform.pro
+++ b/examples/widgets/richtext/orderform/orderform.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(tablewidget))
qtHaveModule(printsupport): QT += printsupport
HEADERS = detailsdialog.h \
diff --git a/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.pro b/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.pro
index ae51662341..e0d26bdbe0 100644
--- a/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.pro
+++ b/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
HEADERS = highlighter.h \
mainwindow.h
diff --git a/examples/widgets/richtext/textedit/textedit.pro b/examples/widgets/richtext/textedit/textedit.pro
index c32bf68f68..b7a2155b0b 100644
--- a/examples/widgets/richtext/textedit/textedit.pro
+++ b/examples/widgets/richtext/textedit/textedit.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
qtHaveModule(printsupport): QT += printsupport
TEMPLATE = app
diff --git a/examples/widgets/statemachine/rogue/window.cpp b/examples/widgets/statemachine/rogue/window.cpp
index 428d4c3af6..3515138382 100644
--- a/examples/widgets/statemachine/rogue/window.cpp
+++ b/examples/widgets/statemachine/rogue/window.cpp
@@ -248,11 +248,9 @@ void Window::movePlayer(Direction direction)
void Window::setupMap()
{
- qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
-
for (int x = 0; x < WIDTH; ++x)
for (int y = 0; y < HEIGHT; ++y) {
- if (x == 0 || x == WIDTH - 1 || y == 0 || y == HEIGHT - 1 || qrand() % 40 == 0)
+ if (x == 0 || x == WIDTH - 1 || y == 0 || y == HEIGHT - 1 || QRandomGenerator::global()->bounded(40) == 0)
map[x][y] = '#';
else
map[x][y] = '.';
diff --git a/examples/widgets/tools/codecs/codecs.pro b/examples/widgets/tools/codecs/codecs.pro
index 2bdb130268..13daa79237 100644
--- a/examples/widgets/tools/codecs/codecs.pro
+++ b/examples/widgets/tools/codecs/codecs.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
HEADERS += mainwindow.h \
previewform.h
diff --git a/examples/widgets/tools/completer/completer.pro b/examples/widgets/tools/completer/completer.pro
index cbc6ec85b5..c616e08468 100644
--- a/examples/widgets/tools/completer/completer.pro
+++ b/examples/widgets/tools/completer/completer.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(completer))
HEADERS = fsmodel.h \
mainwindow.h
diff --git a/examples/widgets/tools/customcompleter/customcompleter.pro b/examples/widgets/tools/customcompleter/customcompleter.pro
index 499fab5537..74c2ceb320 100644
--- a/examples/widgets/tools/customcompleter/customcompleter.pro
+++ b/examples/widgets/tools/customcompleter/customcompleter.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(completer))
HEADERS = mainwindow.h \
textedit.h
diff --git a/examples/widgets/tools/i18n/i18n.pro b/examples/widgets/tools/i18n/i18n.pro
index 8bfdd07a63..a4d5e418ea 100644
--- a/examples/widgets/tools/i18n/i18n.pro
+++ b/examples/widgets/tools/i18n/i18n.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(listwidget))
HEADERS = languagechooser.h \
mainwindow.h
diff --git a/examples/widgets/tools/plugandpaint/plugandpaint.pro b/examples/widgets/tools/plugandpaint/plugandpaint.pro
index f7da8a52bd..58c4dbbb6e 100644
--- a/examples/widgets/tools/plugandpaint/plugandpaint.pro
+++ b/examples/widgets/tools/plugandpaint/plugandpaint.pro
@@ -1,3 +1,6 @@
+QT_FOR_CONFIG += widgets
+requires(qtConfig(inputdialog))
+
TEMPLATE = subdirs
SUBDIRS = plugins app
diff --git a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp
index c929ff6922..92620ddd8c 100644
--- a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp
+++ b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp
@@ -50,13 +50,11 @@
#include <QtWidgets>
-#include <cmath>
+#include <qmath.h>
#include <stdlib.h>
#include "basictoolsplugin.h"
-const float Pi = 3.14159f;
-
//! [0]
QStringList BasicToolsPlugin::brushes() const
{
@@ -103,7 +101,7 @@ QRect BasicToolsPlugin::mouseMove(const QString &brush, QPainter &painter,
thickness, thickness);
}
} else if (brush == tr("Random Letters")) {
- QChar ch('A' + (qrand() % 26));
+ QChar ch(QRandomGenerator::global()->bounded('A', 'Z' + 1));
QFont biggerFont = painter.font();
biggerFont.setBold(true);
@@ -149,8 +147,8 @@ QPainterPath BasicToolsPlugin::generateShape(const QString &shape,
} else if (shape == tr("Star")) {
path.moveTo(90, 50);
for (int i = 1; i < 5; ++i) {
- path.lineTo(50 + 40 * std::cos(0.8 * i * Pi),
- 50 + 40 * std::sin(0.8 * i * Pi));
+ path.lineTo(50 + 40 * std::cos(0.8 * i * M_PI),
+ 50 + 40 * std::sin(0.8 * i * M_PI));
}
path.closeSubpath();
} else if (shape == tr("Text...")) {
diff --git a/examples/widgets/tools/regexp/regexp.pro b/examples/widgets/tools/regexp/regexp.pro
index f80c16fb60..a4c2971c25 100644
--- a/examples/widgets/tools/regexp/regexp.pro
+++ b/examples/widgets/tools/regexp/regexp.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = regexpdialog.h
SOURCES = regexpdialog.cpp \
diff --git a/examples/widgets/tools/regularexpression/regularexpression.pro b/examples/widgets/tools/regularexpression/regularexpression.pro
index 8e72e171b8..cc23402b9d 100644
--- a/examples/widgets/tools/regularexpression/regularexpression.pro
+++ b/examples/widgets/tools/regularexpression/regularexpression.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(treewidget))
HEADERS = regularexpressiondialog.h
SOURCES = regularexpressiondialog.cpp \
diff --git a/examples/widgets/tools/settingseditor/settingseditor.pro b/examples/widgets/tools/settingseditor/settingseditor.pro
index 5e605f1941..4880b7e582 100644
--- a/examples/widgets/tools/settingseditor/settingseditor.pro
+++ b/examples/widgets/tools/settingseditor/settingseditor.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(tablewidget))
HEADERS = locationdialog.h \
mainwindow.h \
diff --git a/examples/widgets/tools/treemodelcompleter/treemodelcompleter.pro b/examples/widgets/tools/treemodelcompleter/treemodelcompleter.pro
index 9f2b1ca9e4..ec25e0fc1c 100644
--- a/examples/widgets/tools/treemodelcompleter/treemodelcompleter.pro
+++ b/examples/widgets/tools/treemodelcompleter/treemodelcompleter.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(completer))
HEADERS = treemodelcompleter.h \
mainwindow.h
diff --git a/examples/widgets/tools/undo/mainwindow.cpp b/examples/widgets/tools/undo/mainwindow.cpp
index aa570caa80..5976163f3f 100644
--- a/examples/widgets/tools/undo/mainwindow.cpp
+++ b/examples/widgets/tools/undo/mainwindow.cpp
@@ -52,6 +52,7 @@
#include <QUndoStack>
#include <QFileDialog>
#include <QMessageBox>
+#include <QRandomGenerator>
#include <QTextStream>
#include <QToolButton>
#include "document.h"
@@ -321,7 +322,7 @@ void MainWindow::newDocument()
static QColor randomColor()
{
- int r = (int) (3.0*(rand()/(RAND_MAX + 1.0)));
+ int r = QRandomGenerator::global()->bounded(3);
switch (r) {
case 0:
return Qt::red;
@@ -337,10 +338,10 @@ static QRect randomRect(const QSize &s)
{
QSize min = Shape::minSize;
- int left = (int) ((0.0 + s.width() - min.width())*(rand()/(RAND_MAX + 1.0)));
- int top = (int) ((0.0 + s.height() - min.height())*(rand()/(RAND_MAX + 1.0)));
- int width = (int) ((0.0 + s.width() - left - min.width())*(rand()/(RAND_MAX + 1.0))) + min.width();
- int height = (int) ((0.0 + s.height() - top - min.height())*(rand()/(RAND_MAX + 1.0))) + min.height();
+ int left = (int) ((0.0 + s.width() - min.width())*(QRandomGenerator::global()->bounded(1.0)));
+ int top = (int) ((0.0 + s.height() - min.height())*(QRandomGenerator::global()->bounded(1.0)));
+ int width = (int) ((0.0 + s.width() - left - min.width())*(QRandomGenerator::global()->bounded(1.0))) + min.width();
+ int height = (int) ((0.0 + s.height() - top - min.height())*(QRandomGenerator::global()->bounded(1.0))) + min.height();
return QRect(left, top, width, height);
}
diff --git a/examples/widgets/tools/undo/undo.pro b/examples/widgets/tools/undo/undo.pro
index 3727c8cbde..9b7b577dd3 100644
--- a/examples/widgets/tools/undo/undo.pro
+++ b/examples/widgets/tools/undo/undo.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(undoview))
SOURCES += main.cpp mainwindow.cpp commands.cpp document.cpp
HEADERS += mainwindow.h commands.h document.h
diff --git a/examples/widgets/tools/undoframework/diagramitem.cpp b/examples/widgets/tools/undoframework/diagramitem.cpp
index 754baa2377..723645c9b2 100644
--- a/examples/widgets/tools/undoframework/diagramitem.cpp
+++ b/examples/widgets/tools/undoframework/diagramitem.cpp
@@ -65,8 +65,7 @@ DiagramItem::DiagramItem(DiagramType diagramType, QGraphicsItem *item)
setPolygon(trianglePolygon);
}
- QColor color(static_cast<int>(qrand()) % 256,
- static_cast<int>(qrand()) % 256, static_cast<int>(qrand()) % 256);
+ QColor color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256));
QBrush brush(color);
setBrush(brush);
setFlag(QGraphicsItem::ItemIsSelectable);
diff --git a/examples/widgets/tools/undoframework/undoframework.pro b/examples/widgets/tools/undoframework/undoframework.pro
index 5c877be338..9f7fbc3375 100644
--- a/examples/widgets/tools/undoframework/undoframework.pro
+++ b/examples/widgets/tools/undoframework/undoframework.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(undoview))
HEADERS = commands.h \
diagramitem.h \
diff --git a/examples/widgets/tutorials/addressbook/part6/part6.pro b/examples/widgets/tutorials/addressbook/part6/part6.pro
index 02473e2bfe..6796f30a73 100644
--- a/examples/widgets/tutorials/addressbook/part6/part6.pro
+++ b/examples/widgets/tutorials/addressbook/part6/part6.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
SOURCES = addressbook.cpp \
finddialog.cpp \
diff --git a/examples/widgets/tutorials/addressbook/part7/part7.pro b/examples/widgets/tutorials/addressbook/part7/part7.pro
index bab6a593d6..6a99799c67 100644
--- a/examples/widgets/tutorials/addressbook/part7/part7.pro
+++ b/examples/widgets/tutorials/addressbook/part7/part7.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
SOURCES = addressbook.cpp \
finddialog.cpp \
diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part5/part5.pro b/examples/widgets/tutorials/gettingStarted/gsQt/part5/part5.pro
index 032f220b83..12378f305a 100644
--- a/examples/widgets/tutorials/gettingStarted/gsQt/part5/part5.pro
+++ b/examples/widgets/tutorials/gettingStarted/gsQt/part5/part5.pro
@@ -1,5 +1,5 @@
-
QT += widgets
+requires(qtConfig(filedialog))
SOURCES = main.cpp
# install
diff --git a/examples/widgets/tutorials/gettingstartedqt.qdoc b/examples/widgets/tutorials/gettingstartedqt.qdoc
new file mode 100644
index 0000000000..921dd7a32d
--- /dev/null
+++ b/examples/widgets/tutorials/gettingstartedqt.qdoc
@@ -0,0 +1,559 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example tutorials/notepad
+ \title Getting Started Programming with Qt Widgets
+ \brief A tutorial for Qt Widgets based on a notepad application
+
+ In this topic, we teach basic Qt knowledge by implementing a simple
+ Notepad application using C++ and the \l{Qt Widgets} module. The
+ application is a small text editor which allows you to create a text
+ file, save it, print it,
+ or reopen and edit it again. You can also set the font to be used.
+
+ \image notepad1.png "Notepad application"
+
+ You can find the final Notepad source files in the qtdoc repository
+ in the tutorials/notepad directory. You can either fetch
+ the Qt 5 sources from Qt Project or install them as part of Qt 5.
+ The application is also available in the example list of Qt Creator's
+ Welcome mode.
+
+ \section1 Creating the Notepad Project
+
+ Setting up a new project in Qt Creator is aided by a wizard that
+ guides you step-by-step through the project creation process. The
+ wizard prompts you to enter the settings needed for that particular
+ type of project and creates the project for you.
+
+ \image notepad2.png "Qt Creator New File or Project dialog"
+
+ To create the Notepad project, select \b File > \b{New File or
+ Project} > \b Applications > \b {Qt Widgets Application} > \b Choose,
+ and follow the instructions of the wizard. In the
+ \b{Class Information}
+ dialog, type \b Notepad as the class name and select \b QMainWindow
+ as the base class.
+
+ \image notepad3.png "Class Information Dialog"
+
+ The \b {Qt Widgets Application} wizard creates a project that contains
+ a main source file and a set of files that specify a user interface
+ (Notepad widget):
+
+ \list
+ \li notepad.pro - the project file.
+ \li main.cpp - the main source file for the application.
+ \li notepad.cpp - the source file of the notepad class of the
+ Notepad widget.
+ \li notepad.h - the header file of the notepad class for the
+ Notepad widget.
+ \li notepad.ui - the UI form for the Notepad widget.
+ \endlist
+
+ The .cpp, .h, and .ui files come with the necessary boiler plate code
+ for you to be able to build and run the project. The .pro file is
+ complete.
+ We will take a closer look at the file contents in the following
+ sections.
+
+ \b{Learn More}
+
+ \table
+ \header
+ \li About
+ \li Here
+ \row
+ \li Using Qt Creator
+ \li \l{Qt Creator Manual}{Qt Creator}
+ \row
+ \li Creating other kind of applications with Qt Creator
+ \li \l{Qt Creator: Tutorials}{Qt Creator Tutorials}
+ \endtable
+
+
+ \section1 Main Source File
+
+ The wizard generates the following code in the main.cpp file:
+
+ \quotefromfile tutorials/notepad/main.cpp
+ \skipto "notepad.h"
+ \printuntil EditorApp.exec()
+ \printuntil }
+
+ We will go through the code line by line. The following lines include
+ the header files for the Notepad widget and QApplication. All Qt classes
+ have a header file named after them.
+
+ \quotefromfile tutorials/notepad/main.cpp
+ \skipto notepad.h
+ \printuntil QApplication
+
+ The following line defines the main function that is the entry point
+ for all C and C++ based applications:
+
+ \printline main
+
+ The following line creates a QApplication object. This object manages
+ application-wide resources and is necessary to run any Qt program
+ that uses Qt Widgets. It constructs an application object with \c argc
+ command line arguments run in \c argv. (For GUI applications that
+ do not use Qt Widgets, you can use QGuiApplication instead.)
+
+ \skipuntil {
+ \printuntil QApplication
+
+ The following line creates the Notepad object. This is the object for
+ which the wizard created the class and the UI file. The user interface
+ contains visual elements that are called \c widgets in Qt. Examples
+ of widgets are text edits, scroll bars, labels, and radio buttons. A
+ widget can also be a container for other widgets; a dialog or a main
+ application window, for example.
+
+ \printline Notepad
+
+ The following line shows the Notepad widget on the screen in its own
+ window. Widgets can also function as containers. An example of this
+ is QMainWindow which often contains several types of widgets. Widgets
+ are not visible by default; the function \l{QWidget::}{show()} makes
+ the widget visible.
+
+ \printline Editor.show
+
+ The following line makes the QApplication enter its event loop. When
+ a Qt application is running, events are generated and sent to the
+ widgets of the application. Examples of events are mouse presses
+ and key strokes.
+
+ \printline EditorApp.exec
+
+ \b{Learn More}
+
+ \table
+ \header
+ \li About
+ \li Here
+ \row
+ \li Widgets and Window Geometry
+ \li \l{Window and Dialog Widgets}
+ \row
+ \li Events and event handling
+ \li \l{The Event System}
+ \endtable
+
+ \section1 Designing a UI
+
+ The wizard generates a user interface definition in XML format: notepad.ui.
+ When you open the notepad.ui file in Qt Creator, it automatically
+ opens in the integrated Qt Designer.
+
+ When you build the application, Qt Creator launches the Qt
+ \l{User Interface Compiler (uic)} that reads the .ui file and creates
+ a corresponding C++ header file, ui_notepad.h.
+
+ \section2 Using Qt Designer
+
+ The wizard creates an application that uses a QMainWindow. It has
+ its own layout to which you can add a menu bar, dock widgets, toolbars,
+ and a status bar. The center area can be occupied by any kind of widget.
+ The wizard places the Notepad widget there.
+
+ To add widgets in Qt Designer:
+
+ \list 1
+ \li In the Qt Creator \b Editor mode, double-click the notepad.ui
+ file in the \b Projects view to launch the file in the integrated
+ Qt Designer.
+ \li Drag and drop widgets Text Edit (QTextEdit) to the form.
+ \li Press \b {Ctrl+A} (or \b {Cmd+A}) to select the widgets and click
+ \b {Lay out Vertically} (or press \b {Ctrl+L}) to apply a vertical
+ layout (QVBoxLayout).
+ \li Press \b {Ctrl+S} (or \b {Cmd+S}) to save your changes.
+ \endlist
+
+ The UI now looks as follows in Qt Designer:
+
+ \image notepad4.png
+
+ You can view the generated XML file in the code editor:
+
+ \quotefromfile tutorials/notepad/notepad.ui
+
+ \printuntil QMenuBar
+ \dots
+
+ The following line contains the XML declaration, which specifies the
+ XML version and character encoding used in the document:
+
+ \code
+ <?xml version="1.0" encoding="UTF-8"?>
+ \endcode
+
+ The rest of the file specifies an \c ui element that defines a
+ Notepad widget:
+
+ \code
+ <ui version="4.0">
+ \endcode
+
+ The UI file is used together with the header and source file of the
+ Notepad class. We will look at the rest of the UI file in the later
+ sections.
+
+ \section2 Notepad Header File
+
+ The wizard generated a header file for the Notepad class that has the
+ necessary #includes, a constructor, a destructor, and the Ui object.
+ The file looks as follows:
+
+ \snippet tutorials/notepad/notepad.h all
+
+ The following line includes QMainWindow that provides a main application
+ window:
+
+ \snippet tutorials/notepad/notepad.h 1
+
+ The following lines declare the Notepad class in the Ui namespace,
+ which is the standard namespace for the UI classes generated from
+ .ui files by the \c uic tool:
+
+ \snippet tutorials/notepad/notepad.h 2
+
+ The class declaration contains the \c Q_OBJECT macro. It must come
+ first in the class definition, and declares our class as a QObject.
+ Naturally, it must also inherit from QObject. A QObject adds several
+ abilities to a normal C++ class. Notably, the class name and slot
+ names can be queried at runtime. It is also possible to query a slot's
+ parameter types and invoke it.
+
+ \snippet tutorials/notepad/notepad.h 3
+
+ The following lines declare a constructor that has a default argument
+ called \c parent.
+ The value 0 indicates that the widget has no parent (it is a top-level
+ widget).
+
+ \snippet tutorials/notepad/notepad.h 4
+
+ The following line declares a virtual destructor to free the resources
+ that were acquired by the object during its life-cycle. According to
+ the C++ naming convention, destructors have the same name as the class
+ they are associated with, prefixed with a tilde (~). In QObject,
+ destructors are virtual to ensure that the destructors of derived
+ classes are invoked properly when an object is deleted through a
+ pointer-to-base-class.
+
+ \snippet tutorials/notepad/notepad.h 5
+
+ The following lines declare a member variable which is a pointer to
+ the Notepad UI class. A member variable is associated with a specific
+ class, and accessible for all its methods.
+
+ \snippet tutorials/notepad/notepad.h 6
+
+ \section2 Notepad Source File
+
+ The source file that the wizard generated for the Notepad class looks
+ as follows:
+
+ \quotefromfile tutorials/notepad/notepad.cpp
+ \skipto notepad.h
+ \printuntil ui->textEdit->setFont(font)
+ \printuntil }
+
+ The following lines include the Notepad class header file that was
+ generated by the wizard and the UI header file that was generated
+ by the \c uic tool:
+
+ \quotefromfile tutorials/notepad/notepad.cpp
+ \skipto notepad.h
+ \printuntil ui_notepad
+
+ The following line defines the \c {Notepad} constructor:
+
+ \skipto Notepad::Notepad
+ \printline Notepad::Notepad
+
+ The following line calls the QMainWindow constructor, which is
+ the base class for the Notepad class:
+
+ \printline QMainWindow
+
+ The following line creates the UI class instance and assigns it to
+ the \c ui member:
+
+ \printline ui(new
+
+ The following line sets up the UI:
+
+ \quotefromfile tutorials/notepad/notepad.cpp
+ \skipto ui->setupUi
+ \printline ui->setupUi(this)
+
+ In the destructor, we delete the \c ui:
+
+ \skipto Notepad::~Notepad
+ \printuntil }
+
+ In order to have the text edit field occupy the whole screen, we add
+ \c setCentralWidget to the main window.
+
+ \quotefromfile tutorials/notepad/notepad.cpp
+ \skipto Notepad::Notepad(QWidget *parent)
+ \printuntil }
+
+ \section2 Project File
+
+ The wizard generates the following project file, \c {notepad.pro}, for
+ us:
+
+ \quotefile tutorials/notepad/notepad.pro
+
+ The project file specifies the application name and the \c qmake
+ template to use for generating the project, as well as the source,
+ header, and UI files included in the project.
+
+ You could also use \c qmake's \c -project option to generate the \.pro
+ file. Although, in that case, you have to remember to add the line
+ \c{QT += widgets} to the generated file in order to link against the
+ Qt Widgets Module.
+
+ \b{Learn More}
+
+ \table
+ \header
+ \li About
+ \li Here
+ \row
+ \li Using Qt Designer
+ \li \l{Qt Designer Manual}
+ \row
+ \li Layouts
+ \li \l{Layout Management},
+ \l{Widgets and Layouts},
+ \l{Layout Examples}
+ \row
+ \li The widgets that come with Qt
+ \li \l{Qt Widget Gallery}
+ \row
+ \li Main windows and main window classes
+ \li \l{Application Main Window},
+ \l{Main Window Examples}
+ \row
+ \li QObjects and the Qt Object model (This is essential to
+ understand Qt)
+ \li \l{Object Model}
+ \row
+ \li qmake and the Qt build system
+ \li \l{qmake Manual}
+ \endtable
+
+ \section1 Adding User Interaction
+
+
+ To add functionality to the editor, we start by adding menu items
+ and buttons on a toolbar.
+
+ Click on "Type Here", and add the options New, Open, Save, Save as,
+ Print and Exit. This creates 5 lines in the Action Editor below.
+ To connect the actions to slots, right-click an action and select
+ Go to slot > triggered(), and complete the code for that given slot.
+
+ If we also want to add the actions to a toolbar, we can assign an
+ icon to each QAction, and then drag the QAction to the toolbar. You
+ assign an icon by entering an icon name in the Icon property of the
+ action concerned. When the QAction has been dragged to the toolbar,
+ clicking the icon will launch the associated slot.
+
+ Complete the method \c on_actionNew_triggered():
+
+ \quotefromfile tutorials/notepad/notepad.cpp
+ \skipto on_actionNew_triggered()
+ \printuntil }
+
+ \c current_file is a global variable containing the file presently
+ being edited.
+ It is defined in the private part of notepad.h:
+
+ \quotefromfile tutorials/notepad/notepad.h
+ \skipto private:
+ \printuntil currentFile;
+
+ \c clear() clears the text buffer.
+
+ \section2 Opening a file
+
+ In \c notepad.ui, right click on \c actionOpen and select \c {Go to
+ slot}
+
+ Complete method \c on_actionOpen_triggered().
+
+ \quotefromfile tutorials/notepad/notepad.cpp
+ \skipto on_actionOpen_triggered()
+ \printuntil file.close
+ \printuntil }
+
+
+ \c QFileDialog::getOpenFileName opens a dialog enabling you to select
+ a file. QFile object \c myfile has the selected \c file_name as
+ parameter. We store the selected file also into the global variable
+ \c current_file for later purposes. We open the file with \c file.open
+ as a readonly text file. If it cannot be opened, a warning is issued,
+ and the program stops.
+
+ We define a QTextStream \c instream for parameter \c myfile.
+ The contents of file \c myfile is copied into QString \a text.
+ \c setText(text) fille the buffer of our editor with \c text.
+
+ \c section2 Saving a file
+
+ We create the method for saving a file in the same way as for
+ \l {Opening a file}, by right clicking on \c actionSave, and
+ selecting \c {Go to Slot}.
+
+ \skipto Notepad::on_actionSave_triggered
+ \printuntil file.close
+ \printuntil }
+
+ QFile object \c myfile is linked to global variable \c current_file,
+ the variable that contains the file we were working with.
+ If we cannot open \c myfile, an error message is issued and the
+ method stops. We create a QTextStream \c outstream. The contents
+ of the editor buffer is converted to plain text, and then written
+ to \c outstream.
+
+ \section2 Saving a file with \c {Save as}
+
+ \skipto Notepad::on_actionSave_as_triggered
+ \printuntil file.close
+ \printuntil }
+
+ This is the same procedure as for \c {Saving a file}, the only
+ difference being that here you need to enter a new file name for
+ the file to be created.
+
+
+ \section2 Print a File
+
+ If you want to use print functionalities, you need to add
+ \c printsupport to the project file:
+
+ \badcode
+ QT += printsupport
+ \endcode
+
+ We declare a QPrinter object called \c printer.
+ We launch a printer dialog box and store the selected printer in
+ object \c printer. If we clicked on \c Cancel and did not select
+ a printer, the methods returns. The actual printer command is given
+ with \a ui->textEdit->print with our QPrinter object as parameter.
+
+ \section2 Select a Font
+
+ \skipto Notepad::on_actionFont_triggered
+ \printuntil ui->textEdit->setFont
+ \printline }
+
+ We declare a boolean indicating if we did select a font with
+ QFontDialog. If so, we set the font with \c ui->textEdit->setFont(myfont).
+
+ \section2 Copy, Cut, Paste, Undo, and Redo
+
+ If you select some text, and want to copy it to the clipboard,
+ you call the appropriate method of ui->textEdit. The same counts
+ for cut, paste, undo, and redo.
+
+ This table shows the method name to use.
+
+ \table
+ \header
+ \li Task
+ \li Method called
+ \row
+ \li Copy
+ \li ui->textEdit->copy()
+ \row
+ \li Cut
+ \li ui->textEdit->cut()
+ \row
+ \li Paste
+ \li ui->textEdit->paste()
+ \row
+ \li Undo
+ \li ui->textEdit->undo()
+ \row
+ \li Redo
+ \li ui->textEdit->redo()
+ \endtable
+
+ \b{Learn More}
+
+ \table
+ \header
+ \li About
+ \li Here
+ \row
+ \li MDI applications
+ \li QMdiArea,
+ \l{MDI Example}
+ \row
+ \li Files and I/O devices
+ \li QFile, QIODevice
+ \row
+ \li tr() and internationalization
+ \li \l{Qt Linguist Manual},
+ \l{Writing Source Code for Translation},
+ \l{Internationalization with Qt}
+ \endtable
+
+ \section1 Building and Running Notepad
+
+ Now that you have all the necessary files, select \b Build >
+ \b {Build Project Notepad} to build and run the application. Qt
+ Creator uses \c qmake and \c make to create an executable in the
+ directory specified in the build settings of the project and runs
+ it.
+
+ \section2 Building and Running from the Command Line
+
+ To build the application from the command line, switch to the
+ directory in which you have the \c .cpp file of the application
+ and add the project file (suffixed .pro) described earlier. The
+ following shell commands then build the application:
+
+ \badcode
+ qmake
+ make (or nmake on Windows)
+ \endcode
+
+ The commands create an executable in the project directory. The
+ \c qmake tool reads the project file and produces a \c Makefile
+ with instructions on how to build the application.
+ The \c make tool (or the \c nmake tool) then reads the \c Makefile
+ and produces the executable binary.
+*/
diff --git a/examples/widgets/tutorials/modelview/1_readonly/1_readonly.pro b/examples/widgets/tutorials/modelview/1_readonly/1_readonly.pro
index 72a74bbbac..18cb65d1ec 100644
--- a/examples/widgets/tutorials/modelview/1_readonly/1_readonly.pro
+++ b/examples/widgets/tutorials/modelview/1_readonly/1_readonly.pro
@@ -3,6 +3,7 @@ TARGET = mv_readonly
TEMPLATE = app
QT += widgets
+requires(qtConfig(tableview))
SOURCES += main.cpp \
mymodel.cpp
diff --git a/examples/widgets/tutorials/modelview/2_formatting/2_formatting.pro b/examples/widgets/tutorials/modelview/2_formatting/2_formatting.pro
index 8bf556f73b..590db82c93 100644
--- a/examples/widgets/tutorials/modelview/2_formatting/2_formatting.pro
+++ b/examples/widgets/tutorials/modelview/2_formatting/2_formatting.pro
@@ -3,6 +3,7 @@ TARGET = mv_formatting
TEMPLATE = app
QT += widgets
+requires(qtConfig(tableview))
SOURCES += main.cpp \
mymodel.cpp
diff --git a/examples/widgets/tutorials/modelview/3_changingmodel/3_changingmodel.pro b/examples/widgets/tutorials/modelview/3_changingmodel/3_changingmodel.pro
index 24c790d3a1..1ac36808e7 100644
--- a/examples/widgets/tutorials/modelview/3_changingmodel/3_changingmodel.pro
+++ b/examples/widgets/tutorials/modelview/3_changingmodel/3_changingmodel.pro
@@ -3,6 +3,7 @@ TARGET = mv_changingmodel
TEMPLATE = app
QT += widgets
+requires(qtConfig(tableview))
SOURCES += main.cpp \
mymodel.cpp
diff --git a/examples/widgets/tutorials/modelview/4_headers/4_headers.pro b/examples/widgets/tutorials/modelview/4_headers/4_headers.pro
index 354c39319c..0aae599de0 100644
--- a/examples/widgets/tutorials/modelview/4_headers/4_headers.pro
+++ b/examples/widgets/tutorials/modelview/4_headers/4_headers.pro
@@ -3,6 +3,7 @@ TARGET = mv_headers
TEMPLATE = app
QT += widgets
+requires(qtConfig(tableview))
SOURCES += main.cpp \
mymodel.cpp
diff --git a/examples/widgets/tutorials/modelview/5_edit/5_edit.pro b/examples/widgets/tutorials/modelview/5_edit/5_edit.pro
index 957f6e701a..b8ac19e140 100644
--- a/examples/widgets/tutorials/modelview/5_edit/5_edit.pro
+++ b/examples/widgets/tutorials/modelview/5_edit/5_edit.pro
@@ -3,6 +3,7 @@ TARGET = mv_edit
TEMPLATE = app
QT += widgets
+requires(qtConfig(tableview))
SOURCES += main.cpp \
mainwindow.cpp \
diff --git a/examples/widgets/tutorials/modelview/6_treeview/6_treeview.pro b/examples/widgets/tutorials/modelview/6_treeview/6_treeview.pro
index cbcd3eed5e..84190d0663 100644
--- a/examples/widgets/tutorials/modelview/6_treeview/6_treeview.pro
+++ b/examples/widgets/tutorials/modelview/6_treeview/6_treeview.pro
@@ -1,6 +1,7 @@
TARGET = mv_tree
TEMPLATE = app
QT += widgets
+requires(qtConfig(treeview))
SOURCES += main.cpp \
mainwindow.cpp
HEADERS += mainwindow.h
diff --git a/examples/widgets/tutorials/modelview/7_selections/7_selections.pro b/examples/widgets/tutorials/modelview/7_selections/7_selections.pro
index 24065d39a7..78ddd8e409 100644
--- a/examples/widgets/tutorials/modelview/7_selections/7_selections.pro
+++ b/examples/widgets/tutorials/modelview/7_selections/7_selections.pro
@@ -1,6 +1,7 @@
TARGET = mv_selections
TEMPLATE = app
QT += widgets
+requires(qtConfig(treeview))
SOURCES += main.cpp \
mainwindow.cpp
HEADERS += mainwindow.h
diff --git a/examples/widgets/tutorials/notepad/images/copy.png b/examples/widgets/tutorials/notepad/images/copy.png
new file mode 100644
index 0000000000..cb3442c04c
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/images/copy.png
Binary files differ
diff --git a/examples/widgets/tutorials/notepad/images/create.png b/examples/widgets/tutorials/notepad/images/create.png
new file mode 100644
index 0000000000..fdfd4b438a
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/images/create.png
Binary files differ
diff --git a/examples/widgets/tutorials/notepad/images/cut.png b/examples/widgets/tutorials/notepad/images/cut.png
new file mode 100644
index 0000000000..74b15301ff
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/images/cut.png
Binary files differ
diff --git a/examples/widgets/tutorials/notepad/images/edit_redo.png b/examples/widgets/tutorials/notepad/images/edit_redo.png
new file mode 100644
index 0000000000..8a7725463c
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/images/edit_redo.png
Binary files differ
diff --git a/examples/widgets/tutorials/notepad/images/edit_undo.png b/examples/widgets/tutorials/notepad/images/edit_undo.png
new file mode 100644
index 0000000000..852f5e3b29
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/images/edit_undo.png
Binary files differ
diff --git a/examples/widgets/tutorials/notepad/images/exit.png b/examples/widgets/tutorials/notepad/images/exit.png
new file mode 100644
index 0000000000..677d4deef2
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/images/exit.png
Binary files differ
diff --git a/examples/widgets/tutorials/notepad/images/font.png b/examples/widgets/tutorials/notepad/images/font.png
new file mode 100644
index 0000000000..925e501c03
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/images/font.png
Binary files differ
diff --git a/examples/widgets/tutorials/notepad/images/info.png b/examples/widgets/tutorials/notepad/images/info.png
new file mode 100644
index 0000000000..9731212c4f
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/images/info.png
Binary files differ
diff --git a/examples/widgets/tutorials/notepad/images/new.png b/examples/widgets/tutorials/notepad/images/new.png
new file mode 100644
index 0000000000..b24edc5d0c
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/images/new.png
Binary files differ
diff --git a/examples/widgets/tutorials/notepad/images/open.png b/examples/widgets/tutorials/notepad/images/open.png
new file mode 100644
index 0000000000..7b052edf5a
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/images/open.png
Binary files differ
diff --git a/examples/widgets/tutorials/notepad/images/paste.png b/examples/widgets/tutorials/notepad/images/paste.png
new file mode 100644
index 0000000000..c50dbd95b2
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/images/paste.png
Binary files differ
diff --git a/examples/widgets/tutorials/notepad/images/pencil.png b/examples/widgets/tutorials/notepad/images/pencil.png
new file mode 100644
index 0000000000..a9c5e5482a
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/images/pencil.png
Binary files differ
diff --git a/examples/widgets/tutorials/notepad/images/print.png b/examples/widgets/tutorials/notepad/images/print.png
new file mode 100644
index 0000000000..0cd3f28bd8
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/images/print.png
Binary files differ
diff --git a/examples/widgets/tutorials/notepad/images/save.png b/examples/widgets/tutorials/notepad/images/save.png
new file mode 100644
index 0000000000..e65a29d5f1
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/images/save.png
Binary files differ
diff --git a/examples/widgets/tutorials/notepad/images/save_as.png b/examples/widgets/tutorials/notepad/images/save_as.png
new file mode 100644
index 0000000000..6040574322
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/images/save_as.png
Binary files differ
diff --git a/examples/widgets/dialogs/configdialog/main.cpp b/examples/widgets/tutorials/notepad/main.cpp
index e73474b866..20bcdaa7df 100644
--- a/examples/widgets/dialogs/configdialog/main.cpp
+++ b/examples/widgets/tutorials/notepad/main.cpp
@@ -1,9 +1,9 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
-** This file is part of the examples of the Qt Toolkit.
+** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
@@ -48,16 +48,14 @@
**
****************************************************************************/
+#include "notepad.h"
#include <QApplication>
-#include "configdialog.h"
-
int main(int argc, char *argv[])
{
- Q_INIT_RESOURCE(configdialog);
+ QApplication EditorApp(argc, argv);
+ Notepad Editor;
+ Editor.show();
- QApplication app(argc, argv);
- app.setApplicationDisplayName("Qt Example");
- ConfigDialog dialog;
- return dialog.exec();
+ return EditorApp.exec();
}
diff --git a/examples/widgets/tutorials/notepad/notepad.cpp b/examples/widgets/tutorials/notepad/notepad.cpp
new file mode 100644
index 0000000000..44d8597cb7
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/notepad.cpp
@@ -0,0 +1,193 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QFile>
+#include <QFileDialog>
+#include <QTextStream>
+#include <QMessageBox>
+#if defined(QT_PRINTSUPPORT_LIB)
+#include <QtPrintSupport/qtprintsupportglobal.h>
+#if QT_CONFIG(printer)
+#if QT_CONFIG(printdialog)
+#include <QPrintDialog>
+#endif // QT_CONFIG(printdialog)
+#include <QPrinter>
+#endif // QT_CONFIG(printer)
+#endif // QT_PRINTSUPPORT_LIB
+#include <QFont>
+#include <QFontDialog>
+
+#include "notepad.h"
+#include "ui_notepad.h"
+
+Notepad::Notepad(QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::Notepad)
+{
+ ui->setupUi(this);
+ this->setCentralWidget(ui->textEdit);
+}
+
+Notepad::~Notepad()
+{
+ delete ui;
+}
+
+void Notepad::on_actionNew_triggered()
+{
+ currentFile.clear();
+ ui->textEdit->setText(QString());
+}
+
+void Notepad::on_actionOpen_triggered()
+{
+ QString fileName = QFileDialog::getOpenFileName(this, "Open the file");
+ QFile file(fileName);
+ currentFile = fileName;
+ if (!file.open(QIODevice::ReadOnly | QFile::Text)) {
+ QMessageBox::warning(this, "Warning", "Cannot open file: " + file.errorString());
+ return;
+ }
+ setWindowTitle(fileName);
+ QTextStream in(&file);
+ QString text = in.readAll();
+ ui->textEdit->setText(text);
+ file.close();
+}
+
+void Notepad::on_actionSave_triggered()
+{
+ QString fileName;
+ // If we don't have a filename from before, get one.
+ if (currentFile.isEmpty()) {
+ fileName = QFileDialog::getSaveFileName(this, "Save");
+ currentFile = fileName;
+ } else {
+ fileName = currentFile;
+ }
+ QFile file(fileName);
+ if (!file.open(QIODevice::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(this, "Warning", "Cannot save file: " + file.errorString());
+ return;
+ }
+ setWindowTitle(fileName);
+ QTextStream out(&file);
+ QString text = ui->textEdit->toPlainText();
+ out << text;
+ file.close();
+}
+
+void Notepad::on_actionSave_as_triggered()
+{
+ QString fileName = QFileDialog::getSaveFileName(this, "Save as");
+ QFile file(fileName);
+
+ if (!file.open(QFile::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(this, "Warning", "Cannot save file: " + file.errorString());
+ return;
+ }
+ currentFile = fileName;
+ setWindowTitle(fileName);
+ QTextStream out(&file);
+ QString text = ui->textEdit->toPlainText();
+ out << text;
+ file.close();
+}
+
+void Notepad::on_actionPrint_triggered()
+{
+#if QT_CONFIG(printer)
+ QPrinter printDev;
+#if QT_CONFIG(printdialog)
+ QPrintDialog dialog(&printDev, this);
+ if (dialog.exec() == QDialog::Rejected)
+ return;
+#endif // QT_CONFIG(printdialog)
+ ui->textEdit->print(&printDev);
+#endif // QT_CONFIG(printer)
+}
+
+void Notepad::on_actionExit_triggered()
+{
+ QCoreApplication::quit();
+}
+
+void Notepad::on_actionCopy_triggered()
+{
+ ui->textEdit->copy();
+}
+
+void Notepad::on_actionCut_triggered()
+{
+ ui->textEdit->cut();
+}
+
+void Notepad::on_actionPaste_triggered()
+{
+ ui->textEdit->paste();
+}
+
+void Notepad::on_actionUndo_triggered()
+{
+ ui->textEdit->undo();
+}
+
+void Notepad::on_actionRedo_triggered()
+{
+ ui->textEdit->redo();
+}
+
+void Notepad::on_actionFont_triggered()
+{
+ bool fontSelected;
+ QFont font = QFontDialog::getFont(&fontSelected, this);
+ if (fontSelected)
+ ui->textEdit->setFont(font);
+}
diff --git a/examples/widgets/dialogs/configdialog/configdialog.h b/examples/widgets/tutorials/notepad/notepad.h
index c2edd204e6..f688df45ac 100644
--- a/examples/widgets/dialogs/configdialog/configdialog.h
+++ b/examples/widgets/tutorials/notepad/notepad.h
@@ -1,9 +1,9 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
-** This file is part of the examples of the Qt Toolkit.
+** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
@@ -48,32 +48,67 @@
**
****************************************************************************/
-#ifndef CONFIGDIALOG_H
-#define CONFIGDIALOG_H
+#ifndef NOTEPAD_H
+#define NOTEPAD_H
-#include <QDialog>
+//! [all]
+//! [1]
+#include <QMainWindow>
+//! [1]
+//! [2]
QT_BEGIN_NAMESPACE
-class QListWidget;
-class QListWidgetItem;
-class QStackedWidget;
+namespace Ui {
+class Notepad;
+}
QT_END_NAMESPACE
+//! [2]
-class ConfigDialog : public QDialog
+//! [3]
+class Notepad : public QMainWindow
{
Q_OBJECT
+//! [3]
+//! [4]
public:
- ConfigDialog();
+ explicit Notepad(QWidget *parent = 0);
+//! [4]
+//! [5]
+ ~Notepad();
+//! [5]
-public slots:
- void changePage(QListWidgetItem *current, QListWidgetItem *previous);
+private slots:
+ void on_actionNew_triggered();
-private:
- void createIcons();
+ void on_actionOpen_triggered();
+
+ void on_actionSave_triggered();
+
+ void on_actionSave_as_triggered();
+
+ void on_actionPrint_triggered();
+
+ void on_actionExit_triggered();
+
+ void on_actionCopy_triggered();
- QListWidget *contentsWidget;
- QStackedWidget *pagesWidget;
+ void on_actionCut_triggered();
+
+ void on_actionPaste_triggered();
+
+ void on_actionUndo_triggered();
+
+ void on_actionRedo_triggered();
+
+ void on_actionFont_triggered();
+
+//! [6]
+private:
+ Ui::Notepad *ui;
+ QString currentFile;
+//! [6]
};
+//! [all]
-#endif
+#endif // NOTEPAD_H
diff --git a/examples/widgets/tutorials/notepad/notepad.pro b/examples/widgets/tutorials/notepad/notepad.pro
new file mode 100644
index 0000000000..6451f22735
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/notepad.pro
@@ -0,0 +1,21 @@
+TEMPLATE = app
+TARGET = notepad
+
+qtHaveModule(printsupport): QT += printsupport
+requires(qtConfig(fontdialog))
+
+SOURCES += \
+ main.cpp\
+ notepad.cpp
+
+HEADERS += notepad.h
+
+FORMS += notepad.ui
+
+RESOURCES += \
+ notepad.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tutorials/notepad
+INSTALLS += target
+
diff --git a/examples/widgets/tutorials/notepad/notepad.qrc b/examples/widgets/tutorials/notepad/notepad.qrc
new file mode 100644
index 0000000000..ec11679f13
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/notepad.qrc
@@ -0,0 +1,19 @@
+<RCC>
+ <qresource prefix="/">
+ <file>images/copy.png</file>
+ <file>images/create.png</file>
+ <file>images/cut.png</file>
+ <file>images/edit_redo.png</file>
+ <file>images/edit_undo.png</file>
+ <file>images/exit.png</file>
+ <file>images/font.png</file>
+ <file>images/info.png</file>
+ <file>images/new.png</file>
+ <file>images/open.png</file>
+ <file>images/paste.png</file>
+ <file>images/pencil.png</file>
+ <file>images/print.png</file>
+ <file>images/save.png</file>
+ <file>images/save_as.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/widgets/tutorials/notepad/notepad.ui b/examples/widgets/tutorials/notepad/notepad.ui
new file mode 100644
index 0000000000..d197a95fe7
--- /dev/null
+++ b/examples/widgets/tutorials/notepad/notepad.ui
@@ -0,0 +1,196 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Notepad</class>
+ <widget class="QMainWindow" name="Notepad">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>524</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Notepad</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QTextEdit" name="textEdit"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>524</width>
+ <height>25</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuFile">
+ <property name="title">
+ <string>File</string>
+ </property>
+ <addaction name="actionNew"/>
+ <addaction name="actionOpen"/>
+ <addaction name="actionSave"/>
+ <addaction name="actionSave_as"/>
+ <addaction name="actionPrint"/>
+ <addaction name="separator"/>
+ <addaction name="actionExit"/>
+ </widget>
+ <widget class="QMenu" name="menuEdit">
+ <property name="title">
+ <string>Edit</string>
+ </property>
+ <addaction name="actionCopy"/>
+ <addaction name="actionCut"/>
+ <addaction name="actionPaste"/>
+ <addaction name="separator"/>
+ <addaction name="actionUndo"/>
+ <addaction name="actionRedo"/>
+ <addaction name="actionFont"/>
+ </widget>
+ <addaction name="menuFile"/>
+ <addaction name="menuEdit"/>
+ </widget>
+ <widget class="QToolBar" name="mainToolBar">
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ <addaction name="actionNew"/>
+ <addaction name="actionOpen"/>
+ <addaction name="actionSave"/>
+ <addaction name="actionSave_as"/>
+ <addaction name="actionPrint"/>
+ <addaction name="separator"/>
+ <addaction name="actionCopy"/>
+ <addaction name="actionCut"/>
+ <addaction name="actionPaste"/>
+ <addaction name="actionUndo"/>
+ <addaction name="actionRedo"/>
+ <addaction name="actionFont"/>
+ <addaction name="separator"/>
+ <addaction name="actionExit"/>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ <action name="actionNew">
+ <property name="icon">
+ <iconset resource="notepad.qrc">
+ <normaloff>:/images/new.png</normaloff>:/images/new.png</iconset>
+ </property>
+ <property name="text">
+ <string>New</string>
+ </property>
+ </action>
+ <action name="actionOpen">
+ <property name="icon">
+ <iconset>
+ <normaloff>:/images/open.png</normaloff>:/images/open.png</iconset>
+ </property>
+ <property name="text">
+ <string>Open</string>
+ </property>
+ </action>
+ <action name="actionSave">
+ <property name="icon">
+ <iconset>
+ <normaloff>:/images/save.png</normaloff>:/images/save.png</iconset>
+ </property>
+ <property name="text">
+ <string>Save</string>
+ </property>
+ </action>
+ <action name="actionSave_as">
+ <property name="icon">
+ <iconset>
+ <normaloff>:/images/save_as.png</normaloff>:/images/save_as.png</iconset>
+ </property>
+ <property name="text">
+ <string>Save as</string>
+ </property>
+ </action>
+ <action name="actionPrint">
+ <property name="icon">
+ <iconset>
+ <normaloff>:/images/print.png</normaloff>:/images/print.png</iconset>
+ </property>
+ <property name="text">
+ <string>Print</string>
+ </property>
+ </action>
+ <action name="actionExit">
+ <property name="icon">
+ <iconset>
+ <normaloff>:/images/exit.png</normaloff>:/images/exit.png</iconset>
+ </property>
+ <property name="text">
+ <string>Exit</string>
+ </property>
+ </action>
+ <action name="actionCopy">
+ <property name="icon">
+ <iconset>
+ <normaloff>:/images/copy.png</normaloff>:/images/copy.png</iconset>
+ </property>
+ <property name="text">
+ <string>Copy</string>
+ </property>
+ </action>
+ <action name="actionCut">
+ <property name="icon">
+ <iconset>
+ <normaloff>:/images/cut.png</normaloff>:/images/cut.png</iconset>
+ </property>
+ <property name="text">
+ <string>Cut</string>
+ </property>
+ </action>
+ <action name="actionPaste">
+ <property name="icon">
+ <iconset>
+ <normaloff>:/images/paste.png</normaloff>:/images/paste.png</iconset>
+ </property>
+ <property name="text">
+ <string>Paste</string>
+ </property>
+ </action>
+ <action name="actionUndo">
+ <property name="icon">
+ <iconset>
+ <normaloff>:/images/edit_undo.png</normaloff>:/images/edit_undo.png</iconset>
+ </property>
+ <property name="text">
+ <string>Undo</string>
+ </property>
+ </action>
+ <action name="actionRedo">
+ <property name="icon">
+ <iconset>
+ <normaloff>:/images/edit_redo.png</normaloff>:/images/edit_redo.png</iconset>
+ </property>
+ <property name="text">
+ <string>Redo</string>
+ </property>
+ </action>
+ <action name="actionFont">
+ <property name="icon">
+ <iconset>
+ <normaloff>:/images/font.png</normaloff>:/images/font.png</iconset>
+ </property>
+ <property name="text">
+ <string>Font</string>
+ </property>
+ </action>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources>
+ <include location="notepad.qrc"/>
+ </resources>
+ <connections/>
+</ui>
diff --git a/examples/widgets/tutorials/tutorials.pro b/examples/widgets/tutorials/tutorials.pro
index 2eb87cdbd5..0aaa119d8f 100644
--- a/examples/widgets/tutorials/tutorials.pro
+++ b/examples/widgets/tutorials/tutorials.pro
@@ -1,2 +1,2 @@
TEMPLATE = subdirs
-SUBDIRS += addressbook widgets modelview gettingStarted
+SUBDIRS += addressbook widgets modelview gettingStarted notepad
diff --git a/examples/widgets/tutorials/widgets/nestedlayouts/nestedlayouts.pro b/examples/widgets/tutorials/widgets/nestedlayouts/nestedlayouts.pro
index 33ee6e6cb0..d47fb15eef 100644
--- a/examples/widgets/tutorials/widgets/nestedlayouts/nestedlayouts.pro
+++ b/examples/widgets/tutorials/widgets/nestedlayouts/nestedlayouts.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(tableview))
SOURCES = main.cpp
diff --git a/examples/widgets/widgets/calendarwidget/calendarwidget.pro b/examples/widgets/widgets/calendarwidget/calendarwidget.pro
index a60f10bf36..4d130a48a1 100644
--- a/examples/widgets/widgets/calendarwidget/calendarwidget.pro
+++ b/examples/widgets/widgets/calendarwidget/calendarwidget.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = window.h
SOURCES = main.cpp \
diff --git a/examples/widgets/widgets/charactermap/charactermap.pro b/examples/widgets/widgets/charactermap/charactermap.pro
index 0450940c22..373aabca73 100644
--- a/examples/widgets/widgets/charactermap/charactermap.pro
+++ b/examples/widgets/widgets/charactermap/charactermap.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = characterwidget.h \
mainwindow.h
diff --git a/examples/widgets/widgets/elidedlabel/elidedlabel.pro b/examples/widgets/widgets/elidedlabel/elidedlabel.pro
index 1c135ed9c3..34040c92af 100644
--- a/examples/widgets/widgets/elidedlabel/elidedlabel.pro
+++ b/examples/widgets/widgets/elidedlabel/elidedlabel.pro
@@ -1,6 +1,7 @@
# Nokia Qt Examples: elided label example
QT += core gui widgets
+requires(qtConfig(combobox))
TARGET = elidedlabel
TEMPLATE = app
diff --git a/examples/widgets/widgets/icons/icons.pro b/examples/widgets/widgets/icons/icons.pro
index 450bdf9f8a..243ce6b092 100644
--- a/examples/widgets/widgets/icons/icons.pro
+++ b/examples/widgets/widgets/icons/icons.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = iconpreviewarea.h \
iconsizespinbox.h \
diff --git a/examples/widgets/widgets/imageviewer/imageviewer.pro b/examples/widgets/widgets/imageviewer/imageviewer.pro
index 4903a68537..d3db63ec20 100644
--- a/examples/widgets/widgets/imageviewer/imageviewer.pro
+++ b/examples/widgets/widgets/imageviewer/imageviewer.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
qtHaveModule(printsupport): QT += printsupport
HEADERS = imageviewer.h
diff --git a/examples/widgets/widgets/lineedits/lineedits.pro b/examples/widgets/widgets/lineedits/lineedits.pro
index 0ab994ea11..71f0e3e681 100644
--- a/examples/widgets/widgets/lineedits/lineedits.pro
+++ b/examples/widgets/widgets/lineedits/lineedits.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = window.h
SOURCES = main.cpp \
diff --git a/examples/widgets/widgets/movie/movie.pro b/examples/widgets/widgets/movie/movie.pro
index e3b9b5129c..f9f89109e4 100644
--- a/examples/widgets/widgets/movie/movie.pro
+++ b/examples/widgets/widgets/movie/movie.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
HEADERS = movieplayer.h
SOURCES = main.cpp \
diff --git a/examples/widgets/widgets/scribble/scribble.pro b/examples/widgets/widgets/scribble/scribble.pro
index aff0fb442c..56caaaf8e6 100644
--- a/examples/widgets/widgets/scribble/scribble.pro
+++ b/examples/widgets/widgets/scribble/scribble.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
qtHaveModule(printsupport): QT += printsupport
HEADERS = mainwindow.h \
diff --git a/examples/widgets/widgets/sliders/sliders.pro b/examples/widgets/widgets/sliders/sliders.pro
index 40c3167eea..963331779c 100644
--- a/examples/widgets/widgets/sliders/sliders.pro
+++ b/examples/widgets/widgets/sliders/sliders.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = slidersgroup.h \
window.h
diff --git a/examples/widgets/widgets/spinboxes/spinboxes.pro b/examples/widgets/widgets/spinboxes/spinboxes.pro
index 67fc9e2d34..832c3725c5 100644
--- a/examples/widgets/widgets/spinboxes/spinboxes.pro
+++ b/examples/widgets/widgets/spinboxes/spinboxes.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(datetimeedit))
HEADERS = window.h
SOURCES = main.cpp \
diff --git a/examples/widgets/widgets/styles/styles.pro b/examples/widgets/widgets/styles/styles.pro
index 235642f270..87dee7e04c 100644
--- a/examples/widgets/widgets/styles/styles.pro
+++ b/examples/widgets/widgets/styles/styles.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = norwegianwoodstyle.h \
widgetgallery.h
diff --git a/examples/widgets/widgets/stylesheet/stylesheet.pro b/examples/widgets/widgets/stylesheet/stylesheet.pro
index 7607006fad..0fe3187f63 100644
--- a/examples/widgets/widgets/stylesheet/stylesheet.pro
+++ b/examples/widgets/widgets/stylesheet/stylesheet.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
HEADERS = mainwindow.h \
stylesheeteditor.h
diff --git a/examples/widgets/widgets/tablet/mainwindow.cpp b/examples/widgets/widgets/tablet/mainwindow.cpp
index 0d63ac316b..feae16dd83 100644
--- a/examples/widgets/widgets/tablet/mainwindow.cpp
+++ b/examples/widgets/widgets/tablet/mainwindow.cpp
@@ -60,6 +60,7 @@ MainWindow::MainWindow(TabletCanvas *canvas)
createMenus();
setWindowTitle(tr("Tablet Example"));
setCentralWidget(m_canvas);
+ QCoreApplication::setAttribute(Qt::AA_CompressHighFrequencyEvents);
}
//! [0]
@@ -97,6 +98,11 @@ void MainWindow::setSaturationValuator(QAction *action)
}
//! [4]
+void MainWindow::setEventCompression(bool compress)
+{
+ QCoreApplication::setAttribute(Qt::AA_CompressTabletEvents, compress);
+}
+
//! [5]
void MainWindow::save()
{
@@ -220,6 +226,10 @@ void MainWindow::createMenus()
connect(colorSaturationGroup, &QActionGroup::triggered,
this, &MainWindow::setSaturationValuator);
+ QAction *compressAction = tabletMenu->addAction(tr("Co&mpress events"));
+ compressAction->setCheckable(true);
+ connect(compressAction, &QAction::toggled, this, &MainWindow::setEventCompression);
+
QMenu *helpMenu = menuBar()->addMenu("&Help");
helpMenu->addAction(tr("A&bout"), this, &MainWindow::about);
helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
diff --git a/examples/widgets/widgets/tablet/mainwindow.h b/examples/widgets/widgets/tablet/mainwindow.h
index 68af1f1687..4b99324f04 100644
--- a/examples/widgets/widgets/tablet/mainwindow.h
+++ b/examples/widgets/widgets/tablet/mainwindow.h
@@ -71,6 +71,7 @@ private slots:
void setAlphaValuator(QAction *action);
void setLineWidthValuator(QAction *action);
void setSaturationValuator(QAction *action);
+ void setEventCompression(bool compress);
void save();
void load();
void about();
diff --git a/examples/widgets/widgets/tablet/tablet.pro b/examples/widgets/widgets/tablet/tablet.pro
index 9b8927f483..5772cd0385 100644
--- a/examples/widgets/widgets/tablet/tablet.pro
+++ b/examples/widgets/widgets/tablet/tablet.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(filedialog))
HEADERS = mainwindow.h \
tabletcanvas.h \
diff --git a/examples/widgets/widgets/tablet/tabletcanvas.cpp b/examples/widgets/widgets/tablet/tabletcanvas.cpp
index 90b3222970..4b11568dfe 100644
--- a/examples/widgets/widgets/tablet/tabletcanvas.cpp
+++ b/examples/widgets/widgets/tablet/tabletcanvas.cpp
@@ -65,21 +65,9 @@ TabletCanvas::TabletCanvas()
, m_deviceDown(false)
{
resize(500, 500);
- initPixmap();
setAutoFillBackground(true);
setAttribute(Qt::WA_TabletTracking);
}
-
-void TabletCanvas::initPixmap()
-{
- QPixmap newPixmap = QPixmap(width(), height());
- newPixmap.fill(Qt::white);
- QPainter painter(&newPixmap);
- if (!m_pixmap.isNull())
- painter.drawPixmap(0, 0, m_pixmap);
- painter.end();
- m_pixmap = newPixmap;
-}
//! [0]
//! [1]
@@ -105,23 +93,26 @@ bool TabletCanvas::loadImage(const QString &file)
//! [3]
void TabletCanvas::tabletEvent(QTabletEvent *event)
{
-
switch (event->type()) {
case QEvent::TabletPress:
if (!m_deviceDown) {
m_deviceDown = true;
lastPoint.pos = event->posF();
+ lastPoint.pressure = event->pressure();
lastPoint.rotation = event->rotation();
}
break;
case QEvent::TabletMove:
+#ifndef Q_OS_IOS
if (event->device() == QTabletEvent::RotationStylus)
updateCursor(event);
+#endif
if (m_deviceDown) {
updateBrush(event);
QPainter painter(&m_pixmap);
paintPixmap(painter, event);
lastPoint.pos = event->posF();
+ lastPoint.pressure = event->pressure();
lastPoint.rotation = event->rotation();
}
break;
@@ -138,8 +129,23 @@ void TabletCanvas::tabletEvent(QTabletEvent *event)
//! [3]
//! [4]
+void TabletCanvas::initPixmap()
+{
+ qreal dpr = devicePixelRatioF();
+ QPixmap newPixmap = QPixmap(width() * dpr, height() * dpr);
+ newPixmap.setDevicePixelRatio(dpr);
+ newPixmap.fill(Qt::white);
+ QPainter painter(&newPixmap);
+ if (!m_pixmap.isNull())
+ painter.drawPixmap(0, 0, m_pixmap);
+ painter.end();
+ m_pixmap = newPixmap;
+}
+
void TabletCanvas::paintEvent(QPaintEvent *)
{
+ if (m_pixmap.isNull())
+ initPixmap();
QPainter painter(this);
painter.drawPixmap(0, 0, m_pixmap);
}
@@ -171,13 +177,14 @@ void TabletCanvas::paintPixmap(QPainter &painter, QTabletEvent *event)
painter.setPen(Qt::NoPen);
painter.setBrush(m_brush);
QPolygonF poly;
- qreal halfWidth = m_pen.widthF();
- QPointF brushAdjust(qSin(qDegreesToRadians(lastPoint.rotation)) * halfWidth,
- qCos(qDegreesToRadians(lastPoint.rotation)) * halfWidth);
+ qreal halfWidth = pressureToWidth(lastPoint.pressure);
+ QPointF brushAdjust(qSin(qDegreesToRadians(-lastPoint.rotation)) * halfWidth,
+ qCos(qDegreesToRadians(-lastPoint.rotation)) * halfWidth);
poly << lastPoint.pos + brushAdjust;
poly << lastPoint.pos - brushAdjust;
- brushAdjust = QPointF(qSin(qDegreesToRadians(event->rotation())) * halfWidth,
- qCos(qDegreesToRadians(event->rotation())) * halfWidth);
+ halfWidth = m_pen.widthF();
+ brushAdjust = QPointF(qSin(qDegreesToRadians(-event->rotation())) * halfWidth,
+ qCos(qDegreesToRadians(-event->rotation())) * halfWidth);
poly << event->posF() - brushAdjust;
poly << event->posF() + brushAdjust;
painter.drawConvexPolygon(poly);
@@ -215,6 +222,11 @@ void TabletCanvas::paintPixmap(QPainter &painter, QTabletEvent *event)
}
//! [5]
+qreal TabletCanvas::pressureToWidth(qreal pressure)
+{
+ return pressure * 10 + 1;
+}
+
//! [7]
void TabletCanvas::updateBrush(const QTabletEvent *event)
{
@@ -260,7 +272,7 @@ void TabletCanvas::updateBrush(const QTabletEvent *event)
//! [9] //! [10]
switch (m_lineWidthValuator) {
case PressureValuator:
- m_pen.setWidthF(event->pressure() * 10 + 1);
+ m_pen.setWidthF(pressureToWidth(event->pressure()));
break;
case TiltValuator:
m_pen.setWidthF(maximum(abs(vValue - 127), abs(hValue - 127)) / 12);
@@ -305,7 +317,7 @@ void TabletCanvas::updateCursor(const QTabletEvent *event)
QPainter painter(&img);
QTransform transform = painter.transform();
transform.translate(16, 16);
- transform.rotate(-event->rotation());
+ transform.rotate(event->rotation());
painter.setTransform(transform);
painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
painter.drawImage(-24, -24, origImg);
diff --git a/examples/widgets/widgets/tablet/tabletcanvas.h b/examples/widgets/widgets/tablet/tabletcanvas.h
index 1784e05916..a1b31c65bf 100644
--- a/examples/widgets/widgets/tablet/tabletcanvas.h
+++ b/examples/widgets/widgets/tablet/tabletcanvas.h
@@ -103,6 +103,7 @@ private:
void initPixmap();
void paintPixmap(QPainter &painter, QTabletEvent *event);
Qt::BrushStyle brushPattern(qreal value);
+ qreal pressureToWidth(qreal pressure);
void updateBrush(const QTabletEvent *event);
void updateCursor(const QTabletEvent *event);
@@ -117,6 +118,7 @@ private:
struct Point {
QPointF pos;
+ qreal pressure;
qreal rotation;
} lastPoint;
};
diff --git a/examples/widgets/widgets/tetrix/main.cpp b/examples/widgets/widgets/tetrix/main.cpp
index 886e94de7c..2698190e76 100644
--- a/examples/widgets/widgets/tetrix/main.cpp
+++ b/examples/widgets/widgets/tetrix/main.cpp
@@ -59,6 +59,5 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
TetrixWindow window;
window.show();
- qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
return app.exec();
}
diff --git a/examples/widgets/widgets/tetrix/tetrixpiece.cpp b/examples/widgets/widgets/tetrix/tetrixpiece.cpp
index 69e1733ac4..3d8fa86860 100644
--- a/examples/widgets/widgets/tetrix/tetrixpiece.cpp
+++ b/examples/widgets/widgets/tetrix/tetrixpiece.cpp
@@ -57,7 +57,7 @@
//! [0]
void TetrixPiece::setRandomShape()
{
- setShape(TetrixShape(qrand() % 7 + 1));
+ setShape(TetrixShape(QRandomGenerator::global()->bounded(7) + 1));
}
//! [0]
diff --git a/examples/widgets/widgets/tooltips/main.cpp b/examples/widgets/widgets/tooltips/main.cpp
index 3c64a33a4c..8276b3dc8d 100644
--- a/examples/widgets/widgets/tooltips/main.cpp
+++ b/examples/widgets/widgets/tooltips/main.cpp
@@ -57,7 +57,6 @@ int main(int argc, char *argv[])
Q_INIT_RESOURCE(tooltips);
QApplication app(argc, argv);
- qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
SortingBox sortingBox;
sortingBox.show();
return app.exec();
diff --git a/examples/widgets/widgets/tooltips/sortingbox.cpp b/examples/widgets/widgets/tooltips/sortingbox.cpp
index c15fdcf95b..4769a30c64 100644
--- a/examples/widgets/widgets/tooltips/sortingbox.cpp
+++ b/examples/widgets/widgets/tooltips/sortingbox.cpp
@@ -292,7 +292,7 @@ QPoint SortingBox::initialItemPosition(const QPainterPath &path)
//! [24]
QPoint SortingBox::randomItemPosition()
{
- return QPoint(qrand() % (width() - 120), qrand() % (height() - 120));
+ return QPoint(QRandomGenerator::global()->bounded(width() - 120), QRandomGenerator::global()->bounded(height() - 120));
}
//! [24]
@@ -306,6 +306,6 @@ QColor SortingBox::initialItemColor()
//! [26]
QColor SortingBox::randomItemColor()
{
- return QColor::fromHsv(qrand() % 256, 255, 190);
+ return QColor::fromHsv(QRandomGenerator::global()->bounded(256), 255, 190);
}
//! [26]
diff --git a/examples/widgets/widgets/validators/validators.pro b/examples/widgets/widgets/validators/validators.pro
index 68805f33d3..ab1eb7809b 100644
--- a/examples/widgets/widgets/validators/validators.pro
+++ b/examples/widgets/widgets/validators/validators.pro
@@ -1,4 +1,5 @@
QT += widgets
+requires(qtConfig(combobox))
FORMS += validators.ui
RESOURCES += validators.qrc