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 //connects request to backbone
58 connect(this, SIGNAL(searchForTranslations(QString)),
59 backbone, SLOT(search(QString)));
61 connect(this, SIGNAL(stopSearching()),
62 backbone, SLOT(stopSearching()));
64 connect(backbone, SIGNAL(ready()),
65 this, SLOT(setEnabled(bool)));
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("sowa.svg"));
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("sowa.svg"));
100 historyNextToolButton->setMaximumSize(
101 historyNextToolButton->sizeHint().width()/2,
102 historyNextToolButton->sizeHint().height()/2);
105 historyPrevToolButton = new QToolButton();
106 historyPrevToolButton->setIcon(QIcon("sowa.svg"));
107 historyPrevToolButton->setMaximumSize(
108 historyPrevToolButton->sizeHint().width()/2,
109 historyPrevToolButton->sizeHint().height()/2);
112 historyShowToolButton = new QToolButton();
113 historyShowToolButton->setIcon(QIcon("sowa.svg"));
114 historyShowToolButton->setMaximumSize(
115 historyShowToolButton->sizeHint().width()/2,
116 historyShowToolButton->sizeHint().height()/2);
119 searchingProgressBar = new QProgressBar();
120 //progress bar have minimum and maximum values set to 0, which will effect
121 //with "I'm alive" bar
122 searchingProgressBar->setMinimum(0);
123 searchingProgressBar->setMaximum(0);
124 searchingProgressBar->hide();
125 searchingProgressBar->setMaximumHeight(50);
129 setLayout(verticalLayout);
131 verticalLayout->addWidget(searchingProgressBar);
133 //adding widgets to layout
134 horizontalLayout->addWidget(searchWordLineEdit);
135 horizontalLayout->addWidget(searchPushButton);
136 horizontalLayout->addWidget(historyPrevToolButton);
137 horizontalLayout->addWidget(historyShowToolButton);
138 horizontalLayout->addWidget(historyNextToolButton);
140 //adding clear toolButton to textEdit with right alignment
141 lineEditLayout->addWidget(clearSearchWordToolButton, 0,
142 Qt::AlignRight | Qt::AlignVCenter);
144 verticalLayout->addLayout(horizontalLayout);
148 void SearchBarWidget::searchPushButtonClicked() {
150 emit stopSearching();
151 searchingProgressBar->hide();
152 searchPushButton->setText(tr("Search"));
154 _isSearching = false;
157 emit searchForTranslations(searchWordLineEdit->text());
158 searchingProgressBar->show();
159 searchPushButton->setText(tr("Stop"));
165 void SearchBarWidget::setEnabled(bool enabled) {
166 searchWordLineEdit->setEnabled(enabled);
167 historyNextToolButton->setEnabled(enabled);
168 historyPrevToolButton->setEnabled(enabled);
169 historyShowToolButton->setEnabled(enabled);
172 void SearchBarWidget::historyNextToolButtonClicked() {
176 void SearchBarWidget::historyPrevToolButtonClicked() {
180 void SearchBarWidget::historyShowToolButtonClicked() {
184 void SearchBarWidget::clearSearchWordToolButtonClicked() {
185 searchWordLineEdit->clear();
188 void SearchBarWidget::showHistoryListDialog() {
192 bool SearchBarWidget::isSearching() const {