Pianobutton.cpp
#include "pianobutton.h"
PianoButton::PianoButton(QWidget *parent, QString name) :
QPushButton(parent), start(QTime::currentTime()), summ(0), isRecord(false)
{
effect = new QSoundEffect;
que new QQueue<QTime>;
this->setFixedSize(50,100);
this->setText(name);
this->setCheckable(true);
connect(this,SIGNAL(pressed()),this,SLOT(onMousePress()));
connect(this,SIGNAL(released()),this,SLOT(onMouseRelease()));
connect(effect,&QSoundEffect::playingChanged,this,[=]()
{
if(!effect->isPlaying())
{
this->setChecked(false);
}
});
void PianoButton::timerEvent(QTimerEvent *e)
{
effect->play();
this->setChecked(true);
this->killTimer(e->timerId());
}
void PianoButton::onPress(QKeyEvent *event)
{
QString notes = "Q1W2ER4T5Y6UI8O9P[-]=,K.ZAXSCVFBGNHM";
QChar c(event->key());
if(this->text().indexOf(c)!=-1)
{
if(!this->isChecked())
{
effect->play();
}
this->setChecked(true);
}
}
void PianoButton::onPress(QKeyEvent *event, QTime elapsed)
{
QChar c(event->key());
if(this->text().indexOf(c)!=-1)
{
if(!this->isChecked())
{
que->enqueue(elapsed);
qDebug() << start.msecsTo(elapsed);
}
}
this->onPress(event);
}
void PianoButton::onRelease(QKeyEvent *event)
{
QString notes = "Q1W2ER4T5Y6UI8O9P[-]=,K.ZAXSCVFBGNHM";
QChar c(event->key());
if(this->text().indexOf(c)!=-1)
{
this->setChecked(false);
}
}
void PianoButton::onRestart(QTime time)
{
que->clear();
start = time;
isRecord = true;
}
void PianoButton::onMousePress()
{
effect->play();
this->setChecked(true);
if(isRecord)
{
que->enqueue(QTime::currentTime());
}
}
void PianoButton::onMouseRelease()
{
this->setChecked(false);
}
void PianoButton::onReplyRecord()
{
QQueue<QTime> temp = *que;
while(!temp.isEmpty())
{
this->startTimer(start.msecsTo(temp.dequeue()),Qt::PreciseTimer);
}
}
void PianoButton::onStopRecord()
{
isRecord = false;
}
Дата добавления: 2014-12-06; просмотров: 782;