📄 qwizard.cpp
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS. All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program is distributed in the hope that it will be useful, but** WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ** See the GNU General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "qwizard.h"#ifndef QT_NO_WIZARD// This class is a copy of QWizard from Qt.//// It is copied here to maintain binary compatibility.// This class should not be used in #ifdef QT_NO_WIZARD_IMPL#include "qlayout.h"#include "qpushbutton.h"#include "qlabel.h"#include "qwidgetstack.h"#include "qapplication.h"#include "qvector.h"#include "qpainter.h"#include "qaccel.h"// NOT REVISED/*! \class QWizard qwizard.h \ingroup qtopiaemb \brief The QWizard class provides a framework for easily writing wizards. A wizard is a dialog that consists of a sequential number of steps, each consisting of a single page. QWizard provides a title for each page, and "Next", "Back", "Finish", "Cancel" and "Help" buttons, as appropriate. QWizard is not supported in the Phone Edition. First availability: Qtopia 1.6*/class QWizardPrivate{public: struct Page { Page( QWidget * widget, const QString & title ): w( widget ), t( title ), back( 0 ), backEnabled( TRUE ), nextEnabled( TRUE ), finishEnabled( FALSE ), helpEnabled( TRUE ), appropriate( TRUE ) {} QWidget * w; QString t; QWidget * back; bool backEnabled; bool nextEnabled; bool finishEnabled; bool helpEnabled; bool appropriate; }; QVBoxLayout * v; Page * current; QWidgetStack * ws; QVector<Page> pages; QLabel * title; QPushButton * backButton; QPushButton * nextButton; QPushButton * finishButton; QPushButton * cancelButton; QPushButton * helpButton; QFrame * hbar1, * hbar2; QAccel * accel; int backAccel; int nextAccel; Page * page( const QWidget * w ) { if ( !w ) return 0; int i = pages.size(); while( --i >= 0 && pages[i] && pages[i]->w != w ) { } return i >= 0 ? pages[i] : 0; }};/*! Constructs an empty wizard dialog. */QWizard::QWizard( QWidget *parent, const char *name, bool modal, WFlags f ) : QDialog( parent, name, modal, f ){ d = new QWizardPrivate(); d->current = 0; // not quite true, but... d->ws = new QWidgetStack( this ); d->pages.setAutoDelete( TRUE ); d->title = 0; // create in nice tab order d->nextButton = new QPushButton( this, "next" ); // No tr d->finishButton = new QPushButton( this, "finish" ); // No tr d->helpButton = new QPushButton( this, "help" ); // No tr d->backButton = new QPushButton( this, "back" ); // No tr d->cancelButton = new QPushButton( this, "cancel" ); // No tr d->ws->installEventFilter( this ); d->v = 0; d->hbar1 = 0; d->hbar2 = 0; d->cancelButton->setText( tr( "Cancel" ) ); d->backButton->setText( tr( "< Back" ) ); d->nextButton->setText( tr( "Next >" ) ); d->finishButton->setText( tr( "Finish" ) ); d->helpButton->setText( tr( "Help" ) ); d->nextButton->setDefault( TRUE ); connect( d->backButton, SIGNAL(clicked()), this, SLOT(back()) ); connect( d->nextButton, SIGNAL(clicked()), this, SLOT(next()) ); connect( d->finishButton, SIGNAL(clicked()), this, SLOT(accept()) ); connect( d->cancelButton, SIGNAL(clicked()), this, SLOT(reject()) ); connect( d->helpButton, SIGNAL(clicked()), this, SLOT(help()) ); d->accel = new QAccel( this, "arrow-key accel" ); d->backAccel = d->accel->insertItem( Qt::ALT + Qt::Key_Left ); d->accel->connectItem( d->backAccel, this, SLOT(back()) ); d->nextAccel = d->accel->insertItem( Qt::ALT + Qt::Key_Right ); d->accel->connectItem( d->nextAccel, this, SLOT(next()) );}/*! Destructs the object and frees any allocated resources, including,of course, all pages and controllers.*/QWizard::~QWizard(){ delete d;}/*! \reimp */void QWizard::show(){ if ( d->current ) showPage( d->current->w ); else if ( pageCount() > 0 ) showPage( d->pages[0]->w ); else showPage( 0 ); QDialog::show();}/*! \reimp */void QWizard::setFont( const QFont & font ){ QApplication::postEvent( this, new QEvent( QEvent::LayoutHint ) ); QDialog::setFont( font );}/*! Adds \a page to the end of the wizard, titled \a title.*/void QWizard::addPage( QWidget * page, const QString & title ){ if ( !page ) return; if ( d->page( page ) ) {#if defined(CHECK_STATE) qWarning( "QWizard::addPage(): already added %s/%s to %s/%s", page->className(), page->name(), className(), name() );#endif return; } int i = d->pages.size(); QWizardPrivate::Page * p = new QWizardPrivate::Page( page, title ); p->backEnabled = ( i > 0 ); d->ws->addWidget( page, i ); d->pages.resize( i+1 ); d->pages.insert( i, p );}/*! \fn void QWizard::selected(const QString&) This signal is emitted when the page changes, signalling the title of the page.*//*! Makes \a page be the displayed page and emits the selected() signal. */void QWizard::showPage( QWidget * page ){ QWizardPrivate::Page * p = d->page( page ); if ( p ) { setBackEnabled( p->back != 0 ); setNextEnabled( TRUE ); d->ws->raiseWidget( page ); d->current = p; } layOut(); updateButtons(); emit selected( p ? p->t : QString::null );}/*! Returns the number of pages in the wizard. */int QWizard::pageCount() const{ return d->pages.count();}/*! Called when the user clicks the Back button, this function shows the page which the user saw prior to the current one.*/void QWizard::back(){ if ( d->current && d->current->back ) showPage( d->current->back );}/*! Called when the user clicks the Next button, this function shows the next appropriate page.*/void QWizard::next(){ if ( nextButton()->isEnabled() ) { int i = 0; while( i < (int)d->pages.size() && d->pages[i] && d->current && d->pages[i]->w != d->current->w ) i++; i++; while( i <= (int)d->pages.size()-1 && ( !d->pages[i] || !appropriate( d->pages[i]->w ) ) ) i++; // if we fell of the end of the world, step back while ( i > 0 && (i >= (int)d->pages.size() || !d->pages[i] ) ) i--; if ( d->pages.at( i ) && d->pages.at( i ) != d->current ) { d->pages[i]->back = d->current ? d->current->w : 0; showPage( d->pages[i]->w ); } }}/*! \fn void QWizard::helpClicked() This signal is emitted when the user clicks on the help button.*//*! This slot either makes the wizard help you, if it can. The onlyway it knows is to emit the helpClicked() signal.*/void QWizard::help(){ QWidget * page = d->ws->visibleWidget(); if ( !page ) return;#if 0 if ( page->inherits( "QWizardPage" ) ) emit ((QWizardPage *)page)->helpClicked();#endif emit helpClicked();}void QWizard::setBackEnabled( bool enable ){ d->backButton->setEnabled( enable ); d->accel->setItemEnabled( d->backAccel, enable );}void QWizard::setNextEnabled( bool enable ){ d->nextButton->setEnabled( enable ); d->accel->setItemEnabled( d->nextAccel, enable );}void QWizard::setHelpEnabled( bool enable ){ d->helpButton->setEnabled( enable );}/*! \obsolete*/void QWizard::setFinish( QWidget *, bool ){ // Didn't do anything.}/*! Enables or disables the "Back" button for pages \a w in the wizard. By default, all pages have this button.*/void QWizard::setBackEnabled( QWidget * w, bool enable ){ QWizardPrivate::Page * p = d->page( w ); if ( !p ) return; p->backEnabled = enable; updateButtons();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -