[polari/wip/raresv/GSoC: 10/11] chatView: add HoverFilterTag class and use it



commit d330d50cc71dbf4ff7083a3cfa48b05b0b50be61
Author: raresv <rares visalom gmail com>
Date:   Sun Aug 14 17:57:47 2016 +0300

    chatView: add HoverFilterTag class and use it
    
    We need a way of highlighting the nicknames as we hover
    over them. We achieve this by creating a new tag that
    wraps around the nickTag. The HoverFilterTag modifies the
    opacity of the nickTag by first taking the color of the
    nickTag, then modifying it with the hover_opacity param.
    The reference to the filtered_tag is used only to get the
    right color from the nickTag so that we can properly modify
    it upon hovering the tag.

 src/chatView.js |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index a56df99..a422281 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -226,6 +226,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,
@@ -1180,6 +1245,12 @@ const ChatView = new Lang.Class({
                 }
                 tags.push(nickTag);
 
+                let hoverTag = new HoverFilterTag({ filtered_tag: nickTag,
+                                                    hover_opacity: 0.8 });
+                buffer.get_tag_table().add(hoverTag);
+
+                tags.push(hoverTag);
+
                 if (needsGap)
                     tags.push(this._lookupTag('gap'));
                 this._insertWithTags(iter, message.nick, tags);


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