Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nheko
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
nheko
Commits
27350cf5
Commit
27350cf5
authored
4 years ago
by
Nicolas Werner
Browse files
Options
Downloads
Patches
Plain Diff
Fix high CPU usage on high dpi screens
Fixes #180
parent
17c657a1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/RoomInfoListItem.cpp
+2
-1
2 additions, 1 deletion
src/RoomInfoListItem.cpp
src/ui/Avatar.cpp
+22
-15
22 additions, 15 deletions
src/ui/Avatar.cpp
src/ui/Avatar.h
+1
-0
1 addition, 0 deletions
src/ui/Avatar.h
with
25 additions
and
16 deletions
src/RoomInfoListItem.cpp
+
2
−
1
View file @
27350cf5
...
...
@@ -151,7 +151,8 @@ RoomInfoListItem::paintEvent(QPaintEvent *event)
auto
wm
=
getMetrics
(
QFont
{});
QPixmap
pixmap
(
avatar_
->
size
());
QPixmap
pixmap
(
avatar_
->
size
()
*
p
.
device
()
->
devicePixelRatioF
());
pixmap
.
setDevicePixelRatio
(
p
.
device
()
->
devicePixelRatioF
());
if
(
isPressed_
)
{
p
.
fillRect
(
rect
(),
highlightedBackgroundColor_
);
titlePen
.
setColor
(
highlightedTitleColor_
);
...
...
This diff is collapsed.
Click to expand it.
src/ui/Avatar.cpp
+
22
−
15
View file @
27350cf5
...
...
@@ -71,11 +71,12 @@ Avatar::setImage(const QString &avatar_url)
AvatarProvider
::
resolve
(
avatar_url
,
static_cast
<
int
>
(
size_
*
pixmap_
.
devicePixelRatio
()),
this
,
[
this
](
QPixmap
pm
)
{
[
this
,
requestedRatio
=
pixmap_
.
devicePixelRatio
()
](
QPixmap
pm
)
{
if
(
pm
.
isNull
())
return
;
type_
=
ui
::
AvatarType
::
Image
;
pixmap_
=
pm
;
pixmap_
.
setDevicePixelRatio
(
requestedRatio
);
update
();
});
}
...
...
@@ -89,15 +90,30 @@ Avatar::setImage(const QString &room, const QString &user)
user
,
static_cast
<
int
>
(
size_
*
pixmap_
.
devicePixelRatio
()),
this
,
[
this
](
QPixmap
pm
)
{
[
this
,
requestedRatio
=
pixmap_
.
devicePixelRatio
()
](
QPixmap
pm
)
{
if
(
pm
.
isNull
())
return
;
type_
=
ui
::
AvatarType
::
Image
;
pixmap_
=
pm
;
pixmap_
.
setDevicePixelRatio
(
requestedRatio
);
update
();
});
}
void
Avatar
::
setDevicePixelRatio
(
double
ratio
)
{
if
(
type_
==
ui
::
AvatarType
::
Image
&&
abs
(
pixmap_
.
devicePixelRatio
()
-
ratio
)
>
0.01
)
{
pixmap_
=
pixmap_
.
scaled
(
QSize
(
size_
,
size_
)
*
ratio
);
pixmap_
.
setDevicePixelRatio
(
ratio
);
if
(
!
avatar_url_
.
isEmpty
())
setImage
(
avatar_url_
);
else
setImage
(
room_
,
user_
);
}
}
void
Avatar
::
paintEvent
(
QPaintEvent
*
)
{
...
...
@@ -106,7 +122,7 @@ Avatar::paintEvent(QPaintEvent *)
QPainter
painter
(
this
);
painter
.
setRenderHint
(
QPainter
::
Antialiasing
);
QRect
r
=
rect
();
QRect
F
r
=
rect
();
const
int
hs
=
size_
/
2
;
if
(
type_
!=
ui
::
AvatarType
::
Image
)
{
...
...
@@ -116,18 +132,9 @@ Avatar::paintEvent(QPaintEvent *)
painter
.
setPen
(
Qt
::
NoPen
);
painter
.
setBrush
(
brush
);
rounded
?
painter
.
drawEllipse
(
r
.
center
(),
hs
,
hs
)
:
painter
.
drawRoundedRect
(
r
,
3
,
3
);
}
else
if
(
painter
.
isActive
()
&&
abs
(
pixmap_
.
devicePixelRatio
()
-
painter
.
device
()
->
devicePixelRatioF
())
>
0.01
)
{
pixmap_
=
pixmap_
.
scaled
(
QSize
(
size_
,
size_
)
*
painter
.
device
()
->
devicePixelRatioF
());
pixmap_
.
setDevicePixelRatio
(
painter
.
device
()
->
devicePixelRatioF
());
if
(
!
avatar_url_
.
isEmpty
())
setImage
(
avatar_url_
);
else
setImage
(
room_
,
user_
);
rounded
?
painter
.
drawEllipse
(
r
)
:
painter
.
drawRoundedRect
(
r
,
3
,
3
);
}
else
if
(
painter
.
isActive
())
{
setDevicePixelRatio
(
painter
.
device
()
->
devicePixelRatioF
());
}
switch
(
type_
)
{
...
...
This diff is collapsed.
Click to expand it.
src/ui/Avatar.h
+
1
−
0
View file @
27350cf5
...
...
@@ -21,6 +21,7 @@ public:
void
setImage
(
const
QString
&
room
,
const
QString
&
user
);
void
setLetter
(
const
QString
&
letter
);
void
setTextColor
(
const
QColor
&
color
);
void
setDevicePixelRatio
(
double
ratio
);
QColor
backgroundColor
()
const
;
QColor
textColor
()
const
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment