31 #define YUILogComponent "qt-ui" 32 #include <yui/YUILog.h> 44 const string & imageFileName,
46 : QLabel( (QWidget *) parent->widgetRep() )
47 , YImage( parent, imageFileName, animated )
50 setAlignment( Qt::AlignLeft | Qt::AlignTop );
52 setScaledContents(
false );
69 YImage::setImage ( fileName, animated );
73 QMovie movie ( fromUTF8 ( imageFileName() ) );
75 if ( movie.isValid() )
77 yuiError() <<
"Couldn't load animation from " << imageFileName() << endl;
81 yuiDebug() <<
"Loading animation from " << imageFileName() << endl;
82 QLabel::setMovie ( &movie );
89 if ( fromUTF8( imageFileName() ).startsWith(
"/" ) )
94 yuiDebug() <<
"Loading pixmap from absolute path: \"" 95 << imageFileName() <<
"\"" << endl;
97 pixmap = QPixmap( fromUTF8 ( imageFileName() ) );
101 yuiDebug() <<
"Using icon loader for \"" << imageFileName() <<
"\"" << endl;
106 if ( pixmap.isNull() )
108 yuiError() <<
"Couldn't load pixmap from \"" 109 << imageFileName() <<
"\"" << endl;
115 QImage scaledImg = pixmap.toImage();
116 scaledImg = scaledImg.scaled( this->width(), this->height(), Qt::KeepAspectRatio );
117 pixmap = pixmap.fromImage( scaledImg );
120 _pixmapWidth = pixmap.size().width();
121 _pixmapHeight = pixmap.size().height();
123 QLabel::setPixmap ( pixmap );
131 if ( autoScale() == newAutoScale )
134 YImage::setAutoScale( newAutoScale );
135 setScaledContents( newAutoScale );
138 setImage( imageFileName(), animated() );
144 if ( hasZeroSize( YD_HORIZ ) )
151 return sizeHint().width();
166 if ( hasZeroSize( YD_VERT ) )
173 return sizeHint().height();
181 return _pixmapHeight;
188 resize( newWidth, newHeight );
194 yuiDebug() <<
"setEnabled: " << enable << endl;
198 setImage( imageFileName(), animated() );
203 QPixmap pixmap( fromUTF8( imageFileName() ) );
205 QLabel::setPixmap( icon.pixmap( pixmap.size(), QIcon::Disabled, QIcon::Off) );
virtual void setImage(const std::string &imageFileName, bool animated=false)
Set and display a new image.
virtual int preferredHeight()
Preferred height of the widget.
virtual void setAutoScale(bool autoScale=true)
Make the image fit into the available space.
YQImage(YWidget *parent, const std::string &imageFileName, bool animated=false)
Constructor.
QIcon loadIcon(const string &iconName) const
Load an icon.
virtual ~YQImage()
Destructor.
virtual void setEnabled(bool enabled)
if false, the image will be displayed in gray
virtual int preferredWidth()
Preferred width of the widget.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
static YQUI * ui()
Access the global Qt-UI.