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(setIdle()));
70 connect(backbone, SIGNAL(htmlReady()),
71 this, SLOT(setIdle()));
73 searchWordLineEdit->setFocus();
76 SearchBarWidget::~SearchBarWidget() {
81 void SearchBarWidget::initializeUI() {
82 horizontalLayout = new QHBoxLayout();
83 verticalLayout = new QVBoxLayout();
86 searchPushButton = new QPushButton(tr("Search"));
87 searchPushButton->setMinimumWidth(150);
90 searchWordLineEdit = new QLineEdit();
91 searchWordLineEdit->setMinimumWidth(300);
92 //create layout for lineEdit to have clear button on it
93 QHBoxLayout* lineEditLayout = new QHBoxLayout;
94 searchWordLineEdit->setLayout(lineEditLayout);
97 clearSearchWordToolButton = new QToolButton();
98 clearSearchWordToolButton->setIcon(QIcon::fromTheme("general_stop"));
99 //tool buttons will have size 2 times smaller
100 clearSearchWordToolButton->setMaximumSize(
101 clearSearchWordToolButton->sizeHint().width()/2,
102 clearSearchWordToolButton->sizeHint().height()/2);
105 historyNextToolButton = new QToolButton();
106 historyNextToolButton->setIcon(QIcon::fromTheme("general_forward"));
108 historyPrevToolButton = new QToolButton();
109 historyPrevToolButton->setIcon(QIcon::fromTheme("general_back"));
111 historyShowToolButton = new QToolButton();
112 historyShowToolButton->setIcon(QIcon::fromTheme("general_back"));
114 QPixmap p = historyShowToolButton->icon().pixmap(256);
120 temp.addPixmap(p.transformed(m));
121 historyShowToolButton->setIcon(temp);
124 searchingProgressBar = new QProgressBar();
125 //progress bar have minimum and maximum values set to 0, which will effect
126 //with "I'm alive" bar
127 searchingProgressBar->setMinimum(0);
128 searchingProgressBar->setMaximum(0);
129 searchingProgressBar->hide();
130 searchingProgressBar->setMaximumHeight(50);
133 setLayout(verticalLayout);
135 verticalLayout->addWidget(searchingProgressBar);
137 //adding widgets to layout
138 horizontalLayout->addWidget(searchWordLineEdit);
139 horizontalLayout->addWidget(searchPushButton);
140 horizontalLayout->addWidget(historyPrevToolButton);
141 horizontalLayout->addWidget(historyShowToolButton);
142 horizontalLayout->addWidget(historyNextToolButton);
144 //adding clear toolButton to textEdit with right alignment
145 lineEditLayout->addWidget(clearSearchWordToolButton, 0,
146 Qt::AlignRight | Qt::AlignVCenter);
148 verticalLayout->addLayout(horizontalLayout);
153 void SearchBarWidget::searchPushButtonClicked() {
156 emit stopSearching();
159 if(searchWordLineEdit->text().isEmpty()) return;
161 QStringList searchWord;
162 searchWord << searchWordLineEdit->text();
163 emit searchForTranslations(searchWord);
167 void SearchBarWidget::searchWordList(QStringList words) {
170 emit searchForTranslations(words);
174 void SearchBarWidget::setEnabled(bool enabled) {
175 searchWordLineEdit->setEnabled(enabled);
176 historyNextToolButton->setEnabled(enabled);
177 historyPrevToolButton->setEnabled(enabled);
178 historyShowToolButton->setEnabled(enabled);
181 void SearchBarWidget::setBusy() {
182 if(_isSearching) return;
183 searchingProgressBar->show();
184 searchPushButton->setText(tr("Stop"));
189 void SearchBarWidget::setIdle() {
190 if(!_isSearching) return;
191 searchingProgressBar->hide();
192 searchPushButton->setText(tr("Search"));
194 _isSearching = false;
197 void SearchBarWidget::historyNextToolButtonClicked() {
201 void SearchBarWidget::historyPrevToolButtonClicked() {
205 void SearchBarWidget::historyShowToolButtonClicked() {
209 void SearchBarWidget::clearSearchWordToolButtonClicked() {
210 searchWordLineEdit->clear();
213 void SearchBarWidget::showHistoryListDialog() {
217 bool SearchBarWidget::isSearching() const {