1 /* 2 Copyright © 2015-2019 by The qTox Project Contributors 3 4 This file is part of qTox, a Qt-based graphical interface for Tox. 5 6 qTox is libre software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 qTox is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with qTox. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef SEARCHFORM_H 21 #define SEARCHFORM_H 22 23 #include <QWidget> 24 #include <QLineEdit> 25 #include "searchtypes.h" 26 27 class QPushButton; 28 class QLabel; 29 class LineEdit; 30 class SearchSettingsForm; 31 32 class SearchForm final : public QWidget 33 { 34 Q_OBJECT 35 public: 36 enum class ToolButtonState { 37 Disabled = 0, // Grey 38 Common = 1, // Green 39 Active = 2, // Red 40 }; 41 42 explicit SearchForm(QWidget* parent = nullptr); 43 void removeSearchPhrase(); 44 QString getSearchPhrase() const; 45 ParameterSearch getParameterSearch(); 46 void setFocusEditor(); 47 void insertEditor(const QString &text); 48 void reloadTheme(); 49 50 protected: 51 virtual void showEvent(QShowEvent* event) final override; 52 53 private: 54 // TODO: Merge with 'createButton' from chatformheader.cpp 55 QPushButton* createButton(const QString& name, const QString& state); 56 ParameterSearch getAndCheckParametrSearch(); 57 void setStateName(QPushButton* btn, ToolButtonState state); 58 void useBeginState(); 59 60 QPushButton* settingsButton; 61 QPushButton* upButton; 62 QPushButton* downButton; 63 QPushButton* hideButton; 64 QPushButton* startButton; 65 LineEdit* searchLine; 66 SearchSettingsForm* settings; 67 QLabel* messageLabel; 68 69 QString searchPhrase; 70 ParameterSearch parameter; 71 72 bool isActiveSettings{false}; 73 bool isChangedPhrase{false}; 74 bool isSearchInBegin{true}; 75 bool isPrevSearch{false}; 76 77 private slots: 78 void changedSearchPhrase(const QString& text); 79 void clickedUp(); 80 void clickedDown(); 81 void clickedHide(); 82 void clickedStart(); 83 void clickedSearch(); 84 void changedState(bool isUpdate); 85 86 public slots: 87 void showMessageNotFound(SearchDirection direction); 88 89 signals: 90 void searchInBegin(const QString& phrase, const ParameterSearch& parameter); 91 void searchUp(const QString& phrase, const ParameterSearch& parameter); 92 void searchDown(const QString& phrase, const ParameterSearch& parameter); 93 void visibleChanged(); 94 }; 95 96 class LineEdit : public QLineEdit 97 { 98 Q_OBJECT 99 100 public: 101 LineEdit(QWidget* parent = nullptr); 102 103 protected: 104 virtual void keyPressEvent(QKeyEvent* event) final override; 105 106 signals: 107 void clickEnter(); 108 void clickShiftEnter(); 109 void clickEsc(); 110 }; 111 112 #endif // SEARCHFORM_H 113