Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

SelectionCollection.h

Go to the documentation of this file.
00001 #ifndef VideoExcel_SelectionCollection_h
00002 #define VideoExcel_SelectionCollection_h
00003 
00004 #include "SelectionCollectionItem.h"
00005 #include "OglGui/ScrollWnd.h"
00006 
00007 namespace Impala {
00008 namespace Application {
00009 namespace VideoExcel {
00010 
00011 
00012 class SelectionCollection : public OglGui::Window,
00013                             OglGui::ScrollBarListener,
00014                             TableUpdateListener,
00015                             SelectionCollectionListener
00016 {
00017 public:
00018     typedef OglGui::Window                          Window;
00019     typedef OglGui::ScrollBar                       ScrollBar;
00020     typedef OglGui::ScrollWnd                       ScrollWnd;
00021 
00022     SelectionCollection(Window* parent, TableDataSource *source, int w, int h) :
00023         Window(parent, w, h)
00024     {
00025         Init(source, w, h);
00026     }
00027 
00028     SelectionCollection(Window* parent, TableDataSource *source, int x, int y,
00029                         int w, int h) :
00030         Window(parent, x, y, w, h)
00031     {
00032         Init(source, w, h);
00033     }
00034 
00035 // Listeners
00036     virtual void UpdateSelectionEvent()
00037     {
00038         UpdateItemCounts();
00039     }
00040 
00041     virtual void OnScroll(ScrollBar *src, int position, void *userData)
00042     {
00043     }
00044 
00045     virtual void MouseFunc(int msg, int but, int state, int x, int y)
00046     {
00047     }
00048 
00049     virtual void KeyboardFunc(int c, int state)
00050     {
00051     }
00052 
00053     void UpdateItemCounts()
00054     {
00055         ILOG_DEBUG("UpdateItemCounts");
00056         std::map<int, int>  marks   = mSource->GetMarkedRowsMap();
00057         std::map<int, bool> visible = mSource->GetVisibleRowsMap();
00058         std::map<int, int>  markcounts;
00059         std::map<int, int>  markviscounts;
00060 
00061         for (int x = 0; x < 9; x++)
00062         {
00063             markcounts[x]    = 0;
00064             markviscounts[x] = 0;
00065         }
00066 
00067         for (int x = 0; x < mSource->GetTotalRows(); x++)
00068         {
00069             if(marks.find(x) != marks.end())
00070             {
00071                 int mark = marks[x];
00072 
00073                 if (mark & 1)   markcounts[1] += 1;
00074                 if (mark & 2)   markcounts[2] += 1;
00075                 if (mark & 4)   markcounts[3] += 1;
00076                 if (mark & 8)   markcounts[4] += 1;
00077                 if (mark & 16)  markcounts[5] += 1;
00078                 if (mark & 32)  markcounts[6] += 1;
00079                 if (mark & 64)  markcounts[7] += 1;
00080                 if (mark & 128) markcounts[8] += 1;
00081                 if (visible[x])
00082                 {
00083                     if (mark & 1)   markviscounts[1] += 1;
00084                     if (mark & 2)   markviscounts[2] += 1;
00085                     if (mark & 4)   markviscounts[3] += 1;
00086                     if (mark & 8)   markviscounts[4] += 1;
00087                     if (mark & 16)  markviscounts[5] += 1;
00088                     if (mark & 32)  markviscounts[6] += 1;
00089                     if (mark & 64)  markviscounts[7] += 1;
00090                     if (mark & 128) markviscounts[8] += 1;
00091                 }
00092             }
00093             else
00094             {
00095                 markcounts[0] += 1;
00096                 if (visible[x])
00097                     markviscounts[0] += 1;
00098             }
00099         }
00100 
00101         for (int x=0; x < 9; x++)
00102             mItems[x + 1]->SetItemCounts(markcounts[x], markviscounts[x]);
00103 
00104         mItems[0]->SetItemCounts(mSource->GetTotalRows(),
00105                                  mSource->GetFilteredRows());
00106         ILOG_DEBUG("UpdateItemCounts done");
00107     }
00108 
00109     /* selection collection listeners ******************************/
00110 
00111     virtual void SelectCollectionEvent(int id)
00112     {
00113         if (id==-1)
00114             mSource->DisableFilterByMark();
00115         else
00116             mSource->EnableFilterByMark(id);
00117         ProcessHighlights();
00118     }
00119 
00120     virtual void SelectCollectionInvertedEvent(int id)
00121     {
00122         int everything = mSource->GetMarkFilterForEverything();
00123         mSource->EnableFilterByMark(everything & ~id);
00124         ProcessHighlights();
00125     }
00126 
00127     virtual void AddCollectionToSelectionEvent(int id)
00128     {
00129         mSource->EnableFilterByMark(mSource->GetMarkFilter() | id);
00130         ProcessHighlights();
00131     }
00132 
00133     virtual void RemoveCollectionFromSelectionEvent(int id)
00134     {
00135         mSource->EnableFilterByMark(mSource->GetMarkFilter() & ~id);
00136         ProcessHighlights();
00137     }
00138 
00139     void ProcessHighlights()
00140     {
00141         int id = mSource->GetMarkFilter();
00142         for (int x=0; x<mItems.size(); x++)
00143             mItems[x]->SetHighlighted(false);
00144 
00145         if (id==-1)
00146             mItems[0]->SetHighlighted(true);
00147         else
00148         {
00149             if (id== 0)  mItems[1]->SetHighlighted(true);
00150             if (id & 1)  mItems[2]->SetHighlighted(true);
00151             if (id & 2)  mItems[3]->SetHighlighted(true);
00152             if (id & 4)  mItems[4]->SetHighlighted(true);
00153             if (id & 8)  mItems[5]->SetHighlighted(true);
00154             if (id & 16) mItems[6]->SetHighlighted(true);
00155             if (id & 32) mItems[7]->SetHighlighted(true);
00156             if (id & 64) mItems[8]->SetHighlighted(true);
00157             if (id & 128) mItems[9]->SetHighlighted(true);
00158         }
00159    }
00160 
00161 private :
00162 
00163     int MarkToColor(int m)
00164     {
00165         int r=127,g=127,b=127;
00166         if (m == -1)
00167             return ARGB2COLOR(255, 200, 200, 200);
00168         if (m & 1)
00169             r = g = b = 255;
00170         if (m & 2)
00171             r = g = b = 20;
00172         if (m & 4)
00173             r += 64;
00174         if (m & 8)
00175             g += 64;
00176         if (m & 16)
00177             b += 64;
00178         if (m & 32)
00179             { r += 64; g += 64; }
00180         if (m & 64)
00181             { g += 64; b += 64; }
00182         if (m & 128)
00183             { r += 64; b += 64; }
00184         if (r>255) r = 255;
00185         if (g>255) g = 255;
00186         if (b>255) b = 255;
00187         return ARGB2COLOR(255, r,g,b);
00188     }
00189 
00190     SelectionCollectionItem*
00191     MakeSelectionCollectionItem(std::string name, int markID)
00192     {
00193         Window* pane = mItemWindow->ContentPane();
00194         SelectionCollectionItem *item =
00195             new SelectionCollectionItem(pane, markID, MarkToColor(markID));
00196         item->SetItemName(name);
00197         item->SetListener(this);
00198         return item;
00199     }
00200 
00201     void Init(TableDataSource *source, int w, int h)
00202     {
00203         mSource = source;
00204         mSource->AddTableUpdateListener(this);
00205 
00206         SetBorderType(1);
00207         SetBorderFillShaded(-2);
00208 
00209         mItemWindow = new ScrollWnd(this, 16, 16, W()-32, H()-32);
00210         mItemWindow->ConnectTo(this);
00211         mItemWindow->ContentPane()->SetDimensions(0, 0, 10 * 90, 90);
00212 
00213         mItems.push_back(MakeSelectionCollectionItem("everything", -1));
00214         mItems.push_back(MakeSelectionCollectionItem("unknown", 0));
00215         mItems.push_back(MakeSelectionCollectionItem("selected", 1));
00216         mItems.push_back(MakeSelectionCollectionItem("seen", 2));
00217         mItems.push_back(MakeSelectionCollectionItem("red", 4));
00218         mItems.push_back(MakeSelectionCollectionItem("green", 8));
00219         mItems.push_back(MakeSelectionCollectionItem("blue", 16));
00220         mItems.push_back(MakeSelectionCollectionItem("yellow", 32));
00221         mItems.push_back(MakeSelectionCollectionItem("cyan", 64));
00222         mItems.push_back(MakeSelectionCollectionItem("other", 128));
00223 
00224         mItems[0]->SetHighlighted(true);
00225     }
00226 
00227     TableDataSource*                        mSource;
00228     ScrollWnd*                              mItemWindow;
00229 
00230     std::vector<SelectionCollectionItem*>   mItems;
00231 
00232     ILOG_VAR_DEC;
00233 };
00234 
00235 ILOG_VAR_INIT(SelectionCollection, Application.VideoExcel);
00236 
00237 
00238 } // namespace VideoExcel
00239 } // namespace Application
00240 } // namespace Impala
00241 
00242 #endif // SelectionCollection_h

Generated on Fri Mar 19 09:30:33 2010 for ImpalaSrc by  doxygen 1.5.1