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