Cleanup Widgets examples - new signal/slot syntax

Cleanup the Widget examples - use the new signal/slot syntax where
possible - painting and richtext subdirectory

Change-Id: If0e365ab1cabf9184076595494cfca151406fddf
Reviewed-by: Luca Beldi <v.ronin@yahoo.it>
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
This commit is contained in:
Christian Ehrlicher 2018-12-07 14:17:02 +01:00
parent 283008e123
commit cf27d9e8a5
14 changed files with 160 additions and 139 deletions

View File

@ -157,22 +157,22 @@ Window::Window()
//! [7] //! [7]
//! [8] //! [8]
connect(shapeComboBox, SIGNAL(activated(int)), connect(shapeComboBox, QOverload<int>::of(&QComboBox::activated),
this, SLOT(shapeChanged())); this, &Window::shapeChanged);
connect(penWidthSpinBox, SIGNAL(valueChanged(int)), connect(penWidthSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
this, SLOT(penChanged())); this, &Window::penChanged);
connect(penStyleComboBox, SIGNAL(activated(int)), connect(penStyleComboBox, QOverload<int>::of(&QComboBox::activated),
this, SLOT(penChanged())); this, &Window::penChanged);
connect(penCapComboBox, SIGNAL(activated(int)), connect(penCapComboBox, QOverload<int>::of(&QComboBox::activated),
this, SLOT(penChanged())); this, &Window::penChanged);
connect(penJoinComboBox, SIGNAL(activated(int)), connect(penJoinComboBox, QOverload<int>::of(&QComboBox::activated),
this, SLOT(penChanged())); this, &Window::penChanged);
connect(brushStyleComboBox, SIGNAL(activated(int)), connect(brushStyleComboBox, QOverload<int>::of(&QComboBox::activated),
this, SLOT(brushChanged())); this, &Window::brushChanged);
connect(antialiasingCheckBox, SIGNAL(toggled(bool)), connect(antialiasingCheckBox, &QAbstractButton::toggled,
renderArea, SLOT(setAntialiased(bool))); renderArea, &RenderArea::setAntialiased);
connect(transformationsCheckBox, SIGNAL(toggled(bool)), connect(transformationsCheckBox, &QAbstractButton::toggled,
renderArea, SLOT(setTransformed(bool))); renderArea, &RenderArea::setTransformed);
//! [8] //! [8]
//! [9] //! [9]

View File

