📄 q3wizard.cpp
字号:
void Q3Wizard::setNextEnabled( bool enable ){ d->nextButton->setEnabled( enable );#ifndef QT_NO_ACCEL d->accel->setItemEnabled( d->nextAccel, enable );#endif}void Q3Wizard::setHelpEnabled( bool enable ){ d->helpButton->setEnabled( enable );}/*! \fn void Q3Wizard::setFinish(QWidget *widget, bool finish) \obsolete Use setFinishEnabled() instead.*//*! If \a enable is true, page \a page has a Back button; otherwise \a page has no Back button. By default all pages have this button.*/void Q3Wizard::setBackEnabled( QWidget * page, bool enable ){ Q3WizardPrivate::Page * p = d->page( page ); if ( !p ) return; p->backEnabled = enable; updateButtons();}/*! If \a enable is true, page \a page has a Next button; otherwise the Next button on \a page is disabled. By default all pages have this button.*/void Q3Wizard::setNextEnabled( QWidget * page, bool enable ){ Q3WizardPrivate::Page * p = d->page( page ); if ( !p ) return; p->nextEnabled = enable; updateButtons();}/*! If \a enable is true, page \a page has a Finish button; otherwise \a page has no Finish button. By default \e no page has this button.*/void Q3Wizard::setFinishEnabled( QWidget * page, bool enable ){ Q3WizardPrivate::Page * p = d->page( page ); if ( !p ) return; p->finishEnabled = enable; updateButtons();}/*! If \a enable is true, page \a page has a Help button; otherwise \a page has no Help button. By default all pages have this button.*/void Q3Wizard::setHelpEnabled( QWidget * page, bool enable ){ Q3WizardPrivate::Page * p = d->page( page ); if ( !p ) return; p->helpEnabled = enable; updateButtons();}/*! Called when the Next button is clicked; this virtual function returns true if \a page is relevant for display in the current context; otherwise it is ignored by Q3Wizard and returns false. The default implementation returns the value set using setAppropriate(). The ultimate default is true. \warning The last page of the wizard will be displayed if no page is relevant in the current context.*/bool Q3Wizard::appropriate( QWidget * page ) const{ Q3WizardPrivate::Page * p = d->page( page ); return p ? p->appropriate : true;}/*! If \a appropriate is true then page \a page is considered relevant in the current context and should be displayed in the page sequence; otherwise \a page should not be displayed in the page sequence. \sa appropriate()*/void Q3Wizard::setAppropriate( QWidget * page, bool appropriate ){ Q3WizardPrivate::Page * p = d->page( page ); if ( p ) p->appropriate = appropriate;}void Q3Wizard::updateButtons(){ if ( !d->current ) return; int i; for( i = 0; i < (int)d->pages.count() && d->pages.at( i ) != d->current; i++ ); bool notFirst( false ); if( i ) { i--; while( ( i >= 0 ) && !notFirst ) { notFirst |= appropriate( d->pages.at( i )->w ); i--; } } setBackEnabled( d->current->backEnabled && notFirst ); setNextEnabled( d->current->nextEnabled ); d->finishButton->setEnabled( d->current->finishEnabled ); d->helpButton->setEnabled( d->current->helpEnabled ); if ( ( d->current->finishEnabled && !d->finishButton->isVisible() ) || ( d->current->backEnabled && !d->backButton->isVisible() ) || ( d->current->nextEnabled && !d->nextButton->isVisible() ) || ( d->current->helpEnabled && !d->helpButton->isVisible() ) ) layOut();}/*! Returns a pointer to the current page in the sequence. Although the wizard does its best to make sure that this value is never 0, it can be if you try hard enough.*/QWidget * Q3Wizard::currentPage() const{ return d->current ? d->current->w : 0;}/*! Returns the title of page \a page.*/QString Q3Wizard::title( QWidget * page ) const{ Q3WizardPrivate::Page * p = d->page( page ); return p ? p->t : QString();}/*! Sets the title for page \a page to \a title.*/void Q3Wizard::setTitle( QWidget *page, const QString &title ){ Q3WizardPrivate::Page * p = d->page( page ); if ( p ) p->t = title; if ( page == currentPage() ) d->title->setText( title );}/*! \property Q3Wizard::titleFont \brief the font used for page titles The default is QApplication::font().*/QFont Q3Wizard::titleFont() const{ return d->title->font();}void Q3Wizard::setTitleFont( const QFont & font ){ d->title->setFont( font );}/*! Returns a pointer to the dialog's Back button By default, this button is connected to the back() slot, which is virtual so you can reimplement it in a Q3Wizard subclass. Use setBackEnabled() to enable/disable this button.*/QPushButton * Q3Wizard::backButton() const{ return d->backButton;}/*! Returns a pointer to the dialog's Next button By default, this button is connected to the next() slot, which is virtual so you can reimplement it in a Q3Wizard subclass. Use setNextEnabled() to enable/disable this button.*/QPushButton * Q3Wizard::nextButton() const{ return d->nextButton;}/*! Returns a pointer to the dialog's Finish button By default, this button is connected to the QDialog::accept() slot, which is virtual so you can reimplement it in a Q3Wizard subclass. Use setFinishEnabled() to enable/disable this button.*/QPushButton * Q3Wizard::finishButton() const{ return d->finishButton;}/*! Returns a pointer to the dialog's Cancel button By default, this button is connected to the QDialog::reject() slot, which is virtual so you can reimplement it in a Q3Wizard subclass.*/QPushButton * Q3Wizard::cancelButton() const{ return d->cancelButton;}/*! Returns a pointer to the dialog's Help button By default, this button is connected to the help() slot, which is virtual so you can reimplement it in a Q3Wizard subclass. Use setHelpEnabled() to enable/disable this button.*/QPushButton * Q3Wizard::helpButton() const{ return d->helpButton;}/*! This virtual function is responsible for adding the buttons below the bottom divider. \a layout is the horizontal layout of the entire wizard.*/void Q3Wizard::layOutButtonRow( QHBoxLayout * layout ){ bool hasHelp = false; bool hasEarlyFinish = false; int i = d->pages.count() - 2; while ( !hasEarlyFinish && i >= 0 ) { if ( d->pages.at( i ) && d->pages.at( i )->finishEnabled ) hasEarlyFinish = true; i--; } i = 0; while ( !hasHelp && i < (int)d->pages.count() ) { if ( d->pages.at( i ) && d->pages.at( i )->helpEnabled ) hasHelp = true; i++; } QBoxLayout * h = new QBoxLayout( QBoxLayout::LeftToRight ); layout->addLayout( h ); if ( hasHelp ) h->addWidget( d->helpButton ); else d->helpButton->hide(); h->addStretch( 42 ); h->addWidget( d->backButton ); h->addSpacing( 6 ); if (d->current == d->pages.at( d->pages.count()-1 )) hasEarlyFinish = false; if ( hasEarlyFinish ) { d->nextButton->show(); d->finishButton->show(); h->addWidget( d->nextButton ); h->addSpacing( 12 ); h->addWidget( d->finishButton ); } else if ( d->pages.count() == 0 || (d->current && d->current->finishEnabled) || d->current == d->pages.at( d->pages.count()-1 ) ) { d->nextButton->hide(); d->finishButton->show(); h->addWidget( d->finishButton ); } else { d->nextButton->show(); d->finishButton->hide(); h->addWidget( d->nextButton ); } // if last page is disabled - show finished btn. at lastpage-1 i = d->pages.count()-1; if ( i >= 0 && !appropriate( d->pages.at( i )->w ) && d->current == d->pages.at( d->pages.count()-2 ) ) { d->nextButton->hide(); d->finishButton->show(); h->addWidget( d->finishButton ); } h->addSpacing( 12 ); h->addWidget( d->cancelButton );}/*! This virtual function is responsible for laying out the title row. \a layout is the horizontal layout for the wizard, and \a title is the title for this page. This function is called every time \a title changes.*/void Q3Wizard::layOutTitleRow( QHBoxLayout * layout, const QString & title ){ d->title->setText( title ); layout->addWidget( d->title, 10 );}/**/void Q3Wizard::layOut(){ delete d->v; d->v = new QVBoxLayout( this, 6, 0, "top-level layout" ); QHBoxLayout * l; l = new QHBoxLayout( 6 ); d->v->addLayout( l, 0 ); layOutTitleRow( l, d->current ? d->current->t : QString() ); if ( ! d->hbar1 ) { d->hbar1 = new QFrame( this, "<hr>", 0 ); d->hbar1->setFrameStyle( QFrame::Sunken + QFrame::HLine ); d->hbar1->setFixedHeight( 12 ); } d->v->addWidget( d->hbar1 ); if (d->current) d->v->addWidget(d->current->w, 10); if ( ! d->hbar2 ) { d->hbar2 = new QFrame( this, "<hr>", 0 ); d->hbar2->setFrameStyle( QFrame::Sunken + QFrame::HLine ); d->hbar2->setFixedHeight( 12 ); } d->v->addWidget( d->hbar2 ); l = new QHBoxLayout( 6 ); d->v->addLayout( l ); layOutButtonRow( l ); d->v->activate();}/*! \reimp*/bool Q3Wizard::eventFilter( QObject * o, QEvent * e ){ return QDialog::eventFilter( o, e );}/*! Removes \a page from the page sequence but does not delete the page. If \a page is currently being displayed, Q3Wizard will display the page that precedes it, or the first page if this was the first page.*/void Q3Wizard::removePage( QWidget * page ){ if ( !page ) return; int i = d->pages.count(); QWidget* cp = currentPage(); while( --i >= 0 && d->pages.at( i ) && d->pages.at( i )->w != page ) { } if ( i < 0 ) return; delete d->pages.takeAt(i); page->hide(); if( cp == page ) { i--; if( i < 0 ) i = 0; if ( pageCount() > 0 ) showPage( Q3Wizard::page( i ) ); } else if (pageCount() > 0) { showPage(cp); }}/*! Returns a pointer to the page at position \a index in the sequence, or 0 if \a index is out of range. The first page has index 0.*/QWidget* Q3Wizard::page( int index ) const{ if ( index >= pageCount() || index < 0 ) return 0; return d->pages.at( index )->w;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -