]> git.sesse.net Git - vlc/blob - modules/gui/skins2/utils/var_tree.hpp
Introduce setLayoutMargins for layout margins difference between Qt4.2 and Qt4.3
[vlc] / modules / gui / skins2 / utils / var_tree.hpp
1 /*****************************************************************************
2  * var_tree.hpp
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea@videolan.org>
8  *          ClĂ©ment Stenac <zorglub@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifndef VAR_TREE_HPP
26 #define VAR_TREE_HPP
27
28 #include <list>
29
30 #include "variable.hpp"
31 #include "observer.hpp"
32 #include "ustring.hpp"
33 #include "var_percent.hpp"
34
35 /// Description of an update to the tree
36 typedef struct tree_update
37 {
38      int i_type;
39      int i_parent;
40      int i_id;
41      bool b_active_item;
42      bool b_visible;
43 } tree_update;
44
45 /// Tree variable
46 class VarTree: public Variable, public Subject<VarTree, tree_update>
47 {
48     public:
49         VarTree( intf_thread_t *pIntf );
50
51         VarTree( intf_thread_t *pIntf, VarTree *pParent, int id,
52                  const UStringPtr &rcString, bool selected, bool playing,
53                  bool expanded,bool readonly, void *pData );
54
55         virtual ~VarTree();
56
57         /// Get the variable type
58         virtual const string &getType() const { return m_type; }
59
60         /// Add a pointer on string in the children's list
61         virtual void add( int id, const UStringPtr &rcString, bool selected,
62                           bool playing, bool expanded, bool readonly,
63                           void *pData );
64
65         /// Remove the selected item from the children's list
66         virtual void delSelected();
67
68         /// Remove all elements from the children's list
69         virtual void clear();
70
71         /// \todo Use accessors for these fields ?
72         int m_id;
73         UStringPtr m_cString;
74         bool m_selected;
75         bool m_playing;
76         bool m_expanded;
77         bool m_deleted;
78         void *m_pData;
79
80         inline bool isReadonly() { return m_readonly; };
81
82         /// Get the number of children
83         int size() const { return m_children.size(); }
84
85         /// Iterators
86         typedef list<VarTree>::iterator Iterator;
87         typedef list<VarTree>::const_iterator ConstIterator;
88
89         /// Begining of the children's list
90         Iterator begin() { return m_children.begin(); }
91         ConstIterator begin() const { return m_children.begin(); }
92
93         /// End of children's list
94         Iterator end() { return m_children.end(); }
95         ConstIterator end() const { return m_children.end(); }
96
97         /// Back of children's list
98         VarTree &back() { return m_children.back(); }
99
100         /// Return an iterator on the n'th element of the children's list
101         Iterator operator[]( int n );
102         ConstIterator operator[]( int n ) const;
103
104         /// Parent node
105         VarTree *parent() { return m_pParent; }
106         void checkParents( VarTree *pParent );
107
108         /// Get next sibling
109         Iterator getNextSibling( Iterator );
110
111         Iterator next_uncle();
112         Iterator prev_uncle();
113
114         /// Get root node
115         VarTree *root()
116         {
117             VarTree *parent = this;
118             while( parent->parent() != NULL )
119                 parent = parent->parent();
120             return parent;
121         }
122
123         /// Get first leaf
124         Iterator firstLeaf();
125
126         void removeChild( VarTree::Iterator item )
127         {
128             m_children.erase( item );
129         }
130
131         /// Execute the action associated to this item
132         virtual void action( VarTree *pItem ) {}
133
134         /// Get a reference on the position variable
135         VarPercent &getPositionVar() const
136         { return *((VarPercent*)m_cPosition.get()); }
137
138         /// Get a counted pointer on the position variable
139         const VariablePtr &getPositionVarPtr() const { return m_cPosition; }
140
141         /// Count the number of items that should be displayed if the playlist window wasn't limited
142         int visibleItems();
143
144         /// Count the number of leafs in the tree
145         int countLeafs();
146
147         /// Return iterator to the n'th visible item
148         Iterator getVisibleItem( int n );
149
150         /// Return iterator to the n'th leaf
151         Iterator getLeaf( int n );
152
153         /// Given an iterator to a visible item, return the next visible item
154         Iterator getNextVisibleItem( Iterator it );
155
156         /// Given an it to a visible item, return the previous visible item
157         Iterator getPrevVisibleItem( Iterator it );
158
159         /// Given an iterator to an item, return the next item
160         Iterator getNextItem( Iterator it );
161
162         /// Given an iterator to an item, return the previous item
163         Iterator getPrevItem( Iterator it );
164
165         /// Given an iterator to an item, return the next leaf
166         Iterator getNextLeaf( Iterator it );
167
168         /// Given an iterator to an item, return the previous leaf
169         Iterator getPrevLeaf( Iterator it );
170
171         /// Find a children node with the given id
172         Iterator findById( int id );
173
174         /// Ensure an item is expanded
175         void ensureExpanded( VarTree::Iterator );
176
177         /// Get depth (root depth is 0)
178         int depth()
179         {
180             VarTree *parent = this;
181             int depth = 0;
182             while( ( parent = parent->parent() ) != NULL )
183                 depth++;
184             return depth;
185         }
186
187
188     private:
189         /// List of children
190         list<VarTree> m_children;
191
192         /// Pointer to parent node
193         VarTree *m_pParent;
194
195         bool m_readonly;
196
197         /// Variable type
198         static const string m_type;
199
200         /// Position variable
201         VariablePtr m_cPosition;
202 };
203
204 #endif