File indexing completed on 2024-05-19 04:49:49
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * Copyright (c) 2010 Oleksandr Khayrullin <saniokh@gmail.com> * 0004 * Copyright (c) 2010 Nanno Langstraat <langstr@gmail.com> * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify it under * 0007 * the terms of the GNU General Public License as published by the Free Software * 0008 * Foundation; either version 2 of the License, or (at your option) any later * 0009 * version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0013 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License along with * 0016 * this program. If not, see <http://www.gnu.org/licenses/>. * 0017 ****************************************************************************************/ 0018 0019 #ifndef LAYOUTITEMCONFIG_H 0020 #define LAYOUTITEMCONFIG_H 0021 0022 #include <QList> 0023 #include <QModelIndex> 0024 #include <QString> 0025 0026 namespace Playlist { 0027 0028 enum 0029 { 0030 ITEM_LEFT, 0031 ITEM_RIGHT, 0032 ITEM_CENTER 0033 }; 0034 0035 /** 0036 * This class corresponds to a single element in a single row in a playlist layout 0037 * @author Nikolaj Hald Nielsen <nhn@kde.org> 0038 */ 0039 class LayoutItemConfigRowElement 0040 { 0041 public: 0042 /** 0043 * Constructor. 0044 * @param value An integer representing the information that this item is to show. 0045 * @param size The percentage size of the row that this item should use. If 0, this 0046 * item shares the space leftover by any non 0 items with all other items with size 0 on the same row. 0047 * @param bold Make the item text bold. 0048 * @param italic Make the item text italic. 0049 * @param underline Make the item text underline. 0050 * @param alignment the alignment of the item (ITEM_LEFT, ITEM_RIGHT or ITEM_CENTER). 0051 * @param prefix Text to show before the actual value text. 0052 * @param suffix Text to show after the actual value text. 0053 */ 0054 LayoutItemConfigRowElement( int value, qreal size, 0055 bool bold, bool italic, bool underline, 0056 Qt::Alignment alignment, 0057 const QString &prefix = QString(), 0058 const QString &suffix = QString() ); 0059 0060 /** 0061 * Get the value of this element. 0062 * @return The value. 0063 */ 0064 int value() const; 0065 0066 /** 0067 * Get the percentage of the row that this element should take up. 0068 * @return The percentage size. 0069 */ 0070 qreal size() const; 0071 0072 /** 0073 * Set the percentage of the row that this element should take up. 0074 */ 0075 void setSize( qreal size ); 0076 0077 /** 0078 * Get whether text should be bold. 0079 * @return Bold or not. 0080 */ 0081 bool bold() const; 0082 0083 /** 0084 * Get whether text should be italic. 0085 * @return Italic or not. 0086 */ 0087 bool italic() const; 0088 0089 /** 0090 * Get whether text should be underlined. 0091 * @return Underlined or not. 0092 */ 0093 bool underline() const; 0094 0095 /** 0096 * Get the alignment of this element. 0097 * @return The alignment. 0098 */ 0099 Qt::Alignment alignment() const; 0100 0101 /** 0102 * Get the prefix. This text is shown before the actual text mandated by value(). For instance, if the value is Artist, a prefix 0103 * could be "Artist: ". This would make the text in the playlist appear as "Artist: _ARTIST_NAME_" 0104 * @return The prefix text. 0105 */ 0106 QString prefix() const; 0107 0108 /** 0109 * Get the suffix. This text is shown after the actual text mandated by value(). For instance, if the value is PlayCount, a prefix 0110 * could be " plays". This would make the text in the playlist appear as "_NO_OF_PLAYS_ plays" 0111 * @return The suffix text. 0112 */ 0113 QString suffix() const; 0114 0115 private: 0116 int m_value; 0117 qreal m_size; 0118 bool m_bold; 0119 bool m_italic; 0120 bool m_underline; 0121 Qt::Alignment m_alignment; 0122 QString m_prefix, m_suffix; 0123 }; 0124 0125 /** 0126 * This class corresponds to a row in a playlist layout 0127 * @author Nikolaj Hald Nielsen <nhn@kde.org> 0128 */ 0129 class LayoutItemConfigRow 0130 { 0131 public: 0132 0133 /** 0134 * Add an element to the end of this row. 0135 * @param element The element to add. 0136 */ 0137 void addElement(const LayoutItemConfigRowElement &element ); 0138 0139 /** 0140 * Get the number of elements in this row. 0141 * @return The element count. 0142 */ 0143 int count(); 0144 0145 /** 0146 * Get the element at a specific index. 0147 * @param at The index of the element. 0148 * @return The element at the index. 0149 */ 0150 LayoutItemConfigRowElement element( int at ); 0151 private: 0152 QList<LayoutItemConfigRowElement> m_elements; 0153 }; 0154 0155 /** 0156 * This class wraps the data needed to paint a LayoutItemDelegate. It knows how many vertical 0157 * rows there should be, how many items in each row, whether an image should be displayed and so on. 0158 * @author Nikolaj Hald Nielsen <nhn@kde.org> 0159 */ 0160 class LayoutItemConfig 0161 { 0162 public: 0163 /** 0164 * Constructor. 0165 */ 0166 LayoutItemConfig(); 0167 0168 /** 0169 * Destructor. 0170 */ 0171 ~LayoutItemConfig(); 0172 0173 /** 0174 * Get the number of rows in this layoutConfig. 0175 * @return The row count. 0176 */ 0177 int rows() const; 0178 0179 /** 0180 * Get a specific row. 0181 * @param at The row index. 0182 * @return The row at the index. 0183 */ 0184 LayoutItemConfigRow row( int at ) const; 0185 0186 /** 0187 * Get whether a cover should be shown. 0188 * @return Show the cover. 0189 */ 0190 bool showCover() const; 0191 0192 /** 0193 * Get which row should be used to paint the active indicator. This is the graphics that is used to show which track is the 0194 * currently playing one. For different configs it might make sense to show this on different rows, usually the one containing the track name. 0195 * @return The row to paint the current track indicator on. 0196 */ 0197 int activeIndicatorRow() const; 0198 0199 /** 0200 * Add a row to this config. 0201 * @param row The row to add. 0202 */ 0203 void addRow( const LayoutItemConfigRow &row ); 0204 0205 /** 0206 * Set whether the cover image should be shown or not. 0207 * @param showCover Show the cover image. 0208 */ 0209 void setShowCover( bool showCover ); 0210 0211 /** 0212 * Get the row that should be used to paint the current track indicator. 0213 * @param row The row to show the indicator on. 0214 */ 0215 void setActiveIndicatorRow( int row ); 0216 0217 private: 0218 QList<LayoutItemConfigRow> m_rows; 0219 bool m_showCover; 0220 int m_activeIndicatorRow; 0221 }; 0222 0223 /** 0224 * This class wraps the data that makes up a playlist layout. A layout consists of 3 LayoutItemConfigs one used for 0225 * painting single tracks, one used for painting group headers and one used for painting group members. 0226 * @author Nikolaj Hald Nielsen <nhn@kde.org> 0227 */ 0228 class PlaylistLayout 0229 { 0230 public: 0231 enum Part { 0232 Head = 0, 0233 StandardBody, 0234 VariousArtistsBody, 0235 Single, 0236 NumParts // The number of Part values 0237 }; 0238 0239 /** 0240 * Default Constructor 0241 */ 0242 PlaylistLayout(); 0243 0244 /** 0245 * Get whether this config can be edited/deleted. The default layouts shipped with Amarok are read only, 0246 * but all user generated layouts can be modified or deleted. 0247 * @return Can this layout be edited or deleted by the user. 0248 */ 0249 bool isEditable() const; 0250 0251 /** 0252 * Get whether this layout has been changed and needs to be saved. 0253 * @return Has this layout changed. 0254 */ 0255 bool isDirty() const; 0256 0257 /** 0258 * Determine the layout config for an item in a QAbstractItemModel. 0259 * Convenience function. 0260 */ 0261 LayoutItemConfig layoutForItem( const QModelIndex &index ) const { return layoutForPart( partForItem( index ) ); } 0262 0263 /** 0264 * Determine the part type for an item in a QAbstractItemModel. 0265 */ 0266 Part partForItem( const QModelIndex &index ) const; 0267 0268 /** 0269 * Get the layout config for the specified part type. 0270 */ 0271 LayoutItemConfig layoutForPart( Part part ) const; 0272 0273 /** 0274 * Set the layout config for the specified part type. 0275 */ 0276 void setLayoutForPart( Part part, const LayoutItemConfig &itemConfig ); 0277 0278 /** 0279 * Set whether this config can be edited by the user. 0280 * @param editable Can this config be edited. 0281 */ 0282 void setEditable( bool editable ); 0283 0284 /** 0285 * Set whether this config has changed and has not yet been saved to file. 0286 * @param dirty Is this layout dirty. 0287 */ 0288 void setDirty( bool dirty ); 0289 0290 bool inlineControls(); 0291 void setInlineControls( bool inlineControls ); 0292 0293 bool tooltips(); 0294 void setTooltips( bool tooltips ); 0295 0296 QString groupBy(); 0297 void setGroupBy( const QString & ); 0298 0299 private: 0300 LayoutItemConfig m_layoutItemConfigs[NumParts]; 0301 0302 bool m_isEditable; 0303 bool m_isDirty; 0304 bool m_inlineControls; 0305 bool m_tooltips; 0306 0307 QString m_groupBy; 0308 }; 0309 0310 } 0311 0312 #endif