1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
26 #define y2log_component "qt-ui"
27 #include <ycp/y2log.h>
34 YQImage::YQImage( YWidget * parent,
35 const string & imageFileName,
37 : QLabel( (QWidget *) parent->widgetRep() )
38 , YImage( parent, imageFileName, animated )
41 setAlignment( Qt::AlignLeft | Qt::AlignTop );
43 setScaledContents( false );
47 setImage( imageFileName, animated );
58 YQImage::setImage( const string & fileName, bool animated )
60 YImage::setImage( fileName, animated );
64 QMovie movie( fromUTF8( imageFileName() ) );
66 if ( movie.isValid() )
68 y2error( "Couldn't load animation from %s", imageFileName().c_str() );
72 y2debug( "Loading animation from %s", imageFileName().c_str() );
73 QLabel::setMovie( &movie );
78 QPixmap pixmap( fromUTF8( imageFileName() ) );
80 if ( pixmap.isNull() )
82 y2error( "Couldn't load pixmap from %s", imageFileName().c_str() );
93 _pixmapWidth = pixmap.size().width();
94 _pixmapHeight = pixmap.size().height();
97 y2debug( "Loading image from %s (%d x %d)",
98 imageFileName().c_str(),
99 pixmap.size().width(),
100 pixmap.size().height() );
102 QLabel::setPixmap( pixmap );
107 void YQImage::setAutoScale( bool newAutoScale )
109 if ( autoScale() == newAutoScale )
112 YImage::setAutoScale( newAutoScale );
113 setScaledContents( newAutoScale );
115 // Trigger image re-display
116 setImage( imageFileName(), animated() );
120 int YQImage::preferredWidth()
122 if ( hasZeroSize( YD_HORIZ ) )
127 // a QMovie doesn't have a size() method, thus use sizeHint() instead.
129 return sizeHint().width();
133 // for non-animated images, the background pixmap is used, thus
134 // sizeHint() will always return ( 0,0 ) - thus, use the internally
135 // stored sizes instead.
142 int YQImage::preferredHeight()
144 if ( hasZeroSize( YD_VERT ) )
149 // a QMovie doesn't have a size() method, thus use sizeHint() instead.
151 return sizeHint().height();
155 // for non-animated images, the background pixmap is used, thus
156 // sizeHint() will always return ( 0,0 ) - thus, use the internally
157 // stored sizes instead.
159 return _pixmapHeight;
164 void YQImage::setSize( int newWidth, int newHeight )
166 resize( newWidth, newHeight );
169 void YQImage::setEnabled( bool enable )
171 qDebug("setEnabled %d", enable);
173 setImage( imageFileName(), animated() );
175 // Trigger image re-display
176 QPixmap pixmap( fromUTF8( imageFileName() ) );
178 QLabel::setPixmap( icon.pixmap( pixmap.size(), QIcon::Disabled, QIcon::Off) );
182 #include "YQImage.moc"