@ -76,68 +76,68 @@ CompositionWidget::CompositionWidget(QWidget *parent)
modesGroup->setTitle(tr("Mode")); modesGroup->setTitle(tr("Mode"));
rbClear = new QRadioButton(tr("Clear"), modesGroup); rbClear = new QRadioButton(tr("Clear"), modesGroup);
connect(rbClear, SIGNAL(clicked()), view, SLOT(setClearMode())); connect(rbClear, &QAbstractButton::clicked, view, &CompositionRenderer::setClearMode);
rbSource = new QRadioButton(tr("Source"), modesGroup); rbSource = new QRadioButton(tr("Source"), modesGroup);
connect(rbSource, SIGNAL(clicked()), view, SLOT(setSourceMode())); connect(rbSource, &QAbstractButton::clicked, view, &CompositionRenderer::setSourceMode);
rbDest = new QRadioButton(tr("Destination"), modesGroup); rbDest = new QRadioButton(tr("Destination"), modesGroup);
connect(rbDest, SIGNAL(clicked()), view, SLOT(setDestMode())); connect(rbDest, &QAbstractButton::clicked, view, &CompositionRenderer::setDestMode);
rbSourceOver = new QRadioButton(tr("Source Over"), modesGroup); rbSourceOver = new QRadioButton(tr("Source Over"), modesGroup);
connect(rbSourceOver, SIGNAL(clicked()), view, SLOT(setSourceOverMode())); connect(rbSourceOver, &QAbstractButton::clicked, view, &CompositionRenderer::setSourceOverMode);
rbDestOver = new QRadioButton(tr("Destination Over"), modesGroup); rbDestOver = new QRadioButton(tr("Destination Over"), modesGroup);
connect(rbDestOver, SIGNAL(clicked()), view, SLOT(setDestOverMode())); connect(rbDestOver, &QAbstractButton::clicked, view, &CompositionRenderer::setDestOverMode);
rbSourceIn = new QRadioButton(tr("Source In"), modesGroup); rbSourceIn = new QRadioButton(tr("Source In"), modesGroup);
connect(rbSourceIn, SIGNAL(clicked()), view, SLOT(setSourceInMode())); connect(rbSourceIn, &QAbstractButton::clicked, view, &CompositionRenderer::setSourceInMode);
rbDestIn = new QRadioButton(tr("Dest In"), modesGroup); rbDestIn = new QRadioButton(tr("Dest In"), modesGroup);
connect(rbDestIn, SIGNAL(clicked()), view, SLOT(setDestInMode())); connect(rbDestIn, &QAbstractButton::clicked, view, &CompositionRenderer::setDestInMode);
rbSourceOut = new QRadioButton(tr("Source Out"), modesGroup); rbSourceOut = new QRadioButton(tr("Source Out"), modesGroup);
connect(rbSourceOut, SIGNAL(clicked()), view, SLOT(setSourceOutMode())); connect(rbSourceOut, &QAbstractButton::clicked, view, &CompositionRenderer::setSourceOutMode);
rbDestOut = new QRadioButton(tr("Dest Out"), modesGroup); rbDestOut = new QRadioButton(tr("Dest Out"), modesGroup);
connect(rbDestOut, SIGNAL(clicked()), view, SLOT(setDestOutMode())); connect(rbDestOut, &QAbstractButton::clicked, view, &CompositionRenderer::setDestOutMode);
rbSourceAtop = new QRadioButton(tr("Source Atop"), modesGroup); rbSourceAtop = new QRadioButton(tr("Source Atop"), modesGroup);
connect(rbSourceAtop, SIGNAL(clicked()), view, SLOT(setSourceAtopMode())); connect(rbSourceAtop, &QAbstractButton::clicked, view, &CompositionRenderer::setSourceAtopMode);
rbDestAtop = new QRadioButton(tr("Dest Atop"), modesGroup); rbDestAtop = new QRadioButton(tr("Dest Atop"), modesGroup);
connect(rbDestAtop, SIGNAL(clicked()), view, SLOT(setDestAtopMode())); connect(rbDestAtop, &QAbstractButton::clicked, view, &CompositionRenderer::setDestAtopMode);
rbXor = new QRadioButton(tr("Xor"), modesGroup); rbXor = new QRadioButton(tr("Xor"), modesGroup);
connect(rbXor, SIGNAL(clicked()), view, SLOT(setXorMode())); connect(rbXor, &QAbstractButton::clicked, view, &CompositionRenderer::setXorMode);
rbPlus = new QRadioButton(tr("Plus"), modesGroup); rbPlus = new QRadioButton(tr("Plus"), modesGroup);
connect(rbPlus, SIGNAL(clicked()), view, SLOT(setPlusMode())); connect(rbPlus, &QAbstractButton::clicked, view, &CompositionRenderer::setPlusMode);
rbMultiply = new QRadioButton(tr("Multiply"), modesGroup); rbMultiply = new QRadioButton(tr("Multiply"), modesGroup);
connect(rbMultiply, SIGNAL(clicked()), view, SLOT(setMultiplyMode())); connect(rbMultiply, &QAbstractButton::clicked, view, &CompositionRenderer::setMultiplyMode);
rbScreen = new QRadioButton(tr("Screen"), modesGroup); rbScreen = new QRadioButton(tr("Screen"), modesGroup);
connect(rbScreen, SIGNAL(clicked()), view, SLOT(setScreenMode())); connect(rbScreen, &QAbstractButton::clicked, view, &CompositionRenderer::setScreenMode);
rbOverlay = new QRadioButton(tr("Overlay"), modesGroup); rbOverlay = new QRadioButton(tr("Overlay"), modesGroup);
connect(rbOverlay, SIGNAL(clicked()), view, SLOT(setOverlayMode())); connect(rbOverlay, &QAbstractButton::clicked, view, &CompositionRenderer::setOverlayMode);
rbDarken = new QRadioButton(tr("Darken"), modesGroup); rbDarken = new QRadioButton(tr("Darken"), modesGroup);
connect(rbDarken, SIGNAL(clicked()), view, SLOT(setDarkenMode())); connect(rbDarken, &QAbstractButton::clicked, view, &CompositionRenderer::setDarkenMode);
rbLighten = new QRadioButton(tr("Lighten"), modesGroup); rbLighten = new QRadioButton(tr("Lighten"), modesGroup);
connect(rbLighten, SIGNAL(clicked()), view, SLOT(setLightenMode())); connect(rbLighten, &QAbstractButton::clicked, view, &CompositionRenderer::setLightenMode);
rbColorDodge = new QRadioButton(tr("Color Dodge"), modesGroup); rbColorDodge = new QRadioButton(tr("Color Dodge"), modesGroup);
connect(rbColorDodge, SIGNAL(clicked()), view, SLOT(setColorDodgeMode())); connect(rbColorDodge, &QAbstractButton::clicked, view, &CompositionRenderer::setColorDodgeMode);
rbColorBurn = new QRadioButton(tr("Color Burn"), modesGroup); rbColorBurn = new QRadioButton(tr("Color Burn"), modesGroup);
connect(rbColorBurn, SIGNAL(clicked()), view, SLOT(setColorBurnMode())); connect(rbColorBurn, &QAbstractButton::clicked, view, &CompositionRenderer::setColorBurnMode);
rbHardLight = new QRadioButton(tr("Hard Light"), modesGroup); rbHardLight = new QRadioButton(tr("Hard Light"), modesGroup);
connect(rbHardLight, SIGNAL(clicked()), view, SLOT(setHardLightMode())); connect(rbHardLight, &QAbstractButton::clicked, view, &CompositionRenderer::setHardLightMode);
rbSoftLight = new QRadioButton(tr("Soft Light"), modesGroup); rbSoftLight = new QRadioButton(tr("Soft Light"), modesGroup);
connect(rbSoftLight, SIGNAL(clicked()), view, SLOT(setSoftLightMode())); connect(rbSoftLight, &QAbstractButton::clicked, view, &CompositionRenderer::setSoftLightMode);
rbDifference = new QRadioButton(tr("Difference"), modesGroup); rbDifference = new QRadioButton(tr("Difference"), modesGroup);
connect(rbDifference, SIGNAL(clicked()), view, SLOT(setDifferenceMode())); connect(rbDifference, &QAbstractButton::clicked, view, &CompositionRenderer::setDifferenceMode);
rbExclusion = new QRadioButton(tr("Exclusion"), modesGroup); rbExclusion = new QRadioButton(tr("Exclusion"), modesGroup);
connect(rbExclusion, SIGNAL(clicked()), view, SLOT(setExclusionMode())); connect(rbExclusion, &QAbstractButton::clicked, view, &CompositionRenderer::setExclusionMode);
QGroupBox *circleColorGroup = new QGroupBox(mainGroup); QGroupBox *circleColorGroup = new QGroupBox(mainGroup);
circleColorGroup->setTitle(tr("Circle color")); circleColorGroup->setTitle(tr("Circle color"));
QSlider *circleColorSlider = new QSlider(Qt::Horizontal, circleColorGroup); QSlider *circleColorSlider = new QSlider(Qt::Horizontal, circleColorGroup);
circleColorSlider->setRange(0, 359); circleColorSlider->setRange(0, 359);
circleColorSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); circleColorSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
connect(circleColorSlider, SIGNAL(valueChanged(int)), view, SLOT(setCircleColor(int))); connect(circleColorSlider, &QAbstractSlider::valueChanged, view, &CompositionRenderer::setCircleColor);
QGroupBox *circleAlphaGroup = new QGroupBox(mainGroup); QGroupBox *circleAlphaGroup = new QGroupBox(mainGroup);
circleAlphaGroup->setTitle(tr("Circle alpha")); circleAlphaGroup->setTitle(tr("Circle alpha"));
QSlider *circleAlphaSlider = new QSlider(Qt::Horizontal, circleAlphaGroup); QSlider *circleAlphaSlider = new QSlider(Qt::Horizontal, circleAlphaGroup);
circleAlphaSlider->setRange(0, 255); circleAlphaSlider->setRange(0, 255);
circleAlphaSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); circleAlphaSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
connect(circleAlphaSlider, SIGNAL(valueChanged(int)), view, SLOT(setCircleAlpha(int))); connect(circleAlphaSlider, &QAbstractSlider::valueChanged, view, &CompositionRenderer::setCircleAlpha);
QPushButton *showSourceButton = new QPushButton(mainGroup); QPushButton *showSourceButton = new QPushButton(mainGroup);
showSourceButton->setText(tr("Show Source")); showSourceButton->setText(tr("Show Source"));
@ -209,13 +209,13 @@ CompositionWidget::CompositionWidget(QWidget *parent)
view->loadDescription(":res/composition/composition.html"); view->loadDescription(":res/composition/composition.html");
view->loadSourceFile(":res/composition/composition.cpp"); view->loadSourceFile(":res/composition/composition.cpp");
connect(whatsThisButton, SIGNAL(clicked(bool)), view, SLOT(setDescriptionEnabled(bool))); connect(whatsThisButton, &QAbstractButton::clicked, view, &ArthurFrame::setDescriptionEnabled);
connect(view, SIGNAL(descriptionEnabledChanged(bool)), whatsThisButton, SLOT(setChecked(bool))); connect(view, &ArthurFrame::descriptionEnabledChanged, whatsThisButton, &QAbstractButton::setChecked);
connect(showSourceButton, SIGNAL(clicked()), view, SLOT(showSource())); connect(showSourceButton, &QAbstractButton::clicked, view, &ArthurFrame::showSource);
#if QT_CONFIG(opengl) #if QT_CONFIG(opengl)
connect(enableOpenGLButton, SIGNAL(clicked(bool)), view, SLOT(enableOpenGL(bool))); connect(enableOpenGLButton, &QAbstractButton::clicked, view, &ArthurFrame::enableOpenGL);
#endif #endif
connect(animateButton, SIGNAL(toggled(bool)), view, SLOT(setAnimationEnabled(bool))); connect(animateButton, &QAbstractButton::toggled, view, &CompositionRenderer::setAnimationEnabled);
circleColorSlider->setValue(270); circleColorSlider->setValue(270);
circleAlphaSlider->setValue(200); circleAlphaSlider->setValue(200);

