X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FInstallWizard.cpp;h=d4bd4da508824be8ebbccc78a47bdf427883564a;hb=3fc3493387b534f9e0c536de985ac0af3413ae7a;hp=be056b12d0c4d9f2658aaeae75558b224eb057ee;hpb=d9de963885e11280b279081c9ab08d6d1ce81a2e;p=tools%2Finstall.git diff --git a/src/InstallWizard.cpp b/src/InstallWizard.cpp index be056b1..d4bd4da 100644 --- a/src/InstallWizard.cpp +++ b/src/InstallWizard.cpp @@ -1,27 +1,73 @@ -// File : InstallWizard.cpp -// Created : Thu Mar 27 12:01:00 2003 -// Author : Vadim SANDLER -// Project : SALOME Professional -// Module : InstallWizard -// Copyright : 2003 CEA/DEN, EDF R&D -// $Header$ +/**************************************************************************** +** $Id$ +** +** Definition of the QWizard class. +** +** Created : 990101 +** +** Copyright (C) 1999 by Trolltech AS. All rights reserved. +** +** This file is part of the dialogs module of the Qt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.QPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for QPL licensing information. +** 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 "InstallWizard.h" -#include "qlayout.h" -#include "qpushbutton.h" -#include "qcursor.h" -#include "qlabel.h" -#include "qwidgetstack.h" -#include "qapplication.h" -#include "qptrlist.h" -#include "qpainter.h" -#include "qaccel.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PROCESS_EVENT QEvent::User+100 + +class ProcessEvent : public QCustomEvent +{ +public: + ProcessEvent( int retValue = 0, void* data = 0 ): QCustomEvent( PROCESS_EVENT ), myReturnValue( retValue ), myData( data ) {} + const int returnValue() const { return myReturnValue; } + void* data() const { return myData; } +private: + int myReturnValue; + void* myData; +}; class InstallWizardPrivate { public: - struct Page { + struct Page { Page( QWidget * widget, const QString & title ): w( widget ), t( title ), backEnabled( TRUE ), nextEnabled( TRUE ), finishEnabled( FALSE ), @@ -42,12 +88,15 @@ public: QWidgetStack * ws; QPtrList pages; QLabel * title; + QHBox * titleBox; + QHBox * logoBox; QPushButton * backButton; QPushButton * nextButton; QPushButton * finishButton; QPushButton * cancelButton; QPushButton * helpButton; QFrame * hbar1, * hbar2; + QToolButton * aboutButton; #ifndef QT_NO_ACCEL QAccel * accel; @@ -80,8 +129,14 @@ InstallWizard::InstallWizard( QWidget *parent, const char *name, bool modal, d->current = 0; // not quite true, but... d->ws = new QWidgetStack( this, "qt_widgetstack" ); d->pages.setAutoDelete( TRUE ); - d->title = new QLabel( this, "title label" ); - + d->titleBox = new QHBox( this, "title box" ); + d->aboutButton = new QToolButton( d->titleBox, "about button"); + d->aboutButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + d->aboutButton->setAutoRaise( true ); + d->title = new QLabel( d->titleBox, "title label" ); + d->logoBox = new QHBox( d->titleBox, "logo box" ); + d->logoBox->setSpacing( 2 ); + d->titleBox->setStretchFactor( d->title, 10 ); // create in nice tab order d->nextButton = new QPushButton( this, "next" ); d->finishButton = new QPushButton( this, "finish" ); @@ -104,8 +159,12 @@ InstallWizard::InstallWizard( QWidget *parent, const char *name, bool modal, d->nextButton->setDefault( TRUE ); connect( d->backButton, SIGNAL(clicked()), + this, SIGNAL(backClicked()) ); + connect( this, SIGNAL(backClicked()), this, SLOT(back()) ); connect( d->nextButton, SIGNAL(clicked()), + this, SIGNAL(nextClicked()) ); + connect( this, SIGNAL(nextClicked()), this, SLOT(next()) ); connect( d->finishButton, SIGNAL(clicked()), this, SLOT(accept()) ); @@ -113,14 +172,18 @@ InstallWizard::InstallWizard( QWidget *parent, const char *name, bool modal, this, SLOT(reject()) ); connect( d->helpButton, SIGNAL(clicked()), this, SLOT(help()) ); + connect( d->aboutButton, SIGNAL(clicked()), + this, SIGNAL(aboutClicked()) ); #ifndef QT_NO_ACCEL 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->accel->connectItem( d->backAccel, this, SIGNAL(backClicked()) ); d->nextAccel = d->accel->insertItem( Qt::ALT + Qt::Key_Right ); - d->accel->connectItem( d->nextAccel, this, SLOT(next()) ); + d->accel->connectItem( d->nextAccel, this, SIGNAL(nextClicked()) ); #endif + + showAboutBtn( false ); } @@ -319,9 +382,21 @@ void InstallWizard::next() while ( i > 0 && (i >= (int)d->pages.count() || !d->pages.at( i ) ) ) i--; if ( d->pages.at( i ) ) { - if ( d->current && !acceptData( d->current->t ) ) - return; - showPage( d->pages.at( i )->w ); + if ( d->current ) { + setNextEnabled( false ); + setBackEnabled( false ); + if ( !acceptData( d->current->t ) ) { + setNextEnabled( true ); + setBackEnabled( true ); + return; + } + } + // VSR : commented 10/02/05 ---> + // Next page will be shown later in processValidateEvent() method + // this allows custom validation, for instance by using external processing threads. + // See SALOME_InstallWizard.cxx for details where it is used. + //showPage( d->pages.at( i )->w ); + // VSR : commented 10/02/05 <--- } } @@ -349,7 +424,9 @@ void InstallWizard::help() emit helpClicked(); } - +/*! + Enables/disables button + */ void InstallWizard::setBackEnabled( bool enable ) { d->backButton->setEnabled( enable ); @@ -358,7 +435,9 @@ void InstallWizard::setBackEnabled( bool enable ) #endif } - +/*! + Enables/disables button + */ void InstallWizard::setNextEnabled( bool enable ) { d->nextButton->setEnabled( enable ); @@ -367,13 +446,14 @@ void InstallWizard::setNextEnabled( bool enable ) #endif } - +/*! + Enables/disables button + */ void InstallWizard::setHelpEnabled( bool enable ) { d->helpButton->setEnabled( enable ); } - /*! \fn void InstallWizard::setFinish( QWidget *, bool ) \obsolete @@ -698,7 +778,7 @@ time \a title changes. void InstallWizard::layOutTitleRow( QHBoxLayout * layout, const QString & title ) { d->title->setText( title ); - layout->addWidget( d->title, 10 ); + layout->addWidget( d->titleBox, 10 ); } /*! @@ -707,6 +787,7 @@ Should return true in success */ bool InstallWizard::acceptData( const QString& ) { + postValidateEvent( this ); return TRUE; } @@ -816,3 +897,95 @@ QWidget* InstallWizard::page( const QString& title ) const } return 0; } + +/*! +Adds logo to be shown at the right of the page title +*/ +void InstallWizard::addLogo( const QPixmap& pm ) +{ + QLabel* logo = new QLabel( d->logoBox, "logo" ); + logo->setPixmap( pm ); + logo->setAlignment( AlignCenter ); + logo->setScaledContents( false ); + logo->show(); +} + +/*! +Remove all logos +*/ +void InstallWizard::removeLogos() +{ + QObjectList* children = d->logoBox->queryList( "QLabel" ); + if ( children ) { + QObjectListIt it( *children ); + QObject *obj; + while ( (obj = it.current()) != 0 ) { + ++it; + delete obj; + } + } + delete children; +} + +/*! +Show/hide "About" button +*/ +void InstallWizard::showAboutBtn( bool show ) +{ + show ? d->aboutButton->show() : d->aboutButton->hide(); +} + +/*! +Set icon for "About" button +*/ +void InstallWizard::setAboutIcon( const QPixmap& px ) +{ + d->aboutButton->setIconSet( px ); +} + +/*! +Posts validation event +*/ +void InstallWizard::postValidateEvent( InstallWizard* iw, const int val, void* data ) +{ +#if QT_VERSION > 0x030005 + QApplication::postEvent( iw, new ProcessEvent( val, data ) ); +#else + QThread::postEvent( iw, new ProcessEvent( val, data ) ); +#endif +} + +/*! +Processes validation event: default implementation just to show next page +*/ +void InstallWizard::processValidateEvent( const int /* val */, void* /* data */ ) +{ + int i = 0; + while( i < (int)d->pages.count() && d->pages.at( i ) && + d->current && d->pages.at( i )->w != d->current->w ) + i++; + i++; + while( i <= (int)d->pages.count()-1 && + ( !d->pages.at( i ) || !appropriate( d->pages.at( i )->w ) ) ) + i++; + // if we fell of the end of the world, step back + while ( i > 0 && (i >= (int)d->pages.count() || !d->pages.at( i ) ) ) + i--; + if ( d->pages.at( i ) ) { + showPage( d->pages.at( i )->w ); + } + setNextEnabled( true ); + setBackEnabled( true ); +} + +/*! +Process events received +*/ +bool InstallWizard::event ( QEvent* e ) +{ + if ( e->type() == PROCESS_EVENT ) { + ProcessEvent* pe = (ProcessEvent*)e; + processValidateEvent( pe->returnValue(), pe->data() ); + } + return QDialog::event( e ); +}