[Option][GUI] Sticker size

This commit is contained in:
Eric Kotato 2022-08-26 15:49:10 +03:00 committed by Eric Kotato
parent 8035f02f96
commit acb0cf8c1e
8 changed files with 100 additions and 5 deletions

View file

@ -28,6 +28,9 @@
"ktg_mac_menu_show": "Show Kotatogram",
"ktg_settings_kotato": "Kotatogram Settings",
"ktg_settings_chats": "Chats",
"ktg_settings_sticker_height": "Sticker height: {pixels}px",
"ktg_settings_sticker_scale_both": "Apply to sticker width",
"ktg_settings_sticker_scale_both_about": "When enabled, sticker maximum width will be changed along with sticker height.",
"ktg_settings_emoji_outline": "Big emoji outline",
"ktg_fonts_title": "Fonts",
"ktg_settings_fonts": "Change application fonts",

View file

@ -578,6 +578,22 @@ HistoryWidget::HistoryWidget(
});
}, lifetime());
::Kotato::JsonSettings::Events(
"sticker_height"
) | rpl::start_with_next([=] {
crl::on_main(this, [=] {
updateHistoryGeometry();
});
}, lifetime());
::Kotato::JsonSettings::Events(
"sticker_scale_both"
) | 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()) {

View file

@ -7,13 +7,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "history/view/media/history_view_media_unwrapped.h"
#include "kotato/kotato_settings.h"
#include "history/view/media/history_view_media_common.h"
#include "history/view/media/history_view_sticker.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 "lottie/lottie_single_player.h"
#include "data/data_session.h"
#include "ui/cached_round_corners.h"
#include "ui/chat/chat_style.h"
#include "styles/style_chat.h"
@ -40,6 +43,17 @@ UnwrappedMedia::UnwrappedMedia(
std::unique_ptr<Content> content)
: Media(parent)
, _content(std::move(content)) {
::Kotato::JsonSettings::Events(
"sticker_height"
) | rpl::start_with_next([=] {
history()->owner().requestItemViewRefresh(_parent->data());
}, _lifetime);
::Kotato::JsonSettings::Events(
"sticker_scale_both"
) | rpl::start_with_next([=] {
history()->owner().requestItemViewRefresh(_parent->data());
}, _lifetime);
}
QSize UnwrappedMedia::countOptimalSize() {
@ -495,7 +509,7 @@ int UnwrappedMedia::calculateFullRight(const QRect &inner) const {
const auto rightActionWidth = rightActionSize
? (st::historyFastShareLeft * 2
+ rightActionSize->width())
: 0;
: st::msgMargin.left() + st::msgMargin.right();
auto fullRight = inner.x()
+ inner.width()
+ (rightAligned ? 0 : infoWidth);

View file

@ -165,6 +165,8 @@ private:
int _topAdded = 0;
bool _additionalOnTop = false;
rpl::lifetime _lifetime;
};
} // namespace HistoryView

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "history/view/media/history_view_sticker.h"
#include "kotato/kotato_settings.h"
#include "boxes/sticker_set_box.h"
#include "history/history.h"
#include "history/history_item_components.h"
@ -310,8 +311,11 @@ bool Sticker::readyToDrawAnimationFrame() {
}
QSize Sticker::Size() {
const auto side = std::min(st::maxStickerSize, kMaxSizeFixed);
return { side, side };
const auto currentStickerHeight = ::Kotato::JsonSettings::GetInt("sticker_height");
const auto currentScaleBoth = ::Kotato::JsonSettings::GetBool("sticker_scale_both");
const auto maxHeight = int(st::maxStickerSize / 256.0 * currentStickerHeight);
const auto maxWidth = currentScaleBoth ? maxHeight : st::maxStickerSize;
return { maxWidth, maxHeight };
}
QSize Sticker::Size(not_null<DocumentData*> document) {
@ -332,7 +336,9 @@ QSize Sticker::EmojiEffectSize() {
}
QSize Sticker::EmojiSize() {
const auto side = std::min(st::maxAnimatedEmojiSize, kMaxEmojiSizeFixed);
const auto currentStickerHeight = ::Kotato::JsonSettings::GetInt("sticker_height");
const auto maxHeight = int(st::maxStickerSize / 256.0 * currentStickerHeight / 2);
const auto side = std::min(maxHeight, kMaxEmojiSizeFixed);
return { side, side };
}

View file

@ -247,6 +247,13 @@ const std::map<QString, Definition, std::greater<QString>> DefinitionMap {
{ "big_emoji_outline", {
.type = SettingType::BoolSetting,
.defaultValue = true, }},
{ "sticker_height", {
.type = SettingType::IntSetting,
.defaultValue = 170,
.limitHandler = IntLimit(64, 256, 170), }},
{ "sticker_scale_both", {
.type = SettingType::BoolSetting,
.defaultValue = true, }},
};
using OldOptionKey = QString;

View file

@ -85,6 +85,53 @@ void SetupKotatoChats(
void SetupKotatoMessages(not_null<Ui::VerticalLayout*> container) {
AddSubsectionTitle(container, rktr("ktg_settings_messages"));
const auto stickerHeightLabel = container->add(
object_ptr<Ui::LabelSimple>(
container,
st::settingsAudioVolumeLabel),
st::settingsAudioVolumeLabelPadding);
const auto stickerHeightSlider = container->add(
object_ptr<Ui::MediaSlider>(
container,
st::settingsAudioVolumeSlider),
st::settingsAudioVolumeSliderPadding);
const auto updateStickerHeightLabel = [=](int value) {
const auto pixels = QString::number(value);
stickerHeightLabel->setText(
ktr("ktg_settings_sticker_height", { "pixels", pixels }));
};
const auto updateStickerHeight = [=](int value) {
updateStickerHeightLabel(value);
::Kotato::JsonSettings::Set("sticker_height", value);
::Kotato::JsonSettings::Write();
};
stickerHeightSlider->resize(st::settingsAudioVolumeSlider.seekSize);
stickerHeightSlider->setPseudoDiscrete(
193,
[](int val) { return val + 64; },
::Kotato::JsonSettings::GetInt("sticker_height"),
updateStickerHeight);
updateStickerHeightLabel(::Kotato::JsonSettings::GetInt("sticker_height"));
container->add(
object_ptr<Ui::Checkbox>(
container,
ktr("ktg_settings_sticker_scale_both"),
::Kotato::JsonSettings::GetBool("sticker_scale_both"),
st::settingsCheckbox),
st::settingsCheckboxPadding
)->checkedChanges(
) | rpl::filter([](bool checked) {
return (checked != ::Kotato::JsonSettings::GetBool("sticker_scale_both"));
}) | rpl::start_with_next([](bool checked) {
::Kotato::JsonSettings::Set("sticker_scale_both", checked);
::Kotato::JsonSettings::Write();
}, container->lifetime());
AddSkip(container);
AddDividerText(container, rktr("ktg_settings_sticker_scale_both_about"));
AddSkip(container);
SettingsMenuJsonSwitch(ktg_settings_emoji_outline, big_emoji_outline);
AddSkip(container);

View file

@ -38,7 +38,7 @@ defaultMessageBar: MessageBar {
minPhotoSize: 100px;
minVideoSize: 160px;
maxMediaSize: 430px;
maxStickerSize: 224px;
maxStickerSize: 256px;
maxAnimatedEmojiSize: 112px;
maxGifSize: 320px;
maxVideoMessageSize: 240px;