View File

@ -77,8 +77,8 @@ Window::Window()
circleWidgets[i][j]->setAntialiased(j != 0); circleWidgets[i][j]->setAntialiased(j != 0);
circleWidgets[i][j]->setFloatBased(i != 0); circleWidgets[i][j]->setFloatBased(i != 0);
connect(timer, SIGNAL(timeout()), connect(timer, &QTimer::timeout,
circleWidgets[i][j], SLOT(nextAnimationFrame())); circleWidgets[i][j], &CircleWidget::nextAnimationFrame);
layout->addWidget(circleWidgets[i][j], i + 1, j + 1); layout->addWidget(circleWidgets[i][j], i + 1, j + 1);
} }

View File

@ -152,19 +152,19 @@ void PathDeformControls::layoutForDesktop()
mainLayout->addWidget(mainGroup); mainLayout->addWidget(mainGroup);
mainLayout->setMargin(0); mainLayout->setMargin(0);
connect(radiusSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setRadius(int))); connect(radiusSlider, &QAbstractSlider::valueChanged, m_renderer, &PathDeformRenderer::setRadius);
connect(deformSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setIntensity(int))); connect(deformSlider, &QAbstractSlider::valueChanged, m_renderer, &PathDeformRenderer::setIntensity);
connect(fontSizeSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setFontSize(int))); connect(fontSizeSlider, &QAbstractSlider::valueChanged, m_renderer, &PathDeformRenderer::setFontSize);
connect(animateButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setAnimated(bool))); connect(animateButton, &QAbstractButton::clicked, m_renderer, &PathDeformRenderer::setAnimated);
#if QT_CONFIG(opengl) #if QT_CONFIG(opengl)
connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool))); connect(enableOpenGLButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::enableOpenGL);
#endif #endif
connect(textInput, SIGNAL(textChanged(QString)), m_renderer, SLOT(setText(QString))); connect(textInput, &QLineEdit::textChanged, m_renderer, &PathDeformRenderer::setText);
connect(m_renderer, SIGNAL(descriptionEnabledChanged(bool)), connect(m_renderer, &ArthurFrame::descriptionEnabledChanged,
whatsThisButton, SLOT(setChecked(bool))); whatsThisButton, &QAbstractButton::setChecked);
connect(whatsThisButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setDescriptionEnabled(bool))); connect(whatsThisButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::setDescriptionEnabled);
connect(showSourceButton, SIGNAL(clicked()), m_renderer, SLOT(showSource())); connect(showSourceButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::showSource);
animateButton->animateClick(); animateButton->animateClick();
deformSlider->setValue(80); deformSlider->setValue(80);
@ -229,14 +229,14 @@ void PathDeformControls::layoutForSmallScreen()
mainLayout->addWidget(okButton); mainLayout->addWidget(okButton);
mainLayout->addWidget(quitButton); mainLayout->addWidget(quitButton);
connect(quitButton, SIGNAL(clicked()), this, SIGNAL(quitPressed())); connect(quitButton, &QAbstractButton::clicked, this, &PathDeformControls::quitPressed);
connect(okButton, SIGNAL(clicked()), this, SIGNAL(okPressed())); connect(okButton, &QAbstractButton::clicked, this, &PathDeformControls::okPressed);
connect(radiusSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setRadius(int))); connect(radiusSlider, &QAbstractSlider::valueChanged, m_renderer, &PathDeformRenderer::setRadius);
connect(deformSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setIntensity(int))); connect(deformSlider, &QAbstractSlider::valueChanged, m_renderer, &PathDeformRenderer::setIntensity);
connect(fontSizeSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setFontSize(int))); connect(fontSizeSlider, &QAbstractSlider::valueChanged, m_renderer, &PathDeformRenderer::setFontSize);
connect(animateButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setAnimated(bool))); connect(animateButton, &QAbstractButton::clicked, m_renderer, &PathDeformRenderer::setAnimated);
#if QT_CONFIG(opengl) #if QT_CONFIG(opengl)
connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool))); connect(enableOpenGLButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::enableOpenGL);
#endif #endif
@ -272,9 +272,12 @@ PathDeformWidget::PathDeformWidget(QWidget *parent, bool smallScreen)
m_renderer->loadDescription(":res/deform/pathdeform.html"); m_renderer->loadDescription(":res/deform/pathdeform.html");
m_renderer->setDescriptionEnabled(false); m_renderer->setDescriptionEnabled(false);
connect(m_renderer, SIGNAL(clicked()), this, SLOT(showControls())); connect(m_renderer, &PathDeformRenderer::clicked,
connect(m_controls, SIGNAL(okPressed()), this, SLOT(hideControls())); this, &PathDeformWidget::showControls);
connect(m_controls, SIGNAL(quitPressed()), QCoreApplication::instance(), SLOT(quit())); connect(m_controls, &PathDeformControls::okPressed,
this, &PathDeformWidget::hideControls);
connect(m_controls, &PathDeformControls::quitPressed,
qApp, &QCoreApplication::quit);
} }

