diff --git a/src/cloud b/src/cloud index 94f715b2e..7fff56051 160000 --- a/src/cloud +++ b/src/cloud @@ -1 +1 @@ -Subproject commit 94f715b2ea630ca6849e179ad38d4c34b180b4e7 +Subproject commit 7fff560513c8b260ea0274a84bf2a6aacf4e168b diff --git a/src/core/management_layer/content/account/account_manager.cpp b/src/core/management_layer/content/account/account_manager.cpp index 5c745a4b0..8b6ee2f16 100644 --- a/src/core/management_layer/content/account/account_manager.cpp +++ b/src/core/management_layer/content/account/account_manager.cpp @@ -601,7 +601,13 @@ void AccountManager::buyProLifetme() } } + const int discount = proPaymentOptions.constFirst().discount; + const auto discountInfo = discount > 0 + ? tr("You have an additional %1% discount due to the promo code activation").arg(discount) + : ""; + d->initPurchaseDialog(); + d->purchaseDialog->setDiscountInfo(discountInfo); d->purchaseDialog->setPaymentOptions(proPaymentOptions); d->purchaseDialog->selectOption(proPaymentOptions.constFirst()); d->purchaseDialog->showDialog(); @@ -622,7 +628,13 @@ void AccountManager::renewPro() return; } + const int discount = proPaymentOptions.constFirst().discount; + const auto discountInfo = discount > 0 + ? tr("You have an additional %1% discount due to the promo code activation").arg(discount) + : ""; + d->initPurchaseDialog(); + d->purchaseDialog->setDiscountInfo(discountInfo); d->purchaseDialog->setPaymentOptions(proPaymentOptions); d->purchaseDialog->selectOption(proPaymentOptions.constLast()); d->purchaseDialog->showDialog(); @@ -640,7 +652,13 @@ void AccountManager::giftPro() } } + const int discount = proPaymentOptions.constFirst().discount; + const auto discountInfo = discount > 0 + ? tr("You have an additional %1% discount due to the promo code activation").arg(discount) + : ""; + d->initPurchaseDialog(); + d->purchaseDialog->setDiscountInfo(discountInfo); d->purchaseDialog->setPaymentOptions(proPaymentOptions); d->purchaseDialog->setPurchaseAvailable(false); d->purchaseDialog->selectOption(proPaymentOptions.constFirst()); @@ -705,7 +723,30 @@ void AccountManager::renewCloud() return; } + const auto hasProLifetime + = std::find_if(d->accountInfo.subscriptions.begin(), d->accountInfo.subscriptions.end(), + [](const Domain::SubscriptionInfo& _subscription) { + return _subscription.type == Domain::SubscriptionType::ProLifetime; + }); + const int discount = cloudPaymentOptions.constFirst().discount; + QString discountInfo; + if (hasProLifetime) { + if (discount > 20) { + discountInfo + = tr("You have an additional 20% discount due to PRO lifetime subscription " + "purchase, and %1% discount due to the promo code activation") + .arg(discount - 20); + } else { + discountInfo = tr("You have an additional 20% discount thanks to the purchasing of the " + "PRO lifetime subscription"); + } + } else if (discount > 0) { + discountInfo = tr("You have an additional %1% discount due to the promo code activation") + .arg(discount); + } + d->initPurchaseDialog(); + d->purchaseDialog->setDiscountInfo(discountInfo); d->purchaseDialog->setPaymentOptions(cloudPaymentOptions); d->purchaseDialog->selectOption(cloudPaymentOptions.constLast()); d->purchaseDialog->showDialog(); @@ -726,7 +767,31 @@ void AccountManager::giftCloud() return; } + const auto hasProLifetime + = std::find_if(d->accountInfo.subscriptions.begin(), d->accountInfo.subscriptions.end(), + [](const Domain::SubscriptionInfo& _subscription) { + return _subscription.type == Domain::SubscriptionType::ProLifetime; + }); + const int discount = cloudPaymentOptions.constFirst().discount; + QString discountInfo; + if (hasProLifetime) { + if (discount > 20) { + discountInfo = tr("You have an additional 20% discount thanks to the purchasing of the " + "PRO lifetime subscription and %1% discount thanks to the activation " + "of the promo code") + .arg(discount - 20); + } else { + discountInfo = tr("You have an additional 20% discount thanks to the purchasing of the " + "PRO lifetime subscription"); + } + } else if (discount > 0) { + discountInfo + = tr("You have an additional %1% discount thanks to the activation of the promo code") + .arg(discount); + } + d->initPurchaseDialog(); + d->purchaseDialog->setDiscountInfo(discountInfo); d->purchaseDialog->setPaymentOptions(cloudPaymentOptions); d->purchaseDialog->setPurchaseAvailable(false); d->purchaseDialog->selectOption(cloudPaymentOptions.constLast()); @@ -754,11 +819,18 @@ void AccountManager::buyCredits() return; } + const int discount = creditPaymentOptions.constFirst().discount; + const auto discountInfo = discount > 0 + ? tr("You have an additional %1% discount thanks to the activation of the promo code") + .arg(discount) + : ""; + d->initPurchaseDialog(); d->purchaseDialog->setDescription( tr("Credits are our internal currency. They are used for AI tools, such as text " "generation.\n\n1 credit equals 1000 words processed by AI.\n1 credit equals 10 images " "generated by AI.")); + d->purchaseDialog->setDiscountInfo(discountInfo); d->purchaseDialog->setPaymentOptions(creditPaymentOptions); d->purchaseDialog->selectOption(creditPaymentOptions.constLast()); d->purchaseDialog->showDialog(); diff --git a/src/core/ui/account/purchase_dialog.cpp b/src/core/ui/account/purchase_dialog.cpp index 17a3edba1..70958e009 100644 --- a/src/core/ui/account/purchase_dialog.cpp +++ b/src/core/ui/account/purchase_dialog.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -27,6 +28,9 @@ class PurchaseDialog::Implementation Body1Label* descriptionLabel = nullptr; Widget* content = nullptr; QVector options; + Body1Label* information = nullptr; + IconsMidLabel* informationIcon = nullptr; + Body2Label* informationText = nullptr; QHBoxLayout* buttonsLayout = nullptr; Button* giftButton = nullptr; @@ -37,12 +41,17 @@ class PurchaseDialog::Implementation PurchaseDialog::Implementation::Implementation(QWidget* _parent) : descriptionLabel(new Body1Label(_parent)) , content(new Widget(_parent)) + , information(new Body1Label(content)) + , informationIcon(new IconsMidLabel(content)) + , informationText(new Body2Label(content)) , buttonsLayout(new QHBoxLayout) , giftButton(new Button(_parent)) , cancelButton(new Button(_parent)) , purchaseButton(new Button(_parent)) { descriptionLabel->hide(); + information->hide(); + informationIcon->setIcon(u8"\U000F02FD"); buttonsLayout->setContentsMargins({}); buttonsLayout->setSpacing(0); @@ -74,9 +83,18 @@ PurchaseDialog::PurchaseDialog(QWidget* _parent) setAcceptButton(d->purchaseButton); setRejectButton(d->cancelButton); - contentsLayout()->addWidget(d->descriptionLabel, 0, 0); - contentsLayout()->addWidget(d->content, 1, 0); - contentsLayout()->addLayout(d->buttonsLayout, 2, 0); + auto informationLayout = new QHBoxLayout; + informationLayout->setContentsMargins({}); + informationLayout->setSpacing(0); + informationLayout->addWidget(d->informationIcon, 0, Qt::AlignTop); + informationLayout->addWidget(d->informationText, 1); + d->information->setLayout(informationLayout); + + int row = 0; + contentsLayout()->addWidget(d->descriptionLabel, row++, 0); + contentsLayout()->addWidget(d->content, row++, 0); + contentsLayout()->addWidget(d->information, row++, 0); + contentsLayout()->addLayout(d->buttonsLayout, row++, 0); connect(d->giftButton, &Button::clicked, this, [this] { for (auto option : std::as_const(d->options)) { @@ -105,6 +123,12 @@ void PurchaseDialog::setDescription(const QString& _description) d->descriptionLabel->setVisible(!_description.isEmpty()); } +void PurchaseDialog::setDiscountInfo(const QString& _info) +{ + d->informationText->setText(_info); + d->information->setVisible(!_info.isEmpty()); +} + void PurchaseDialog::setPurchaseAvailable(bool _available) { d->purchaseButton->setEnabled(_available); @@ -194,13 +218,32 @@ void PurchaseDialog::designSystemChangeEvent(DesignSystemChangeEvent* _event) setContentFixedWidth(DesignSystem::dialog().maximumWidth()); - d->content->setBackgroundColor(DesignSystem::color().background()); - d->descriptionLabel->setBackgroundColor(DesignSystem::color().background()); d->descriptionLabel->setTextColor(DesignSystem::color().onBackground()); d->descriptionLabel->setContentsMargins(DesignSystem::layout().px24(), 0, DesignSystem::layout().px24(), 0); + d->content->setBackgroundColor(DesignSystem::color().background()); + + d->information->setBackgroundColor(ColorHelper::transparent( + DesignSystem::color().accent(), DesignSystem::focusBackgroundOpacity())); + d->information->setContentsMargins(DesignSystem::layout().px24(), DesignSystem::layout().px24(), + DesignSystem::layout().px24(), 0); + d->information->setBorderRadius(DesignSystem::layout().px4()); + for (auto label : std::vector{ + d->informationIcon, + d->informationText, + }) { + label->setBackgroundColor(Qt::transparent); + label->setTextColor(DesignSystem::color().onBackground()); + } + d->informationIcon->setContentsMargins(DesignSystem::layout().px12(), + DesignSystem::layout().px16(), + DesignSystem::layout().px12(), 0); + d->informationText->setContentsMargins(0, DesignSystem::layout().px16(), + DesignSystem::layout().px12(), + DesignSystem::layout().px16()); + for (auto button : { d->giftButton, d->cancelButton, diff --git a/src/core/ui/account/purchase_dialog.h b/src/core/ui/account/purchase_dialog.h index d25c32413..a0a7fddf1 100644 --- a/src/core/ui/account/purchase_dialog.h +++ b/src/core/ui/account/purchase_dialog.h @@ -25,6 +25,11 @@ class PurchaseDialog : public AbstractDialog */ void setDescription(const QString& _description); + /** + * @brief Задать информацию о скидке + */ + void setDiscountInfo(const QString& _info); + /** * @brief Задать возможность покупки подписки для себя */