File indexing completed on 2024-04-28 17:06:21
0001 /* 0002 SPDX-FileCopyrightText: 2010 Jan Lepper <dehtris@yahoo.de> 0003 SPDX-FileCopyrightText: 2010-2022 Krusader Krew <https://krusader.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef KRSEARCHBAR_H 0009 #define KRSEARCHBAR_H 0010 0011 #include <QComboBox> 0012 #include <QToolButton> 0013 #include <QWidget> 0014 0015 #include <KCompletion/KComboBox> 0016 0017 class KrView; 0018 0019 /** 0020 * @brief Search, select or filter files by search string 0021 * 0022 * The search bar can be used in three different modes: 0023 * search: cursor jumpes with up/down arrow keys to previous/next matching file 0024 * select: all files in model matching an expression are selected 0025 * filter: all files in model not matching an expression are filtered (hidden) 0026 * 0027 * These actions are implemented in KrView and KrViewOperator. 0028 * 0029 * NOTE: some key events in KrView are filtered here. 0030 */ 0031 class KrSearchBar : public QWidget 0032 { 0033 Q_OBJECT 0034 0035 public: 0036 enum SearchMode { 0037 MODE_DEFAULT = -1, 0038 // NOTE: values used for combobox index 0039 MODE_SEARCH = 0, 0040 MODE_SELECT = 1, 0041 MODE_FILTER = 2, 0042 }; 0043 0044 public: 0045 KrSearchBar(KrView *view, QWidget *parent); 0046 /** 0047 * Set another KrView, old one must not be deleted yet! 0048 */ 0049 void setView(KrView *view); 0050 /** 0051 * Hide the search bar if its mode was the search one. 0052 * 0053 * This function is normally used to hide bar after a user has quicksearched for something and found it. 0054 */ 0055 void hideBarIfSearching(); 0056 0057 public slots: 0058 void showBar(SearchMode mode = MODE_DEFAULT); 0059 void hideBar(); 0060 /** 0061 * Reset search to empty string. 0062 */ 0063 void resetSearch(); 0064 0065 protected slots: 0066 void onModeChange(); 0067 void onSearchChange(); 0068 /** 0069 * Save current search string to settings 0070 */ 0071 void saveSearchString(); 0072 0073 protected: 0074 void keyPressEvent(QKeyEvent *) override; 0075 /** 0076 * Filter key events from view widget and text combo box 0077 */ 0078 bool eventFilter(QObject *, QEvent *) override; 0079 0080 private: 0081 /** 0082 * Handle events when search bar is open or open it. 0083 */ 0084 bool handleKeyPressEvent(QKeyEvent *ke); 0085 bool handleUpDownKeyPress(bool); 0086 bool handleLeftRightKeyPress(QKeyEvent *ke); 0087 /** 0088 * Set color of line edit to highlight if anything matches. 0089 */ 0090 void indicateMatch(bool); 0091 static bool caseSensitive(); 0092 0093 private: 0094 KrView *_view; 0095 QComboBox *_modeBox; 0096 KComboBox *_textBox; 0097 QToolButton *_openSelectDialogBtn; 0098 SearchMode _currentMode; 0099 bool _rightArrowEntersDirFlag; 0100 }; 0101 0102 #endif // KRSEARCHBAR_H