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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| #include "GUI.h"
#include <stdio.h>
#include <QtGui>
#include <QtCore>
#include <time.h>
#include <string>
#include <fstream>
#include <iostream>
#include <QKeyEvent>
using namespace std;
GUI::GUI(QWidget *parent)
: QMainWindow(parent)
{
//initialise l'interface
this->interface.setupUi(this);
thread = new Media(this);
paused=true;
//émission vers le thread
connect(this->interface.playButton, SIGNAL(clicked()), this, SLOT(sPlay()));
connect(this->interface.loopButton, SIGNAL(clicked()), this, SLOT(sLoop()));
connect(this->interface.stopButton, SIGNAL(clicked()), this, SLOT(sStop()));
connect(this->interface.transportSlider, SIGNAL(sliderReleased()), this, SLOT(sPosition()));
connect(this->interface.solo, SIGNAL(clicked()), this, SLOT(sVolume()));
connect(this->interface.level, SIGNAL(released()), this, SLOT(sVolume()));
//réception depuis thread :
connect(thread, SIGNAL(renderPlay()), this, SLOT(rPlay()));
connect(thread, SIGNAL(renderPause()), this, SLOT(rPause()));
connect(thread, SIGNAL(renderStop()), this, SLOT(rStop()));
connect(thread, SIGNAL(renderPosition(unsigned int position)), this, SLOT(rPosition(unsigned int position)));
};
GUI::~GUI(){
};
//reception from keyboard
void GUI::keyPressEvent(QKeyEvent *event){
if (event->key()==Qt::Key_Space){
sPlay();//alterne play et pause
}
if (event->key()==Qt::Key_S){//solo-mute pour le son, également daisable avec la checkBox solo
this->interface.solo->setChecked(!this->interface.solo1->isChecked());//actualise la checkBox solo
sVolume();// volume 0 (si muté) ou x, avec x = la valeur du slider de volume
}
if (event->key()==Qt::Key_P){
sPlay();//play ou pause, en fonction de bool::paused
}
};
//send to thread
void GUI::sStop(){
thread->stop();//ou quit ? exit ?... ou ~thread() ?
};
void GUI::sPosition(){
int new_pos = this->interface.transportSlider->value();
thread->setTrackPosition(new_pos);//change la position de la tete de lecture dans le media, ca marche très bien
};
void GUI::sPlay(){
if(!thread->launched) {//si on a pas démarré la lecture
this->sPosition();//position tete lecture, ca ne marche pas ici
thread->start();//lancement du thread contenant play
thread->launched=true;//actualisation état play/stop
}
else{
paused=!paused;//actualisation état play/pause
thread->pause();
}
};
void GUI::sLoop(){
thread->loop(this->interface.loopButton->isChecked());//pour l'instant les 2 états sont en mode OFF
};
void GUI::sVolume(){
if(this->interface.solo->isChecked()){//si on est en solo, réglage volume
unsigned int new_vol=this->interface.level1->value();
thread->setMainVolume(new_vol);
}
else{//sinon on mute le son
thread->setMainVolume(0);
}
};
//reception from thread
void GUI::rStop(){//affiche le checker "stop", remonte le boutton play
this->interface.mediaInfoLabel->setText(QString("stop"));
this->interface.playButton->setChecked(false);
};
void GUI::rPause(){
this->interface.mediaInfoLabel->setText(QString("pause"));//affiche le checker pause
this->interface.playButton->setChecked(!paused);//change état du toggleButton, il est forcé ici, si on ne se fie qu'à un stateChange, les états s'inversent...
};
void GUI::rPlay(){
this->interface.mediaInfoLabel->setText(QString("play"));//checker play
};
void GUI::rPosition(unsigned int position){
this->interface.transportSlider->setValue(position);//la conversion en % est gérée..., actualise la position du slider, contraint par le compteur en boucle perpetuelle
this->interface.timeLabel->setText(QString(position));//la conversion en seconde est gérée..., idem mais en texte
}; |