18 #include <kanimwidget.h>
21 #include <tqpainter.h>
23 #include <tdetoolbar.h>
25 #include <kiconloader.h>
27 class KAnimWidgetPrivate
30 bool loadingCompleted : 1;
43 : TQFrame( parent, name ),
44 d( new KAnimWidgetPrivate )
46 connect( &d->timer, TQ_SIGNAL(timeout()),
this, TQ_SLOT(slotTimerUpdate()));
48 if (parent && parent->inherits(
"TDEToolBar" ))
49 connect(parent, TQ_SIGNAL(modechange()),
this, TQ_SLOT(updateIcons()));
51 d->loadingCompleted =
false;
55 setFrameStyle( StyledPanel | Sunken );
80 if ( d->size ==
size )
89 if ( d->icon_name ==
icons )
107 void KAnimWidget::showEvent(TQShowEvent* e)
114 TQFrame::showEvent(e);
117 void KAnimWidget::hideEvent(TQHideEvent* e)
119 TQFrame::hideEvent(e);
122 void KAnimWidget::enterEvent( TQEvent *e )
124 setFrameStyle( Panel | Raised );
126 TQFrame::enterEvent( e );
129 void KAnimWidget::leaveEvent( TQEvent *e )
131 setFrameStyle( StyledPanel | Sunken );
133 TQFrame::leaveEvent( e );
136 void KAnimWidget::mousePressEvent( TQMouseEvent *e )
138 TQFrame::mousePressEvent( e );
141 void KAnimWidget::mouseReleaseEvent( TQMouseEvent *e )
143 if ( e->button() == TQt::LeftButton &&
144 rect().contains( e->pos() ) )
147 TQFrame::mouseReleaseEvent( e );
150 void KAnimWidget::slotTimerUpdate()
156 if (d->current_frame == d->frames)
157 d->current_frame = 0;
163 repaint(d->transparent);
166 void KAnimWidget::drawContents( TQPainter *p )
168 if ( d->pixmap.isNull() )
171 int w = d->pixmap.width();
173 int x = (width() - w) / 2;
174 int y = (height() - h) / 2;
175 p->drawPixmap(TQPoint(x, y), d->pixmap, TQRect(0, d->current_frame*h, w, h));
178 void KAnimWidget::updateIcons()
183 if (parent()->inherits(
"TDEToolBar" ))
184 d->size = ((
TDEToolBar*)parent())->iconSize();
194 d->current_frame = 0;
195 d->frames = img.height() / img.width();
196 d->transparent = img.hasAlphaBuffer();
197 if (d->pixmap.width() != d->size)
199 img = img.smoothScale(d->size, d->size*d->frames);
203 setFixedSize( d->size+2, d->size+2 );
204 resize( d->size+2, d->size+2 );
207 void KAnimWidget::virtual_hook(
int,
void* )
210 #include "kanimwidget.moc"
static TDEIconLoader * iconLoader()
int currentSize(TDEIcon::Group group) const
TQString iconPath(const TQString &name, int group_or_size, bool canReturnNull=false) const