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(historyNextToolButton, SIGNAL(clicked()),
45 this, SLOT(historyNextToolButtonClicked()));
47 connect(historyPrevToolButton, SIGNAL(clicked()),
48 this, SLOT(historyPrevToolButtonClicked()));
50 connect(historyShowToolButton, SIGNAL(clicked()),
51 this, SLOT(historyShowToolButtonClicked()));
53 connect(clearSearchWordToolButton, SIGNAL(clicked()),
54 this, SLOT(clearSearchWordToolButtonClicked()));
57 //connects request to backbone
58 connect(this, SIGNAL(searchForTranslations(QStringList)),
59 backbone, SLOT(search(QStringList)));
61 connect(this, SIGNAL(stopSearching()),
62 backbone, SLOT(stopSearching()));
64 connect(backbone, SIGNAL(ready()),
65 this, SLOT(searchFinished()));
69 SearchBarWidget::~SearchBarWidget() {
74 void SearchBarWidget::initializeUI() {
75 horizontalLayout = new QHBoxLayout();
76 verticalLayout = new QVBoxLayout();
79 searchPushButton = new QPushButton(tr("Search"));
80 searchPushButton->setMinimumWidth(200);
83 searchWordLineEdit = new QLineEdit();
84 searchWordLineEdit->setMinimumWidth(350);
85 //create layout for lineEdit to have clear button on it
86 QHBoxLayout* lineEditLayout = new QHBoxLayout;
87 searchWordLineEdit->setLayout(lineEditLayout);
90 clearSearchWordToolButton = new QToolButton();
91 clearSearchWordToolButton->setIcon(QIcon::fromTheme("general_stop"));
92 //tool buttons will have size 2 times smaller
93 clearSearchWordToolButton->setMaximumSize(
94 clearSearchWordToolButton->sizeHint().width()/2,
95 clearSearchWordToolButton->sizeHint().height()/2);
98 historyNextToolButton = new QToolButton();
99 historyNextToolButton->setIcon(QIcon::fromTheme("general_forward"));
100 historyNextToolButton->setMaximumSize(
101 historyNextToolButton->sizeHint().width()/2,
102 historyNextToolButton->sizeHint().height()/2);
105 historyPrevToolButton = new QToolButton();
106 historyPrevToolButton->setIcon(QIcon::fromTheme("general_back"));
107 historyPrevToolButton->setMaximumSize(
108 historyPrevToolButton->sizeHint().width()/2,
109 historyPrevToolButton->sizeHint().height()/2);
112 historyShowToolButton = new QToolButton();
113 historyShowToolButton->setIcon(QIcon::fromTheme("general_back"));
114 historyShowToolButton->setMaximumSize(
115 historyShowToolButton->sizeHint().width()/2,
116 historyShowToolButton->sizeHint().height()/2);
118 QPixmap p = historyShowToolButton->icon().pixmap(256);
124 temp.addPixmap(p.transformed(m));
125 historyShowToolButton->setIcon(temp);
128 searchingProgressBar = new QProgressBar();
129 //progress bar have minimum and maximum values set to 0, which will effect
130 //with "I'm alive" bar
131 searchingProgressBar->setMinimum(0);
132 searchingProgressBar->setMaximum(0);
133 searchingProgressBar->hide();
134 searchingProgressBar->setMaximumHeight(50);
138 setLayout(verticalLayout);
140 verticalLayout->addWidget(searchingProgressBar);
142 //adding widgets to layout
143 horizontalLayout->addWidget(searchWordLineEdit);
144 horizontalLayout->addWidget(searchPushButton);
145 horizontalLayout->addWidget(historyPrevToolButton);
146 horizontalLayout->addWidget(historyShowToolButton);
147 horizontalLayout->addWidget(historyNextToolButton);
149 //adding clear toolButton to textEdit with right alignment
150 lineEditLayout->addWidget(clearSearchWordToolButton, 0,
151 Qt::AlignRight | Qt::AlignVCenter);
153 verticalLayout->addLayout(horizontalLayout);
157 void SearchBarWidget::searchPushButtonClicked() {
159 searchingProgressBar->hide();
160 searchPushButton->setText(tr("Search"));
162 _isSearching = false;
163 emit stopSearching();
166 searchingProgressBar->show();
167 searchPushButton->setText(tr("Stop"));
170 QStringList searchWord;
171 searchWord << searchWordLineEdit->text();
172 emit searchForTranslations(searchWord);
176 void SearchBarWidget::searchWordList(QStringList words) {
178 searchingProgressBar->show();
179 searchPushButton->setText(tr("Stop"));
182 emit searchForTranslations(words);
186 void SearchBarWidget::setEnabled(bool enabled) {
187 searchWordLineEdit->setEnabled(enabled);
188 historyNextToolButton->setEnabled(enabled);
189 historyPrevToolButton->setEnabled(enabled);
190 historyShowToolButton->setEnabled(enabled);
193 void SearchBarWidget::showBusy() {
194 searchingProgressBar->show();
198 void SearchBarWidget::showIdle() {
199 searchingProgressBar->hide();
203 void SearchBarWidget::searchFinished() {
204 searchingProgressBar->hide();
205 searchPushButton->setText(tr("Search"));
207 _isSearching = false;
210 void SearchBarWidget::historyNextToolButtonClicked() {
212 CommonDictInterface*p = backbone->getPlugins()[0];
213 p->dictDialog()->addNewDictionary(this);
216 void SearchBarWidget::historyPrevToolButtonClicked() {
220 void SearchBarWidget::historyShowToolButtonClicked() {
224 void SearchBarWidget::clearSearchWordToolButtonClicked() {
225 searchWordLineEdit->clear();
228 void SearchBarWidget::showHistoryListDialog() {
232 bool SearchBarWidget::isSearching() const {