kwave  18.07.70
LogoWidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  LogoWidget.cpp - widget with the animated Kwave logo
3  -------------------
4  begin : Sun Oct 29 2000
5  copyright : (C) 2000 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 #include <math.h>
20 
21 #include <QBrush>
22 #include <QColor>
23 #include <QImage>
24 #include <QObject>
25 #include <QPainter>
26 #include <QPalette>
27 #include <QPolygon>
28 #include <QTimer>
29 
30 #include "libkwave/Utils.h"
31 
32 #include "LogoWidget.h"
33 #include "logo.xpm"
34 
36 #define COLOR_INCREMENT (static_cast<double>(0.001))
37 
38 //***************************************************************************
40  :QWidget(parent), m_width(-1), m_height(-1), m_repaint(false),
41  m_image(Q_NULLPTR), m_logo(xpm_aboutlogo), m_timer(Q_NULLPTR),
42  m_color_h(0.0)
43 {
44  for (int i = 0; i < MAXSIN; m_deg[i++] = 0) {}
45 
46  m_timer = new QTimer(this);
47  Q_ASSERT(m_timer);
48  if (!m_timer) return;
49  connect(m_timer, SIGNAL(timeout()), this, SLOT(doAnim()));
50 
51  // gives 40ms refresh ;-)...
52  m_timer->setInterval(40);
53  m_timer->start();
54 
55  QPalette pal = palette();
56  pal.setColor(QPalette::Window, Qt::black);
57  setPalette(pal);
58 }
59 
60 //***************************************************************************
62 {
63  double mul = 0.04131211 + m_deg[MAXSIN-1] / 75;
64 
65  for (int i = 0; i < MAXSIN; i++) {
66  m_deg[i] += mul;
67  if (m_deg[i] > 2 * M_PI) m_deg[i] = 0;
68  mul = ((mul * 521)/437);
69  mul -= floor(mul); // gives again a number between 0 and 1
70  mul /= 17;
71  mul += m_deg[i] / 100; //so that chaos may be ...
72  }
73 
74  m_repaint = true;
75  repaint();
76 }
77 
78 //***************************************************************************
80 {
81  if (m_timer) delete m_timer;
82  if (m_image) delete m_image;
83 }
84 
85 //***************************************************************************
86 void Kwave::LogoWidget::paintEvent(QPaintEvent *)
87 {
88  // if image has to be resized ...
89  if ((rect().height() != m_height) || (rect().width() != m_width)) {
90  m_height = rect().height();
91  m_width = rect().width();
92 
93  if (m_image) delete m_image;
94  m_image = new QImage(size(), QImage::Format_ARGB32_Premultiplied);
95  m_repaint = true;
96  }
97 
98  if ((m_repaint) && (m_image)) {
99  QPainter p;
100  QPolygon si(20 + 3);
101 
102  p.begin(m_image);
103 
104  // erase everything to black
105  p.setPen(Qt::black);
106  p.setBrush(Qt::black);
107  p.drawRect(0, 0, m_width, m_height);
108 
109  // blit logo bitmap
110  int ampx = (m_logo.width() - m_width ) / 2;
111  int ampy = (m_logo.height() - m_height) / 2;
112  p.setCompositionMode(QPainter::CompositionMode_Source);
113  p.drawPixmap(
114  -ampx + Kwave::toInt(sin(m_deg[0]) * ampx),
115  -ampy + Kwave::toInt(sin(m_deg[1]) * ampy),
116  m_logo);
117 
118  // draw the sine waves with XOR
119  p.setCompositionMode(QPainter::CompositionMode_Exclusion);
120  p.setBrush(QColor::fromHsvF(m_color_h, 1.0, 1.0));
121  m_color_h += COLOR_INCREMENT; // this gives the nice color change :-)
122  if (m_color_h > 1.0) m_color_h -= 1.0;
123 
124  double amp = sin(m_deg[MAXSIN - 1] * 3);
125  for (int j = 0; j < MAXSIN; j++) {
126  for (int i = 0; i < 21; i++) {
127  si.setPoint(i, (j * m_width / MAXSIN) +
128  Kwave::toInt(amp * sin(M_PI * i / 10 + m_deg[j])
129  * m_width / 2),
130  m_height * i / 20);
131  }
132  si.setPoint(21, m_width / 2, m_height);
133  si.setPoint(22, m_width / 2, 0);
134 
135  p.drawPolygon(si);
136  amp = sin(m_deg[j] * 3);
137  }
138 
139  p.end();
140  m_repaint = false;
141  }
142 
143  // blit the result to the display
144  if (m_image) {
145  QPainter p(this);
146  p.drawImage(0, 0, *m_image);
147  p.end();
148  }
149 
150 }
151 
152 //***************************************************************************
153 //***************************************************************************
virtual void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE
Definition: LogoWidget.cpp:86
QTimer * m_timer
Definition: LogoWidget.h:76
LogoWidget(QWidget *parent)
Definition: LogoWidget.cpp:39
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
QImage * m_image
Definition: LogoWidget.h:70
virtual ~LogoWidget() Q_DECL_OVERRIDE
Definition: LogoWidget.cpp:79
int toInt(T x)
Definition: Utils.h:127
#define COLOR_INCREMENT
Definition: LogoWidget.cpp:36
#define MAXSIN
Definition: LogoWidget.h:31
double m_deg[MAXSIN]
Definition: LogoWidget.h:67
static double rect(double param)
Definition: Functions.cpp:29