mirror of
https://github.com/vale981/tdesktop
synced 2025-03-08 19:21:39 -05:00
Merge branch 'game_media' into player
This commit is contained in:
commit
fee1cec3d9
6 changed files with 40 additions and 21 deletions
|
@ -117,7 +117,7 @@ void BotGameUrlClickHandler::onClick(Qt::MouseButton button) const {
|
||||||
|
|
||||||
if (u.startsWith(qstr("tg://"))) {
|
if (u.startsWith(qstr("tg://"))) {
|
||||||
App::openLocalUrl(u);
|
App::openLocalUrl(u);
|
||||||
} else if (!_bot || Local::isBotTrusted(_bot)) {
|
} else if (!_bot || _bot->isVerified() || Local::isBotTrusted(_bot)) {
|
||||||
doOpen(u);
|
doOpen(u);
|
||||||
} else {
|
} else {
|
||||||
Ui::showLayer(new ConfirmBotGameBox(_bot, u));
|
Ui::showLayer(new ConfirmBotGameBox(_bot, u));
|
||||||
|
|
|
@ -1094,7 +1094,7 @@ void HistoryDocument::draw(Painter &p, const QRect &r, TextSelection selection,
|
||||||
auto inWebPage = (_parent->getMedia() != this);
|
auto inWebPage = (_parent->getMedia() != this);
|
||||||
auto roundRadius = inWebPage ? ImageRoundRadius::Small : ImageRoundRadius::Large;
|
auto roundRadius = inWebPage ? ImageRoundRadius::Small : ImageRoundRadius::Large;
|
||||||
QRect rthumb(rtlrect(st::msgFileThumbPadding.left(), st::msgFileThumbPadding.top(), st::msgFileThumbSize, st::msgFileThumbSize, _width));
|
QRect rthumb(rtlrect(st::msgFileThumbPadding.left(), st::msgFileThumbPadding.top(), st::msgFileThumbSize, st::msgFileThumbSize, _width));
|
||||||
QPixmap thumb = loaded ? _data->thumb->pixSingle(roundRadius, thumbed->_thumbw, 0, st::msgFileThumbSize, st::msgFileThumbSize) : _data->thumb->pixBlurredSingle(ImageRoundRadius::Small, thumbed->_thumbw, 0, st::msgFileThumbSize, st::msgFileThumbSize);
|
QPixmap thumb = loaded ? _data->thumb->pixSingle(roundRadius, thumbed->_thumbw, 0, st::msgFileThumbSize, st::msgFileThumbSize) : _data->thumb->pixBlurredSingle(roundRadius, thumbed->_thumbw, 0, st::msgFileThumbSize, st::msgFileThumbSize);
|
||||||
p.drawPixmap(rthumb.topLeft(), thumb);
|
p.drawPixmap(rthumb.topLeft(), thumb);
|
||||||
if (selected) {
|
if (selected) {
|
||||||
auto overlayCorners = inWebPage ? SelectedOverlaySmallCorners : SelectedOverlayLargeCorners;
|
auto overlayCorners = inWebPage ? SelectedOverlaySmallCorners : SelectedOverlayLargeCorners;
|
||||||
|
|
|
@ -968,6 +968,9 @@ void HistoryMessage::setMedia(const MTPMessageMedia *media) {
|
||||||
|
|
||||||
bool mediaRemovedSkipBlock = false;
|
bool mediaRemovedSkipBlock = false;
|
||||||
if (_media) {
|
if (_media) {
|
||||||
|
// Don't update Game media because we loose the consumed text of the message.
|
||||||
|
if (_media->type() == MediaTypeGame) return;
|
||||||
|
|
||||||
mediaRemovedSkipBlock = _media->isDisplayed() && _media->isBubbleBottom();
|
mediaRemovedSkipBlock = _media->isDisplayed() && _media->isBubbleBottom();
|
||||||
_media.clear();
|
_media.clear();
|
||||||
}
|
}
|
||||||
|
@ -2180,7 +2183,7 @@ HistoryTextState HistoryService::getState(int x, int y, HistoryStateRequest requ
|
||||||
result = _text.getState(x - trect.x(), y - trect.y(), trect.width(), textRequest);
|
result = _text.getState(x - trect.x(), y - trect.y(), trect.width(), textRequest);
|
||||||
textstyleRestore();
|
textstyleRestore();
|
||||||
if (auto gamescore = Get<HistoryServiceGameScore>()) {
|
if (auto gamescore = Get<HistoryServiceGameScore>()) {
|
||||||
if (!result.link && outer.contains(x, y)) {
|
if (!result.link && result.cursor == HistoryInTextCursorState && outer.contains(x, y)) {
|
||||||
result.link = gamescore->lnk;
|
result.link = gamescore->lnk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6027,7 +6027,7 @@ void HistoryWidget::inlineBotResolveDone(const MTPcontacts_ResolvedPeer &result)
|
||||||
|
|
||||||
UserData *bot = nullptr;
|
UserData *bot = nullptr;
|
||||||
QString inlineBotUsername;
|
QString inlineBotUsername;
|
||||||
QString query = _field.getInlineBotQuery(&bot, &inlineBotUsername);
|
auto query = _field.getInlineBotQuery(&bot, &inlineBotUsername);
|
||||||
if (inlineBotUsername == _inlineBotUsername) {
|
if (inlineBotUsername == _inlineBotUsername) {
|
||||||
if (bot == LookingUpInlineBot) {
|
if (bot == LookingUpInlineBot) {
|
||||||
bot = resolvedBot;
|
bot = resolvedBot;
|
||||||
|
@ -6567,7 +6567,7 @@ void HistoryWidget::uploadImage(const QImage &img, PrepareMediaType type, FileLo
|
||||||
if (!_history) return;
|
if (!_history) return;
|
||||||
|
|
||||||
App::wnd()->activateWindow();
|
App::wnd()->activateWindow();
|
||||||
FileLoadTask *task = new FileLoadTask(img, type, FileLoadTo(_peer->id, _silent.checked(), replyToId()), confirm, source);
|
auto task = new FileLoadTask(img, type, FileLoadTo(_peer->id, _silent.checked(), replyToId()), confirm, source);
|
||||||
if (withText) {
|
if (withText) {
|
||||||
_confirmWithTextId = task->fileid();
|
_confirmWithTextId = task->fileid();
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,7 +286,7 @@ void FlatTextarea::paintEvent(QPaintEvent *e) {
|
||||||
p.setFont(_st.font);
|
p.setFont(_st.font);
|
||||||
p.setPen(a_phColor.current());
|
p.setPen(a_phColor.current());
|
||||||
if (_st.phAlign == style::al_topleft && _phAfter > 0) {
|
if (_st.phAlign == style::al_topleft && _phAfter > 0) {
|
||||||
int skipWidth = _st.font->width(getTextWithTags().text.mid(0, _phAfter));
|
int skipWidth = placeholderSkipWidth();
|
||||||
p.drawText(_st.textMrg.left() - _fakeMargin + a_phLeft.current() + skipWidth, _st.textMrg.top() - _fakeMargin - st::lineWidth + _st.font->ascent, _ph);
|
p.drawText(_st.textMrg.left() - _fakeMargin + a_phLeft.current() + skipWidth, _st.textMrg.top() - _fakeMargin - st::lineWidth + _st.font->ascent, _ph);
|
||||||
} else {
|
} else {
|
||||||
QRect phRect(_st.textMrg.left() - _fakeMargin + _st.phPos.x() + a_phLeft.current(), _st.textMrg.top() - _fakeMargin + _st.phPos.y(), width() - _st.textMrg.left() - _st.textMrg.right(), height() - _st.textMrg.top() - _st.textMrg.bottom());
|
QRect phRect(_st.textMrg.left() - _fakeMargin + _st.phPos.x() + a_phLeft.current(), _st.textMrg.top() - _fakeMargin + _st.phPos.y(), width() - _st.textMrg.left() - _st.textMrg.right(), height() - _st.textMrg.top() - _st.textMrg.bottom());
|
||||||
|
@ -298,6 +298,18 @@ void FlatTextarea::paintEvent(QPaintEvent *e) {
|
||||||
QTextEdit::paintEvent(e);
|
QTextEdit::paintEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FlatTextarea::placeholderSkipWidth() const {
|
||||||
|
if (!_phAfter) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
auto text = getTextWithTags().text;
|
||||||
|
auto result = _st.font->width(text.mid(0, _phAfter));
|
||||||
|
if (_phAfter > text.size()) {
|
||||||
|
result += _st.font->spacew;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void FlatTextarea::focusInEvent(QFocusEvent *e) {
|
void FlatTextarea::focusInEvent(QFocusEvent *e) {
|
||||||
a_phColor.start(_st.phFocusColor->c);
|
a_phColor.start(_st.phFocusColor->c);
|
||||||
_a_appearance.start();
|
_a_appearance.start();
|
||||||
|
@ -339,11 +351,12 @@ QString FlatTextarea::getInlineBotQuery(UserData **outInlineBot, QString *outInl
|
||||||
t_assert(outInlineBotUsername != nullptr);
|
t_assert(outInlineBotUsername != nullptr);
|
||||||
|
|
||||||
auto &text = getTextWithTags().text;
|
auto &text = getTextWithTags().text;
|
||||||
|
auto textLength = text.size();
|
||||||
|
|
||||||
int32 inlineUsernameStart = 1, inlineUsernameLength = 0, size = text.size();
|
int inlineUsernameStart = 1, inlineUsernameLength = 0;
|
||||||
if (size > 2 && text.at(0) == '@' && text.at(1).isLetter()) {
|
if (textLength > 2 && text.at(0) == '@' && text.at(1).isLetter()) {
|
||||||
inlineUsernameLength = 1;
|
inlineUsernameLength = 1;
|
||||||
for (int32 i = inlineUsernameStart + 1, l = text.size(); i < l; ++i) {
|
for (int i = inlineUsernameStart + 1; i != textLength; ++i) {
|
||||||
if (text.at(i).isLetterOrNumber() || text.at(i).unicode() == '_') {
|
if (text.at(i).isLetterOrNumber() || text.at(i).unicode() == '_') {
|
||||||
++inlineUsernameLength;
|
++inlineUsernameLength;
|
||||||
continue;
|
continue;
|
||||||
|
@ -353,11 +366,19 @@ QString FlatTextarea::getInlineBotQuery(UserData **outInlineBot, QString *outInl
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (inlineUsernameLength && inlineUsernameStart + inlineUsernameLength < text.size() && text.at(inlineUsernameStart + inlineUsernameLength).isSpace()) {
|
auto inlineUsernameEnd = inlineUsernameStart + inlineUsernameLength;
|
||||||
QStringRef username = text.midRef(inlineUsernameStart, inlineUsernameLength);
|
auto inlineUsernameEqualsText = (inlineUsernameEnd == textLength);
|
||||||
|
auto validInlineUsername = false;
|
||||||
|
if (inlineUsernameEqualsText) {
|
||||||
|
validInlineUsername = text.endsWith(qstr("bot"));
|
||||||
|
} else if (inlineUsernameEnd < textLength && inlineUsernameLength) {
|
||||||
|
validInlineUsername = text.at(inlineUsernameEnd).isSpace();
|
||||||
|
}
|
||||||
|
if (validInlineUsername) {
|
||||||
|
auto username = text.midRef(inlineUsernameStart, inlineUsernameLength);
|
||||||
if (username != *outInlineBotUsername) {
|
if (username != *outInlineBotUsername) {
|
||||||
*outInlineBotUsername = username.toString();
|
*outInlineBotUsername = username.toString();
|
||||||
PeerData *peer = App::peerByName(*outInlineBotUsername);
|
auto peer = App::peerByName(*outInlineBotUsername);
|
||||||
if (peer) {
|
if (peer) {
|
||||||
if (peer->isUser()) {
|
if (peer->isUser()) {
|
||||||
*outInlineBot = peer->asUser();
|
*outInlineBot = peer->asUser();
|
||||||
|
@ -373,7 +394,7 @@ QString FlatTextarea::getInlineBotQuery(UserData **outInlineBot, QString *outInl
|
||||||
if (*outInlineBot && (!(*outInlineBot)->botInfo || (*outInlineBot)->botInfo->inlinePlaceholder.isEmpty())) {
|
if (*outInlineBot && (!(*outInlineBot)->botInfo || (*outInlineBot)->botInfo->inlinePlaceholder.isEmpty())) {
|
||||||
*outInlineBot = nullptr;
|
*outInlineBot = nullptr;
|
||||||
} else {
|
} else {
|
||||||
return text.mid(inlineUsernameStart + inlineUsernameLength + 1);
|
return inlineUsernameEqualsText ? QString() : text.mid(inlineUsernameEnd + 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
inlineUsernameLength = 0;
|
inlineUsernameLength = 0;
|
||||||
|
@ -1265,10 +1286,7 @@ void FlatTextarea::setPlaceholder(const QString &ph, int32 afterSymbols) {
|
||||||
_phAfter = afterSymbols;
|
_phAfter = afterSymbols;
|
||||||
updatePlaceholder();
|
updatePlaceholder();
|
||||||
}
|
}
|
||||||
int skipWidth = 0;
|
int skipWidth = placeholderSkipWidth();
|
||||||
if (_phAfter) {
|
|
||||||
skipWidth = _st.font->width(getTextWithTags().text.mid(0, _phAfter));
|
|
||||||
}
|
|
||||||
_phelided = _st.font->elided(_ph, width() - _st.textMrg.left() - _st.textMrg.right() - _st.phPos.x() - 1 - skipWidth);
|
_phelided = _st.font->elided(_ph, width() - _st.textMrg.left() - _st.textMrg.right() - _st.phPos.x() - 1 - skipWidth);
|
||||||
if (_phVisible) update();
|
if (_phVisible) update();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ class FlatTextarea : public QTextEdit {
|
||||||
T_WIDGET
|
T_WIDGET
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
struct Tag {
|
struct Tag {
|
||||||
int offset, length;
|
int offset, length;
|
||||||
QString id;
|
QString id;
|
||||||
|
@ -122,7 +121,6 @@ public:
|
||||||
void setTagMimeProcessor(std_::unique_ptr<TagMimeProcessor> &&processor);
|
void setTagMimeProcessor(std_::unique_ptr<TagMimeProcessor> &&processor);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void onTouchTimer();
|
void onTouchTimer();
|
||||||
|
|
||||||
void onDocumentContentsChange(int position, int charsRemoved, int charsAdded);
|
void onDocumentContentsChange(int position, int charsRemoved, int charsAdded);
|
||||||
|
@ -132,7 +130,6 @@ public slots:
|
||||||
void onRedoAvailable(bool avail);
|
void onRedoAvailable(bool avail);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void resized();
|
void resized();
|
||||||
void changed();
|
void changed();
|
||||||
void submitted(bool ctrlShiftEnter);
|
void submitted(bool ctrlShiftEnter);
|
||||||
|
@ -170,7 +167,6 @@ protected:
|
||||||
void checkContentHeight();
|
void checkContentHeight();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// "start" and "end" are in coordinates of text where emoji are replaced
|
// "start" and "end" are in coordinates of text where emoji are replaced
|
||||||
// by ObjectReplacementCharacter. If "end" = -1 means get text till the end.
|
// by ObjectReplacementCharacter. If "end" = -1 means get text till the end.
|
||||||
QString getTextPart(int start, int end, TagList *outTagsList, bool *outTagsChanged = nullptr) const;
|
QString getTextPart(int start, int end, TagList *outTagsList, bool *outTagsChanged = nullptr) const;
|
||||||
|
@ -188,6 +184,8 @@ private:
|
||||||
|
|
||||||
bool heightAutoupdated();
|
bool heightAutoupdated();
|
||||||
|
|
||||||
|
int placeholderSkipWidth() const;
|
||||||
|
|
||||||
int _minHeight = -1; // < 0 - no autosize
|
int _minHeight = -1; // < 0 - no autosize
|
||||||
int _maxHeight = -1;
|
int _maxHeight = -1;
|
||||||
int _maxLength = -1;
|
int _maxLength = -1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue