Skip to content

Commit

Permalink
Started implementation of the compare versions dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkanovikov committed Aug 22, 2024
1 parent 00d186f commit b03e340
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/core/core.pro
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ SOURCES += \
ui/account/account_view_teams.cpp \
ui/account/account_view_teams_sidebar.cpp \
ui/account/collaborators_tool_bar.cpp \
ui/account/compare_subscriptions_dialog.cpp \
ui/account/connection_status_tool_bar.cpp \
ui/account/login_dialog.cpp \
ui/account/purchase_dialog.cpp \
Expand Down Expand Up @@ -164,6 +165,7 @@ HEADERS += \
ui/account/account_view_teams.h \
ui/account/account_view_teams_sidebar.h \
ui/account/collaborators_tool_bar.h \
ui/account/compare_subscriptions_dialog.h \
ui/account/connection_status_tool_bar.h \
ui/account/login_dialog.h \
ui/account/purchase_dialog.h \
Expand Down
192 changes: 192 additions & 0 deletions src/core/ui/account/compare_subscriptions_dialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
#include "compare_subscriptions_dialog.h"

#include <ui/design_system/design_system.h>
#include <ui/widgets/button/button.h>
#include <ui/widgets/label/label.h>
#include <utils/helpers/ui_helper.h>

#include <QBoxLayout>
#include <QScrollArea>


namespace Ui {

class CompareSubscriptionsDialog::Implementation
{
public:
explicit Implementation(QWidget* _parent);


IconsMidLabel* freeTitleIcon = nullptr;
ButtonLabel* freeTitle = nullptr;
Subtitle2Label* freeSubtitle = nullptr;
//
IconsMidLabel* proTitleIcon = nullptr;
ButtonLabel* proTitle = nullptr;
Subtitle2Label* proSubtitle = nullptr;
//
IconsMidLabel* cloudTitleIcon = nullptr;
ButtonLabel* cloudTitle = nullptr;
Subtitle2Label* cloudSubtitle = nullptr;
//
QScrollArea* content = nullptr;
QGridLayout* contentLayout = nullptr;
QVector<QVector<QWidget*>> contentWidgets;
//
Button* buyPro = nullptr;
Button* buyCloud = nullptr;
};

CompareSubscriptionsDialog::Implementation::Implementation(QWidget* _parent)
: freeTitleIcon(new IconsMidLabel(_parent))
, freeTitle(new ButtonLabel(_parent))
, freeSubtitle(new Subtitle2Label(_parent))
, proTitleIcon(new IconsMidLabel(_parent))
, proTitle(new ButtonLabel(_parent))
, proSubtitle(new Subtitle2Label(_parent))
, cloudTitleIcon(new IconsMidLabel(_parent))
, cloudTitle(new ButtonLabel(_parent))
, cloudSubtitle(new Subtitle2Label(_parent))
, content(UiHelper::createScrollArea(_parent, true))
, buyPro(new Button(_parent))
, buyCloud(new Button(_parent))
{
contentLayout = qobject_cast<QGridLayout*>(content->widget()->layout());
}


// ****


CompareSubscriptionsDialog::CompareSubscriptionsDialog(QWidget* _parent)
: AbstractDialog(_parent)
, d(new Implementation(this))
{
auto topLayout = new QHBoxLayout;
topLayout->setContentsMargins({});
topLayout->setSpacing(0);
topLayout->addStretch(1);
{
auto titleLayout = new QHBoxLayout;
titleLayout->setContentsMargins({});
titleLayout->setSpacing(0);
titleLayout->addWidget(d->freeTitleIcon);
titleLayout->addWidget(d->freeTitle);
auto layout = new QVBoxLayout;
layout->setContentsMargins({});
layout->setSpacing(0);
layout->addLayout(titleLayout);
layout->addWidget(d->freeSubtitle, 0, Qt::AlignLeft | Qt::AlignTop);
topLayout->addLayout(layout, 1);
}
{
auto titleLayout = new QHBoxLayout;
titleLayout->setContentsMargins({});
titleLayout->setSpacing(0);
titleLayout->addWidget(d->proTitleIcon);
titleLayout->addWidget(d->proTitle);
auto layout = new QVBoxLayout;
layout->setContentsMargins({});
layout->setSpacing(0);
layout->addLayout(titleLayout);
layout->addWidget(d->proSubtitle, 0, Qt::AlignLeft | Qt::AlignTop);
topLayout->addLayout(layout, 1);
}
{
auto titleLayout = new QHBoxLayout;
titleLayout->setContentsMargins({});
titleLayout->setSpacing(0);
titleLayout->addWidget(d->cloudTitleIcon);
titleLayout->addWidget(d->cloudTitle);
auto layout = new QVBoxLayout;
layout->setContentsMargins({});
layout->setSpacing(0);
layout->addLayout(titleLayout);
layout->addWidget(d->cloudSubtitle, 0, Qt::AlignLeft | Qt::AlignTop);
topLayout->addLayout(layout, 1);
}

auto buttonsLayout = new QHBoxLayout;
buttonsLayout->setContentsMargins({});
buttonsLayout->setSpacing(0);
buttonsLayout->addStretch(1);
buttonsLayout->addStretch(1);
buttonsLayout->addWidget(d->buyPro, 1, Qt::AlignCenter);
buttonsLayout->addWidget(d->buyCloud, 1, Qt::AlignCenter);

int row = 0;
contentsLayout()->addLayout(topLayout, row++, 0);
contentsLayout()->addWidget(d->content, row++, 0);
contentsLayout()->addLayout(buttonsLayout, row++, 0);
}

CompareSubscriptionsDialog::~CompareSubscriptionsDialog() = default;

QWidget* CompareSubscriptionsDialog::focusedWidgetAfterShow() const
{
return d->content;
}

QWidget* CompareSubscriptionsDialog::lastFocusableWidget() const
{
return d->buyCloud;
}

void CompareSubscriptionsDialog::updateTranslations()
{
for (const auto& row : std::as_const(d->contentWidgets)) {
for (auto widget : row) {
d->contentLayout->removeWidget(widget);
widget->deleteLater();
}
}
d->contentWidgets.clear();

struct Row {
QString text = {};
bool free = false;
bool pro = false;
bool cloud = false;

bool isTitle() const
{
return !free && !pro && !cloud;
}
};
const QVector<Row> table = {
{ tr("Title") },
{ tr("Feature"), false, true, true },
};
int row = 0;
for (const auto& rowData : table) {
if (rowData.isTitle()) {

} else {
auto label = new Body1Label;
label->setText(rowData.text);
d->contentLayout->addWidget(label, row, 0);
//
auto free = new IconsMidLabel;
free->setIcon(rowData.free ? u8"\U000F012C" : u8"\U000F0374");
d->contentLayout->addWidget(free, row, 1);
//
auto pro = new IconsMidLabel;
pro->setIcon(rowData.pro ? u8"\U000F012C" : u8"\U000F0374");
d->contentLayout->addWidget(pro, row, 2);
//
auto cloud = new IconsMidLabel;
cloud->setIcon(rowData.cloud ? u8"\U000F012C" : u8"\U000F0374");
d->contentLayout->addWidget(cloud, row, 3);

d->contentWidgets.append({ label, free, pro, cloud });
}

++row;
}
}

void CompareSubscriptionsDialog::designSystemChangeEvent(DesignSystemChangeEvent* _event)
{
}

} // namespace Ui
53 changes: 53 additions & 0 deletions src/core/ui/account/compare_subscriptions_dialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#pragma once

