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(); updateInnerVisibleTopBottom();
auto top = _scroll->scrollTop(); auto top = _scroll->scrollTop();
if (top > 0 || _innerTopSkip > 0) { _topShadow->toggleFast(top > 0 || _innerTopSkip > 0);
_topShadow->showFast(); _bottomShadow->toggleFast(top < _scroll->scrollTopMax());
} else {
_topShadow->hideFast();
}
if (top < _scroll->scrollTopMax()) {
_bottomShadow->showFast();
} else {
_bottomShadow->hideFast();
}
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -250,11 +250,10 @@ void GeneralWidget::onRestart() {
void GeneralWidget::onUpdateAutomatically() { void GeneralWidget::onUpdateAutomatically() {
cSetAutoUpdate(_updateAutomatically->checked()); cSetAutoUpdate(_updateAutomatically->checked());
Local::writeSettings(); Local::writeSettings();
_updateRow->toggleAnimated(cAutoUpdate());
if (cAutoUpdate()) { if (cAutoUpdate()) {
_updateRow->slideDown();
Sandbox::startUpdateCheck(); Sandbox::startUpdateCheck();
} else { } else {
_updateRow->slideUp();
Sandbox::stopUpdate(); Sandbox::stopUpdate();
} }
} }
@ -290,7 +289,6 @@ void GeneralWidget::onAutoStart() {
cSetAutoStart(_autoStart->checked()); cSetAutoStart(_autoStart->checked());
if (cAutoStart()) { if (cAutoStart()) {
psAutoStart(true); psAutoStart(true);
_startMinimized->slideDown();
Local::writeSettings(); Local::writeSettings();
} else { } else {
psAutoStart(false); psAutoStart(false);
@ -299,8 +297,8 @@ void GeneralWidget::onAutoStart() {
} else { } else {
Local::writeSettings(); Local::writeSettings();
} }
_startMinimized->slideUp();
} }
_startMinimized->toggleAnimated(cAutoStart());
} }
void GeneralWidget::onStartMinimized() { 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) { void InfoWidget::setLabeledText(object_ptr<LabeledWrap> &row, const QString &label, const TextWithEntities &textWithEntities, const TextWithEntities &shortTextWithEntities, const QString &copyText) {
if (textWithEntities.text.isEmpty()) { auto nonEmptyText = !textWithEntities.text.isEmpty();
row->slideUp(); if (nonEmptyText) {
} else {
row->entity()->setLabeledText(label, textWithEntities, shortTextWithEntities, copyText); row->entity()->setLabeledText(label, textWithEntities, shortTextWithEntities, copyText);
row->slideDown();
} }
row->toggleAnimated(nonEmptyText);
} }
InfoWidget::LabeledWidget::LabeledWidget(QWidget *parent) : TWidget(parent) { InfoWidget::LabeledWidget::LabeledWidget(QWidget *parent) : TWidget(parent) {

View File

@ -106,15 +106,8 @@ void NotificationsWidget::onDesktopNotifications() {
void NotificationsWidget::desktopEnabledUpdated() { void NotificationsWidget::desktopEnabledUpdated() {
_desktopNotifications->setChecked(Global::DesktopNotify()); _desktopNotifications->setChecked(Global::DesktopNotify());
if (Global::DesktopNotify()) { _showSenderName->toggleAnimated(Global::DesktopNotify());
_showSenderName->slideDown(); _showMessagePreview->toggleAnimated(Global::DesktopNotify() && _showSenderName->entity()->checked());
if (_showSenderName->entity()->checked()) {
_showMessagePreview->slideDown();
}
} else {
_showSenderName->slideUp();
_showMessagePreview->slideUp();
}
} }
void NotificationsWidget::onShowSenderName() { void NotificationsWidget::onShowSenderName() {
@ -153,11 +146,7 @@ void NotificationsWidget::onShowMessagePreview() {
} }
void NotificationsWidget::viewParamUpdated() { void NotificationsWidget::viewParamUpdated() {
if (_showSenderName->entity()->checked()) { _showMessagePreview->toggleAnimated(_showSenderName->entity()->checked());
_showMessagePreview->slideDown();
} else {
_showMessagePreview->slideUp();
}
} }
void NotificationsWidget::onNativeNotifications() { void NotificationsWidget::onNativeNotifications() {
@ -170,11 +159,7 @@ void NotificationsWidget::onNativeNotifications() {
AuthSession::Current().notifications()->createManager(); AuthSession::Current().notifications()->createManager();
if (Global::NativeNotifications()) { _advanced->toggleAnimated(!Global::NativeNotifications());
_advanced->slideUp();
} else {
_advanced->slideDown();
}
} }
void NotificationsWidget::onAdvanced() { 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); 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); _autoLock->entity()->link()->setText(value);
resizeToWidth(width()); resizeToWidth(width());
_autoLock->slideDown();
} else {
_autoLock->slideUp();
} }
_autoLock->toggleAnimated(Global::LocalPasscode());
} }
void PrivacyWidget::onBlockedUsers() { void PrivacyWidget::onBlockedUsers() {

View File

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

View File

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

View File

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