Skip to content

Commit

Permalink
Refactor toggleButtonAnimation function.
Browse files Browse the repository at this point in the history
Signed-off-by: Camila <[email protected]>
  • Loading branch information
Camila authored and mgallien committed Oct 28, 2021
1 parent ab524d2 commit d68b860
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
45 changes: 23 additions & 22 deletions src/gui/sharelinkwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,19 @@ void ShareLinkWidget::slotToggleShareLinkAnimation(const bool start)
}
}

void ShareLinkWidget::toggleButtonAnimation(QToolButton *button, QProgressIndicator *progressIndicator, const QAction *checkedAction, const bool start)
void ShareLinkWidget::toggleButtonAnimation(QToolButton *button, QProgressIndicator *progressIndicator, const QAction *checkedAction) const
{
if (!progressIndicator->isAnimated() && checkedAction->isChecked()) {
auto startAnimation = false;
const auto actionIsChecked = checkedAction->isChecked();
if (!progressIndicator->isAnimated() && actionIsChecked) {
progressIndicator->startAnimation();
startAnimation = true;
} else {
progressIndicator->stopAnimation();
}

const auto startAnimation = checkedAction->isChecked()? progressIndicator->isAnimated() : checkedAction->isChecked();
button->setVisible(!startAnimation && checkedAction->isChecked());
progressIndicator->setVisible(startAnimation && checkedAction->isChecked());
button->setVisible(!startAnimation && actionIsChecked);
progressIndicator->setVisible(startAnimation && actionIsChecked);
}

void ShareLinkWidget::setLinkShare(QSharedPointer<LinkShare> linkShare)
Expand Down Expand Up @@ -255,7 +257,7 @@ void ShareLinkWidget::setupUiOptions()
if (_linkShare->getNote().isSimpleText() && !_linkShare->getNote().isEmpty()) {
_ui->textEdit_note->setText(_linkShare->getNote());
_noteLinkAction->setChecked(true);
toggleNoteOptions(true);
toggleNoteOptions();
}

// Adds action to display password widget (check box)
Expand All @@ -265,7 +267,7 @@ void ShareLinkWidget::setupUiOptions()
if (_linkShare.data()->isPasswordSet()) {
_passwordProtectLinkAction->setChecked(true);
_ui->lineEdit_password->setPlaceholderText(QString::fromUtf8(passwordIsSetPlaceholder));
togglePasswordOptions(true);
togglePasswordOptions();
}

// If password is enforced then don't allow users to disable it
Expand All @@ -283,7 +285,7 @@ void ShareLinkWidget::setupUiOptions()
if (!expireDate.isNull()) {
_ui->calendar->setDate(expireDate);
_expirationDateLinkAction->setChecked(true);
toggleExpireDateOptions(true);
toggleExpireDateOptions();
}
connect(_ui->calendar, &QDateTimeEdit::dateChanged, this, &ShareLinkWidget::slotSetExpireDate);
connect(_linkShare.data(), &LinkShare::expireDateSet, this, &ShareLinkWidget::slotExpireDateSet);
Expand Down Expand Up @@ -332,17 +334,17 @@ void ShareLinkWidget::slotCreateNote()
return;
}

toggleButtonAnimation(_ui->confirmNote, _ui->noteProgressIndicator, _noteLinkAction, true);
toggleButtonAnimation(_ui->confirmNote, _ui->noteProgressIndicator, _noteLinkAction);
_ui->errorLabel->hide();
_linkShare->setNote(note);
}

void ShareLinkWidget::slotNoteSet()
{
toggleButtonAnimation(_ui->confirmNote, _ui->noteProgressIndicator, _noteLinkAction, false);
toggleButtonAnimation(_ui->confirmNote, _ui->noteProgressIndicator, _noteLinkAction);
}

void ShareLinkWidget::slotCopyLinkShare(const bool clicked)
void ShareLinkWidget::slotCopyLinkShare(const bool clicked) const
{
Q_UNUSED(clicked);

Expand All @@ -351,7 +353,7 @@ void ShareLinkWidget::slotCopyLinkShare(const bool clicked)

void ShareLinkWidget::slotExpireDateSet()
{
toggleButtonAnimation(_ui->confirmExpirationDate, _ui->expirationDateProgressIndicator, _expirationDateLinkAction, false);
toggleButtonAnimation(_ui->confirmExpirationDate, _ui->expirationDateProgressIndicator, _expirationDateLinkAction);
}

void ShareLinkWidget::slotSetExpireDate()
Expand All @@ -360,7 +362,7 @@ void ShareLinkWidget::slotSetExpireDate()
return;
}

