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"
30 SearchBarWidget::SearchBarWidget(Backbone* backbone, QWidget *parent) :
33 this->backbone = backbone;
37 setMaximumHeight(150);
41 connect(searchPushButton, SIGNAL(clicked()),
42 this, SLOT(searchPushButtonClicked()));
44 connect(searchWordLineEdit, SIGNAL(returnPressed()),
45 this, SLOT(searchPushButtonClicked()));
47 connect(historyNextToolButton, SIGNAL(clicked()),
48 this, SLOT(historyNextToolButtonClicked()));
50 connect(historyPrevToolButton, SIGNAL(clicked()),
51 this, SLOT(historyPrevToolButtonClicked()));
53 connect(historyShowToolButton, SIGNAL(clicked()),
54 this, SLOT(historyShowToolButtonClicked()));
56 connect(clearSearchWordToolButton, SIGNAL(clicked()),
57 this, SLOT(clearSearchWordToolButtonClicked()));
60 //connects request to backbone
61 connect(this, SIGNAL(searchForTranslations(QString)),
62 backbone, SLOT(search(QString)));
64 connect(this, SIGNAL(stopSearching()),
65 backbone, SLOT(stopSearching()));
67 connect(backbone, SIGNAL(ready()),
68 this, SLOT(setIdle()));
70 connect(backbone, SIGNAL(htmlReady()),
71 this, SLOT(setIdle()));
73 searchWordLineEdit->setFocus();
76 SearchBarWidget::~SearchBarWidget() {
80 QIcon SearchBarWidget::generateIcon(QIcon oryginal, qreal rotation) {
81 QPixmap p = oryginal.pixmap(64);
94 painter.fillRect(p.rect(), QColor(0,0,0,192));
96 newIcon.addPixmap(p, QIcon::Disabled, QIcon::Off);
102 void SearchBarWidget::initializeUI() {
103 horizontalLayout = new QHBoxLayout();
104 verticalLayout = new QVBoxLayout();
107 searchPushButton = new QPushButton(tr("Search"));
108 searchPushButton->setMinimumWidth(150);
111 searchWordLineEdit = new QLineEdit();
112 searchWordLineEdit->setMinimumWidth(300);
113 //create layout for lineEdit to have clear button on it
114 QHBoxLayout* lineEditLayout = new QHBoxLayout;
115 searchWordLineEdit->setLayout(lineEditLayout);
118 clearSearchWordToolButton = new QToolButton();
119 clearSearchWordToolButton->setIcon(QIcon::fromTheme("general_stop"));
120 //tool buttons will have size 2 times smaller
121 clearSearchWordToolButton->setMaximumSize(
122 clearSearchWordToolButton->sizeHint().width()/2,
123 clearSearchWordToolButton->sizeHint().height()/2);
126 historyNextToolButton = new QToolButton();
127 historyNextToolButton->setIcon(
128 generateIcon(QIcon::fromTheme("general_forward")));
130 historyPrevToolButton = new QToolButton();
131 historyPrevToolButton->setIcon(
132 generateIcon(QIcon::fromTheme("general_back")));
134 historyShowToolButton = new QToolButton();
135 historyShowToolButton->setIcon(
136 generateIcon(QIcon::fromTheme("general_back"), 90));
140 searchingProgressBar = new QProgressBar();
141 //progress bar have minimum and maximum values set to 0, which will effect
142 //with "I'm alive" bar
143 searchingProgressBar->setMinimum(0);
144 searchingProgressBar->setMaximum(0);
145 searchingProgressBar->hide();
146 searchingProgressBar->setMaximumHeight(50);
149 setLayout(verticalLayout);
151 verticalLayout->addWidget(searchingProgressBar);
153 //adding widgets to layout
154 horizontalLayout->addWidget(searchWordLineEdit);
155 horizontalLayout->addWidget(searchPushButton);
156 horizontalLayout->addWidget(historyPrevToolButton);
157 horizontalLayout->addWidget(historyShowToolButton);
158 horizontalLayout->addWidget(historyNextToolButton);
160 //adding clear toolButton to textEdit with right alignment
161 lineEditLayout->addWidget(clearSearchWordToolButton, 0,
162 Qt::AlignRight | Qt::AlignVCenter);
164 verticalLayout->addLayout(horizontalLayout);
169 void SearchBarWidget::searchPushButtonClicked() {
172 emit stopSearching();
175 search(searchWordLineEdit->text());
180 void SearchBarWidget::search(QString word) {
181 if(!_isSearching && !word.isEmpty()) {
182 searchWordLineEdit->setText(word);
184 emit searchForTranslations(word);
188 void SearchBarWidget::setEnabled(bool enabled) {
189 searchWordLineEdit->setEnabled(enabled);
190 historyNextToolButton->setEnabled(enabled);
191 historyPrevToolButton->setEnabled(enabled);
192 historyShowToolButton->setEnabled(enabled);
195 void SearchBarWidget::setBusy() {
196 if(_isSearching) return;
197 searchingProgressBar->show();
198 searchPushButton->setText(tr("Stop"));
204 void SearchBarWidget::setIdle() {
205 if(!_isSearching) return;
206 searchingProgressBar->hide();
207 searchPushButton->setText(tr("Search"));
209 _isSearching = false;
213 void SearchBarWidget::historyNextToolButtonClicked() {
217 void SearchBarWidget::historyPrevToolButtonClicked() {
221 void SearchBarWidget::historyShowToolButtonClicked() {
225 void SearchBarWidget::clearSearchWordToolButtonClicked() {
226 searchWordLineEdit->clear();
229 void SearchBarWidget::showHistoryListDialog() {
233 bool SearchBarWidget::isSearching() const {