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

tdeui

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

tdeui

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

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.