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(QStringList)),
62 backbone, SLOT(search(QStringList)));
64 connect(this, SIGNAL(stopSearching()),
65 backbone, SLOT(stopSearching()));
67 connect(backbone, SIGNAL(ready()),
68 this, SLOT(searchFinished()));
70 searchWordLineEdit->setFocus();
73 SearchBarWidget::~SearchBarWidget() {
78 void SearchBarWidget::initializeUI() {
79 horizontalLayout = new QHBoxLayout();
80 verticalLayout = new QVBoxLayout();
84 searchPushButton = new QPushButton(tr("Search"));
85 searchPushButton->setMinimumWidth(150);
88 searchWordLineEdit = new QLineEdit();
89 searchWordLineEdit->setMinimumWidth(300);
90 //create layout for lineEdit to have clear button on it
91 QHBoxLayout* lineEditLayout = new QHBoxLayout;
92 searchWordLineEdit->setLayout(lineEditLayout);
95 clearSearchWordToolButton = new QToolButton();
96 clearSearchWordToolButton->setIcon(QIcon::fromTheme("general_stop"));
97 //tool buttons will have size 2 times smaller
98 clearSearchWordToolButton->setMaximumSize(
99 clearSearchWordToolButton->sizeHint().width()/2,
100 clearSearchWordToolButton->sizeHint().height()/2);
103 historyNextToolButton = new QToolButton();
104 historyNextToolButton->setIcon(QIcon::fromTheme("general_forward"));
105 /* historyNextToolButton->setMaximumSize(
106 historyNextToolButton->sizeHint().width()/2,
107 historyNextToolButton->sizeHint().height()/2);*/
110 historyPrevToolButton = new QToolButton();
111 historyPrevToolButton->setIcon(QIcon::fromTheme("general_back"));
112 /*historyPrevToolButton->setMaximumSize(
113 historyPrevToolButton->sizeHint().width()/2,
114 historyPrevToolButton->sizeHint().height()/2);*/
117 historyShowToolButton = new QToolButton();
118 historyShowToolButton->setIcon(QIcon::fromTheme("general_back"));
119 /*historyShowToolButton->setMaximumSize(
120 historyShowToolButton->sizeHint().width()/2,
121 historyShowToolButton->sizeHint().height()/2);*/
123 QPixmap p = historyShowToolButton->icon().pixmap(256);
129 temp.addPixmap(p.transformed(m));
130 historyShowToolButton->setIcon(temp);
133 searchingProgressBar = new QProgressBar();
134 //progress bar have minimum and maximum values set to 0, which will effect
135 //with "I'm alive" bar
136 searchingProgressBar->setMinimum(0);
137 searchingProgressBar->setMaximum(0);
138 searchingProgressBar->hide();
139 searchingProgressBar->setMaximumHeight(50);
143 setLayout(verticalLayout);
145 verticalLayout->addWidget(searchingProgressBar);
147 //adding widgets to layout
148 horizontalLayout->addWidget(searchWordLineEdit);
149 horizontalLayout->addWidget(searchPushButton);
150 horizontalLayout->addWidget(historyPrevToolButton);
151 horizontalLayout->addWidget(historyShowToolButton);
152 horizontalLayout->addWidget(historyNextToolButton);
154 //adding clear toolButton to textEdit with right alignment
155 lineEditLayout->addWidget(clearSearchWordToolButton, 0,
156 Qt::AlignRight | Qt::AlignVCenter);
158 verticalLayout->addLayout(horizontalLayout);
164 void SearchBarWidget::searchPushButtonClicked() {
166 searchingProgressBar->hide();
167 searchPushButton->setText(tr("Search"));
169 emit enableMenu(true);
170 _isSearching = false;
171 emit stopSearching();
174 searchingProgressBar->show();
175 searchPushButton->setText(tr("Stop"));
177 emit enableMenu(false);
179 QStringList searchWord;
180 searchWord << searchWordLineEdit->text();
181 emit searchForTranslations(searchWord);
185 void SearchBarWidget::searchWordList(QStringList words) {
187 searchingProgressBar->show();
188 searchPushButton->setText(tr("Stop"));
190 emit enableMenu(false);
192 emit searchForTranslations(words);
196 void SearchBarWidget::setEnabled(bool enabled) {
197 searchWordLineEdit->setEnabled(enabled);
198 historyNextToolButton->setEnabled(enabled);
199 historyPrevToolButton->setEnabled(enabled);
200 historyShowToolButton->setEnabled(enabled);
203 void SearchBarWidget::showBusy() {
204 searchingProgressBar->show();
208 void SearchBarWidget::showIdle() {
209 searchingProgressBar->hide();
213 void SearchBarWidget::searchFinished() {
214 searchingProgressBar->hide();
215 searchPushButton->setText(tr("Search"));
217 emit enableMenu(true);
218 _isSearching = false;
221 void SearchBarWidget::historyNextToolButtonClicked() {
225 void SearchBarWidget::historyPrevToolButtonClicked() {
229 void SearchBarWidget::historyShowToolButtonClicked() {
233 void SearchBarWidget::clearSearchWordToolButtonClicked() {
234 searchWordLineEdit->clear();
237 void SearchBarWidget::showHistoryListDialog() {
241 bool SearchBarWidget::isSearching() const {