summaryrefslogtreecommitdiffstats
path: root/examples/widgets/tools/plugandpaint/app/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/tools/plugandpaint/app/mainwindow.cpp')
-rw-r--r--examples/widgets/tools/plugandpaint/app/mainwindow.cpp83
1 files changed, 41 insertions, 42 deletions
diff --git a/examples/widgets/tools/plugandpaint/app/mainwindow.cpp b/examples/widgets/tools/plugandpaint/app/mainwindow.cpp
index 12c65e9364..ebe1150eea 100644
--- a/examples/widgets/tools/plugandpaint/app/mainwindow.cpp
+++ b/examples/widgets/tools/plugandpaint/app/mainwindow.cpp
@@ -54,19 +54,18 @@
#include "paintarea.h"
#include "plugindialog.h"
-#include <QPluginLoader>
-#include <QTimer>
-
-#include <QScrollArea>
-#include <QMessageBox>
-#include <QActionGroup>
#include <QAction>
-#include <QMenu>
-#include <QMenuBar>
-#include <QFileDialog>
+#include <QActionGroup>
+#include <QApplication>
#include <QColorDialog>
+#include <QFileDialog>
#include <QInputDialog>
-#include <QApplication>
+#include <QMenu>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QPluginLoader>
+#include <QScrollArea>
+#include <QTimer>
MainWindow::MainWindow() :
paintArea(new PaintArea),
@@ -85,7 +84,7 @@ MainWindow::MainWindow() :
if (!brushActionGroup->actions().isEmpty())
brushActionGroup->actions().first()->trigger();
- QTimer::singleShot(500, this, SLOT(aboutPlugins()));
+ QTimer::singleShot(500, this, &MainWindow::aboutPlugins);
}
void MainWindow::open()
@@ -109,11 +108,10 @@ bool MainWindow::saveAs()
const QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
initialPath);
- if (fileName.isEmpty()) {
+ if (fileName.isEmpty())
return false;
- } else {
- return paintArea->saveImage(fileName, "png");
- }
+
+ return paintArea->saveImage(fileName, "png");
}
void MainWindow::brushColor()
@@ -137,8 +135,8 @@ void MainWindow::brushWidth()
//! [0]
void MainWindow::changeBrush()
{
- QAction *action = qobject_cast<QAction *>(sender());
- BrushInterface *iBrush = qobject_cast<BrushInterface *>(action->parent());
+ auto action = qobject_cast<QAction *>(sender());
+ auto iBrush = qobject_cast<BrushInterface *>(action->parent());
const QString brush = action->text();
paintArea->setBrush(iBrush, brush);
@@ -148,8 +146,8 @@ void MainWindow::changeBrush()
//! [1]
void MainWindow::insertShape()
{
- QAction *action = qobject_cast<QAction *>(sender());
- ShapeInterface *iShape = qobject_cast<ShapeInterface *>(action->parent());
+ auto action = qobject_cast<QAction *>(sender());
+ auto iShape = qobject_cast<ShapeInterface *>(action->parent());
const QPainterPath path = iShape->generateShape(action->text(), this);
if (!path.isEmpty())
@@ -160,9 +158,8 @@ void MainWindow::insertShape()
//! [2]
void MainWindow::applyFilter()
{
- QAction *action = qobject_cast<QAction *>(sender());
- FilterInterface *iFilter =
- qobject_cast<FilterInterface *>(action->parent());
+ auto action = qobject_cast<QAction *>(sender());
+ auto iFilter = qobject_cast<FilterInterface *>(action->parent());
const QImage image = iFilter->filterImage(action->text(), paintArea->image(),
this);
@@ -189,32 +186,32 @@ void MainWindow::createActions()
{
openAct = new QAction(tr("&Open..."), this);
openAct->setShortcuts(QKeySequence::Open);
- connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+ connect(openAct, &QAction::triggered, this, &MainWindow::open);
saveAsAct = new QAction(tr("&Save As..."), this);
saveAsAct->setShortcuts(QKeySequence::SaveAs);
- connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
+ connect(saveAsAct, &QAction::triggered, this, &MainWindow::saveAs);
exitAct = new QAction(tr("E&xit"), this);
exitAct->setShortcuts(QKeySequence::Quit);
- connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+ connect(exitAct, &QAction::triggered, this, &MainWindow::close);
brushColorAct = new QAction(tr("&Brush Color..."), this);
- connect(brushColorAct, SIGNAL(triggered()), this, SLOT(brushColor()));
+ connect(brushColorAct, &QAction::triggered, this, &MainWindow::brushColor);
brushWidthAct = new QAction(tr("&Brush Width..."), this);
- connect(brushWidthAct, SIGNAL(triggered()), this, SLOT(brushWidth()));
+ connect(brushWidthAct, &QAction::triggered, this, &MainWindow::brushWidth);
brushActionGroup = new QActionGroup(this);
aboutAct = new QAction(tr("&About"), this);
- connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+ connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
aboutQtAct = new QAction(tr("About &Qt"), this);
- connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+ connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
aboutPluginsAct = new QAction(tr("About &Plugins"), this);
- connect(aboutPluginsAct, SIGNAL(triggered()), this, SLOT(aboutPlugins()));
+ connect(aboutPluginsAct, &QAction::triggered, this, &MainWindow::aboutPlugins);
}
void MainWindow::createMenus()
@@ -245,7 +242,8 @@ void MainWindow::createMenus()
//! [4]
void MainWindow::loadPlugins()
{
- foreach (QObject *plugin, QPluginLoader::staticInstances())
+ const auto staticInstances = QPluginLoader::staticInstances();
+ for (QObject *plugin : staticInstances)
populateMenus(plugin);
//! [4] //! [5]
@@ -265,7 +263,8 @@ void MainWindow::loadPlugins()
//! [5]
//! [6]
- foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
+ const auto entryList = pluginsDir.entryList(QDir::Files);
+ for (const QString &fileName : entryList) {
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
QObject *plugin = loader.instance();
if (plugin) {
@@ -287,28 +286,28 @@ void MainWindow::loadPlugins()
//! [10]
void MainWindow::populateMenus(QObject *plugin)
{
- BrushInterface *iBrush = qobject_cast<BrushInterface *>(plugin);
+ auto iBrush = qobject_cast<BrushInterface *>(plugin);
if (iBrush)
- addToMenu(plugin, iBrush->brushes(), brushMenu, SLOT(changeBrush()),
+ addToMenu(plugin, iBrush->brushes(), brushMenu, &MainWindow::changeBrush,
brushActionGroup);
- ShapeInterface *iShape = qobject_cast<ShapeInterface *>(plugin);
+ auto iShape = qobject_cast<ShapeInterface *>(plugin);
if (iShape)
- addToMenu(plugin, iShape->shapes(), shapesMenu, SLOT(insertShape()));
+ addToMenu(plugin, iShape->shapes(), shapesMenu, &MainWindow::insertShape);
- FilterInterface *iFilter = qobject_cast<FilterInterface *>(plugin);
+ auto iFilter = qobject_cast<FilterInterface *>(plugin);
if (iFilter)
- addToMenu(plugin, iFilter->filters(), filterMenu, SLOT(applyFilter()));
+ addToMenu(plugin, iFilter->filters(), filterMenu, &MainWindow::applyFilter);
}
//! [10]
void MainWindow::addToMenu(QObject *plugin, const QStringList &texts,
- QMenu *menu, const char *member,
+ QMenu *menu, Member member,
QActionGroup *actionGroup)
{
- foreach (QString text, texts) {
- QAction *action = new QAction(text, plugin);
- connect(action, SIGNAL(triggered()), this, member);
+ for (const QString &text : texts) {
+ auto action = new QAction(text, plugin);
+ connect(action, &QAction::triggered, this, member);
menu->addAction(action);
if (actionGroup) {