From cb303ccad89cf50b9f4f9f625ec7fb73bd8e25a9 Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 29 Jan 2008 08:44:16 +0000 Subject: [PATCH] Improve splash screen: add margin attribute --- src/Qtx/QtxSplash.cxx | 94 +++++++++++++++++---------- src/Qtx/QtxSplash.h | 4 ++ src/SalomeApp/resources/SalomeApp.xml | 3 +- 3 files changed, 66 insertions(+), 35 deletions(-) diff --git a/src/Qtx/QtxSplash.cxx b/src/Qtx/QtxSplash.cxx index d3244efc9..ff4808076 100644 --- a/src/Qtx/QtxSplash.cxx +++ b/src/Qtx/QtxSplash.cxx @@ -66,6 +66,7 @@ QtxSplash::QtxSplash( const QPixmap& pixmap ) myGradientType = Vertical; myError = 0; myStartColor = red; + myMargin = 5; setPixmap( pixmap ); } @@ -256,6 +257,30 @@ int QtxSplash::textAlignment() const return myAlignment; } +/*! + \brief Set margin. + + Margin is used when drawing progress bar and status messages. + + \param m new margin + \sa margin() +*/ +void QtxSplash::setMargin( const int m ) +{ + myMargin = m; + repaint(); +} + +/*! + \brief Get margin. + \return current margin. + \sa setMargin() +*/ +int QtxSplash::margin() const +{ + return myMargin; +} + /*! Sets message text color to \a color. Default is white. @@ -382,29 +407,11 @@ void QtxSplash::clear() void QtxSplash::drawContents( QPainter* painter ) { QRect r = rect(); + int m = margin(); if ( myTotal > 0 ) { - // draw progress bar outline rectangle - painter->setPen( palette().active().dark() ); - 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()-5-_PROGRESS_WIDTH, - r.width()-5, - r.height()-5 ); // draw progress bar if ( myGradientType == Horizontal ) { - int tng = r.width() - r.x() - 11; + int tng = r.width() - r.x() - m*2; int ng = (int) ( 1.0 * tng * ( myProgress > 0 ? myProgress : 0 ) / myTotal ); int h1, h2, s1, s2, v1, v2; myStartColor.hsv( &h1, &s1, &v1 ); @@ -415,29 +422,48 @@ void QtxSplash::drawContents( QPainter* painter ) s1 + ((s2-s1)*i)/(tng-1), v1 + ((v2-v1)*i)/(tng-1), QColor::Hsv ) ); - painter->drawLine( r.x()+6+i, - r.height()-5-_PROGRESS_WIDTH+1, - r.x()+6+i, - r.height()-6 ); + painter->drawLine( r.x()+m+i, + r.height()-m-_PROGRESS_WIDTH, + r.x()+m+i, + r.height()-m ); } } else { - int ng = (int) ( 1.0 * (r.width() - r.x() - 11) * ( myProgress > 0 ? myProgress : 0 ) / myTotal ); + int ng = (int) ( 1.0 * (r.width() - r.x() - m*2 - 1) * ( 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 < _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), + for ( int i = 0; i < _PROGRESS_WIDTH; i++ ) { + painter->setPen( QColor( h1 + ((h2-h1)*i)/(_PROGRESS_WIDTH-1), + s1 + ((s2-s1)*i)/(_PROGRESS_WIDTH-1), + v1 + ((v2-v1)*i)/(_PROGRESS_WIDTH-1), QColor::Hsv ) ); - painter->drawLine( r.x()+6, - r.height()-5-_PROGRESS_WIDTH+1+i, - r.x()+6+ng-1, - r.height()-5-_PROGRESS_WIDTH+1+i ); + painter->drawLine( r.x()+m, + r.height()-m-_PROGRESS_WIDTH+i, + r.x()+m+ng, + r.height()-m-_PROGRESS_WIDTH+i ); } } + // draw progress bar outline rectangle + painter->setPen( palette().active().dark() ); + painter->drawLine( r.x()+m, + r.height()-m-_PROGRESS_WIDTH, + r.width()-m, + r.height()-m-_PROGRESS_WIDTH ); + painter->drawLine( r.x()+m, + r.height()-m-_PROGRESS_WIDTH, + r.x()+m, + r.height()-m ); + painter->setPen( palette().active().light() ); + painter->drawLine( r.x()+m, + r.height()-m, + r.width()-m, + r.height()-m ); + painter->drawLine( r.width()-m, + r.height()-m-_PROGRESS_WIDTH, + r.width()-m, + r.height()-m ); } // draw status if ( !myMessage.isEmpty() ) { @@ -447,7 +473,7 @@ void QtxSplash::drawContents( QPainter* painter ) int i = myMessage.length() - 1; while( i >= 0 && myMessage[ i-- ] == '\n' ) shift += spacing; - QRect r1( r.x() + 5, r.y() + 5, r.width() - 10, r.height() - 10 - shift ); + QRect r1( r.x() + m, r.y() + m, r.width() - m*2, r.height() - m*2 - shift ); QRect r2 = r1; if ( myAlignment & Qt::AlignLeft ) r2.setLeft ( r2.left() + 1 ); if ( myAlignment & Qt::AlignTop ) r2.setTop ( r2.top() + 1 ); diff --git a/src/Qtx/QtxSplash.h b/src/Qtx/QtxSplash.h index b6ade167c..05b7088a1 100644 --- a/src/Qtx/QtxSplash.h +++ b/src/Qtx/QtxSplash.h @@ -66,6 +66,9 @@ public: void setTextAlignment( const int ); int textAlignment() const; + void setMargin( const int ); + int margin() const; + void setTextColor( const QColor& ); QColor textColor() const; void setTextColors( const QColor&, const QColor& = QColor() ); @@ -109,6 +112,7 @@ private: QColor myEndColor; int myGradientType; int myError; + int myMargin; }; #endif diff --git a/src/SalomeApp/resources/SalomeApp.xml b/src/SalomeApp/resources/SalomeApp.xml index 3fe19a79e..04a671cfe 100644 --- a/src/SalomeApp/resources/SalomeApp.xml +++ b/src/SalomeApp/resources/SalomeApp.xml @@ -27,7 +27,8 @@ - + +
-- 2.39.2