[longomatch] Add support for filters in the timeline too



commit b817d99801a3f395831a12d5b55a89d1a58c19e9
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sat Apr 20 19:22:32 2013 +0200

    Add support for filters in the timeline too

 LongoMatch.GUI/Gui/Base/TimeScaleBase.cs           | 11 +++-
 LongoMatch.GUI/Gui/Component/TimeLineWidget.cs     | 70 +++++++++++-----------
 LongoMatch.GUI/Gui/Component/TimeScale.cs          |  8 ++-
 .../Gui/Component/TimelineLabelsWidget.cs          | 35 ++++++++---
 LongoMatch.GUI/Gui/MainWindow.cs                   |  2 +-
 .../Gui/TreeView/CategoriesFilterTreeView.cs       | 29 ++++++---
 6 files changed, 102 insertions(+), 53 deletions(-)
---
diff --git a/LongoMatch.GUI/Gui/Base/TimeScaleBase.cs b/LongoMatch.GUI/Gui/Base/TimeScaleBase.cs
index d3c39ae..111e431 100644
--- a/LongoMatch.GUI/Gui/Base/TimeScaleBase.cs
+++ b/LongoMatch.GUI/Gui/Base/TimeScaleBase.cs
@@ -46,6 +46,7 @@ namespace LongoMatch.Gui.Base
 
                Cairo.Color color;
                List<T> list;
+               PlaysFilter filter;
 
                T candidateTN;
                bool candidateStart;
@@ -64,10 +65,11 @@ namespace LongoMatch.Gui.Base
                protected string elementName = "";
                protected int cursorFrame;
 
