some warnings fixed, new way of drawing avatars in message line

This commit is contained in:
Blue 2022-01-05 22:29:34 +03:00
parent e27ae1a82f
commit 7130e674c4
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
7 changed files with 65 additions and 16 deletions

View File

@ -601,6 +601,9 @@ void Core::Account::onClientError(QXmppClient::Error err)
errorText = "Policy violation"; errorText = "Policy violation";
break; break;
#endif #endif
default:
errorText = "Unknown Error";
break;
} }
errorType = "Client stream error"; errorType = "Client stream error";
@ -837,7 +840,6 @@ void Core::Account::uploadVCard(const Shared::VCard& card)
QXmppVCardIq iq; QXmppVCardIq iq;
initializeQXmppVCard(iq, card); initializeQXmppVCard(iq, card);
bool avatarChanged = false;
if (card.getAvatarType() != Shared::Avatar::empty) { if (card.getAvatarType() != Shared::Avatar::empty) {
QString newPath = card.getAvatarPath(); QString newPath = card.getAvatarPath();
QString oldPath = getAvatarPath(); QString oldPath = getAvatarPath();
@ -859,7 +861,6 @@ void Core::Account::uploadVCard(const Shared::VCard& card)
} }
} else { } else {
data = avatar.readAll(); data = avatar.readAll();
avatarChanged = true;
} }
} else { } else {
if (avatarType.size() > 0) { if (avatarType.size() > 0) {

View File

@ -264,7 +264,7 @@ void Core::initializeQXmppVCard(QXmppVCardIq& iq, const Shared::VCard& card) {
phone.setType(phone.type() | QXmppVCardPhone::Preferred); phone.setType(phone.type() | QXmppVCardPhone::Preferred);
} }
} }
for (const std::pair<QString, QXmppVCardPhone>& phone : phones) { for (const std::pair<const QString, QXmppVCardPhone>& phone : phones) {
phs.push_back(phone.second); phs.push_back(phone.second);
} }

View File

