From 8a79d6fbc64f60963597bda34d1d324681deec9f Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 31 Jul 2007 09:47:31 +0000 Subject: [PATCH] *** empty log message *** --- src/Qtx/Qtx.cxx | 22 ++++++++++++++++++++++ src/Qtx/Qtx.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/Qtx/Qtx.cxx b/src/Qtx/Qtx.cxx index db5c4d0b7..89d87060d 100755 --- a/src/Qtx/Qtx.cxx +++ b/src/Qtx/Qtx.cxx @@ -685,6 +685,28 @@ void Qtx::scaleColors( const int num, QColorList& lst ) lst.append( scaleColor( i, 0, num - 1 ) ); } +/*! + \brief Scale the pixmap to the required size. + + If \h is 0 (default) the value of \a w is used instead (to create + square pixmap). + + \param icon pixmap to be resized + \param w required pixmap width + \param h required pixmap height + \return scaled pixmap +*/ +QPixmap Qtx::scaleIcon( const QPixmap& icon, const unsigned w, const unsigned h ) +{ + QPixmap p; + int aw = w, ah = h <= 0 ? w : h; + if ( p.isNull() || aw <= 0 || ah <= 0 || aw == icon.width() && ah == icon.height() ) + p = icon; + else + p = icon.fromImage( icon.toImage().scaled( aw, ah, Qt::KeepAspectRatio, Qt::SmoothTransformation ) ); + return p; +} + /*! \brief Convert given image to the grayscale format. \param img initial image diff --git a/src/Qtx/Qtx.h b/src/Qtx/Qtx.h index a96420ce6..90a79b30e 100755 --- a/src/Qtx/Qtx.h +++ b/src/Qtx/Qtx.h @@ -129,6 +129,7 @@ public: static QColor scaleColor( const int, const int, const int ); static void scaleColors( const int, QColorList& ); + static QPixmap scaleIcon( const QPixmap&, const unsigned, const unsigned = 0 ); static QImage grayscale( const QImage& ); static QPixmap grayscale( const QPixmap& ); static QImage transparentImage( const int, const int, const int = -1 ); -- 2.39.2