View File

@ -71,11 +71,12 @@ MainWindow::MainWindow(QWidget *parent)
markedCount = 0; markedCount = 0;
setupFontTree(); setupFontTree();
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(quitAction, &QAction::triggered,
connect(fontTree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), qApp, &QApplication::quit);
this, SLOT(showFont(QTreeWidgetItem*))); connect(fontTree, &QTreeWidget::currentItemChanged,
connect(fontTree, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, &MainWindow::showFont);
this, SLOT(updateStyles(QTreeWidgetItem*,int))); connect(fontTree, &QTreeWidget::itemChanged,
this, &MainWindow::updateStyles);
fontTree->setItemSelected(fontTree->topLevelItem(0), true); fontTree->setItemSelected(fontTree->topLevelItem(0), true);
showFont(fontTree->topLevelItem(0)); showFont(fontTree->topLevelItem(0));
@ -285,8 +286,8 @@ void MainWindow::on_printPreviewAction_triggered()
QPrinter printer(QPrinter::HighResolution); QPrinter printer(QPrinter::HighResolution);
QPrintPreviewDialog preview(&printer, this); QPrintPreviewDialog preview(&printer, this);
connect(&preview, SIGNAL(paintRequested(QPrinter*)), connect(&preview, &QPrintPreviewDialog::paintRequested,
this, SLOT(printDocument(QPrinter*))); this, &MainWindow::printDocument);
preview.exec(); preview.exec();
#endif #endif
} }

