some warnings fixed, new way of drawing avatars in message line
This commit is contained in:
parent
e27ae1a82f
commit
7130e674c4
@ -601,6 +601,9 @@ void Core::Account::onClientError(QXmppClient::Error err)
|
||||
errorText = "Policy violation";
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
errorText = "Unknown Error";
|
||||
break;
|
||||
}
|
||||
|
||||
errorType = "Client stream error";
|
||||
@ -837,7 +840,6 @@ void Core::Account::uploadVCard(const Shared::VCard& card)
|
||||
QXmppVCardIq iq;
|
||||
initializeQXmppVCard(iq, card);
|
||||
|
||||
bool avatarChanged = false;
|
||||
if (card.getAvatarType() != Shared::Avatar::empty) {
|
||||
QString newPath = card.getAvatarPath();
|
||||
QString oldPath = getAvatarPath();
|
||||
@ -859,7 +861,6 @@ void Core::Account::uploadVCard(const Shared::VCard& card)
|
||||
}
|
||||
} else {
|
||||
data = avatar.readAll();
|
||||
avatarChanged = true;
|
||||
}
|
||||
} else {
|
||||
if (avatarType.size() > 0) {
|
||||
|
@ -264,7 +264,7 @@ void Core::initializeQXmppVCard(QXmppVCardIq& iq, const Shared::VCard& card) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -356,7 +356,7 @@ Shared::VCard Core::Conference::handleResponseVCard(const QXmppVCardIq& card, co
|
||||
QMap<QString, QVariant> Core::Conference::getAllAvatars() const
|
||||
{
|
||||
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);
|
||||
}
|
||||
return result;
|
||||
|
@ -97,7 +97,10 @@ void Models::Accounts::addAccount(Account* account)
|
||||
|
||||
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);
|
||||
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
|
||||
|
@ -31,6 +31,10 @@ constexpr int approximateSingleMessageHeight = 20;
|
||||
constexpr int progressSize = 70;
|
||||
constexpr int dateDeviderMargin = 10;
|
||||
|
||||
constexpr int avatarHeight = 50;
|
||||
constexpr int margin = 6;
|
||||
constexpr int halfMargin = 3;
|
||||
|
||||
const std::set<int> FeedView::geometryChangingRoles = {
|
||||
Models::MessageFeed::Attach,
|
||||
Models::MessageFeed::Text,
|
||||
@ -334,6 +338,20 @@ void FeedView::paintEvent(QPaintEvent* event)
|
||||
drawDateDevider(option.rect.bottom(), lastDate, painter);
|
||||
}
|
||||
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
|
||||
drawDateDevider(option.rect.bottom(), lastDate, painter);
|
||||
@ -344,10 +362,6 @@ void FeedView::paintEvent(QPaintEvent* event)
|
||||
del->endClearWidgets();
|
||||
clearWidgetsMode = false;
|
||||
}
|
||||
|
||||
if (event->rect().height() == vp->height()) {
|
||||
// draw the blurred drop shadow...
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
vo = verticalScrollBar()->maximum() - value;
|
||||
|
@ -74,6 +74,7 @@ private:
|
||||
bool tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewItem& option, const QAbstractItemModel* model, uint32_t totalHeight);
|
||||
void positionProgress();
|
||||
void drawDateDevider(int top, const QDateTime& date, QPainter& painter);
|
||||
void drawAvatar(const QModelIndex& index, const QStyleOptionViewItem& option, QPainter& painter);
|
||||
|
||||
private:
|
||||
struct Hint {
|
||||
|
@ -104,13 +104,7 @@ void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
|
||||
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;
|
||||
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
|
||||
case Models::uploading:
|
||||
paintPreview(data, painter, opt);
|
||||
[[fallthrough]];
|
||||
case Models::downloading:
|
||||
paintBar(getBar(data), painter, data.sentByMe, opt);
|
||||
break;
|
||||
@ -268,6 +263,7 @@ QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel
|
||||
break;
|
||||
case Models::uploading:
|
||||
messageSize.rheight() += Preview::calculateAttachSize(attach.localPath, messageRect).height() + textMargin;
|
||||
[[fallthrough]];
|
||||
case Models::downloading:
|
||||
messageSize.rheight() += barHeight + textMargin;
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user