From: vsr Date: Mon, 10 Feb 2020 07:31:27 +0000 (+0300) Subject: QtxSplash: add option to scale splash screen to given width/height X-Git-Tag: V9_5_0a1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=48b5edbee3573695a152ac4a9b079bde7a7b77d2;p=modules%2Fgui.git QtxSplash: add option to scale splash screen to given width/height --- diff --git a/src/Qtx/QtxSplash.cxx b/src/Qtx/QtxSplash.cxx index 3a5ecf2b8..e3c68a583 100644 --- a/src/Qtx/QtxSplash.cxx +++ b/src/Qtx/QtxSplash.cxx @@ -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 ) ) { diff --git a/src/Qtx/QtxSplash.h b/src/Qtx/QtxSplash.h index 6add6a654..4a33f2e26 100644 --- a/src/Qtx/QtxSplash.h +++ b/src/Qtx/QtxSplash.h @@ -64,6 +64,10 @@ public: static void setStatus( const QString&, const int = -1 ); static void setError( const QString&, const QString& = QString(), const int = -1 ); + void setSize( const QSize& ); + void setSize( int, int ); + QSize fixedSize() const; + void setPixmap( const QPixmap& ); QPixmap pixmap() const; @@ -152,7 +156,8 @@ private: private: static QtxSplash* mySplash; - + + QSize mySize; //!< splash size QPixmap myPixmap; //!< splash pixmap QString myInfo; //!< constant info QString myMessage; //!< current status message