📄 qwizard.cpp
字号:
public: enum TriState { Tri_Unknown = -1, Tri_False, Tri_True }; inline QWizardPagePrivate() : wizard(0), completeState(Tri_Unknown), explicitlyFinal(false), commit(false) {} bool cachedIsComplete() const; void _q_maybeEmitCompleteChanged(); void _q_updateCachedCompleteState(); QWizard *wizard; QString title; QString subTitle; QPixmap pixmaps[QWizard::NPixmaps]; QVector<QWizardField> pendingFields; mutable TriState completeState; bool explicitlyFinal; bool commit; QMap<int, QString> buttonCustomTexts;};bool QWizardPagePrivate::cachedIsComplete() const{ Q_Q(const QWizardPage); if (completeState == Tri_Unknown) completeState = q->isComplete() ? Tri_True : Tri_False; return completeState == Tri_True;}void QWizardPagePrivate::_q_maybeEmitCompleteChanged(){ Q_Q(QWizardPage); TriState newState = q->isComplete() ? Tri_True : Tri_False; if (newState != completeState) emit q->completeChanged();}void QWizardPagePrivate::_q_updateCachedCompleteState(){ Q_Q(QWizardPage); completeState = q->isComplete() ? Tri_True : Tri_False;}class QWizardAntiFlickerWidget : public QWidget{ QWizard *wizard; QWizardPrivate *wizardPrivate;public: QWizardAntiFlickerWidget(QWizard *wizard, QWizardPrivate *wizardPrivate) : QWidget(wizard) , wizard(wizard) , wizardPrivate(wizardPrivate) {}#if !defined(QT_NO_STYLE_WINDOWSVISTA)protected: void paintEvent(QPaintEvent *);#endif};class QWizardPrivate : public QDialogPrivate{ Q_DECLARE_PUBLIC(QWizard)public: typedef QMap<int, QWizardPage *> PageMap; enum Direction { Backward, Forward }; inline QWizardPrivate() : start(-1), current(-1), canContinue(false), canFinish(false), disableUpdatesCount(0), currentPageExplicitlyIncomplete(false), currentPageExplicitlyFinal(false), opts(0), buttonsHaveCustomLayout(false), titleFmt(Qt::AutoText), subTitleFmt(Qt::AutoText), placeholderWidget1(0), placeholderWidget2(0), headerWidget(0), watermarkLabel(0), titleLabel(0), subTitleLabel(0), bottomRuler(0)#if !defined(QT_NO_STYLE_WINDOWSVISTA) , wasCompositionEnabled(false)#endif , aeroStyleOverride(false) { for (int i = 0; i < QWizard::NButtons; ++i) btns[i] = 0; } void init(); void reset(); void cleanupPagesNotInHistory(); void addField(const QWizardField &field); void switchToPage(int newId, Direction direction); QWizardLayoutInfo layoutInfoForCurrentPage(); void recreateLayout(const QWizardLayoutInfo &info); void updateLayout(); void updateMinMaxSizes(const QWizardLayoutInfo &info); bool ensureButton(QWizard::WizardButton which) const; void connectButton(QWizard::WizardButton which) const; void updateButtonTexts(); void updateButtons(); void setButtonLayout(const QWizard::WizardButton *array, int size); bool buttonLayoutContains(QWizard::WizardButton which); void updatePixmap(QWizard::WizardPixmap which);#if !defined(QT_NO_STYLE_WINDOWSVISTA) void handleAeroStyleChange();#endif void disableUpdates(); void enableUpdates(); void _q_emitCustomButtonClicked(); void _q_updateButtonStates();#ifdef Q_WS_MAC static QPixmap findDefaultBackgroundPixmap();#endif PageMap pageMap; QVector<QWizardField> fields; QMap<QString, int> fieldIndexMap; QVector<QWizardDefaultProperty> defaultPropertyTable; QList<int> history; QSet<int> initialized; // ### remove and move bit to QWizardPage? int start; int current; bool canContinue; bool canFinish; QWizardLayoutInfo layoutInfo; int disableUpdatesCount; bool currentPageExplicitlyIncomplete; // ### written but never read -> remove? bool currentPageExplicitlyFinal; // ### written but never read -> remove? QWizard::WizardStyle wizStyle; QWizard::WizardOptions opts; QMap<int, QMap<int, QString> > buttonDefaultTexts; QMap<int, QString> buttonCustomTexts; bool buttonsHaveCustomLayout; QList<QWizard::WizardButton> buttonsCustomLayout; Qt::TextFormat titleFmt; Qt::TextFormat subTitleFmt; mutable QPixmap defaultPixmaps[QWizard::NPixmaps]; union { // keep in sync with QWizard::WizardButton mutable struct { QAbstractButton *back; QAbstractButton *next; QAbstractButton *commit; QAbstractButton *finish; QAbstractButton *cancel; QAbstractButton *help; } btn; mutable QAbstractButton *btns[QWizard::NButtons]; }; QWizardAntiFlickerWidget *antiFlickerWidget; QWidget *placeholderWidget1; QWidget *placeholderWidget2; QWizardHeader *headerWidget; QLabel *watermarkLabel; QFrame *pageFrame; QLabel *titleLabel; QLabel *subTitleLabel; QWizardRuler *bottomRuler; QVBoxLayout *pageVBoxLayout; QHBoxLayout *buttonLayout; QGridLayout *mainLayout;#if !defined(QT_NO_STYLE_WINDOWSVISTA) QVistaHelper *vistaHelper; bool wasCompositionEnabled;#endif bool aeroStyleOverride;};void QWizardPrivate::init(){ Q_Q(QWizard); antiFlickerWidget = new QWizardAntiFlickerWidget(q, this); wizStyle = QWizard::WizardStyle(q->style()->styleHint(QStyle::SH_WizardStyle, 0, q)); if (wizStyle == QWizard::MacStyle) { opts = (QWizard::NoDefaultButton | QWizard::NoCancelButton); } else if (wizStyle == QWizard::ModernStyle) { opts = QWizard::HelpButtonOnRight; } for (int wstyle = 0; wstyle < QWizard::NStyles; ++wstyle) { QMap<int, QString> texts; // keep in sync with QWizard::WizardButton if (wstyle == QWizard::MacStyle) { texts.insert(QWizard::BackButton, QWizard::tr("Go Back")); texts.insert(QWizard::NextButton, QWizard::tr("Continue")); texts.insert(QWizard::CommitButton, QWizard::tr("Commit")); texts.insert(QWizard::FinishButton, QWizard::tr("Done")); texts.insert(QWizard::CancelButton, QWizard::tr("Quit")); texts.insert(QWizard::HelpButton, QWizard::tr("Help")); } else { texts.insert(QWizard::BackButton, QWizard::tr("< &Back")); texts.insert( QWizard::NextButton, wstyle == QWizard::AeroStyle ? QWizard::tr("&Next") : QWizard::tr("&Next >")); texts.insert(QWizard::CommitButton, QWizard::tr("Commit")); texts.insert(QWizard::FinishButton, QWizard::tr("&Finish")); texts.insert(QWizard::CancelButton, QWizard::tr("Cancel")); texts.insert(QWizard::HelpButton, QWizard::tr("&Help")); } buttonDefaultTexts.insert(wstyle, texts); } // create these buttons right away; create the other buttons as necessary ensureButton(QWizard::BackButton); ensureButton(QWizard::NextButton); ensureButton(QWizard::CommitButton); ensureButton(QWizard::FinishButton); pageFrame = new QFrame(antiFlickerWidget); pageFrame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); pageVBoxLayout = new QVBoxLayout(pageFrame); pageVBoxLayout->setSpacing(0); pageVBoxLayout->addSpacing(0); pageVBoxLayout->addStretch(1); buttonLayout = new QHBoxLayout; mainLayout = new QGridLayout(antiFlickerWidget); mainLayout->setSizeConstraint(QLayout::SetNoConstraint); updateButtons(); for (int i = 0; i < NFallbackDefaultProperties; ++i) defaultPropertyTable.append(QWizardDefaultProperty(fallbackProperties[i].className, fallbackProperties[i].property, fallbackProperties[i].changedSignal));#if !defined(QT_NO_STYLE_WINDOWSVISTA) vistaHelper = new QVistaHelper(q); wasCompositionEnabled = vistaHelper->isCompositionEnabled(); vistaHelper->backButton()->move( 0, vistaHelper->topOffset() - qMin(vistaHelper->topOffset(), vistaHelper->topPadding())); if (vistaHelper->isCompositionEnabled()) wizStyle = QWizard::AeroStyle; handleAeroStyleChange();#endif}void QWizardPrivate::reset(){ Q_Q(QWizard); if (current != -1) { q->currentPage()->hide(); cleanupPagesNotInHistory(); for (int i = history.count() - 1; i >= 0; --i) q->cleanupPage(history.at(i)); history.clear(); initialized.clear(); current = -1; emit q->currentIdChanged(-1); }}void QWizardPrivate::cleanupPagesNotInHistory(){ Q_Q(QWizard); const QSet<int> original = initialized; QSet<int>::const_iterator i = original.constBegin(); QSet<int>::const_iterator end = original.constEnd(); for (; i != end; ++i) { if (!history.contains(*i)) { q->cleanupPage(*i); initialized.remove(*i); } }}void QWizardPrivate::addField(const QWizardField &field){ QWizardField myField = field; myField.resolve(defaultPropertyTable); if (fieldIndexMap.contains(myField.name)) { qWarning("QWizardPage::addField: Duplicate field '%s'", qPrintable(myField.name)); return; } fieldIndexMap.insert(myField.name, fields.count()); fields += myField; if (myField.mandatory && !myField.changedSignal.isEmpty()) QObject::connect(myField.object, myField.changedSignal, myField.page, SLOT(_q_maybeEmitCompleteChanged()));}void QWizardPrivate::switchToPage(int newId, Direction direction){ Q_Q(QWizard); disableUpdates(); int oldId = current; if (QWizardPage *oldPage = q->currentPage()) { oldPage->hide(); if (direction == Backward) { if (!(opts & QWizard::IndependentPages)) { q->cleanupPage(oldId); initialized.remove(oldId); } Q_ASSERT(history.last() == oldId); history.removeLast(); Q_ASSERT(history.last() == newId); } } current = newId; currentPageExplicitlyIncomplete = false; currentPageExplicitlyFinal = false; QWizardPage *newPage = q->currentPage(); if (newPage) { if (direction == Forward) { if (!initialized.contains(current)) { initialized.insert(current); q->initializePage(current); } history.append(current); } newPage->show(); } canContinue = (q->nextId() != -1); canFinish = (newPage && newPage->isFinalPage()); _q_updateButtonStates(); updateButtonTexts(); const QWizard::WizardButton nextOrCommit = newPage && newPage->isCommitPage() ? QWizard::CommitButton : QWizard::NextButton; QAbstractButton *nextOrFinishButton = btns[canContinue ? nextOrCommit : QWizard::FinishButton]; QWidget *candidate = 0; /* If there is no default button and the Next or Finish button is enabled, give focus directly to it as a convenience to the user. This is the normal case on Mac OS X. Otherwise, give the focus to the new page's first child that can handle it. If there is no such child, give the focus to Next or Finish. */ if ((opts & QWizard::NoDefaultButton) && nextOrFinishButton->isEnabled()) { candidate = nextOrFinishButton; } else if (newPage) { candidate = iWantTheFocus(newPage); } if (!candidate) candidate = nextOrFinishButton; candidate->setFocus(); if (wizStyle == QWizard::MacStyle) q->updateGeometry(); enableUpdates(); updateLayout(); emit q->currentIdChanged(current);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -