1 /* ============================================================
2 * Falkon - Qt web browser
3 * Copyright (C) 2010-2014  David Rosca <nowrep@gmail.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 * ============================================================ */
18 #ifndef WEBSEARCHBAR_H
19 #define WEBSEARCHBAR_H
20 
21 #include <QPointer>
22 
23 #include "qzcommon.h"
24 #include "lineedit.h"
25 #include "buttonwithmenu.h"
26 #include "searchenginesmanager.h"
27 #include "clickablelabel.h"
28 
29 class QStringListModel;
30 
31 class BrowserWindow;
32 class LineEdit;
33 class ClickableLabel;
34 class SearchEnginesManager;
35 class SearchEnginesDialog;
36 class OpenSearchEngine;
37 
38 class FALKON_EXPORT WebSearchBar_Button : public ClickableLabel
39 {
40 public:
41     explicit WebSearchBar_Button(QWidget* parent = 0);
42 
43 private:
44     void contextMenuEvent(QContextMenuEvent* event) override;
45 };
46 
47 class FALKON_EXPORT WebSearchBar : public LineEdit
48 {
49     Q_OBJECT
50 
51 public:
52     explicit WebSearchBar(BrowserWindow* window);
53 
54 private Q_SLOTS:
55     void searchChanged(const ButtonWithMenu::Item &item);
56     void setupEngines();
57 
58     void search();
59     void searchInNewTab();
60 
61     void aboutToShowMenu();
62     void openSearchEnginesDialog();
63 
64     void enableSearchSuggestions(bool enable);
65     void addSuggestions(const QStringList &list);
66 
67     void addEngineFromAction();
68     void pasteAndGo();
69     void instantSearchChanged(bool);
70 
71 private:
72     void focusOutEvent(QFocusEvent* e) override;
73     void dropEvent(QDropEvent* event) override;
74     void keyPressEvent(QKeyEvent* event) override;
75 
76     void contextMenuEvent(QContextMenuEvent* event) override;
77 
78     QCompleter* m_completer;
79     QStringListModel* m_completerModel;
80 
81     OpenSearchEngine* m_openSearchEngine;
82     SearchEngine m_activeEngine;
83 
84     BrowserWindow* m_window;
85 
86     WebSearchBar_Button* m_buttonSearch;
87     ButtonWithMenu* m_boxSearchType;
88     SearchEnginesManager* m_searchManager;
89     QPointer<SearchEnginesDialog> m_searchDialog;
90 
91     bool m_reloadingEngines;
92 };
93 
94 #endif // WEBSEARCHBAR_H
95