1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
25 #define y2log_component "qt-ui"
26 #include <ycp/y2log.h>
33 YQImage::YQImage( YWidget * parent,
34 const string & imageFileName,
36 : QLabel( (QWidget *) parent->widgetRep() )
37 , YImage( parent, imageFileName, animated )
40 setAlignment( Qt::AlignLeft | Qt::AlignTop );
42 setScaledContents( false );
46 setImage( imageFileName, animated );
57 YQImage::setImage( const string & fileName, bool animated )
59 YImage::setImage( fileName, animated );
63 QMovie movie( fromUTF8( imageFileName() ) );
67 y2error( "Couldn't load animation from %s", imageFileName().c_str() );
71 y2debug( "Loading animation from %s", imageFileName().c_str() );
72 QLabel::setMovie( &movie );
77 QPixmap pixmap( fromUTF8( imageFileName() ) );
79 if ( pixmap.isNull() )
81 y2error( "Couldn't load pixmap from %s", imageFileName().c_str() );
92 _pixmapWidth = pixmap.size().width();
93 _pixmapHeight = pixmap.size().height();
96 y2debug( "Loading image from %s (%d x %d)",
97 imageFileName().c_str(),
98 pixmap.size().width(),
99 pixmap.size().height() );
101 QLabel::setPixmap( pixmap );
106 void YQImage::setAutoScale( bool newAutoScale )
108 if ( autoScale() == newAutoScale )
111 YImage::setAutoScale( newAutoScale );
112 setScaledContents( newAutoScale );
114 // Trigger image re-display
115 setImage( imageFileName(), animated() );
119 int YQImage::preferredWidth()
121 if ( hasZeroSize( YD_HORIZ ) )
126 // a QMovie doesn't have a size() method, thus use sizeHint() instead.
128 return sizeHint().width();
132 // for non-animated images, the background pixmap is used, thus
133 // sizeHint() will always return ( 0,0 ) - thus, use the internally
134 // stored sizes instead.
141 int YQImage::preferredHeight()
143 if ( hasZeroSize( YD_VERT ) )
148 // a QMovie doesn't have a size() method, thus use sizeHint() instead.
150 return sizeHint().height();
154 // for non-animated images, the background pixmap is used, thus
155 // sizeHint() will always return ( 0,0 ) - thus, use the internally
156 // stored sizes instead.
158 return _pixmapHeight;
163 void YQImage::setSize( int newWidth, int newHeight )
165 resize( newWidth, newHeight );
169 #include "YQImage.moc"