Debian Codegraph @

src/playlist/layouts/LayoutItemConfig.h

raw
1 /****************************************************************************************
2 * Copyright (c) 2008 Nikolaj Hald Nielsen <[email protected]> *
3 * Copyright (c) 2010 Oleksandr Khayrullin <[email protected]> *
4 * Copyright (c) 2010 Nanno Langstraat <[email protected]> *
5 * *
6 * This program is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU General Public License as published by the Free Software *
8 * Foundation; either version 2 of the License, or (at your option) any later *
9 * version. *
10 * *
11 * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License along with *
16 * this program. If not, see <http://www.gnu.org/licenses/>. *
17 ****************************************************************************************/
18
19 #ifndef LAYOUTITEMCONFIG_H
20 #define LAYOUTITEMCONFIG_H
21
22 #include <QList>
23 #include <QModelIndex>
24 #include <QString>
25
26 namespace Playlist {
27
28 enum
29 {
30 ITEM_LEFT,
31 ITEM_RIGHT,
32 ITEM_CENTER
33 };
34
35 /**
36 * This class corresponds to a single element in a single row in a playlist layout
37 * @author Nikolaj Hald Nielsen <[email protected]>
38 */
39 class LayoutItemConfigRowElement
40 {
41 public:
42 /**
43 * Constructor.
44 * @param value An integer representing the information that this item is to show.
45 * @param size The percentage size of the row that this item should use. If 0, this
46 * item shares the space leftover by any non 0 items with all other items with size 0 on the same row.
47 * @param bold Make the item text bold.
48 * @param italic Make the item text italic.
49 * @param underline Make the item text underline.
50 * @param alignment the alignment of the item (ITEM_LEFT, ITEM_RIGHT or ITEM_CENTER).
51 * @param prefix Text to show before the actual value text.
52 * @param suffix Text to show after the actual value text.
53 */
54 LayoutItemConfigRowElement( int value, qreal size,
55 bool bold, bool italic, bool underline,
56 Qt::Alignment alignment,
57 const QString &prefix = QString(),
58 const QString &suffix = QString() );
59
60 /**
61 * Get the value of this element.
62 * @return The value.
63 */
64 int value() const;
65
66 /**
67 * Get the percentage of the row that this element should take up.
68 * @return The percentage size.
69 */
70 qreal size() const;
71
72 /**
73 * Set the percentage of the row that this element should take up.
74 */
75 void setSize( qreal size );
76
77 /**
78 * Get whether text should be bold.
79 * @return Bold or not.
80 */
81 bool bold() const;
82
83 /**
84 * Get whether text should be italic.
85 * @return Italic or not.
86 */
87 bool italic() const;
88
89 /**
90 * Get whether text should be underlined.
91 * @return Underlined or not.
92 */
93 bool underline() const;
94
95 /**
96 * Get the alignment of this element.
97 * @return The alignment.
98 */
99 Qt::Alignment alignment() const;
100
101 /**
102 * Get the prefix. This text is shown before the actual text mandated by value(). For instance, if the value is Artist, a prefix
103 * could be "Artist: ". This would make the text in the playlist appear as "Artist: _ARTIST_NAME_"
104 * @return The prefix text.
105 */
106 QString prefix() const;
107
108 /**
109 * Get the suffix. This text is shown after the actual text mandated by value(). For instance, if the value is PlayCount, a prefix
110 * could be " plays". This would make the text in the playlist appear as "_NO_OF_PLAYS_ plays"
111 * @return The suffix text.
112 */
113 QString suffix() const;
114
115 private:
116 int m_value;
117 qreal m_size;
118 bool m_bold;
119 bool m_italic;
120 bool m_underline;
121 Qt::Alignment m_alignment;
122 QString m_prefix, m_suffix;
123 };
124
125 /**
126 * This class corresponds to a row in a playlist layout
127 * @author Nikolaj Hald Nielsen <[email protected]>
128 */
129 class LayoutItemConfigRow
130 {
131 public:
132
133 /**
134 * Add an element to the end of this row.
135 * @param element The element to add.
136 */
137 void addElement(const LayoutItemConfigRowElement &element );
138
139 /**
140 * Get the number of elements in this row.
141 * @return The element count.
142 */
143 int count();
144
145 /**
146 * Get the element at a specific index.
147 * @param at The index of the element.
148 * @return The element at the index.
149 */
150 LayoutItemConfigRowElement element( int at );
151 private:
152 QList<LayoutItemConfigRowElement> m_elements;
153 };
154
155 /**
156 * This class wraps the data needed to paint a LayoutItemDelegate. It knows how many vertical
157 * rows there should be, how many items in each row, whether an image should be displayed and so on.
158 * @author Nikolaj Hald Nielsen <[email protected]>
159 */
160 class LayoutItemConfig
161 {
162 public:
163 /**
164 * Constructor.
165 */
166 LayoutItemConfig();
167
168 /**
169 * Destructor.
170 */
171 ~LayoutItemConfig();
172
173 /**
174 * Get the number of rows in this layoutConfig.
175 * @return The row count.
176 */
177 int rows() const;
178
179 /**
180 * Get a specific row.
181 * @param at The row index.
182 * @return The row at the index.
183 */
184 LayoutItemConfigRow row( int at ) const;
185
186 /**
187 * Get whether a cover should be shown.
188 * @return Show the cover.
189 */
190 bool showCover() const;
191
192 /**
193 * Get which row should be used to paint the active indicator. This is the graphics that is used to show which track is the
194 * currently playing one. For different configs it might make sense to show this on different rows, usually the one containing the track name.
195 * @return The row to paint the current track indicator on.
196 */
197 int activeIndicatorRow() const;
198
199 /**
200 * Add a row to this config.
201 * @param row The row to add.
202 */
203 void addRow( const LayoutItemConfigRow &row );
204
205 /**
206 * Set whether the cover image should be shown or not.
207 * @param showCover Show the cover image.
208 */
209 void setShowCover( bool showCover );
210
211 /**
212 * Get the row that should be used to paint the current track indicator.
213 * @param row The row to show the indicator on.
214 */
215 void setActiveIndicatorRow( int row );
216
217 private:
218 QList<LayoutItemConfigRow> m_rows;
219 bool m_showCover;
220 int m_activeIndicatorRow;
221 };
222
223 /**
224 * This class wraps the data that makes up a playlist layout. A layout consists of 3 LayoutItemConfigs one used for
225 * painting single tracks, one used for painting group headers and one used for painting group members.
226 * @author Nikolaj Hald Nielsen <[email protected]>
227 */
228 class PlaylistLayout
229 {
230 public:
231 enum Part {
232 Head = 0,
233 StandardBody,
234 VariousArtistsBody,
235 Single,
236 NumParts // The number of Part values
237 };
238
239 /**
240 * Default Constructor
241 */
242 PlaylistLayout();
243
244 /**
245 * Get whether this config can be edited/deleted. The default layouts shipped with Amarok are read only,
246 * but all user generated layouts can be modified or deleted.
247 * @return Can this layout be edited or deleted by the user.
248 */
249 bool isEditable() const;
250
251 /**
252 * Get whether this layout has been changed and needs to be saved.
253 * @return Has this layout changed.
254 */
255 bool isDirty() const;
256
257 /**
258 * Determine the layout config for an item in a QAbstractItemModel.
259 * Convenience function.
260 */
261 LayoutItemConfig layoutForItem( const QModelIndex &index ) const { return layoutForPart( partForItem( index ) ); }
262
263 /**
264 * Determine the part type for an item in a QAbstractItemModel.
265 */
266 Part partForItem( const QModelIndex &index ) const;
267
268 /**
269 * Get the layout config for the specified part type.
270 */
271 LayoutItemConfig layoutForPart( Part part ) const;
272
273 /**
274 * Set the layout config for the specified part type.
275 */
276 void setLayoutForPart( Part part, const LayoutItemConfig &itemConfig );
277
278 /**
279 * Set whether this config can be edited by the user.
280 * @param editable Can this config be edited.
281 */
282 void setEditable( bool editable );
283
284 /**
285 * Set whether this config has changed and has not yet been saved to file.
286 * @param dirty Is this layout dirty.
287 */
288 void setDirty( bool dirty );
289
290 bool inlineControls();
291 void setInlineControls( bool inlineControls );
292
293 bool tooltips();
294 void setTooltips( bool tooltips );
295
296 QString groupBy();
297 void setGroupBy( const QString & );
298
299 private:
300 LayoutItemConfig m_layoutItemConfigs[NumParts];
301
302 bool m_isEditable;
303 bool m_isDirty;
304 bool m_inlineControls;
305 bool m_tooltips;
306
307 QString m_groupBy;
308 };
309
310 }
311
312 #endif