further code cleanup
[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     void historyShow();
64
65     //! Requests to refresh state of history buttons
66     void refreshHistoryButtons();
67
68 public Q_SLOTS:
69     //! Enables or disables search word line edit and history buttons
70     /*!
71       While searching it disables only history button and line edit.
72       Search/Stop button is always enabled.
73     */
74     void setEnabled(bool);
75
76
77     //! Sets search bar in busy state
78     /*!
79       Displays "busy" bar and disables search word text edit and history buttons
80       */
81     void setBusy();
82
83     //! Sets search bar in idle state
84     /*!
85       Hides "busy" bar and enables all widgets, refreshes state of history buttons
86       by emitting refreshHistoryButtons signal
87       */
88     void setIdle();
89
90     //! Searches for given word
91     /*!
92       Sets word as text in search word line edit
93       */
94     void search(QString word);
95
96     //! Starts to search for given word after 500 ms
97     /*!
98       Sets word as text in search word line edit, and waits 500 ms to start
99       search. If in meanwhile this slot is called again it will stop previous
100       timers.
101       */
102     void searchDelay(QString word);
103
104     //! Updates state of history buttons
105     void updateHistoryButtons(bool prev, bool next, bool list);
106
107 private Q_SLOTS:
108     void clearSearchWordToolButtonClicked();
109     void searchPushButtonClicked();
110     void delaySearchTimeout();
111
112
113 private:
114     QLineEdit* searchWordLineEdit;
115     QToolButton* clearSearchWordToolButton;
116     QPushButton* searchPushButton;
117     QToolButton* historyPrevToolButton;
118     QToolButton* historyNextToolButton;
119     QToolButton* historyShowToolButton;
120     QToolButton* fullScreenToolButton;
121     QHBoxLayout* horizontalLayout;
122     QProgressBar* searchingProgressBar;
123
124     QIcon generateIcon(QIcon oryginal, qreal rotation=0);
125
126     QVBoxLayout* verticalLayout;
127
128     bool _isSearching;
129
130     QTimer delayTimer;
131     QString delayString;
132
133     void initializeUI();
134 };
135
136 #endif // SEARCHBARWIDGET_H