[banshee/1.5.1-fixes: 2/56] Make license column fixed size and show tooltip



commit a8a1b1ed99f65987c11be143db666c099f2656d4
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Wed Oct 7 17:29:39 2009 -0700

    Make license column fixed size and show tooltip

 .../ColumnCellCreativeCommons.cs                   |  105 +++++++++++++-------
 1 files changed, 68 insertions(+), 37 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellCreativeCommons.cs b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellCreativeCommons.cs
index 170e473..fb3f3cb 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellCreativeCommons.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellCreativeCommons.cs
@@ -27,6 +27,8 @@
 //
 
 using System;
+using System.Linq;
+using System.Collections.Generic;
 using Gtk;
 using Cairo;
 
@@ -40,18 +42,58 @@ using Banshee.ServiceStack;
 
 namespace Banshee.Collection.Gui
 {
-    public class ColumnCellCreativeCommons : ColumnCell
+    public class ColumnCellCreativeCommons : ColumnCell, ISizeRequestCell, ITooltipCell
     {
         private static Gdk.Pixbuf [] pixbufs;
         private static string [] attributes = new string [] {"by", "nc", "nd", "sa", "pd"};
+        private static string [] attributes_uc = new string [] {"BY", "NC", "ND", "SA", "PD"};
         private const string CC_ID = "creativecommons.org/licenses/";
         private static int CC_ID_LEN = CC_ID.Length;
+        private const int ICON_SIZE = 16;
 
         public ColumnCellCreativeCommons (string property, bool expand) : base (property, expand)
         {
             LoadPixbufs ();
         }
 
+        public override void Render (CellContext context, StateType state, double cellWidth, double cellHeight)
+        {
+            context.Context.Translate (0, 0.5);
+            int draw_x = 0;
+
+            foreach (int i in AttributesForBoundObject) {
+                Gdk.Pixbuf render_pixbuf = pixbufs[i];
+
+                Cairo.Rectangle pixbuf_area = new Cairo.Rectangle (draw_x,
+                    (cellHeight - render_pixbuf.Height) / 2, render_pixbuf.Width, render_pixbuf.Height);
+                
+                if (!context.Opaque) {
+                    context.Context.Save ();
+                }
+                
+                Gdk.CairoHelper.SetSourcePixbuf (context.Context, render_pixbuf, pixbuf_area.X, pixbuf_area.Y);
+                context.Context.Rectangle (pixbuf_area);
+                
+                if (!context.Opaque) {
+                    context.Context.Clip ();
+                    context.Context.PaintWithAlpha (0.5);
+                    context.Context.Restore ();
+                } else {
+                    context.Context.Fill ();
+                }
+
+                draw_x += render_pixbuf.Width;
+            }
+        }
+
+        public string GetTooltipMarkup (CellContext cellContext, double columnWidth)
+        {
+            var our_attributes = AttributesForBoundObject.Select (i => attributes_uc[i]);
+            return our_attributes.Count () > 0
+                ? String.Format ("Creative Commons {0}", String.Join ("-", our_attributes.ToArray ()))
+                : null;
+        }
+
         private void LoadPixbufs ()
         {
             if (pixbufs == null) {
@@ -59,51 +101,40 @@ namespace Banshee.Collection.Gui
             }
             
             for (int i = 0; i < attributes.Length; i++) {
-                pixbufs[i] = IconThemeUtils.LoadIcon (16, String.Format ("creative-commons-{0}", attributes[i]));
+                pixbufs[i] = IconThemeUtils.LoadIcon (ICON_SIZE, String.Format ("creative-commons-{0}", attributes[i]));
             }
         }
 
-        public override void Render (CellContext context, StateType state, double cellWidth, double cellHeight)
-        {
-            string license_uri = BoundObject as string;
-            if (String.IsNullOrEmpty (license_uri)) {
-                return;
-            }
+        private IEnumerable<int> AttributesForBoundObject {
+            get {
+                string license_uri = BoundObject as string;
+                if (String.IsNullOrEmpty (license_uri)) {
+                    yield break;
+                }
 
-            int start_index = license_uri.IndexOf (CC_ID);
-            if (start_index == -1) {
-                return;
-            }
+                int start_index = license_uri.IndexOf (CC_ID);
+                if (start_index == -1) {
+                    yield break;
+                }
 
-            start_index += CC_ID_LEN;
-            context.Context.Translate (0, 0.5);
+                start_index += CC_ID_LEN;
 
-            int draw_x = 0;
-            for (int i = 0; i < attributes.Length; i++) {
-                if (license_uri.IndexOf (attributes[i], start_index) != -1) {
-                    Gdk.Pixbuf render_pixbuf = pixbufs[i];
-
-                    Cairo.Rectangle pixbuf_area = new Cairo.Rectangle (draw_x,
-                        (cellHeight - render_pixbuf.Height) / 2, render_pixbuf.Width, render_pixbuf.Height);
-                    
-                    if (!context.Opaque) {
-                        context.Context.Save ();
+                for (int i = 0; i < attributes.Length; i++) {
+                    if (license_uri.IndexOf (attributes[i], start_index) != -1) {
+                        yield return i;
                     }
-                    
-                    Gdk.CairoHelper.SetSourcePixbuf (context.Context, render_pixbuf, pixbuf_area.X, pixbuf_area.Y);
-                    context.Context.Rectangle (pixbuf_area);
-                    
-                    if (!context.Opaque) {
-                        context.Context.Clip ();
-                        context.Context.PaintWithAlpha (0.5);
-                        context.Context.Restore ();
-                    } else {
-                        context.Context.Fill ();
-                    }
-
-                    draw_x += render_pixbuf.Width;
                 }
             }
         }
+
+        public bool RestrictSize {
+            get { return true; }
+            set {}
+        }
+
+        public void GetWidthRange (Pango.Layout layout, out int min, out int max)
+        {
+            min = max = ICON_SIZE * attributes.Length;
+        }
     }
 }



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