summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2014-07-01 10:03:53 +0200
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2014-07-01 16:25:19 +0200
commita09a8d509a69ed16d8afbe15296b8332cacd6c66 (patch)
tree28645b437fd0390d903f753a44ba79626eecb8ac /examples
parent4b28152da64f7f23a1bbb810d8cdb7626a5f0b8e (diff)
parent83f06da1c6bffff61af78cbe75a0691d53742b53 (diff)
downloadqtbase-a09a8d509a69ed16d8afbe15296b8332cacd6c66.tar.gz
qtbase-a09a8d509a69ed16d8afbe15296b8332cacd6c66.tar.bz2
qtbase-a09a8d509a69ed16d8afbe15296b8332cacd6c66.zip
Merge remote-tracking branch 'origin/5.3' into dev
Conflicts: mkspecs/qnx-x86-qcc/qplatformdefs.h src/corelib/global/qglobal.h src/network/socket/qnativesocketengine_winrt.cpp src/plugins/platforms/android/androidjniaccessibility.cpp src/plugins/platforms/windows/qwindowswindow.cpp Manually adjusted: mkspecs/qnx-armle-v7-qcc/qplatformdefs.h to include 9ce697f2d54be6d94381c72af28dda79cbc027d4 Thanks goes to Sergio for the qnx mkspecs adjustments. Change-Id: I53b1fd6bc5bc884e5ee2c2b84975f58171a1cb8e
Diffstat (limited to 'examples')
-rw-r--r--examples/widgets/doc/src/basiclayouts.qdoc22
-rw-r--r--examples/widgets/doc/src/borderlayout.qdoc11
-rw-r--r--examples/widgets/doc/src/dynamiclayouts.qdoc12
-rw-r--r--examples/widgets/doc/src/flowlayout.qdoc17
-rw-r--r--examples/widgets/doc/src/imageviewer.qdoc21
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.cpp68
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.h3
-rw-r--r--examples/widgets/widgets/imageviewer/main.cpp12
8 files changed, 109 insertions, 57 deletions
diff --git a/examples/widgets/doc/src/basiclayouts.qdoc b/examples/widgets/doc/src/basiclayouts.qdoc
index d219b7bff3..0066317165 100644
--- a/examples/widgets/doc/src/basiclayouts.qdoc
+++ b/examples/widgets/doc/src/basiclayouts.qdoc
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
@@ -28,31 +28,35 @@
/*!
\example layouts/basiclayouts
\title Basic Layouts Example
+ \brief Shows how to use the standard layout managers.
- \brief The Basic Layouts example shows how to use the standard layout
- managers that are available in Qt: QBoxLayout, QGridLayout and
- QFormLayout.
+ \e{Basic Layouts} shows how to use the standard layout managers that are
+ available in Qt: QBoxLayout, QGridLayout, and QFormLayout.
\image basiclayouts-example.png Screenshot of the Basic Layouts example
The QBoxLayout class lines up widgets horizontally or vertically.
QHBoxLayout and QVBoxLayout are convenience subclasses of QBoxLayout.
QGridLayout lays out widgets in cells by dividing the available space
- into rows and columns. QFormLayout, on the other hand, lays out its
+ into rows and columns. QFormLayout, on the other hand, sets its
children in a two-column form with labels in the left column and
input fields in the right column.
+ For more information, visit the \l{Layout Management} page.
+
+ \include examples-run.qdocinc
+
\section1 Dialog Class Definition
\snippet layouts/basiclayouts/dialog.h 0
The \c Dialog class inherits QDialog. It is a custom widget that
displays its child widgets using the geometry managers:
- QHBoxLayout, QVBoxLayout, QGridLayout and QFormLayout.
+ QHBoxLayout, QVBoxLayout, QGridLayout, and QFormLayout.
- We declare four private functions to simplify the class
- constructor: The \c createMenu(), \c createHorizontalGroupBox(),
- \c createGridGroupBox() and \c createFormGroupBox() functions create
+ There are four private functions to simplify the class
+ constructor: the \c createMenu(), \c createHorizontalGroupBox(),
+ \c createGridGroupBox(), and \c createFormGroupBox() functions create
several widgets that the example uses to demonstrate how the layout
affects their appearances.
diff --git a/examples/widgets/doc/src/borderlayout.qdoc b/examples/widgets/doc/src/borderlayout.qdoc
index 8a2958ee80..03a2bf1672 100644
--- a/examples/widgets/doc/src/borderlayout.qdoc
+++ b/examples/widgets/doc/src/borderlayout.qdoc
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
@@ -28,9 +28,14 @@
/*!
\example layouts/borderlayout
\title Border Layout Example
+ \brief Shows how to arrange child widgets along a border.
- \brief The Border Layout example shows how to create a custom layout that arranges
- child widgets according to a simple set of rules.
+ \e{Border Layout} implements a layout that arranges child widgets to
+ surround the main area.
\image borderlayout-example.png
+
+ For more information, visit the \l{Layout Management} page.
+
+ \include examples-run.qdocinc
*/
diff --git a/examples/widgets/doc/src/dynamiclayouts.qdoc b/examples/widgets/doc/src/dynamiclayouts.qdoc
index 5590ec61f1..497a0d23fd 100644
--- a/examples/widgets/doc/src/dynamiclayouts.qdoc
+++ b/examples/widgets/doc/src/dynamiclayouts.qdoc
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
@@ -28,7 +28,13 @@
/*!
\example layouts/dynamiclayouts
\title Dynamic Layouts Example
+ \brief Shows how to re-orient widgets in running applications.
- \brief The Dynamic Layouts example shows how to move widgets around in
- existing layouts.
+ \e{Dynamic Layouts} implements dynamically placed widgets within running
+ applications. The widget placement depends on whether \c Horizontal or \c
+ Vertical is chosen.
+
+ For more information, visit the \l{Layout Management} page.
+
+ \include examples-run.qdocinc
*/
diff --git a/examples/widgets/doc/src/flowlayout.qdoc b/examples/widgets/doc/src/flowlayout.qdoc
index b482edf946..84de22416c 100644
--- a/examples/widgets/doc/src/flowlayout.qdoc
+++ b/examples/widgets/doc/src/flowlayout.qdoc
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
@@ -28,18 +28,19 @@
/*!
\example layouts/flowlayout
\title Flow Layout Example
+ \brief Shows how to arrange widgets for different window sizes.
- \brief The Flow Layout example demonstrates a custom layout that arranges child
- widgets from left to right and top to bottom in a top-level widget.
+ \e{Flow Layout} implements a layout that handles different window sizes. The
+ widget placement changes depending on the width of the application window.
\image flowlayout-example.png Screenshot of the Flow Layout example
- The items are first laid out horizontally and then vertically when each line
- in the layout runs out of space.
-
The Flowlayout class mainly uses QLayout and QWidgetItem, while the
- Window uses QWidget and QLabel. We will only document the definition
- and implementation of \c FlowLayout below.
+ Window uses QWidget and QLabel.
+
+ For more information, visit the \l{Layout Management} page.
+
+ \include examples-run.qdocinc
\section1 FlowLayout Class Definition
diff --git a/examples/widgets/doc/src/imageviewer.qdoc b/examples/widgets/doc/src/imageviewer.qdoc
index 96013e844a..6361e3f35b 100644
--- a/examples/widgets/doc/src/imageviewer.qdoc
+++ b/examples/widgets/doc/src/imageviewer.qdoc
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
@@ -112,15 +112,19 @@
{ImageViewer}'s appearance.
\snippet widgets/imageviewer/imageviewer.cpp 1
- \snippet widgets/imageviewer/imageviewer.cpp 2
- In the \c open() slot, we show a file dialog to the user. The
- easiest way to create a QFileDialog is to use the static
- convenience functions. QFileDialog::getOpenFileName() returns an
- existing file selected by the user. If the user presses \uicontrol
- Cancel, QFileDialog returns an empty string.
+ In the \c open() slot, we show a file dialog to the user. We compile
+ a list of mime types for use as a filter by querying QImageReader
+ for the available mime type names.
+
+ We show the file dialog until a valid file name is entered or
+ the user cancels.
+
+ The function \c loadFile() is used to load the image.
+
+ \snippet widgets/imageviewer/imageviewer.cpp 2
- Unless the file name is a empty string, we check if the file's
+ In the \c loadFile() function, we check if the file's
format is an image format by constructing a QImage which tries to
load the image from the file. If the constructor returns a null
image, we use a QMessageBox to alert the user.
@@ -135,7 +139,6 @@
information message with an \uicontrol OK button (the default) is
sufficient, since the message is part of a normal operation.
- \snippet widgets/imageviewer/imageviewer.cpp 3
\snippet widgets/imageviewer/imageviewer.cpp 4
If the format is supported, we display the image in \c imageLabel
diff --git a/examples/widgets/widgets/imageviewer/imageviewer.cpp b/examples/widgets/widgets/imageviewer/imageviewer.cpp
index 77ec92d57a..eae94a2499 100644
--- a/examples/widgets/widgets/imageviewer/imageviewer.cpp
+++ b/examples/widgets/widgets/imageviewer/imageviewer.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -61,39 +61,61 @@ ImageViewer::ImageViewer()
createActions();
createMenus();
- setWindowTitle(tr("Image Viewer"));
- resize(500, 400);
+ resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5);
}
+
//! [0]
+//! [2]
-//! [1]
-void ImageViewer::open()
-//! [1] //! [2]
+bool ImageViewer::loadFile(const QString &fileName)
{
- QString fileName = QFileDialog::getOpenFileName(this,
- tr("Open File"), QDir::currentPath());
- if (!fileName.isEmpty()) {
- QImage image(fileName);
- if (image.isNull()) {
- QMessageBox::information(this, tr("Image Viewer"),
- tr("Cannot load %1.").arg(fileName));
- return;
- }
+ QImage image(fileName);
+ if (image.isNull()) {
+ QMessageBox::information(this, QGuiApplication::applicationDisplayName(),
+ tr("Cannot load %1.").arg(QDir::toNativeSeparators(fileName)));
+ setWindowFilePath(QString());
+ imageLabel->setPixmap(QPixmap());
+ imageLabel->adjustSize();
+ return false;
+ }
//! [2] //! [3]
- imageLabel->setPixmap(QPixmap::fromImage(image));
+ imageLabel->setPixmap(QPixmap::fromImage(image));
//! [3] //! [4]
- scaleFactor = 1.0;
+ scaleFactor = 1.0;
+
+ printAct->setEnabled(true);
+ fitToWindowAct->setEnabled(true);
+ updateActions();
- printAct->setEnabled(true);
- fitToWindowAct->setEnabled(true);
- updateActions();
+ if (!fitToWindowAct->isChecked())
+ imageLabel->adjustSize();
- if (!fitToWindowAct->isChecked())
- imageLabel->adjustSize();
- }
+ setWindowFilePath(fileName);
+ return true;
}
+
//! [4]
+//! [2]
+
+//! [1]
+void ImageViewer::open()
+{
+ QStringList mimeTypeFilters;
+ foreach (const QByteArray &mimeTypeName, QImageReader::supportedMimeTypes())
+ mimeTypeFilters.append(mimeTypeName);
+ mimeTypeFilters.sort();
+ const QStringList picturesLocations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation);
+ QFileDialog dialog(this, tr("Open File"),
+ picturesLocations.isEmpty() ? QDir::currentPath() : picturesLocations.first());
+ dialog.setAcceptMode(QFileDialog::AcceptOpen);
+ dialog.setMimeTypeFilters(mimeTypeFilters);
+ dialog.selectMimeTypeFilter("image/jpeg");
+
+ while (dialog.exec() == QDialog::Accepted && !loadFile(dialog.selectedFiles().first())) {}
+}
+//! [1]
+
//! [5]
void ImageViewer::print()
//! [5] //! [6]
diff --git a/examples/widgets/widgets/imageviewer/imageviewer.h b/examples/widgets/widgets/imageviewer/imageviewer.h
index 7a0f0eb845..a4fd82a696 100644
--- a/examples/widgets/widgets/imageviewer/imageviewer.h
+++ b/examples/widgets/widgets/imageviewer/imageviewer.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -61,6 +61,7 @@ class ImageViewer : public QMainWindow
public:
ImageViewer();
+ bool loadFile(const QString &);
private slots:
void open();
diff --git a/examples/widgets/widgets/imageviewer/main.cpp b/examples/widgets/widgets/imageviewer/main.cpp
index f1697f9e3f..ee66b29591 100644
--- a/examples/widgets/widgets/imageviewer/main.cpp
+++ b/examples/widgets/widgets/imageviewer/main.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -39,13 +39,23 @@
****************************************************************************/
#include <QApplication>
+#include <QCommandLineParser>
#include "imageviewer.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
+ QGuiApplication::setApplicationDisplayName(ImageViewer::tr("Image Viewer"));
+ QCommandLineParser commandLineParser;
+ commandLineParser.addHelpOption();
+ commandLineParser.addPositionalArgument(ImageViewer::tr("[file]"), ImageViewer::tr("Image file to open."));
+ commandLineParser.process(QCoreApplication::arguments());
ImageViewer imageViewer;
+ if (!commandLineParser.positionalArguments().isEmpty()
+ && !imageViewer.loadFile(commandLineParser.positionalArguments().front())) {
+ return -1;
+ }
imageViewer.show();
return app.exec();
}