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"
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 connect(this, SIGNAL(searchForTranslations(QString)),
58 backbone, SLOT(search(QString)));
60 connect(this, SIGNAL(stopSearching()),
61 backbone, SLOT(stopSearching()));
63 connect(backbone, SIGNAL(ready()),
64 this, SLOT(setEnabled(bool)));
68 SearchBarWidget::~SearchBarWidget() {
73 void SearchBarWidget::initializeUI() {
74 horizontalLayout = new QHBoxLayout();
75 verticalLayout = new QVBoxLayout();
78 searchPushButton = new QPushButton(tr("Search"));
79 searchPushButton->setMinimumWidth(200);
82 searchWordLineEdit = new QLineEdit();
83 searchWordLineEdit->setMinimumWidth(350);
84 //create layout for lineEdit to have clear button on it
85 QHBoxLayout* lineEditLayout = new QHBoxLayout;
86 searchWordLineEdit->setLayout(lineEditLayout);
89 clearSearchWordToolButton = new QToolButton();
90 clearSearchWordToolButton->setIcon(QIcon("sowa.svg"));
91 //tool buttons will have size 2 times smaller
92 clearSearchWordToolButton->setMaximumSize(
93 clearSearchWordToolButton->sizeHint().width()/2,
94 clearSearchWordToolButton->sizeHint().height()/2);
97 historyNextToolButton = new QToolButton();
98 historyNextToolButton->setIcon(QIcon("sowa.svg"));
99 historyNextToolButton->setMaximumSize(
100 historyNextToolButton->sizeHint().width()/2,
101 historyNextToolButton->sizeHint().height()/2);
104 historyPrevToolButton = new QToolButton();
105 historyPrevToolButton->setIcon(QIcon("sowa.svg"));
106 historyPrevToolButton->setMaximumSize(
107 historyPrevToolButton->sizeHint().width()/2,
108 historyPrevToolButton->sizeHint().height()/2);
111 historyShowToolButton = new QToolButton();
112 historyShowToolButton->setIcon(QIcon("sowa.svg"));
113 historyShowToolButton->setMaximumSize(
114 historyShowToolButton->sizeHint().width()/2,
115 historyShowToolButton->sizeHint().height()/2);
118 searchingProgressBar = new QProgressBar();
119 searchingProgressBar->setMinimum(0);
120 searchingProgressBar->setMaximum(0);
121 searchingProgressBar->hide();
122 searchingProgressBar->setMaximumHeight(50);
126 setLayout(verticalLayout);
128 verticalLayout->addWidget(searchingProgressBar);
130 //adding widgets to layout
131 horizontalLayout->addWidget(searchWordLineEdit);
132 horizontalLayout->addWidget(searchPushButton);
133 horizontalLayout->addWidget(historyPrevToolButton);
134 horizontalLayout->addWidget(historyShowToolButton);
135 horizontalLayout->addWidget(historyNextToolButton);
137 //adding clear toolButton to textEdit with right alignment
138 lineEditLayout->addWidget(clearSearchWordToolButton, 0,
139 Qt::AlignRight | Qt::AlignVCenter);
141 verticalLayout->addLayout(horizontalLayout);
145 void SearchBarWidget::searchPushButtonClicked() {
147 emit stopSearching();
148 searchingProgressBar->hide();
149 searchPushButton->setText(tr("Search"));
151 _isSearching = false;
154 emit searchForTranslations(searchWordLineEdit->text());
155 searchingProgressBar->show();
156 searchPushButton->setText(tr("Stop"));
162 void SearchBarWidget::setEnabled(bool enabled) {
163 searchWordLineEdit->setEnabled(enabled);
164 historyNextToolButton->setEnabled(enabled);
165 historyPrevToolButton->setEnabled(enabled);
166 historyShowToolButton->setEnabled(enabled);
169 void SearchBarWidget::historyNextToolButtonClicked() {
173 void SearchBarWidget::historyPrevToolButtonClicked() {
177 void SearchBarWidget::historyShowToolButtonClicked() {
181 void SearchBarWidget::clearSearchWordToolButtonClicked() {
182 searchWordLineEdit->clear();
185 void SearchBarWidget::showHistoryListDialog() {
189 bool SearchBarWidget::isSearching() const {