Updated lib_ui sources to TDesktop version 2.4.7

This commit is contained in:
Eric Kotato 2020-11-07 00:16:01 +03:00
commit 5f5339aa7e
13 changed files with 97 additions and 101 deletions

View file

@ -1,57 +0,0 @@
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<dir>/usr/share/fonts</dir>
<dir>/usr/local/share/fonts</dir>
<dir>~/.fonts</dir>
<dir>~/.local/share/fonts</dir>
<dir>/usr/X11R6/lib/X11/fonts</dir>
<dir prefix="xdg">fonts</dir>
<match target="pattern">
<test qual="any" name="family">
<string>mono</string>
</test>
<edit name="family" mode="assign" binding="same">
<string>monospace</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family">
<string>sans serif</string>
</test>
<edit name="family" mode="assign" binding="same">
<string>sans-serif</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family">
<string>sans</string>
</test>
<edit name="family" mode="assign" binding="same">
<string>sans-serif</string>
</edit>
</match>
<cachedir>/var/cache/fontconfig_11</cachedir>
<cachedir prefix="xdg">fontconfig_11</cachedir>
<cachedir>~/.fontconfig_11</cachedir>
<match target="font">
<edit mode="assign" name="antialias">
<bool>true</bool>
</edit>
<edit mode="assign" name="embeddedbitmap">
<bool>false</bool>
</edit>
<edit mode="assign" name="hinting">
<bool>true</bool>
</edit>
<edit mode="assign" name="hintstyle">
<const>hintslight</const>
</edit>
<edit mode="assign" name="lcdfilter">
<const>lcddefault</const>
</edit>
<edit mode="assign" name="rgba">
<const>rgb</const>
</edit>
</match>
</fontconfig>

View file

@ -10,7 +10,4 @@
<file>DAVazirMediumAsBold.ttf</file> <file>DAVazirMediumAsBold.ttf</file>
<file>DAVazirMedium.ttf</file> <file>DAVazirMedium.ttf</file>
</qresource> </qresource>
<qresource prefix="/fc">
<file>fc-custom.conf</file>
</qresource>
</RCC> </RCC>

View file

