--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+
+#include "SearchBarWidget.h"
+#include <QDebug>
+
+
+
+SearchBarWidget::SearchBarWidget(Backbone* backbone, QWidget *parent) :
+ QWidget(parent) {
+
+ this->backbone = backbone;
+
+ initializeUI();
+
+ setMaximumHeight(150);
+
+ _isSearching = false;
+
+ connect(searchPushButton, SIGNAL(clicked()),
+ this, SLOT(searchPushButtonClicked()));
+
+ connect(historyNextToolButton, SIGNAL(clicked()),
+ this, SLOT(historyNextToolButtonClicked()));
+
+ connect(historyPrevToolButton, SIGNAL(clicked()),
+ this, SLOT(historyPrevToolButtonClicked()));
+
+ connect(historyShowToolButton, SIGNAL(clicked()),
+ this, SLOT(historyShowToolButtonClicked()));
+
+ connect(clearSearchWordToolButton, SIGNAL(clicked()),
+ this, SLOT(clearSearchWordToolButtonClicked()));
+
+
+ //connects request to backbone
+ connect(this, SIGNAL(searchForTranslations(QString)),
+ backbone, SLOT(search(QString)));
+
+ connect(this, SIGNAL(stopSearching()),
+ backbone, SLOT(stopSearching()));
+
+ connect(backbone, SIGNAL(ready()),
+ this, SLOT(setEnabled(bool)));
+
+}
+
+SearchBarWidget::~SearchBarWidget() {
+
+}
+
+
+void SearchBarWidget::initializeUI() {
+ horizontalLayout = new QHBoxLayout();
+ verticalLayout = new QVBoxLayout();
+
+
+ searchPushButton = new QPushButton(tr("Search"));
+ searchPushButton->setMinimumWidth(200);
+
+
+ searchWordLineEdit = new QLineEdit();
+ searchWordLineEdit->setMinimumWidth(350);
+ //create layout for lineEdit to have clear button on it
+ QHBoxLayout* lineEditLayout = new QHBoxLayout;
+ searchWordLineEdit->setLayout(lineEditLayout);
+
+
+ clearSearchWordToolButton = new QToolButton();
+ clearSearchWordToolButton->setIcon(QIcon("sowa.svg"));
+ //tool buttons will have size 2 times smaller
+ clearSearchWordToolButton->setMaximumSize(
+ clearSearchWordToolButton->sizeHint().width()/2,
+ clearSearchWordToolButton->sizeHint().height()/2);
+
+
+ historyNextToolButton = new QToolButton();
+ historyNextToolButton->setIcon(QIcon("sowa.svg"));
+ historyNextToolButton->setMaximumSize(
+ historyNextToolButton->sizeHint().width()/2,
+ historyNextToolButton->sizeHint().height()/2);
+
+
+ historyPrevToolButton = new QToolButton();
+ historyPrevToolButton->setIcon(QIcon("sowa.svg"));
+ historyPrevToolButton->setMaximumSize(
+ historyPrevToolButton->sizeHint().width()/2,
+ historyPrevToolButton->sizeHint().height()/2);
+
+
+ historyShowToolButton = new QToolButton();
+ historyShowToolButton->setIcon(QIcon("sowa.svg"));
+ historyShowToolButton->setMaximumSize(
+ historyShowToolButton->sizeHint().width()/2,
+ historyShowToolButton->sizeHint().height()/2);
+
+
+ searchingProgressBar = new QProgressBar();
+ //progress bar have minimum and maximum values set to 0, which will effect
+ //with "I'm alive" bar
+ searchingProgressBar->setMinimum(0);
+ searchingProgressBar->setMaximum(0);
+ searchingProgressBar->hide();
+ searchingProgressBar->setMaximumHeight(50);
+
+
+
+ setLayout(verticalLayout);
+
+ verticalLayout->addWidget(searchingProgressBar);
+
+ //adding widgets to layout
+ horizontalLayout->addWidget(searchWordLineEdit);
+ horizontalLayout->addWidget(searchPushButton);
+ horizontalLayout->addWidget(historyPrevToolButton);
+ horizontalLayout->addWidget(historyShowToolButton);
+ horizontalLayout->addWidget(historyNextToolButton);
+
+ //adding clear toolButton to textEdit with right alignment
+ lineEditLayout->addWidget(clearSearchWordToolButton, 0,
+ Qt::AlignRight | Qt::AlignVCenter);
+
+ verticalLayout->addLayout(horizontalLayout);
+}
+
+
+void SearchBarWidget::searchPushButtonClicked() {
+ if(_isSearching) {
+ emit stopSearching();
+ searchingProgressBar->hide();
+ searchPushButton->setText(tr("Search"));
+ setEnabled(true);
+ _isSearching = false;
+ }
+ else {
+ emit searchForTranslations(searchWordLineEdit->text());
+ searchingProgressBar->show();
+ searchPushButton->setText(tr("Stop"));
+ setEnabled(false);
+ _isSearching = true;
+ }
+}
+
+void SearchBarWidget::setEnabled(bool enabled) {
+ searchWordLineEdit->setEnabled(enabled);
+ historyNextToolButton->setEnabled(enabled);
+ historyPrevToolButton->setEnabled(enabled);
+ historyShowToolButton->setEnabled(enabled);
+}
+
+void SearchBarWidget::historyNextToolButtonClicked() {
+
+}
+
+void SearchBarWidget::historyPrevToolButtonClicked() {
+
+}
+
+void SearchBarWidget::historyShowToolButtonClicked() {
+
+}
+
+void SearchBarWidget::clearSearchWordToolButtonClicked() {
+ searchWordLineEdit->clear();
+}
+
+void SearchBarWidget::showHistoryListDialog() {
+
+}
+
+bool SearchBarWidget::isSearching() const {
+ return _isSearching;
+}