Skip to content

Commit

Permalink
UI improvements for misc cases with buying gifts
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkanovikov committed Aug 16, 2024
1 parent 88de570 commit 93462aa
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 8 deletions.
48 changes: 45 additions & 3 deletions src/core/management_layer/content/account/account_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ void AccountManager::Implementation::initViewConnections()
connect(view, &Ui::AccountView::tryCloudForFreePressed, q, &AccountManager::tryCloudForFree);
connect(view, &Ui::AccountView::buyProLifetimePressed, q, &AccountManager::buyProLifetme);
connect(view, &Ui::AccountView::renewProPressed, q, &AccountManager::renewPro);
connect(view, &Ui::AccountView::giftProPressed, q, &AccountManager::giftPro);
connect(view, &Ui::AccountView::renewCloudPressed, q, &AccountManager::renewCloud);
connect(view, &Ui::AccountView::giftCloudPressed, q, &AccountManager::giftCloud);
connect(view, &Ui::AccountView::activatePromocodePressed, q,
&AccountManager::activatePromocodeRequested);

Expand Down Expand Up @@ -493,7 +495,7 @@ void AccountManager::setAccountInfo(const Domain::AccountInfo& _accountInfo)
d->purchaseDialog->hideDialog();
}
if (d->purchaseGiftDialog != nullptr && d->purchaseGiftDialog->isVisible()) {
d->purchaseDialog->hideDialog();
d->purchaseGiftDialog->hideDialog();
}
}

Expand Down Expand Up @@ -589,8 +591,6 @@ bool AccountManager::tryProForFree()

void AccountManager::buyProLifetme()
{
d->initPurchaseDialog();

auto proPaymentOptions = d->accountInfo.paymentOptions;
for (int index = proPaymentOptions.size() - 1; index >= 0; --index) {
const auto& option = proPaymentOptions.at(index);
Expand All @@ -601,6 +601,7 @@ void AccountManager::buyProLifetme()
}
}

d->initPurchaseDialog();
d->purchaseDialog->setPaymentOptions(proPaymentOptions);
d->purchaseDialog->selectOption(proPaymentOptions.constFirst());
d->purchaseDialog->showDialog();
Expand All @@ -627,6 +628,25 @@ void AccountManager::renewPro()
d->purchaseDialog->showDialog();
}

void AccountManager::giftPro()
{
auto proPaymentOptions = d->accountInfo.paymentOptions;
for (int index = proPaymentOptions.size() - 1; index >= 0; --index) {
const auto& option = proPaymentOptions.at(index);
if (option.amount == 0
|| (option.subscriptionType != Domain::SubscriptionType::ProMonthly
&& option.subscriptionType != Domain::SubscriptionType::ProLifetime)) {
proPaymentOptions.removeAt(index);
}
}

d->initPurchaseDialog();
d->purchaseDialog->setPaymentOptions(proPaymentOptions);
d->purchaseDialog->setPurchaseAvailable(false);
d->purchaseDialog->selectOption(proPaymentOptions.constFirst());
d->purchaseDialog->showDialog();
}

bool AccountManager::tryCloudForFree()
{
//
Expand Down Expand Up @@ -691,6 +711,28 @@ void AccountManager::renewCloud()
d->purchaseDialog->showDialog();
}

void AccountManager::giftCloud()
{
auto cloudPaymentOptions = d->accountInfo.paymentOptions;
for (int index = cloudPaymentOptions.size() - 1; index >= 0; --index) {
const auto& option = cloudPaymentOptions.at(index);
if (option.amount == 0 || option.type != Domain::PaymentType::Subscription
|| (option.subscriptionType != Domain::SubscriptionType::CloudMonthly
&& option.subscriptionType != Domain::SubscriptionType::CloudLifetime)) {
cloudPaymentOptions.removeAt(index);
}
}
if (cloudPaymentOptions.isEmpty()) {
return;
}

d->initPurchaseDialog();
d->purchaseDialog->setPaymentOptions(cloudPaymentOptions);
d->purchaseDialog->setPurchaseAvailable(false);
d->purchaseDialog->selectOption(cloudPaymentOptions.constLast());
d->purchaseDialog->showDialog();
}

