Skip to content

Commit

Permalink
Stil refactor toggleAnimation function.
Browse files Browse the repository at this point in the history
Signed-off-by: Camila <[email protected]>
  • Loading branch information
Camila committed Oct 4, 2021
1 parent 47e2073 commit 78c2990
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 16 additions & 15 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)
{
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 @@ -332,14 +334,14 @@ 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)
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,7 +373,7 @@ 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());
}
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,7 +403,7 @@ 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);
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 Down
2 changes: 1 addition & 1 deletion src/gui/sharelinkwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ 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 toggleButtonAnimation(QToolButton *button, QProgressIndicator *progressIndicator, const QAction *checkedAction);
void slotServerError(const int code, const QString &message);
void slotCreateShareRequiresPassword(const QString &message);
void slotStyleChanged();
Expand Down

0 comments on commit 78c2990

Please sign in to comment.