1 /*******************************************************************************
3 This file is part of mDictionary.
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.
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.
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/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
22 //Created by Mateusz Półrola
25 #include "SearchBarWidget.h"
27 #include "../../includes/DictDialog.h"
28 #include "HistoryListDialog.h"
31 SearchBarWidget::SearchBarWidget(QWidget *parent) :
39 connect(searchPushButton, SIGNAL(clicked()),
40 this, SLOT(searchPushButtonClicked()));
42 connect(searchWordLineEdit, SIGNAL(returnPressed()),
43 this, SLOT(searchPushButtonClicked()));
45 connect(historyNextToolButton, SIGNAL(clicked()),
46 this, SIGNAL(historyNext()));
48 connect(historyPrevToolButton, SIGNAL(clicked()),
49 this, SIGNAL(historyPrev()));
51 connect(historyShowToolButton, SIGNAL(clicked()),
52 this, SIGNAL(historyShow()));
54 connect(clearSearchWordToolButton, SIGNAL(clicked()),
55 this, SLOT(clearSearchWordToolButtonClicked()));
58 connect(&delayTimer, SIGNAL(timeout()),
59 this, SLOT(delaySearchTimeout()));
62 searchWordLineEdit->setFocus();
64 historyPrevToolButton->setEnabled(false);
65 historyNextToolButton->setEnabled(false);
66 historyShowToolButton->setEnabled(false);
70 SearchBarWidget::~SearchBarWidget() {
74 QIcon SearchBarWidget::generateIcon(QIcon oryginal, qreal rotation) {
75 QPixmap p = oryginal.pixmap(64);
90 painter.fillRect(p.rect(), QColor(0,0,0,192));
92 newIcon.addPixmap(p, QIcon::Disabled, QIcon::Off);
99 void SearchBarWidget::initializeUI() {
102 setMaximumHeight(150);
104 setMaximumHeight(70);
108 horizontalLayout = new QHBoxLayout(this);
109 verticalLayout = new QVBoxLayout(this);
112 searchPushButton = new QPushButton(tr("Search"),this);
113 searchPushButton->setMinimumWidth(125);
116 searchWordLineEdit = new QLineEdit(this);
117 searchWordLineEdit->setMinimumWidth(250);
120 searchWordLineEdit->setMinimumHeight(
121 searchWordLineEdit->sizeHint().height()*3/2);
125 //create layout for lineEdit to have clear button on it
126 QHBoxLayout* lineEditLayout = new QHBoxLayout(this);
127 searchWordLineEdit->setLayout(lineEditLayout);
130 clearSearchWordToolButton = new QToolButton(this);
132 clearSearchWordToolButton->setIcon(QIcon::fromTheme("general_stop"));
133 //tool buttons will have size 2 times smaller
134 clearSearchWordToolButton->setMaximumSize(
135 clearSearchWordToolButton->sizeHint().height()/2,
136 clearSearchWordToolButton->sizeHint().height()/2);
138 clearSearchWordToolButton->setIcon(QIcon::fromTheme("edit-clear"));
139 clearSearchWordToolButton->setMinimumSize(
140 clearSearchWordToolButton->sizeHint().height(),
141 clearSearchWordToolButton->sizeHint().height());
145 historyNextToolButton = new QToolButton(this);
147 historyNextToolButton->setIcon(
148 generateIcon(QIcon::fromTheme("general_forward")));
150 historyNextToolButton->setIcon(
151 generateIcon(QIcon::fromTheme("go-next")));
156 historyPrevToolButton = new QToolButton(this);
158 historyPrevToolButton->setIcon(
159 generateIcon(QIcon::fromTheme("general_back")));
161 historyPrevToolButton->setIcon(
162 generateIcon(QIcon::fromTheme("go-previous")));
167 historyShowToolButton = new QToolButton(this);
169 historyShowToolButton->setIcon(
170 generateIcon(QIcon::fromTheme("general_back"), 90));
172 historyShowToolButton->setIcon(
173 generateIcon(QIcon::fromTheme("go-up")));
176 /*fullScreenToolButton = new QToolButton();
178 fullScreenToolButton->setIcon(
179 generateIcon(QIcon::fromTheme("general_fullsize")));
181 fullScreenToolButton->setIcon(
182 generateIcon(QIcon::fromTheme("view-fullscreen")));
183 fullScreenToolButton->setMinimumSize(
184 fullScreenToolButton->sizeHint().height()*2,
185 fullScreenToolButton->sizeHint().height()*2);
189 searchingProgressBar = new QProgressBar(this);
190 //progress bar have minimum and maximum values set to 0, which will effect
191 //with "I'm alive" bar
192 searchingProgressBar->setMinimum(0);
193 searchingProgressBar->setMaximum(0);
194 searchingProgressBar->hide();
196 searchingProgressBar->setMaximumHeight(50);
200 setLayout(verticalLayout);
202 verticalLayout->addWidget(searchingProgressBar);
204 //adding widgets to layout
205 horizontalLayout->addWidget(searchWordLineEdit);
206 horizontalLayout->addWidget(searchPushButton);
207 horizontalLayout->addWidget(historyPrevToolButton);
208 horizontalLayout->addWidget(historyShowToolButton);
209 horizontalLayout->addWidget(historyNextToolButton);
210 // horizontalLayout->addWidget(fullScreenToolButton);
212 //adding clear toolButton to textEdit with right alignment
213 lineEditLayout->addWidget(clearSearchWordToolButton, 0,
214 Qt::AlignRight | Qt::AlignVCenter);
216 verticalLayout->addLayout(horizontalLayout);
220 void SearchBarWidget::searchPushButtonClicked() {
222 emit stopSearching();
225 search(searchWordLineEdit->text());
230 void SearchBarWidget::search(QString word) {
231 if(!_isSearching && !word.isEmpty()) {
232 searchWordLineEdit->setText(word);
233 emit searchForTranslations(word);
237 void SearchBarWidget::searchDelay(QString word) {
238 if(!_isSearching && !word.isEmpty()) {
239 searchWordLineEdit->setText(word);
242 if(delayTimer.isActive()) {
247 delayTimer.start(500);
251 void SearchBarWidget::delaySearchTimeout() {
254 emit searchForTranslations(delayString);
258 void SearchBarWidget::setEnabled(bool enabled) {
259 searchWordLineEdit->setEnabled(enabled);
262 historyPrevToolButton->setEnabled(false);
263 historyNextToolButton->setEnabled(false);
264 historyShowToolButton->setEnabled(false);
268 void SearchBarWidget::setBusy() {
269 if(_isSearching) return;
270 searchingProgressBar->show();
271 searchPushButton->setText(tr("Stop"));
276 void SearchBarWidget::setIdle() {
277 if(!_isSearching) return;
278 searchingProgressBar->hide();
279 searchPushButton->setText(tr("Search"));
281 _isSearching = false;
282 emit refreshHistoryButtons();
286 void SearchBarWidget::clearSearchWordToolButtonClicked() {
287 searchWordLineEdit->clear();
292 void SearchBarWidget::updateHistoryButtons(bool prev, bool next, bool list) {
294 historyPrevToolButton->setEnabled(prev);
295 historyNextToolButton->setEnabled(next);
296 historyShowToolButton->setEnabled(list);