Clean and order documentation in source files. Source ready to beta 2 release
[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 "../backbone/backbone.h"
34 #include "../../include/History.h"
35
36 /*!
37     Contains line edit field to input word which user would like to find
38     and buttons to start/stop search and browse search history.
39     Line edit and history buttons are disabled when search is ongoing,
40     only start/stop button stays active. When searching it also displays
41     progress bar.
42 */
43 class SearchBarWidget : public QWidget {
44     Q_OBJECT
45 public:
46     explicit SearchBarWidget(QWidget *parent = 0);
47     ~SearchBarWidget();
48
49 Q_SIGNALS:
50     //! Requests to search for a list of words matching a word passed as
51     //! a parameter
52     void searchForTranslations(QString);
53
54     //! Requests to stop all active searchings
55     void stopSearching();
56
57     //! Requests to show previous translation in history
58     void historyPrev();
59
60     //! Requests to show next translation in history
61     void historyNext();
62
63     //! Requests to show history list
64     /*!
65       \param p this argument is used only on desktop, it defines place on
66       which a popup with history will be shown
67     */
68     void historyShow(QPoint p = QPoint(-1,-1));
69
70     //! Requests to refresh state of history buttons
71     void refreshHistoryButtons();
72
73 public Q_SLOTS:
74     //! Enables or disables search word line edit and history buttons
75     /*!
76       While searching it disables only history button and line edit.
77       Search/Stop button is always enabled.
78     */
79     void setEnabled(bool);
80
81
82     //! Sets search bar in busy state
83     /*!
84       Displays "busy" bar and disables search word text edit and history buttons
85     */
86     void setBusy();
87
88     //! Sets search bar in idle state
89     /*!
90       Hides "busy" bar and enables all widgets, refreshes state of history buttons
91       by emitting refreshHistoryButtons signal
92     */
93     void setIdle();
94
95     //! Searches for a given word
96     /*!
97       Sets word as text in search word line edit
98     */
99     void search(QString word);
100
101     //! Starts to search for a given word after 500 ms delay
102     /*!
103       Sets word as text in search word line edit, and waits 500 ms to start
104       search. If in the meantime this slot is called again it will stop previous
105       timers.
106     */
107     void searchDelay(QString word);
108
109     //! Updates state of history buttons
110     /*!
111       \param prev if set to true, the history has some previous words
112       \param next if set to true, the history has some next words
113       \param list if set to true, the history can show word list
114     */
115     void updateHistoryButtons(bool prev, bool next, bool list);
116
117     void setFocus();
118
119 private Q_SLOTS:
120     //! Clears search word line edit
121     void clearSearchWordToolButtonClicked();
122
123     //! Starts to search for given words
124     void searchPushButtonClicked();
125
126     //! starts to search word which was passed to searchDelay
127     void delaySearchTimeout();
128
129     //! shows history
130     void showHistoryButtonClicked();
131
132
133 private:
134     QLineEdit* searchWordLineEdit;
135     QCompleter* lineEditCompleter;
136     QStringListModel* completerModel;
137     QToolButton* clearSearchWordToolButton;
138     QPushButton* searchPushButton;
139     QToolButton* historyPrevToolButton;
140     QToolButton* historyNextToolButton;
141     QToolButton* historyShowToolButton;
142     QToolButton* fullScreenToolButton;
143     QHBoxLayout* horizontalLayout;
144     QProgressBar* searchingProgressBar;
145
146
147     //! generates icon for maemo (some of icons we use don't have inactive
148     //! pixmaps, so we generate them)
149     /*!
150       \param original original icon
151       \param rotation rotation of resulting icon
152     */
153     QIcon generateIcon(QIcon original, qreal rotation=0);
154
155     QVBoxLayout* verticalLayout;
156
157     bool busy;
158
159     QTimer delayTimer;
160     QString delayString;
161
162     void initializeUI();
163 };
164
165 #endif // SEARCHBARWIDGET_H