diff options
Diffstat (limited to 'examples/widgets/graphicsview')
21 files changed, 168 insertions, 186 deletions
diff --git a/examples/widgets/graphicsview/boxes/glbuffers.cpp b/examples/widgets/graphicsview/boxes/glbuffers.cpp index 851cd17796..b52b26c4ef 100644 --- a/examples/widgets/graphicsview/boxes/glbuffers.cpp +++ b/examples/widgets/graphicsview/boxes/glbuffers.cpp @@ -218,14 +218,14 @@ GLTextureCube::GLTextureCube(int size) glBindTexture(GL_TEXTURE_CUBE_MAP, 0); } -GLTextureCube::GLTextureCube(const QStringList& fileNames, int size) +GLTextureCube::GLTextureCube(const QStringList &fileNames, int size) { // TODO: Add error handling. glBindTexture(GL_TEXTURE_CUBE_MAP, m_texture); int index = 0; - foreach (QString file, fileNames) { + for (const QString &file : fileNames) { QImage image(file); if (image.isNull()) { m_failed = true; diff --git a/examples/widgets/graphicsview/boxes/glbuffers.h b/examples/widgets/graphicsview/boxes/glbuffers.h index 03c24a91d3..e2363d561e 100644 --- a/examples/widgets/graphicsview/boxes/glbuffers.h +++ b/examples/widgets/graphicsview/boxes/glbuffers.h @@ -129,7 +129,7 @@ class GLTextureCube : public GLTexture { public: GLTextureCube(int size); - explicit GLTextureCube(const QStringList& fileNames, int size = 0); + explicit GLTextureCube(const QStringList &fileNames, int size = 0); void load(int size, int face, QRgb *data); void bind() override; void unbind() override; diff --git a/examples/widgets/graphicsview/boxes/qtbox.cpp b/examples/widgets/graphicsview/boxes/qtbox.cpp index 3a184dd0b6..68d5c251f4 100644 --- a/examples/widgets/graphicsview/boxes/qtbox.cpp +++ b/examples/widgets/graphicsview/boxes/qtbox.cpp @@ -127,10 +127,8 @@ void ItemBase::duplicateSelectedItems(QGraphicsScene *scene) if (!scene) return; - QList<QGraphicsItem *> selected; - selected = scene->selectedItems(); - - foreach (QGraphicsItem *item, selected) { + const QList<QGraphicsItem *> selected = scene->selectedItems(); + for (QGraphicsItem *item : selected) { ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item); if (itemBase) scene->addItem(itemBase->createNew(itemBase->m_size, itemBase->pos().x() + itemBase->m_size, itemBase->pos().y())); @@ -142,10 +140,8 @@ void ItemBase::deleteSelectedItems(QGraphicsScene *scene) if (!scene) return; - QList<QGraphicsItem *> selected; - selected = scene->selectedItems(); - - foreach (QGraphicsItem *item, selected) { + const QList<QGraphicsItem *> selected = scene->selectedItems(); + for (QGraphicsItem *item : selected) { ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item); if (itemBase) delete itemBase; @@ -157,10 +153,8 @@ void ItemBase::growSelectedItems(QGraphicsScene *scene) if (!scene) return; - QList<QGraphicsItem *> selected; - selected = scene->selectedItems(); - - foreach (QGraphicsItem *item, selected) { + const QList<QGraphicsItem *> selected = scene->selectedItems(); + for (QGraphicsItem *item : selected) { ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item); if (itemBase) { itemBase->prepareGeometryChange(); @@ -176,10 +170,8 @@ void ItemBase::shrinkSelectedItems(QGraphicsScene *scene) if (!scene) return; - QList<QGraphicsItem *> selected; - selected = scene->selectedItems(); - - foreach (QGraphicsItem *item, selected) { + const QList<QGraphicsItem *> selected = scene->selectedItems(); + for (QGraphicsItem *item : selected) { ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item); if (itemBase) { itemBase->prepareGeometryChange(); diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp index 1637c1f781..7f62ac894b 100644 --- a/examples/widgets/graphicsview/boxes/scene.cpp +++ b/examples/widgets/graphicsview/boxes/scene.cpp @@ -111,7 +111,7 @@ ColorEdit::ColorEdit(QRgb initialColor, int id) m_button->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); layout->addWidget(m_button); - connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(editDone())); + connect(m_lineEdit, &QLineEdit::editingFinished, this, &ColorEdit::editDone); } void ColorEdit::editDone() @@ -166,7 +166,7 @@ FloatEdit::FloatEdit(float initialValue, int id) m_lineEdit = new QLineEdit(QString::number(m_value)); layout->addWidget(m_lineEdit); - connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(editDone())); + connect(m_lineEdit, &QLineEdit::editingFinished, this, &FloatEdit::editDone); } void FloatEdit::editDone() @@ -252,7 +252,7 @@ void TwoSidedGraphicsWidget::animateFlip() .translate(-r.width() / 2, -r.height() / 2)); if ((m_current == 0 && m_angle > 0) || (m_current == 1 && m_angle < 180)) - QTimer::singleShot(25, this, SLOT(animateFlip())); + QTimer::singleShot(25, this, &TwoSidedGraphicsWidget::animateFlip); } QVariant GraphicsWidget::itemChange(GraphicsItemChange change, const QVariant &value) @@ -307,19 +307,17 @@ RenderOptionsDialog::RenderOptionsDialog() check->setCheckState(Qt::Unchecked); // Dynamic cube maps are only enabled when multi-texturing and render to texture are available. check->setEnabled(glActiveTexture && glGenFramebuffersEXT); - connect(check, SIGNAL(stateChanged(int)), this, SIGNAL(dynamicCubemapToggled(int))); + connect(check, &QCheckBox::stateChanged, this, &RenderOptionsDialog::dynamicCubemapToggled); layout->addWidget(check, 0, 0, 1, 2); ++row; - QPalette palette; - // Load all .par files // .par files have a simple syntax for specifying user adjustable uniform variables. - QSet<QByteArray> uniforms; - QList<QString> filter = QStringList("*.par"); - QList<QFileInfo> files = QDir(":/res/boxes/").entryInfoList(filter, QDir::Files | QDir::Readable); + const QList<QFileInfo> files = QDir(QStringLiteral(":/res/boxes/")) + .entryInfoList({ QStringLiteral("*.par") }, + QDir::Files | QDir::Readable); - foreach (QFileInfo fileInfo, files) { + for (const QFileInfo &fileInfo : files) { QFile file(fileInfo.absoluteFilePath()); if (file.open(QIODevice::ReadOnly)) { while (!file.atEnd()) { @@ -356,7 +354,7 @@ RenderOptionsDialog::RenderOptionsDialog() ColorEdit *colorEdit = new ColorEdit(it->toUInt(&ok, 16), m_parameterNames.size() - 1); m_parameterEdits << colorEdit; layout->addWidget(colorEdit); - connect(colorEdit, SIGNAL(colorChanged(QRgb,int)), this, SLOT(setColorParameter(QRgb,int))); + connect(colorEdit, &ColorEdit::colorChanged, this, &RenderOptionsDialog::setColorParameter); ++row; } else if (type == "float") { layout->addWidget(new QLabel(m_parameterNames.back())); @@ -364,7 +362,7 @@ RenderOptionsDialog::RenderOptionsDialog() FloatEdit *floatEdit = new FloatEdit(it->toFloat(&ok), m_parameterNames.size() - 1); m_parameterEdits << floatEdit; layout->addWidget(floatEdit); - connect(floatEdit, SIGNAL(valueChanged(float,int)), this, SLOT(setFloatParameter(float,int))); + connect(floatEdit, &FloatEdit::valueChanged, this, &RenderOptionsDialog::setFloatParameter); ++row; } } @@ -375,13 +373,15 @@ RenderOptionsDialog::RenderOptionsDialog() layout->addWidget(new QLabel(tr("Texture:"))); m_textureCombo = new QComboBox; - connect(m_textureCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(textureChanged(int))); + connect(m_textureCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), + this, &RenderOptionsDialog::textureChanged); layout->addWidget(m_textureCombo); ++row; layout->addWidget(new QLabel(tr("Shader:"))); m_shaderCombo = new QComboBox; - connect(m_shaderCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(shaderChanged(int))); + connect(m_shaderCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), + this, &RenderOptionsDialog::shaderChanged); layout->addWidget(m_shaderCombo); ++row; @@ -402,7 +402,7 @@ int RenderOptionsDialog::addShader(const QString &name) void RenderOptionsDialog::emitParameterChanged() { - foreach (ParameterEdit *edit, m_parameterEdits) + for (ParameterEdit *edit : qAsConst(m_parameterEdits)) edit->emitChange(); } @@ -439,15 +439,15 @@ ItemDialog::ItemDialog() button = new QPushButton(tr("Add Qt box")); layout->addWidget(button); - connect(button, SIGNAL(clicked()), this, SLOT(triggerNewQtBox())); + connect(button, &QAbstractButton::clicked, this, &ItemDialog::triggerNewQtBox); button = new QPushButton(tr("Add circle")); layout->addWidget(button); - connect(button, SIGNAL(clicked()), this, SLOT(triggerNewCircleItem())); + connect(button, &QAbstractButton::clicked, this, &ItemDialog::triggerNewCircleItem); button = new QPushButton(tr("Add square")); layout->addWidget(button); - connect(button, SIGNAL(clicked()), this, SLOT(triggerNewSquareItem())); + connect(button, &QAbstractButton::clicked, this, &ItemDialog::triggerNewSquareItem); layout->addStretch(1); } @@ -506,21 +506,21 @@ Scene::Scene(int width, int height, int maxTextureSize) m_renderOptions->move(20, 120); m_renderOptions->resize(m_renderOptions->sizeHint()); - connect(m_renderOptions, SIGNAL(dynamicCubemapToggled(int)), this, SLOT(toggleDynamicCubemap(int))); - connect(m_renderOptions, SIGNAL(colorParameterChanged(QString,QRgb)), this, SLOT(setColorParameter(QString,QRgb))); - connect(m_renderOptions, SIGNAL(floatParameterChanged(QString,float)), this, SLOT(setFloatParameter(QString,float))); - connect(m_renderOptions, SIGNAL(textureChanged(int)), this, SLOT(setTexture(int))); - connect(m_renderOptions, SIGNAL(shaderChanged(int)), this, SLOT(setShader(int))); + connect(m_renderOptions, &RenderOptionsDialog::dynamicCubemapToggled, this, &Scene::toggleDynamicCubemap); + connect(m_renderOptions, &RenderOptionsDialog::colorParameterChanged, this, &Scene::setColorParameter); + connect(m_renderOptions, &RenderOptionsDialog::floatParameterChanged, this, &Scene::setFloatParameter); + connect(m_renderOptions, &RenderOptionsDialog::textureChanged, this, &Scene::setTexture); + connect(m_renderOptions, &RenderOptionsDialog::shaderChanged, this, &Scene::setShader); m_itemDialog = new ItemDialog; - connect(m_itemDialog, SIGNAL(newItemTriggered(ItemDialog::ItemType)), this, SLOT(newItem(ItemDialog::ItemType))); + connect(m_itemDialog, &ItemDialog::newItemTriggered, this, &Scene::newItem); TwoSidedGraphicsWidget *twoSided = new TwoSidedGraphicsWidget(this); twoSided->setWidget(0, m_renderOptions); twoSided->setWidget(1, m_itemDialog); - connect(m_renderOptions, SIGNAL(doubleClicked()), twoSided, SLOT(flip())); - connect(m_itemDialog, SIGNAL(doubleClicked()), twoSided, SLOT(flip())); + connect(m_renderOptions, &RenderOptionsDialog::doubleClicked, twoSided, &TwoSidedGraphicsWidget::flip); + connect(m_itemDialog, &ItemDialog::doubleClicked, twoSided, &TwoSidedGraphicsWidget::flip); addItem(new QtBox(64, width - 64, height - 64)); addItem(new QtBox(64, width - 64, 64)); @@ -531,7 +531,7 @@ Scene::Scene(int width, int height, int maxTextureSize) m_timer = new QTimer(this); m_timer->setInterval(20); - connect(m_timer, SIGNAL(timeout()), this, SLOT(update())); + connect(m_timer, &QTimer::timeout, this, [this](){ update(); }); m_timer->start(); m_time.start(); @@ -539,24 +539,15 @@ Scene::Scene(int width, int height, int maxTextureSize) Scene::~Scene() { - if (m_box) - delete m_box; - foreach (GLTexture *texture, m_textures) - if (texture) delete texture; - if (m_mainCubemap) - delete m_mainCubemap; - foreach (QGLShaderProgram *program, m_programs) - if (program) delete program; - if (m_vertexShader) - delete m_vertexShader; - foreach (QGLShader *shader, m_fragmentShaders) - if (shader) delete shader; - foreach (GLRenderTargetCube *rt, m_cubemaps) - if (rt) delete rt; - if (m_environmentShader) - delete m_environmentShader; - if (m_environmentProgram) - delete m_environmentProgram; + delete m_box; + qDeleteAll(m_textures); + delete m_mainCubemap; + qDeleteAll(m_programs); + delete m_vertexShader; + qDeleteAll(m_fragmentShaders); + qDeleteAll(m_cubemaps); + delete m_environmentShader; + delete m_environmentProgram; } void Scene::initGL() @@ -601,15 +592,13 @@ void Scene::initGL() m_mainCubemap = new GLRenderTargetCube(512); - QStringList filter; QList<QFileInfo> files; // Load all .png files as textures m_currentTexture = 0; - filter = QStringList("*.png"); - files = QDir(":/res/boxes/").entryInfoList(filter, QDir::Files | QDir::Readable); + files = QDir(":/res/boxes/").entryInfoList({ QStringLiteral("*.png") }, QDir::Files | QDir::Readable); - foreach (QFileInfo file, files) { + for (const QFileInfo &file : qAsConst(files)) { GLTexture *texture = new GLTexture2D(file.absoluteFilePath(), qMin(256, m_maxTextureSize), qMin(256, m_maxTextureSize)); if (texture->failed()) { delete texture; @@ -624,9 +613,8 @@ void Scene::initGL() // Load all .fsh files as fragment shaders m_currentShader = 0; - filter = QStringList("*.fsh"); - files = QDir(":/res/boxes/").entryInfoList(filter, QDir::Files | QDir::Readable); - foreach (QFileInfo file, files) { + files = QDir(":/res/boxes/").entryInfoList({ QStringLiteral("*.fsh") }, QDir::Files | QDir::Readable); + for (const QFileInfo &file : qAsConst(files)) { QGLShaderProgram *program = new QGLShaderProgram; QGLShader* shader = new QGLShader(QGLShader::Fragment); shader->compileSourceFile(file.absoluteFilePath()); @@ -662,7 +650,7 @@ void Scene::initGL() m_renderOptions->emitParameterChanged(); } -static void loadMatrix(const QMatrix4x4& m) +static void loadMatrix(const QMatrix4x4 &m) { // static to prevent glLoadMatrixf to fail on certain drivers static GLfloat mat[16]; @@ -1051,7 +1039,7 @@ void Scene::toggleDynamicCubemap(int state) void Scene::setColorParameter(const QString &name, QRgb color) { // set the color in all programs - foreach (QGLShaderProgram *program, m_programs) { + for (QGLShaderProgram *program : qAsConst(m_programs)) { program->bind(); program->setUniformValue(program->uniformLocation(name), QColor(color)); program->release(); @@ -1061,7 +1049,7 @@ void Scene::setColorParameter(const QString &name, QRgb color) void Scene::setFloatParameter(const QString &name, float value) { // set the color in all programs - foreach (QGLShaderProgram *program, m_programs) { + for (QGLShaderProgram *program : qAsConst(m_programs)) { program->bind(); program->setUniformValue(program->uniformLocation(name), value); program->release(); diff --git a/examples/widgets/graphicsview/chip/chip.cpp b/examples/widgets/graphicsview/chip/chip.cpp index 443994e121..3d2bbdfcef 100644 --- a/examples/widgets/graphicsview/chip/chip.cpp +++ b/examples/widgets/graphicsview/chip/chip.cpp @@ -79,9 +79,9 @@ void Chip::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid { Q_UNUSED(widget); - QColor fillColor = (option->state & QStyle::State_Selected) ? color.dark(150) : color; + QColor fillColor = (option->state & QStyle::State_Selected) ? color.darker(150) : color; if (option->state & QStyle::State_MouseOver) - fillColor = fillColor.light(125); + fillColor = fillColor.lighter(125); const qreal lod = option->levelOfDetailFromTransform(painter->worldTransform()); if (lod < 0.2) { @@ -105,7 +105,7 @@ void Chip::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid pen.setWidth(width); QBrush b = painter->brush(); - painter->setBrush(QBrush(fillColor.dark(option->state & QStyle::State_Sunken ? 120 : 100))); + painter->setBrush(QBrush(fillColor.darker(option->state & QStyle::State_Sunken ? 120 : 100))); painter->drawRect(QRect(14, 14, 79, 39)); painter->setBrush(b); diff --git a/examples/widgets/graphicsview/chip/view.cpp b/examples/widgets/graphicsview/chip/view.cpp index 491f1a54cf..9676c13ff7 100644 --- a/examples/widgets/graphicsview/chip/view.cpp +++ b/examples/widgets/graphicsview/chip/view.cpp @@ -190,22 +190,22 @@ View::View(const QString &name, QWidget *parent) topLayout->addWidget(resetButton, 2, 1); setLayout(topLayout); - connect(resetButton, SIGNAL(clicked()), this, SLOT(resetView())); - connect(zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix())); - connect(rotateSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix())); - connect(graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(setResetButtonEnabled())); - connect(graphicsView->horizontalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(setResetButtonEnabled())); - connect(selectModeButton, SIGNAL(toggled(bool)), this, SLOT(togglePointerMode())); - connect(dragModeButton, SIGNAL(toggled(bool)), this, SLOT(togglePointerMode())); - connect(antialiasButton, SIGNAL(toggled(bool)), this, SLOT(toggleAntialiasing())); - connect(openGlButton, SIGNAL(toggled(bool)), this, SLOT(toggleOpenGL())); - connect(rotateLeftIcon, SIGNAL(clicked()), this, SLOT(rotateLeft())); - connect(rotateRightIcon, SIGNAL(clicked()), this, SLOT(rotateRight())); - connect(zoomInIcon, SIGNAL(clicked()), this, SLOT(zoomIn())); - connect(zoomOutIcon, SIGNAL(clicked()), this, SLOT(zoomOut())); - connect(printButton, SIGNAL(clicked()), this, SLOT(print())); + connect(resetButton, &QAbstractButton::clicked, this, &View::resetView); + connect(zoomSlider, &QAbstractSlider::valueChanged, this, &View::setupMatrix); + connect(rotateSlider, &QAbstractSlider::valueChanged, this, &View::setupMatrix); + connect(graphicsView->verticalScrollBar(), &QAbstractSlider::valueChanged, + this, &View::setResetButtonEnabled); + connect(graphicsView->horizontalScrollBar(), &QAbstractSlider::valueChanged, + this, &View::setResetButtonEnabled); + connect(selectModeButton, &QAbstractButton::toggled, this, &View::togglePointerMode); + connect(dragModeButton, &QAbstractButton::toggled, this, &View::togglePointerMode); + connect(antialiasButton, &QAbstractButton::toggled, this, &View::toggleAntialiasing); + connect(openGlButton, &QAbstractButton::toggled, this, &View::toggleOpenGL); + connect(rotateLeftIcon, &QAbstractButton::clicked, this, &View::rotateLeft); + connect(rotateRightIcon, &QAbstractButton::clicked, this, &View::rotateRight); + connect(zoomInIcon, &QAbstractButton::clicked, this, &View::zoomIn); + connect(zoomOutIcon, &QAbstractButton::clicked, this, &View::zoomOut); + connect(printButton, &QAbstractButton::clicked, this, &View::print); setupMatrix(); } diff --git a/examples/widgets/graphicsview/collidingmice/main.cpp b/examples/widgets/graphicsview/collidingmice/main.cpp index 91aee70b86..dfb20815b9 100644 --- a/examples/widgets/graphicsview/collidingmice/main.cpp +++ b/examples/widgets/graphicsview/collidingmice/main.cpp @@ -92,7 +92,7 @@ int main(int argc, char **argv) view.show(); QTimer timer; - QObject::connect(&timer, SIGNAL(timeout()), &scene, SLOT(advance())); + QObject::connect(&timer, &QTimer::timeout, &scene, &QGraphicsScene::advance); timer.start(1000 / 33); return app.exec(); diff --git a/examples/widgets/graphicsview/collidingmice/mouse.cpp b/examples/widgets/graphicsview/collidingmice/mouse.cpp index 14f887f6e3..a8fcc05d76 100644 --- a/examples/widgets/graphicsview/collidingmice/mouse.cpp +++ b/examples/widgets/graphicsview/collidingmice/mouse.cpp @@ -160,11 +160,12 @@ void Mouse::advance(int step) // Try not to crash with any other mice //! [7] - QList<QGraphicsItem *> dangerMice = scene()->items(QPolygonF() - << mapToScene(0, 0) - << mapToScene(-30, -50) - << mapToScene(30, -50)); - foreach (QGraphicsItem *item, dangerMice) { + const QList<QGraphicsItem *> dangerMice = scene()->items(QPolygonF() + << mapToScene(0, 0) + << mapToScene(-30, -50) + << mapToScene(30, -50)); + + for (const QGraphicsItem *item : dangerMice) { if (item == this) continue; diff --git a/examples/widgets/graphicsview/diagramscene/diagramitem.cpp b/examples/widgets/graphicsview/diagramscene/diagramitem.cpp index db6dabee56..3aa685635e 100644 --- a/examples/widgets/graphicsview/diagramscene/diagramitem.cpp +++ b/examples/widgets/graphicsview/diagramscene/diagramitem.cpp @@ -111,7 +111,7 @@ void DiagramItem::removeArrow(Arrow *arrow) //! [2] void DiagramItem::removeArrows() { - foreach (Arrow *arrow, arrows) { + for (Arrow *arrow : qAsConst(arrows)) { arrow->startItem()->removeArrow(arrow); arrow->endItem()->removeArrow(arrow); scene()->removeItem(arrow); @@ -154,9 +154,8 @@ void DiagramItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) QVariant DiagramItem::itemChange(GraphicsItemChange change, const QVariant &value) { if (change == QGraphicsItem::ItemPositionChange) { - foreach (Arrow *arrow, arrows) { + for (Arrow *arrow : qAsConst(arrows)) arrow->updatePosition(); - } } return value; diff --git a/examples/widgets/graphicsview/diagramscene/diagramscene.cpp b/examples/widgets/graphicsview/diagramscene/diagramscene.cpp index bbbc512b55..40272834c3 100644 --- a/examples/widgets/graphicsview/diagramscene/diagramscene.cpp +++ b/examples/widgets/graphicsview/diagramscene/diagramscene.cpp @@ -169,10 +169,10 @@ void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) textItem->setFont(myFont); textItem->setTextInteractionFlags(Qt::TextEditorInteraction); textItem->setZValue(1000.0); - connect(textItem, SIGNAL(lostFocus(DiagramTextItem*)), - this, SLOT(editorLostFocus(DiagramTextItem*))); - connect(textItem, SIGNAL(selectedChange(QGraphicsItem*)), - this, SIGNAL(itemSelected(QGraphicsItem*))); + connect(textItem, &DiagramTextItem::lostFocus, + this, &DiagramScene::editorLostFocus); + connect(textItem, &DiagramTextItem::selectedChange, + this, &DiagramScene::itemSelected); addItem(textItem); textItem->setDefaultTextColor(myTextColor); textItem->setPos(mouseEvent->scenePos()); @@ -234,12 +234,10 @@ void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) //! [13] //! [14] -bool DiagramScene::isItemChange(int type) +bool DiagramScene::isItemChange(int type) const { - foreach (QGraphicsItem *item, selectedItems()) { - if (item->type() == type) - return true; - } - return false; + const QList<QGraphicsItem *> items = selectedItems(); + const auto cb = [type](const QGraphicsItem *item) { return item->type() == type; }; + return std::find_if(items.begin(), items.end(), cb) != items.end(); } //! [14] diff --git a/examples/widgets/graphicsview/diagramscene/diagramscene.h b/examples/widgets/graphicsview/diagramscene/diagramscene.h index 95f7f3c621..15063d58b7 100644 --- a/examples/widgets/graphicsview/diagramscene/diagramscene.h +++ b/examples/widgets/graphicsview/diagramscene/diagramscene.h @@ -100,7 +100,7 @@ protected: void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) override; private: - bool isItemChange(int type); + bool isItemChange(int type) const; DiagramItem::DiagramType myItemType; QMenu *myItemMenu; diff --git a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp index 36353674ea..07f92f61c1 100644 --- a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp +++ b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp @@ -67,12 +67,12 @@ MainWindow::MainWindow() scene = new DiagramScene(itemMenu, this); scene->setSceneRect(QRectF(0, 0, 5000, 5000)); - connect(scene, SIGNAL(itemInserted(DiagramItem*)), - this, SLOT(itemInserted(DiagramItem*))); - connect(scene, SIGNAL(textInserted(QGraphicsTextItem*)), - this, SLOT(textInserted(QGraphicsTextItem*))); - connect(scene, SIGNAL(itemSelected(QGraphicsItem*)), - this, SLOT(itemSelected(QGraphicsItem*))); + connect(scene, &DiagramScene::itemInserted, + this, &MainWindow::itemInserted); + connect(scene, &DiagramScene::textInserted, + this, &MainWindow::textInserted); + connect(scene, &DiagramScene::itemSelected, + this, &MainWindow::itemSelected); createToolbars(); QHBoxLayout *layout = new QHBoxLayout; @@ -92,8 +92,8 @@ MainWindow::MainWindow() //! [1] void MainWindow::backgroundButtonGroupClicked(QAbstractButton *button) { - QList<QAbstractButton *> buttons = backgroundButtonGroup->buttons(); - foreach (QAbstractButton *myButton, buttons) { + const QList<QAbstractButton *> buttons = backgroundButtonGroup->buttons(); + for (QAbstractButton *myButton : buttons) { if (myButton != button) button->setChecked(false); } @@ -115,8 +115,8 @@ void MainWindow::backgroundButtonGroupClicked(QAbstractButton *button) //! [2] void MainWindow::buttonGroupClicked(int id) { - QList<QAbstractButton *> buttons = buttonGroup->buttons(); - foreach (QAbstractButton *button, buttons) { + const QList<QAbstractButton *> buttons = buttonGroup->buttons(); + for (QAbstractButton *button : buttons) { if (buttonGroup->button(id) != button) button->setChecked(false); } @@ -132,7 +132,8 @@ void MainWindow::buttonGroupClicked(int id) //! [3] void MainWindow::deleteItem() { - foreach (QGraphicsItem *item, scene->selectedItems()) { + QList<QGraphicsItem *> selectedItems = scene->selectedItems(); + for (QGraphicsItem *item : qAsConst(selectedItems)) { if (item->type() == Arrow::Type) { scene->removeItem(item); Arrow *arrow = qgraphicsitem_cast<Arrow *>(item); @@ -142,7 +143,8 @@ void MainWindow::deleteItem() } } - foreach (QGraphicsItem *item, scene->selectedItems()) { + selectedItems = scene->selectedItems(); + for (QGraphicsItem *item : qAsConst(selectedItems)) { if (item->type() == DiagramItem::Type) qgraphicsitem_cast<DiagramItem *>(item)->removeArrows(); scene->removeItem(item); @@ -165,10 +167,10 @@ void MainWindow::bringToFront() return; QGraphicsItem *selectedItem = scene->selectedItems().first(); - QList<QGraphicsItem *> overlapItems = selectedItem->collidingItems(); + const QList<QGraphicsItem *> overlapItems = selectedItem->collidingItems(); qreal zValue = 0; - foreach (QGraphicsItem *item, overlapItems) { + for (const QGraphicsItem *item : overlapItems) { if (item->zValue() >= zValue && item->type() == DiagramItem::Type) zValue = item->zValue() + 0.1; } @@ -183,10 +185,10 @@ void MainWindow::sendToBack() return; QGraphicsItem *selectedItem = scene->selectedItems().first(); - QList<QGraphicsItem *> overlapItems = selectedItem->collidingItems(); + const QList<QGraphicsItem *> overlapItems = selectedItem->collidingItems(); qreal zValue = 0; - foreach (QGraphicsItem *item, overlapItems) { + for (const QGraphicsItem *item : overlapItems) { if (item->zValue() <= zValue && item->type() == DiagramItem::Type) zValue = item->zValue() - 0.1; } @@ -332,8 +334,8 @@ void MainWindow::createToolBox() { buttonGroup = new QButtonGroup(this); buttonGroup->setExclusive(false); - connect(buttonGroup, SIGNAL(buttonClicked(int)), - this, SLOT(buttonGroupClicked(int))); + connect(buttonGroup, QOverload<int>::of(&QButtonGroup::buttonClicked), + this, &MainWindow::buttonGroupClicked); QGridLayout *layout = new QGridLayout; layout->addWidget(createCellWidget(tr("Conditional"), DiagramItem::Conditional), 0, 0); layout->addWidget(createCellWidget(tr("Process"), DiagramItem::Step),0, 1); @@ -359,8 +361,8 @@ void MainWindow::createToolBox() itemWidget->setLayout(layout); backgroundButtonGroup = new QButtonGroup(this); - connect(backgroundButtonGroup, SIGNAL(buttonClicked(QAbstractButton*)), - this, SLOT(backgroundButtonGroupClicked(QAbstractButton*))); + connect(backgroundButtonGroup, QOverload<QAbstractButton *>::of(&QButtonGroup::buttonClicked), + this, &MainWindow::backgroundButtonGroupClicked); QGridLayout *backgroundLayout = new QGridLayout; backgroundLayout->addWidget(createBackgroundCellWidget(tr("Blue Grid"), @@ -395,44 +397,44 @@ void MainWindow::createActions() tr("Bring to &Front"), this); toFrontAction->setShortcut(tr("Ctrl+F")); toFrontAction->setStatusTip(tr("Bring item to front")); - connect(toFrontAction, SIGNAL(triggered()), this, SLOT(bringToFront())); + connect(toFrontAction, &QAction::triggered, this, &MainWindow::bringToFront); //! [23] sendBackAction = new QAction(QIcon(":/images/sendtoback.png"), tr("Send to &Back"), this); sendBackAction->setShortcut(tr("Ctrl+T")); sendBackAction->setStatusTip(tr("Send item to back")); - connect(sendBackAction, SIGNAL(triggered()), this, SLOT(sendToBack())); + connect(sendBackAction, &QAction::triggered, this, &MainWindow::sendToBack); deleteAction = new QAction(QIcon(":/images/delete.png"), tr("&Delete"), this); deleteAction->setShortcut(tr("Delete")); deleteAction->setStatusTip(tr("Delete item from diagram")); - connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem())); + connect(deleteAction, &QAction::triggered, this, &MainWindow::deleteItem); exitAction = new QAction(tr("E&xit"), this); exitAction->setShortcuts(QKeySequence::Quit); exitAction->setStatusTip(tr("Quit Scenediagram example")); - connect(exitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(exitAction, &QAction::triggered, this, &QWidget::close); boldAction = new QAction(tr("Bold"), this); boldAction->setCheckable(true); QPixmap pixmap(":/images/bold.png"); boldAction->setIcon(QIcon(pixmap)); boldAction->setShortcut(tr("Ctrl+B")); - connect(boldAction, SIGNAL(triggered()), this, SLOT(handleFontChange())); + connect(boldAction, &QAction::triggered, this, &MainWindow::handleFontChange); italicAction = new QAction(QIcon(":/images/italic.png"), tr("Italic"), this); italicAction->setCheckable(true); italicAction->setShortcut(tr("Ctrl+I")); - connect(italicAction, SIGNAL(triggered()), this, SLOT(handleFontChange())); + connect(italicAction, &QAction::triggered, this, &MainWindow::handleFontChange); underlineAction = new QAction(QIcon(":/images/underline.png"), tr("Underline"), this); underlineAction->setCheckable(true); underlineAction->setShortcut(tr("Ctrl+U")); - connect(underlineAction, SIGNAL(triggered()), this, SLOT(handleFontChange())); + connect(underlineAction, &QAction::triggered, this, &MainWindow::handleFontChange); aboutAction = new QAction(tr("A&bout"), this); aboutAction->setShortcut(tr("F1")); - connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); + connect(aboutAction, &QAction::triggered, this, &MainWindow::about); } //! [24] @@ -462,8 +464,8 @@ void MainWindow::createToolbars() editToolBar->addAction(sendBackAction); fontCombo = new QFontComboBox(); - connect(fontCombo, SIGNAL(currentFontChanged(QFont)), - this, SLOT(currentFontChanged(QFont))); + connect(fontCombo, &QFontComboBox::currentFontChanged, + this, &MainWindow::currentFontChanged); fontSizeCombo = new QComboBox; fontSizeCombo->setEditable(true); @@ -471,8 +473,8 @@ void MainWindow::createToolbars() fontSizeCombo->addItem(QString().setNum(i)); QIntValidator *validator = new QIntValidator(2, 64, this); fontSizeCombo->setValidator(validator); - connect(fontSizeCombo, SIGNAL(currentIndexChanged(QString)), - this, SLOT(fontSizeChanged(QString))); + connect(fontSizeCombo, QOverload<const QString &>::of(&QComboBox::currentIndexChanged), + this, &MainWindow::fontSizeChanged); fontColorToolButton = new QToolButton; fontColorToolButton->setPopupMode(QToolButton::MenuButtonPopup); @@ -480,8 +482,8 @@ void MainWindow::createToolbars() textAction = fontColorToolButton->menu()->defaultAction(); fontColorToolButton->setIcon(createColorToolButtonIcon(":/images/textpointer.png", Qt::black)); fontColorToolButton->setAutoFillBackground(true); - connect(fontColorToolButton, SIGNAL(clicked()), - this, SLOT(textButtonTriggered())); + connect(fontColorToolButton, &QAbstractButton::clicked, + this, &MainWindow::textButtonTriggered); //! [26] fillColorToolButton = new QToolButton; @@ -490,8 +492,8 @@ void MainWindow::createToolbars() fillAction = fillColorToolButton->menu()->defaultAction(); fillColorToolButton->setIcon(createColorToolButtonIcon( ":/images/floodfill.png", Qt::white)); - connect(fillColorToolButton, SIGNAL(clicked()), - this, SLOT(fillButtonTriggered())); + connect(fillColorToolButton, &QAbstractButton::clicked, + this, &MainWindow::fillButtonTriggered); //! [26] lineColorToolButton = new QToolButton; @@ -500,8 +502,8 @@ void MainWindow::createToolbars() lineAction = lineColorToolButton->menu()->defaultAction(); lineColorToolButton->setIcon(createColorToolButtonIcon( ":/images/linecolor.png", Qt::black)); - connect(lineColorToolButton, SIGNAL(clicked()), - this, SLOT(lineButtonTriggered())); + connect(lineColorToolButton, &QAbstractButton::clicked, + this, &MainWindow::lineButtonTriggered); textToolBar = addToolBar(tr("Font")); textToolBar->addWidget(fontCombo); @@ -526,16 +528,16 @@ void MainWindow::createToolbars() pointerTypeGroup = new QButtonGroup(this); pointerTypeGroup->addButton(pointerButton, int(DiagramScene::MoveItem)); pointerTypeGroup->addButton(linePointerButton, int(DiagramScene::InsertLine)); - connect(pointerTypeGroup, SIGNAL(buttonClicked(int)), - this, SLOT(pointerGroupClicked(int))); + connect(pointerTypeGroup, QOverload<int>::of(&QButtonGroup::buttonClicked), + this, &MainWindow::pointerGroupClicked); sceneScaleCombo = new QComboBox; QStringList scales; scales << tr("50%") << tr("75%") << tr("100%") << tr("125%") << tr("150%"); sceneScaleCombo->addItems(scales); sceneScaleCombo->setCurrentIndex(2); - connect(sceneScaleCombo, SIGNAL(currentIndexChanged(QString)), - this, SLOT(sceneScaleChanged(QString))); + connect(sceneScaleCombo, QOverload<const QString &>::of(&QComboBox::currentIndexChanged), + this, &MainWindow::sceneScaleChanged); pointerToolbar = addToolBar(tr("Pointer type")); pointerToolbar->addWidget(pointerButton); diff --git a/examples/widgets/graphicsview/dragdroprobot/robot.cpp b/examples/widgets/graphicsview/dragdroprobot/robot.cpp index 38552747af..cc70366872 100644 --- a/examples/widgets/graphicsview/dragdroprobot/robot.cpp +++ b/examples/widgets/graphicsview/dragdroprobot/robot.cpp @@ -113,7 +113,7 @@ void RobotHead::paint(QPainter *painter, Q_UNUSED(option); Q_UNUSED(widget); if (pixmap.isNull()) { - painter->setBrush(dragOver ? color.light(130) : color); + painter->setBrush(dragOver ? color.lighter(130) : color); painter->drawRoundedRect(-10, -30, 20, 30, 25, 25, Qt::RelativeSize); painter->setBrush(Qt::white); painter->drawEllipse(-7, -3 - 20, 7, 7); @@ -173,7 +173,7 @@ void RobotTorso::paint(QPainter *painter, Q_UNUSED(option); Q_UNUSED(widget); - painter->setBrush(dragOver ? color.light(130) : color); + painter->setBrush(dragOver ? color.lighter(130) : color); painter->drawRoundedRect(-20, -20, 40, 60, 25, 25, Qt::RelativeSize); painter->drawEllipse(-25, -20, 20, 20); painter->drawEllipse(5, -20, 20, 20); @@ -197,7 +197,7 @@ void RobotLimb::paint(QPainter *painter, Q_UNUSED(option); Q_UNUSED(widget); - painter->setBrush(dragOver ? color.light(130) : color); + painter->setBrush(dragOver ? color.lighter(130) : color); painter->drawRoundedRect(boundingRect(), 50, 50, Qt::RelativeSize); painter->drawEllipse(-5, -5, 10, 10); } diff --git a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp index 81928a4ee1..6b817b2a21 100644 --- a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp +++ b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp @@ -164,16 +164,17 @@ void GraphWidget::timerEvent(QTimerEvent *event) Q_UNUSED(event); QList<Node *> nodes; - foreach (QGraphicsItem *item, scene()->items()) { + const QList<QGraphicsItem *> items = scene()->items(); + for (QGraphicsItem *item : items) { if (Node *node = qgraphicsitem_cast<Node *>(item)) nodes << node; } - foreach (Node *node, nodes) + for (Node *node : qAsConst(nodes)) node->calculateForces(); bool itemsMoved = false; - foreach (Node *node, nodes) { + for (Node *node : qAsConst(nodes)) { if (node->advancePosition()) itemsMoved = true; } @@ -246,7 +247,8 @@ void GraphWidget::scaleView(qreal scaleFactor) void GraphWidget::shuffle() { - foreach (QGraphicsItem *item, scene()->items()) { + const QList<QGraphicsItem *> items = scene()->items(); + for (QGraphicsItem *item : items) { if (qgraphicsitem_cast<Node *>(item)) item->setPos(-150 + QRandomGenerator::global()->bounded(300), -150 + QRandomGenerator::global()->bounded(300)); } diff --git a/examples/widgets/graphicsview/elasticnodes/node.cpp b/examples/widgets/graphicsview/elasticnodes/node.cpp index 71737c984b..8d44a167fa 100644 --- a/examples/widgets/graphicsview/elasticnodes/node.cpp +++ b/examples/widgets/graphicsview/elasticnodes/node.cpp @@ -94,7 +94,8 @@ void Node::calculateForces() // Sum up all forces pushing this item away qreal xvel = 0; qreal yvel = 0; - foreach (QGraphicsItem *item, scene()->items()) { + const QList<QGraphicsItem *> items = scene()->items(); + for (QGraphicsItem *item : items) { Node *node = qgraphicsitem_cast<Node *>(item); if (!node) continue; @@ -113,7 +114,7 @@ void Node::calculateForces() //! [4] // Now subtract all forces pulling items together double weight = (edgeList.size() + 1) * 10; - foreach (Edge *edge, edgeList) { + for (const Edge *edge : qAsConst(edgeList)) { QPointF vec; if (edge->sourceNode() == this) vec = mapToItem(edge->destNode(), 0, 0); @@ -176,8 +177,8 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid if (option->state & QStyle::State_Sunken) { gradient.setCenter(3, 3); gradient.setFocalPoint(3, 3); - gradient.setColorAt(1, QColor(Qt::yellow).light(120)); - gradient.setColorAt(0, QColor(Qt::darkYellow).light(120)); + gradient.setColorAt(1, QColor(Qt::yellow).lighter(120)); + gradient.setColorAt(0, QColor(Qt::darkYellow).lighter(120)); } else { gradient.setColorAt(0, Qt::yellow); gradient.setColorAt(1, Qt::darkYellow); @@ -194,7 +195,7 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value) { switch (change) { case ItemPositionHasChanged: - foreach (Edge *edge, edgeList) + for (Edge *edge : qAsConst(edgeList)) edge->adjust(); graph->itemMoved(); break; diff --git a/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp b/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp index 158c31d9c1..f510ebc07f 100644 --- a/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp +++ b/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp @@ -55,13 +55,13 @@ #include <QGraphicsScene> CustomProxy::CustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags) - : QGraphicsProxyWidget(parent, wFlags), popupShown(false), currentPopup(0) + : QGraphicsProxyWidget(parent, wFlags), popupShown(false), currentPopup(nullptr) { timeLine = new QTimeLine(250, this); - connect(timeLine, SIGNAL(valueChanged(qreal)), - this, SLOT(updateStep(qreal))); - connect(timeLine, SIGNAL(stateChanged(QTimeLine::State)), - this, SLOT(stateChanged(QTimeLine::State))); + connect(timeLine, &QTimeLine::valueChanged, + this, &CustomProxy::updateStep); + connect(timeLine, &QTimeLine::stateChanged, + this, &CustomProxy::stateChanged); } QRectF CustomProxy::boundingRect() const @@ -133,7 +133,7 @@ QVariant CustomProxy::itemChange(GraphicsItemChange change, const QVariant &valu currentPopup->installSceneEventFilter(this); } else if (scene()) { currentPopup->removeSceneEventFilter(this); - currentPopup = 0; + currentPopup = nullptr; } } else if (currentPopup && change == ItemSceneHasChanged) { currentPopup->installSceneEventFilter(this); diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp index 0c3ed86565..0c831360cf 100644 --- a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp +++ b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp @@ -60,7 +60,8 @@ EmbeddedDialog::EmbeddedDialog(QWidget *parent) ui->setupUi(this); ui->layoutDirection->setCurrentIndex(layoutDirection() != Qt::LeftToRight); - foreach (QString styleName, QStyleFactory::keys()) { + const QStringList styleKeys = QStyleFactory::keys(); + for (const QString &styleName : styleKeys) { ui->style->addItem(styleName); if (style()->objectName().toLower() == styleName.toLower()) ui->style->setCurrentIndex(ui->style->count() - 1); @@ -101,7 +102,8 @@ static void setStyleHelper(QWidget *widget, QStyle *style) { widget->setStyle(style); widget->setPalette(style->standardPalette()); - foreach (QObject *child, widget->children()) { + const QObjectList children = widget->children(); + for (QObject *child : children) { if (QWidget *childWidget = qobject_cast<QWidget *>(child)) setStyleHelper(childWidget, style); } diff --git a/examples/widgets/graphicsview/embeddeddialogs/main.cpp b/examples/widgets/graphicsview/embeddeddialogs/main.cpp index cbd5dd5890..501405e3ff 100644 --- a/examples/widgets/graphicsview/embeddeddialogs/main.cpp +++ b/examples/widgets/graphicsview/embeddeddialogs/main.cpp @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) for (int y = 0; y < gridSize; ++y) { for (int x = 0; x < gridSize; ++x) { - CustomProxy *proxy = new CustomProxy(0, Qt::Window); + CustomProxy *proxy = new CustomProxy(nullptr, Qt::Window); proxy->setWidget(new EmbeddedDialog); QRectF rect = proxy->boundingRect(); diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.cpp b/examples/widgets/graphicsview/flowlayout/flowlayout.cpp index 065c3e00ea..ab6bbb7aa4 100644 --- a/examples/widgets/graphicsview/flowlayout/flowlayout.cpp +++ b/examples/widgets/graphicsview/flowlayout/flowlayout.cpp @@ -154,8 +154,7 @@ QSizeF FlowLayout::minSize(const QSizeF &constraint) const } else if (constraint.height() >= 0) { // width for height? // not supported } else { - QGraphicsLayoutItem *item; - foreach (item, m_items) + for (const QGraphicsLayoutItem *item : qAsConst(m_items)) size = size.expandedTo(item->effectiveSizeHint(Qt::MinimumSize)); size += QSize(left + right, top + bottom); } @@ -167,10 +166,9 @@ QSizeF FlowLayout::prefSize() const qreal left, right; getContentsMargins(&left, 0, &right, 0); - QGraphicsLayoutItem *item; qreal maxh = 0; qreal totalWidth = 0; - foreach (item, m_items) { + for (const QGraphicsLayoutItem *item : qAsConst(m_items)) { if (totalWidth > 0) totalWidth += spacing(Qt::Horizontal); QSizeF pref = item->effectiveSizeHint(Qt::PreferredSize); @@ -187,10 +185,9 @@ QSizeF FlowLayout::prefSize() const QSizeF FlowLayout::maxSize() const { - QGraphicsLayoutItem *item; qreal totalWidth = 0; qreal totalHeight = 0; - foreach (item, m_items) { + for (const QGraphicsLayoutItem *item : qAsConst(m_items)) { if (totalWidth > 0) totalWidth += spacing(Qt::Horizontal); if (totalHeight > 0) diff --git a/examples/widgets/graphicsview/padnavigator/roundrectitem.cpp b/examples/widgets/graphicsview/padnavigator/roundrectitem.cpp index f629400a76..82205050ec 100644 --- a/examples/widgets/graphicsview/padnavigator/roundrectitem.cpp +++ b/examples/widgets/graphicsview/padnavigator/roundrectitem.cpp @@ -62,7 +62,7 @@ RoundRectItem::RoundRectItem(const QRectF &bounds, const QColor &color, gradient.setStart(bounds.topLeft()); gradient.setFinalStop(bounds.bottomRight()); gradient.setColorAt(0, color); - gradient.setColorAt(1, color.dark(200)); + gradient.setColorAt(1, color.darker(200)); setCacheMode(ItemCoordinateCache); } //! [0] @@ -94,7 +94,7 @@ void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt Q_UNUSED(widget); painter->setPen(Qt::NoPen); painter->setBrush(QColor(0, 0, 0, 64)); - painter->drawRoundRect(bounds.translated(2, 2)); + painter->drawRoundedRect(bounds.translated(2, 2), 25, 25, Qt::RelativeSize); //! [3] //! [4] if (fillRect) @@ -102,7 +102,7 @@ void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt else painter->setBrush(gradient); painter->setPen(QPen(Qt::black, 1)); - painter->drawRoundRect(bounds); + painter->drawRoundedRect(bounds, 25,25, Qt::RelativeSize); //! [4] //! [5] if (!pix.isNull()) { diff --git a/examples/widgets/graphicsview/padnavigator/splashitem.cpp b/examples/widgets/graphicsview/padnavigator/splashitem.cpp index 0c3a05dd9a..7c3dfba588 100644 --- a/examples/widgets/graphicsview/padnavigator/splashitem.cpp +++ b/examples/widgets/graphicsview/padnavigator/splashitem.cpp @@ -79,7 +79,7 @@ void SplashItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option painter->setPen(QPen(Qt::black, 2)); painter->setBrush(QColor(245, 245, 255, 220)); painter->setClipRect(boundingRect()); - painter->drawRoundRect(3, -100 + 3, 400 - 6, 250 - 6); + painter->drawRoundedRect(3, -100 + 3, 400 - 6, 250 - 6, 25, 25, Qt::RelativeSize); QRectF textRect = boundingRect().adjusted(10, 10, -10, -10); int flags = Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap; |