[polari/wip/raresv/nick-popover: 7/10] chatView: Add HoverFilterTag



commit 75be206984b8cc203a0b8b17ed9d5c6646312675
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Jul 27 22:30:17 2016 +0200

    chatView: Add HoverFilterTag
    
    We want to show the newly added UserPopover when clicking a nick in
    the chat log. Currently those nicks use a common tag for general
    styling and a per-nick tag to represent the online status of the
    nick, however we will also want to indicate that the element is
    activatable by highlighting it on hover. To allow this effect while
    keeping the status color in a per-nick tag, add a HoverFilterTag
    class that takes the color from an existing tag and applies an
    opacity effect when hovered.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=760853

 src/chatView.js |   65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 0 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index 9079861..1e783cf 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -225,6 +225,71 @@ const ButtonTag = new Lang.Class({
     }
 });
 
+const HoverFilterTag = new Lang.Class({
+    Name: 'HoverFilterTag',
+    Extends: ButtonTag,
+    Properties: {
+        'filtered-tag': GObject.ParamSpec.object('filtered-tag',
+                                                 'filtered-tag',
+                                                 'filtered-tag',
+                                                 GObject.ParamFlags.READWRITE |
+                                                 GObject.ParamFlags.CONSTRUCT_ONLY,
+                                                 Gtk.TextTag.$gtype),
+        'hover-opacity': GObject.ParamSpec.double('hover-opacity',
+                                                  'hover-opacity',
+                                                  'hover-opacity',
+                                                  GObject.ParamFlags.READWRITE,
+                                                  0.0, 1.0, 1.0)
+    },
+
+    _init: function(params) {
+        this._filteredTag = null;
+        this._hoverOpacity = 1.;
+
+        this.parent(params);
+
+        this.connect('notify::hover', () => { this._updateColor(); });
+    },
+
+    _updateColor: function() {
+        if (!this._filteredTag)
+            return;
+
+        let color = this._filteredTag.foreground_rgba;
+        if (this.hover)
+            color.alpha *= this._hoverOpacity;
+        this.foreground_rgba = color;
+    },
+
+    set filtered_tag(value) {
+        this._filteredTag = value;
+        this.notify('filtered-tag');
+
+        this._filteredTag.connect('notify::foreground-rgba', () => {
+            this._updateColor();
+        });
+        this._updateColor();
+    },
+
+    get filtered_tag() {
+        return this._filteredTag;
+    },
+
+    set hover_opacity(value) {
+        if (this._hoverOpacity == value)
+            return;
+        this._hoverOpacity = value;
+        this.notify('hover-opacity');
+
+        if (this.hover)
+            this._updateColor();
+    },
+
+    get hover_opacity() {
+        return this._hoverOpacity;
+    }
+});
+
 const ChatView = new Lang.Class({
     Name: 'ChatView',
     Extends: Gtk.ScrolledWindow,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]