diff options
Diffstat (limited to 'src/widgets/dialogs/qwizard.cpp')
-rw-r--r-- | src/widgets/dialogs/qwizard.cpp | 95 |
1 files changed, 41 insertions, 54 deletions
diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index cd41efa313..f3fbdad483 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -29,12 +29,10 @@ #include "qstyleoption.h" #include "qvarlengtharray.h" #if defined(Q_OS_MACOS) -#include <QtCore/QMetaMethod> -#include <QtGui/QGuiApplication> -#include <qpa/qplatformnativeinterface.h> +#include <AppKit/AppKit.h> +#include <QtGui/private/qcoregraphics_p.h> #elif QT_CONFIG(style_windowsvista) #include "qwizard_win_p.h" -#include "qtimer.h" #endif #include "private/qdialog_p.h" @@ -415,8 +413,8 @@ public: } QSize minimumSizeHint() const override { - if (!pixmap(Qt::ReturnByValue).isNull()) - return pixmap(Qt::ReturnByValue).deviceIndependentSize().toSize(); + if (!pixmap().isNull()) + return pixmap().deviceIndependentSize().toSize(); return QFrame::minimumSizeHint(); } @@ -692,8 +690,9 @@ void QWizardPrivate::reset() if (current != -1) { q->currentPage()->hide(); cleanupPagesNotInHistory(); - for (int i = history.size() - 1; i >= 0; --i) - q->cleanupPage(history.at(i)); + const auto end = history.crend(); + for (auto it = history.crbegin(); it != end; ++it) + q->cleanupPage(*it); history.clear(); for (QWizardPage *page : std::as_const(pageMap)) page->d_func()->initialized = false; @@ -863,7 +862,7 @@ QWizardLayoutInfo QWizardPrivate::layoutInfoForCurrentPage() QStyleOption option; option.initFrom(q); - const int layoutHorizontalSpacing = style->pixelMetric(QStyle::PM_LayoutHorizontalSpacing, &option); + const int layoutHorizontalSpacing = style->pixelMetric(QStyle::PM_LayoutHorizontalSpacing, &option, q); info.topLevelMarginLeft = style->pixelMetric(QStyle::PM_LayoutLeftMargin, nullptr, q); info.topLevelMarginRight = style->pixelMetric(QStyle::PM_LayoutRightMargin, nullptr, q); info.topLevelMarginTop = style->pixelMetric(QStyle::PM_LayoutTopMargin, nullptr, q); @@ -875,7 +874,7 @@ QWizardLayoutInfo QWizardPrivate::layoutInfoForCurrentPage() info.hspacing = (layoutHorizontalSpacing == -1) ? style->layoutSpacing(QSizePolicy::DefaultType, QSizePolicy::DefaultType, Qt::Horizontal) : layoutHorizontalSpacing; - info.vspacing = style->pixelMetric(QStyle::PM_LayoutVerticalSpacing, &option); + info.vspacing = style->pixelMetric(QStyle::PM_LayoutVerticalSpacing, &option, q); info.buttonSpacing = (layoutHorizontalSpacing == -1) ? style->layoutSpacing(QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal) : layoutHorizontalSpacing; @@ -1421,10 +1420,9 @@ void QWizardPrivate::updateButtonTexts() void QWizardPrivate::updateButtonLayout() { if (buttonsHaveCustomLayout) { - QVarLengthArray<QWizard::WizardButton, QWizard::NButtons> array(buttonsCustomLayout.size()); - for (int i = 0; i < buttonsCustomLayout.size(); ++i) - array[i] = buttonsCustomLayout.at(i); - setButtonLayout(array.constData(), array.size()); + QVarLengthArray<QWizard::WizardButton, QWizard::NButtons> array{ + buttonsCustomLayout.cbegin(), buttonsCustomLayout.cend()}; + setButtonLayout(array.constData(), int(array.size())); } else { // Positions: // Help Stretch Custom1 Custom2 Custom3 Cancel Back Next Commit Finish Cancel Help @@ -1705,23 +1703,19 @@ void QWizardPrivate::setStyle(QStyle *style) } #ifdef Q_OS_MACOS - QPixmap QWizardPrivate::findDefaultBackgroundPixmap() { - QGuiApplication *app = qobject_cast<QGuiApplication *>(QCoreApplication::instance()); - if (!app) - return QPixmap(); - QPlatformNativeInterface *platformNativeInterface = app->platformNativeInterface(); - int at = platformNativeInterface->metaObject()->indexOfMethod("defaultBackgroundPixmapForQWizard()"); - if (at == -1) - return QPixmap(); - QMetaMethod defaultBackgroundPixmapForQWizard = platformNativeInterface->metaObject()->method(at); - QPixmap result; - if (!defaultBackgroundPixmapForQWizard.invoke(platformNativeInterface, Q_RETURN_ARG(QPixmap, result))) - return QPixmap(); - return result; -} + auto *keyboardAssistantURL = [NSWorkspace.sharedWorkspace + URLForApplicationWithBundleIdentifier:@"com.apple.KeyboardSetupAssistant"]; + auto *keyboardAssistantBundle = [NSBundle bundleWithURL:keyboardAssistantURL]; + auto *assistantBackground = [keyboardAssistantBundle imageForResource:@"Background"]; + auto size = QSizeF::fromCGSize(assistantBackground.size); + static const QSizeF expectedSize(242, 414); + if (size == expectedSize) + return qt_mac_toQPixmap(assistantBackground, size); + return QPixmap(); +} #endif #if QT_CONFIG(style_windowsvista) @@ -1766,9 +1760,8 @@ void QWizardAntiFlickerWidget::paintEvent(QPaintEvent *) \section1 A Trivial Example The following example illustrates how to create wizard pages and - add them to a wizard. For more advanced examples, see - \l{dialogs/classwizard}{Class Wizard} and \l{dialogs/licensewizard}{License - Wizard}. + add them to a wizard. For more advanced examples, see the + \l{dialogs/licensewizard}{License Wizard}. \snippet dialogs/trivialwizard/trivialwizard.cpp 1 \snippet dialogs/trivialwizard/trivialwizard.cpp 3 @@ -1897,12 +1890,7 @@ void QWizardAntiFlickerWidget::paintEvent(QPaintEvent *) To register a field, call QWizardPage::registerField() field. For example: - \snippet dialogs/classwizard/classwizard.cpp 8 - \dots - \snippet dialogs/classwizard/classwizard.cpp 10 - \snippet dialogs/classwizard/classwizard.cpp 11 - \dots - \snippet dialogs/classwizard/classwizard.cpp 13 + \snippet dialogs/licensewizard/licensewizard.cpp 21 The above code registers three fields, \c className, \c baseClass, and \c qobjectMacro, which are associated with three @@ -1913,11 +1901,11 @@ void QWizardAntiFlickerWidget::paintEvent(QPaintEvent *) The fields of any page are accessible from any other page. For example: - \snippet dialogs/classwizard/classwizard.cpp 17 + \snippet dialogs/licensewizard/licensewizard.cpp 27 Here, we call QWizardPage::field() to access the contents of the - \c className field (which was defined in the \c ClassInfoPage) - and use it to initialize the \c OutputFilePage. The field's + \c details.email field (which was defined in the \c DetailsPage) + and use it to initialize the \c ConclusionPage. The field's contents is returned as a QVariant. When we create a field using QWizardPage::registerField(), we @@ -1960,15 +1948,13 @@ void QWizardAntiFlickerWidget::paintEvent(QPaintEvent *) \section1 Creating Linear Wizards Most wizards have a linear structure, with page 1 followed by - page 2 and so on until the last page. The \l{dialogs/classwizard}{Class - Wizard} example is such a wizard. With QWizard, linear wizards + page 2 and so on until the last page. The \l{dialogs/trivialwizard} + {Trivial Wizard} example is such a wizard. With QWizard, linear wizards are created by instantiating the \l{QWizardPage}s and inserting them using addPage(). By default, the pages are shown in the order in which they were added. For example: - \snippet dialogs/classwizard/classwizard.cpp 0 - \dots - \snippet dialogs/classwizard/classwizard.cpp 2 + \snippet dialogs/trivialwizard/trivialwizard.cpp linearAddPage When a page is about to be shown, QWizard calls initializePage() (which in turn calls QWizardPage::initializePage()) to fill the @@ -2038,7 +2024,7 @@ void QWizardAntiFlickerWidget::paintEvent(QPaintEvent *) \snippet dialogs/licensewizard/licensewizard.cpp 27 - \sa QWizardPage, {Class Wizard Example}, {License Wizard Example} + \sa QWizardPage, {Trivial Wizard Example}, {License Wizard Example} */ /*! @@ -2201,8 +2187,8 @@ void QWizard::setPage(int theid, QWizardPage *page) page->setParent(d->pageFrame); QList<QWizardField> &pendingFields = page->d_func()->pendingFields; - for (int i = 0; i < pendingFields.size(); ++i) - d->addField(pendingFields.at(i)); + for (const auto &field : std::as_const(pendingFields)) + d->addField(field); pendingFields.clear(); connect(page, SIGNAL(completeChanged()), this, SLOT(_q_updateButtonStates())); @@ -2820,7 +2806,7 @@ void QWizard::setPixmap(WizardPixmap which, const QPixmap &pixmap) Returns the pixmap set for role \a which. By default, the only pixmap that is set is the BackgroundPixmap on - \macos version 10.13 and earlier. + \macos. \sa QWizardPage::pixmap(), {Elements of a Wizard Page} */ @@ -3412,7 +3398,7 @@ int QWizard::nextId() const using registerField() and can be accessed at any time using field() and setField(). - \sa QWizard, {Class Wizard Example}, {License Wizard Example} + \sa QWizard, {Trivial Wizard Example}, {License Wizard Example} */ /*! @@ -3555,7 +3541,7 @@ QPixmap QWizardPage::pixmap(QWizard::WizardPixmap which) const fields are properly initialized based on fields from previous pages. For example: - \snippet dialogs/classwizard/classwizard.cpp 17 + \snippet dialogs/licensewizard/licensewizard.cpp 27 The default implementation does nothing. @@ -3632,8 +3618,9 @@ bool QWizardPage::isComplete() const return true; const QList<QWizardField> &wizardFields = d->wizard->d_func()->fields; - for (int i = wizardFields.size() - 1; i >= 0; --i) { - const QWizardField &field = wizardFields.at(i); + const auto end = wizardFields.crend(); + for (auto it = wizardFields.crbegin(); it != end; ++it) { + const QWizardField &field = *it; if (field.page == this && field.mandatory) { QVariant value = field.object->property(field.property); if (value == field.initialValue) @@ -3859,7 +3846,7 @@ void QWizardPage::setField(const QString &name, const QVariant &value) Example: - \snippet dialogs/classwizard/classwizard.cpp 17 + \snippet dialogs/licensewizard/licensewizard.cpp accessField \sa QWizard::field(), setField(), registerField() */ |