void AccountManager::buyCredits()
{
//
Expand Down
2 changes: 2 additions & 0 deletions src/core/management_layer/content/account/account_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class AccountManager : public QObject
*/
void buyProLifetme();
void renewPro();
void giftPro();

/**
* @brief Активировать бесплатный период для ПРО
Expand All @@ -79,6 +80,7 @@ class AccountManager : public QObject
* @brief Оплатить ПРО версию
*/
void renewCloud();
void giftCloud();

/**
* @brief Докупить кредиты
Expand Down
4 changes: 4 additions & 0 deletions src/core/ui/account/account_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,14 @@ AccountView::AccountView(QWidget* _parent)
&AccountView::renewProPressed);
connect(d->proSubscription, &SubscriptionWidget::buyLifetimePressed, this,
&AccountView::buyProLifetimePressed);
connect(d->proSubscription, &SubscriptionWidget::giftPressed, this,
&AccountView::giftProPressed);
connect(d->cloudSubscription, &SubscriptionWidget::tryPressed, this,
&AccountView::tryCloudForFreePressed);
connect(d->cloudSubscription, &SubscriptionWidget::buyPressed, this,
&AccountView::renewCloudPressed);
connect(d->cloudSubscription, &SubscriptionWidget::giftPressed, this,
&AccountView::giftCloudPressed);

connect(d->promocodeName, &TextField::textChanged, d->promocodeName,
[this] { d->promocodeName->setError({}); });
Expand Down
2 changes: 2 additions & 0 deletions src/core/ui/account/account_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ class AccountView : public StackWidget
void tryProForFreePressed();
void buyProLifetimePressed();
void renewProPressed();
void giftProPressed();
void tryCloudForFreePressed();
void renewCloudPressed();
void giftCloudPressed();

/**
* @brief Пользователь нажал кнопку активировать промокод
Expand Down
5 changes: 5 additions & 0 deletions src/core/ui/account/purchase_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ void PurchaseDialog::setDescription(const QString& _description)
d->descriptionLabel->setVisible(!_description.isEmpty());
}

void PurchaseDialog::setPurchaseAvailable(bool _available)
{
d->purchaseButton->setEnabled(_available);
}

void PurchaseDialog::setPaymentOptions(const QVector<Domain::PaymentOption>& _paymentOptions)
{
QGridLayout* contentLayout = nullptr;
Expand Down
5 changes: 5 additions & 0 deletions src/core/ui/account/purchase_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class PurchaseDialog : public AbstractDialog
*/
void setDescription(const QString& _description);

/**
* @brief Задать возможность покупки подписки для себя
*/
void setPurchaseAvailable(bool _available);

/**
* @brief Задать доступные опции покупки
*/
Expand Down
8 changes: 4 additions & 4 deletions src/core/ui/account/purchase_gift_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <utils/helpers/color_helper.h>
#include <utils/validators/email_validator.h>

#include <QHBoxLayout>
#include <QBoxLayout>


namespace Ui {
Expand Down Expand Up @@ -50,7 +50,7 @@ PurchaseGiftDialog::Implementation::Implementation(QWidget* _parent)
paymentOption->setWide(true);
paymentOption->setShowTotal(true);
email->setCapitalizeWords(false);
informationIcon->setIcon(u8"\U000F02FC");
informationIcon->setIcon(u8"\U000F02FD");

auto informationLayout = new QHBoxLayout;
informationLayout->setContentsMargins({});
Expand Down Expand Up @@ -123,7 +123,7 @@ QWidget* PurchaseGiftDialog::lastFocusableWidget() const

void PurchaseGiftDialog::updateTranslations()
{
setTitle(tr("Subscription as a gift"));
setTitle(tr("Purchasing a gift"));
d->email->setLabel(tr("Recepient email"));
d->email->setHelper(tr("A promo code to activate the gift will be sent here"));
d->greeting->setLabel(tr("Greeting text"));
Expand Down Expand Up @@ -170,7 +170,7 @@ void PurchaseGiftDialog::designSystemChangeEvent(DesignSystemChangeEvent* _event
}
d->informationIcon->setContentsMargins(DesignSystem::layout().px12(),
DesignSystem::layout().px16(),
DesignSystem::layout().px8(), 0);
DesignSystem::layout().px12(), 0);
d->informationText->setContentsMargins(0, DesignSystem::layout().px16(),
DesignSystem::layout().px12(),
DesignSystem::layout().px16());
Expand Down
9 changes: 8 additions & 1 deletion src/core/ui/account/subscription_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SubscriptionWidget::Implementation
Button* tryButton = nullptr;
Button* buyButton = nullptr;
Button* buyLifetimeButton = nullptr;
Button* giftButton = nullptr;
QVBoxLayout* layout = nullptr;
};

Expand All @@ -43,6 +44,7 @@ SubscriptionWidget::Implementation::Implementation(QWidget* _parent)
, tryButton(new Button(_parent))
, buyButton(new Button(_parent))
, buyLifetimeButton(new Button(_parent))
, giftButton(new Button(_parent))
, layout(new QVBoxLayout)
{
isActiveIcon->setIcon(u8"\U000F05E0");
Expand Down Expand Up @@ -77,6 +79,7 @@ SubscriptionWidget::Implementation::Implementation(QWidget* _parent)
buttonsLayout->addWidget(tryButton, 0, Qt::AlignBottom);
buttonsLayout->addWidget(buyButton, 0, Qt::AlignBottom);
buttonsLayout->addWidget(buyLifetimeButton, 0, Qt::AlignBottom);
buttonsLayout->addWidget(giftButton, 0, Qt::AlignBottom);
layout->addLayout(buttonsLayout);
}
}
Expand All @@ -94,6 +97,7 @@ SubscriptionWidget::SubscriptionWidget(QWidget* _parent)
connect(d->tryButton, &Button::clicked, this, &SubscriptionWidget::tryPressed);
connect(d->buyButton, &Button::clicked, this, &SubscriptionWidget::buyPressed);
connect(d->buyLifetimeButton, &Button::clicked, this, &SubscriptionWidget::buyLifetimePressed);
connect(d->giftButton, &Button::clicked, this, &SubscriptionWidget::giftPressed);
}

