af7c1b388681073bfe7c3f3c59e90ade6e3c02cc
[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 a list of words matching a word passed as
49     //! a 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 a 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 a 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 a 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     void setFocus();
116
117 private Q_SLOTS:
118     //! Clears search word line edit
119     void clearSearchWordToolButtonClicked();
120
121     //! Starts to search for given words
122     void searchPushButtonClicked();
123
124     //! starts to search word which was passed to searchDelay
125     void delaySearchTimeout();
126
127     //! shows history
128     void showHistoryButtonClicked();
129
130
131 private:
132     QLineEdit* searchWordLineEdit;
133     QCompleter* lineEditCompleter;
134     QStringListModel* completerModel;
135     QToolButton* clearSearchWordToolButton;
136     QPushButton* searchPushButton;
137     QToolButton* historyPrevToolButton;
138     QToolButton* historyNextToolButton;
139     QToolButton* historyShowToolButton;
140     QToolButton* fullScreenToolButton;
141     QHBoxLayout* horizontalLayout;
142     QProgressBar* searchingProgressBar;
143
144
145     //! generates icon for maemo (some of icons we use don't have inactive
146     //! pixmaps, so we generate them)
147     /*!
148       \param original original icon
149       \param rotation rotation of resulting icon
150     */
151     QIcon generateIcon(QIcon original, qreal rotation=0);
152
153     QVBoxLayout* verticalLayout;
154
155     bool busy;
156
157     QTimer delayTimer;
158     QString delayString;
159
160     void initializeUI();
161 };
162
163 #endif // SEARCHBARWIDGET_H