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