Enlarge desktop chat and member avatars
This commit is contained in:
1 parent
aa58c7fd3d
commit
29ee55d751
7 files changed
+42
-22
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#include "accountdelegate.h"
|
||||
#include "flagpainter.h"
|
||||
#include "memberlistmodel.h"
|
||||
#include "debug_ui.h"
|
||||
#include <QPainter>
|
||||
#include <QFont>
|
||||
#include <QMouseEvent>
|
||||
@@ -9,8 +10,16 @@ static QRect inviteButtonRect(const QRect& row) {
|
||||
return QRect(row.right() - 31, row.center().y() - 14, 28, 28);
|
||||
}
|
||||
|
||||
static QRect avatarRect(const QRect& row) {
|
||||
const int size = MemberListModel::kAvatarSize;
|
||||
return QRect(row.left() + 4, row.top() + (row.height() - size) / 2, size, size);
|
||||
}
|
||||
|
||||
AccountDelegate::AccountDelegate(QObject *parent)
|
||||
: QStyledItemDelegate(parent) {}
|
||||
: QStyledItemDelegate(parent) {
|
||||
GUI_DEBUG("AccountDelegate: row height=%dpx avatar=%dpx gap=%dpx", MemberListModel::kRowHeight,
|
||||
MemberListModel::kAvatarSize, MemberListModel::kRowHeight - MemberListModel::kAvatarSize);
|
||||
}
|
||||
|
||||
void AccountDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const {
|
||||
@@ -24,11 +33,11 @@ void AccountDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio
|
||||
painter->fillRect(option.rect, option.palette.alternateBase());
|
||||
|
||||
const int margin = 4;
|
||||
const int iconSz = 24;
|
||||
const int iconSz = MemberListModel::kAvatarSize;
|
||||
|
||||
QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
|
||||
if (!icon.isNull())
|
||||
icon.paint(painter, option.rect.left() + margin, option.rect.top() + (option.rect.height() - iconSz) / 2, iconSz, iconSz);
|
||||
icon.paint(painter, avatarRect(option.rect));
|
||||
|
||||
const int x = option.rect.left() + iconSz + margin * 3;
|
||||
const bool canInvite = !index.data(Qt::UserRole + 2).toBool();
|
||||
@@ -96,7 +105,7 @@ bool AccountDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, cons
|
||||
event->type() != QEvent::MouseButtonDblClick) return false;
|
||||
auto* mouse = static_cast<QMouseEvent*>(event);
|
||||
if (mouse->button() != Qt::LeftButton) return false;
|
||||
const bool onAvatar=QRect(option.rect.left()+4,option.rect.center().y()-12,24,24).contains(mouse->pos());
|
||||
const bool onAvatar = avatarRect(option.rect).contains(mouse->pos());
|
||||
if (event->type()==QEvent::MouseButtonPress) {
|
||||
m_avatarPress=onAvatar ? index : QModelIndex(); m_avatarPosition=mouse->pos();
|
||||
}
|
||||
@@ -119,5 +128,5 @@ bool AccountDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, cons
|
||||
QSize AccountDelegate::sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const {
|
||||
(void)option; (void)index;
|
||||
return QSize(160, 36);
|
||||
return QSize(160, MemberListModel::kRowHeight);
|
||||
}
|
||||
Reference in new issue
Block a user