View File

@ -421,7 +421,7 @@ GradientWidget::GradientWidget(QWidget *parent)
m_renderer->loadSourceFile(":res/gradients/gradients.cpp"); m_renderer->loadSourceFile(":res/gradients/gradients.cpp");
m_renderer->loadDescription(":res/gradients/gradients.html"); m_renderer->loadDescription(":res/gradients/gradients.html");
QTimer::singleShot(50, this, SLOT(setDefault1())); QTimer::singleShot(50, this, &GradientWidget::setDefault1);
} }
void GradientWidget::setDefault(int config) void GradientWidget::setDefault(int config)

View File

@ -100,9 +100,12 @@ ImageComposer::ImageComposer()
//! [2] //! [2]
//! [3] //! [3]
connect(sourceButton, SIGNAL(clicked()), this, SLOT(chooseSource())); connect(sourceButton, &QAbstractButton::clicked,
connect(operatorComboBox, SIGNAL(activated(int)), this, SLOT(recalculateResult())); this, &ImageComposer::chooseSource);
connect(destinationButton, SIGNAL(clicked()), this, SLOT(chooseDestination())); connect(operatorComboBox, QOverload<int>::of(&QComboBox::activated),
this, &ImageComposer::recalculateResult);
connect(destinationButton, &QAbstractButton::clicked,
this, &ImageComposer::chooseDestination);
//! [3] //! [3]
//! [4] //! [4]

View File

