1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the Qt Components project.
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 ** the names of its contributors may be used to endorse or promote
23 ** products derived from this software without specific prior written
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
42 import com.nokia.meego 1.0
49 // Input. Set to true if user is signed in to Nokia account.
50 // Account email using agreement is shown if user is signed in.
51 // Otherwise email input box is shown instead.
52 property bool isSignedIn: false
54 // Input. Array of localised UI strings:
55 // header - 'Tell us what you think'
56 // question - 'How likely ... ?'
57 // notLikely - 'Not at all\nlikely'
58 // extremelyLikely - 'Extremely\nlikely'
59 // selectScore - 'You must select ...'
60 // commentsInputLabel - 'Please tell us why ...'
61 // contactAgreement - 'You can contact me using ...'
62 // emailInputLabel - 'You can contact me for details...'
63 // emailPlaceholderText - 'Your email address'
64 // emailSipActionKeyLabel - 'Done'
65 // invalidEmail - 'Invalid email address'
66 // legalText - 'Your information will be ...'
69 property variant uiString: QtObject {}
71 // Input. Array of horizontal alignments for strings. Accept same
72 // values as Text { horizontalAlignment: ... } e.g. Text.AlignLeft, Text.AlignRight and so on.
73 // By default all text strings aligned to the left.
83 property variant uiHorizontalAlignment: QtObject {}
85 // Promoter score, between 0 ~ 10
86 property alias score: scoreSlider.value
88 // True if user touched score slider
89 property alias scoreTouched: scoreSlider.touched
91 // Optional comments text
92 property alias comments: commentsText.text
94 // Optional email address
95 // emailAddress shall be ignored if isSignedIn is true.
96 property alias emailAddress: emailAddressField.text
98 // True if user agrees to be contacted using Nokia Account email address.
99 // useEmail shall be ignored if isSignedIn is false.
100 property alias useEmail: useEmailCheckBox.checked
102 // Signal emitted when 'Submit' button is clicked and form passes validation.
105 height: childrenRect.height
111 property variant defaultValidator: RegExpValidator{regExp: /.*/}
112 property variant emailValidator: RegExpValidator{regExp: /^\w([a-zA-Z0-9._-]+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/}
114 function validateForm() {
118 if (!scoreSlider.touched) {
119 sliderErrorLabel.visible = true;
123 if (emailAddress && emailAddress.length > 0) {
124 var validator = internal.emailValidator
125 emailAddressField.validator = validator;
126 var result = emailAddressField.acceptableInput;
127 if (result)emailAddressField.validator = internal.defaultValidator;
128 mouseArea.enabled = !result;
129 invalidEmailLabel.visible = !result;
130 if (!result)isValid = false;
146 height: childrenRect.height
158 leftMargin: 18 - parent.anchors.leftMargin
165 horizontalAlignment: uiHorizontalAlignment.header || Text.AlignLeft
166 text: uiString.header ||
167 "!!Tell us what you think"
181 horizontalAlignment: uiHorizontalAlignment.question || Text.AlignLeft
182 text: uiString.question ||
183 "!!How likely are you to recommend this app to a friend or a colleague?"
194 height: childrenRect.height
197 width: parent.width/2
200 horizontalAlignment: Text.AlignLeft
204 width: parent.width/2
207 horizontalAlignment: Text.AlignRight
214 objectName: "slider_nps_score"
216 property bool touched: false
222 valueIndicatorVisible: true
226 sliderErrorLabel.visible = false;
235 height: childrenRect.height
238 width: parent.width/3
241 horizontalAlignment: Text.AlignLeft
242 text: uiString.notLikely || "!!Not at all \nlikely"
246 width: parent.width/3
251 width: parent.width/3
254 horizontalAlignment: Text.AlignRight
255 text: uiString.extremelyLikely || "!!Extremely \nlikely"
262 visible: sliderErrorLabel.visible
272 horizontalAlignment: uiHorizontalAlignment.selectScore || Text.AlignLeft
273 text: uiString.selectScore ||
274 "!!You must select a rating"
283 width: parent.width + 16
284 x: 8 - parent.anchors.leftMargin
285 source: "image://theme/meegotouch-separator-background-horizontal"
286 fillMode: Image.TileHorizontally
298 horizontalAlignment: uiHorizontalAlignment.commentsInputLabel || Text.AlignLeft
299 text: uiString.commentsInputLabel ||
300 "!!Please tell us why you gave this score (optional)"
304 id: sipAttributesDefault
311 height: Math.max(118, implicitHeight)
312 platformSipAttributes: sipAttributesDefault
328 objectName: "check_nps_email"
330 verticalCenter: parent.verticalCenter
337 verticalCenter: parent.verticalCenter
340 width: parent.width - useEmailCheckBox.width - parent.spacing
344 horizontalAlignment: uiHorizontalAlignment.contactAgreement || Text.AlignLeft
345 text: uiString.contactAgreement ||
346 "!!You can contact me for details using my Nokia Account e-mail."
352 width: parent.width + 16
353 x: 8 - parent.anchors.leftMargin
354 source: "image://theme/meegotouch-separator-background-horizontal"
355 fillMode: Image.TileHorizontally
374 horizontalAlignment: uiHorizontalAlignment.emailInputLabel || Text.AlignLeft
375 text: uiString.emailInputLabel ||
376 "!!You can contact me for details (Optional)"
380 id: emailAddressField
381 objectName: "input_nps_email"
383 inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhEmailCharactersOnly | Qt.ImhNoAutoUppercase
384 placeholderText: uiString.emailPlaceholderText ||
385 "!!Your email address"
386 platformSipAttributes: SipAttributes {
387 actionKeyLabel: uiString.emailSipActionKeyLabel || ""
388 actionKeyHighlighted: !!uiString.emailSipActionKeyLabel
391 Keys.onReturnPressed: {
392 if (internal.validateForm()) {
393 platformCloseSoftwareInputPanel();
404 invalidEmailLabel.visible = false;
405 emailAddressField.forceActiveFocus();
406 emailAddressField.validator = internal.defaultValidator;
411 if (invalidEmailLabel.visible) {
412 invalidEmailLabel.visible = false;
413 emailAddressField.validator = internal.defaultValidator;
419 id: invalidEmailLabel
424 horizontalAlignment: uiHorizontalAlignment.invalidEmail || Text.AlignLeft
425 text: uiString.invalidEmail ||
426 "!!Invalid email address"
440 horizontalAlignment: uiHorizontalAlignment.legalText || Text.AlignLeft
441 text: uiString.legalText ||
442 "!!Your information will be treated according to Nokia privacy policy."
451 objectName: "btn_nps_submit"
455 horizontalCenter: parent.horizontalCenter
458 text: uiString.submit || "!!Submit"
461 if (internal.validateForm()) {