summaryrefslogtreecommitdiffstats
path: root/src/tts/qvoice.h
blob: 4a336fc69f33892d9318864827e7129ef627dd81 (plain)
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
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only

#ifndef QVOICE_H
#define QVOICE_H

#include <QtTextToSpeech/qtexttospeech_global.h>
#include <QtCore/qlocale.h>
#include <QtCore/qshareddata.h>
#include <QtCore/qmetatype.h>
#include <QtCore/qvariant.h>

QT_BEGIN_NAMESPACE

class QVoicePrivate;

QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QVoicePrivate, Q_TEXTTOSPEECH_EXPORT)

class Q_TEXTTOSPEECH_EXPORT QVoice
{
    Q_GADGET
    Q_PROPERTY(QString name READ name CONSTANT)
    Q_PROPERTY(Gender gender READ gender CONSTANT)
    Q_PROPERTY(Age age READ age CONSTANT)
    Q_PROPERTY(QLocale locale READ locale CONSTANT)
    Q_PROPERTY(QLocale::Language language READ language STORED false)

public:
    enum Gender {
        Male,
        Female,
        Unknown
    };
    Q_ENUM(Gender)

    enum Age {
        Child,
        Teenager,
        Adult,
        Senior,
        Other
    };
    Q_ENUM(Age)

    QVoice();
    ~QVoice();
    QVoice(const QVoice &other) noexcept;
    QVoice &operator=(const QVoice &other) noexcept;
    QVoice(QVoice &&other) noexcept = default;
    QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QVoice)

    void swap(QVoice &other) noexcept
    { d.swap(other.d); }

    friend inline bool operator==(const QVoice &lhs, const QVoice &rhs) noexcept
    { return lhs.isEqual(rhs); }
    friend inline bool operator!=(const QVoice &lhs, const QVoice &rhs) noexcept
    { return !lhs.isEqual(rhs); }

#ifndef QT_NO_DATASTREAM
    friend inline QDataStream &operator<<(QDataStream &str, const QVoice &voice)
    { return voice.writeTo(str); }
    friend inline QDataStream &operator>>(QDataStream &str, QVoice &voice)
    { return voice.readFrom(str); }
#endif

    QString name() const;
    QLocale locale() const;
    Gender gender() const;
    Age age() const;

    inline QLocale::Language language() const { return locale().language(); }

    static QString genderName(QVoice::Gender gender);
    static QString ageName(QVoice::Age age);

private:
    QVoice(const QString &name, const QLocale &loc, Gender gender, Age age, const QVariant &data);
    bool isEqual(const QVoice &other) const noexcept;
#ifndef QT_NO_DATASTREAM
    QDataStream &writeTo(QDataStream &) const;
    QDataStream &readFrom(QDataStream &);
#endif

    QVariant data() const;

    QExplicitlySharedDataPointer<QVoicePrivate> d;
    friend class QVoicePrivate;
    friend class QTextToSpeechEngine;
    friend Q_TEXTTOSPEECH_EXPORT QDebug operator<<(QDebug, const QVoice &);
};

#ifndef QT_NO_DEBUG_STREAM
Q_TEXTTOSPEECH_EXPORT QDebug operator<<(QDebug, const QVoice &);
#endif

Q_DECLARE_SHARED(QVoice)

QT_END_NAMESPACE

Q_DECLARE_METATYPE(QVoice)
Q_DECLARE_METATYPE(QVoice::Age)
Q_DECLARE_METATYPE(QVoice::Gender)

#endif