Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
e860bdcf
Commit
e860bdcf
authored
Mar 04, 2015
by
dogmaphobic
Browse files
Made spoken time in milliseconds into something more normal like x minutes and y seconds.
parent
134b2c1a
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/audio/QGCAudioWorker.cpp
View file @
e860bdcf
...
...
@@ -2,6 +2,7 @@
#include
<QDebug>
#include
<QCoreApplication>
#include
<QFile>
#include
<QRegularExpression>
#include
"QGC.h"
#include
"QGCAudioWorker.h"
...
...
@@ -89,7 +90,7 @@ QGCAudioWorker::~QGCAudioWorker()
#endif
}
void
QGCAudioWorker
::
say
(
QString
t
ext
,
int
severity
)
void
QGCAudioWorker
::
say
(
QString
inT
ext
,
int
severity
)
{
static
bool
threadInit
=
false
;
if
(
!
threadInit
)
{
...
...
@@ -99,6 +100,7 @@ void QGCAudioWorker::say(QString text, int severity)
if
(
!
muted
)
{
QString
text
=
_fixMillisecondString
(
inText
);
// Prepend high priority text with alert beep
if
(
severity
<
GAudioOutput
::
AUDIO_SEVERITY_CRITICAL
)
{
beep
();
...
...
@@ -170,3 +172,40 @@ bool QGCAudioWorker::isMuted()
{
return
this
->
muted
;
}
bool
QGCAudioWorker
::
_getMillisecondString
(
const
QString
&
string
,
QString
&
match
,
int
&
number
)
{
QRegularExpression
re
(
"([0-9]*ms)"
);
QRegularExpressionMatchIterator
i
=
re
.
globalMatch
(
string
);
while
(
i
.
hasNext
())
{
QRegularExpressionMatch
qmatch
=
i
.
next
();
if
(
qmatch
.
hasMatch
())
{
match
=
qmatch
.
captured
(
0
);
number
=
qmatch
.
captured
(
0
).
replace
(
"ms"
,
""
).
toInt
();
return
true
;
}
}
return
false
;
}
QString
QGCAudioWorker
::
_fixMillisecondString
(
const
QString
&
string
)
{
QString
match
;
QString
newNumber
;
QString
result
=
string
;
int
number
;
if
(
_getMillisecondString
(
string
,
match
,
number
)
&&
number
>
1000
)
{
if
(
number
<
60000
)
{
int
seconds
=
number
/
1000
;
newNumber
=
QString
(
"%1 second%2"
).
arg
(
seconds
).
arg
(
seconds
>
1
?
"s"
:
""
);
}
else
{
int
minutes
=
number
/
60000
;
int
seconds
=
(
number
-
(
minutes
*
60000
))
/
1000
;
if
(
!
seconds
)
{
newNumber
=
QString
(
"%1 minute%2"
).
arg
(
minutes
).
arg
(
minutes
>
1
?
"s"
:
""
);
}
else
{
newNumber
=
QString
(
"%1 minute%2 and %3 second%4"
).
arg
(
minutes
).
arg
(
minutes
>
1
?
"s"
:
""
).
arg
(
seconds
).
arg
(
seconds
>
1
?
"s"
:
""
);
}
}
result
.
replace
(
match
,
newNumber
);
}
return
result
;
}
src/audio/QGCAudioWorker.h
View file @
e860bdcf
...
...
@@ -50,6 +50,9 @@ protected:
bool
emergency
;
///< Emergency status flag
QTimer
*
emergencyTimer
;
bool
muted
;
private:
QString
_fixMillisecondString
(
const
QString
&
string
);
bool
_getMillisecondString
(
const
QString
&
string
,
QString
&
match
,
int
&
number
);
};
#endif // QGCAUDIOWORKER_H
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment