Commit f1aceae2 authored by Philipp Hörist's avatar Philipp Hörist

Fix avatar ratio

Fixes #8907
parent 481ad882
......@@ -392,6 +392,8 @@
<property name="visible_window">False</property>
<child>
<object class="GtkImage" id="avatar_image">
<property name="width_request">48</property>
<property name="height_request">48</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
......
......@@ -3018,6 +3018,7 @@ class ContactRow(Gtk.Grid):
'avatar-default', Gtk.IconSize.DND)
else:
image = Gtk.Image.new_from_pixbuf(avatar)
image.set_size_request(AvatarSize.ROSTER, AvatarSize.ROSTER)
self.add(image)
middle_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
......
......@@ -114,11 +114,7 @@ def avatar_cell_data_func(column, renderer, model, iter_, has_parent):
surface = image.get_property('surface')
renderer.set_property('surface', surface)
avatar_position = app.config.get('avatar_position_in_roster')
if avatar_position == 'right':
renderer.set_property('xalign', 1)
else:
renderer.set_property('xalign', 0.5)
renderer.set_property('xalign', 0.5)
if has_parent:
renderer.set_property('visible', True)
renderer.set_property('width', AvatarSize.ROSTER)
......
......@@ -437,6 +437,16 @@ def get_possible_button_event(event):
def destroy_widget(widget):
widget.destroy()
def scale_with_ratio(size, width, height):
if height == width:
return size, size
if height > width:
ratio = height / float(width)
return int(size / ratio), size
else:
ratio = width / float(height)
return size, int(size / ratio)
def on_avatar_save_as_menuitem_activate(widget, avatar, default_name=''):
def on_continue(response, file_path):
if response < 0:
......
......@@ -2483,7 +2483,7 @@ class Interface:
try:
if size is not None:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
path, size, size, False)
path, size, size, True)
else:
pixbuf = GdkPixbuf.Pixbuf.new_from_file(path)
except GLib.GError as error:
......@@ -2504,8 +2504,10 @@ class Interface:
array, GdkPixbuf.Colorspace.RGB, True,
8, width, height, width * 4)
if size:
width, height = gtkgui_helpers.scale_with_ratio(
size, width, height)
pixbuf = pixbuf.scale_simple(
size, size, GdkPixbuf.InterpType.BILINEAR)
width, height, GdkPixbuf.InterpType.BILINEAR)
if filename not in app.avatar_cache:
app.avatar_cache[filename] = {}
......
......@@ -4864,11 +4864,8 @@ class RosterWindow:
app.config.get('avatar_position_in_roster') != 'left':
renderer.set_property('visible', False)
if app.config.get('avatar_position_in_roster') == 'left':
renderer.set_property('width', AvatarSize.ROSTER)
renderer.set_property('xalign', 0.5)
else:
renderer.set_property('xalign', 1) # align pixbuf to the right
renderer.set_property('width', AvatarSize.ROSTER)
renderer.set_property('xalign', 0.5)
def _fill_padlock_pixbuf_renderer(self, column, renderer, model, titer,
data=None):
......
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