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();
61 historyPrevToolButton->setEnabled(false);
62 historyNextToolButton->setEnabled(false);
63 historyShowToolButton->setEnabled(false);
67 SearchBarWidget::~SearchBarWidget() {
71 QIcon SearchBarWidget::generateIcon(QIcon oryginal, qreal rotation) {
72 QPixmap p = oryginal.pixmap(64);
85 painter.fillRect(p.rect(), QColor(0,0,0,192));
87 newIcon.addPixmap(p, QIcon::Disabled, QIcon::Off);
93 void SearchBarWidget::initializeUI() {
94 horizontalLayout = new QHBoxLayout();
95 verticalLayout = new QVBoxLayout();
98 searchPushButton = new QPushButton(tr("Search"));
99 searchPushButton->setMinimumWidth(150);
102 searchWordLineEdit = new QLineEdit();
103 searchWordLineEdit->setMinimumWidth(300);
107 //create layout for lineEdit to have clear button on it
108 QHBoxLayout* lineEditLayout = new QHBoxLayout;
109 searchWordLineEdit->setLayout(lineEditLayout);
112 clearSearchWordToolButton = new QToolButton();
113 clearSearchWordToolButton->setIcon(QIcon::fromTheme("general_stop"));
114 //tool buttons will have size 2 times smaller
115 clearSearchWordToolButton->setMaximumSize(
116 clearSearchWordToolButton->sizeHint().width()/2,
117 clearSearchWordToolButton->sizeHint().height()/2);
120 historyNextToolButton = new QToolButton();
121 historyNextToolButton->setIcon(
122 generateIcon(QIcon::fromTheme("general_forward")));
124 historyPrevToolButton = new QToolButton();
125 historyPrevToolButton->setIcon(
126 generateIcon(QIcon::fromTheme("general_back")));
128 historyShowToolButton = new QToolButton();
129 historyShowToolButton->setIcon(
130 generateIcon(QIcon::fromTheme("general_back"), 90));
134 searchingProgressBar = new QProgressBar();
135 //progress bar have minimum and maximum values set to 0, which will effect
136 //with "I'm alive" bar
137 searchingProgressBar->setMinimum(0);
138 searchingProgressBar->setMaximum(0);
139 searchingProgressBar->hide();
140 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);
162 void SearchBarWidget::searchPushButtonClicked() {
164 emit stopSearching();
167 search(searchWordLineEdit->text());
172 void SearchBarWidget::search(QString word) {
173 if(!_isSearching && !word.isEmpty()) {
174 searchWordLineEdit->setText(word);
175 emit searchForTranslations(word);
179 void SearchBarWidget::setEnabled(bool enabled) {
180 searchWordLineEdit->setEnabled(enabled);
183 historyPrevToolButton->setEnabled(false);
184 historyNextToolButton->setEnabled(false);
185 historyShowToolButton->setEnabled(false);
189 void SearchBarWidget::setBusy() {
190 if(_isSearching) return;
191 searchingProgressBar->show();
192 searchPushButton->setText(tr("Stop"));
197 void SearchBarWidget::setIdle() {
198 if(!_isSearching) return;
199 searchingProgressBar->hide();
200 searchPushButton->setText(tr("Search"));
202 _isSearching = false;
203 emit refreshHistoryButtons();
207 void SearchBarWidget::clearSearchWordToolButtonClicked() {
208 searchWordLineEdit->clear();
213 void SearchBarWidget::updateHistoryButtons(bool prev, bool next, bool list) {
215 historyPrevToolButton->setEnabled(prev);
216 historyNextToolButton->setEnabled(next);
217 historyShowToolButton->setEnabled(list);