#include "SearchBarWidget.h"
#include <QDebug>
#include "../../includes/DictDialog.h"
+#include "HistoryListDialog.h"
SearchBarWidget::SearchBarWidget(Backbone* backbone, QWidget *parent) :
this->backbone = backbone;
+ history = backbone->history();
+
initializeUI();
setMaximumHeight(150);
connect(backbone, SIGNAL(htmlReady()),
this, SLOT(setIdle()));
+
+ connect(history, SIGNAL(historyChanged(bool,bool,bool)),
+ this, SLOT(updateHistoryButtons(bool,bool,bool)));
+
searchWordLineEdit->setFocus();
+
+ setEnabled(true);
}
SearchBarWidget::~SearchBarWidget() {
Qt::AlignRight | Qt::AlignVCenter);
verticalLayout->addLayout(horizontalLayout);
-
}
if(!_isSearching && !word.isEmpty()) {
searchWordLineEdit->setText(word);
setBusy();
+ history->add(word);
emit searchForTranslations(word);
}
}
void SearchBarWidget::setEnabled(bool enabled) {
searchWordLineEdit->setEnabled(enabled);
- historyNextToolButton->setEnabled(enabled);
- historyPrevToolButton->setEnabled(enabled);
- historyShowToolButton->setEnabled(enabled);
+
+ if(enabled) {
+ historyNextToolButton->setEnabled(history->nextAvailable());
+ historyPrevToolButton->setEnabled(history->prevAvailable());
+ historyShowToolButton->setEnabled(history->listAvailable());
+ }
}
void SearchBarWidget::setBusy() {
}
void SearchBarWidget::historyNextToolButtonClicked() {
-
+ QString next = history->next();
+ if(!next.isEmpty()) {
+ searchWordLineEdit->setText(next);
+ }
}
void SearchBarWidget::historyPrevToolButtonClicked() {
-
+ QString prev = history->previous();
+ if(!prev.isEmpty()) {
+ searchWordLineEdit->setText(prev);
+ }
}
void SearchBarWidget::historyShowToolButtonClicked() {
-
+ HistoryListDialog listDialog(history, this);
+ listDialog.exec();
}
void SearchBarWidget::clearSearchWordToolButtonClicked() {
searchWordLineEdit->clear();
}
-void SearchBarWidget::showHistoryListDialog() {
-
-}
bool SearchBarWidget::isSearching() const {
return _isSearching;
}
+
+void SearchBarWidget::updateHistoryButtons(bool prev, bool next, bool list) {
+ if(!isSearching()) {
+ historyPrevToolButton->setEnabled(prev);
+ historyNextToolButton->setEnabled(next);
+ historyShowToolButton->setEnabled(list);
+ }
+}