blob: 4862aa975ec1ab560bd094611d91d5b81edc4470 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include "happybirthday.h"
#include <QTimer>
HappyBirthday::HappyBirthday(QObject *parent)
: QObject(parent), m_line(-1)
{
setName(QString());
QTimer *timer = new QTimer(this);
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(advance()));
timer->start(1000);
}
void HappyBirthday::setTarget(const QmlMetaProperty &p)
{
m_target = p;
}
QString HappyBirthday::name() const
{
return m_name;
}
void HappyBirthday::setName(const QString &name)
{
m_name = name;
m_lyrics.clear();
m_lyrics << "Happy birthday to you,";
m_lyrics << "Happy birthday to you,";
m_lyrics << "Happy birthday dear " + m_name + ",";
m_lyrics << "Happy birthday to you!";
m_lyrics << "";
}
void HappyBirthday::advance()
{
m_line = (m_line + 1) % m_lyrics.count();
m_target.write(m_lyrics.at(m_line));
}
QML_DEFINE_TYPE(People, 1, 0, 0, HappyBirthday, HappyBirthday);
|