Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
KAddressBook
Commits
ad580a0b
Commit
ad580a0b
authored
Sep 17, 2020
by
Konrad Czapla
Browse files
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
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/contactinfoproxymodel.cpp
View file @
ad580a0b
...
...
@@ -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
();
}
...
...
src/stylecontactlistdelegate.cpp
View file @
ad580a0b
...
...
@@ -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
())
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment