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) :
36 setMaximumHeight(150);
40 connect(searchPushButton, SIGNAL(clicked()),
41 this, SLOT(searchPushButtonClicked()));
43 connect(searchWordLineEdit, SIGNAL(returnPressed()),
44 this, SLOT(searchPushButtonClicked()));
46 connect(historyNextToolButton, SIGNAL(clicked()),
47 this, SIGNAL(historyNext()));
49 connect(historyPrevToolButton, SIGNAL(clicked()),
50 this, SIGNAL(historyPrev()));
52 connect(historyShowToolButton, SIGNAL(clicked()),
53 this, SIGNAL(historyShow()));
55 connect(clearSearchWordToolButton, SIGNAL(clicked()),
56 this, SLOT(clearSearchWordToolButtonClicked()));
59 searchWordLineEdit->setFocus();
64 SearchBarWidget::~SearchBarWidget() {
68 QIcon SearchBarWidget::generateIcon(QIcon oryginal, qreal rotation) {
69 QPixmap p = oryginal.pixmap(64);
82 painter.fillRect(p.rect(), QColor(0,0,0,192));
84 newIcon.addPixmap(p, QIcon::Disabled, QIcon::Off);
90 void SearchBarWidget::initializeUI() {
91 horizontalLayout = new QHBoxLayout();
92 verticalLayout = new QVBoxLayout();
95 searchPushButton = new QPushButton(tr("Search"));
96 searchPushButton->setMinimumWidth(150);
99 searchWordLineEdit = new QLineEdit();
100 searchWordLineEdit->setMinimumWidth(300);
104 //create layout for lineEdit to have clear button on it
105 QHBoxLayout* lineEditLayout = new QHBoxLayout;
106 searchWordLineEdit->setLayout(lineEditLayout);
109 clearSearchWordToolButton = new QToolButton();
110 clearSearchWordToolButton->setIcon(QIcon::fromTheme("general_stop"));
111 //tool buttons will have size 2 times smaller
112 clearSearchWordToolButton->setMaximumSize(
113 clearSearchWordToolButton->sizeHint().width()/2,
114 clearSearchWordToolButton->sizeHint().height()/2);
117 historyNextToolButton = new QToolButton();
118 historyNextToolButton->setIcon(
119 generateIcon(QIcon::fromTheme("general_forward")));
121 historyPrevToolButton = new QToolButton();
122 historyPrevToolButton->setIcon(
123 generateIcon(QIcon::fromTheme("general_back")));
125 historyShowToolButton = new QToolButton();
126 historyShowToolButton->setIcon(
127 generateIcon(QIcon::fromTheme("general_back"), 90));
131 searchingProgressBar = new QProgressBar();
132 //progress bar have minimum and maximum values set to 0, which will effect
133 //with "I'm alive" bar
134 searchingProgressBar->setMinimum(0);
135 searchingProgressBar->setMaximum(0);
136 searchingProgressBar->hide();
137 searchingProgressBar->setMaximumHeight(50);
140 setLayout(verticalLayout);
142 verticalLayout->addWidget(searchingProgressBar);
144 //adding widgets to layout
145 horizontalLayout->addWidget(searchWordLineEdit);
146 horizontalLayout->addWidget(searchPushButton);
147 horizontalLayout->addWidget(historyPrevToolButton);
148 horizontalLayout->addWidget(historyShowToolButton);
149 horizontalLayout->addWidget(historyNextToolButton);
151 //adding clear toolButton to textEdit with right alignment
152 lineEditLayout->addWidget(clearSearchWordToolButton, 0,
153 Qt::AlignRight | Qt::AlignVCenter);
155 verticalLayout->addLayout(horizontalLayout);
159 void SearchBarWidget::searchPushButtonClicked() {
161 emit stopSearching();
164 search(searchWordLineEdit->text());
169 void SearchBarWidget::search(QString word) {
170 if(!_isSearching && !word.isEmpty()) {
171 searchWordLineEdit->setText(word);
172 emit searchForTranslations(word);
176 void SearchBarWidget::setEnabled(bool enabled) {
177 searchWordLineEdit->setEnabled(enabled);
180 historyPrevToolButton->setEnabled(false);
181 historyNextToolButton->setEnabled(false);
182 historyShowToolButton->setEnabled(false);
186 void SearchBarWidget::setBusy() {
187 if(_isSearching) return;
188 searchingProgressBar->show();
189 searchPushButton->setText(tr("Stop"));
194 void SearchBarWidget::setIdle() {
195 if(!_isSearching) return;
196 searchingProgressBar->hide();
197 searchPushButton->setText(tr("Search"));
199 _isSearching = false;
200 emit refreshHistoryButtons();
204 void SearchBarWidget::clearSearchWordToolButtonClicked() {
205 searchWordLineEdit->clear();
209 bool SearchBarWidget::isSearching() const {
213 void SearchBarWidget::updateHistoryButtons(bool prev, bool next, bool list) {
215 historyPrevToolButton->setEnabled(prev);
216 historyNextToolButton->setEnabled(next);
217 historyShowToolButton->setEnabled(list);