@ -356,7 +356,7 @@ Shared::VCard Core::Conference::handleResponseVCard(const QXmppVCardIq& card, co
QMap<QString, QVariant> Core::Conference::getAllAvatars() const QMap<QString, QVariant> Core::Conference::getAllAvatars() const
{ {
QMap<QString, QVariant> result; QMap<QString, QVariant> result;
for (const std::pair<QString, Archive::AvatarInfo>& pair : exParticipants) { for (const std::pair<const QString, Archive::AvatarInfo>& pair : exParticipants) {
result.insert(pair.first, avatarPath(pair.first) + "." + pair.second.type); result.insert(pair.first, avatarPath(pair.first) + "." + pair.second.type);
} }
return result; return result;

View File

@ -97,7 +97,10 @@ void Models::Accounts::addAccount(Account* account)
void Models::Accounts::onAccountChanged(Item* item, int row, int col) void Models::Accounts::onAccountChanged(Item* item, int row, int col)
{ {
if (row < accs.size()) { if (row < 0) {
return;
}
if (static_cast<std::deque<Models::Account*>::size_type>(row) < accs.size()) {
Account* acc = getAccount(row); Account* acc = getAccount(row);
if (item != acc) { if (item != acc) {
return; //it means the signal is emitted by one of accounts' children, not exactly him, this model has no interest in that return; //it means the signal is emitted by one of accounts' children, not exactly him, this model has no interest in that

View File

@ -31,6 +31,10 @@ constexpr int approximateSingleMessageHeight = 20;
constexpr int progressSize = 70; constexpr int progressSize = 70;
constexpr int dateDeviderMargin = 10; constexpr int dateDeviderMargin = 10;
constexpr int avatarHeight = 50;
constexpr int margin = 6;
constexpr int halfMargin = 3;
const std::set<int> FeedView::geometryChangingRoles = { const std::set<int> FeedView::geometryChangingRoles = {
Models::MessageFeed::Attach, Models::MessageFeed::Attach,
Models::MessageFeed::Text, Models::MessageFeed::Text,
@ -334,6 +338,20 @@ void FeedView::paintEvent(QPaintEvent* event)
drawDateDevider(option.rect.bottom(), lastDate, painter); drawDateDevider(option.rect.bottom(), lastDate, painter);
} }
lastDate = currentDate; lastDate = currentDate;
if ((option.rect.y() < 1) || (index.row() == m->rowCount() - 1)) {
drawAvatar(index, option, painter);
} else {
QString mySender = index.data(Models::MessageFeed::Sender).toString();
QModelIndex prevIndex = m->index(index.row() + 1, 0, rootIndex());
if (
(prevIndex.data(Models::MessageFeed::Sender).toString() != mySender) ||
(prevIndex.data(Models::MessageFeed::Date).toDateTime().daysTo(currentDate) != 0)
) {
drawAvatar(index, option, painter);
}
}
} }
if (!lastDate.isNull() && inZone) { //if after drawing all messages there is still space if (!lastDate.isNull() && inZone) { //if after drawing all messages there is still space
drawDateDevider(option.rect.bottom(), lastDate, painter); drawDateDevider(option.rect.bottom(), lastDate, painter);
@ -344,10 +362,6 @@ void FeedView::paintEvent(QPaintEvent* event)
del->endClearWidgets(); del->endClearWidgets();
clearWidgetsMode = false; clearWidgetsMode = false;
} }
if (event->rect().height() == vp->height()) {
// draw the blurred drop shadow...
}
} }
void FeedView::drawDateDevider(int top, const QDateTime& date, QPainter& painter) void FeedView::drawDateDevider(int top, const QDateTime& date, QPainter& painter)
@ -360,6 +374,40 @@ void FeedView::drawDateDevider(int top, const QDateTime& date, QPainter& painter
painter.restore(); painter.restore();
} }
void FeedView::drawAvatar(const QModelIndex& index, const QStyleOptionViewItem& option, QPainter& painter)
{
int currentRow = index.row();
int y = option.rect.y();
bool firstAttempt = true;
QString mySender = index.data(Models::MessageFeed::Sender).toString();
QDateTime currentDate = index.data(Models::MessageFeed::Date).toDateTime();
QIcon icon(index.data(Models::MessageFeed::Avatar).toString());
while (y < 0 && currentRow > 0) {
QRect rect;
if (firstAttempt) {
firstAttempt = false;
rect = option.rect;
} else {
QModelIndex ci = model()->index(currentRow, 0, rootIndex());
if (
(ci.data(Models::MessageFeed::Sender).toString() != mySender) ||
(ci.data(Models::MessageFeed::Date).toDateTime().daysTo(currentDate) != 0)
) {
break;
}
rect = visualRect(ci);
}
y = std::min(0, rect.bottom() - margin - avatarHeight);
--currentRow;
}
if (index.data(Models::MessageFeed::SentByMe).toBool()) {
painter.drawPixmap(option.rect.width() - avatarHeight - margin, y + halfMargin, icon.pixmap(avatarHeight, avatarHeight));
} else {
painter.drawPixmap(margin, y + halfMargin, icon.pixmap(avatarHeight, avatarHeight));
}
}
void FeedView::verticalScrollbarValueChanged(int value) void FeedView::verticalScrollbarValueChanged(int value)
{ {
vo = verticalScrollBar()->maximum() - value; vo = verticalScrollBar()->maximum() - value;

View File

@ -74,6 +74,7 @@ private:
bool tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewItem& option, const QAbstractItemModel* model, uint32_t totalHeight); bool tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewItem& option, const QAbstractItemModel* model, uint32_t totalHeight);
void positionProgress(); void positionProgress();
void drawDateDevider(int top, const QDateTime& date, QPainter& painter); void drawDateDevider(int top, const QDateTime& date, QPainter& painter);
void drawAvatar(const QModelIndex& index, const QStyleOptionViewItem& option, QPainter& painter);
private: private:
struct Hint { struct Hint {

View File

@ -104,13 +104,7 @@ void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
painter->fillRect(option.rect, option.palette.brush(QPalette::Inactive, QPalette::Highlight)); painter->fillRect(option.rect, option.palette.brush(QPalette::Inactive, QPalette::Highlight));
} }
QIcon icon(data.avatar);
if (data.sentByMe) {
painter->drawPixmap(option.rect.width() - avatarHeight - margin, option.rect.y() + margin / 2, icon.pixmap(avatarHeight, avatarHeight));
} else {
painter->drawPixmap(margin, option.rect.y() + margin / 2, icon.pixmap(avatarHeight, avatarHeight));
}
QStyleOptionViewItem opt = option; QStyleOptionViewItem opt = option;
QRect messageRect = option.rect.adjusted(margin, margin / 2, -(avatarHeight + 2 * margin), -margin / 2); QRect messageRect = option.rect.adjusted(margin, margin / 2, -(avatarHeight + 2 * margin), -margin / 2);
@ -163,6 +157,7 @@ void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
break; //but it's a possible performance problem break; //but it's a possible performance problem
case Models::uploading: case Models::uploading:
paintPreview(data, painter, opt); paintPreview(data, painter, opt);
[[fallthrough]];
case Models::downloading: case Models::downloading:
paintBar(getBar(data), painter, data.sentByMe, opt); paintBar(getBar(data), painter, data.sentByMe, opt);
break; break;
@ -268,6 +263,7 @@ QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel
break; break;
case Models::uploading: case Models::uploading:
messageSize.rheight() += Preview::calculateAttachSize(attach.localPath, messageRect).height() + textMargin; messageSize.rheight() += Preview::calculateAttachSize(attach.localPath, messageRect).height() + textMargin;
[[fallthrough]];
case Models::downloading: case Models::downloading:
messageSize.rheight() += barHeight + textMargin; messageSize.rheight() += barHeight + textMargin;
break; break;