SubscriptionWidget::~SubscriptionWidget() = default;
Expand Down Expand Up @@ -149,7 +153,8 @@ void SubscriptionWidget::setPaymentOptions(const QVector<Domain::PaymentOption>&
d->trialInfo->setVisible(hasTrial);
d->tryButton->setVisible(hasTrial);
d->buyButton->setVisible(!hasTrial && !d->isLifetime);
d->buyLifetimeButton->setVisible(!hasTrial && hasLifetime);
d->buyLifetimeButton->setVisible(!hasTrial && hasLifetime && !d->isLifetime);
d->giftButton->setVisible(d->isLifetime);
}

void SubscriptionWidget::updateTranslations()
Expand All @@ -158,6 +163,7 @@ void SubscriptionWidget::updateTranslations()
d->tryButton->setText(tr("Try for free"));
d->buyButton->setText(tr("Renew"));
d->buyLifetimeButton->setText(tr("Buy lifetime"));
d->giftButton->setText(tr("Buy as a gift"));
}

void SubscriptionWidget::designSystemChangeEvent(DesignSystemChangeEvent* _event)
Expand Down Expand Up @@ -203,6 +209,7 @@ void SubscriptionWidget::designSystemChangeEvent(DesignSystemChangeEvent* _event
d->tryButton,
d->buyButton,
d->buyLifetimeButton,
d->giftButton,
}) {
button->setBackgroundColor(DesignSystem::color().accent());
button->setTextColor(DesignSystem::color().accent());
Expand Down
5 changes: 5 additions & 0 deletions src/core/ui/account/subscription_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class SubscriptionWidget : public Card
*/
void buyLifetimePressed();

/**
* @brief Нажата кнопка подарить
*/
void giftPressed();

protected:
/**
* @brief Обновляем переводы
Expand Down

0 comments on commit 93462aa

Please sign in to comment.