Commit ad580a0b authored by Konrad Czapla's avatar Konrad Czapla

Fix initials in contact list and don't try to draw empty name

parent b65e7f18
Pipeline #34646 failed with stage
in 5 minutes and 36 seconds
......@@ -116,17 +116,17 @@ QVariant ContactInfoProxyModel::data(const QModelIndex &index, int role) const
QString ContactInfoProxyModel::getInitials(const KContacts::Addressee &contact) const
{
QString initials;
QString names = contact.realName();
names.remove(contact.prefix());
names.remove(contact.suffix());
names.remove(contact.additionalName());
const QStringList contactListNames = names.split(QRegularExpression(QStringLiteral("\\s+")));
for (const QString &name : contactListNames) {
if (!name.isEmpty()) {
initials.append(name.front());
}
if (!contact.givenName().isEmpty()) {
initials.append(contact.givenName().front());
}
if (!contact.familyName().isEmpty()) {
initials.append(contact.familyName().front());
}
if (initials.isEmpty() && !contact.realName().isEmpty()) {
initials.append(contact.realName().front());
}
return initials.toUpper();
}
......
......@@ -76,13 +76,13 @@ void StyleContactListDelegate::paint(QPainter *painter, const QStyleOptionViewIt
painter->drawPath(path);
painter->setFont(QFont(option.font.family(), 12, QFont::Bold, true));
if (index.data(ContactInfoProxyModel::Roles::PictureRole).value<QImage>().isNull()) {
QImage image(index.data(ContactInfoProxyModel::Roles::PictureRole).value<QImage>());
if (image.isNull()) {
const QString initials = index.data(ContactInfoProxyModel::Roles::InitialsRole).value<QString>();
painter->drawText(pictureRect, Qt::AlignCenter, painter->fontMetrics().elidedText(initials,
Qt::ElideRight, pictureRect.width() - qreal(10)));
} else {
const qreal dpr = qApp->devicePixelRatio();
QImage image(index.data(ContactInfoProxyModel::Roles::PictureRole).value<QImage>());
image = image.scaled(mKImageSize * dpr, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
image.setDevicePixelRatio(dpr);
painter->drawImage(pictureRect, image);
......@@ -90,10 +90,13 @@ void StyleContactListDelegate::paint(QPainter *painter, const QStyleOptionViewIt
painter->restore();
painter->setFont(QFont(option.font.family(), 11));
const QString name = index.data(Qt::DisplayRole).value<QString>();
painter->drawText(nameTextRect, Qt::AlignLeft | Qt::AlignVCenter,
painter->fontMetrics().elidedText(name, Qt::ElideRight, nameTextRect.width()));
if (!name.isEmpty()) {
painter->setFont(QFont(option.font.family(), 11));
painter->drawText(nameTextRect, Qt::AlignLeft | Qt::AlignVCenter,
painter->fontMetrics().elidedText(name, Qt::ElideRight, nameTextRect.width()));
}
const QString description = index.data(ContactInfoProxyModel::Roles::DescriptionRole).value<QString>();
if (!description.isEmpty()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment