File indexing completed on 2025-04-27 03:58:40
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2007-11-25 0007 * Description : a bar used to search a string - version not based on database models 0008 * 0009 * SPDX-FileCopyrightText: 2007-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_SEARCH_TEXT_BAR_H 0016 #define DIGIKAM_SEARCH_TEXT_BAR_H 0017 0018 // Qt includes 0019 0020 #include <QAbstractItemModel> 0021 #include <QStringList> 0022 #include <QLineEdit> 0023 0024 // Local includes 0025 0026 #include "digikam_export.h" 0027 #include "modelcompleter.h" 0028 #include "statesavingobject.h" 0029 0030 namespace Digikam 0031 { 0032 0033 class DIGIKAM_EXPORT SearchTextSettings 0034 { 0035 0036 public: 0037 0038 SearchTextSettings() 0039 : caseSensitive(Qt::CaseInsensitive) 0040 { 0041 } 0042 0043 Qt::CaseSensitivity caseSensitive; 0044 0045 QString text; 0046 }; 0047 0048 bool DIGIKAM_EXPORT operator==(const SearchTextSettings& a, const SearchTextSettings& b); 0049 0050 /** 0051 * A text input for searching entries with visual feedback. 0052 * Can be used on QAbstractItemModels. 0053 */ 0054 class DIGIKAM_EXPORT SearchTextBar : public QLineEdit, 0055 public StateSavingObject 0056 { 0057 Q_OBJECT 0058 0059 public: 0060 0061 /** 0062 * Possible highlighting states a SearchTextBar can have. 0063 */ 0064 enum HighlightState 0065 { 0066 /** 0067 * No highlighting at all. Background is colored in a neutral way 0068 * according to the theme. 0069 */ 0070 NEUTRAL, 0071 0072 /** 0073 * The background color of the text input indicates that a result was 0074 * found. 0075 */ 0076 HAS_RESULT, 0077 0078 /** 0079 * The background color indicates that no result was found. 0080 */ 0081 NO_RESULT 0082 }; 0083 0084 public: 0085 0086 explicit SearchTextBar(QWidget* const parent, 0087 const QString& name, 0088 const QString& msg = QString()); 0089 ~SearchTextBar() override; 0090 0091 void setTextQueryCompletion(bool b); 0092 bool hasTextQueryCompletion() const; 0093 0094 /** 0095 * Tells whether highlighting for found search results shall be used or not 0096 * (green and red). 0097 * 0098 * Default behavior has highlighting enabled. 0099 * 0100 * @param highlight <code>true</code> activates green and red highlighting, 0101 * with <code>false</code> the normal widget background 0102 * color will be displayed always 0103 */ 0104 void setHighlightOnResult(bool highlight); 0105 0106 /** 0107 * Tells the current highlighting state of the text input indicated via the 0108 * background color. 0109 * 0110 * @return current highlight state 0111 */ 0112 HighlightState getCurrentHighlightState() const; 0113 0114 /** 0115 * Indicate whether this search text bar can be toggled to between case- 0116 * sensitive and -insensitive or if always case-insensitive shall be 0117 * used. 0118 * 0119 * @param b if <code>true</code> the user can decide the toggle between 0120 * case sensitivity, on <code>false</code> every search is case- 0121 * insensitive 0122 */ 0123 void setCaseSensitive(bool b); 0124 bool hasCaseSensitive() const; 0125 0126 void setSearchTextSettings(const SearchTextSettings& settings); 0127 SearchTextSettings searchTextSettings() const; 0128 ModelCompleter* completerModel() const; 0129 0130 Q_SIGNALS: 0131 0132 void signalSearchTextSettings(const SearchTextSettings& settings); 0133 void completerHighlighted(int albumId); 0134 void completerActivated(); 0135 0136 public Q_SLOTS: 0137 0138 void slotSearchResult(bool match); 0139 0140 private Q_SLOTS: 0141 0142 void slotTextChanged(); 0143 0144 protected: 0145 0146 void doLoadState() override; 0147 void doSaveState() override; 0148 0149 private: 0150 0151 void contextMenuEvent(QContextMenuEvent* e) override; 0152 0153 /** 0154 * If hasCaseSensitive returns <code>true</code> this tells the search 0155 * text bar whether to ignore case or not. 0156 * 0157 * @param ignore if <code>true</code>, case is ignored in the emitted 0158 * search text settings and the completion 0159 */ 0160 void setIgnoreCase(bool ignore); 0161 0162 private: 0163 0164 class Private; 0165 Private* const d; 0166 }; 0167 0168 } // namespace Digikam 0169 0170 #endif // DIGIKAM_SEARCH_TEXT_BAR_H