serachBar + progressBar
[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
60     //! Requests to search for a list of words matching a word passed as
61     //! a parameter
62     void searchForTranslations(QString);
63
64     //! Requests to stop all active searchings
65     void stopSearching();
66
67     //! Requests to show previous translation in history
68     void historyPrev();
69
70     //! Requests to show next translation in history
71     void historyNext();
72
73     //! Requests to show history list
74     /*!
75       \param p this argument is used only on desktop, it defines place on
76       which a popup with history will be shown
77     */
78     void historyShow(QPoint p = QPoint(-1,-1));
79
80     //! Requests to refresh state of history buttons
81     void refreshHistoryButtons();
82
83 public Q_SLOTS:
84
85     void searchButtonClicked(QString text);
86
87     //! Enables or disables search word line edit and history buttons
88     /*!
89       While searching it disables only history button and line edit.
90       Search/Stop button is always enabled.
91     */
92     void setEnabled(bool);
93
94
95     //! Sets search bar in busy state
96     /*!
97       Displays "busy" bar and disables search word text edit and history buttons
98     */
99     void setBusy();
100
101     //! Sets search bar in idle state
102     /*!
103       Hides "busy" bar and enables all widgets, refreshes state of history buttons
104       by emitting refreshHistoryButtons signal
105     */
106     void setIdle();
107
108     //! Searches for a given word
109     /*!
110       Sets word as text in search word line edit
111     */
112     void search(QString word);
113
114     //! Starts to search for a given word after 500 ms delay
115     /*!
116       Sets word as text in search word line edit, and waits 500 ms to start
117       search. If in the meantime this slot is called again it will stop previous
118       timers.
119     */
120     void searchDelay(QString word);
121
122     //! Updates state of history buttons
123     /*!
124       \param prev if set to true, the history has some previous words
125       \param next if set to true, the history has some next words
126       \param list if set to true, the history can show word list
127     */
128     void updateHistoryButtons(bool prev, bool next, bool list);
129
130     void setFocus();
131
132 private Q_SLOTS:
133     //! Clears search word line edit
134     void clearSearchWordToolButtonClicked();
135
136     //! Starts to search for given words
137     void searchPushButtonClicked();
138
139     //! starts to search word which was passed to searchDelay
140     void delaySearchTimeout();
141
142     //! shows history
143     void showHistoryButtonClicked();
144
145
146 private:
147
148     QVBoxLayout* mainLayout;
149     QDeclarativeView *view;
150
151     QLineEdit* searchWordLineEdit;
152     QCompleter* lineEditCompleter;
153     QStringListModel* completerModel;
154     QToolButton* clearSearchWordToolButton;
155     QPushButton* searchPushButton;
156     QToolButton* historyPrevToolButton;
157     QToolButton* historyNextToolButton;
158     QToolButton* historyShowToolButton;
159     QToolButton* fullScreenToolButton;
160     QHBoxLayout* horizontalLayout;
161     QProgressBar* searchingProgressBar;
162
163
164     //! generates icon for maemo (some of icons we use don't have inactive
165     //! pixmaps, so we generate them)
166     /*!
167       \param original original icon
168       \param rotation rotation of resulting icon
169     */
170     QIcon generateIcon(QIcon original, qreal rotation=0);
171
172     QVBoxLayout* verticalLayout;
173
174     bool busy;
175
176     QTimer delayTimer;
177     QString delayString;
178
179     void initializeUI();
180 };
181
182 #endif // SEARCHBARWIDGET_H