-               public TimeScaleBase(List<T> list, uint frames)
+               public TimeScaleBase(List<T> list, uint frames, PlaysFilter filter = null)
                {
                        this.frames = frames;
                        this.list = list;
+                       this.filter = filter;
                        this.color = new Cairo.Color(0, 0, 1);
                        this.color.A = ALPHA;
                        HeightRequest= SECTION_HEIGHT;
@@ -163,6 +165,10 @@ namespace LongoMatch.Gui.Base
                                g.Operator = Operator.Over;
                                
                                foreach(T tn in list) {
+                                       if (filter != null && !filter.IsVisible (tn)) {
+                                               continue;
+                                       }
+                                       
                                        if(!tn.Equals(selected)) {
                                                Cairo.Color borderColor = new Cairo.Color(color.R+0.1, 
color.G+0.1,color.B+0.1, 1);
                                                CairoUtils.DrawRoundedRectangle(g,tn.StartFrame/pixelRatio,3,
@@ -209,6 +215,9 @@ namespace LongoMatch.Gui.Base
 
                void DrawTimeNodesName() {
                        foreach(T tn in list) {
+                               if (filter != null && !filter.IsVisible (tn)) {
+                                       continue;
+                               }
                                layout.Width = Pango.Units.FromPixels((int)(tn.TotalFrames/pixelRatio));
                                layout.SetMarkup(tn.Name);
                                GdkWindow.DrawLayout(Style.TextGC(StateType.Normal),
diff --git a/LongoMatch.GUI/Gui/Component/TimeLineWidget.cs b/LongoMatch.GUI/Gui/Component/TimeLineWidget.cs
index 5d0b5e5..6d54cc0 100644
--- a/LongoMatch.GUI/Gui/Component/TimeLineWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/TimeLineWidget.cs
@@ -26,6 +26,7 @@ using LongoMatch.Gui.Base;
 using LongoMatch.Handlers;
 using LongoMatch.Store;
 using LongoMatch.Store.Templates;
+using LongoMatch.Common;
 
 namespace LongoMatch.Gui.Component {
 
@@ -42,42 +43,41 @@ namespace LongoMatch.Gui.Component {
                public TimeLineWidget(): base()
                {
                }
-
-               public Project Project {
-                       set {
-                               ResetGui();
-
-                               if(value == null) {
-                                       categories = null;
-                                       tsList.Clear();
-                                       loaded = false;
-                                       return;
-                               }
-                               loaded = true;
-                               categories = value.Categories;
-                               tsList.Clear(); 
-                               frames = value.Description.File.GetFrames();
-
-                               cs.Categories = categories;
-                               cs.Show();
-
-                               tr.Frames = frames;
-                               tr.FrameRate = value.Description.File.Fps;
-                               tr.Show();
-
-                               foreach(Category cat in  categories) {
-                                       List<Play> playsList = value.PlaysInCategory(cat);
-                                       TimeScale ts = new TimeScale(cat, playsList,frames);
-                                       tsList[cat] = ts;
-                                       ts.TimeNodeChanged += new TimeNodeChangedHandler(OnTimeNodeChanged);
-                                       ts.TimeNodeSelected += new PlaySelectedHandler(OnTimeNodeSelected);
-                                       ts.TimeNodeDeleted += new PlaysDeletedHandler(OnTimeNodeDeleted);
-                                       ts.NewMarkAtFrameEvent += new NewTagAtFrameHandler(OnNewMark);
-                                       TimelineBox.PackStart(ts,false,true,0);
-                                       ts.Show();
-                               }
-                               SetPixelRatio(3);
+               
+               public void SetProject (Project project, PlaysFilter filter) {
+                       ResetGui();
+                       
+                       if(project == null) {
+                               categories = null;
+                               tsList.Clear();
+                               loaded = false;
+                               return;
+                       }
+                       loaded = true;
+                       categories = project.Categories;
+                       tsList.Clear(); 
+                       frames = project.Description.File.GetFrames();
+                       
+                       cs.Categories = categories;
+                       cs.Filter = filter;
+                       cs.Show();
+                       
+                       tr.Frames = frames;
+                       tr.FrameRate = project.Description.File.Fps;
+                       tr.Show();
+                       
+                       foreach(Category cat in  categories) {
+                               List<Play> playsList = project.PlaysInCategory(cat);
+                               TimeScale ts = new TimeScale(cat, playsList, frames, filter);
+                               tsList[cat] = ts;
+                               ts.TimeNodeChanged += new TimeNodeChangedHandler(OnTimeNodeChanged);
+                               ts.TimeNodeSelected += new PlaySelectedHandler(OnTimeNodeSelected);
+                               ts.TimeNodeDeleted += new PlaysDeletedHandler(OnTimeNodeDeleted);
+                               ts.NewMarkAtFrameEvent += new NewTagAtFrameHandler(OnNewMark);
+                               TimelineBox.PackStart(ts,false,true,0);
+                               ts.Show();
                        }
+                       SetPixelRatio(3);
                }
 
                public void AddPlay(Play play) {
diff --git a/LongoMatch.GUI/Gui/Component/TimeScale.cs b/LongoMatch.GUI/Gui/Component/TimeScale.cs
index 528cb05..df524ec 100644
--- a/LongoMatch.GUI/Gui/Component/TimeScale.cs
+++ b/LongoMatch.GUI/Gui/Component/TimeScale.cs
@@ -39,7 +39,7 @@ namespace LongoMatch.Gui.Component
        [System.ComponentModel.ToolboxItem(true)]
        public class TimeScale : TimeScaleBase<Play>
        {
-               private Category category;
+               Category category;
                
                public event NewTagAtFrameHandler NewMarkAtFrameEvent;
                public event TimeNodeChangedHandler TimeNodeChanged;
@@ -47,10 +47,14 @@ namespace LongoMatch.Gui.Component
                public event PlaysDeletedHandler TimeNodeDeleted;
 
 
-               public TimeScale(Category category, List<Play> list, uint frames): base(list, frames)
+               public TimeScale(Category category, List<Play> list, uint frames, PlaysFilter filter): 
base(list, frames, filter)
                {
                        this.category = category;
                        elementName = Catalog.GetString("play");
+                       filter.FilterUpdated += () => {
+                               Visible = filter.VisibleCategories.Contains (category);
+                               QueueDraw();
+                       };
                }
 
                public void AddPlay(Play play) {
diff --git a/LongoMatch.GUI/Gui/Component/TimelineLabelsWidget.cs 
b/LongoMatch.GUI/Gui/Component/TimelineLabelsWidget.cs
index 79cbd9c..09571d4 100644
--- a/LongoMatch.GUI/Gui/Component/TimelineLabelsWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/TimelineLabelsWidget.cs
@@ -34,7 +34,8 @@ namespace LongoMatch.Gui.Component
                private const int LINE_WIDTH = 2;
                private double scroll;
                Pango.Layout layout;
-               Dictionary<Label, Gdk.Color> labelsDict;
+               Dictionary<Label, Category> labelsDict;
+               PlaysFilter filter;
 
                [System.ComponentModel.Category("LongoMatch")]
                [System.ComponentModel.ToolboxItem(true)]
@@ -43,14 +44,14 @@ namespace LongoMatch.Gui.Component
                        layout =  new Pango.Layout(PangoContext);
                        layout.Wrap = Pango.WrapMode.Char;
                        layout.Alignment = Pango.Alignment.Left;
-                       labelsDict = new Dictionary<Label, Gdk.Color> ();
+                       labelsDict = new Dictionary<Label, Category> ();
                }
 
                public List<string> Labels {
                        set {
                                labelsDict.Clear();
                                foreach (String label in value)
-                                       labelsDict.Add(new Label(label), Gdk.Color.Zero);
+                                       labelsDict.Add(new Label(label), null);
                        }
                }
                
@@ -58,7 +59,14 @@ namespace LongoMatch.Gui.Component
                        set {
                                labelsDict.Clear();
                                foreach (Category cat in value)
-                                       labelsDict.Add(new Label(cat.Name), 
Helpers.Misc.ToGdkColor(cat.Color));
+                                       labelsDict.Add(new Label(cat.Name), cat);
+                       }
+               }
+               
+               public PlaysFilter Filter {
+                       set {
+                               filter = value;
+                               filter.FilterUpdated += () => {QueueDraw();};
                        }
                }
 
@@ -88,11 +96,24 @@ namespace LongoMatch.Gui.Component
 
                        using(Cairo.Context g = Gdk.CairoHelper.Create(win)) {
                                foreach(Label label in labelsDict.Keys) {
-                                       int y = LINE_WIDTH/2 + i * SECTION_HEIGHT - (int)Scroll;
+                                       Cairo.Color color;
+                                       Category cat;
+                                       int y;
+                                       
+                                       cat = labelsDict[label];
+                                       y = LINE_WIDTH/2 + i * SECTION_HEIGHT - (int)Scroll;
+                                       
+                                       if (cat != null) {
+                                               if (filter != null && 
!filter.VisibleCategories.Contains(cat)) {
+                                                       continue;
+                                               }
+                                               color = 
CairoUtils.RGBToCairoColor(Helpers.Misc.ToGdkColor(cat.Color));
+                                       } else {
+                                               color = new Cairo.Color (0, 0, 0);
+                                       }
                                        CairoUtils.DrawRoundedRectangle(g, 2, y + 3 , Allocation.Width - 3,
                                                                        SECTION_HEIGHT - 3, SECTION_HEIGHT/7,
-                                                                       
CairoUtils.RGBToCairoColor(labelsDict[label]),
-                                                                       
CairoUtils.RGBToCairoColor(labelsDict[label]));
+                                                                       color, color);
                                        DrawCairoText(label.Text, 0 + 3, y + SECTION_HEIGHT / 2 - 5);
                                        i++;
                                }
diff --git a/LongoMatch.GUI/Gui/MainWindow.cs b/LongoMatch.GUI/Gui/MainWindow.cs
index 2920360..6b4f6c0 100644
--- a/LongoMatch.GUI/Gui/MainWindow.cs
+++ b/LongoMatch.GUI/Gui/MainWindow.cs
@@ -378,7 +378,7 @@ namespace LongoMatch.Gui
                                Title = System.IO.Path.GetFileNameWithoutExtension(desc.File.FilePath) +
                                        " - " + Constants.SOFTWARE_NAME;
                                playercapturer.LogoMode = false;
-                               timeline.Project = project;
+                               timeline.SetProject (project, filter);
                                guTimeline.Project = project;
 
                        } else {
diff --git a/LongoMatch.GUI/Gui/TreeView/CategoriesFilterTreeView.cs 
b/LongoMatch.GUI/Gui/TreeView/CategoriesFilterTreeView.cs
index 25f602a..ae5816a 100644
--- a/LongoMatch.GUI/Gui/TreeView/CategoriesFilterTreeView.cs
+++ b/LongoMatch.GUI/Gui/TreeView/CategoriesFilterTreeView.cs
@@ -64,8 +64,8 @@ namespace LongoMatch.Gui.Component
                        Model = store;
                }
                
-               protected override void UpdateSelection(TreeIter iter, bool active) {
-                       TreeIter child;
+               void UpdateSelectionPriv(TreeIter iter, bool active, bool checkParents=true, bool 
recurse=true) {
+                       TreeIter child, parent;
                        
                        object o = store.GetValue(iter, 0);
                        
@@ -78,13 +78,28 @@ namespace LongoMatch.Gui.Component
                        }
                        store.SetValue(iter, 1, active);
                        
+                       /* Check its parents */
+                       if (active && checkParents) {
+                               if (store.IterParent(out parent, iter)) {
+                                       UpdateSelectionPriv (parent, active, true, false);
+                               }
+                       }
+                       
                        /* Check/Uncheck all children */
-                       store.IterChildren(out child, iter);
-                       while (store.IterIsValid(child)) {
-                               UpdateSelection(child, active);
-                               store.IterNext(ref child);
+                       if (recurse) {
+                               store.IterChildren(out child, iter);
+                               while (store.IterIsValid(child)) {
+                                       UpdateSelectionPriv (child, active, false, true);
+                                       store.IterNext(ref child);
+                               }
                        }
-                       filter.Update();
+                       
+                       if (recurse && checkParents)
+                               filter.Update();
+               }
+               
+               protected override void UpdateSelection(TreeIter iter, bool active) {
+                       UpdateSelectionPriv (iter, active, true, true);
                }
  
                protected override void RenderColumn (TreeViewColumn column, CellRenderer cell, TreeModel 
model, TreeIter iter)


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