mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
stickers emoji tab done, local cache for stickers, recent stickers and voice messages
This commit is contained in:
@@ -4512,6 +4512,71 @@ void findEmoji(const QChar *ch, const QChar *e, const QChar *&newEmojiEnd, uint3
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'k':
|
||||
if (ch + 2 != e) switch ((ch + 2)->unicode()) {
|
||||
case 'i':
|
||||
if (ch + 3 != e) switch ((ch + 3)->unicode()) {
|
||||
case 's':
|
||||
if (ch + 4 != e) switch ((ch + 4)->unicode()) {
|
||||
case 's':
|
||||
if (ch + 5 != e) switch ((ch + 5)->unicode()) {
|
||||
case ':':
|
||||
newEmojiEnd = ch + 6;
|
||||
if (newEmojiEnd == e || emojiEdge(newEmojiEnd) || newEmojiEnd->unicode() == ' ') {
|
||||
emojiCode = 0xD83DDC8BU;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'j':
|
||||
if (ch + 2 != e) switch ((ch + 2)->unicode()) {
|
||||
case 'o':
|
||||
if (ch + 3 != e) switch ((ch + 3)->unicode()) {
|
||||
case 'y':
|
||||
if (ch + 4 != e) switch ((ch + 4)->unicode()) {
|
||||
case ':':
|
||||
newEmojiEnd = ch + 5;
|
||||
if (newEmojiEnd == e || emojiEdge(newEmojiEnd) || newEmojiEnd->unicode() == ' ') {
|
||||
emojiCode = 0xD83DDE02U;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'g':
|
||||
if (ch + 2 != e) switch ((ch + 2)->unicode()) {
|
||||
case 'r':
|
||||
if (ch + 3 != e) switch ((ch + 3)->unicode()) {
|
||||
case 'i':
|
||||
if (ch + 4 != e) switch ((ch + 4)->unicode()) {
|
||||
case 'n':
|
||||
if (ch + 5 != e) switch ((ch + 5)->unicode()) {
|
||||
case ':':
|
||||
newEmojiEnd = ch + 6;
|
||||
if (newEmojiEnd == e || emojiEdge(newEmojiEnd) || newEmojiEnd->unicode() == ' ') {
|
||||
emojiCode = 0xD83DDE01U;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
if (ch + 2 != e) switch ((ch + 2)->unicode()) {
|
||||
case 'i':
|
||||
@@ -4605,7 +4670,7 @@ void findEmoji(const QChar *ch, const QChar *e, const QChar *&newEmojiEnd, uint3
|
||||
case '(':
|
||||
newEmojiEnd = ch + 3;
|
||||
if (newEmojiEnd == e || emojiEdge(newEmojiEnd) || newEmojiEnd->unicode() == ' ') {
|
||||
emojiCode = 0xD83DDE12U;
|
||||
emojiCode = 0xD83DDE1EU;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
@@ -166,6 +166,75 @@ QSize FlatTextarea::minimumSizeHint() const {
|
||||
return geometry().size();
|
||||
}
|
||||
|
||||
EmojiPtr FlatTextarea::getSingleEmoji() const {
|
||||
QString text;
|
||||
QTextFragment fragment;
|
||||
|
||||
getSingleEmojiFragment(text, fragment);
|
||||
|
||||
if (!text.isEmpty()) {
|
||||
QString imageName = static_cast<const QTextImageFormat*>(&fragment.charFormat())->name();
|
||||
return getEmoji(imageName.mid(8).toUInt(0, 16));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FlatTextarea::getSingleEmojiFragment(QString &text, QTextFragment &fragment) const {
|
||||
int32 end = textCursor().position(), start = end - 1;
|
||||
if (textCursor().anchor() != end) return;
|
||||
|
||||
if (start < 0) start = 0;
|
||||
|
||||
QTextDocument *doc(document());
|
||||
QTextBlock from = doc->findBlock(start), till = doc->findBlock(end);
|
||||
if (till.isValid()) till = till.next();
|
||||
|
||||
for (QTextBlock b = from; b != till; b = b.next()) {
|
||||
for (QTextBlock::Iterator iter = b.begin(); !iter.atEnd(); ++iter) {
|
||||
QTextFragment fr(iter.fragment());
|
||||
if (!fr.isValid()) continue;
|
||||
|
||||
int32 p = fr.position(), e = (p + fr.length());
|
||||
if (p >= end || e <= start) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QTextCharFormat f = fr.charFormat();
|
||||
QString t(fr.text());
|
||||
if (p < start) {
|
||||
t = t.mid(start - p, end - start);
|
||||
} else if (e > end) {
|
||||
t = t.mid(0, end - p);
|
||||
}
|
||||
if (f.isImageFormat() && !t.isEmpty() && t.at(0).unicode() == QChar::ObjectReplacementCharacter) {
|
||||
QString imageName = static_cast<QTextImageFormat*>(&f)->name();
|
||||
if (imageName.midRef(0, 8) == qsl("emoji://")) {
|
||||
fragment = fr;
|
||||
text = t;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void FlatTextarea::removeSingleEmoji() {
|
||||
QString text;
|
||||
QTextFragment fragment;
|
||||
|
||||
getSingleEmojiFragment(text, fragment);
|
||||
|
||||
if (!text.isEmpty()) {
|
||||
QTextCursor t(textCursor());
|
||||
t.setPosition(fragment.position());
|
||||
t.setPosition(fragment.position() + fragment.length(), QTextCursor::KeepAnchor);
|
||||
t.removeSelectedText();
|
||||
setTextCursor(t);
|
||||
}
|
||||
}
|
||||
|
||||
QString FlatTextarea::getText(int32 start, int32 end) const {
|
||||
if (end >= 0 && end <= start) return QString();
|
||||
|
||||
|
@@ -48,6 +48,8 @@ public:
|
||||
QSize sizeHint() const;
|
||||
QSize minimumSizeHint() const;
|
||||
|
||||
EmojiPtr getSingleEmoji() const;
|
||||
void removeSingleEmoji();
|
||||
QString getText(int32 start = 0, int32 end = -1) const;
|
||||
bool hasText() const;
|
||||
|
||||
@@ -77,6 +79,7 @@ protected:
|
||||
|
||||
private:
|
||||
|
||||
void getSingleEmojiFragment(QString &text, QTextFragment &fragment) const;
|
||||
void processDocumentContentsChange(int position, int charsAdded);
|
||||
|
||||
QMimeData *createMimeDataFromSelection() const;
|
||||
|
@@ -330,7 +330,7 @@ void Image::invalidateSizeCache() const {
|
||||
}
|
||||
|
||||
LocalImage::LocalImage(const QString &file, QByteArray fmt) {
|
||||
data = QPixmap::fromImage(App::readImage(file, &fmt, false), Qt::ColorOnly);
|
||||
data = QPixmap::fromImage(App::readImage(file, &fmt, false, 0, &saved), Qt::ColorOnly);
|
||||
format = fmt;
|
||||
if (!data.isNull()) {
|
||||
globalAquiredSize += int64(data.width()) * data.height() * 4;
|
||||
|
@@ -4212,7 +4212,7 @@ LinkRanges textParseLinks(const QString &text, bool rich) {
|
||||
}
|
||||
}
|
||||
if (p > domainEnd) { // check, that domain ended
|
||||
if (domainEnd->unicode() != '/') {
|
||||
if (domainEnd->unicode() != '/' && domainEnd->unicode() != '?') {
|
||||
matchOffset = domainEnd - start;
|
||||
continue;
|
||||
}
|
||||
|
Reference in New Issue
Block a user