2016-04-09 18:45:55 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-04-09 18:45:55 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "dialogs/dialogs_layout.h"
|
|
|
|
|
2016-06-09 11:51:24 +00:00
|
|
|
#include "data/data_abstract_structure.h"
|
2016-06-09 14:31:10 +00:00
|
|
|
#include "data/data_drafts.h"
|
2016-04-09 18:45:55 +00:00
|
|
|
#include "dialogs/dialogs_list.h"
|
2016-05-31 09:46:31 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
|
|
|
#include "localstorage.h"
|
2016-04-09 18:45:55 +00:00
|
|
|
#include "lang.h"
|
|
|
|
|
|
|
|
namespace Dialogs {
|
|
|
|
namespace Layout {
|
2016-04-09 20:41:20 +00:00
|
|
|
namespace {
|
|
|
|
|
2016-07-26 12:09:40 +00:00
|
|
|
// Show all dates that are in the last 20 hours in time format.
|
|
|
|
constexpr int kRecentlyInSeconds = 20 * 3600;
|
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
void paintRowDate(Painter &p, const QDateTime &date, QRect &rectForName, bool active, bool selected) {
|
|
|
|
auto now = QDateTime::currentDateTime();
|
|
|
|
auto lastTime = date;
|
|
|
|
auto nowDate = now.date();
|
|
|
|
auto lastDate = lastTime.date();
|
|
|
|
|
2016-06-03 18:24:27 +00:00
|
|
|
QString dt;
|
2016-07-26 12:09:40 +00:00
|
|
|
bool wasSameDay = (lastDate == nowDate);
|
|
|
|
bool wasRecently = qAbs(lastTime.secsTo(now)) < kRecentlyInSeconds;
|
|
|
|
if (wasSameDay || wasRecently) {
|
2016-06-03 18:24:27 +00:00
|
|
|
dt = lastTime.toString(cTimeFormat());
|
|
|
|
} else if (lastDate.year() == nowDate.year() && lastDate.weekNumber() == nowDate.weekNumber()) {
|
|
|
|
dt = langDayOfWeek(lastDate);
|
|
|
|
} else {
|
|
|
|
dt = lastDate.toString(qsl("d.MM.yy"));
|
|
|
|
}
|
2016-06-07 19:59:39 +00:00
|
|
|
int32 dtWidth = st::dialogsDateFont->width(dt);
|
|
|
|
rectForName.setWidth(rectForName.width() - dtWidth - st::dialogsDateSkip);
|
|
|
|
p.setFont(st::dialogsDateFont);
|
2016-11-05 08:36:24 +00:00
|
|
|
p.setPen(active ? st::dialogsDateFgActive : (selected ? st::dialogsDateFgOver : st::dialogsDateFg));
|
2016-06-07 19:59:39 +00:00
|
|
|
p.drawText(rectForName.left() + rectForName.width() + st::dialogsDateSkip, rectForName.top() + st::msgNameFont->height - st::msgDateFont->descent, dt);
|
2016-06-03 18:24:27 +00:00
|
|
|
}
|
|
|
|
|
2017-01-14 18:50:16 +00:00
|
|
|
template <typename PaintItemCallback, typename PaintCounterCallback>
|
|
|
|
void paintRow(Painter &p, const RippleRow *row, History *history, HistoryItem *item, Data::Draft *draft, QDateTime date, int fullWidth, bool active, bool selected, bool onlyBackground, TimeMs ms, PaintItemCallback paintItemCallback, PaintCounterCallback paintCounterCallback) {
|
2016-12-05 11:01:08 +00:00
|
|
|
QRect fullRect(0, 0, fullWidth, st::dialogsRowHeight);
|
2016-06-07 19:59:39 +00:00
|
|
|
p.fillRect(fullRect, active ? st::dialogsBgActive : (selected ? st::dialogsBgOver : st::dialogsBg));
|
2016-12-05 11:01:08 +00:00
|
|
|
row->paintRipple(p, 0, 0, fullWidth, ms, &(active ? st::dialogsRippleBgActive : st::dialogsRippleBg)->c);
|
2016-04-09 18:45:55 +00:00
|
|
|
if (onlyBackground) return;
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto userpicPeer = (history->peer->migrateTo() ? history->peer->migrateTo() : history->peer);
|
2016-12-29 09:03:51 +00:00
|
|
|
userpicPeer->paintUserpicLeft(p, st::dialogsPadding.x(), st::dialogsPadding.y(), fullWidth, st::dialogsPhotoSize);
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto nameleft = st::dialogsPadding.x() + st::dialogsPhotoSize + st::dialogsPhotoPadding;
|
2017-01-14 18:50:16 +00:00
|
|
|
if (fullWidth <= nameleft) {
|
|
|
|
if (!draft && item && !item->isEmpty()) {
|
|
|
|
paintCounterCallback();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto namewidth = fullWidth - nameleft - st::dialogsPadding.x();
|
2016-06-07 19:59:39 +00:00
|
|
|
QRect rectForName(nameleft, st::dialogsPadding.y() + st::dialogsNameTop, namewidth, st::msgNameFont->height);
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
if (auto chatTypeIcon = ChatTypeIcon(history->peer, active, selected)) {
|
2016-12-05 11:01:08 +00:00
|
|
|
chatTypeIcon->paint(p, rectForName.topLeft(), fullWidth);
|
2016-09-30 12:52:03 +00:00
|
|
|
rectForName.setLeft(rectForName.left() + st::dialogsChatTypeSkip);
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 19:59:39 +00:00
|
|
|
int texttop = st::dialogsPadding.y() + st::msgNameFont->height + st::dialogsSkip;
|
2016-06-03 18:24:27 +00:00
|
|
|
if (draft) {
|
2016-11-05 08:36:24 +00:00
|
|
|
paintRowDate(p, date, rectForName, active, selected);
|
2016-06-03 18:24:27 +00:00
|
|
|
|
2017-01-02 17:11:49 +00:00
|
|
|
auto availableWidth = namewidth;
|
|
|
|
if (history->isPinnedDialog()) {
|
|
|
|
auto &icon = (active ? st::dialogsPinnedIconActive : (selected ? st::dialogsPinnedIconOver : st::dialogsPinnedIcon));
|
|
|
|
icon.paint(p, fullWidth - st::dialogsPadding.x() - icon.width(), texttop, fullWidth);
|
|
|
|
availableWidth -= icon.width() + st::dialogsUnreadPadding;
|
|
|
|
}
|
|
|
|
|
2016-06-07 19:59:39 +00:00
|
|
|
p.setFont(st::dialogsTextFont);
|
2016-12-01 19:20:33 +00:00
|
|
|
auto &color = active ? st::dialogsTextFgServiceActive : (selected ? st::dialogsTextFgServiceOver : st::dialogsTextFgService);
|
2017-01-02 17:11:49 +00:00
|
|
|
if (!history->paintSendAction(p, nameleft, texttop, availableWidth, fullWidth, color, ms)) {
|
2016-06-03 18:24:27 +00:00
|
|
|
if (history->cloudDraftTextCache.isEmpty()) {
|
2016-06-22 13:39:54 +00:00
|
|
|
auto draftWrapped = textcmdLink(1, lng_dialogs_text_from_wrapped(lt_from, lang(lng_from_draft)));
|
|
|
|
auto draftText = lng_dialogs_text_with_from(lt_from_part, draftWrapped, lt_message, textClean(draft->textWithTags.text));
|
2016-12-23 13:21:01 +00:00
|
|
|
history->cloudDraftTextCache.setText(st::dialogsTextStyle, draftText, _textDlgOptions);
|
2016-06-03 18:24:27 +00:00
|
|
|
}
|
2016-11-05 08:36:24 +00:00
|
|
|
p.setPen(active ? st::dialogsTextFgActive : (selected ? st::dialogsTextFgOver : st::dialogsTextFg));
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setTextPalette(active ? st::dialogsTextPaletteDraftActive : (selected ? st::dialogsTextPaletteDraftOver : st::dialogsTextPaletteDraft));
|
2017-01-02 17:11:49 +00:00
|
|
|
history->cloudDraftTextCache.drawElided(p, nameleft, texttop, availableWidth, 1);
|
2016-12-23 13:21:01 +00:00
|
|
|
p.restoreTextPalette();
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2016-06-03 18:24:27 +00:00
|
|
|
} else if (!item) {
|
2017-02-16 16:47:50 +00:00
|
|
|
auto availableWidth = namewidth;
|
|
|
|
if (history->isPinnedDialog()) {
|
|
|
|
auto &icon = (active ? st::dialogsPinnedIconActive : (selected ? st::dialogsPinnedIconOver : st::dialogsPinnedIcon));
|
|
|
|
icon.paint(p, fullWidth - st::dialogsPadding.x() - icon.width(), texttop, fullWidth);
|
|
|
|
availableWidth -= icon.width() + st::dialogsUnreadPadding;
|
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
auto &color = active ? st::dialogsTextFgServiceActive : (selected ? st::dialogsTextFgServiceOver : st::dialogsTextFgService);
|
2016-06-07 19:59:39 +00:00
|
|
|
p.setFont(st::dialogsTextFont);
|
2017-02-16 16:47:50 +00:00
|
|
|
if (!history->paintSendAction(p, nameleft, texttop, availableWidth, fullWidth, color, ms)) {
|
2017-01-14 18:50:16 +00:00
|
|
|
// Empty history
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2016-06-08 19:14:17 +00:00
|
|
|
} else if (!item->isEmpty()) {
|
2016-11-05 08:36:24 +00:00
|
|
|
paintRowDate(p, date, rectForName, active, selected);
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2016-09-30 12:52:03 +00:00
|
|
|
paintItemCallback(nameleft, namewidth, item);
|
2017-02-16 16:47:50 +00:00
|
|
|
} else if (history->isPinnedDialog()) {
|
|
|
|
auto availableWidth = namewidth;
|
|
|
|
auto &icon = (active ? st::dialogsPinnedIconActive : (selected ? st::dialogsPinnedIconOver : st::dialogsPinnedIcon));
|
|
|
|
icon.paint(p, fullWidth - st::dialogsPadding.x() - icon.width(), texttop, fullWidth);
|
|
|
|
availableWidth -= icon.width() + st::dialogsUnreadPadding;
|
2016-09-30 12:52:03 +00:00
|
|
|
}
|
2016-11-05 08:36:24 +00:00
|
|
|
auto sendStateIcon = ([draft, item, active, selected]() -> const style::icon* {
|
2016-09-30 12:52:03 +00:00
|
|
|
if (draft) {
|
|
|
|
if (draft->saveRequestId) {
|
2016-11-05 08:36:24 +00:00
|
|
|
return &(active ? st::dialogsSendingIconActive : (selected ? st::dialogsSendingIconOver : st::dialogsSendingIcon));
|
2016-09-30 12:52:03 +00:00
|
|
|
}
|
|
|
|
} else if (item && !item->isEmpty() && item->needCheck()) {
|
2016-04-09 20:41:20 +00:00
|
|
|
if (item->id > 0) {
|
|
|
|
if (item->unread()) {
|
2016-11-05 08:36:24 +00:00
|
|
|
return &(active ? st::dialogsSentIconActive : (selected ? st::dialogsSentIconOver : st::dialogsSentIcon));
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2016-11-05 08:36:24 +00:00
|
|
|
return &(active ? st::dialogsReceivedIconActive : (selected ? st::dialogsReceivedIconOver : st::dialogsReceivedIcon));
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2016-11-05 08:36:24 +00:00
|
|
|
return &(active ? st::dialogsSendingIconActive : (selected ? st::dialogsSendingIconOver : st::dialogsSendingIcon));
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
2016-09-30 12:52:03 +00:00
|
|
|
return nullptr;
|
|
|
|
})();
|
|
|
|
if (sendStateIcon) {
|
|
|
|
rectForName.setWidth(rectForName.width() - st::dialogsSendStateSkip);
|
2016-12-05 11:01:08 +00:00
|
|
|
sendStateIcon->paint(p, rectForName.topLeft() + QPoint(rectForName.width(), 0), fullWidth);
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
if (history->peer->isVerified()) {
|
2016-11-05 08:36:24 +00:00
|
|
|
auto icon = &(active ? st::dialogsVerifiedIconActive : (selected ? st::dialogsVerifiedIconOver : st::dialogsVerifiedIcon));
|
2016-09-30 12:52:03 +00:00
|
|
|
rectForName.setWidth(rectForName.width() - icon->width());
|
2016-12-05 11:01:08 +00:00
|
|
|
icon->paint(p, rectForName.topLeft() + QPoint(qMin(history->peer->dialogName().maxWidth(), rectForName.width()), 0), fullWidth);
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
p.setPen(active ? st::dialogsNameFgActive : (selected ? st::dialogsNameFgOver : st::dialogsNameFg));
|
2016-04-09 20:41:20 +00:00
|
|
|
history->peer->dialogName().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width());
|
|
|
|
}
|
|
|
|
|
2016-06-21 15:58:07 +00:00
|
|
|
struct UnreadBadgeSizeData {
|
2016-04-09 20:41:20 +00:00
|
|
|
QImage circle;
|
2016-11-07 11:24:19 +00:00
|
|
|
QPixmap left[6], right[6];
|
2016-06-21 15:58:07 +00:00
|
|
|
};
|
|
|
|
class UnreadBadgeStyleData : public Data::AbstractStructure {
|
|
|
|
public:
|
|
|
|
UnreadBadgeSizeData sizes[UnreadBadgeSizesCount];
|
2016-12-23 13:21:01 +00:00
|
|
|
style::color bg[6] = {
|
|
|
|
st::dialogsUnreadBg,
|
|
|
|
st::dialogsUnreadBgOver,
|
|
|
|
st::dialogsUnreadBgActive,
|
|
|
|
st::dialogsUnreadBgMuted,
|
|
|
|
st::dialogsUnreadBgMutedOver,
|
|
|
|
st::dialogsUnreadBgMutedActive
|
2016-11-03 10:33:57 +00:00
|
|
|
};
|
2016-04-09 20:41:20 +00:00
|
|
|
};
|
2016-06-09 11:51:24 +00:00
|
|
|
Data::GlobalStructurePointer<UnreadBadgeStyleData> unreadBadgeStyle;
|
2016-04-09 20:41:20 +00:00
|
|
|
|
2016-06-21 15:58:07 +00:00
|
|
|
void createCircleMask(UnreadBadgeSizeData *data, int size) {
|
|
|
|
if (!data->circle.isNull()) return;
|
2016-04-09 20:41:20 +00:00
|
|
|
|
2016-06-21 15:58:07 +00:00
|
|
|
data->circle = style::createCircleMask(size);
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
QImage colorizeCircleHalf(UnreadBadgeSizeData *data, int size, int half, int xoffset, style::color color) {
|
2016-06-21 15:58:07 +00:00
|
|
|
auto result = style::colorizeImage(data->circle, color, QRect(xoffset, 0, half, size));
|
2016-04-09 20:41:20 +00:00
|
|
|
result.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-06-03 12:45:33 +00:00
|
|
|
} // namepsace
|
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
const style::icon *ChatTypeIcon(PeerData *peer, bool active, bool selected) {
|
2016-09-30 12:52:03 +00:00
|
|
|
if (peer->isChat() || peer->isMegagroup()) {
|
2016-11-05 08:36:24 +00:00
|
|
|
return &(active ? st::dialogsChatIconActive : (selected ? st::dialogsChatIconOver : st::dialogsChatIcon));
|
2016-09-30 12:52:03 +00:00
|
|
|
} else if (peer->isChannel()) {
|
2016-11-05 08:36:24 +00:00
|
|
|
return &(active ? st::dialogsChannelIconActive : (selected ? st::dialogsChannelIconOver : st::dialogsChannelIcon));
|
2016-09-30 12:52:03 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-06-21 15:58:07 +00:00
|
|
|
void paintUnreadBadge(Painter &p, const QRect &rect, const UnreadBadgeStyle &st) {
|
|
|
|
t_assert(rect.height() == st.size);
|
|
|
|
|
2016-11-07 11:24:19 +00:00
|
|
|
int index = (st.muted ? 0x03 : 0x00) + (st.active ? 0x02 : (st.selected ? 0x01 : 0x00));
|
2016-06-21 15:58:07 +00:00
|
|
|
int size = st.size, sizehalf = size / 2;
|
2016-04-09 20:41:20 +00:00
|
|
|
|
|
|
|
unreadBadgeStyle.createIfNull();
|
2016-06-21 15:58:07 +00:00
|
|
|
auto badgeData = unreadBadgeStyle->sizes;
|
|
|
|
if (st.sizeId > 0) {
|
|
|
|
t_assert(st.sizeId < UnreadBadgeSizesCount);
|
|
|
|
badgeData = &unreadBadgeStyle->sizes[st.sizeId];
|
|
|
|
}
|
2016-11-03 10:33:57 +00:00
|
|
|
auto bg = unreadBadgeStyle->bg[index];
|
2016-06-21 15:58:07 +00:00
|
|
|
if (badgeData->left[index].isNull()) {
|
2016-04-09 20:41:20 +00:00
|
|
|
int imgsize = size * cIntRetinaFactor(), imgsizehalf = sizehalf * cIntRetinaFactor();
|
2016-06-21 15:58:07 +00:00
|
|
|
createCircleMask(badgeData, size);
|
2016-12-23 13:21:01 +00:00
|
|
|
badgeData->left[index] = App::pixmapFromImageInPlace(colorizeCircleHalf(badgeData, imgsize, imgsizehalf, 0, bg));
|
|
|
|
badgeData->right[index] = App::pixmapFromImageInPlace(colorizeCircleHalf(badgeData, imgsize, imgsizehalf, imgsize - imgsizehalf, bg));
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2016-04-09 20:41:20 +00:00
|
|
|
int bar = rect.width() - 2 * sizehalf;
|
2016-06-21 15:58:07 +00:00
|
|
|
p.drawPixmap(rect.x(), rect.y(), badgeData->left[index]);
|
2016-04-09 20:41:20 +00:00
|
|
|
if (bar) {
|
2016-12-23 13:21:01 +00:00
|
|
|
p.fillRect(rect.x() + sizehalf, rect.y(), bar, rect.height(), bg);
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
2016-06-21 15:58:07 +00:00
|
|
|
p.drawPixmap(rect.x() + sizehalf + bar, rect.y(), badgeData->right[index]);
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 15:58:07 +00:00
|
|
|
UnreadBadgeStyle::UnreadBadgeStyle()
|
|
|
|
: align(style::al_right)
|
|
|
|
, active(false)
|
2016-11-07 11:24:19 +00:00
|
|
|
, selected(false)
|
2016-06-21 15:58:07 +00:00
|
|
|
, muted(false)
|
|
|
|
, size(st::dialogsUnreadHeight)
|
2016-11-22 09:48:13 +00:00
|
|
|
, padding(st::dialogsUnreadPadding)
|
2016-06-21 15:58:07 +00:00
|
|
|
, sizeId(UnreadBadgeInDialogs)
|
|
|
|
, font(st::dialogsUnreadFont) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void paintUnreadCount(Painter &p, const QString &text, int x, int y, const UnreadBadgeStyle &st, int *outUnreadWidth) {
|
|
|
|
int unreadWidth = st.font->width(text);
|
2016-11-22 09:48:13 +00:00
|
|
|
int unreadRectWidth = unreadWidth + 2 * st.padding;
|
2016-06-21 15:58:07 +00:00
|
|
|
int unreadRectHeight = st.size;
|
2016-04-11 10:59:01 +00:00
|
|
|
accumulate_max(unreadRectWidth, unreadRectHeight);
|
|
|
|
|
2016-06-03 12:45:33 +00:00
|
|
|
int unreadRectLeft = x;
|
2016-06-21 15:58:07 +00:00
|
|
|
if ((st.align & Qt::AlignHorizontal_Mask) & style::al_center) {
|
2016-06-03 12:45:33 +00:00
|
|
|
unreadRectLeft = (x - unreadRectWidth) / 2;
|
2016-06-21 15:58:07 +00:00
|
|
|
} else if ((st.align & Qt::AlignHorizontal_Mask) & style::al_right) {
|
2016-06-03 12:45:33 +00:00
|
|
|
unreadRectLeft = x - unreadRectWidth;
|
|
|
|
}
|
|
|
|
int unreadRectTop = y;
|
|
|
|
if (outUnreadWidth) {
|
|
|
|
*outUnreadWidth = unreadRectWidth;
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 15:58:07 +00:00
|
|
|
paintUnreadBadge(p, QRect(unreadRectLeft, unreadRectTop, unreadRectWidth, unreadRectHeight), st);
|
2016-04-11 10:59:01 +00:00
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
auto textTop = st.textTop ? st.textTop : (unreadRectHeight - st.font->height) / 2;
|
2016-06-21 15:58:07 +00:00
|
|
|
p.setFont(st.font);
|
2016-11-07 11:24:19 +00:00
|
|
|
p.setPen(st.active ? st::dialogsUnreadFgActive : (st.selected ? st::dialogsUnreadFgOver : st::dialogsUnreadFg));
|
2016-11-22 09:48:13 +00:00
|
|
|
p.drawText(unreadRectLeft + (unreadRectWidth - unreadWidth) / 2, unreadRectTop + textTop + st.font->ascent, text);
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void RowPainter::paint(Painter &p, const Row *row, int fullWidth, bool active, bool selected, bool onlyBackground, TimeMs ms) {
|
2016-04-09 20:41:20 +00:00
|
|
|
auto history = row->history();
|
|
|
|
auto item = history->lastMsg;
|
2016-06-03 18:24:27 +00:00
|
|
|
auto cloudDraft = history->cloudDraft();
|
2016-06-13 18:42:25 +00:00
|
|
|
if (Data::draftIsNull(cloudDraft)) {
|
|
|
|
cloudDraft = nullptr;
|
2016-06-03 18:24:27 +00:00
|
|
|
}
|
2016-06-13 18:42:25 +00:00
|
|
|
auto displayDate = [item, cloudDraft]() {
|
|
|
|
if (item) {
|
|
|
|
if (cloudDraft) {
|
|
|
|
return (item->date > cloudDraft->date) ? item->date : cloudDraft->date;
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2016-06-13 18:42:25 +00:00
|
|
|
return item->date;
|
|
|
|
}
|
|
|
|
return cloudDraft ? cloudDraft->date : QDateTime();
|
|
|
|
};
|
|
|
|
int unreadCount = history->unreadCount();
|
|
|
|
if (history->peer->migrateFrom()) {
|
|
|
|
if (auto migrated = App::historyLoaded(history->peer->migrateFrom()->id)) {
|
|
|
|
unreadCount += migrated->unreadCount();
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2016-06-13 18:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item && cloudDraft && unreadCount > 0) {
|
|
|
|
cloudDraft = nullptr; // Draw item, if draft is older.
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
paintRow(p, row, history, item, cloudDraft, displayDate(), fullWidth, active, selected, onlyBackground, ms, [&p, fullWidth, active, selected, ms, history, unreadCount](int nameleft, int namewidth, HistoryItem *item) {
|
2016-04-11 10:59:01 +00:00
|
|
|
int availableWidth = namewidth;
|
2016-06-07 19:59:39 +00:00
|
|
|
int texttop = st::dialogsPadding.y() + st::msgNameFont->height + st::dialogsSkip;
|
2016-06-13 18:42:25 +00:00
|
|
|
if (unreadCount) {
|
|
|
|
auto counter = QString::number(unreadCount);
|
2016-06-07 19:59:39 +00:00
|
|
|
auto mutedCounter = history->mute();
|
2016-12-05 11:01:08 +00:00
|
|
|
auto unreadRight = fullWidth - st::dialogsPadding.x();
|
|
|
|
auto unreadTop = texttop + st::dialogsTextFont->ascent - st::dialogsUnreadFont->ascent - (st::dialogsUnreadHeight - st::dialogsUnreadFont->height) / 2;
|
|
|
|
auto unreadWidth = 0;
|
2016-06-21 15:58:07 +00:00
|
|
|
|
|
|
|
UnreadBadgeStyle st;
|
|
|
|
st.active = active;
|
|
|
|
st.muted = history->mute();
|
|
|
|
paintUnreadCount(p, counter, unreadRight, unreadTop, st, &unreadWidth);
|
2016-11-22 09:48:13 +00:00
|
|
|
availableWidth -= unreadWidth + st.padding;
|
2016-12-13 07:59:57 +00:00
|
|
|
} else if (history->isPinnedDialog()) {
|
|
|
|
auto &icon = (active ? st::dialogsPinnedIconActive : (selected ? st::dialogsPinnedIconOver : st::dialogsPinnedIcon));
|
|
|
|
icon.paint(p, fullWidth - st::dialogsPadding.x() - icon.width(), texttop, fullWidth);
|
|
|
|
availableWidth -= icon.width() + st::dialogsUnreadPadding;
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2016-12-01 19:20:33 +00:00
|
|
|
auto &color = active ? st::dialogsTextFgServiceActive : (selected ? st::dialogsTextFgServiceOver : st::dialogsTextFgService);
|
2016-12-05 11:01:08 +00:00
|
|
|
if (!history->paintSendAction(p, nameleft, texttop, availableWidth, fullWidth, color, ms)) {
|
2016-11-05 08:36:24 +00:00
|
|
|
item->drawInDialog(p, QRect(nameleft, texttop, availableWidth, st::dialogsTextFont->height), active, selected, history->textCachedFor, history->lastItemTextCache);
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2017-01-14 18:50:16 +00:00
|
|
|
}, [&p, fullWidth, active, selected, ms, history, unreadCount] {
|
|
|
|
if (unreadCount) {
|
|
|
|
auto counter = QString::number(unreadCount);
|
|
|
|
if (counter.size() > 4) {
|
|
|
|
counter = qsl("..") + counter.mid(counter.size() - 3);
|
|
|
|
}
|
|
|
|
auto mutedCounter = history->mute();
|
|
|
|
auto unreadRight = st::dialogsPadding.x() + st::dialogsPhotoSize;
|
|
|
|
auto unreadTop = st::dialogsPadding.y() + st::dialogsPhotoSize - st::dialogsUnreadHeight;
|
|
|
|
auto unreadWidth = 0;
|
|
|
|
|
|
|
|
UnreadBadgeStyle st;
|
|
|
|
st.active = active;
|
|
|
|
st.muted = history->mute();
|
|
|
|
paintUnreadCount(p, counter, unreadRight, unreadTop, st, &unreadWidth);
|
|
|
|
}
|
2016-04-09 20:41:20 +00:00
|
|
|
});
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void RowPainter::paint(Painter &p, const FakeRow *row, int fullWidth, bool active, bool selected, bool onlyBackground, TimeMs ms) {
|
2016-04-09 18:45:55 +00:00
|
|
|
auto item = row->item();
|
|
|
|
auto history = item->history();
|
2016-12-05 11:01:08 +00:00
|
|
|
paintRow(p, row, history, item, nullptr, item->date, fullWidth, active, selected, onlyBackground, ms, [&p, row, active, selected](int nameleft, int namewidth, HistoryItem *item) {
|
2016-06-07 19:59:39 +00:00
|
|
|
int lastWidth = namewidth, texttop = st::dialogsPadding.y() + st::msgNameFont->height + st::dialogsSkip;
|
2016-11-05 08:36:24 +00:00
|
|
|
item->drawInDialog(p, QRect(nameleft, texttop, lastWidth, st::dialogsTextFont->height), active, selected, row->_cacheFor, row->_cache);
|
2017-01-14 18:50:16 +00:00
|
|
|
}, [] {
|
2016-04-09 20:41:20 +00:00
|
|
|
});
|
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2016-12-05 08:45:56 +00:00
|
|
|
QRect RowPainter::sendActionAnimationRect(int animationWidth, int animationHeight, int fullWidth, bool textUpdated) {
|
|
|
|
auto nameleft = st::dialogsPadding.x() + st::dialogsPhotoSize + st::dialogsPhotoPadding;
|
|
|
|
auto namewidth = fullWidth - nameleft - st::dialogsPadding.x();
|
|
|
|
auto texttop = st::dialogsPadding.y() + st::msgNameFont->height + st::dialogsSkip;
|
|
|
|
return QRect(nameleft, texttop, textUpdated ? namewidth : animationWidth, animationHeight);
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void paintImportantSwitch(Painter &p, Mode current, int fullWidth, bool selected, bool onlyBackground) {
|
|
|
|
p.fillRect(0, 0, fullWidth, st::dialogsImportantBarHeight, selected ? st::dialogsBgOver : st::dialogsBg);
|
2016-04-11 10:59:01 +00:00
|
|
|
if (onlyBackground) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
p.setFont(st::semiboldFont);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::dialogsNameFg);
|
2016-04-11 10:59:01 +00:00
|
|
|
|
2016-06-07 19:59:39 +00:00
|
|
|
int unreadTop = (st::dialogsImportantBarHeight - st::dialogsUnreadHeight) / 2;
|
2016-04-11 10:59:01 +00:00
|
|
|
bool mutedHidden = (current == Dialogs::Mode::Important);
|
2016-10-31 12:29:26 +00:00
|
|
|
QString text = lang(mutedHidden ? lng_dialogs_show_all_chats : lng_dialogs_hide_muted_chats);
|
2016-06-28 18:05:38 +00:00
|
|
|
int textBaseline = unreadTop + (st::dialogsUnreadHeight - st::dialogsUnreadFont->height) / 2 + st::dialogsUnreadFont->ascent;
|
2016-06-07 19:59:39 +00:00
|
|
|
p.drawText(st::dialogsPadding.x(), textBaseline, text);
|
2016-04-11 10:59:01 +00:00
|
|
|
|
|
|
|
if (mutedHidden) {
|
|
|
|
if (int32 unread = App::histories().unreadMutedCount()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
int unreadRight = fullWidth - st::dialogsPadding.x();
|
2016-06-21 15:58:07 +00:00
|
|
|
UnreadBadgeStyle st;
|
|
|
|
st.muted = true;
|
|
|
|
paintUnreadCount(p, QString::number(unread), unreadRight, unreadTop, st, nullptr);
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-31 13:34:41 +00:00
|
|
|
void clearUnreadBadgesCache() {
|
|
|
|
if (unreadBadgeStyle) {
|
|
|
|
for (auto &data : unreadBadgeStyle->sizes) {
|
|
|
|
for (auto &left : data.left) {
|
|
|
|
left = QPixmap();
|
|
|
|
}
|
|
|
|
for (auto &right : data.right) {
|
|
|
|
right = QPixmap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-09 18:45:55 +00:00
|
|
|
} // namespace Layout
|
|
|
|
} // namespace Dialogs
|