Commit a38cdead authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Show progress bar in phrase tree view.

parent 37ddf5d3
......@@ -27,13 +27,14 @@
#include "artikulate_debug.h"
#include <QTemporaryFile>
#include <sys/stat.h>
Phrase::Phrase(QObject *parent)
: QObject(parent)
, m_type(Phrase::AllTypes)
, m_editState(Unknown)
, m_unit(nullptr)
, m_trainingProgress(0)
, m_skipCounter(0)
, m_excludedFromUnit(false)
{
connect(this, &Phrase::idChanged, this, &Phrase::modified);
......@@ -270,6 +271,34 @@ void Phrase::setExcluded(bool excluded)
emit excludedChanged();
}
int Phrase::progress() const
{
return m_trainingProgress;
}
void Phrase::updateProgress(Phrase::Progress progress)
{
// logic of progress computation:
// a) if skipped 3 times in a row, decrease progress
// b) if done and skipped less than two times in a row, increase progress
if (progress == Progress::Done) {
m_skipCounter = 0;
if (m_trainingProgress < 3) {
++m_trainingProgress;
emit progressChanged();
}
return;
}
if (progress == Progress::Skip) {
++m_skipCounter;
if (m_skipCounter > 2 && m_trainingProgress > 0) {
--m_trainingProgress;
emit progressChanged();
}
return;
}
}
QList<Phoneme *> Phrase::phonemes() const
{
return m_phonemes;
......
......@@ -44,6 +44,7 @@ class ARTIKULATECORE_EXPORT Phrase : public QObject
Q_PROPERTY(Phrase::EditState editState READ editState WRITE setEditState NOTIFY editStateChanged)
Q_PROPERTY(Unit *unit READ unit NOTIFY unitChanged)
Q_PROPERTY(bool excluded READ isExcluded NOTIFY excludedChanged)
Q_PROPERTY(int progress READ progress NOTIFY progressChanged)
public:
Q_ENUMS(EditState)
Q_ENUMS(TrainingState)
......@@ -57,6 +58,10 @@ public:
Trained,
Untrained
};
enum class Progress {
Skip,
Done
};
enum Type {
Word,
Expression,
......@@ -94,6 +99,8 @@ public:
QList<Phoneme *> phonemes() const;
bool isExcluded() const;
void setExcluded(bool excluded = false);
int progress() const;
void updateProgress(Phrase::Progress progress);
Q_INVOKABLE bool hasPhoneme(Phoneme *phoneme);
Q_INVOKABLE void addPhoneme(Phoneme *phoneme);
......@@ -110,6 +117,7 @@ Q_SIGNALS:
void excludedChanged();
void phonemesChanged();
void modified();
void progressChanged();
private:
Q_DISABLE_COPY(Phrase)
......@@ -120,6 +128,8 @@ private:
Type m_type;
EditState m_editState;
Unit *m_unit;
unsigned m_trainingProgress;
int m_skipCounter; // count how many skips occured since last progress update
bool m_excludedFromUnit;
QList<Phoneme *> m_phonemes;
QUrl m_nativeSoundFile;
......
......@@ -144,7 +144,7 @@ void TrainingSession::showNextPhrase()
m_phrase->id(),
static_cast<int>(LearnerProfile::ProfileManager::Skip)
);
m_phrase->updateProgress(Phrase::Progress::Done);
setPhrase(nextPhrase());
}
......@@ -162,7 +162,8 @@ void TrainingSession::skipPhrase()
m_phrase->id(),
static_cast<int>(LearnerProfile::ProfileManager::Skip)
);
showNextPhrase();
m_phrase->updateProgress(Phrase::Progress::Skip);
setPhrase(nextPhrase());
}
bool TrainingSession::hasNextPhrase() const
......
......@@ -98,26 +98,45 @@ ApplicationWindow {
id: unitRowBackground
Rectangle {anchors.fill: parent; color: "steelblue"}
}
Component {
id: phraseProgress
Row {
property int progress: isUnit ? 0 : phraseModel.phrase(styleData.index).progress
Repeater {
model: 3
QIconItem {
width: 16
height: width
icon: progress > index ? "rating" : "rating-unrated"
}
}
}
}
Loader {
anchors.fill: parent
sourceComponent: isUnit ? unitRowBackground : null
}
Text {
width: phraseTree.width - 100 //TODO check if this is really a reasonable value
anchors {
verticalCenter: parent.verticalCenter
topMargin: 5
bottomMargin: 5
}
color: {
if (isUnit) {
return "white";
Row {
Text {
width: phraseTree.width - 130 //TODO check if this is really a reasonable value
anchors {
verticalCenter: parent.verticalCenter
topMargin: 5
bottomMargin: 5
}
color: {
if (isUnit) {
return "white";
}
return styleData.textColor
}
return styleData.textColor
elide: Text.ElideRight
text: " " + styleData.value
font.bold: isUnit
}
Loader {
sourceComponent: isUnit ? null : phraseProgress
}
elide: Text.ElideRight
text: " " + styleData.value
font.bold: isUnit
}
}
onClicked: {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment