ba3e36da65bdfdfea3ce171868a909bbdf2a28c9
[mdictionary] / trunk / src / base / mDictionary / gui / SearchBarWidget.cpp
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
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.
9
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.
14
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/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21
22 //Created by Mateusz Półrola
23
24
25 #include "SearchBarWidget.h"
26 #include <QDebug>
27
28
29
30 SearchBarWidget::SearchBarWidget(QWidget *parent) :
31     QWidget(parent) {
32
33     initializeUI();
34
35     setMaximumHeight(150);
36
37     isSearching = false;
38
39     connect(searchPushButton, SIGNAL(clicked()),
40             this, SLOT(searchPushButtonClicked()));
41
42     connect(historyNextToolButton, SIGNAL(clicked()),
43             this, SLOT(historyNextToolButtonClicked()));
44
45     connect(historyPrevToolButton, SIGNAL(clicked()),
46             this, SLOT(historyPrevToolButtonClicked()));
47
48     connect(historyShowToolButton, SIGNAL(clicked()),
49             this, SLOT(historyShowToolButtonClicked()));
50
51     connect(clearSearchWordToolButton, SIGNAL(clicked()),
52             this, SLOT(clearSearchWordToolButtonClicked()));
53
54 }
55
56 SearchBarWidget::~SearchBarWidget() {
57
58 }
59
60
61 void SearchBarWidget::initializeUI() {
62     horizontalLayout = new QHBoxLayout();
63     verticalLayout = new QVBoxLayout();
64
65
66     searchPushButton = new QPushButton(tr("Search"));
67     searchPushButton->setMinimumWidth(200);
68
69
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);
75
76
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);
83
84
85     historyNextToolButton = new QToolButton();
86     historyNextToolButton->setIcon(QIcon("sowa.svg"));
87     historyNextToolButton->setMaximumSize(
88             historyNextToolButton->sizeHint().width()/2,
89             historyNextToolButton->sizeHint().height()/2);
90
91
92     historyPrevToolButton = new QToolButton();
93     historyPrevToolButton->setIcon(QIcon("sowa.svg"));
94     historyPrevToolButton->setMaximumSize(
95             historyPrevToolButton->sizeHint().width()/2,
96             historyPrevToolButton->sizeHint().height()/2);
97
98
99     historyShowToolButton = new QToolButton();
100     historyShowToolButton->setIcon(QIcon("sowa.svg"));
101     historyShowToolButton->setMaximumSize(
102             historyShowToolButton->sizeHint().width()/2,
103             historyShowToolButton->sizeHint().height()/2);
104
105
106     searchingProgressBar = new QProgressBar();
107     searchingProgressBar->setMinimum(0);
108     searchingProgressBar->setMaximum(0);
109     searchingProgressBar->hide();
110     searchingProgressBar->setMaximumHeight(50);
111
112
113
114     setLayout(verticalLayout);
115
116     verticalLayout->addWidget(searchingProgressBar);
117
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);
124
125     //adding clear toolButton to textEdit with right alignment
126     lineEditLayout->addWidget(clearSearchWordToolButton, 0,
127                               Qt::AlignRight | Qt::AlignVCenter);
128
129     verticalLayout->addLayout(horizontalLayout);
130 }
131
132
133 void SearchBarWidget::searchPushButtonClicked() {
134     if(isSearching) {
135         emit stopSearching();
136         searchingProgressBar->hide();
137         searchPushButton->setText(tr("Search"));
138         setEnabled(true);
139         isSearching = false;
140     }
141     else {
142         emit searchForTranslations(searchWordLineEdit->text());
143         searchingProgressBar->show();
144         searchPushButton->setText(tr("Stop"));
145         setEnabled(false);
146         isSearching = true;
147     }
148 }
149
150 void SearchBarWidget::setEnabled(bool enabled) {
151     searchWordLineEdit->setEnabled(enabled);
152     historyNextToolButton->setEnabled(enabled);
153     historyPrevToolButton->setEnabled(enabled);
154     historyShowToolButton->setEnabled(enabled);
155 }
156
157 void SearchBarWidget::historyNextToolButtonClicked() {
158
159 }
160
161 void SearchBarWidget::historyPrevToolButtonClicked() {
162
163 }
164
165 void SearchBarWidget::historyShowToolButtonClicked() {
166
167 }
168
169 void SearchBarWidget::clearSearchWordToolButtonClicked() {
170     searchWordLineEdit->clear();
171 }
172
173 void SearchBarWidget::showHistoryListDialog() {
174
175 }
176
177 bool SearchBarWidget::isSearching() {
178     return _isSearching;
179 }