toggleButtonAnimation(_ui->confirmExpirationDate, _ui->expirationDateProgressIndicator, _expirationDateLinkAction, true);
toggleButtonAnimation(_ui->confirmExpirationDate, _ui->expirationDateProgressIndicator, _expirationDateLinkAction);
_ui->errorLabel->hide();
_linkShare->setExpireDate(_ui->calendar->date());
}
Expand All @@ -371,12 +373,12 @@ void ShareLinkWidget::slotCreatePassword()
return;
}

toggleButtonAnimation(_ui->confirmPassword, _ui->passwordProgressIndicator, _passwordProtectLinkAction, true);
toggleButtonAnimation(_ui->confirmPassword, _ui->passwordProgressIndicator, _passwordProtectLinkAction);
_ui->errorLabel->hide();
emit createPassword(_ui->lineEdit_password->text());
}

void ShareLinkWidget::slotCreateShareLink(bool clicked)
void ShareLinkWidget::slotCreateShareLink(const bool clicked)
{
Q_UNUSED(clicked);
slotToggleShareLinkAnimation(true);
Expand All @@ -385,7 +387,7 @@ void ShareLinkWidget::slotCreateShareLink(bool clicked)

void ShareLinkWidget::slotPasswordSet()
{
toggleButtonAnimation(_ui->confirmPassword, _ui->passwordProgressIndicator, _passwordProtectLinkAction, false);
toggleButtonAnimation(_ui->confirmPassword, _ui->passwordProgressIndicator, _passwordProtectLinkAction);

_ui->lineEdit_password->setText({});

Expand All @@ -401,10 +403,10 @@ void ShareLinkWidget::slotPasswordSet()

void ShareLinkWidget::slotPasswordSetError(const int code, const QString &message)
{
toggleButtonAnimation(_ui->confirmPassword, _ui->passwordProgressIndicator, _passwordProtectLinkAction, false);
toggleButtonAnimation(_ui->confirmPassword, _ui->passwordProgressIndicator, _passwordProtectLinkAction);

slotServerError(code, message);
togglePasswordOptions(true);
togglePasswordOptions();
_ui->lineEdit_password->setFocus();
emit createPasswordProcessed();
}
Expand Down Expand Up @@ -461,15 +463,14 @@ void ShareLinkWidget::slotCreateLabel()
return;
}
_shareLinkWidgetAction->setChecked(true);
toggleButtonAnimation(_shareLinkButton, _shareLinkProgressIndicator, _shareLinkWidgetAction, true);
toggleButtonAnimation(_shareLinkButton, _shareLinkProgressIndicator, _shareLinkWidgetAction);
_ui->errorLabel->hide();
_linkShare->setLabel(_shareLinkEdit->text());
}

void ShareLinkWidget::slotLabelSet()
{
_shareLinkWidgetAction->setChecked(false);
toggleButtonAnimation(_shareLinkButton, _shareLinkProgressIndicator, _shareLinkWidgetAction, false);
toggleButtonAnimation(_shareLinkButton, _shareLinkProgressIndicator, _shareLinkWidgetAction);
displayShareLinkLabel();
}

Expand All @@ -492,7 +493,7 @@ void ShareLinkWidget::slotCreateShareRequiresPassword(const QString &message)

_passwordRequired = true;

togglePasswordOptions(true);
togglePasswordOptions();
}

void ShareLinkWidget::togglePasswordOptions(const bool enable)
Expand Down
13 changes: 6 additions & 7 deletions src/gui/sharelinkwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ class ShareLinkWidget : public QWidget
public slots:
void slotDeleteShareFetched();
void slotToggleShareLinkAnimation(const bool start);
void toggleButtonAnimation(QToolButton *button, QProgressIndicator *progressIndicator, const QAction *checkedAction, const bool start);
void slotServerError(const int code, const QString &message);
void slotCreateShareRequiresPassword(const QString &message);
void slotStyleChanged();

private slots:
void slotCreateShareLink(bool clicked);
void slotCreateShareLink(const bool clicked);
void slotCopyLinkShare(const bool clicked) const;

void slotCreatePassword();
void slotPasswordSet();
Expand Down Expand Up @@ -108,11 +108,10 @@ private slots:
private:
void displayError(const QString &errMsg);

void togglePasswordOptions(const bool enable);
void toggleNoteOptions(const bool enable);
void toggleExpireDateOptions(const bool enable);

void slotCopyLinkShare(const bool clicked);
void togglePasswordOptions(const bool enable = true);
void toggleNoteOptions(const bool enable = true);
void toggleExpireDateOptions(const bool enable = true);
void toggleButtonAnimation(QToolButton *button, QProgressIndicator *progressIndicator, const QAction *checkedAction) const;

/** Confirm with the user and then delete the share */
void confirmAndDeleteShare();
Expand Down

0 comments on commit d68b860

Please sign in to comment.