1 /*
2     SPDX-FileCopyrightText: 2013-2014 Andreas Cord-Landwehr <cordlandwehr@kde.org>
3 
4     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5 */
6 
7 #ifndef PHRASE_H
8 #define PHRASE_H
9 
10 #include "artikulatecore_export.h"
11 #include "ieditablephrase.h"
12 #include "iphrase.h"
13 #include "iunit.h"
14 #include <QList>
15 #include <QUrl>
16 #include <QVector>
17 #include <memory>
18 
19 class QString;
20 class Phoneme;
21 class IUnit;
22 
23 class ARTIKULATECORE_EXPORT Phrase : public IEditablePhrase
24 {
25     Q_OBJECT
26     Q_PROPERTY(QString id READ id WRITE setId NOTIFY idChanged)
27     Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
28     Q_PROPERTY(QString i18nText READ i18nText WRITE seti18nText NOTIFY i18nTextChanged)
29     Q_PROPERTY(QString soundFileUrl READ soundFileUrl NOTIFY soundChanged)
30     Q_PROPERTY(IPhrase::Type type READ type WRITE setType NOTIFY typeChanged)
31     Q_PROPERTY(Phrase::EditState editState READ editState WRITE setEditState NOTIFY editStateChanged)
32     Q_PROPERTY(bool excluded READ isExcluded NOTIFY excludedChanged)
33     Q_PROPERTY(int progress READ progress NOTIFY progressChanged)
34 public:
35     enum class Progress { Skip, Done };
36     Q_ENUM(Progress)
37 
38     static std::shared_ptr<Phrase> create();
39     std::shared_ptr<IPhrase> self() const override;
40 
41     ~Phrase() override;
42 
43     QString id() const override;
44     void setId(QString id) override;
45     QString foreignId() const override;
46     void setForeignId(QString id) override;
47     QString text() const override;
48     void setText(QString text) override;
49     QString i18nText() const override;
50     void seti18nText(QString text) override;
51     std::shared_ptr<IUnit> unit() const override;
52     void setUnit(std::shared_ptr<IUnit> unit) override;
53     IPhrase::Type type() const override;
54     QString typeString() const override;
55     void setType(IPhrase::Type type) override;
56     void setType(const QString &typeString);
57     QString soundFileUrl() const override;
58     Q_INVOKABLE QString soundFileOutputPath() const;
59     Q_INVOKABLE void setSoundFileUrl() override;
60     IEditablePhrase::EditState editState() const override;
61     QString editStateString() const override;
62     void setEditState(IEditablePhrase::EditState state) override;
63     void setEditState(const QString &stateString) override;
64     QUrl sound() const override;
65     void setSound(QUrl soundFile) override;
66     QVector<Phoneme *> phonemes() const override;
67     bool isExcluded() const;
68     void setExcluded(bool excluded = false);
69     int progress() const;
70     void setProgress(int value);
71     void updateProgress(Phrase::Progress progress);
72 
73     Q_INVOKABLE bool hasPhoneme(Phoneme *phoneme);
74     Q_INVOKABLE void addPhoneme(Phoneme *phoneme);
75     Q_INVOKABLE void removePhoneme(Phoneme *phoneme);
76 
77 Q_SIGNALS:
78     void progressChanged();
79     void excludedChanged();
80 
81 private:
82     Q_DISABLE_COPY(Phrase)
83     explicit Phrase();
84     void setSelf(std::shared_ptr<IPhrase> self) override;
85     std::weak_ptr<IPhrase> m_self;
86     QString m_id;
87     QString m_foreignId;
88     QString m_text;
89     QString m_i18nText;
90     IPhrase::Type m_type;
91     EditState m_editState;
92     std::weak_ptr<IUnit> m_unit;
93     unsigned m_trainingProgress;
94     int m_skipCounter; // count how many skips occurred since last progress update
95     bool m_excludedFromUnit;
96     QVector<Phoneme *> m_phonemes;
97     QUrl m_nativeSoundFile;
98 };
99 
100 #endif // PHRASE_H
101