31 #define YUILogComponent "qt-ui" 32 #include <yui/YUILog.h> 43 const std::string & imageFileName,
45 : QLabel( (QWidget *) parent->widgetRep() )
46 , YImage( parent, imageFileName, animated )
49 setAlignment( Qt::AlignLeft | Qt::AlignTop );
51 setScaledContents(
false );
68 YImage::setImage ( fileName, animated );
72 QMovie movie ( fromUTF8 ( imageFileName() ) );
74 if ( movie.isValid() )
76 yuiError() <<
"Couldn't load animation from " << imageFileName() << endl;
80 yuiDebug() <<
"Loading animation from " << imageFileName() << endl;
81 QLabel::setMovie ( &movie );
88 if ( fromUTF8( imageFileName() ).startsWith(
"/" ) )
93 yuiDebug() <<
"Loading pixmap from absolute path: \"" 94 << imageFileName() <<
"\"" << endl;
96 pixmap = QPixmap( fromUTF8 ( imageFileName() ) );
100 yuiDebug() <<
"Using icon loader for \"" << imageFileName() <<
"\"" << endl;
105 if ( pixmap.isNull() )
107 yuiError() <<
"Couldn't load pixmap from \"" 108 << imageFileName() <<
"\"" << endl;
114 QImage scaledImg = pixmap.toImage();
115 scaledImg = scaledImg.scaled( this->width(), this->height(), Qt::KeepAspectRatio );
116 pixmap = pixmap.fromImage( scaledImg );
119 _pixmapWidth = pixmap.size().width();
120 _pixmapHeight = pixmap.size().height();
122 QLabel::setPixmap ( pixmap );
130 if ( autoScale() == newAutoScale )
133 YImage::setAutoScale( newAutoScale );
134 setScaledContents( newAutoScale );
137 setImage( imageFileName(), animated() );
143 if ( hasZeroSize( YD_HORIZ ) )
150 return sizeHint().width();
165 if ( hasZeroSize( YD_VERT ) )
172 return sizeHint().height();
180 return _pixmapHeight;
187 resize( newWidth, newHeight );
192 yuiDebug() <<
"setEnabled: " << enable << endl;
196 setImage( imageFileName(), animated() );
201 QPixmap pixmap( fromUTF8( imageFileName() ) );
203 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.