Fix avatar ratio

Fixes #8907
This commit is contained in:
Philipp Hörist 2018-02-19 19:37:53 +01:00
parent 481ad882a0
commit f1aceae214
6 changed files with 20 additions and 12 deletions

View file

@ -392,6 +392,8 @@
<property name="visible_window">False</property> <property name="visible_window">False</property>
<child> <child>
<object class="GtkImage" id="avatar_image"> <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="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property> <property name="stock">gtk-missing-image</property>

View file

@ -3018,6 +3018,7 @@ class ContactRow(Gtk.Grid):
'avatar-default', Gtk.IconSize.DND) 'avatar-default', Gtk.IconSize.DND)
else: else:
image = Gtk.Image.new_from_pixbuf(avatar) image = Gtk.Image.new_from_pixbuf(avatar)
image.set_size_request(AvatarSize.ROSTER, AvatarSize.ROSTER)
self.add(image) self.add(image)
middle_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) middle_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)

View file

@ -114,10 +114,6 @@ def avatar_cell_data_func(column, renderer, model, iter_, has_parent):
surface = image.get_property('surface') surface = image.get_property('surface')
renderer.set_property('surface', 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: if has_parent:
renderer.set_property('visible', True) renderer.set_property('visible', True)

View file

@ -437,6 +437,16 @@ def get_possible_button_event(event):
def destroy_widget(widget): def destroy_widget(widget):
widget.destroy() 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_avatar_save_as_menuitem_activate(widget, avatar, default_name=''):
def on_continue(response, file_path): def on_continue(response, file_path):
if response < 0: if response < 0:

View file

@ -2483,7 +2483,7 @@ class Interface:
try: try:
if size is not None: if size is not None:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
path, size, size, False) path, size, size, True)
else: else:
pixbuf = GdkPixbuf.Pixbuf.new_from_file(path) pixbuf = GdkPixbuf.Pixbuf.new_from_file(path)
except GLib.GError as error: except GLib.GError as error:
@ -2504,8 +2504,10 @@ class Interface:
array, GdkPixbuf.Colorspace.RGB, True, array, GdkPixbuf.Colorspace.RGB, True,
8, width, height, width * 4) 8, width, height, width * 4)
if size: if size:
width, height = gtkgui_helpers.scale_with_ratio(
size, width, height)
pixbuf = pixbuf.scale_simple( pixbuf = pixbuf.scale_simple(
size, size, GdkPixbuf.InterpType.BILINEAR) width, height, GdkPixbuf.InterpType.BILINEAR)
if filename not in app.avatar_cache: if filename not in app.avatar_cache:
app.avatar_cache[filename] = {} app.avatar_cache[filename] = {}

View file

@ -4864,11 +4864,8 @@ class RosterWindow:
app.config.get('avatar_position_in_roster') != 'left': app.config.get('avatar_position_in_roster') != 'left':
renderer.set_property('visible', False) renderer.set_property('visible', False)
if app.config.get('avatar_position_in_roster') == 'left':
renderer.set_property('width', AvatarSize.ROSTER) renderer.set_property('width', AvatarSize.ROSTER)
renderer.set_property('xalign', 0.5) renderer.set_property('xalign', 0.5)
else:
renderer.set_property('xalign', 1) # align pixbuf to the right
def _fill_padlock_pixbuf_renderer(self, column, renderer, model, titer, def _fill_padlock_pixbuf_renderer(self, column, renderer, model, titer,
data=None): data=None):