File indexing completed on 2024-05-05 04:48:45
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef PROGRESSIVESEARCHWIDGET_H 0018 #define PROGRESSIVESEARCHWIDGET_H 0019 0020 #include "widgets/LineEdit.h" 0021 #include "widgets/BoxWidget.h" 0022 0023 class QAction; 0024 class QKeyEvent; 0025 class QMenu; 0026 class QToolBar; 0027 0028 namespace Playlist 0029 { 0030 0031 /** 0032 A composite widget for progressive (Firefox style search as you type) 0033 searching, with buttons for next and previous result. Also includes 0034 a drop down menu to configure which fields in the track ( track name, 0035 album name, genre, ...) should be used for matching, as well as a config 0036 option for whether the current search and search fields should be taken 0037 into account when doing track progression (i.e. should navigators only 0038 jump between tracks that match the current search term) 0039 0040 @author Nikolaj Hald Nielsen <nhn@kde.org> 0041 */ 0042 class ProgressiveSearchWidget : public BoxWidget 0043 { 0044 Q_OBJECT 0045 0046 public: 0047 /** 0048 * Constructor. 0049 * @param parent The parent widget this is added to. 0050 */ 0051 explicit ProgressiveSearchWidget( QWidget * parent ); 0052 0053 QString currentFilter() const { return m_searchEdit->text(); } 0054 0055 void focusInputLine(); 0056 void setCurrentFilter( const QString &filterExpr ) { m_searchEdit->setText( filterExpr ); } 0057 0058 bool onlyMatches() const { return m_showOnlyMatches; } 0059 0060 Q_SIGNALS: 0061 /** 0062 * Signal emitted when the search term has changed. 0063 * @param filter The new search term. 0064 * @param fields The mask containing the fields to match against. 0065 * @param showOnlyMatches Determines whether to show only matches. 0066 */ 0067 void filterChanged( const QString &filter, int fields, bool showOnlyMatches ); 0068 0069 /** 0070 * Signal emitted when the search term is cleared. 0071 */ 0072 void filterCleared(); 0073 0074 /** 0075 * Signal emitted when the "next" button is pressed. 0076 * @param filter The current search term. 0077 * @param fields The mask containing the fields to match against. 0078 */ 0079 void next( const QString &filter, int fields ); 0080 0081 /** 0082 * Signal emitted when the "previous" button is pressed. 0083 * @param filter The current search term. 0084 * @param fields The mask containing the fields to match against. 0085 */ 0086 void previous( const QString &filter, int fields ); 0087 0088 /** 0089 * Signal emitted when the user changes the value of the "Play only 0090 * matches" option. 0091 * @param onlyMatches The value selected by the user. 0092 */ 0093 void showOnlyMatches( bool onlyMatches ); 0094 0095 /** 0096 * Signal emitted when the user presses the return key, signifying that the matched 0097 * item in the playlist should be activated 0098 */ 0099 void activateFilterResult(); 0100 0101 /** 0102 * Signal emitted when the down key is pressed. Forwarded on from Amarok::LineEdit 0103 */ 0104 void downPressed(); 0105 0106 /** 0107 * Signal emitted when the up key is pressed. Forwarded on from Amarok::LineEdit 0108 */ 0109 void upPressed(); 0110 0111 public Q_SLOTS: 0112 /** 0113 * Notify the widget that there are matches (at least one), so the next and previous actions 0114 * should be enabled and the text color set to normal. 0115 */ 0116 void match(); 0117 0118 /** 0119 * Notify the widget that there are no matches, so the next and previous actions 0120 * should be disabled and the text color set to no_match color. 0121 */ 0122 void noMatch(); 0123 0124 /** 0125 * Clear the filter. 0126 */ 0127 void slotFilterClear(); 0128 0129 /** 0130 * Toggle navigate only tracks that match the current search term and 0131 * search fields. (The user can always manually select a track that 0132 * is not a part of the search results. 0133 * @param onlyMatches On/off. 0134 */ 0135 void slotShowOnlyMatches( bool onlyMatches ); 0136 0137 protected Q_SLOTS: 0138 /** 0139 * Notify widget that the text in the search edit has changed. 0140 * @param filter The new text in the search widget. 0141 */ 0142 void slotFilterChanged( const QString &filter ); 0143 0144 /** 0145 * Notify widget that the "next" button has been pressed. 0146 */ 0147 void slotNext(); 0148 0149 /** 0150 * Notify widget that the "previous" button has been pressed. 0151 */ 0152 void slotPrevious(); 0153 0154 /** 0155 * Toggle track name matching when searching. 0156 * @param search On/off. 0157 */ 0158 void slotSearchTracks( bool search ); 0159 0160 /** 0161 * Toggle artist name matching when searching. 0162 * @param search On/off. 0163 */ 0164 void slotSearchArtists( bool search ); 0165 0166 /** 0167 * Toggle album name matching when searching. 0168 * @param search On/off. 0169 */ 0170 void slotSearchAlbums( bool search ); 0171 0172 /** 0173 * Toggle genre name matching when searching. 0174 * @param search On/off. 0175 */ 0176 void slotSearchGenre( bool search ); 0177 0178 /** 0179 * Toggle composer name matching when searching. 0180 * @param search On/off. 0181 */ 0182 void slotSearchComposers( bool search ); 0183 0184 /** 0185 * toggle rating matching when searching 0186 * @param search On/off. 0187 */ 0188 void slotSearchRating( bool search ); 0189 0190 /** 0191 * Toggle year matching when searching. 0192 * @param search On/off. 0193 */ 0194 void slotSearchYears( bool search ); 0195 0196 protected: 0197 void keyPressEvent( QKeyEvent *event ) override; 0198 0199 private Q_SLOTS: 0200 void defocus() { m_searchEdit->clearFocus(); } 0201 0202 private: 0203 /** 0204 * Load the current search field settings from config. 0205 */ 0206 void readConfig(); 0207 0208 Amarok::LineEdit *m_searchEdit; 0209 QAction *m_nextAction; 0210 QAction *m_previousAction; 0211 QMenu *m_menu; 0212 QToolBar *m_toolBar; 0213 0214 int m_searchFieldsMask; 0215 bool m_showOnlyMatches; 0216 0217 QString m_lastFilter; 0218 }; 0219 0220 } //namespace Playlist 0221 0222 #endif