@ -194,22 +194,30 @@ Window::Window()
//! [12] //! [12]
//! [16] //! [16]
connect(fillRuleComboBox, SIGNAL(activated(int)), this, SLOT(fillRuleChanged())); connect(fillRuleComboBox, QOverload<int>::of(&QComboBox::activated),
connect(fillColor1ComboBox, SIGNAL(activated(int)), this, SLOT(fillGradientChanged())); this, &Window::fillRuleChanged);
connect(fillColor2ComboBox, SIGNAL(activated(int)), this, SLOT(fillGradientChanged())); connect(fillColor1ComboBox, QOverload<int>::of(&QComboBox::activated),
connect(penColorComboBox, SIGNAL(activated(int)), this, SLOT(penColorChanged())); this, &Window::fillGradientChanged);
connect(fillColor2ComboBox, QOverload<int>::of(&QComboBox::activated),
this, &Window::fillGradientChanged);
connect(penColorComboBox, QOverload<int>::of(&QComboBox::activated),
this, &Window::penColorChanged);
for(QList<RenderArea*>::iterator it = renderAreas.begin(); it != renderAreas.end(); it++) { for (RenderArea *area : qAsConst(renderAreas)) {
connect(penWidthSpinBox, SIGNAL(valueChanged(int)), *it, SLOT(setPenWidth(int))); connect(penWidthSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
connect(rotationAngleSpinBox, SIGNAL(valueChanged(int)), *it, SLOT(setRotationAngle(int))); area, &RenderArea::setPenWidth);
connect(rotationAngleSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
area, &RenderArea::setRotationAngle);
} }
//! [16] //! [17] //! [16] //! [17]
QGridLayout *topLayout = new QGridLayout; QGridLayout *topLayout = new QGridLayout;
int i = 0; int i = 0;
for(QList<RenderArea*>::iterator it = renderAreas.begin(); it != renderAreas.end(); it++, i++) for (RenderArea *area : qAsConst(renderAreas)) {
topLayout->addWidget(*it, i / 3, i % 3); topLayout->addWidget(area, i / 3, i % 3);
++i;
}
QGridLayout *mainLayout = new QGridLayout; QGridLayout *mainLayout = new QGridLayout;
mainLayout->addLayout(topLayout, 0, 0, 1, 4); mainLayout->addLayout(topLayout, 0, 0, 1, 4);
@ -243,8 +251,8 @@ void Window::fillRuleChanged()
{ {
Qt::FillRule rule = (Qt::FillRule)currentItemData(fillRuleComboBox).toInt(); Qt::FillRule rule = (Qt::FillRule)currentItemData(fillRuleComboBox).toInt();
for (QList<RenderArea*>::iterator it = renderAreas.begin(); it != renderAreas.end(); ++it) for (RenderArea *area : qAsConst(renderAreas))
(*it)->setFillRule(rule); area->setFillRule(rule);
} }
//! [19] //! [19]
@ -254,8 +262,8 @@ void Window::fillGradientChanged()
QColor color1 = qvariant_cast<QColor>(currentItemData(fillColor1ComboBox)); QColor color1 = qvariant_cast<QColor>(currentItemData(fillColor1ComboBox));
QColor color2 = qvariant_cast<QColor>(currentItemData(fillColor2ComboBox)); QColor color2 = qvariant_cast<QColor>(currentItemData(fillColor2ComboBox));
for (QList<RenderArea*>::iterator it = renderAreas.begin(); it != renderAreas.end(); ++it) for (RenderArea *area : qAsConst(renderAreas))
(*it)->setFillGradient(color1, color2); area->setFillGradient(color1, color2);
} }
//! [20] //! [20]
@ -264,8 +272,8 @@ void Window::penColorChanged()
{ {
QColor color = qvariant_cast<QColor>(currentItemData(penColorComboBox)); QColor color = qvariant_cast<QColor>(currentItemData(penColorComboBox));
for (QList<RenderArea*>::iterator it = renderAreas.begin(); it != renderAreas.end(); ++it) for (RenderArea *area : qAsConst(renderAreas))
(*it)->setPenColor(color); area->setPenColor(color);
} }
//! [21] //! [21]

View File

