Salome HOME
updated copyright message
[modules/gui.git] / src / Qtx / QtxSplash.cxx
index 968d41fc2a5f0a08c0a214ee0a045b483d081ded..b5c1b24cc5b359f215b73619e2bcf9d3a1b1c66b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -200,9 +200,9 @@ QtxSplash::QtxSplash( const QPixmap& pixmap )
   myMargin( 5 ),
   myOpacity( 1.0 ),
   myError( 0 ),
-  myShowPercent( true ),
   myShowProgress( true ),
-  myShowMessage( true )
+  myShowMessage( true ),
+  myShowPercent( true )
 {
   setAttribute( Qt::WA_DeleteOnClose, true );
   setPixmap( pixmap );
@@ -272,10 +272,50 @@ void QtxSplash::setError( const QString& error, const QString& title, const int
                            tr( "&OK" ) );
   }
   else {
-    printf( "QtxSplash::error: %s\n",error.toLatin1().constData() );
+    qCritical( "QtxSplash::error: %s\n", qPrintable( error ) );
   }
 }
 
+/*!
+  \brief Set fixed size of splash screen.
+
+  If size is not set explicitly, it is inherited from image being used.
+  Otherwise, image is rescaled to given size.
+
+  Width and height can be given indepdently; not given dimension
+  (zero of negative value) is ignored.
+
+  \param size fixed splash size
+  \sa fixedSize()
+*/
+void QtxSplash::setSize( const QSize& size )
+{
+  mySize = size;
+  setPixmap( pixmap() );
+}
+
+/*!
+  \brief This is an overloaded function.
+
+  \param w width
+  \param h height
+  \sa fixedSize()
+*/
+void QtxSplash::setSize( int w, int h )
+{
+  setSize( QSize( w, h ) );
+}
+
+/*!
+  \brief Get fixed splash screen's size if it was set.
+  \sa setSize()
+*/
+QSize QtxSplash::fixedSize() const
+{
+  return mySize;
+}
+
+
 /*!
   \brief Set the pixmap that will be used as the splash screen's image.
   \param pixmap spash screen image pixmap
@@ -283,6 +323,9 @@ void QtxSplash::setError( const QString& error, const QString& title, const int
 */
 void QtxSplash::setPixmap( const QPixmap& pixmap )
 {
+  if ( pixmap.isNull() )
+    return;
+
   if ( pixmap.hasAlpha() ) {
     QPixmap opaque( pixmap.size() );
     QPainter p( &opaque );
@@ -294,6 +337,18 @@ void QtxSplash::setPixmap( const QPixmap& pixmap )
   else {
     myPixmap = pixmap;
   }
+
+  int width = fixedSize().width();
+  int height = fixedSize().height();
+  if ( width > 0 || height > 0 ) {
+    QImage img = myPixmap.toImage();
+    img = img.scaled( width > 0 ? width : myPixmap.width(),
+                      height > 0 ? height : myPixmap.height(),
+                      Qt::IgnoreAspectRatio,
+                      Qt::SmoothTransformation );
+    myPixmap = QPixmap::fromImage( img );
+  }
+
   QRect r( 0, 0, myPixmap.size().width(), myPixmap.size().height() );
   resize( myPixmap.size() );
   move( QApplication::desktop()->screenGeometry().center() - r.center() );
@@ -856,7 +911,11 @@ void QtxSplash::repaint()
 void QtxSplash::readSettings( QtxResourceMgr* resMgr, const QString& section )
 {
   QString resSection = section.isEmpty() ? QString( "splash" ) : section;
-  
+
+  // size
+  setSize( resMgr->integerValue( resSection, "width", 0 ),
+           resMgr->integerValue( resSection, "height", 0 ) );
+
   // pixmap
   QString pxname;
   if ( resMgr->value( resSection, "image", pxname ) ) {