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(QWidget *parent) :
35 setMaximumHeight(150);
39 connect(searchPushButton, SIGNAL(clicked()),
40 this, SLOT(searchPushButtonClicked()));
42 connect(historyNextToolButton, SIGNAL(clicked()),
43 this, SLOT(historyNextToolButtonClicked()));
45 connect(historyPrevToolButton, SIGNAL(clicked()),
46 this, SLOT(historyPrevToolButtonClicked()));
48 connect(historyShowToolButton, SIGNAL(clicked()),
49 this, SLOT(historyShowToolButtonClicked()));
51 connect(clearSearchWordToolButton, SIGNAL(clicked()),
52 this, SLOT(clearSearchWordToolButtonClicked()));
56 SearchBarWidget::~SearchBarWidget() {
61 void SearchBarWidget::initializeUI() {
62 horizontalLayout = new QHBoxLayout();
63 verticalLayout = new QVBoxLayout();
66 searchPushButton = new QPushButton(tr("Search"));
67 searchPushButton->setMinimumWidth(200);
70 searchWordLineEdit = new QLineEdit();
71 searchWordLineEdit->setMinimumWidth(350);
72 //create layout for lineEdit to have clear button on it
73 QHBoxLayout* lineEditLayout = new QHBoxLayout;
74 searchWordLineEdit->setLayout(lineEditLayout);
77 clearSearchWordToolButton = new QToolButton();
78 clearSearchWordToolButton->setIcon(QIcon("sowa.svg"));
79 //tool buttons will have size 2 times smaller
80 clearSearchWordToolButton->setMaximumSize(
81 clearSearchWordToolButton->sizeHint().width()/2,
82 clearSearchWordToolButton->sizeHint().height()/2);
85 historyNextToolButton = new QToolButton();
86 historyNextToolButton->setIcon(QIcon("sowa.svg"));
87 historyNextToolButton->setMaximumSize(
88 historyNextToolButton->sizeHint().width()/2,
89 historyNextToolButton->sizeHint().height()/2);
92 historyPrevToolButton = new QToolButton();
93 historyPrevToolButton->setIcon(QIcon("sowa.svg"));
94 historyPrevToolButton->setMaximumSize(
95 historyPrevToolButton->sizeHint().width()/2,
96 historyPrevToolButton->sizeHint().height()/2);
99 historyShowToolButton = new QToolButton();
100 historyShowToolButton->setIcon(QIcon("sowa.svg"));
101 historyShowToolButton->setMaximumSize(
102 historyShowToolButton->sizeHint().width()/2,
103 historyShowToolButton->sizeHint().height()/2);
106 searchingProgressBar = new QProgressBar();
107 searchingProgressBar->setMinimum(0);
108 searchingProgressBar->setMaximum(0);
109 searchingProgressBar->hide();
110 searchingProgressBar->setMaximumHeight(50);
114 setLayout(verticalLayout);
116 verticalLayout->addWidget(searchingProgressBar);
118 //adding widgets to layout
119 horizontalLayout->addWidget(searchWordLineEdit);
120 horizontalLayout->addWidget(searchPushButton);
121 horizontalLayout->addWidget(historyPrevToolButton);
122 horizontalLayout->addWidget(historyShowToolButton);
123 horizontalLayout->addWidget(historyNextToolButton);
125 //adding clear toolButton to textEdit with right alignment
126 lineEditLayout->addWidget(clearSearchWordToolButton, 0,
127 Qt::AlignRight | Qt::AlignVCenter);
129 verticalLayout->addLayout(horizontalLayout);
133 void SearchBarWidget::searchPushButtonClicked() {
135 emit stopSearching();
136 searchingProgressBar->hide();
137 searchPushButton->setText(tr("Search"));
139 _isSearching = false;
142 emit searchForTranslations(searchWordLineEdit->text());
143 searchingProgressBar->show();
144 searchPushButton->setText(tr("Stop"));
150 void SearchBarWidget::setEnabled(bool enabled) {
151 searchWordLineEdit->setEnabled(enabled);
152 historyNextToolButton->setEnabled(enabled);
153 historyPrevToolButton->setEnabled(enabled);
154 historyShowToolButton->setEnabled(enabled);
157 void SearchBarWidget::historyNextToolButtonClicked() {
161 void SearchBarWidget::historyPrevToolButtonClicked() {
165 void SearchBarWidget::historyShowToolButtonClicked() {
169 void SearchBarWidget::clearSearchWordToolButtonClicked() {
170 searchWordLineEdit->clear();
173 void SearchBarWidget::showHistoryListDialog() {
177 bool SearchBarWidget::isSearching() const {