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