2016-06-09 11:51:24 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-06-09 11:51:24 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-06-09 11:51:24 +00:00
|
|
|
*/
|
2018-01-09 17:08:31 +00:00
|
|
|
#include "history/view/history_view_service_message.h"
|
2016-06-09 11:51:24 +00:00
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2017-06-22 15:11:41 +00:00
|
|
|
#include "history/history_service.h"
|
|
|
|
#include "history/history_media.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history_item_components.h"
|
|
|
|
#include "history/view/history_view_cursor_state.h"
|
2016-06-09 11:51:24 +00:00
|
|
|
#include "data/data_abstract_structure.h"
|
2016-07-08 10:06:41 +00:00
|
|
|
#include "styles/style_history.h"
|
2016-06-09 11:51:24 +00:00
|
|
|
#include "mainwidget.h"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "layout.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-06-09 11:51:24 +00:00
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
namespace HistoryView {
|
2016-06-09 11:51:24 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
enum CircleMask {
|
|
|
|
NormalMask = 0x00,
|
|
|
|
InvertedMask = 0x01,
|
|
|
|
};
|
|
|
|
enum CircleMaskMultiplier {
|
|
|
|
MaskMultiplier = 0x04,
|
|
|
|
};
|
|
|
|
enum CornerVerticalSide {
|
|
|
|
CornerTop = 0x00,
|
|
|
|
CornerBottom = 0x02,
|
|
|
|
};
|
|
|
|
enum CornerHorizontalSide {
|
|
|
|
CornerLeft = 0x00,
|
|
|
|
CornerRight = 0x01,
|
|
|
|
};
|
|
|
|
|
|
|
|
class ServiceMessageStyleData : public Data::AbstractStructure {
|
|
|
|
public:
|
|
|
|
// circle[CircleMask value]
|
|
|
|
QImage circle[2];
|
|
|
|
|
|
|
|
// corners[(CircleMask value) * MaskMultiplier | (CornerVerticalSide value) | (CornerHorizontalSide value)]
|
|
|
|
QPixmap corners[8];
|
|
|
|
};
|
|
|
|
Data::GlobalStructurePointer<ServiceMessageStyleData> serviceMessageStyle;
|
|
|
|
|
2016-08-14 19:56:26 +00:00
|
|
|
int historyServiceMsgRadius() {
|
|
|
|
static int HistoryServiceMsgRadius = ([]() {
|
|
|
|
auto minMsgHeight = (st::msgServiceFont->height + st::msgServicePadding.top() + st::msgServicePadding.bottom());
|
|
|
|
return minMsgHeight / 2;
|
|
|
|
})();
|
|
|
|
return HistoryServiceMsgRadius;
|
|
|
|
}
|
|
|
|
|
|
|
|
int historyServiceMsgInvertedRadius() {
|
|
|
|
static int HistoryServiceMsgInvertedRadius = ([]() {
|
|
|
|
auto minRowHeight = st::msgServiceFont->height;
|
|
|
|
return minRowHeight - historyServiceMsgRadius();
|
|
|
|
})();
|
|
|
|
return HistoryServiceMsgInvertedRadius;
|
|
|
|
}
|
|
|
|
|
|
|
|
int historyServiceMsgInvertedShrink() {
|
|
|
|
static int HistoryServiceMsgInvertedShrink = ([]() {
|
|
|
|
return (historyServiceMsgInvertedRadius() * 2) / 3;
|
|
|
|
})();
|
|
|
|
return HistoryServiceMsgInvertedShrink;
|
|
|
|
}
|
|
|
|
|
2016-06-09 11:51:24 +00:00
|
|
|
void createCircleMasks() {
|
|
|
|
serviceMessageStyle.createIfNull();
|
|
|
|
if (!serviceMessageStyle->circle[NormalMask].isNull()) return;
|
|
|
|
|
2016-08-14 19:56:26 +00:00
|
|
|
int size = historyServiceMsgRadius() * 2;
|
2016-06-09 11:51:24 +00:00
|
|
|
serviceMessageStyle->circle[NormalMask] = style::createCircleMask(size);
|
2016-08-14 19:56:26 +00:00
|
|
|
int sizeInverted = historyServiceMsgInvertedRadius() * 2;
|
2016-07-08 10:06:41 +00:00
|
|
|
serviceMessageStyle->circle[InvertedMask] = style::createInvertedCircleMask(sizeInverted);
|
2016-06-09 11:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap circleCorner(int corner) {
|
|
|
|
if (serviceMessageStyle->corners[corner].isNull()) {
|
2016-07-08 10:06:41 +00:00
|
|
|
int maskType = corner / MaskMultiplier;
|
2016-08-14 19:56:26 +00:00
|
|
|
int radius = (maskType == NormalMask ? historyServiceMsgRadius() : historyServiceMsgInvertedRadius());
|
2016-07-08 10:06:41 +00:00
|
|
|
int size = radius * cIntRetinaFactor();
|
2016-06-09 11:51:24 +00:00
|
|
|
|
|
|
|
int xoffset = 0, yoffset = 0;
|
|
|
|
if (corner & CornerRight) {
|
|
|
|
xoffset = size;
|
|
|
|
}
|
|
|
|
if (corner & CornerBottom) {
|
|
|
|
yoffset = size;
|
|
|
|
}
|
|
|
|
auto part = QRect(xoffset, yoffset, size, size);
|
2016-11-03 10:33:57 +00:00
|
|
|
auto result = style::colorizeImage(serviceMessageStyle->circle[maskType], st::msgServiceBg, part);
|
2016-06-09 11:51:24 +00:00
|
|
|
result.setDevicePixelRatio(cRetinaFactor());
|
2017-02-21 13:45:56 +00:00
|
|
|
serviceMessageStyle->corners[corner] = App::pixmapFromImageInPlace(std::move(result));
|
2016-06-09 11:51:24 +00:00
|
|
|
}
|
|
|
|
return serviceMessageStyle->corners[corner];
|
|
|
|
}
|
|
|
|
|
|
|
|
enum class SideStyle {
|
|
|
|
Rounded,
|
|
|
|
Plain,
|
|
|
|
Inverted,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Returns amount of pixels already painted vertically (so you can skip them in the complex rect shape).
|
|
|
|
int paintBubbleSide(Painter &p, int x, int y, int width, SideStyle style, CornerVerticalSide side) {
|
|
|
|
if (style == SideStyle::Rounded) {
|
|
|
|
auto left = circleCorner((NormalMask * MaskMultiplier) | side | CornerLeft);
|
|
|
|
int leftWidth = left.width() / cIntRetinaFactor();
|
|
|
|
p.drawPixmap(x, y, left);
|
|
|
|
|
|
|
|
auto right = circleCorner((NormalMask * MaskMultiplier) | side | CornerRight);
|
|
|
|
int rightWidth = right.width() / cIntRetinaFactor();
|
|
|
|
p.drawPixmap(x + width - rightWidth, y, right);
|
|
|
|
|
|
|
|
int cornerHeight = left.height() / cIntRetinaFactor();
|
2016-11-03 10:33:57 +00:00
|
|
|
p.fillRect(x + leftWidth, y, width - leftWidth - rightWidth, cornerHeight, st::msgServiceBg);
|
2016-06-09 11:51:24 +00:00
|
|
|
return cornerHeight;
|
|
|
|
} else if (style == SideStyle::Inverted) {
|
|
|
|
// CornerLeft and CornerRight are inverted for SideStyle::Inverted sprites.
|
|
|
|
auto left = circleCorner((InvertedMask * MaskMultiplier) | side | CornerRight);
|
|
|
|
int leftWidth = left.width() / cIntRetinaFactor();
|
|
|
|
p.drawPixmap(x - leftWidth, y, left);
|
|
|
|
|
|
|
|
auto right = circleCorner((InvertedMask * MaskMultiplier) | side | CornerLeft);
|
|
|
|
p.drawPixmap(x + width, y, right);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-14 19:56:26 +00:00
|
|
|
void paintBubblePart(Painter &p, int x, int y, int width, int height, SideStyle topStyle, SideStyle bottomStyle, bool forceShrink = false) {
|
|
|
|
if (topStyle == SideStyle::Inverted || bottomStyle == SideStyle::Inverted || forceShrink) {
|
|
|
|
width -= historyServiceMsgInvertedShrink() * 2;
|
|
|
|
x += historyServiceMsgInvertedShrink();
|
2016-07-08 10:06:41 +00:00
|
|
|
}
|
|
|
|
|
2016-06-09 11:51:24 +00:00
|
|
|
if (int skip = paintBubbleSide(p, x, y, width, topStyle, CornerTop)) {
|
|
|
|
y += skip;
|
|
|
|
height -= skip;
|
|
|
|
}
|
2016-07-08 10:06:41 +00:00
|
|
|
int bottomSize = 0;
|
|
|
|
if (bottomStyle == SideStyle::Rounded) {
|
2016-08-14 19:56:26 +00:00
|
|
|
bottomSize = historyServiceMsgRadius();
|
2016-07-08 10:06:41 +00:00
|
|
|
} else if (bottomStyle == SideStyle::Inverted) {
|
2016-08-14 19:56:26 +00:00
|
|
|
bottomSize = historyServiceMsgInvertedRadius();
|
2016-07-08 10:06:41 +00:00
|
|
|
}
|
|
|
|
if (int skip = paintBubbleSide(p, x, y + height - bottomSize, width, bottomStyle, CornerBottom)) {
|
2016-06-09 11:51:24 +00:00
|
|
|
height -= skip;
|
|
|
|
}
|
|
|
|
|
2016-11-03 10:33:57 +00:00
|
|
|
p.fillRect(x, y, width, height, st::msgServiceBg);
|
2016-06-09 11:51:24 +00:00
|
|
|
}
|
|
|
|
|
2016-06-10 10:21:09 +00:00
|
|
|
void paintPreparedDate(Painter &p, const QString &dateText, int dateTextWidth, int y, int w) {
|
|
|
|
int left = st::msgServiceMargin.left();
|
|
|
|
int maxwidth = w;
|
2017-01-14 18:50:16 +00:00
|
|
|
if (Adaptive::ChatWide()) {
|
2017-05-17 12:38:42 +00:00
|
|
|
maxwidth = qMin(maxwidth, WideChatWidth());
|
2016-06-10 10:21:09 +00:00
|
|
|
}
|
|
|
|
w = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left();
|
|
|
|
|
|
|
|
left += (w - dateTextWidth - st::msgServicePadding.left() - st::msgServicePadding.right()) / 2;
|
|
|
|
int height = st::msgServicePadding.top() + st::msgServiceFont->height + st::msgServicePadding.bottom();
|
2016-07-08 10:06:41 +00:00
|
|
|
ServiceMessagePainter::paintBubble(p, left, y + st::msgServiceMargin.top(), dateTextWidth + st::msgServicePadding.left() + st::msgServicePadding.left(), height);
|
2016-06-10 10:21:09 +00:00
|
|
|
|
|
|
|
p.setFont(st::msgServiceFont);
|
2016-12-21 15:05:58 +00:00
|
|
|
p.setPen(st::msgServiceFg);
|
2016-06-10 10:21:09 +00:00
|
|
|
p.drawText(left + st::msgServicePadding.left(), y + st::msgServiceMargin.top() + st::msgServicePadding.top() + st::msgServiceFont->ascent, dateText);
|
|
|
|
}
|
|
|
|
|
2016-06-09 11:51:24 +00:00
|
|
|
} // namepsace
|
|
|
|
|
2017-05-17 12:38:42 +00:00
|
|
|
int WideChatWidth() {
|
|
|
|
return st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left();
|
|
|
|
}
|
|
|
|
|
2016-06-10 10:21:09 +00:00
|
|
|
void ServiceMessagePainter::paintDate(Painter &p, const QDateTime &date, int y, int w) {
|
|
|
|
auto dateText = langDayOfMonthFull(date.date());
|
|
|
|
auto dateTextWidth = st::msgServiceFont->width(dateText);
|
|
|
|
paintPreparedDate(p, dateText, dateTextWidth, y, w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServiceMessagePainter::paintDate(Painter &p, const QString &dateText, int dateTextWidth, int y, int w) {
|
|
|
|
paintPreparedDate(p, dateText, dateTextWidth, y, w);
|
|
|
|
}
|
|
|
|
|
2016-07-08 10:06:41 +00:00
|
|
|
void ServiceMessagePainter::paintBubble(Painter &p, int x, int y, int w, int h) {
|
|
|
|
createCircleMasks();
|
|
|
|
|
|
|
|
paintBubblePart(p, x, y, w, h, SideStyle::Rounded, SideStyle::Rounded);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServiceMessagePainter::paintComplexBubble(Painter &p, int left, int width, const Text &text, const QRect &textRect) {
|
2016-06-09 11:51:24 +00:00
|
|
|
createCircleMasks();
|
|
|
|
|
|
|
|
auto lineWidths = countLineWidths(text, textRect);
|
|
|
|
|
2016-08-14 19:56:26 +00:00
|
|
|
int y = st::msgServiceMargin.top(), previousRichWidth = 0;
|
|
|
|
bool previousShrink = false, forceShrink = false;
|
2016-06-09 11:51:24 +00:00
|
|
|
SideStyle topStyle = SideStyle::Rounded, bottomStyle;
|
|
|
|
for (int i = 0, count = lineWidths.size(); i < count; ++i) {
|
|
|
|
auto lineWidth = lineWidths.at(i);
|
|
|
|
if (i + 1 < count) {
|
|
|
|
auto nextLineWidth = lineWidths.at(i + 1);
|
|
|
|
if (nextLineWidth > lineWidth) {
|
|
|
|
bottomStyle = SideStyle::Inverted;
|
|
|
|
} else if (nextLineWidth < lineWidth) {
|
|
|
|
bottomStyle = SideStyle::Rounded;
|
|
|
|
} else {
|
|
|
|
bottomStyle = SideStyle::Plain;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bottomStyle = SideStyle::Rounded;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto richWidth = lineWidth + st::msgServicePadding.left() + st::msgServicePadding.right();
|
|
|
|
auto richHeight = st::msgServiceFont->height;
|
|
|
|
if (topStyle == SideStyle::Rounded) {
|
|
|
|
richHeight += st::msgServicePadding.top();
|
|
|
|
} else if (topStyle == SideStyle::Inverted) {
|
|
|
|
richHeight -= st::msgServicePadding.bottom();
|
|
|
|
}
|
|
|
|
if (bottomStyle == SideStyle::Rounded) {
|
|
|
|
richHeight += st::msgServicePadding.bottom();
|
|
|
|
} else if (bottomStyle == SideStyle::Inverted) {
|
|
|
|
richHeight -= st::msgServicePadding.top();
|
|
|
|
}
|
2016-08-14 19:56:26 +00:00
|
|
|
forceShrink = previousShrink && (richWidth == previousRichWidth);
|
|
|
|
paintBubblePart(p, left + ((width - richWidth) / 2), y, richWidth, richHeight, topStyle, bottomStyle, forceShrink);
|
2016-06-09 11:51:24 +00:00
|
|
|
y += richHeight;
|
|
|
|
|
2016-08-14 19:56:26 +00:00
|
|
|
previousShrink = forceShrink || (topStyle == SideStyle::Inverted) || (bottomStyle == SideStyle::Inverted);
|
|
|
|
previousRichWidth = richWidth;
|
|
|
|
|
2016-06-09 11:51:24 +00:00
|
|
|
if (bottomStyle == SideStyle::Inverted) {
|
|
|
|
topStyle = SideStyle::Rounded;
|
|
|
|
} else if (bottomStyle == SideStyle::Rounded) {
|
|
|
|
topStyle = SideStyle::Inverted;
|
|
|
|
} else {
|
|
|
|
topStyle = SideStyle::Plain;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<int> ServiceMessagePainter::countLineWidths(const Text &text, const QRect &textRect) {
|
|
|
|
int linesCount = qMax(textRect.height() / st::msgServiceFont->height, 1);
|
|
|
|
QVector<int> lineWidths;
|
|
|
|
lineWidths.reserve(linesCount);
|
|
|
|
text.countLineWidths(textRect.width(), &lineWidths);
|
|
|
|
|
2016-08-14 19:56:26 +00:00
|
|
|
int minDelta = 2 * (historyServiceMsgRadius() + historyServiceMsgInvertedRadius() - historyServiceMsgInvertedShrink());
|
2016-06-09 11:51:24 +00:00
|
|
|
for (int i = 0, count = lineWidths.size(); i < count; ++i) {
|
|
|
|
int width = qMax(lineWidths.at(i), 0);
|
|
|
|
if (i > 0) {
|
|
|
|
int widthBefore = lineWidths.at(i - 1);
|
|
|
|
if (width < widthBefore && width + minDelta > widthBefore) {
|
|
|
|
width = widthBefore;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i + 1 < count) {
|
|
|
|
int widthAfter = lineWidths.at(i + 1);
|
|
|
|
if (width < widthAfter && width + minDelta > widthAfter) {
|
|
|
|
width = widthAfter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (width > lineWidths.at(i)) {
|
|
|
|
lineWidths[i] = width;
|
|
|
|
if (i > 0) {
|
|
|
|
int widthBefore = lineWidths.at(i - 1);
|
|
|
|
if (widthBefore != width && widthBefore < width + minDelta && widthBefore + minDelta > width) {
|
|
|
|
i -= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lineWidths;
|
|
|
|
}
|
|
|
|
|
2016-10-22 18:58:25 +00:00
|
|
|
void paintEmpty(Painter &p, int width, int height) {
|
|
|
|
}
|
|
|
|
|
2016-06-09 11:51:24 +00:00
|
|
|
void serviceColorsUpdated() {
|
|
|
|
if (serviceMessageStyle) {
|
|
|
|
for (auto &corner : serviceMessageStyle->corners) {
|
|
|
|
corner = QPixmap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-19 17:10:58 +00:00
|
|
|
Service::Service(
|
|
|
|
not_null<ElementDelegate*> delegate,
|
|
|
|
not_null<HistoryService*> data)
|
|
|
|
: Element(delegate, data) {
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
not_null<HistoryService*> Service::message() const {
|
|
|
|
return static_cast<HistoryService*>(data().get());
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect Service::countGeometry() const {
|
|
|
|
auto result = QRect(0, 0, width(), height());
|
|
|
|
if (Adaptive::ChatWide()) {
|
|
|
|
result.setWidth(qMin(result.width(), st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()));
|
|
|
|
}
|
|
|
|
return result.marginsRemoved(st::msgServiceMargin);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize Service::performCountCurrentSize(int newWidth) {
|
|
|
|
const auto item = message();
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto media = this->media();
|
2018-01-13 12:45:11 +00:00
|
|
|
|
2018-01-23 11:47:38 +00:00
|
|
|
auto newHeight = displayedDateHeight();
|
2018-01-21 19:21:08 +00:00
|
|
|
if (const auto bar = Get<UnreadBar>()) {
|
|
|
|
newHeight += bar->height();
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item->_text.isEmpty()) {
|
|
|
|
item->_textHeight = 0;
|
2016-11-18 16:27:47 +00:00
|
|
|
} else {
|
2018-01-13 12:45:11 +00:00
|
|
|
auto contentWidth = newWidth;
|
|
|
|
if (Adaptive::ChatWide()) {
|
|
|
|
accumulate_min(contentWidth, st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left());
|
|
|
|
}
|
|
|
|
contentWidth -= st::msgServiceMargin.left() + st::msgServiceMargin.left(); // two small margins
|
|
|
|
if (contentWidth < st::msgServicePadding.left() + st::msgServicePadding.right() + 1) {
|
|
|
|
contentWidth = st::msgServicePadding.left() + st::msgServicePadding.right() + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto nwidth = qMax(contentWidth - st::msgServicePadding.left() - st::msgServicePadding.right(), 0);
|
|
|
|
if (nwidth != item->_textWidth) {
|
|
|
|
item->_textWidth = nwidth;
|
|
|
|
item->_textHeight = item->_text.countHeight(nwidth);
|
|
|
|
}
|
|
|
|
if (contentWidth >= maxWidth()) {
|
|
|
|
newHeight += minHeight();
|
|
|
|
} else {
|
|
|
|
newHeight += item->_textHeight;
|
|
|
|
}
|
|
|
|
newHeight += st::msgServicePadding.top() + st::msgServicePadding.bottom() + st::msgServiceMargin.top() + st::msgServiceMargin.bottom();
|
|
|
|
if (media) {
|
|
|
|
newHeight += st::msgServiceMargin.top() + media->resizeGetHeight(media->width());
|
|
|
|
}
|
2016-11-18 16:27:47 +00:00
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
|
|
|
|
return { newWidth, newHeight };
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize Service::performCountOptimalSize() {
|
|
|
|
const auto item = message();
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto media = this->media();
|
2018-01-13 12:45:11 +00:00
|
|
|
|
|
|
|
auto maxWidth = item->_text.maxWidth() + st::msgServicePadding.left() + st::msgServicePadding.right();
|
|
|
|
auto minHeight = item->_text.minHeight();
|
|
|
|
if (media) {
|
|
|
|
media->initDimensions();
|
|
|
|
}
|
|
|
|
return { maxWidth, minHeight };
|
|
|
|
}
|
|
|
|
|
|
|
|
void Service::draw(
|
|
|
|
Painter &p,
|
|
|
|
QRect clip,
|
|
|
|
TextSelection selection,
|
|
|
|
TimeMs ms) const {
|
|
|
|
const auto item = message();
|
|
|
|
auto g = countGeometry();
|
|
|
|
if (g.width() < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto height = this->height() - st::msgServiceMargin.top() - st::msgServiceMargin.bottom();
|
|
|
|
auto dateh = 0;
|
|
|
|
auto unreadbarh = 0;
|
2018-01-23 11:47:38 +00:00
|
|
|
if (auto date = Get<DateBadge>()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
dateh = date->height();
|
|
|
|
p.translate(0, dateh);
|
|
|
|
clip.translate(0, -dateh);
|
|
|
|
height -= dateh;
|
|
|
|
}
|
2018-01-21 19:21:08 +00:00
|
|
|
if (const auto bar = Get<UnreadBar>()) {
|
|
|
|
unreadbarh = bar->height();
|
2018-01-13 12:45:11 +00:00
|
|
|
if (clip.intersects(QRect(0, 0, width(), unreadbarh))) {
|
2018-01-21 19:21:08 +00:00
|
|
|
bar->paint(p, 0, width());
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
p.translate(0, unreadbarh);
|
|
|
|
clip.translate(0, -unreadbarh);
|
|
|
|
height -= unreadbarh;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto fullAnimMs = App::main() ? App::main()->highlightStartTime(item) : 0LL;
|
|
|
|
if (fullAnimMs > 0 && fullAnimMs <= ms) {
|
|
|
|
auto animms = ms - fullAnimMs;
|
|
|
|
if (animms < st::activeFadeInDuration + st::activeFadeOutDuration) {
|
|
|
|
auto top = st::msgServiceMargin.top();
|
|
|
|
auto bottom = st::msgServiceMargin.bottom();
|
|
|
|
auto fill = qMin(top, bottom);
|
|
|
|
auto skiptop = top - fill;
|
|
|
|
auto fillheight = fill + height + fill;
|
|
|
|
|
|
|
|
auto dt = (animms > st::activeFadeInDuration) ? (1. - (animms - st::activeFadeInDuration) / float64(st::activeFadeOutDuration)) : (animms / float64(st::activeFadeInDuration));
|
|
|
|
auto o = p.opacity();
|
|
|
|
p.setOpacity(o * dt);
|
2018-01-21 19:21:08 +00:00
|
|
|
p.fillRect(0, skiptop, width(), fillheight, st::defaultTextPalette.selectOverlay);
|
2018-01-13 12:45:11 +00:00
|
|
|
p.setOpacity(o);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p.setTextPalette(st::serviceTextPalette);
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
if (auto media = this->media()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
height -= st::msgServiceMargin.top() + media->height();
|
|
|
|
auto left = st::msgServiceMargin.left() + (g.width() - media->maxWidth()) / 2, top = st::msgServiceMargin.top() + height + st::msgServiceMargin.top();
|
|
|
|
p.translate(left, top);
|
2018-01-14 16:02:25 +00:00
|
|
|
media->draw(p, clip.translated(-left, -top), TextSelection(), ms);
|
2018-01-13 12:45:11 +00:00
|
|
|
p.translate(-left, -top);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto trect = QRect(g.left(), st::msgServiceMargin.top(), g.width(), height).marginsAdded(-st::msgServicePadding);
|
|
|
|
|
|
|
|
ServiceMessagePainter::paintComplexBubble(p, g.left(), g.width(), item->_text, trect);
|
|
|
|
|
|
|
|
p.setBrush(Qt::NoBrush);
|
|
|
|
p.setPen(st::msgServiceFg);
|
|
|
|
p.setFont(st::msgServiceFont);
|
|
|
|
item->_text.draw(p, trect.x(), trect.y(), trect.width(), Qt::AlignCenter, 0, -1, selection, false);
|
|
|
|
|
|
|
|
p.restoreTextPalette();
|
|
|
|
|
|
|
|
if (auto skiph = dateh + unreadbarh) {
|
|
|
|
p.translate(0, -skiph);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Service::hasPoint(QPoint point) const {
|
|
|
|
const auto item = message();
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto media = this->media();
|
2018-01-13 12:45:11 +00:00
|
|
|
|
|
|
|
auto g = countGeometry();
|
|
|
|
if (g.width() < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-23 11:47:38 +00:00
|
|
|
if (const auto dateh = displayedDateHeight()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
g.setTop(g.top() + dateh);
|
|
|
|
}
|
2018-01-21 19:21:08 +00:00
|
|
|
if (const auto bar = Get<UnreadBar>()) {
|
|
|
|
g.setTop(g.top() + bar->height());
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
if (media) {
|
|
|
|
g.setHeight(g.height() - (st::msgServiceMargin.top() + media->height()));
|
|
|
|
}
|
|
|
|
return g.contains(point);
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryTextState Service::getState(QPoint point, HistoryStateRequest request) const {
|
|
|
|
const auto item = message();
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto media = this->media();
|
2018-01-13 12:45:11 +00:00
|
|
|
|
|
|
|
auto result = HistoryTextState(item);
|
|
|
|
|
|
|
|
auto g = countGeometry();
|
|
|
|
if (g.width() < 1) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-01-23 11:47:38 +00:00
|
|
|
if (const auto dateh = displayedDateHeight()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
point.setY(point.y() - dateh);
|
|
|
|
g.setHeight(g.height() - dateh);
|
|
|
|
}
|
2018-01-21 19:21:08 +00:00
|
|
|
if (const auto bar = Get<UnreadBar>()) {
|
|
|
|
auto unreadbarh = bar->height();
|
2018-01-13 12:45:11 +00:00
|
|
|
point.setY(point.y() - unreadbarh);
|
|
|
|
g.setHeight(g.height() - unreadbarh);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (media) {
|
|
|
|
g.setHeight(g.height() - (st::msgServiceMargin.top() + media->height()));
|
|
|
|
}
|
|
|
|
auto trect = g.marginsAdded(-st::msgServicePadding);
|
|
|
|
if (trect.contains(point)) {
|
|
|
|
auto textRequest = request.forText();
|
|
|
|
textRequest.align = style::al_center;
|
|
|
|
result = HistoryTextState(item, item->_text.getState(
|
|
|
|
point - trect.topLeft(),
|
|
|
|
trect.width(),
|
|
|
|
textRequest));
|
|
|
|
if (auto gamescore = item->Get<HistoryServiceGameScore>()) {
|
|
|
|
if (!result.link && result.cursor == HistoryInTextCursorState && g.contains(point)) {
|
|
|
|
result.link = gamescore->lnk;
|
|
|
|
}
|
|
|
|
} else if (auto payment = item->Get<HistoryServicePayment>()) {
|
|
|
|
if (!result.link && result.cursor == HistoryInTextCursorState && g.contains(point)) {
|
|
|
|
result.link = payment->lnk;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (media) {
|
|
|
|
result = media->getState(point - QPoint(st::msgServiceMargin.left() + (g.width() - media->maxWidth()) / 2, st::msgServiceMargin.top() + g.height() + st::msgServiceMargin.top()), request);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Service::updatePressed(QPoint point) {
|
2016-11-18 16:27:47 +00:00
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
TextWithEntities Service::selectedText(TextSelection selection) const {
|
|
|
|
return message()->_text.originalTextWithEntities(
|
|
|
|
(selection == FullSelection) ? AllTextSelection : selection);
|
|
|
|
}
|
|
|
|
|
|
|
|
TextSelection Service::adjustSelection(
|
|
|
|
TextSelection selection,
|
|
|
|
TextSelectType type) const {
|
|
|
|
return message()->_text.adjustSelection(selection, type);
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
} // namespace HistoryView
|