d19ce214c662b30a9b93b64e0ef0a69a75110119
[mdictionary] / src / mdictionary / gui / SearchBarWidget.h
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
5     mDictionary 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     mDictionary 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 mDictionary.  If not, see <http://www.gnu.org/licenses/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21 /*! \file SearchBarWidget.h
22     \brief Displays search bar
23
24     \author Mateusz Półrola <mateusz.polrola@comarch.pl>
25 */
26
27
28 #ifndef SEARCHBARWIDGET_H
29 #define SEARCHBARWIDGET_H
30
31 #include <QWidget>
32 #include <QtGui>
33 #include <QDeclarativeView>
34
35 #include "../backbone/backbone.h"
36 #include "../../include/History.h"
37
38 /*!
39     Contains line edit field to input word which user would like to find
40     and buttons to start/stop search and browse search history.
41     Line edit and history buttons are disabled when search is ongoing,
42     only start/stop button stays active. When searching it also displays
43     progress bar.
44 */
45 class SearchBarWidget : public QWidget {
46     Q_OBJECT
47 public:
48     explicit SearchBarWidget(QWidget *parent = 0);
49     ~SearchBarWidget();
50
51 Q_SIGNALS:
52
53     void setEnableHistoryNext(QVariant enable);
54     void setEnableHistoryShow(QVariant enable);
55     void setEnableHistoryPrev(QVariant enable);
56     void setButtonText(QVariant text);
57     void setLineEditText(QVariant text);
58     void setLineEditEnables(QVariant enabled);
59     void progresSetMax(QVariant);
60     void progresSetMin(QVariant);
61     void progresSetValue(QVariant);
62     void progresSetValue2(QVariant);
63     void setCompleterText(QVariant);
64     void focusOff();
65
66     //! Requests to search for a list of words matching a word passed as
67     //! a parameter
68     void searchForTranslations(QString);
69
70     //! Requests to stop all active searchings
71     void stopSearching();
72
73     //! Requests to show previous translation in history
74     void historyPrev();
75
76     //! Requests to show next translation in history
77     void historyNext();
78
79     //! Requests to show history list
80     /*!
81       \param p this argument is used only on desktop, it defines place on
82       which a popup with history will be shown
83     */
84     void historyShow(QPoint p = QPoint(-1,-1));
85
86     //! Requests to refresh state of history buttons
87     void refreshHistoryButtons();
88
89 public Q_SLOTS:
90
91     void updateBusyTimer();
92
93     void searchButtonClicked(QString text);
94
95     //! Enables or disables search word line edit and history buttons
96     /*!
97       While searching it disables only history button and line edit.
98       Search/Stop button is always enabled.
99     */
100     void setEnabled(bool);
101
102
103     //! Sets search bar in busy state
104     /*!
105       Displays "busy" bar and disables search word text edit and history buttons
106     */
107     void setBusy();
108
109     //! Sets search bar in idle state
110     /*!
111       Hides "busy" bar and enables all widgets, refreshes state of history buttons
112       by emitting refreshHistoryButtons signal
113     */
114     void setIdle();
115
116     //! Searches for a given word
117     /*!
118       Sets word as text in search word line edit
119     */
120     void search(QString word);
121
122     //! Starts to search for a given word after 500 ms delay
123     /*!
124       Sets word as text in search word line edit, and waits 500 ms to start
125       search. If in the meantime this slot is called again it will stop previous
126       timers.
127     */
128     void searchDelay(QString word);
129
130     //! Updates state of history buttons
131     /*!
132       \param prev if set to true, the history has some previous words
133       \param next if set to true, the history has some next words
134       \param list if set to true, the history can show word list
135     */
136     void updateHistoryButtons(bool prev, bool next, bool list);
137
138     void setFocus();
139     void nextFocus();
140     void checkFocus();
141
142 private Q_SLOTS:
143     //! Clears search word line edit
144     void clearSearchWordToolButtonClicked();
145
146     //! Starts to search for given words
147     void searchPushButtonClicked();
148
149     //! starts to search word which was passed to searchDelay
150     void delaySearchTimeout();
151
152     //! shows history
153     void showHistoryButtonClicked();
154
155     void textChange(QString text);
156
157     void nextCompleter();
158
159     void prevCompleter();
160
161
162 private:
163
164     QVBoxLayout* mainLayout;
165     QDeclarativeView *view;
166     QDeclarativeView *progressBar;
167     QTimer *busyTimer;
168     bool progressMax;
169     QDeclarativeContext *ctxt;
170     QStringList* completerModel;
171     QCompleter* lineEditCompleter;
172     QString preferedCompliter;
173     QString actualString;
174     QStringList completerActualList;
175
176     QLineEdit* searchWordLineEdit;
177     QToolButton* clearSearchWordToolButton;
178     QPushButton* searchPushButton;
179     QToolButton* historyPrevToolButton;
180     QToolButton* historyNextToolButton;
181     QToolButton* historyShowToolButton;
182     QToolButton* fullScreenToolButton;
183     QHBoxLayout* horizontalLayout;
184     QProgressBar* searchingProgressBar;
185
186
187     //! generates icon for maemo (some of icons we use don't have inactive
188     //! pixmaps, so we generate them)
189     /*!
190       \param original original icon
191       \param rotation rotation of resulting icon
192     */
193     QIcon generateIcon(QIcon original, qreal rotation=0);
194
195     QVBoxLayout* verticalLayout;
196
197     bool busy;
198
199     QTimer delayTimer;
200     QString delayString;
201
202     void initializeUI();
203 };
204
205 #endif // SEARCHBARWIDGET_H