@ -164,24 +164,24 @@ void PathStrokeControls::createCommonControls(QWidget* parent)
// Connections // Connections
connect(flatCap, SIGNAL(clicked()), m_renderer, SLOT(setFlatCap())); connect(flatCap, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setFlatCap);
connect(squareCap, SIGNAL(clicked()), m_renderer, SLOT(setSquareCap())); connect(squareCap, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setSquareCap);
connect(roundCap, SIGNAL(clicked()), m_renderer, SLOT(setRoundCap())); connect(roundCap, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setRoundCap);
connect(bevelJoin, SIGNAL(clicked()), m_renderer, SLOT(setBevelJoin())); connect(bevelJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setBevelJoin);
connect(miterJoin, SIGNAL(clicked()), m_renderer, SLOT(setMiterJoin())); connect(miterJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setMiterJoin);
connect(svgMiterJoin, SIGNAL(clicked()), m_renderer, SLOT(setSvgMiterJoin())); connect(svgMiterJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setSvgMiterJoin);
connect(roundJoin, SIGNAL(clicked()), m_renderer, SLOT(setRoundJoin())); connect(roundJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setRoundJoin);
connect(curveMode, SIGNAL(clicked()), m_renderer, SLOT(setCurveMode())); connect(curveMode, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setCurveMode);
connect(lineMode, SIGNAL(clicked()), m_renderer, SLOT(setLineMode())); connect(lineMode, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setLineMode);
connect(solidLine, SIGNAL(clicked()), m_renderer, SLOT(setSolidLine())); connect(solidLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setSolidLine);
connect(dashLine, SIGNAL(clicked()), m_renderer, SLOT(setDashLine())); connect(dashLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDashLine);
connect(dotLine, SIGNAL(clicked()), m_renderer, SLOT(setDotLine())); connect(dotLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDotLine);
connect(dashDotLine, SIGNAL(clicked()), m_renderer, SLOT(setDashDotLine())); connect(dashDotLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDashDotLine);
connect(dashDotDotLine, SIGNAL(clicked()), m_renderer, SLOT(setDashDotDotLine())); connect(dashDotDotLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDashDotDotLine);
connect(customDashLine, SIGNAL(clicked()), m_renderer, SLOT(setCustomDashLine())); connect(customDashLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setCustomDashLine);
// Set the defaults: // Set the defaults:
flatCap->setChecked(true); flatCap->setChecked(true);
@ -247,17 +247,17 @@ void PathStrokeControls::layoutForDesktop()
// Set up connections // Set up connections
connect(animated, SIGNAL(toggled(bool)), m_renderer, SLOT(setAnimation(bool))); connect(animated, &QAbstractButton::toggled, m_renderer, &PathStrokeRenderer::setAnimation);
connect(penWidth, SIGNAL(valueChanged(int)), m_renderer, SLOT(setPenWidth(int))); connect(penWidth, &QAbstractSlider::valueChanged, m_renderer, &PathStrokeRenderer::setPenWidth);
connect(showSourceButton, SIGNAL(clicked()), m_renderer, SLOT(showSource())); connect(showSourceButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::showSource);
#if QT_CONFIG(opengl) #if QT_CONFIG(opengl)
connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool))); connect(enableOpenGLButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::enableOpenGL);
#endif #endif
connect(whatsThisButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setDescriptionEnabled(bool))); connect(whatsThisButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::setDescriptionEnabled);
connect(m_renderer, SIGNAL(descriptionEnabledChanged(bool)), connect(m_renderer, &ArthurFrame::descriptionEnabledChanged,
whatsThisButton, SLOT(setChecked(bool))); whatsThisButton, &QAbstractButton::setChecked);
// Set the defaults // Set the defaults
@ -327,12 +327,12 @@ void PathStrokeControls::layoutForSmallScreens()
mainLayout->addWidget(okBtn, 2, 2, Qt::AlignHCenter | Qt::AlignTop); mainLayout->addWidget(okBtn, 2, 2, Qt::AlignHCenter | Qt::AlignTop);
#if QT_CONFIG(opengl) #if QT_CONFIG(opengl)
connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool))); connect(enableOpenGLButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::enableOpenGL);
#endif #endif
connect(penWidth, SIGNAL(valueChanged(int)), m_renderer, SLOT(setPenWidth(int))); connect(penWidth, &QAbstractSlider::valueChanged, m_renderer, &PathStrokeRenderer::setPenWidth);
connect(quitBtn, SIGNAL(clicked()), this, SLOT(emitQuitSignal())); connect(quitBtn, &QAbstractButton::clicked, this, &PathStrokeControls::emitQuitSignal);
connect(okBtn, SIGNAL(clicked()), this, SLOT(emitOkSignal())); connect(okBtn, &QAbstractButton::clicked, this, &PathStrokeControls::emitOkSignal);
m_renderer->setAnimation(true); m_renderer->setAnimation(true);
penWidth->setValue(50); penWidth->setValue(50);
@ -368,8 +368,8 @@ PathStrokeWidget::PathStrokeWidget(bool smallScreen)
m_renderer->loadSourceFile(":res/pathstroke/pathstroke.cpp"); m_renderer->loadSourceFile(":res/pathstroke/pathstroke.cpp");
m_renderer->loadDescription(":res/pathstroke/pathstroke.html"); m_renderer->loadDescription(":res/pathstroke/pathstroke.html");
connect(m_renderer, SIGNAL(clicked()), this, SLOT(showControls())); connect(m_renderer, &PathStrokeRenderer::clicked, this, &PathStrokeWidget::showControls);
connect(m_controls, SIGNAL(okPressed()), this, SLOT(hideControls())); connect(m_controls, &PathStrokeControls::okPressed, this, &PathStrokeWidget::hideControls);
connect(m_controls, SIGNAL(quitPressed()), QApplication::instance(), SLOT(quit())); connect(m_controls, SIGNAL(quitPressed()), QApplication::instance(), SLOT(quit()));
} }

View File

@ -73,8 +73,8 @@ HoverPoints::HoverPoints(QWidget *widget, PointShape shape)
m_editable = true; m_editable = true;
m_enabled = true; m_enabled = true;
connect(this, SIGNAL(pointsChanged(QPolygonF)), connect(this, &HoverPoints::pointsChanged,
m_widget, SLOT(update())); m_widget, QOverload<>::of(&QWidget::update));
} }

