📄 qwizard.cpp
字号:
}// keep in sync with QWizard::WizardButtonstatic const char * const buttonSlots[QWizard::NStandardButtons] = { SLOT(back()), SLOT(next()), SLOT(next()), SLOT(accept()), SLOT(reject()), SIGNAL(helpRequested())};QWizardLayoutInfo QWizardPrivate::layoutInfoForCurrentPage(){ Q_Q(QWizard); QStyle *style = q->style(); QWizardLayoutInfo info; const int layoutHorizontalSpacing = style->pixelMetric(QStyle::PM_LayoutHorizontalSpacing); info.topLevelMargin = style->pixelMetric(QStyle::PM_LayoutBottomMargin, 0, q); info.childMargin = style->pixelMetric(QStyle::PM_LayoutLeftMargin, 0, titleLabel); info.hspacing = (layoutHorizontalSpacing == -1) ? style->layoutSpacing(QSizePolicy::DefaultType, QSizePolicy::DefaultType, Qt::Horizontal) : layoutHorizontalSpacing; info.vspacing = style->pixelMetric(QStyle::PM_LayoutVerticalSpacing); info.buttonSpacing = (layoutHorizontalSpacing == -1) ? style->layoutSpacing(QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal) : layoutHorizontalSpacing;#ifdef Q_WS_MAC if (qobject_cast<QMacStyle *>(style)) info.buttonSpacing = 12;#endif info.wizStyle = wizStyle; QString titleText; QString subTitleText; QPixmap backgroundPixmap; QPixmap watermarkPixmap; if (QWizardPage *page = q->currentPage()) { titleText = page->title(); subTitleText = page->subTitle(); backgroundPixmap = page->pixmap(QWizard::BackgroundPixmap); watermarkPixmap = page->pixmap(QWizard::WatermarkPixmap); } info.header = (info.wizStyle == QWizard::ClassicStyle || info.wizStyle == QWizard::ModernStyle) && !(opts & QWizard::IgnoreSubTitles) && !subTitleText.isEmpty(); info.watermark = (info.wizStyle != QWizard::MacStyle) && (info.wizStyle != QWizard::AeroStyle) && !watermarkPixmap.isNull(); info.title = !info.header && !titleText.isEmpty(); info.subTitle = !(opts & QWizard::IgnoreSubTitles) && !info.header && !subTitleText.isEmpty(); info.extension = info.watermark && (opts & QWizard::ExtendedWatermarkPixmap); return info;}void QWizardPrivate::recreateLayout(const QWizardLayoutInfo &info){ Q_Q(QWizard); /* Start by undoing the main layout. */ for (int i = mainLayout->count() - 1; i >= 0; --i) { QLayoutItem *item = mainLayout->takeAt(i); if (item->layout()) { item->layout()->setParent(0); } else { delete item; } } for (int i = mainLayout->columnCount() - 1; i >= 0; --i) mainLayout->setColumnMinimumWidth(i, 0); for (int i = mainLayout->rowCount() - 1; i >= 0; --i) mainLayout->setRowMinimumHeight(i, 0); /* Now, recreate it. */ bool mac = (info.wizStyle == QWizard::MacStyle); bool classic = (info.wizStyle == QWizard::ClassicStyle); bool modern = (info.wizStyle == QWizard::ModernStyle); bool aero = (info.wizStyle == QWizard::AeroStyle); int deltaMargin = info.topLevelMargin - info.childMargin; int deltaVSpacing = info.topLevelMargin - info.vspacing; int row = 0; int numColumns; if (mac) { numColumns = 3; } else if (info.watermark) { numColumns = 2; } else { numColumns = 1; } int pageColumn = qMin(1, numColumns - 1); if (mac) { mainLayout->setMargin(0); mainLayout->setSpacing(0); buttonLayout->setContentsMargins(MacLayoutLeftMargin, MacButtonTopMargin, MacLayoutRightMargin, MacLayoutBottomMargin); pageVBoxLayout->setMargin(7); } else { if (modern) { mainLayout->setMargin(0); mainLayout->setSpacing(0); pageVBoxLayout->setMargin(deltaMargin); buttonLayout->setMargin(info.topLevelMargin); } else { mainLayout->setMargin(info.topLevelMargin); mainLayout->setHorizontalSpacing(info.hspacing); mainLayout->setVerticalSpacing(info.vspacing); pageVBoxLayout->setMargin(0); buttonLayout->setMargin(0); } } buttonLayout->setSpacing(info.buttonSpacing); if (info.header) { if (!headerWidget) headerWidget = new QWizardHeader(antiFlickerWidget); headerWidget->setAutoFillBackground(modern); mainLayout->addWidget(headerWidget, row++, 0, 1, numColumns); } if (headerWidget) headerWidget->setVisible(info.header); int watermarkStartRow = row; if (mac) mainLayout->setRowMinimumHeight(row++, 10); if (info.title) { if (!titleLabel) { titleLabel = new QLabel(antiFlickerWidget); titleLabel->setBackgroundRole(QPalette::Base); titleLabel->setWordWrap(true); } QFont titleFont = q->font(); titleFont.setPointSize(titleFont.pointSize() + (mac ? 3 : 4)); titleFont.setBold(true); titleLabel->setPalette(QPalette()); if (aero) { // ### hardcoded for now: titleFont = QFont(QLatin1String("Segoe UI"), 12); QPalette pal(titleLabel->palette()); pal.setColor(QPalette::Text, "#003399"); titleLabel->setPalette(pal); } titleLabel->setFont(titleFont); const int aeroTitleIndent = 25; // ### hardcoded for now - should be calculated somehow titleLabel->setIndent(aero ? aeroTitleIndent : mac ? 2 : classic ? info.childMargin : info.topLevelMargin); if (modern) { if (!placeholderWidget1) { placeholderWidget1 = new QWidget(antiFlickerWidget); placeholderWidget1->setBackgroundRole(QPalette::Base); } placeholderWidget1->setFixedHeight(info.topLevelMargin + 2); mainLayout->addWidget(placeholderWidget1, row++, pageColumn); } mainLayout->addWidget(titleLabel, row++, pageColumn); if (modern) { if (!placeholderWidget2) { placeholderWidget2 = new QWidget(antiFlickerWidget); placeholderWidget2->setBackgroundRole(QPalette::Base); } placeholderWidget2->setFixedHeight(5); mainLayout->addWidget(placeholderWidget2, row++, pageColumn); } if (mac) mainLayout->setRowMinimumHeight(row++, 7); } if (placeholderWidget1) placeholderWidget1->setVisible(info.title && modern); if (placeholderWidget2) placeholderWidget2->setVisible(info.title && modern); if (info.subTitle) { if (!subTitleLabel) { subTitleLabel = new QLabel(pageFrame); subTitleLabel->setWordWrap(true); // ideally, the same margin should be used on the right side as well subTitleLabel->setIndent(info.childMargin + 1); // ### pageVBoxLayout->insertWidget(1, subTitleLabel); } } // ### try to replace with margin. changeSpacerSize(pageVBoxLayout, 0, 0, info.subTitle ? info.childMargin : 0); int hMargin = mac ? 1 : 0; int vMargin = hMargin; pageFrame->setFrameStyle(mac ? (QFrame::Box | QFrame::Raised) : QFrame::NoFrame); pageFrame->setLineWidth(0); pageFrame->setMidLineWidth(hMargin); if (info.header) { if (modern) { hMargin = info.topLevelMargin; vMargin = deltaMargin; } else if (classic) { hMargin = deltaMargin + ClassicHMargin; vMargin = 0; } } if (aero) { int leftMargin = 18; // ### hardcoded for now - should be calculated somehow int topMargin = vMargin; int rightMargin = hMargin; // ### for now int bottomMargin = vMargin; pageFrame->setContentsMargins(leftMargin, topMargin, rightMargin, bottomMargin); } else { pageFrame->setContentsMargins(hMargin, vMargin, hMargin, vMargin); } if (info.watermark && !watermarkLabel) { watermarkLabel = new QLabel(antiFlickerWidget); watermarkLabel->setBackgroundRole(QPalette::Base); watermarkLabel->setMinimumHeight(1); watermarkLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); watermarkLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop); } //bool wasSemiTransparent = pageFrame->testAttribute(Qt::WA_SetPalette); const bool wasSemiTransparent = pageFrame->palette().brush(QPalette::Window).color().alpha() < 255 || pageFrame->palette().brush(QPalette::Base).color().alpha() < 255; if (mac) { if (!wasSemiTransparent) { QPalette pal = pageFrame->palette(); pal.setBrush(QPalette::Window, QColor(255, 255, 255, 153)); // ### The next line is required to ensure visual semitransparency when // ### switching from ModernStyle to MacStyle. See TAG1 below. pal.setBrush(QPalette::Base, QColor(255, 255, 255, 153)); pageFrame->setPalette(pal); pageFrame->setAutoFillBackground(true); antiFlickerWidget->setAutoFillBackground(false); } } else { if (wasSemiTransparent) pageFrame->setPalette(QPalette()); bool baseBackground = (modern && !info.header); // ### TAG1 pageFrame->setBackgroundRole(baseBackground ? QPalette::Base : QPalette::Window); if (titleLabel) titleLabel->setAutoFillBackground(baseBackground); pageFrame->setAutoFillBackground(baseBackground); if (watermarkLabel) watermarkLabel->setAutoFillBackground(baseBackground); if (placeholderWidget1) placeholderWidget1->setAutoFillBackground(baseBackground); if (placeholderWidget2) placeholderWidget2->setAutoFillBackground(baseBackground); if (aero) { QPalette pal = pageFrame->palette(); pal.setBrush(QPalette::Window, QColor(255, 255, 255)); pageFrame->setPalette(pal); pageFrame->setAutoFillBackground(true); pal = antiFlickerWidget->palette(); pal.setBrush(QPalette::Window, QColor(255, 255, 255)); antiFlickerWidget->setPalette(pal); antiFlickerWidget->setAutoFillBackground(true); } } mainLayout->addWidget(pageFrame, row++, pageColumn); int watermarkEndRow = row; if (classic) mainLayout->setRowMinimumHeight(row++, deltaVSpacing); if (aero) { buttonLayout->setContentsMargins(9, 9, 9, 9); mainLayout->setContentsMargins(0, 11, 0, 0); } int buttonStartColumn = info.extension ? 1 : 0; int buttonNumColumns = info.extension ? 1 : numColumns; if (classic || modern) { if (!bottomRuler) bottomRuler = new QWizardRuler(antiFlickerWidget); mainLayout->addWidget(bottomRuler, row++, buttonStartColumn, 1, buttonNumColumns); } if (classic) mainLayout->setRowMinimumHeight(row++, deltaVSpacing); mainLayout->addLayout(buttonLayout, row++, buttonStartColumn, 1, buttonNumColumns); if (info.watermark) { if (info.extension) watermarkEndRow = row; mainLayout->addWidget(watermarkLabel, watermarkStartRow, 0, watermarkEndRow - watermarkStartRow, 1); } mainLayout->setColumnMinimumWidth(0, mac && !info.watermark ? 181 : 0); if (mac) mainLayout->setColumnMinimumWidth(2, 21); if (headerWidget) headerWidget->setVisible(info.header); if (titleLabel) titleLabel->setVisible(info.title); if (subTitleLabel) subTitleLabel->setVisible(info.subTitle); if (bottomRuler) bottomRuler->setVisible(classic || modern); if (watermarkLabel) watermarkLabel->setVisible(info.watermark); layoutInfo = info;}void QWizardPrivate::updateLayout(){ Q_Q(QWizard); disableUpdates(); QWizardLayoutInfo info = layoutInfoForCurrentPage(); if (layoutInfo != info) recreateLayout(info); QWizardPage *page = q->currentPage(); if (info.header) { Q_ASSERT(page); headerWidget->setup(info, page->title(), page->subTitle(), page->pixmap(QWizard::LogoPixmap), page->pixmap(QWizard::BannerPixmap), titleFmt, subTitleFmt); } if (info.watermark) { Q_ASSERT(page); watermarkLabel->setPixmap(page->pixmap(QWizard::WatermarkPixmap)); } if (info.title) { Q_ASSERT(page); titleLabel->setTextFormat(titleFmt); titleLabel->setText(page->title()); } if (info.subTitle) { Q_ASSERT(page); subTitleLabel->setTextFormat(subTitleFmt); subTitleLabel->setText(page->subTitle()); } enableUpdates(); updateMinMaxSizes(info);}void QWizardPrivate::updateMinMaxSizes(const QWizardLayoutInfo &info){ Q_Q(QWizard); int extraHeight = 0;#if !defined(QT_NO_STYLE_WINDOWSVISTA) if (wizStyle == QWizard::AeroStyle) extraHeight = vistaHelper->titleBarSize() + vistaHelper->topOffset();#endif q->setMinimumSize(mainLayout->totalMinimumSize() + QSize(0, extraHeight));#if defined(Q_WS_WIN) if (QSysInfo::WindowsVersion > QSysInfo::WV_98) // ### See Tasks 164078 and 161660#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -