Unity 8
PreviewPayments.qml
1 /*
2  * Copyright (C) 2014 Canonical, Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 import QtQuick 2.4
18 import Ubuntu.Components 1.3
19 import Ubuntu.Payments 0.1
20 
21 /*! \brief Preview widget for a purchase button.
22  *
23  * When clicked, this button starts the payments service.
24  * Then it waits until the purchase finishes or fails.
25  * Those events trigger the corresponding actions.
26  */
27 
28 PreviewWidget {
29  id: root
30 
31  implicitHeight: paymentButton.implicitHeight
32  implicitWidth: paymentButton.implicitWidth
33 
34  Button {
35  id: paymentButton
36  objectName: "paymentButton"
37 
38  color: UbuntuColors.orange
39  text: paymentClient.formattedPrice
40  onClicked: {
41  paymentClient.start();
42  paymentButton.opacity = 0;
43  }
44  anchors.right: parent.right
45  width: (root.width - units.gu(1)) / 2
46  opacity: 1
47  visible: paymentButton.opacity == 0 ? false : true
48  Behavior on opacity { PropertyAnimation { duration: UbuntuAnimation.FastDuration } }
49 
50  Payments {
51  id: paymentClient
52  objectName: "paymentClient"
53 
54  property var source: widgetData["source"]
55 
56  price: source["price"]
57  currency: source["currency"]
58  storeItemId: source["store_item_id"]
59  onPurchaseCompleted: {
60  root.triggered(widgetId, "purchaseCompleted", source);
61  }
62  onPurchaseError: {
63  paymentButton.opacity = 1;
64  root.triggered(widgetId, "purchaseError", source);
65  }
66  onPurchaseCancelled: {
67  paymentButton.opacity = 1;
68  // DO NOT emit the signal right now, as it causes a new
69  // preview to be requested, when that is not what we want.
70  //root.triggered(widgetId, "purchaseCancelled", source);
71  }
72  }
73  }
74 
75  ProgressBar {
76  id: loadingBar
77  objectName: "loadingBar"
78  indeterminate: true
79  anchors.fill: paymentButton
80  opacity: 1 - paymentButton.opacity
81  visible: !paymentButton.visible
82  }
83 }