/
Shymer123
/
Messenger
Обзор
Документация
Войти
/
Shymer123
/
Messenger
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
UI_Client/SourceFiles/Ui/ContactsMenu/AddContact/AddContact.cpp
251 строка
8 KB
Shymer123
A lot of bugs related to the creation of dialogs and groups have been
26 мар 2025, 16:07
26 мар 2025, 16:07
6a8c3e4
Код
Авторство
О чём код?
#include "AddContact.h" #include "Processes/ContactsMenu/addContact/AddContactProcess.h" #include "RequestResponseHandler/dependencyManager.h" #include "Ui/ContactsMenu/NotExistPhoneNumber/NotExistPhoneNumber.h" #include "DataModels/user_data.h" #include "Ui/Widgets/Inputs/PhoneLineEdit/PhoneLineEdit.h" #include <QLabel> #include <QPushButton> #include <QLineEdit> #include <QVBoxLayout> #include <QHBoxLayout> #include <QStyleOption> #include <QPainter> #include <QPropertyAnimation> namespace Ui { namespace ContactsMenu { AddContact::AddContact(QWidget* parent) : QWidget(parent) { setFixedSize(300, 280); setObjectName("wdg_addContact_menu"); m_communicationHandler = DependencyManager::instance().communicationHandler(); m_userID = UserData::instance().getID(); m_userName = UserData::instance().getUserName(); setupFull(); } AddContact::~AddContact() {} void AddContact::paintEvent(QPaintEvent* event) { Q_UNUSED(event); QStyleOption opt; opt.initFrom(this); QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } void AddContact::setupFull() { setupHeader(); setupFirstNameLayout(); setupLastNameLayout(); setupPhoneNumberLayout(); setupInfoLabel(); setupButtonsLayout(); setupAnimation(); QVBoxLayout* vMainLayout = new QVBoxLayout; vMainLayout->addWidget(m_headerLabel); vMainLayout->addLayout(m_firstNameLayout); vMainLayout->addLayout(m_lastNameLayout); vMainLayout->addLayout(m_phoneNumberLayout); vMainLayout->addWidget(m_infoLabel); vMainLayout->addLayout(m_buttonsLayoutAddContact); notExistPhoneNumberWidget = new NotExistPhoneNumber(parentWidget()); m_addContactProcess = new Processes::AddContactProcess(); m_addContactProcess->setAddContactWidget(this); m_addContactProcess->setNotExistPhoneNumberWidget(notExistPhoneNumberWidget); connectSignals(); setLayout(vMainLayout); } void AddContact::setupHeader() { m_headerLabel = new QLabel(tr("New contact"), this); m_headerLabel->setObjectName("lbl_addContact_header"); } void AddContact::setupFirstNameLayout() { QLabel* m_nameIconAddContactLabel = new QLabel(this); m_nameIconAddContactLabel->setPixmap(QPixmap(":/icons/ContactsMenu/user.png")); m_nameIconAddContactLabel->setFixedSize(32, 32); m_firstNameField = new QLineEdit(this); m_firstNameField->setPlaceholderText(tr("First name")); m_firstNameField->setMaxLength(16); m_firstNameField->setObjectName("txt_addContact_first_name"); m_firstNameField->setProperty("class", ""); m_firstNameLayout = new QHBoxLayout; m_firstNameLayout->addWidget(m_nameIconAddContactLabel); m_firstNameLayout->addWidget(m_firstNameField); } void AddContact::setupLastNameLayout() { m_lastNameField = new QLineEdit(this); m_lastNameField->setPlaceholderText(tr("Last name")); m_lastNameField->setMaxLength(16); m_lastNameField->setObjectName("txt_addContact_last_name"); m_lastNameField->setProperty("class", ""); m_lastNameLayout = new QHBoxLayout; QSpacerItem* spacer = new QSpacerItem(38, 0); m_lastNameLayout->addSpacerItem(spacer); m_lastNameLayout->addWidget(m_lastNameField); } void AddContact::setupPhoneNumberLayout() { QLabel* m_phoneNumberIconAddContactLabel = new QLabel(this); m_phoneNumberIconAddContactLabel->setPixmap(QPixmap(":/icons/ContactsMenu/phone.png")); m_phoneNumberIconAddContactLabel->setFixedSize(32, 32); m_phoneNumberField = new Widgets::PhoneLineEdit(this); m_phoneNumberField->setObjectName("txt_addContact_phone_number"); m_phoneNumberField->setProperty("class", ""); m_phoneNumberLayout = new QHBoxLayout; m_phoneNumberLayout->addWidget(m_phoneNumberIconAddContactLabel); m_phoneNumberLayout->addWidget(m_phoneNumberField); } void AddContact::setupInfoLabel() { m_infoLabel = new QLabel(this); m_infoLabel->setObjectName("lbl_addContact_info"); m_infoLabel->setFixedHeight(40); } void AddContact::setupButtonsLayout() { m_cancelButton = new QPushButton(tr("Cancel"), this); m_cancelButton->setObjectName("btn_addContact_cancel"); m_createButton = new QPushButton(tr("Create"), this); m_createButton->setObjectName("btn_addContact_create"); m_buttonsLayoutAddContact = new QHBoxLayout; m_buttonsLayoutAddContact->addStretch(); m_buttonsLayoutAddContact->addWidget(m_cancelButton); m_buttonsLayoutAddContact->addWidget(m_createButton); } void AddContact::connectSignals() { connect(m_cancelButton, &QPushButton::clicked, this, [this]() { emit clickedCancelSignal(); }); connect(m_addContactProcess, &Processes::AddContactProcess::clickedCancelSignal, this, [this]() { emit clickedCancelSignal(); }); connect(m_createButton, &QPushButton::clicked, this, &AddContact::onClickedCreateAddContact); connect(m_firstNameField, &QLineEdit::textEdited, this, &AddContact::onTextChangedLineEdit); connect(m_lastNameField, &QLineEdit::textEdited, this, &AddContact::onTextChangedLineEdit); connect(m_phoneNumberField, &QLineEdit::textEdited, this, &AddContact::onTextChangedLineEdit); } void AddContact::onClickedCreateAddContact() { m_infoLabel->setText(""); QString firstNameText = m_firstNameField->text(); QString lastNameText = m_lastNameField->text(); QString phoneNumberText = m_phoneNumberField->text(); m_addContactProcess->processAddContact(firstNameText, lastNameText, phoneNumberText); } void AddContact::onTextChangedLineEdit() { QLineEdit* lineEdit = static_cast<QLineEdit*>(sender()); lineEdit->setProperty("class", "changed"); lineEdit->style()->unpolish(lineEdit); lineEdit->style()->polish(lineEdit); } void AddContact::setupAnimation() { m_animation = new QPropertyAnimation(this, "geometry"); m_animation->setDuration(200); m_animation->setStartValue(QRect(parentWidget()->width(), parentWidget()->height() / 2 - 270, this->width(), this->height())); m_animation->setEndValue(QRect(parentWidget()->width() / 2 - 150, parentWidget()->height() / 2 - 270, this->width(), this->height())); connect(m_animation, &QPropertyAnimation::finished, this, &AddContact::onAnimationFinished); } void AddContact::animateAddContact(bool show) { m_animation->setDirection(show ? QPropertyAnimation::Forward : QPropertyAnimation::Backward); if (!m_isAnimationRunning) { m_isAnimationRunning = true; this->show(); m_animation->start(); } } void AddContact::onAnimationFinished() { m_isAnimationRunning = false; if (m_animation->direction() == QPropertyAnimation::Backward) { this->hide(); } emit animatedFinishedSignal(); } void AddContact::updateGeometry() { this->setGeometry(parentWidget()->width() / 2 - 150, parentWidget()->height() / 2 - 270, this->width(), this->height()); m_animation->setStartValue(QRect(parentWidget()->width(), parentWidget()->height() / 2 - 270, this->width(), this->height())); m_animation->setEndValue(QRect(parentWidget()->width() / 2 - 150, parentWidget()->height() / 2 - 270, this->width(), parentWidget()->height())); } NotExistPhoneNumber* AddContact::getNotExistPhoneNumberWidget() const { return notExistPhoneNumberWidget; } QLineEdit* AddContact::getFirstNameField() const { return m_firstNameField; } QLineEdit* AddContact::getLastNameField() const { return m_lastNameField; } Widgets::PhoneLineEdit* AddContact::getPhoneNumberField() const { return m_phoneNumberField; } QLabel* AddContact::getInfoLabel() const { return m_infoLabel; } } // namespace ContactsMenu } // namespace Ui