Closes #7417 Only show read/unstarred icon in conversation list when hovering
This commit is contained in:
parent
9c458e34fc
commit
8d1f7a2b26
3 changed files with 66 additions and 23 deletions
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
public class ConversationListCellRenderer : Gtk.CellRenderer {
|
||||
private static FormattedConversationData? example_data = null;
|
||||
private static bool hover_selected = false;
|
||||
|
||||
// Mail message data.
|
||||
public FormattedConversationData data { get; set; }
|
||||
|
|
@ -24,7 +25,7 @@ public class ConversationListCellRenderer : Gtk.CellRenderer {
|
|||
public override void render(Cairo.Context ctx, Gtk.Widget widget, Gdk.Rectangle background_area,
|
||||
Gdk.Rectangle cell_area, Gtk.CellRendererState flags) {
|
||||
if (data != null)
|
||||
data.render(ctx, widget, background_area, cell_area, flags);
|
||||
data.render(ctx, widget, background_area, cell_area, flags, hover_selected);
|
||||
}
|
||||
|
||||
// Recalculates size when the style changed.
|
||||
|
|
@ -36,5 +37,10 @@ public class ConversationListCellRenderer : Gtk.CellRenderer {
|
|||
|
||||
example_data.calculate_sizes(widget);
|
||||
}
|
||||
|
||||
// Shows hover effect on all selected cells.
|
||||
public static void set_hover_selected(bool hover) {
|
||||
hover_selected = hover;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,6 +69,10 @@ public class ConversationListView : Gtk.TreeView {
|
|||
GearyApplication.instance.config.display_preview_changed.connect(on_display_preview_changed);
|
||||
GearyApplication.instance.controller.notify[GearyController.PROP_CURRENT_CONVERSATION].
|
||||
connect(on_conversation_monitor_changed);
|
||||
|
||||
// Watch for mouse events.
|
||||
motion_notify_event.connect(on_motion_notify_event);
|
||||
leave_notify_event.connect(on_leave_notify_event);
|
||||
}
|
||||
|
||||
private void on_conversation_monitor_changed() {
|
||||
|
|
@ -399,5 +403,31 @@ public class ConversationListView : Gtk.TreeView {
|
|||
if (c != null)
|
||||
conversation_activated(c);
|
||||
}
|
||||
|
||||
// Enable/disable hover effect on all selected cells.
|
||||
private void set_hover_selected(bool hover) {
|
||||
ConversationListCellRenderer.set_hover_selected(hover);
|
||||
queue_draw();
|
||||
}
|
||||
|
||||
private bool on_motion_notify_event(Gdk.EventMotion event) {
|
||||
if (get_selected_path() == null)
|
||||
return false;
|
||||
|
||||
Gtk.TreePath? path = null;
|
||||
int cell_x, cell_y;
|
||||
get_path_at_pos((int) event.x, (int) event.y, out path, null, out cell_x, out cell_y);
|
||||
|
||||
set_hover_selected(path != null && get_selection().path_is_selected(path));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool on_leave_notify_event() {
|
||||
if (get_selected_path() != null)
|
||||
set_hover_selected(false);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -262,13 +262,13 @@ public class FormattedConversationData : Geary.BaseObject {
|
|||
}
|
||||
|
||||
public void render(Cairo.Context ctx, Gtk.Widget widget, Gdk.Rectangle background_area,
|
||||
Gdk.Rectangle cell_area, Gtk.CellRendererState flags) {
|
||||
render_internal(widget, cell_area, ctx, (flags & Gtk.CellRendererState.SELECTED) != 0);
|
||||
Gdk.Rectangle cell_area, Gtk.CellRendererState flags, bool hover_select) {
|
||||
render_internal(widget, cell_area, ctx, flags, false, hover_select);
|
||||
}
|
||||
|
||||
// Call this on style changes.
|
||||
public void calculate_sizes(Gtk.Widget widget) {
|
||||
render_internal(widget, null, null, false, true);
|
||||
render_internal(widget, null, null, 0, true);
|
||||
}
|
||||
|
||||
// Must call calculate_sizes() first.
|
||||
|
|
@ -284,10 +284,13 @@ public class FormattedConversationData : Geary.BaseObject {
|
|||
|
||||
// Can be used for rendering or calculating height.
|
||||
private void render_internal(Gtk.Widget widget, Gdk.Rectangle? cell_area = null,
|
||||
Cairo.Context? ctx = null, bool selected, bool recalc_dims = false) {
|
||||
|
||||
Cairo.Context? ctx = null, Gtk.CellRendererState flags, bool recalc_dims = false,
|
||||
bool hover_select = false) {
|
||||
int y = LINE_SPACING + (cell_area != null ? cell_area.y : 0);
|
||||
|
||||
bool selected = (flags & Gtk.CellRendererState.SELECTED) != 0;
|
||||
bool hover = (flags & Gtk.CellRendererState.PRELIT) != 0 || (selected && hover_select);
|
||||
|
||||
// Date field.
|
||||
Pango.Rectangle ink_rect = render_date(widget, cell_area, ctx, y, selected);
|
||||
|
||||
|
|
@ -325,14 +328,14 @@ public class FormattedConversationData : Geary.BaseObject {
|
|||
y += ink_rect.height + ink_rect.y + LINE_SPACING;
|
||||
}
|
||||
|
||||
// Draw separator line.
|
||||
if (ctx != null && cell_area != null) {
|
||||
ctx.set_line_width(1.0);
|
||||
GtkUtil.set_source_color_from_string(ctx, CountBadge.UNREAD_BG_COLOR);
|
||||
ctx.move_to(cell_area.x - 1, cell_area.y + cell_area.height);
|
||||
ctx.line_to(cell_area.x + cell_area.width + 1, cell_area.y + cell_area.height);
|
||||
ctx.stroke();
|
||||
}
|
||||
// Draw separator line.
|
||||
if (ctx != null && cell_area != null) {
|
||||
ctx.set_line_width(1.0);
|
||||
GtkUtil.set_source_color_from_string(ctx, CountBadge.UNREAD_BG_COLOR);
|
||||
ctx.move_to(cell_area.x - 1, cell_area.y + cell_area.height);
|
||||
ctx.line_to(cell_area.x + cell_area.width + 1, cell_area.y + cell_area.height);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
if (recalc_dims) {
|
||||
FormattedConversationData.preview_height = preview_height;
|
||||
|
|
@ -342,17 +345,21 @@ public class FormattedConversationData : Geary.BaseObject {
|
|||
cell_area.y + LINE_SPACING * 2 : cell_area.y + LINE_SPACING;
|
||||
|
||||
// Unread indicator.
|
||||
Gdk.Pixbuf read_icon = is_unread ? IconFactory.instance.unread_colored
|
||||
: IconFactory.instance.read_colored;
|
||||
Gdk.cairo_set_source_pixbuf(ctx, read_icon, cell_area.x + LINE_SPACING, unread_y);
|
||||
ctx.paint();
|
||||
if (is_unread || hover) {
|
||||
Gdk.Pixbuf read_icon = is_unread ? IconFactory.instance.unread_colored
|
||||
: IconFactory.instance.read_colored;
|
||||
Gdk.cairo_set_source_pixbuf(ctx, read_icon, cell_area.x + LINE_SPACING, unread_y);
|
||||
ctx.paint();
|
||||
}
|
||||
|
||||
// Starred indicator.
|
||||
Gdk.Pixbuf starred_icon = is_flagged ? IconFactory.instance.starred_colored
|
||||
: IconFactory.instance.unstarred_colored;
|
||||
Gdk.cairo_set_source_pixbuf(ctx, starred_icon, cell_area.x + LINE_SPACING, cell_area.y +
|
||||
(cell_area.height / 2) + LINE_SPACING);
|
||||
ctx.paint();
|
||||
if (is_flagged || hover) {
|
||||
Gdk.Pixbuf starred_icon = is_flagged ? IconFactory.instance.starred_colored
|
||||
: IconFactory.instance.unstarred_colored;
|
||||
Gdk.cairo_set_source_pixbuf(ctx, starred_icon, cell_area.x + LINE_SPACING, cell_area.y +
|
||||
(cell_area.height / 2) + LINE_SPACING);
|
||||
ctx.paint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue