Krita Source Code Documentation
Loading...
Searching...
No Matches
KisDonationManagementDialog.cpp
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-3.0-or-later
3 */
5#include "kis_assert.h"
8#include <QFrame>
9#include <QLabel>
10
12 : QDialog(parent)
13 , m_androidDonations(KisAndroidDonations::instance())
14{
16 setupUi(this);
17 setWindowTitle(i18n("Supporter Benefits"));
18
19 QScroller *scroller = KisKineticScroller::createPreconfiguredScroller(m_scrBenefitsList);
20 if (scroller) {
21 connect(scroller, &QScroller::stateChanged, this, [&](QScroller::State state) {
23 });
24 }
25
26 QPushButton *btnManageSubscriptions =
27 m_buttons->addButton(i18n("Manage Subscriptions"), QDialogButtonBox::ActionRole);
28
30 // It is theoretically possible that the user purchases a product while
31 // Krita is still loading, hence the existence of this "pending" flag,
32 // in case the Qt UI isn't ready yet. This here is the dialog that's
33 // pending to be shown, so its appearance clears that flag.
35 connect(m_androidDonations,
37 this,
39 Qt::QueuedConnection);
40 connect(m_btnNoBenefitsSupport,
41 &QPushButton::clicked,
44 connect(btnManageSubscriptions,
45 &QPushButton::clicked,
48 } else {
49 // Shouldn't happen, but just revert to a blank no benefits page.
50 m_stack->setCurrentWidget(m_pgNoBenefits);
51 m_btnNoBenefitsSupport->hide();
52 }
53
55
56 connect(m_buttons, &QDialogButtonBox::rejected, this, &KisDonationManagementDialog::reject);
57}
58
69
71{
72 if (m_availableProducts.isEmpty() && m_ownedProducts.isEmpty()) {
73 m_stack->setCurrentWidget(m_pgNoBenefits);
74 } else {
75 m_stack->setCurrentWidget(m_pgBenefitsList);
76 }
77}
78
80{
81 QVector<KisSupporterProduct> availableProducts;
82 QVector<KisSupporterProduct> ownedProducts;
85 switch (product.availability) {
86 case KisSupporterProductAvailability::Missing:
87 break;
88 case KisSupporterProductAvailability::Available:
89 availableProducts.append(product);
90 break;
91 case KisSupporterProductAvailability::Owned:
92 ownedProducts.append(product);
93 break;
94 }
95 }
96 }
97
98 bool productsChanged = !isProductIdsEqual(m_availableProducts, availableProducts)
99 || !isProductIdsEqual(m_ownedProducts, ownedProducts);
100 if (productsChanged) {
101 m_availableProducts = availableProducts;
102 m_ownedProducts = ownedProducts;
103
104 while (!m_lytScrBenefitsList->isEmpty()) {
105 QLayoutItem *item = m_lytScrBenefitsList->takeAt(m_lytScrBenefitsList->count() - 1);
106 QWidget *widget = item->widget();
107 if (widget) {
108 widget->deleteLater();
109 }
110 delete item;
111 }
112
114 i18np("You have %1 supporter benefit:", "You have %1 supporter benefits:", m_ownedProducts.size()),
116
117 if (!m_availableProducts.isEmpty() && !m_ownedProducts.isEmpty()) {
119 m_lytScrBenefitsList->addSpacing(12);
120 }
121
122 addProductWidgets(i18np("There is %1 supporter benefit available:",
123 "There are %1 supporter benefits available:",
124 m_availableProducts.size()),
126
127 m_lytScrBenefitsList->addStretch();
129 }
130}
131
133 const QVector<KisSupporterProduct> &products)
134{
135 int count = products.size();
136 if (count != 0) {
137 QLabel *label =
138 new QLabel(QStringLiteral("<span style=\"font-size:large;\">%1</span>").arg(heading.toHtmlEscaped()));
139 label->setWordWrap(true);
140 m_lytScrBenefitsList->addWidget(label);
141
142 for (int i = 0; i < count; ++i) {
145 m_lytScrBenefitsList->addWidget(widget);
146 connect(widget,
148 this,
150 }
151 }
152}
153
155{
156 QFrame *separator = new QFrame;
157 separator->setFrameShape(QFrame::HLine);
158 separator->setFrameShadow(QFrame::Sunken);
159 m_lytScrBenefitsList->addWidget(separator);
160}
161
164{
165 int count = a.size();
166 if (b.size() != count) {
167 return false;
168 }
169
170 for (int i = 0; i < count; ++i) {
171 if (a[i].id != b[i].id) {
172 return false;
173 }
174 }
175
176 return true;
177}
PythonPluginManager * instance
void setShowDonationManagementDialogPending(bool pending)
QVector< KisSupporterProduct > getCurrentProducts() const
QVector< KisSupporterProduct > m_availableProducts
void addProductWidgets(const QString &heading, const QVector< KisSupporterProduct > &products)
KisDonationManagementDialog(QWidget *parent=nullptr)
static bool isProductIdsEqual(const QVector< KisSupporterProduct > &a, const QVector< KisSupporterProduct > &b)
QVector< KisSupporterProduct > m_ownedProducts
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
KRITAWIDGETUTILS_EXPORT void updateCursor(QWidget *source, QScroller::State state)
KRITAWIDGETUTILS_EXPORT QScroller * createPreconfiguredScroller(QAbstractScrollArea *target)