• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdeui
 

kdeui

  • kdeui
kanimwidget.cpp
1 // -*- c-basic-offset: 2 -*-
2 
3 /* This file is part of the KDE libraries
4  Copyright (C) 2000 Kurt Granroth <granroth@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 #include <kanimwidget.h>
21 #include <tqpixmap.h>
22 #include <tqtimer.h>
23 #include <tqpainter.h>
24 #include <tqimage.h>
25 #include <ktoolbar.h>
26 #include <kdebug.h>
27 #include <kiconloader.h>
28 
29 class KAnimWidgetPrivate
30 {
31 public:
32  bool loadingCompleted : 1;
33  bool initDone : 1;
34  bool transparent : 1;
35  int frames;
36  int current_frame;
37  TQPixmap pixmap;
38  TQTimer timer;
39  TQString icon_name;
40  int size;
41 };
42 
43 KAnimWidget::KAnimWidget( const TQString& icons, int size, TQWidget *parent,
44  const char *name )
45  : TQFrame( parent, name ),
46  d( new KAnimWidgetPrivate )
47 {
48  connect( &d->timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotTimerUpdate()));
49 
50  if (parent && parent->inherits( "KToolBar" ))
51  connect(parent, TQT_SIGNAL(modechange()), this, TQT_SLOT(updateIcons()));
52 
53  d->loadingCompleted = false;
54  d->size = size;
55  d->initDone = false;
56  setIcons( icons );
57  setFrameStyle( StyledPanel | Sunken );
58 }
59 
60 KAnimWidget::~KAnimWidget()
61 {
62  d->timer.stop();
63 
64  delete d; d = 0;
65 }
66 
67 void KAnimWidget::start()
68 {
69  d->current_frame = 0;
70  d->timer.start( 50 );
71 }
72 
73 void KAnimWidget::stop()
74 {
75  d->current_frame = 0;
76  d->timer.stop();
77  repaint();
78 }
79 
80 void KAnimWidget::setSize( int size )
81 {
82  if ( d->size == size )
83  return;
84 
85  d->size = size;
86  updateIcons();
87 }
88 
89 void KAnimWidget::setIcons( const TQString& icons )
90 {
91  if ( d->icon_name == icons )
92  return;
93 
94  d->icon_name = icons;
95  updateIcons();
96 }
97 
98 TQString KAnimWidget::icons( ) const
99 {
100  return d->icon_name;
101 }
102 
103 int KAnimWidget::size( ) const
104 {
105  return d->size;
106 }
107 
108 
109 void KAnimWidget::showEvent(TQShowEvent* e)
110 {
111  if (!d->initDone)
112  {
113  d->initDone = true;
114  updateIcons();
115  }
116  TQFrame::showEvent(e);
117 }
118 
119 void KAnimWidget::hideEvent(TQHideEvent* e)
120 {
121  TQFrame::hideEvent(e);
122 }
123 
124 void KAnimWidget::enterEvent( TQEvent *e )
125 {
126  setFrameStyle( Panel | Raised );
127 
128  TQFrame::enterEvent( e );
129 }
130 
131 void KAnimWidget::leaveEvent( TQEvent *e )
132 {
133  setFrameStyle( StyledPanel | Sunken );
134 
135  TQFrame::leaveEvent( e );
136 }
137 
138 void KAnimWidget::mousePressEvent( TQMouseEvent *e )
139 {
140  TQFrame::mousePressEvent( e );
141 }
142 
143 void KAnimWidget::mouseReleaseEvent( TQMouseEvent *e )
144 {
145  if ( e->button() == Qt::LeftButton &&
146  rect().contains( e->pos() ) )
147  emit clicked();
148 
149  TQFrame::mouseReleaseEvent( e );
150 }
151 
152 void KAnimWidget::slotTimerUpdate()
153 {
154  if(!isVisible())
155  return;
156 
157  d->current_frame++;
158  if (d->current_frame == d->frames)
159  d->current_frame = 0;
160 
161  // TODO
162  // We have to clear the widget when repainting a transparent image
163  // By doing it like this we get a bit of flicker though. A better
164  // way might be to merge it with the background in drawContents.
165  repaint(d->transparent);
166 }
167 
168 void KAnimWidget::drawContents( TQPainter *p )
169 {
170  if ( d->pixmap.isNull() )
171  return;
172 
173  int w = d->pixmap.width();
174  int h = w;
175  int x = (width() - w) / 2;
176  int y = (height() - h) / 2;
177  p->drawPixmap(TQPoint(x, y), d->pixmap, TQRect(0, d->current_frame*h, w, h));
178 }
179 
180 void KAnimWidget::updateIcons()
181 {
182  if (!d->initDone)
183  return;
184 
185  if (parent()->inherits( "KToolBar" ))
186  d->size = ((KToolBar*)parent())->iconSize();
187  if (!d->size)
188  d->size = KGlobal::iconLoader()->currentSize(KIcon::MainToolbar);
189 
190  TQString path = KGlobal::iconLoader()->iconPath(d->icon_name, -d->size);
191  TQImage img(path);
192 
193  if (img.isNull())
194  return;
195 
196  d->current_frame = 0;
197  d->frames = img.height() / img.width();
198  d->transparent = img.hasAlphaBuffer();
199  if (d->pixmap.width() != d->size)
200  {
201  img = img.smoothScale(d->size, d->size*d->frames);
202  }
203  d->pixmap = img;
204 
205  setFixedSize( d->size+2, d->size+2 );
206  resize( d->size+2, d->size+2 );
207 }
208 
209 void KAnimWidget::virtual_hook( int, void* )
210 { /*BASE::virtual_hook( id, data );*/ }
211 
212 #include "kanimwidget.moc"
KAnimWidget::setIcons
void setIcons(const TQString &icons)
Sets the name of the animated icons to load.
Definition: kanimwidget.cpp:89
KAnimWidget::KAnimWidget
KAnimWidget(const TQString &icons, int size=0, TQWidget *parent=0L, const char *name=0L)
This is the most common constructor.
Definition: kanimwidget.cpp:43
KIconLoader::currentSize
int currentSize(KIcon::Group group) const
KGlobal::iconLoader
static KIconLoader * iconLoader()
KIconLoader::iconPath
TQString iconPath(const TQString &name, int group_or_size, bool canReturnNull=false) const
KAnimWidget::setSize
void setSize(int size)
Sets the size of the icons.
Definition: kanimwidget.cpp:80
KAnimWidget::icons
TQString icons() const
Returns the current icons since 3.4.
KAnimWidget::stop
void stop()
Stops the animation.
Definition: kanimwidget.cpp:73
KAnimWidget::~KAnimWidget
virtual ~KAnimWidget()
Destructor.
Definition: kanimwidget.cpp:60
KAnimWidget::start
void start()
Starts the animation from frame 1.
Definition: kanimwidget.cpp:67
KAnimWidget::size
int size() const
Returns the current size.
KToolBar
Floatable toolbar with auto resize.
Definition: ktoolbar.h:104
KIcon::MainToolbar
MainToolbar

kdeui

Skip menu "kdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeui

Skip menu "kdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeui by doxygen 1.8.13
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |