1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
23 #define y2log_component "qt-ui"
24 #include <ycp/y2log.h>
31 YQImage::YQImage( YWidget * parent,
32 const string & imageFileName,
34 : QLabel( (QWidget *) parent->widgetRep() )
35 , YImage( parent, imageFileName, animated )
38 setAlignment( Qt::AlignLeft | Qt::AlignTop );
40 setScaledContents( false );
44 setImage( imageFileName, animated );
55 YQImage::setImage( const string & fileName, bool animated )
57 YImage::setImage( fileName, animated );
61 QMovie movie( fromUTF8( imageFileName() ) );
65 y2error( "Couldn't load animation from %s", imageFileName().c_str() );
69 y2debug( "Loading animation from %s", imageFileName().c_str() );
70 QLabel::setMovie( movie );
75 QPixmap pixmap( fromUTF8( imageFileName() ) );
77 if ( pixmap.isNull() )
79 y2error( "Couldn't load pixmap from %s", imageFileName().c_str() );
90 _pixmapWidth = pixmap.size().width();
91 _pixmapHeight = pixmap.size().height();
94 y2debug( "Loading image from %s (%d x %d)",
95 imageFileName().c_str(),
96 pixmap.size().width(),
97 pixmap.size().height() );
99 QLabel::setPixmap( pixmap );
104 void YQImage::setAutoScale( bool newAutoScale )
106 if ( autoScale() == newAutoScale )
109 YImage::setAutoScale( newAutoScale );
110 setScaledContents( newAutoScale );
112 // Trigger image re-display
113 setImage( imageFileName(), animated() );
117 int YQImage::preferredWidth()
119 if ( hasZeroSize( YD_HORIZ ) )
124 // a QMovie doesn't have a size() method, thus use sizeHint() instead.
126 return sizeHint().width();
130 // for non-animated images, the background pixmap is used, thus
131 // sizeHint() will always return ( 0,0 ) - thus, use the internally
132 // stored sizes instead.
139 int YQImage::preferredHeight()
141 if ( hasZeroSize( YD_VERT ) )
146 // a QMovie doesn't have a size() method, thus use sizeHint() instead.
148 return sizeHint().height();
152 // for non-animated images, the background pixmap is used, thus
153 // sizeHint() will always return ( 0,0 ) - thus, use the internally
154 // stored sizes instead.
156 return _pixmapHeight;
161 void YQImage::setSize( int newWidth, int newHeight )
163 resize( newWidth, newHeight );
167 #include "YQImage.moc"