-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.cpp
More file actions
82 lines (77 loc) · 2.13 KB
/
Copy pathreader.cpp
File metadata and controls
82 lines (77 loc) · 2.13 KB
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
#include "reader.h"
#include <QApplication>
#include <QFile>
#include <QTextStream>
#include <QUrl>
Reader::Reader(QObject *parent) : QObject(parent)
{
ini_file=NULL;
opened=false;
position=0,rate=0,vol=80;
connect(&thread,&Speech_Thread::select_Changed,this,&Reader::select_Changed);
QFile seperate_file(":/seperate.txt");
seperate_file.open(QIODevice::ReadOnly);
QTextStream seperate_stream(&seperate_file);
thread.seperate=seperate_stream.readAll();
if(qApp->arguments().count()>1)
read(QUrl::fromLocalFile(qApp->arguments()[1]));
}
Reader::~Reader()
{
}
void Reader::read(QString url){
read(QUrl(url));
}
void Reader::read(QUrl url){
if(ini_file) delete ini_file;
ini_file=new QSettings(url.toLocalFile().append(".ini"),
QSettings::IniFormat);
position=ini_file->value("/Reader/position").toInt();
QFile txt_file(QUrl(url).toLocalFile());
txt_file.open(QIODevice::ReadOnly);
QTextStream txt_stream(&txt_file);
thread.text=txt_stream.readAll();
thread.text.replace(QRegExp("\n")," \n");
emit text_Changed(thread.text);
opened=true;
emit select_Changed(position,position);
return;
}
void Reader::position_save(){
if(opened)
ini_file->setValue("/Reader/position",position);
}
void Reader::position_set(int pos){
position=pos;
thread.position=position;
}
void Reader::read_start(){
thread.speech.dynamicCall("SetRate(int)",rate);
thread.speech.dynamicCall("SetVolume(int)",vol);
//thread.speech.initialize();
thread.start();
}
void Reader::read_stop(){
if(thread.running){
thread.terminate();
thread.running=false;
}
}
void Reader::read_pause(){
if(thread.running)
thread.speech.dynamicCall("Pause()");
}
void Reader::read_resume(){
if(thread.running)
thread.speech.dynamicCall("Resume()");
}
void Reader::rate_change(int newrate){
rate=newrate;
if(thread.running)
thread.speech.dynamicCall("SetRate(int)",rate);
}
void Reader::volume_change(int newvol){
vol=newvol;
if(thread.running)
thread.speech.dynamicCall("SetVolume(int)",vol);
}