1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2015 The Qt Company Ltd. |
4 | ** Contact: http://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtContacts module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL21$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at http://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 or version 3 as published by the Free |
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and |
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the |
22 | ** following information to ensure the GNU Lesser General Public License |
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and |
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
25 | ** |
26 | ** As a special exception, The Qt Company gives you certain additional |
27 | ** rights. These rights are described in The Qt Company LGPL Exception |
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
29 | ** |
30 | ** $QT_END_LICENSE$ |
31 | ** |
32 | ****************************************************************************/ |
33 | |
34 | #ifndef QDECLARATIVECONTACTPHONENUMBER_H |
35 | #define QDECLARATIVECONTACTPHONENUMBER_H |
36 | |
37 | #include <QtContacts/qcontactphonenumber.h> |
38 | |
39 | #include "qdeclarativecontactdetail_p.h" |
40 | |
41 | QTCONTACTS_USE_NAMESPACE |
42 | |
43 | QT_BEGIN_NAMESPACE |
44 | |
45 | class QDeclarativeContactPhoneNumber : public QDeclarativeContactDetail |
46 | { |
47 | Q_OBJECT |
48 | |
49 | Q_PROPERTY(QString number READ number WRITE setNumber NOTIFY valueChanged) |
50 | Q_PROPERTY(QList<int> subTypes READ subTypes WRITE setSubTypes NOTIFY valueChanged) |
51 | Q_ENUMS(FieldType) |
52 | Q_ENUMS(PhoneNumberSubType) |
53 | |
54 | Q_CLASSINFO("DefaultProperty" , "number" ) |
55 | public: |
56 | enum FieldType { |
57 | Number = QContactPhoneNumber::FieldNumber, |
58 | SubTypes = QContactPhoneNumber::FieldSubTypes |
59 | }; |
60 | |
61 | enum PhoneNumberSubType { |
62 | Landline = QContactPhoneNumber::SubTypeLandline, |
63 | Mobile = QContactPhoneNumber::SubTypeMobile, |
64 | Fax = QContactPhoneNumber::SubTypeFax, |
65 | = QContactPhoneNumber::SubTypePager, |
66 | Voice = QContactPhoneNumber::SubTypeVoice, |
67 | Modem = QContactPhoneNumber::SubTypeModem, |
68 | Video = QContactPhoneNumber::SubTypeVideo, |
69 | Car = QContactPhoneNumber::SubTypeCar, |
70 | BulletinBoardSystem = QContactPhoneNumber::SubTypeBulletinBoardSystem, |
71 | MessagingCapable = QContactPhoneNumber::SubTypeMessagingCapable, |
72 | Assistant = QContactPhoneNumber::SubTypeAssistant, |
73 | = QContactPhoneNumber::SubTypeDtmfMenu |
74 | }; |
75 | |
76 | QDeclarativeContactPhoneNumber(QObject* parent = Q_NULLPTR) |
77 | :QDeclarativeContactDetail(parent) |
78 | { |
79 | setDetail(QContactPhoneNumber()); |
80 | connect(asender: this, SIGNAL(valueChanged()), SIGNAL(detailChanged())); |
81 | } |
82 | DetailType detailType() const |
83 | { |
84 | return QDeclarativeContactDetail::PhoneNumber; |
85 | } |
86 | |
87 | void setNumber(const QString& v) |
88 | { |
89 | if (!readOnly() && v != number()) { |
90 | detail().setValue(field: QContactPhoneNumber::FieldNumber, value: v); |
91 | emit valueChanged(); |
92 | } |
93 | } |
94 | QString number() const {return detail().value(field: QContactPhoneNumber::FieldNumber).toString();} |
95 | |
96 | |
97 | void setSubTypes(const QList<int>& subTypes) |
98 | { |
99 | QList<int> oldList = detail().value< QList<int> >(field: QContactPhoneNumber::FieldSubTypes); |
100 | |
101 | if (!readOnly() && subTypes.toSet() != oldList.toSet()) { |
102 | detail().setValue(field: QContactPhoneNumber::FieldSubTypes, value: QVariant::fromValue(value: subTypes)); |
103 | emit valueChanged(); |
104 | } |
105 | } |
106 | |
107 | QList<int> subTypes() const |
108 | { |
109 | return detail().value< QList<int> >(field: QContactPhoneNumber::FieldSubTypes); |
110 | } |
111 | |
112 | signals: |
113 | void valueChanged(); |
114 | |
115 | }; |
116 | |
117 | QT_END_NAMESPACE |
118 | |
119 | QML_DECLARE_TYPE(QDeclarativeContactPhoneNumber) |
120 | |
121 | #endif // QDECLARATIVECONTACTPHONENUMBER_H |
122 | |