Add some helper methods to effect wrappers.

Add and use similar methods to WidgetSlideWrap and WidgetFadeWrap:
[show|hide|toggle]Fast() and [show|hide|toggle]Animated().
This commit is contained in:
John Preston 2017-03-15 18:10:18 +03:00
parent fed20435ad
commit 1027bd431a
16 changed files with 80 additions and 131 deletions

View file

@ -175,16 +175,8 @@ void BoxContent::updateScrollAreaGeometry() {
updateInnerVisibleTopBottom();
auto top = _scroll->scrollTop();
if (top > 0 || _innerTopSkip > 0) {
_topShadow->showFast();
} else {
_topShadow->hideFast();
}
if (top < _scroll->scrollTopMax()) {
_bottomShadow->showFast();
} else {
_bottomShadow->hideFast();
}
_topShadow->toggleFast(top > 0 || _innerTopSkip > 0);
_bottomShadow->toggleFast(top < _scroll->scrollTopMax());
}
}

View file

@ -140,21 +140,16 @@ void ContactsBox::prepare() {
addPeerToMultiSelect(i, true);
}
_inner->setAllAdminsChangedCallback([this] {
_select->toggleAnimated(!_inner->allAdmins());
if (_inner->allAdmins()) {
_select->entity()->clearQuery();
_select->slideUp();
_inner->setFocus();
} else {
_select->slideDown();
_select->entity()->setInnerFocus();
}
updateScrollSkips();
});
if (_inner->chat() && _inner->membersFilter() == MembersFilter::Admins && _inner->allAdmins()) {
_select->hideFast();
} else {
_select->showFast();
}
_select->toggleFast(!_inner->chat() || (_inner->membersFilter() != MembersFilter::Admins) || !_inner->allAdmins());
_select->entity()->setQueryChangedCallback([this](const QString &query) { onFilterUpdate(query); });
_select->entity()->setItemRemovedCallback([this](uint64 itemId) {
if (auto peer = App::peerLoaded(itemId)) {

View file

@ -154,17 +154,15 @@ void PeerListBox::refreshRows() {
void PeerListBox::setSearchMode(SearchMode mode) {
_inner->setSearchMode(mode);
if (mode != SearchMode::None) {
if (!_select) {
_select = createMultiSelect();
_select->entity()->setSubmittedCallback([this](bool chtrlShiftEnter) { _inner->submitted(); });
_select->entity()->setQueryChangedCallback([this](const QString &query) { searchQueryChanged(query); });
_select->resizeToWidth(width());
_select->moveToLeft(0, 0);
}
_select->slideDown();
} else if (_select) {
_select->slideUp();
if (mode != SearchMode::None && !_select) {
_select = createMultiSelect();
_select->entity()->setSubmittedCallback([this](bool chtrlShiftEnter) { _inner->submitted(); });
_select->entity()->setQueryChangedCallback([this](const QString &query) { searchQueryChanged(query); });
_select->resizeToWidth(width());
_select->moveToLeft(0, 0);
}
if (_select) {
_select->toggleAnimated(mode != SearchMode::None);
}
}

View file

@ -3054,16 +3054,11 @@ void DialogsWidget::updateLockUnlockVisibility() {
void DialogsWidget::updateJumpToDateVisibility(bool fast) {
if (_a_show.animating()) return;
if (_searchInPeer && _filter->getLastText().isEmpty()) {
if (fast) {
_jumpToDate->showFast();
} else {
_jumpToDate->showAnimated();
}
} else if (fast) {
_jumpToDate->hideFast();
auto jumpToDateVisible = (_searchInPeer && _filter->getLastText().isEmpty());
if (fast) {
_jumpToDate->toggleFast(jumpToDateVisible);
} else {
_jumpToDate->hideAnimated();
_jumpToDate->toggleAnimated(jumpToDateVisible);
}
}

View file

@ -276,20 +276,11 @@ void Widget::showControls() {
getStep()->show();
_next->show();
_next->setText(getStep()->nextButtonText());
if (getStep()->hasCover()) {
_settings->hideFast();
if (_update) _update->hideFast();
if (_changeLanguage) _changeLanguage->showFast();
} else {
_settings->showFast();
if (_update) _update->showFast();
if (_changeLanguage) _changeLanguage->hideFast();
}
if (getStep()->hasBack()) {
_back->showFast();
} else {
_back->hideFast();
}
auto hasCover = getStep()->hasCover();
_settings->toggleFast(!hasCover);
if (_update) _update->toggleFast(!hasCover);
if (_changeLanguage) _changeLanguage->toggleFast(hasCover);
_back->toggleFast(getStep()->hasBack());
}
void Widget::hideControls() {

View file

@ -1612,7 +1612,7 @@ void MainWidget::switchToPanelPlayer() {
if (_playerUsingPanel) return;
_playerUsingPanel = true;
_player->slideUp();
_player->hideAnimated();
_playerVolume.destroyDelayed();
_playerPlaylist->hideIgnoringEnterEvents();
@ -1626,7 +1626,7 @@ void MainWidget::switchToFixedPlayer() {
if (!_player) {
createPlayer();
} else {
_player->slideDown();
_player->showAnimated();
if (!_playerVolume) {
_playerVolume.create(this);
_player->entity()->volumeWidgetCreated(_playerVolume);
@ -1643,7 +1643,7 @@ void MainWidget::closeBothPlayers() {
_playerUsingPanel = false;
_player.destroyDelayed();
} else {
_player->slideUp();
_player->hideAnimated();
}
_playerVolume.destroyDelayed();
@ -1667,7 +1667,7 @@ void MainWidget::createPlayer() {
} else {
_player->hideFast();
if (_player) {
_player->slideDown();
_player->showAnimated();
_playerHeight = _contentScrollAddToY = _player->contentHeight();
updateControlsGeometry();
}

View file

@ -88,11 +88,7 @@ void AdvancedWidget::createControls() {
void AdvancedWidget::checkNonDefaultTheme() {
if (self()) return;
if (Local::hasTheme()) {
_useDefaultTheme->slideDown();
} else {
_useDefaultTheme->slideUp();
}
_useDefaultTheme->toggleAnimated(Local::hasTheme());
}
void AdvancedWidget::onManageLocalStorage() {

View file

@ -208,11 +208,7 @@ BackgroundWidget::BackgroundWidget(QWidget *parent, UserData *self) : BlockWidge
}
});
subscribe(Adaptive::Changed(), [this]() {
if (Global::AdaptiveChatLayout() == Adaptive::ChatLayout::Wide) {
_adaptive->slideDown();
} else {
_adaptive->slideUp();
}
_adaptive->toggleAnimated(Global::AdaptiveChatLayout() == Adaptive::ChatLayout::Wide);
});
}

View file

@ -190,11 +190,7 @@ void ChatSettingsWidget::onReplaceEmoji() {
cSetReplaceEmojis(_replaceEmoji->checked());
Local::writeUserSettings();
if (_replaceEmoji->checked()) {
_viewList->slideDown();
} else {
_viewList->slideUp();
}
_viewList->toggleAnimated(_replaceEmoji->checked());
}
void ChatSettingsWidget::onViewList() {
@ -205,11 +201,7 @@ void ChatSettingsWidget::onDontAskDownloadPath() {
Global::SetAskDownloadPath(!_dontAskDownloadPath->checked());
Local::writeUserSettings();
#ifndef OS_WIN_STORE
if (_dontAskDownloadPath->checked()) {
_downloadPath->slideDown();
} else {
_downloadPath->slideUp();
}
_downloadPath->toggleAnimated(_dontAskDownloadPath->checked());
#endif // OS_WIN_STORE
}

View file

@ -250,11 +250,10 @@ void GeneralWidget::onRestart() {
void GeneralWidget::onUpdateAutomatically() {
cSetAutoUpdate(_updateAutomatically->checked());
Local::writeSettings();
_updateRow->toggleAnimated(cAutoUpdate());
if (cAutoUpdate()) {
_updateRow->slideDown();
Sandbox::startUpdateCheck();
} else {
_updateRow->slideUp();
Sandbox::stopUpdate();
}
}
@ -290,7 +289,6 @@ void GeneralWidget::onAutoStart() {
cSetAutoStart(_autoStart->checked());
if (cAutoStart()) {
psAutoStart(true);
_startMinimized->slideDown();
Local::writeSettings();
} else {
psAutoStart(false);
@ -299,8 +297,8 @@ void GeneralWidget::onAutoStart() {
} else {
Local::writeSettings();
}
_startMinimized->slideUp();
}
_startMinimized->toggleAnimated(cAutoStart());
}
void GeneralWidget::onStartMinimized() {

View file

@ -115,12 +115,11 @@ void InfoWidget::refreshLink() {
}
void InfoWidget::setLabeledText(object_ptr<LabeledWrap> &row, const QString &label, const TextWithEntities &textWithEntities, const TextWithEntities &shortTextWithEntities, const QString &copyText) {
if (textWithEntities.text.isEmpty()) {
row->slideUp();
} else {
auto nonEmptyText = !textWithEntities.text.isEmpty();
if (nonEmptyText) {
row->entity()->setLabeledText(label, textWithEntities, shortTextWithEntities, copyText);
row->slideDown();
}
row->toggleAnimated(nonEmptyText);
}
InfoWidget::LabeledWidget::LabeledWidget(QWidget *parent) : TWidget(parent) {

View file

@ -106,15 +106,8 @@ void NotificationsWidget::onDesktopNotifications() {
void NotificationsWidget::desktopEnabledUpdated() {
_desktopNotifications->setChecked(Global::DesktopNotify());
if (Global::DesktopNotify()) {
_showSenderName->slideDown();
if (_showSenderName->entity()->checked()) {
_showMessagePreview->slideDown();
}
} else {
_showSenderName->slideUp();
_showMessagePreview->slideUp();
}
_showSenderName->toggleAnimated(Global::DesktopNotify());
_showMessagePreview->toggleAnimated(Global::DesktopNotify() && _showSenderName->entity()->checked());
}
void NotificationsWidget::onShowSenderName() {
@ -153,11 +146,7 @@ void NotificationsWidget::onShowMessagePreview() {
}
void NotificationsWidget::viewParamUpdated() {
if (_showSenderName->entity()->checked()) {
_showMessagePreview->slideDown();
} else {
_showMessagePreview->slideUp();
}
_showMessagePreview->toggleAnimated(_showSenderName->entity()->checked());
}
void NotificationsWidget::onNativeNotifications() {
@ -170,11 +159,7 @@ void NotificationsWidget::onNativeNotifications() {
AuthSession::Current().notifications()->createManager();
if (Global::NativeNotifications()) {
_advanced->slideUp();
} else {
_advanced->slideDown();
}
_advanced->toggleAnimated(!Global::NativeNotifications());
}
void NotificationsWidget::onAdvanced() {

View file

@ -189,10 +189,8 @@ void PrivacyWidget::autoLockUpdated() {
auto value = (Global::AutoLock() % 3600) ? lng_passcode_autolock_minutes(lt_count, Global::AutoLock() / 60) : lng_passcode_autolock_hours(lt_count, Global::AutoLock() / 3600);
_autoLock->entity()->link()->setText(value);
resizeToWidth(width());
_autoLock->slideDown();
} else {
_autoLock->slideUp();
}
_autoLock->toggleAnimated(Global::LocalPasscode());
}
void PrivacyWidget::onBlockedUsers() {

View file

@ -86,19 +86,30 @@ public:
, bool scaled = false);
void showAnimated() {
_animation.fadeIn(_duration);
toggleAnimated(true);
}
void hideAnimated() {
_animation.fadeOut(_duration);
toggleAnimated(false);
}
void showFast() {
_animation.show();
if (_updateCallback) {
_updateCallback();
void toggleAnimated(bool visible) {
if (visible) {
_animation.fadeIn(_duration);
} else {
_animation.fadeOut(_duration);
}
}
void showFast() {
toggleFast(true);
}
void hideFast() {
_animation.hide();
toggleFast(false);
}
void toggleFast(bool visible) {
if (visible) {
_animation.show();
} else {
_animation.hide();
}
if (_updateCallback) {
_updateCallback();
}

View file

@ -39,7 +39,7 @@ WidgetSlideWrap<TWidget>::WidgetSlideWrap(QWidget *parent
resizeToWidth(_realSize.width());
}
void WidgetSlideWrap<TWidget>::slideUp() {
void WidgetSlideWrap<TWidget>::hideAnimated() {
if (isHidden()) {
_forceHeight = 0;
resizeToWidth(_realSize.width());
@ -53,7 +53,7 @@ void WidgetSlideWrap<TWidget>::slideUp() {
_a_height.start([this] { animationCallback(); }, _realSize.height(), 0., _duration);
}
void WidgetSlideWrap<TWidget>::slideDown() {
void WidgetSlideWrap<TWidget>::showAnimated() {
if (isHidden()) {
show();
}
@ -69,21 +69,12 @@ void WidgetSlideWrap<TWidget>::slideDown() {
_a_height.start([this] { animationCallback(); }, 0., _realSize.height(), _duration);
}
void WidgetSlideWrap<TWidget>::showFast() {
show();
void WidgetSlideWrap<TWidget>::toggleFast(bool visible) {
if (visible) show();
_a_height.finish();
_forceHeight = -1;
_forceHeight = visible ? -1 : 0;
resizeToWidth(_realSize.width());
if (_updateCallback) {
_updateCallback();
}
}
void WidgetSlideWrap<TWidget>::hideFast() {
_a_height.finish();
_forceHeight = 0;
resizeToWidth(_realSize.width());
hide();
if (!visible) hide();
if (_updateCallback) {
_updateCallback();
}

View file

@ -36,10 +36,22 @@ public:
, base::lambda<void()> updateCallback
, int duration = st::widgetSlideDuration);
void slideUp();
void slideDown();
void showFast();
void hideFast();
void showAnimated();
void hideAnimated();
void toggleAnimated(bool visible) {
if (visible) {
showAnimated();
} else {
hideAnimated();
}
}
void showFast() {
toggleFast(true);
}
void hideFast() {
toggleFast(false);
}
void toggleFast(bool visible);
void finishAnimation() {
_a_height.finish();