kwave  18.07.70
StatusWidget.cpp
Go to the documentation of this file.
1 /*************************************************************************
2  StatusWidget.cpp - little widget with status icons
3  -------------------
4  begin : Sat Apr 15 2006
5  copyright : (C) 2006 by Thomas Eschenbacher
6  email : Thomas.Eschenbacher@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 
20 #include <QPainter>
21 #include <QPixmap>
22 
23 #include "libkwave/Utils.h"
24 
25 #include "StatusWidget.h"
26 
27 //***************************************************************************
29  :QWidget(parent), m_pixmaps(), m_index(0), m_timer()
30 {
31  connect(&m_timer, SIGNAL(timeout()),
32  this, SLOT(nextPixmap()));
33 }
34 
35 //***************************************************************************
37 {
38  m_timer.stop();
39  m_pixmaps.clear();
40 }
41 
42 //***************************************************************************
44 {
45  if (!m_pixmaps.count()) return;
46 
47  QPixmap pixmap = m_pixmaps.at(m_index);
48  const int ww = width();
49  const int wh = height();
50  const int pw = pixmap.width();
51  const int ph = pixmap.height();
52 
53  QPainter p(this);
54  p.drawPixmap((ww - pw) >> 1, (wh - ph) >> 1, pixmap);
55 }
56 
57 //***************************************************************************
58 void Kwave::StatusWidget::setPixmaps(const QVector<QPixmap> &pixmaps,
59  unsigned int speed)
60 {
61  m_timer.stop();
62  m_pixmaps.clear();
63  m_pixmaps = pixmaps;
64  m_index = 0;
65  repaint();
66 
67  m_timer.setSingleShot(false);
68  m_timer.setInterval(speed);
69  if (m_pixmaps.count() > 1) m_timer.start();
70 }
71 
72 //***************************************************************************
74 {
75  m_index++;
76  if (Kwave::toInt(m_index) >= m_pixmaps.count())
77  m_index = 0;
78  repaint();
79 }
80 
81 //***************************************************************************
82 //***************************************************************************
void setPixmaps(const QVector< QPixmap > &pixmaps, unsigned int speed=150)
virtual void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
StatusWidget(QWidget *parent=Q_NULLPTR)
QVector< QPixmap > m_pixmaps
Definition: StatusWidget.h:66
int toInt(T x)
Definition: Utils.h:127
virtual ~StatusWidget() Q_DECL_OVERRIDE
unsigned int m_index
Definition: StatusWidget.h:69