Skip to content

Commit

Permalink
Automatic applying of sticker height change
Browse files Browse the repository at this point in the history
  • Loading branch information
EricKotato committed Oct 10, 2019
1 parent 7393cb5 commit 4caedcb
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/core/kotato_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ bool Manager::readCustomFile() {
if (settingsStickerHeightIt != settings.constEnd()) {
const auto settingsStickerHeight = (*settingsStickerHeightIt).toInt();
if (settingsStickerHeight >= 128 || settingsStickerHeight <= 256) {
cSetStickerHeight(settingsStickerHeight);
SetStickerHeight(settingsStickerHeight);
}
}

Expand Down Expand Up @@ -246,7 +246,7 @@ void Manager::writeDefaultFile() {

settings.insert(qsl("fonts"), settingsFonts);

settings.insert(qsl("sticker_height"), cStickerHeight());
settings.insert(qsl("sticker_height"), StickerHeight());
settings.insert(qsl("big_emoji_outline"), BigEmojiOutline());
settings.insert(qsl("always_show_scheduled"), cAlwaysShowScheduled());
settings.insert(qsl("show_chat_id"), cShowChatId());
Expand Down
7 changes: 7 additions & 0 deletions Telegram/SourceFiles/history/history_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,13 @@ HistoryWidget::HistoryWidget(
});
}, lifetime());

StickerHeightChanges(
) | rpl::start_with_next([=] {
crl::on_main(this, [=] {
updateHistoryGeometry();
});
}, lifetime());

session().data().animationPlayInlineRequest(
) | rpl::start_with_next([=](not_null<HistoryItem*> item) {
if (const auto view = item->mainView()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ For license and copyright information please follow this link:
#include "history/view/media/history_view_media_common.h"
#include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_item_components.h"
#include "data/data_session.h"
#include "layout.h"
#include "facades.h"
#include "app.h"
Expand All @@ -26,13 +28,17 @@ UnwrappedMedia::UnwrappedMedia(
std::unique_ptr<Content> content)
: Media(parent)
, _content(std::move(content)) {
StickerHeightChanges(
) | rpl::start_with_next([=] {
history()->owner().requestItemViewRefresh(_parent->data());
}, _lifetime);
}

QSize UnwrappedMedia::countOptimalSize() {
_content->refreshLink();
_contentSize = NonEmptySize(DownscaledSize(
_content->size(),
{ st::maxStickerSize, cStickerHeight() }));
{ st::maxStickerSize, StickerHeight() }));
auto maxWidth = _contentSize.width();
const auto minimal = st::largeEmojiSize + 2 * st::largeEmojiOutline;
auto minHeight = std::max(_contentSize.height(), minimal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class UnwrappedMedia final : public Media {
std::unique_ptr<Content> _content;
QSize _contentSize;

rpl::lifetime _lifetime;

};

} // namespace HistoryView
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ QSize Sticker::size() {
constexpr auto kIdealStickerSize = 512;
const auto zoom = GetEmojiStickerZoom(&_document->session());
const auto convert = [&](int size) {
return int(size * cStickerHeight() * zoom / kIdealStickerSize);
return int(size * StickerHeight() * zoom / kIdealStickerSize);
};
_size = QSize(convert(_size.width()), convert(_size.height()));
} else {
_size = DownscaledSize(
_size,
{ st::maxStickerSize, cStickerHeight() });
{ st::maxStickerSize, StickerHeight() });
}
return _size;
}
Expand Down
11 changes: 10 additions & 1 deletion Telegram/SourceFiles/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,16 @@ rpl::producer<> UpdatedRecentEmoji() {
QString gMainFont, gSemiboldFont, gMonospaceFont;
bool gSemiboldFontIsBold = false;

int gStickerHeight = 128;
rpl::variable<int> gStickerHeight = 128;
void SetStickerHeight(int height) {
gStickerHeight = height;
}
int StickerHeight() {
return gStickerHeight.current();
}
rpl::producer<int> StickerHeightChanges() {
return gStickerHeight.changes();
}

rpl::variable<bool> gBigEmojiOutline = false;
void SetBigEmojiOutline(bool enabled) {
Expand Down
5 changes: 4 additions & 1 deletion Telegram/SourceFiles/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ void SetBigEmojiOutline(bool enabled);
[[nodiscard]] bool BigEmojiOutline();
[[nodiscard]] rpl::producer<bool> BigEmojiOutlineChanges();

DeclareSetting(int, StickerHeight);
void SetStickerHeight(int height);
[[nodiscard]] int StickerHeight();
[[nodiscard]] rpl::producer<int> StickerHeightChanges();

DeclareSetting(bool, AlwaysShowScheduled);
DeclareSetting(bool, ShowChatId);

Expand Down
6 changes: 3 additions & 3 deletions Telegram/SourceFiles/settings/settings_kotato.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ void SetupKotatoChats(not_null<Ui::VerticalLayout*> container) {
};
const auto updateStickerHeight = [=](int value) {
updateStickerHeightLabel(value);
cSetStickerHeight(value);
SetStickerHeight(value);
};
stickerHeightSlider->resize(st::settingsAudioVolumeSlider.seekSize);
stickerHeightSlider->setPseudoDiscrete(
129,
[](int val) { return val + 128; },
cStickerHeight(),
StickerHeight(),
updateStickerHeight);
updateStickerHeightLabel(cStickerHeight());
updateStickerHeightLabel(StickerHeight());

AddButton(
container,
Expand Down

0 comments on commit 4caedcb

Please sign in to comment.