diff options
author | Timothy Pearson <[email protected]> | 2011-07-10 15:24:15 -0500 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2011-07-10 15:24:15 -0500 |
commit | bd0f3345a938b35ce6a12f6150373b0955b8dd12 (patch) | |
tree | 7a520322212d48ebcb9fbe1087e7fca28b76185c /examples/wizard | |
download | qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.tar.gz qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.zip |
Add Qt3 development HEAD version
Diffstat (limited to 'examples/wizard')
-rw-r--r-- | examples/wizard/main.cpp | 20 | ||||
-rw-r--r-- | examples/wizard/wizard.cpp | 226 | ||||
-rw-r--r-- | examples/wizard/wizard.doc | 29 | ||||
-rw-r--r-- | examples/wizard/wizard.h | 44 | ||||
-rw-r--r-- | examples/wizard/wizard.pro | 11 |
5 files changed, 330 insertions, 0 deletions
diff --git a/examples/wizard/main.cpp b/examples/wizard/main.cpp new file mode 100644 index 0000000..b54dca4 --- /dev/null +++ b/examples/wizard/main.cpp @@ -0,0 +1,20 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "wizard.h" +#include <qapplication.h> + +int main(int argc,char **argv) +{ + QApplication a(argc,argv); + + Wizard wizard; + wizard.setCaption("Qt Example - Wizard"); + return wizard.exec(); +} diff --git a/examples/wizard/wizard.cpp b/examples/wizard/wizard.cpp new file mode 100644 index 0000000..9370efd --- /dev/null +++ b/examples/wizard/wizard.cpp @@ -0,0 +1,226 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "wizard.h" + +#include <qwidget.h> +#include <qhbox.h> +#include <qvbox.h> +#include <qlabel.h> +#include <qlineedit.h> +#include <qpushbutton.h> +#include <qvalidator.h> +#include <qapplication.h> + +Wizard::Wizard( QWidget *parent, const char *name ) + : QWizard( parent, name, TRUE ) +{ + setupPage1(); + setupPage2(); + setupPage3(); + + key->setFocus(); +} + +void Wizard::setupPage1() +{ + page1 = new QHBox( this ); + page1->setSpacing(8); + + QLabel *info = new QLabel( page1 ); + info->setMargin( 11 ); + info->setPalette( yellow ); + info->setText( "Enter your personal\n" + "key here.\n\n" + "Your personal key\n" + "consists of 4 digits" ); + info->setMaximumWidth( info->sizeHint().width() ); + + QVBox *page = new QVBox( page1 ); + + QHBox *row1 = new QHBox( page ); + + (void)new QLabel( "Key:", row1 ); + + key = new QLineEdit( row1 ); + key->setMaxLength( 4 ); + key->setValidator( new QIntValidator( 1000, 9999, key ) ); + + connect( key, SIGNAL( textChanged( const QString & ) ), + this, SLOT( keyChanged( const QString & ) ) ); + + addPage( page1, "Personal Key" ); + + setNextEnabled( page1, FALSE ); + setHelpEnabled( page1, FALSE ); +} + +void Wizard::setupPage2() +{ + page2 = new QHBox( this ); + page2->setSpacing(8); + + QLabel *info = new QLabel( page2 ); + info->setMargin( 11 ); + info->setPalette( yellow ); + info->setText( "\n" + "Enter your personal\n" + "data here.\n\n" + "The required fields are\n" + "First Name, Last Name \n" + "and E-Mail.\n" ); + info->setMaximumWidth( info->sizeHint().width() ); + + QVBox *page = new QVBox( page2 ); + + QHBox *row1 = new QHBox( page ); + QHBox *row2 = new QHBox( page ); + QHBox *row3 = new QHBox( page ); + QHBox *row4 = new QHBox( page ); + QHBox *row5 = new QHBox( page ); + + QLabel *label1 = new QLabel( " First Name: ", row1 ); + label1->setAlignment( Qt::AlignVCenter ); + QLabel *label2 = new QLabel( " Last Name: ", row2 ); + label2->setAlignment( Qt::AlignVCenter ); + QLabel *label3 = new QLabel( " Address: ", row3 ); + label3->setAlignment( Qt::AlignVCenter ); + QLabel *label4 = new QLabel( " Phone Number: ", row4 ); + label4->setAlignment( Qt::AlignVCenter ); + QLabel *label5 = new QLabel( " E-Mail: ", row5 ); + label5->setAlignment( Qt::AlignVCenter ); + + label1->setMinimumWidth( label4->sizeHint().width() ); + label2->setMinimumWidth( label4->sizeHint().width() ); + label3->setMinimumWidth( label4->sizeHint().width() ); + label4->setMinimumWidth( label4->sizeHint().width() ); + label5->setMinimumWidth( label4->sizeHint().width() ); + + firstName = new QLineEdit( row1 ); + lastName = new QLineEdit( row2 ); + address = new QLineEdit( row3 ); + phone = new QLineEdit( row4 ); + email = new QLineEdit( row5 ); + + connect( firstName, SIGNAL( textChanged( const QString & ) ), + this, SLOT( dataChanged( const QString & ) ) ); + connect( lastName, SIGNAL( textChanged( const QString & ) ), + this, SLOT( dataChanged( const QString & ) ) ); + connect( email, SIGNAL( textChanged( const QString & ) ), + this, SLOT( dataChanged( const QString & ) ) ); + + addPage( page2, "Personal Data" ); + + setHelpEnabled( page2, FALSE ); +} + +void Wizard::setupPage3() +{ + page3 = new QHBox( this ); + page3->setSpacing(8); + + QLabel *info = new QLabel( page3 ); + info->setPalette( yellow ); + info->setText( "\n" + "Look here to see of\n" + "the data you entered\n" + "is correct. To confirm,\n" + "press the [Finish] button\n" + "else go back to correct\n" + "mistakes." ); + info->setMargin( 11 ); + info->setAlignment( AlignTop|AlignLeft ); + info->setMaximumWidth( info->sizeHint().width() ); + + QVBox *page = new QVBox( page3 ); + + QHBox *row1 = new QHBox( page ); + QHBox *row2 = new QHBox( page ); + QHBox *row3 = new QHBox( page ); + QHBox *row4 = new QHBox( page ); + QHBox *row5 = new QHBox( page ); + QHBox *row6 = new QHBox( page ); + + QLabel *label1 = new QLabel( " Personal Key: ", row1 ); + label1->setAlignment( Qt::AlignVCenter ); + QLabel *label2 = new QLabel( " First Name: ", row2 ); + label2->setAlignment( Qt::AlignVCenter ); + QLabel *label3 = new QLabel( " Last Name: ", row3 ); + label3->setAlignment( Qt::AlignVCenter ); + QLabel *label4 = new QLabel( " Address: ", row4 ); + label4->setAlignment( Qt::AlignVCenter ); + QLabel *label5 = new QLabel( " Phone Number: ", row5 ); + label5->setAlignment( Qt::AlignVCenter ); + QLabel *label6 = new QLabel( " E-Mail: ", row6 ); + label6->setAlignment( Qt::AlignVCenter ); + + label1->setMinimumWidth( label1->sizeHint().width() ); + label2->setMinimumWidth( label1->sizeHint().width() ); + label3->setMinimumWidth( label1->sizeHint().width() ); + label4->setMinimumWidth( label1->sizeHint().width() ); + label5->setMinimumWidth( label1->sizeHint().width() ); + label6->setMinimumWidth( label1->sizeHint().width() ); + + lKey = new QLabel( row1 ); + lFirstName = new QLabel( row2 ); + lLastName = new QLabel( row3 ); + lAddress = new QLabel( row4 ); + lPhone = new QLabel( row5 ); + lEmail = new QLabel( row6 ); + + addPage( page3, "Finish" ); + + setFinishEnabled( page3, TRUE ); + setHelpEnabled( page3, FALSE ); +} + +void Wizard::showPage( QWidget* page ) +{ + if ( page == page1 ) { + } else if ( page == page2 ) { + } else if ( page == page3 ) { + lKey->setText( key->text() ); + lFirstName->setText( firstName->text() ); + lLastName->setText( lastName->text() ); + lAddress->setText( address->text() ); + lPhone->setText( phone->text() ); + lEmail->setText( email->text() ); + } + + QWizard::showPage(page); + + if ( page == page1 ) { + keyChanged( key->text() ); + key->setFocus(); + } else if ( page == page2 ) { + dataChanged( firstName->text() ); + firstName->setFocus(); + } else if ( page == page3 ) { + finishButton()->setEnabled( TRUE ); + finishButton()->setFocus(); + } +} + +void Wizard::keyChanged( const QString &text ) +{ + QString t = text; + int p = 0; + bool on = ( key->validator()->validate(t, p) == QValidator::Acceptable ); + nextButton()->setEnabled( on ); +} + +void Wizard::dataChanged( const QString & ) +{ + if ( !firstName->text().isEmpty() && + !lastName->text().isEmpty() && + !email->text().isEmpty() ) + nextButton()->setEnabled( TRUE ); + else + nextButton()->setEnabled( FALSE ); +} diff --git a/examples/wizard/wizard.doc b/examples/wizard/wizard.doc new file mode 100644 index 0000000..581e1b7 --- /dev/null +++ b/examples/wizard/wizard.doc @@ -0,0 +1,29 @@ +/* +*/ +/*! \page wizard-example.html + + \ingroup examples + \title Wizard + + This example shows the usage of Qt's wizard class. A wizard + should be used to help a user with complicated actions. + + <hr> + + Header file: + + \include wizard/wizard.h + + <hr> + + Implementation: + + \include wizard/wizard.cpp + + <hr> + + Main: + + \include wizard/main.cpp +*/ + diff --git a/examples/wizard/wizard.h b/examples/wizard/wizard.h new file mode 100644 index 0000000..49fcf7a --- /dev/null +++ b/examples/wizard/wizard.h @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef WIZARD_H +#define WIZARD_H + +#include <qwizard.h> + +class QWidget; +class QHBox; +class QLineEdit; +class QLabel; + +class Wizard : public QWizard +{ + Q_OBJECT + +public: + Wizard( QWidget *parent = 0, const char *name = 0 ); + + void showPage(QWidget* page); + +protected: + void setupPage1(); + void setupPage2(); + void setupPage3(); + + QHBox *page1, *page2, *page3; + QLineEdit *key, *firstName, *lastName, *address, *phone, *email; + QLabel *lKey, *lFirstName, *lLastName, *lAddress, *lPhone, *lEmail; + +protected slots: + void keyChanged( const QString & ); + void dataChanged( const QString & ); + +}; + +#endif diff --git a/examples/wizard/wizard.pro b/examples/wizard/wizard.pro new file mode 100644 index 0000000..0a85036 --- /dev/null +++ b/examples/wizard/wizard.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +TARGET = wizard + +CONFIG += qt warn_on release +DEPENDPATH = ../../include + +REQUIRES = full-config + +HEADERS = wizard.h +SOURCES = main.cpp \ + wizard.cpp |