31 #define YUILogComponent "qt-ui" 32 #include <yui/YUILog.h> 40 const std::string & imageFileName,
42 : QLabel( (QWidget *) parent->widgetRep() )
43 , YImage( parent, imageFileName, animated )
46 setAlignment( Qt::AlignLeft | Qt::AlignTop );
48 setScaledContents(
false );
65 YImage::setImage ( fileName, animated );
69 QMovie movie ( fromUTF8 ( imageFileName() ) );
71 if ( movie.isValid() )
73 yuiError() <<
"Couldn't load animation from " << imageFileName() << std::endl;
77 yuiDebug() <<
"Loading animation from " << imageFileName() << std::endl;
78 QLabel::setMovie ( &movie );
84 if (QIcon::hasThemeIcon(imageFileName().c_str()))
86 yuiDebug() <<
"Trying theme icon from " << imageFileName() << std::endl;
87 QIcon icon = QIcon::fromTheme(imageFileName().c_str());
88 pixmap = icon.pixmap(22);
92 pixmap = QPixmap( fromUTF8 ( imageFileName() ) );
95 if ( pixmap.isNull() )
97 yuiError() <<
"Couldn't load pixmap from " << imageFileName() << std::endl;
103 QImage scaledImg = pixmap.toImage();
104 scaledImg = scaledImg.scaled ( this->width(), this->height(), Qt::KeepAspectRatio );
105 pixmap = pixmap.fromImage ( scaledImg );
107 _pixmapWidth = pixmap.size().width();
108 _pixmapHeight = pixmap.size().height();
110 yuiDebug() <<
"Loading image from " << imageFileName()
111 <<
" (" << pixmap.size().width() <<
" x " << pixmap.size().height() <<
")" 114 QLabel::setPixmap ( pixmap );
121 if ( autoScale() == newAutoScale )
124 YImage::setAutoScale( newAutoScale );
125 setScaledContents( newAutoScale );
128 setImage( imageFileName(), animated() );
134 if ( hasZeroSize( YD_HORIZ ) )
141 return sizeHint().width();
156 if ( hasZeroSize( YD_VERT ) )
163 return sizeHint().height();
171 return _pixmapHeight;
178 resize( newWidth, newHeight );
183 yuiDebug() <<
"setEnabled: " << enable << std::endl;
187 setImage( imageFileName(), animated() );
192 QPixmap pixmap( fromUTF8( imageFileName() ) );
194 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.
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.