View File

@ -79,8 +79,8 @@ Window::Window()
operationComboBoxes[i]->addItem(tr("Scale to 75%")); operationComboBoxes[i]->addItem(tr("Scale to 75%"));
operationComboBoxes[i]->addItem(tr("Translate by (50, 50)")); operationComboBoxes[i]->addItem(tr("Translate by (50, 50)"));
connect(operationComboBoxes[i], SIGNAL(activated(int)), connect(operationComboBoxes[i], QOverload<int>::of(&QComboBox::activated),
this, SLOT(operationChanged())); this, &Window::operationChanged);
layout->addWidget(transformedRenderAreas[i], 0, i + 1); layout->addWidget(transformedRenderAreas[i], 0, i + 1);
layout->addWidget(operationComboBoxes[i], 1, i + 1); layout->addWidget(operationComboBoxes[i], 1, i + 1);
@ -159,7 +159,8 @@ void Window::setupShapes()
shapes.append(text); shapes.append(text);
shapes.append(truck); shapes.append(truck);
connect(shapeComboBox, SIGNAL(activated(int)), this, SLOT(shapeSelected(int))); connect(shapeComboBox, QOverload<int>::of(&QComboBox::activated),
this, &Window::shapeSelected);
} }
//! [7] //! [7]

View File

@ -86,10 +86,12 @@ MainWindow::MainWindow()
//! [2] //! [2]
//! [3] //! [3]
connect(monthCombo, SIGNAL(activated(int)), this, SLOT(setMonth(int))); connect(monthCombo, QOverload<int>::of(&QComboBox::activated),
connect(yearEdit, SIGNAL(dateChanged(QDate)), this, SLOT(setYear(QDate))); this, &MainWindow::setMonth);
connect(fontSizeSpinBox, SIGNAL(valueChanged(int)), connect(yearEdit, &QDateTimeEdit::dateChanged,
this, SLOT(setFontSize(int))); this, &MainWindow::setYear);
connect(fontSizeSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
this, &MainWindow::setFontSize);
//! [3] //! [3]
fontSizeSpinBox->setValue(10); fontSizeSpinBox->setValue(10);

View File

@ -66,7 +66,7 @@ MainWindow::MainWindow()
QMenu *fileMenu = new QMenu(tr("&File"), this); QMenu *fileMenu = new QMenu(tr("&File"), this);
QAction *newAction = fileMenu->addAction(tr("&New...")); QAction *newAction = fileMenu->addAction(tr("&New..."));
newAction->setShortcuts(QKeySequence::New); newAction->setShortcuts(QKeySequence::New);
printAction = fileMenu->addAction(tr("&Print..."), this, SLOT(printFile())); printAction = fileMenu->addAction(tr("&Print..."), this, &MainWindow::printFile);
printAction->setShortcuts(QKeySequence::Print); printAction->setShortcuts(QKeySequence::Print);
printAction->setEnabled(false); printAction->setEnabled(false);
QAction *quitAction = fileMenu->addAction(tr("E&xit")); QAction *quitAction = fileMenu->addAction(tr("E&xit"));

View File

@ -117,9 +117,12 @@ void MainWindow::setupFileMenu()
QMenu *fileMenu = new QMenu(tr("&File"), this); QMenu *fileMenu = new QMenu(tr("&File"), this);
menuBar()->addMenu(fileMenu); menuBar()->addMenu(fileMenu);
fileMenu->addAction(tr("&New"), this, SLOT(newFile()), QKeySequence::New); fileMenu->addAction(tr("&New"), this,
fileMenu->addAction(tr("&Open..."), this, SLOT(openFile()), QKeySequence::Open); &MainWindow::newFile, QKeySequence::New);
fileMenu->addAction(tr("E&xit"), qApp, SLOT(quit()), QKeySequence::Quit); fileMenu->addAction(tr("&Open..."),
this, [this](){ openFile(); }, QKeySequence::Open);
fileMenu->addAction(tr("E&xit"), qApp,
&QApplication::quit, QKeySequence::Quit);
} }
void MainWindow::setupHelpMenu() void MainWindow::setupHelpMenu()
@ -127,6 +130,6 @@ void MainWindow::setupHelpMenu()
QMenu *helpMenu = new QMenu(tr("&Help"), this); QMenu *helpMenu = new QMenu(tr("&Help"), this);
menuBar()->addMenu(helpMenu); menuBar()->addMenu(helpMenu);
helpMenu->addAction(tr("&About"), this, SLOT(about())); helpMenu->addAction(tr("&About"), this, &MainWindow::about);
helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt())); helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
} }