#include <ui/widgets/dialog/abstract_dialog.h>


namespace Ui {

class CompareSubscriptionsDialog : public AbstractDialog
{
Q_OBJECT

public:
explicit CompareSubscriptionsDialog(QWidget* _parent = nullptr);
~CompareSubscriptionsDialog() override;

protected:
/**
* @brief Определим виджет, который необходимо сфокусировать после отображения диалога
*/
QWidget* focusedWidgetAfterShow() const override;

/**
* @brief Опеределим последний фокусируемый виджет в диалоге
*/
QWidget* lastFocusableWidget() const override;

/**
* @brief Обновить переводы
*/
void updateTranslations() override;

/**
* @brief Обновляем UI при изменении дизайн системы
*/
void designSystemChangeEvent(DesignSystemChangeEvent* _event) override;

signals:
/**
* @brief Пользователь нажал кнопку оплаты
*/
void purchasePressed();

/**
* @brief Пользователь передумал вносить платёж
*/
void canceled();

private:
class Implementation;
QScopedPointer<Implementation> d;
};

} // namespace Ui
16 changes: 11 additions & 5 deletions src/corelib/utils/helpers/ui_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void UiHelper::setFocusPolicyRecursively(QWidget* _widget, Qt::FocusPolicy _poli
}
}

QScrollArea* UiHelper::createScrollArea(QWidget* _parent)
QScrollArea* UiHelper::createScrollArea(QWidget* _parent, bool _withGridLayout)
{
auto content = new QScrollArea(_parent);
QPalette palette;
Expand All @@ -53,10 +53,16 @@ QScrollArea* UiHelper::createScrollArea(QWidget* _parent)
auto contentWidget = new QWidget;
content->setWidget(contentWidget);
content->setWidgetResizable(true);
auto layout = new QVBoxLayout(contentWidget);
layout->setContentsMargins({});
layout->setSpacing(0);
layout->addStretch();
if (_withGridLayout) {
auto layout = new QGridLayout(contentWidget);
layout->setContentsMargins({});
layout->setSpacing(0);
} else {
auto layout = new QVBoxLayout(contentWidget);
layout->setContentsMargins({});
layout->setSpacing(0);
layout->addStretch();
}

return content;
}
Expand Down
2 changes: 1 addition & 1 deletion src/corelib/utils/helpers/ui_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CORE_LIBRARY_EXPORT UiHelper
/**
* @brief Создать виджет скролареи с настроенной палитрой и скролбаром
*/
static QScrollArea* createScrollArea(QWidget* _parent);
static QScrollArea* createScrollArea(QWidget* _parent, bool _withGridLayout = false);

/**
* @brief Показать тултип в текущем положении мышки
Expand Down

0 comments on commit b03e340

Please sign in to comment.