Show nice padded code blocks.

This commit is contained in:
John Preston 2023-10-13 10:04:29 +04:00
parent dd692f2d26
commit 0e79bd3d12
47 changed files with 187 additions and 46 deletions

View file

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_calls.h" #include "styles/style_calls.h"
#include <QtCore/QDateTime> #include <QtCore/QDateTime>
#include <QtCore/QLocale>
namespace Calls::Group::Ui { namespace Calls::Group::Ui {

View file

@ -787,7 +787,7 @@ void MessageLinksParser::parse() {
} }
offset = matchOffset = p - start; offset = matchOffset = p - start;
} }
processTagsBefore(QFIXED_MAX); processTagsBefore(Ui::kQFixedMax);
apply(text, ranges); apply(text, ranges);
} }

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "countries/countries_instance.h" #include "countries/countries_instance.h"
#include "base/qt/qt_common_adapters.h" #include "base/qt/qt_common_adapters.h"
#include "base/qt/qt_string_view.h"
namespace Countries { namespace Countries {
namespace { namespace {

View file

@ -69,7 +69,7 @@ void ApplyPeerCloudDraft(
textWithTags, textWithTags,
replyTo, replyTo,
topicRootId, topicRootId,
MessageCursor(QFIXED_MAX, QFIXED_MAX, QFIXED_MAX), MessageCursor(Ui::kQFixedMax, Ui::kQFixedMax, Ui::kQFixedMax),
(draft.is_no_webpage() (draft.is_no_webpage()
? Data::PreviewState::Cancelled ? Data::PreviewState::Cancelled
: Data::PreviewState::Allowed)); : Data::PreviewState::Allowed));

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_statistics_chart.h" #include "data/data_statistics_chart.h"
#include <QtCore/QDateTime> #include <QtCore/QDateTime>
#include <QtCore/QLocale>
namespace Data { namespace Data {

View file

@ -102,7 +102,7 @@ void MessageCursor::fillFrom(not_null<const Ui::InputField*> field) {
position = cursor.position(); position = cursor.position();
anchor = cursor.anchor(); anchor = cursor.anchor();
const auto top = field->scrollTop().current(); const auto top = field->scrollTop().current();
scroll = (top != field->scrollTopMax()) ? top : QFIXED_MAX; scroll = (top != field->scrollTopMax()) ? top : Ui::kQFixedMax;
} }
void MessageCursor::applyTo(not_null<Ui::InputField*> field) { void MessageCursor::applyTo(not_null<Ui::InputField*> field) {

View file

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "ui/text/text.h" // For QFIXED_MAX #include "ui/text/text.h" // Ui::kQFixedMax.
#include "data/data_peer_id.h" #include "data/data_peer_id.h"
#include "data/data_msg_id.h" #include "data/data_msg_id.h"
#include "base/qt/qt_compare.h" #include "base/qt/qt_compare.h"
@ -196,7 +196,7 @@ struct MessageCursor {
int position = 0; int position = 0;
int anchor = 0; int anchor = 0;
int scroll = QFIXED_MAX; int scroll = Ui::kQFixedMax;
}; };

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/qt/qt_key_modifiers.h" #include "base/qt/qt_key_modifiers.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "ui/effects/ripple_animation.h" #include "ui/effects/ripple_animation.h"
#include "ui/effects/spoiler_mess.h"
#include "ui/image/image.h" #include "ui/image/image.h"
#include "ui/toast/toast.h" #include "ui/toast/toast.h"
#include "ui/text/text_options.h" #include "ui/text/text_options.h"
@ -260,6 +261,17 @@ void HistoryMessageForwarded::create(const HistoryMessageVia *via) const {
} }
} }
HistoryMessageReply::HistoryMessageReply() = default;
HistoryMessageReply &HistoryMessageReply::operator=(
HistoryMessageReply &&other) = default;
HistoryMessageReply::~HistoryMessageReply() {
// clearData() should be called by holder.
Expects(replyToMsg.empty());
Expects(replyToVia == nullptr);
}
bool HistoryMessageReply::updateData( bool HistoryMessageReply::updateData(
not_null<HistoryItem*> holder, not_null<HistoryItem*> holder,
bool force) { bool force) {
@ -311,7 +323,7 @@ bool HistoryMessageReply::updateData(
.customEmojiRepaint = repaint, .customEmojiRepaint = repaint,
}; };
replyToText.setMarkedText( replyToText.setMarkedText(
st::messageTextStyle, st::defaultTextStyle,
(replyToMsg (replyToMsg
? replyToMsg->inReplyText() ? replyToMsg->inReplyText()
: replyToStory->inReplyText()), : replyToStory->inReplyText()),
@ -333,7 +345,8 @@ bool HistoryMessageReply::updateData(
if (replyToMsg) { if (replyToMsg) {
const auto peer = replyToMsg->history()->peer; const auto peer = replyToMsg->history()->peer;
replyToColorKey = (!holder->out() replyToColorKey = (!holder->out()
&& (peer->isMegagroup() || peer->isChat())) && (peer->isMegagroup() || peer->isChat())
&& replyToMsg->from()->isUser())
? replyToMsg->from()->id ? replyToMsg->from()->id
: PeerId(0); : PeerId(0);
} else { } else {

View file

@ -22,6 +22,7 @@ namespace Ui {
struct ChatPaintContext; struct ChatPaintContext;
class ChatStyle; class ChatStyle;
struct PeerUserpicView; struct PeerUserpicView;
class SpoilerAnimation;
} // namespace Ui } // namespace Ui
namespace Data { namespace Data {
@ -227,17 +228,13 @@ private:
struct HistoryMessageReply struct HistoryMessageReply
: public RuntimeComponent<HistoryMessageReply, HistoryItem> { : public RuntimeComponent<HistoryMessageReply, HistoryItem> {
HistoryMessageReply() = default; HistoryMessageReply();
HistoryMessageReply(const HistoryMessageReply &other) = delete; HistoryMessageReply(const HistoryMessageReply &other) = delete;
HistoryMessageReply(HistoryMessageReply &&other) = delete; HistoryMessageReply(HistoryMessageReply &&other) = delete;
HistoryMessageReply &operator=( HistoryMessageReply &operator=(
const HistoryMessageReply &other) = delete; const HistoryMessageReply &other) = delete;
HistoryMessageReply &operator=(HistoryMessageReply &&other) = default; HistoryMessageReply &operator=(HistoryMessageReply &&other);
~HistoryMessageReply() { ~HistoryMessageReply();
// clearData() should be called by holder.
Expects(replyToMsg.empty());
Expects(replyToVia == nullptr);
}
static constexpr auto kBarAlpha = 230. / 255.; static constexpr auto kBarAlpha = 230. / 255.;

View file

@ -38,6 +38,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/chat/message_bar.h" #include "ui/chat/message_bar.h"
#include "ui/chat/attach/attach_send_files_way.h" #include "ui/chat/attach/attach_send_files_way.h"
#include "ui/chat/choose_send_as.h" #include "ui/chat/choose_send_as.h"
#include "ui/effects/spoiler_mess.h"
#include "ui/image/image.h" #include "ui/image/image.h"
#include "ui/painter.h" #include "ui/painter.h"
#include "ui/power_saving.h" #include "ui/power_saving.h"
@ -1774,7 +1775,7 @@ bool HistoryWidget::notify_switchInlineBotButtonReceived(
MessageCursor cursor = { MessageCursor cursor = {
int(textWithTags.text.size()), int(textWithTags.text.size()),
int(textWithTags.text.size()), int(textWithTags.text.size()),
QFIXED_MAX, Ui::kQFixedMax,
}; };
_history->setLocalDraft(std::make_unique<Data::Draft>( _history->setLocalDraft(std::make_unique<Data::Draft>(
textWithTags, textWithTags,
@ -7184,7 +7185,7 @@ void HistoryWidget::editMessage(not_null<HistoryItem*> item) {
const auto cursor = MessageCursor { const auto cursor = MessageCursor {
int(editData.text.size()), int(editData.text.size()),
int(editData.text.size()), int(editData.text.size()),
QFIXED_MAX Ui::kQFixedMax
}; };
const auto previewPage = [&]() -> WebPageData* { const auto previewPage = [&]() -> WebPageData* {
if (const auto media = item->media()) { if (const auto media = item->media()) {
@ -7486,7 +7487,7 @@ void HistoryWidget::updatePreview() {
Ui::NameTextOptions()); Ui::NameTextOptions());
auto linkText = QStringView(_previewLinks).split(' ').at(0).toString(); auto linkText = QStringView(_previewLinks).split(' ').at(0).toString();
_previewDescription.setText( _previewDescription.setText(
st::messageTextStyle, st::defaultTextStyle,
linkText, linkText,
Ui::DialogTextOptions()); Ui::DialogTextOptions());
@ -7507,7 +7508,7 @@ void HistoryWidget::updatePreview() {
preview.title, preview.title,
Ui::NameTextOptions()); Ui::NameTextOptions());
_previewDescription.setText( _previewDescription.setText(
st::messageTextStyle, st::defaultTextStyle,
preview.description, preview.description,
Ui::DialogTextOptions()); Ui::DialogTextOptions());
} }
@ -7762,7 +7763,7 @@ void HistoryWidget::updateReplyEditText(not_null<HistoryItem*> item) {
.customEmojiRepaint = [=] { updateField(); }, .customEmojiRepaint = [=] { updateField(); },
}; };
_replyEditMsgText.setMarkedText( _replyEditMsgText.setMarkedText(
st::messageTextStyle, st::defaultTextStyle,
item->inReplyText(), item->inReplyText(),
Ui::DialogTextOptions(), Ui::DialogTextOptions(),
context); context);

View file

@ -68,6 +68,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/controls/send_as_button.h" #include "ui/controls/send_as_button.h"
#include "ui/controls/silent_toggle.h" #include "ui/controls/silent_toggle.h"
#include "ui/chat/choose_send_as.h" #include "ui/chat/choose_send_as.h"
#include "ui/effects/spoiler_mess.h"
#include "window/window_adaptive.h" #include "window/window_adaptive.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "mainwindow.h" #include "mainwindow.h"
@ -2883,7 +2884,7 @@ void ComposeControls::editMessage(not_null<HistoryItem*> item) {
const auto cursor = MessageCursor{ const auto cursor = MessageCursor{
int(editData.text.size()), int(editData.text.size()),
int(editData.text.size()), int(editData.text.size()),
QFIXED_MAX Ui::kQFixedMax
}; };
const auto previewPage = [&]() -> WebPageData* { const auto previewPage = [&]() -> WebPageData* {
if (const auto media = item->media()) { if (const auto media = item->media()) {

View file

@ -216,7 +216,7 @@ void ForwardPanel::updateTexts() {
.customEmojiRepaint = _repaint, .customEmojiRepaint = _repaint,
}; };
_text.setMarkedText( _text.setMarkedText(
st::messageTextStyle, st::defaultTextStyle,
text, text,
Ui::DialogTextOptions(), Ui::DialogTextOptions(),
context); context);

View file

@ -1622,6 +1622,8 @@ void Message::paintText(
.position = trect.topLeft(), .position = trect.topLeft(),
.availableWidth = trect.width(), .availableWidth = trect.width(),
.palette = &stm->textPalette, .palette = &stm->textPalette,
.pre = stm->preBlockCache.get(),
.blockquote = stm->blockquoteBlockCache.get(),
.colors = context.st->highlightColors(), .colors = context.st->highlightColors(),
.spoiler = Ui::Text::DefaultSpoilerCache(), .spoiler = Ui::Text::DefaultSpoilerCache(),
.now = context.now, .now = context.now,

View file

@ -748,6 +748,8 @@ void Document::draw(
.position = { st::msgPadding.left(), captiontop }, .position = { st::msgPadding.left(), captiontop },
.availableWidth = captionw, .availableWidth = captionw,
.palette = &stm->textPalette, .palette = &stm->textPalette,
.pre = stm->preBlockCache.get(),
.blockquote = stm->blockquoteBlockCache.get(),
.colors = context.st->highlightColors(), .colors = context.st->highlightColors(),
.spoiler = Ui::Text::DefaultSpoilerCache(), .spoiler = Ui::Text::DefaultSpoilerCache(),
.now = context.now, .now = context.now,

View file

@ -235,6 +235,8 @@ void ExtendedPreview::draw(Painter &p, const PaintContext &context) const {
painty + painth + st::mediaCaptionSkip), painty + painth + st::mediaCaptionSkip),
.availableWidth = captionw, .availableWidth = captionw,
.palette = &stm->textPalette, .palette = &stm->textPalette,
.pre = stm->preBlockCache.get(),
.blockquote = stm->blockquoteBlockCache.get(),
.colors = context.st->highlightColors(), .colors = context.st->highlightColors(),
.spoiler = Ui::Text::DefaultSpoilerCache(), .spoiler = Ui::Text::DefaultSpoilerCache(),
.now = context.now, .now = context.now,

View file

@ -709,6 +709,8 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
.position = QPoint(st::msgPadding.left(), top), .position = QPoint(st::msgPadding.left(), top),
.availableWidth = captionw, .availableWidth = captionw,
.palette = &stm->textPalette, .palette = &stm->textPalette,
.pre = stm->preBlockCache.get(),
.blockquote = stm->blockquoteBlockCache.get(),
.colors = context.st->highlightColors(), .colors = context.st->highlightColors(),
.spoiler = Ui::Text::DefaultSpoilerCache(), .spoiler = Ui::Text::DefaultSpoilerCache(),
.now = context.now, .now = context.now,

View file

@ -14,6 +14,10 @@ namespace Stickers {
struct LargeEmojiImage; struct LargeEmojiImage;
} // namespace Stickers } // namespace Stickers
namespace Ui::Text {
class CustomEmoji;
} // namespace Ui::Text
namespace HistoryView { namespace HistoryView {
using LargeEmojiMedia = std::variant< using LargeEmojiMedia = std::variant<

View file

@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/item_text_options.h" #include "ui/item_text_options.h"
#include "ui/chat/chat_style.h" #include "ui/chat/chat_style.h"
#include "ui/chat/message_bubble.h" #include "ui/chat/message_bubble.h"
#include "ui/effects/spoiler_mess.h"
#include "ui/image/image_prepare.h" #include "ui/image/image_prepare.h"
#include "ui/power_saving.h" #include "ui/power_saving.h"
#include "core/ui_integration.h" #include "core/ui_integration.h"

View file

@ -367,6 +367,9 @@ void GroupedMedia::draw(Painter &p, const PaintContext &context) const {
captiony), captiony),
.availableWidth = captionw, .availableWidth = captionw,
.palette = &stm->textPalette, .palette = &stm->textPalette,
.pre = stm->preBlockCache.get(),
.blockquote = stm->blockquoteBlockCache.get(),
.colors = context.st->highlightColors(),
.spoiler = Ui::Text::DefaultSpoilerCache(), .spoiler = Ui::Text::DefaultSpoilerCache(),
.now = context.now, .now = context.now,
.pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat),

View file

@ -10,6 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/chat/message_bubble.h" #include "ui/chat/message_bubble.h"
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
namespace Ui {
class SpoilerAnimation;
} // namespace Ui
namespace HistoryView { namespace HistoryView {
struct MediaSpoiler { struct MediaSpoiler {

View file

@ -405,6 +405,8 @@ void Photo::draw(Painter &p, const PaintContext &context) const {
.position = QPoint(st::msgPadding.left(), top), .position = QPoint(st::msgPadding.left(), top),
.availableWidth = captionw, .availableWidth = captionw,
.palette = &stm->textPalette, .palette = &stm->textPalette,
.pre = stm->preBlockCache.get(),
.blockquote = stm->blockquoteBlockCache.get(),
.colors = context.st->highlightColors(), .colors = context.st->highlightColors(),
.spoiler = Ui::Text::DefaultSpoilerCache(), .spoiler = Ui::Text::DefaultSpoilerCache(),
.now = context.now, .now = context.now,

View file

@ -20,6 +20,10 @@ struct ReactionFlyAnimationArgs;
class ReactionFlyAnimation; class ReactionFlyAnimation;
} // namespace Ui } // namespace Ui
namespace Ui::Text {
class CustomEmoji;
} // namespace Ui::Text
namespace HistoryView { namespace HistoryView {
using PaintContext = Ui::ChatPaintContext; using PaintContext = Ui::ChatPaintContext;
class Message; class Message;

View file

@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "ui/text/text_custom_emoji.h" // Ui::Text::CustomEmojiFactory.
namespace Ui { namespace Ui {
enum class WhoReadType; enum class WhoReadType;
} // namespace Ui } // namespace Ui

View file

@ -76,6 +76,8 @@ Badge::Badge(
}, _lifetime); }, _lifetime);
} }
Badge::~Badge() = default;
Ui::RpWidget *Badge::widget() const { Ui::RpWidget *Badge::widget() const {
return _view.data(); return _view.data();
} }

View file

@ -27,6 +27,10 @@ class RpWidget;
class AbstractButton; class AbstractButton;
} // namespace Ui } // namespace Ui
namespace Ui::Text {
class CustomEmoji;
} // namespace Ui::Text
namespace Info::Profile { namespace Info::Profile {
class EmojiStatusPanel; class EmojiStatusPanel;
@ -69,6 +73,8 @@ public:
base::flags<BadgeType> allowed base::flags<BadgeType> allowed
= base::flags<BadgeType>::from_raw(-1)); = base::flags<BadgeType>::from_raw(-1));
~Badge();
[[nodiscard]] Ui::RpWidget *widget() const; [[nodiscard]] Ui::RpWidget *widget() const;
void setPremiumClickCallback(Fn<void()> callback); void setPremiumClickCallback(Fn<void()> callback);

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "ui/text/text.h" #include "ui/text/text.h"
#include "base/qt/qt_common_adapters.h" #include "base/qt/qt_common_adapters.h"
#include "base/qt/qt_string_view.h"
namespace Lang { namespace Lang {
namespace { namespace {

View file

@ -596,7 +596,7 @@ bool MainWidget::shareUrl(
const auto cursor = MessageCursor{ const auto cursor = MessageCursor{
int(url.size()) + 1, int(url.size()) + 1,
int(url.size()) + 1 + int(text.size()), int(url.size()) + 1 + int(text.size()),
QFIXED_MAX Ui::kQFixedMax
}; };
const auto history = thread->owningHistory(); const auto history = thread->owningHistory();
const auto topicRootId = thread->topicRootId(); const auto topicRootId = thread->topicRootId();

View file

@ -346,6 +346,8 @@ Photo::Photo(
} }
} }
Photo::~Photo() = default;
void Photo::initDimensions() { void Photo::initDimensions() {
_maxw = 2 * st::overviewPhotoMinSize; _maxw = 2 * st::overviewPhotoMinSize;
_minh = _story ? qRound(_maxw * kStoryRatio) : _maxw; _minh = _story ? qRound(_maxw * kStoryRatio) : _maxw;

View file

@ -195,6 +195,7 @@ public:
not_null<HistoryItem*> parent, not_null<HistoryItem*> parent,
not_null<PhotoData*> photo, not_null<PhotoData*> photo,
MediaOptions options); MediaOptions options);
~Photo();
void initDimensions() override; void initDimensions() override;
int32 resizeGetHeight(int32 width) override; int32 resizeGetHeight(int32 width) override;

View file

@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
#include <QtGui/QWindow> #include <QtGui/QWindow>
#include <QtGui/QScreen> #include <QtGui/QScreen>
#include <QtCore/QOperatingSystemVersion>
#include <Shobjidl.h> #include <Shobjidl.h>
#include <shellapi.h> #include <shellapi.h>

View file

@ -73,6 +73,7 @@ private:
void validateShadowCache(); void validateShadowCache();
[[nodiscard]] int scaled(int value) const; [[nodiscard]] int scaled(int value) const;
[[nodiscard]] QPoint scaled(QPoint value) const;
[[nodiscard]] QMargins scaled(QMargins value) const; [[nodiscard]] QMargins scaled(QMargins value) const;
[[nodiscard]] style::font scaled( [[nodiscard]] style::font scaled(
const style::font &value, int size) const; const style::font &value, int size) const;
@ -307,6 +308,10 @@ int Preview::scaled(int value) const {
return style::ConvertScale(value, _scale); return style::ConvertScale(value, _scale);
} }
QPoint Preview::scaled(QPoint value) const {
return { scaled(value.x()), scaled(value.y()) };
}
QMargins Preview::scaled(QMargins value) const { QMargins Preview::scaled(QMargins value) const {
return { return {
scaled(value.left()), scaled(value.left()),
@ -328,7 +333,11 @@ style::TextStyle Preview::scaled(
.font = scaled(value.font, fontSize), .font = scaled(value.font, fontSize),
.linkUnderline = value.linkUnderline, .linkUnderline = value.linkUnderline,
.blockPadding = scaled(value.blockPadding), .blockPadding = scaled(value.blockPadding),
.blockVerticalSkip = scaled(value.blockVerticalSkip),
.blockHeader = scaled(value.blockHeader),
.blockHeaderPosition = scaled(value.blockHeaderPosition),
.blockOutline = scaled(value.blockOutline), .blockOutline = scaled(value.blockOutline),
.blockRadius = scaled(value.blockRadius),
.preScrollable = value.preScrollable, .preScrollable = value.preScrollable,
.lineHeight = scaled(value.lineHeight), .lineHeight = scaled(value.lineHeight),
}; };

View file

@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_statistics.h" #include "styles/style_statistics.h"
#include <QtCore/QDateTime> #include <QtCore/QDateTime>
#include <QtCore/QLocale>
namespace Statistic { namespace Statistic {
namespace { namespace {

View file

@ -109,29 +109,30 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <rpl/rpl.h> #include <rpl/rpl.h>
#include <crl/crl.h> #include <crl/crl.h>
#include "base/variant.h"
#include "base/optional.h"
#include "base/algorithm.h" #include "base/algorithm.h"
#include "base/invoke_queued.h" #include "base/basic_types.h"
#include "base/flat_set.h" #include "base/flat_set.h"
#include "base/flat_map.h" #include "base/flat_map.h"
#include "base/invoke_queued.h"
#include "base/optional.h"
#include "base/variant.h"
#include "base/weak_ptr.h" #include "base/weak_ptr.h"
#include "base/basic_types.h"
#include "logs.h"
#include "core/utils.h"
#include "config.h"
#include "scheme.h" #include "scheme.h"
#include "mtproto/type_utils.h" #include "mtproto/type_utils.h"
#include "ui/image/image_location.h"
#include "ui/style/style_core.h" #include "ui/style/style_core.h"
#include "ui/text/text.h"
#include "ui/arc_angles.h"
#include "ui/emoji_config.h"
#include "styles/palette.h" #include "styles/palette.h"
#include "styles/style_basic.h" #include "styles/style_basic.h"
#include "ui/arc_angles.h" #include "core/utils.h"
#include "ui/image/image_location.h" #include "logs.h"
#include "ui/text/text.h" #include "config.h"
#include "data/data_types.h" #include "data/data_types.h"

View file

@ -1272,7 +1272,7 @@ void Account::readDraftCursors(PeerId peerId, Data::HistoryDrafts &map) {
: keysOld : keysOld
? Data::DraftKey::FromSerializedOld(keyValueOld) ? Data::DraftKey::FromSerializedOld(keyValueOld)
: Data::DraftKey::Local(0); : Data::DraftKey::Local(0);
qint32 position = 0, anchor = 0, scroll = QFIXED_MAX; qint32 position = 0, anchor = 0, scroll = Ui::kQFixedMax;
draft.stream >> position >> anchor >> scroll; draft.stream >> position >> anchor >> scroll;
if (const auto i = map.find(key); i != end(map)) { if (const auto i = map.find(key); i != end(map)) {
i->second->cursor = MessageCursor(position, anchor, scroll); i->second->cursor = MessageCursor(position, anchor, scroll);
@ -1285,8 +1285,8 @@ void Account::readDraftCursorsLegacy(
details::FileReadDescriptor &draft, details::FileReadDescriptor &draft,
quint64 draftPeerSerialized, quint64 draftPeerSerialized,
Data::HistoryDrafts &map) { Data::HistoryDrafts &map) {
qint32 localPosition = 0, localAnchor = 0, localScroll = QFIXED_MAX; qint32 localPosition = 0, localAnchor = 0, localScroll = Ui::kQFixedMax;
qint32 editPosition = 0, editAnchor = 0, editScroll = QFIXED_MAX; qint32 editPosition = 0, editAnchor = 0, editScroll = Ui::kQFixedMax;
draft.stream >> localPosition >> localAnchor >> localScroll; draft.stream >> localPosition >> localAnchor >> localScroll;
if (!draft.stream.atEnd()) { if (!draft.stream.atEnd()) {
draft.stream >> editPosition >> editAnchor >> editScroll; draft.stream >> editPosition >> editAnchor >> editScroll;

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/chat/attach/attach_abstract_single_preview.h" #include "ui/chat/attach/attach_abstract_single_preview.h"
#include "ui/chat/attach/attach_controls.h" #include "ui/chat/attach/attach_controls.h"
#include "ui/chat/attach/attach_send_files_way.h" #include "ui/chat/attach/attach_send_files_way.h"
#include "ui/effects/spoiler_mess.h"
#include "ui/abstract_button.h" #include "ui/abstract_button.h"
namespace style { namespace style {

View file

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/chat/attach/attach_album_thumbnail.h" #include "ui/chat/attach/attach_album_thumbnail.h"
#include "ui/chat/attach/attach_prepare.h" #include "ui/chat/attach/attach_prepare.h"
#include "ui/effects/spoiler_mess.h"
#include "ui/widgets/popup_menu.h" #include "ui/widgets/popup_menu.h"
#include "ui/painter.h" #include "ui/painter.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"

View file

@ -40,7 +40,15 @@ msgDateDelta: point(2px, 5px);
msgDateImgDelta: 4px; msgDateImgDelta: 4px;
msgDateImgPadding: point(8px, 2px); msgDateImgPadding: point(8px, 2px);
messageTextStyle: defaultTextStyle; messageTextStyle: TextStyle(defaultTextStyle) {
blockPadding: margins(10px, 4px, 6px, 4px);
blockVerticalSkip: 4px;
blockHeader: 20px;
blockHeaderPosition: point(10px, 2px);
blockOutline: 3px;
blockRadius: 5px;
preScrollable: true;
}
msgDateTextStyle: defaultTextStyle; msgDateTextStyle: defaultTextStyle;
serviceTextPalette: TextPalette(defaultTextPalette) { serviceTextPalette: TextPalette(defaultTextPalette) {
linkFg: msgServiceFg; linkFg: msgServiceFg;

View file

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/chat/chat_theme.h" #include "ui/chat/chat_theme.h"
#include "ui/image/image_prepare.h" // ImageRoundRadius #include "ui/image/image_prepare.h" // ImageRoundRadius
#include "ui/color_contrast.h"
#include "ui/painter.h" #include "ui/painter.h"
#include "ui/ui_utility.h" #include "ui/ui_utility.h"
#include "styles/style_chat.h" #include "styles/style_chat.h"
@ -28,6 +29,39 @@ void EnsureCorners(
} }
} }
void EnsureBlockquoteCache(
std::unique_ptr<Text::BlockPaintCache> &cache,
const style::color &color) {
if (cache) {
return;
}
cache = std::make_unique<Text::BlockPaintCache>();
cache->bg = color->c;
cache->bg.setAlphaF(0.12);
cache->outline = color->c;
cache->outline.setAlphaF(0.9);
}
void EnsurePreCache(
std::unique_ptr<Text::BlockPaintCache> &cache,
const style::color &color,
Fn<std::optional<QColor>()> bgOverride) {
if (cache) {
return;
}
cache = std::make_unique<Text::BlockPaintCache>();
const auto bg = bgOverride();
cache->bg = bg.value_or(color->c);
if (!bg) {
cache->bg.setAlphaF(0.12);
}
cache->outline = color->c;
cache->outline.setAlphaF(0.9);
cache->withHeader = true;
cache->header = color->c;
cache->header.setAlphaF(0.25);
}
} // namespace } // namespace
not_null<const MessageStyle*> ChatPaintContext::messageStyle() const { not_null<const MessageStyle*> ChatPaintContext::messageStyle() const {
@ -487,6 +521,8 @@ void ChatStyle::assignPalette(not_null<const style::palette*> palette) {
for (auto &style : _messageStyles) { for (auto &style : _messageStyles) {
style.msgBgCornersSmall = {}; style.msgBgCornersSmall = {};
style.msgBgCornersLarge = {}; style.msgBgCornersLarge = {};
style.blockquoteBlockCache = nullptr;
style.preBlockCache = nullptr;
} }
for (auto &style : _imageStyles) { for (auto &style : _imageStyles) {
style.msgDateImgBgCorners = {}; style.msgDateImgBgCorners = {};
@ -541,6 +577,23 @@ const MessageStyle &ChatStyle::messageStyle(bool outbg, bool selected) const {
BubbleRadiusLarge(), BubbleRadiusLarge(),
result.msgBg, result.msgBg,
&result.msgShadow); &result.msgShadow);
EnsureBlockquoteCache(
result.blockquoteBlockCache,
result.msgReplyBarColor);
const auto preBgOverride = [&] {
const auto withBg = [&](const QColor &color) {
return Ui::CountContrast(windowBg()->c, color);
};
const auto dark = (withBg({ 0, 0, 0 }) < withBg({ 255, 255, 255 }));
return dark ? QColor(0, 0, 0, 192) : std::optional<QColor>();
};
EnsurePreCache(
result.preBlockCache,
(selected
? result.textPalette.selectMonoFg
: result.textPalette.monoFg),
preBgOverride);
return result; return result;
} }

View file

@ -76,6 +76,8 @@ struct MessageStyle {
style::icon historyPollChoiceRight = { Qt::Uninitialized }; style::icon historyPollChoiceRight = { Qt::Uninitialized };
style::icon historyTranscribeIcon = { Qt::Uninitialized }; style::icon historyTranscribeIcon = { Qt::Uninitialized };
style::icon historyTranscribeHide = { Qt::Uninitialized }; style::icon historyTranscribeHide = { Qt::Uninitialized };
std::unique_ptr<Text::BlockPaintCache> blockquoteBlockCache;
std::unique_ptr<Text::BlockPaintCache> preBlockCache;
}; };

View file

@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/palette.h" #include "styles/palette.h"
#include <QtGui/QtEvents> #include <QtGui/QtEvents>
#include <QtCore/QLocale>
namespace Ui { namespace Ui {

View file

@ -7,8 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "ui/chat/message_bar.h" #include "ui/chat/message_bar.h"
#include "ui/text/text_options.h" #include "ui/effects/spoiler_mess.h"
#include "ui/image/image_prepare.h" #include "ui/image/image_prepare.h"
#include "ui/text/text_options.h"
#include "ui/painter.h" #include "ui/painter.h"
#include "ui/power_saving.h" #include "ui/power_saving.h"
#include "styles/style_chat.h" #include "styles/style_chat.h"

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/chat/pinned_bar.h" #include "ui/chat/pinned_bar.h"
#include "ui/chat/message_bar.h" #include "ui/chat/message_bar.h"
#include "ui/effects/spoiler_mess.h"
#include "ui/widgets/shadow.h" #include "ui/widgets/shadow.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/wrap/fade_wrap.h" #include "ui/wrap/fade_wrap.h"

View file

@ -25,6 +25,12 @@ constexpr auto kPlayStatusLimit = 2;
} // namespace } // namespace
struct PeerBadge::EmojiStatus {
DocumentId id = 0;
std::unique_ptr<Ui::Text::CustomEmoji> emoji;
int skip = 0;
};
void UnreadBadge::setText(const QString &text, bool active) { void UnreadBadge::setText(const QString &text, bool active) {
_text = text; _text = text;
_active = active; _active = active;

View file

@ -55,11 +55,7 @@ public:
void unload(); void unload();
private: private:
struct EmojiStatus { struct EmojiStatus;
DocumentId id = 0;
std::unique_ptr<Ui::Text::CustomEmoji> emoji;
int skip = 0;
};
std::unique_ptr<EmojiStatus> _emojiStatus; std::unique_ptr<EmojiStatus> _emojiStatus;
}; };

View file

@ -1069,7 +1069,7 @@ void Manager::notificationActivated(
MessageCursor{ MessageCursor{
int(reply.text.size()), int(reply.text.size()),
int(reply.text.size()), int(reply.text.size()),
QFIXED_MAX, Ui::kQFixedMax,
}, },
Data::PreviewState::Allowed); Data::PreviewState::Allowed);
history->setLocalDraft(std::move(draft)); history->setLocalDraft(std::move(draft));

View file

@ -1519,7 +1519,11 @@ bool SessionController::switchInlineQuery(
'@' + bot->username() + ' ' + query, '@' + bot->username() + ' ' + query,
TextWithTags::Tags(), TextWithTags::Tags(),
}; };
MessageCursor cursor = { int(textWithTags.text.size()), int(textWithTags.text.size()), QFIXED_MAX }; MessageCursor cursor = {
int(textWithTags.text.size()),
int(textWithTags.text.size()),
Ui::kQFixedMax
};
auto draft = std::make_unique<Data::Draft>( auto draft = std::make_unique<Data::Draft>(
textWithTags, textWithTags,
to.currentReplyToId, to.currentReplyToId,

@ -1 +1 @@
Subproject commit 44f8d862ff03390217841fb282cb8dd55e0d5d7d Subproject commit a38b60636a42932b5e4d3d2391769a34876a2626