@ -41,13 +41,16 @@ QString UrlClickHandler::copyToClipboardContextItemText() const {
: Ui::Integration::Instance().phraseContextCopyLink(); : Ui::Integration::Instance().phraseContextCopyLink();
} }
QString UrlClickHandler::url() const { QString UrlClickHandler::EncodeForOpening(const QString &originalUrl) {
if (isEmail()) { if (IsEmail(originalUrl)) {
return _originalUrl; return originalUrl;
} }
QUrl u(_originalUrl), good(u.isValid() ? u.toEncoded() : QString()); const auto u = QUrl(originalUrl);
QString result(good.isValid() ? QString::fromUtf8(good.toEncoded()) : _originalUrl); const auto good = QUrl(u.isValid() ? u.toEncoded() : QString());
const auto result = good.isValid()
? QString::fromUtf8(good.toEncoded())
: originalUrl;
if (!result.isEmpty() if (!result.isEmpty()
&& !QRegularExpression( && !QRegularExpression(

View file

@ -59,11 +59,17 @@ public:
const auto at = url.indexOf('@'), slash = url.indexOf('/'); const auto at = url.indexOf('@'), slash = url.indexOf('/');
return ((at > 0) && (slash < 0 || slash > at)); return ((at > 0) && (slash < 0 || slash > at));
} }
[[nodiscard]] static QString EncodeForOpening(const QString &originalUrl);
[[nodiscard]] static bool IsSuspicious(const QString &url); [[nodiscard]] static bool IsSuspicious(const QString &url);
[[nodiscard]] static QString ShowEncoded(const QString &url); [[nodiscard]] static QString ShowEncoded(const QString &url);
protected: protected:
QString url() const override; [[nodiscard]] QString originalUrl() const {
return _originalUrl;
}
QString url() const override {
return EncodeForOpening(_originalUrl);
}
QString readable() const override { QString readable() const override {
return _readable; return _readable;
} }

View file

@ -97,6 +97,20 @@ std::array<QImage, 4> PrepareCorners(
return result; return result;
} }
std::array<QImage, 4> CornersMask(int radius) {
return PrepareCornersMask(radius);
}
std::array<QImage, 4> PrepareCorners(
int radius,
const style::color &color) {
auto result = CornersMask(radius);
for (auto &image : result) {
style::colorizeImage(image, color->c, &image);
}
return result;
}
QImage prepareBlur(QImage img) { QImage prepareBlur(QImage img) {
if (img.isNull()) { if (img.isNull()) {
return img; return img;

View file

@ -27,12 +27,18 @@ namespace Images {
[[nodiscard]] QPixmap PixmapFast(QImage &&image); [[nodiscard]] QPixmap PixmapFast(QImage &&image);
[[nodiscard]] QImage BlurLargeImage(QImage image, int radius); [[nodiscard]] QImage BlurLargeImage(QImage image, int radius);
[[nodiscard]] const std::array<QImage, 4> &CornersMask( [[nodiscard]] const std::array<QImage, 4> &CornersMask(
ImageRoundRadius radius); ImageRoundRadius radius);
[[nodiscard]] std::array<QImage, 4> PrepareCorners( [[nodiscard]] std::array<QImage, 4> PrepareCorners(
ImageRoundRadius radius, ImageRoundRadius radius,
const style::color &color); const style::color &color);
[[nodiscard]] std::array<QImage, 4> CornersMask(int radius);
[[nodiscard]] std::array<QImage, 4> PrepareCorners(
int radius,
const style::color &color);
QImage prepareBlur(QImage image); QImage prepareBlur(QImage image);
void prepareRound( void prepareRound(
QImage &image, QImage &image,

View file

@ -37,7 +37,7 @@ void IgnoreAllActivation(not_null<QWidget*> widget) {
ShowWindow(handle, SW_HIDE); ShowWindow(handle, SW_HIDE);
const auto style = GetWindowLongPtr(handle, GWL_EXSTYLE); const auto style = GetWindowLongPtr(handle, GWL_EXSTYLE);
SetWindowLong( SetWindowLongPtr(
handle, handle,
GWL_EXSTYLE, GWL_EXSTYLE,
style | WS_EX_NOACTIVATE | WS_EX_APPWINDOW); style | WS_EX_NOACTIVATE | WS_EX_APPWINDOW);

View file

@ -213,7 +213,7 @@ void WindowShadow::init(QColor color) {
return; return;
} }
ShadowByHandle.emplace(_handles[i], this); ShadowByHandle.emplace(_handles[i], this);
SetWindowLongPtr(_handles[i], GWLP_HWNDPARENT, (LONG)_handle); SetWindowLongPtr(_handles[i], GWLP_HWNDPARENT, (LONG_PTR)_handle);
_contexts[i] = CreateCompatibleDC(_screenContext); _contexts[i] = CreateCompatibleDC(_screenContext);
if (!_contexts[i]) { if (!_contexts[i]) {

View file

@ -74,6 +74,17 @@ RoundRect::RoundRect(
}, _lifetime); }, _lifetime);
} }
RoundRect::RoundRect(
int radius,
const style::color &color)
: _color(color)
, _corners(Images::PrepareCorners(radius, color)) {
style::PaletteChanged(
) | rpl::start_with_next([=] {
_corners = Images::PrepareCorners(radius, _color);
}, _lifetime);
}
const style::color &RoundRect::color() const { const style::color &RoundRect::color() const {
return _color; return _color;
} }

View file

@ -24,6 +24,7 @@ void DrawRoundedRect(
class RoundRect final { class RoundRect final {
public: public:
RoundRect(ImageRoundRadius radius, const style::color &color); RoundRect(ImageRoundRadius radius, const style::color &color);
RoundRect(int radius, const style::color &color);
[[nodiscard]] const style::color &color() const; [[nodiscard]] const style::color &color() const;
void paint( void paint(

View file

@ -535,6 +535,20 @@ bool Parser::checkEntities() {
const auto entityLength = _waitingEntity->length(); const auto entityLength = _waitingEntity->length();
const auto entityBegin = _start + _waitingEntity->offset(); const auto entityBegin = _start + _waitingEntity->offset();
const auto entityEnd = entityBegin + entityLength; const auto entityEnd = entityBegin + entityLength;
const auto pushSimpleUrl = [&](EntityType type) {
link.type = type;
link.data = QString(entityBegin, entityLength);
if (type == EntityType::Url) {
computeLinkText(link.data, &link.text, &link.shown);
} else {
link.text = link.data;
}
};
const auto pushComplexUrl = [&] {
link.type = entityType;
link.data = _waitingEntity->data();
link.text = QString(entityBegin, entityLength);
};
if (entityType == EntityType::Bold) { if (entityType == EntityType::Bold) {
flags = TextBlockFBold; flags = TextBlockFBold;
} else if (entityType == EntityType::Semibold) { } else if (entityType == EntityType::Semibold) {
@ -559,18 +573,17 @@ bool Parser::checkEntities() {
|| entityType == EntityType::Hashtag || entityType == EntityType::Hashtag
|| entityType == EntityType::Cashtag || entityType == EntityType::Cashtag
|| entityType == EntityType::BotCommand) { || entityType == EntityType::BotCommand) {
link.type = entityType; pushSimpleUrl(entityType);
link.data = QString(entityBegin, entityLength); } else if (entityType == EntityType::CustomUrl) {
if (link.type == EntityType::Url) { const auto url = _waitingEntity->data();
computeLinkText(link.data, &link.text, &link.shown); const auto text = QString(entityBegin, entityLength);
if (url == text) {
pushSimpleUrl(EntityType::Url);
} else { } else {
link.text = link.data; pushComplexUrl();
} }
} else if (entityType == EntityType::CustomUrl } else if (entityType == EntityType::MentionName) {
|| entityType == EntityType::MentionName) { pushComplexUrl();
link.type = entityType;
link.data = _waitingEntity->data();
link.text = QString(_start + _waitingEntity->offset(), _waitingEntity->length());
} }
if (link.type != EntityType::Invalid) { if (link.type != EntityType::Invalid) {
@ -3271,16 +3284,20 @@ TextForMimeData String::toText(
if (!composeExpanded && !composeEntities) { if (!composeExpanded && !composeEntities) {
return; return;
} }
const auto skipLink = (entity.type == EntityType::CustomUrl) const auto customTextLink = (entity.type == EntityType::CustomUrl);
&& (entity.data.startsWith(qstr("internal:"))); const auto internalLink = customTextLink
&& entity.data.startsWith(qstr("internal:"));
if (composeExpanded) { if (composeExpanded) {
result.expanded.append(full); result.expanded.append(full);
if (entity.type == EntityType::CustomUrl && !skipLink) { const auto sameAsTextLink = customTextLink
&& (entity.data
== UrlClickHandler::EncodeForOpening(full.toString()));
if (customTextLink && !internalLink && !sameAsTextLink) {
const auto &url = entity.data; const auto &url = entity.data;
result.expanded.append(qstr(" (")).append(url).append(')'); result.expanded.append(qstr(" (")).append(url).append(')');
} }
} }
if (composeEntities && !skipLink) { if (composeEntities && !internalLink) {
insertEntity({ insertEntity({
entity.type, entity.type,
linkStart, linkStart,

View file

@ -1587,7 +1587,8 @@ void ParseEntities(TextWithEntities &result, int32 flags, bool rich) {
int32 len = result.text.size(), commandOffset = rich ? 0 : len; int32 len = result.text.size(), commandOffset = rich ? 0 : len;
bool inLink = false, commandIsLink = false; bool inLink = false, commandIsLink = false;
const QChar *start = result.text.constData(), *end = start + result.text.size(); const auto start = result.text.constData();
const auto end = start + result.text.size();
for (int32 offset = 0, matchOffset = offset, mentionSkip = 0; offset < len;) { for (int32 offset = 0, matchOffset = offset, mentionSkip = 0; offset < len;) {
if (commandOffset <= offset) { if (commandOffset <= offset) {
for (commandOffset = offset; commandOffset < len; ++commandOffset) { for (commandOffset = offset; commandOffset < len; ++commandOffset) {
@ -1642,6 +1643,10 @@ void ParseEntities(TextWithEntities &result, int32 flags, bool rich) {
} }
if (!(start + mentionStart + 1)->isLetter() || !(start + mentionEnd - 1)->isLetterOrNumber()) { if (!(start + mentionStart + 1)->isLetter() || !(start + mentionEnd - 1)->isLetterOrNumber()) {
mentionSkip = mentionEnd; mentionSkip = mentionEnd;
if (mentionSkip < len
&& (start + mentionSkip)->isLowSurrogate()) {
++mentionSkip;
}
mMention = RegExpMention().match(result.text, qMax(mentionSkip, matchOffset)); mMention = RegExpMention().match(result.text, qMax(mentionSkip, matchOffset));
if (mMention.hasMatch()) { if (mMention.hasMatch()) {
mentionStart = mMention.capturedStart(); mentionStart = mMention.capturedStart();

View file

@ -24,23 +24,11 @@ class object_ptr;
namespace Ui { namespace Ui {
namespace details { namespace details {
struct ForwardTag {
};
struct InPlaceTag {
};
template <typename Value> template <typename Value>
class AttachmentOwner : public QObject { class AttachmentOwner : public QObject {
public: public:
template <typename OtherValue>
AttachmentOwner(QObject *parent, const ForwardTag&, OtherValue &&value)
: QObject(parent)
, _value(std::forward<OtherValue>(value)) {
}
template <typename ...Args> template <typename ...Args>
AttachmentOwner(QObject *parent, const InPlaceTag&, Args &&...args) AttachmentOwner(QObject *parent, Args &&...args)
: QObject(parent) : QObject(parent)
, _value(std::forward<Args>(args)...) { , _value(std::forward<Args>(args)...) {
} }
@ -74,11 +62,19 @@ inline Value *CreateChild(
} else { } else {
return CreateChild<details::AttachmentOwner<Value>>( return CreateChild<details::AttachmentOwner<Value>>(
parent, parent,
details::InPlaceTag{},
std::forward<Args>(args)...)->value(); std::forward<Args>(args)...)->value();
} }
} }
template <typename Value>
inline not_null<details::AttachmentOwner<std::decay_t<Value>>*> WrapAsQObject(
not_null<QObject*> parent,
Value &&value) {
return CreateChild<details::AttachmentOwner<std::decay_t<Value>>>(
parent.get(),
std::forward<Value>(value));
}
inline void DestroyChild(QWidget *child) { inline void DestroyChild(QWidget *child) {
delete child; delete child;
} }
@ -92,10 +88,7 @@ template <typename Value>
inline not_null<std::decay_t<Value>*> AttachAsChild( inline not_null<std::decay_t<Value>*> AttachAsChild(
not_null<QObject*> parent, not_null<QObject*> parent,
Value &&value) { Value &&value) {
return CreateChild<details::AttachmentOwner<std::decay_t<Value>>>( return WrapAsQObject(parent, std::forward<Value>(value))->value();
parent.get(),
details::ForwardTag{},
std::forward<Value>(value))->value();
} }
[[nodiscard]] bool AppInFocus(); [[nodiscard]] bool AppInFocus();