From 4b8890ff5c0d097f82fb3b9eca2a8a36501ce92d Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 2 May 2006 10:24:33 +0000 Subject: [PATCH] Improve splash screen --- src/Qtx/QtxSplash.cxx | 118 +++++++++++++++++++++++++++++++--------- src/Qtx/QtxSplash.h | 9 ++- src/SUITApp/SUITApp.cxx | 12 +++- 3 files changed, 110 insertions(+), 29 deletions(-) diff --git a/src/Qtx/QtxSplash.cxx b/src/Qtx/QtxSplash.cxx index f2a70117b..3b8737394 100644 --- a/src/Qtx/QtxSplash.cxx +++ b/src/Qtx/QtxSplash.cxx @@ -24,22 +24,25 @@ #include #include #include +#include -#define PROGRESS_EVENT QEvent::User + 10 +const int _PROGRESS_EVENT = QEvent::User + 10; +const int _PROGRESS_WIDTH = 10; /*! - Class ProgressEvent [internal]. + Class ProgressEvent [ internal ]. */ class ProgressEvent: public QCustomEvent { public: ProgressEvent( const QString& msg, const int progress = 0 ) - : QCustomEvent( PROGRESS_EVENT ), + : QCustomEvent( id() ), myMessage( msg ), myProgress( progress ) {} - QString message() const { return myMessage; } - int progress() const { return myProgress; } + QString message() const { return myMessage; } + int progress() const { return myProgress; } + static int id() { return _PROGRESS_EVENT; } private: QString myMessage; @@ -53,7 +56,7 @@ QtxSplash* QtxSplash::mySplash = 0; Construct a splash screen that will display the \a pixmap. */ QtxSplash::QtxSplash( const QPixmap& pixmap ) - : QWidget( 0, 0, WStyle_Customize | WStyle_StaysOnTop ) + : QWidget( 0, 0, WStyle_Customize | WStyle_StaysOnTop | WX11BypassWM | WStyle_NoBorder ) { myAlignment = AlignBottom | AlignRight; myColor = white; @@ -61,7 +64,7 @@ QtxSplash::QtxSplash( const QPixmap& pixmap ) myProgress = 0; myTotal = 0; myGradientType = Vertical; - + myError = 0; myStartColor = red; setPixmap( pixmap ); @@ -101,6 +104,21 @@ void QtxSplash::setStatus( const QString& msg, } } +/*! + Sets error status and shows error message box to the user. +*/ +void QtxSplash::error( const QString& error, const QString& title, const int code ) +{ + printf("QtxSplash::error: %s\n",error.latin1()); + if ( mySplash ) { + mySplash->setError( code ); + QMessageBox::critical( mySplash, + title.isEmpty() ? tr( "Error" ) : title, + error, + tr( "&OK" ) ); + } +} + /*! Sets the pixmap that will be used as the splash screen's image to \a pixmap. @@ -280,6 +298,23 @@ void QtxSplash::textColors( QColor& color, QColor& shadow ) const shadow = myShadowColor; } +/*! + Returns current status message. +*/ +QString QtxSplash::message() const +{ + return myMessage; +} + +/*! + Return error code. If no errors were occured returns 0. + Error code can be set by error( QString&, QString, int ). +*/ +int QtxSplash::error() const +{ + return myError; +} + /*! Makes the splash screen wait until the widget \a mainWin is displayed before calling close() on itself. @@ -348,48 +383,71 @@ void QtxSplash::drawContents( QPainter* painter ) { QRect r = rect(); if ( myTotal > 0 ) { + // draw progress bar outline rectangle painter->setPen( palette().active().dark() ); - painter->drawLine( r.x()+5, r.height()-15, r.width()-5, r.height()-15 ); - painter->drawLine( r.x()+5, r.height()-15, r.x()+5, r.height()-5 ); + painter->drawLine( r.x()+5, + r.height()-5-_PROGRESS_WIDTH, + r.width()-5, + r.height()-5-_PROGRESS_WIDTH ); + painter->drawLine( r.x()+5, + r.height()-5-_PROGRESS_WIDTH, + r.x()+5, + r.height()-5 ); painter->setPen( palette().active().light() ); - painter->drawLine( r.x()+5, r.height()-5, r.width()-5, r.height()-5 ); - painter->drawLine( r.width()-5, r.height()-15, r.width()-5, r.height()-5 ); + painter->drawLine( r.x()+5, + r.height()-5, + r.width()-5, + r.height()-5 ); + painter->drawLine( r.width()-5, + r.height()-5-_PROGRESS_WIDTH, + r.width()-5, + r.height()-5 ); + // draw progress bar if ( myGradientType == Horizontal ) { int tng = r.width() - r.x() - 11; - int ng = (int) ( 1.0 * (r.width() - r.x() - 11) * ( myProgress > 0 ? myProgress : 0 ) / myTotal ); + int ng = (int) ( 1.0 * tng * ( myProgress > 0 ? myProgress : 0 ) / myTotal ); int h1, h2, s1, s2, v1, v2; myStartColor.hsv( &h1, &s1, &v1 ); - myEndColor.isValid() ? myEndColor.hsv( &h2, &s2, &v2 ) : myStartColor.hsv( &h2, &s2, &v2 ); + myEndColor.isValid() ? myEndColor.hsv( &h2, &s2, &v2 ) : + myStartColor.hsv( &h2, &s2, &v2 ); for ( int i = 0; i < ng; i++ ) { painter->setPen( QColor( h1 + ((h2-h1)*i)/(tng-1), s1 + ((s2-s1)*i)/(tng-1), v1 + ((v2-v1)*i)/(tng-1), QColor::Hsv ) ); - painter->drawLine( r.x()+6+i, r.height()-14, r.x()+6+i, r.height()-6 ); + painter->drawLine( r.x()+6+i, + r.height()-5-_PROGRESS_WIDTH+1, + r.x()+6+i, + r.height()-6 ); } } else { int ng = (int) ( 1.0 * (r.width() - r.x() - 11) * ( myProgress > 0 ? myProgress : 0 ) / myTotal ); int h1, h2, s1, s2, v1, v2; myStartColor.hsv( &h1, &s1, &v1 ); - myEndColor.isValid() ? myEndColor.hsv( &h2, &s2, &v2 ) : myStartColor.hsv( &h2, &s2, &v2 ); - for ( int i = 0; i < 9; i++ ) { - painter->setPen( QColor( h1 + ((h2-h1)*i)/8, - s1 + ((s2-s1)*i)/8, - v1 + ((v2-v1)*i)/8, + myEndColor.isValid() ? myEndColor.hsv( &h2, &s2, &v2 ) : + myStartColor.hsv( &h2, &s2, &v2 ); + for ( int i = 0; i < _PROGRESS_WIDTH-1; i++ ) { + painter->setPen( QColor( h1 + ((h2-h1)*i)/(_PROGRESS_WIDTH-2), + s1 + ((s2-s1)*i)/(_PROGRESS_WIDTH-2), + v1 + ((v2-v1)*i)/(_PROGRESS_WIDTH-2), QColor::Hsv ) ); - painter->drawLine( r.x()+6, r.height()-14+i, r.x()+6+ng, r.height()-14+i ); + painter->drawLine( r.x()+6, + r.height()-5-_PROGRESS_WIDTH+1+i, + r.x()+6+ng-1, + r.height()-5-_PROGRESS_WIDTH+1+i ); } } } + // draw status if ( !myMessage.isEmpty() ) { - int shift = myTotal > 0 ? 12 : 0; - int bottom = 0; QFontMetrics f( font() ); + int spacing = f.lineSpacing(); + int shift = myTotal > 0 ? _PROGRESS_WIDTH : _PROGRESS_WIDTH; // : 0 int i = myMessage.length() - 1; while( i >= 0 && myMessage[ i-- ] == '\n' ) - bottom += f.lineSpacing(); - QRect r1( r.x() + 5, r.y() + 5, r.width() - 10, r.height() - 10 - shift - bottom ); + shift += spacing; + QRect r1( r.x() + 5, r.y() + 5, r.width() - 10, r.height() - 10 - shift ); QRect r2 = r1; if ( myAlignment & Qt::AlignLeft ) r2.setLeft ( r2.left() + 1 ); if ( myAlignment & Qt::AlignTop ) r2.setTop ( r2.top() + 1 ); @@ -421,7 +479,7 @@ void QtxSplash::mousePressEvent( QMouseEvent* ) */ void QtxSplash::customEvent( QCustomEvent* ce ) { - if ( ce->type() == PROGRESS_EVENT ) { + if ( ce->type() == ProgressEvent::id() ) { ProgressEvent* pe = (ProgressEvent*)ce; pe->message().isEmpty() ? clear() : message( pe->message() ); setProgress( pe->progress() ); @@ -430,7 +488,7 @@ void QtxSplash::customEvent( QCustomEvent* ce ) } /*! - Draws the splash screen window. + Draws the splash screen window [ internal ]. */ void QtxSplash::drawContents() { @@ -439,3 +497,11 @@ void QtxSplash::drawContents() drawContents( &painter ); setErasePixmap( textPix ); } + +/*! + Sets error code [ internal ]. +*/ +void QtxSplash::setError( const int code ) +{ + myError = code; +} diff --git a/src/Qtx/QtxSplash.h b/src/Qtx/QtxSplash.h index 65527e29a..cc24f7fce 100644 --- a/src/Qtx/QtxSplash.h +++ b/src/Qtx/QtxSplash.h @@ -44,7 +44,8 @@ public: virtual ~QtxSplash(); static QtxSplash* splash( const QPixmap& = QPixmap() ); - static void setStatus( const QString& msg, const int progress = 0 ); + static void setStatus( const QString&, const int = 0 ); + static void error( const QString&, const QString& = QString::null, const int = -1 ); void setPixmap( const QPixmap& ); QPixmap pixmap() const; @@ -69,6 +70,10 @@ public: QColor textColor() const; void setTextColors( const QColor&, const QColor& = QColor() ); void textColors( QColor&, QColor& ) const; + + QString message() const; + + int error() const; void finish( QWidget* ); void repaint(); @@ -87,6 +92,7 @@ protected: private: void drawContents(); + void setError( const int ); private: static QtxSplash* mySplash; @@ -102,6 +108,7 @@ private: QColor myStartColor; QColor myEndColor; int myGradientType; + int myError; }; #endif diff --git a/src/SUITApp/SUITApp.cxx b/src/SUITApp/SUITApp.cxx index de2f76d96..57098d0cc 100644 --- a/src/SUITApp/SUITApp.cxx +++ b/src/SUITApp/SUITApp.cxx @@ -169,6 +169,14 @@ int main( int args, char* argv[] ) resMgr->value( "splash", "image", splashIcon ); resMgr->value( "splash", "info", splashInfo, false ); resMgr->value( "splash", "text_colors", splashTextColors ); + QString appName = QObject::tr( "APP_NAME" ).stripWhiteSpace(); + QString appVersion = QObject::tr( "APP_VERSION" ).stripWhiteSpace(); + if ( appVersion == "APP_VERSION" ) { + if ( appName == "APP_NAME" || appName.lower() == "salome" ) + appVersion = salomeVersion(); + else + appVersion = ""; + } QPixmap px( splashIcon ); if ( !px.isNull() ) { splash = QtxSplash::splash( px ); @@ -189,8 +197,8 @@ int main( int args, char* argv[] ) f.setBold( true ); splash->setFont( f ); if ( !splashInfo.isEmpty() ) { - splashInfo.replace( QRegExp( "%A" ), QObject::tr( "APP_NAME" ) ); - splashInfo.replace( QRegExp( "%V" ), QObject::tr( "ABOUT_VERSION" ).arg( salomeVersion() ) ); + splashInfo.replace( QRegExp( "%A" ), appName ); + splashInfo.replace( QRegExp( "%V" ), QObject::tr( "ABOUT_VERSION" ).arg( appVersion ) ); splashInfo.replace( QRegExp( "%L" ), QObject::tr( "ABOUT_LICENSE" ) ); splashInfo.replace( QRegExp( "%C" ), QObject::tr( "ABOUT_COPYRIGHT" ) ); splashInfo.replace( QRegExp( "\\\\n" ), "\n" ); -- 2.39.2