#include "HistoryListDialog.h"
-SearchBarWidget::SearchBarWidget(Backbone* backbone, QWidget *parent) :
+SearchBarWidget::SearchBarWidget(QWidget *parent) :
QWidget(parent) {
- this->backbone = backbone;
-
- history = backbone->history();
-
initializeUI();
- setMaximumHeight(150);
_isSearching = false;
this, SLOT(searchPushButtonClicked()));
connect(historyNextToolButton, SIGNAL(clicked()),
- this, SLOT(historyNextToolButtonClicked()));
+ this, SIGNAL(historyNext()));
connect(historyPrevToolButton, SIGNAL(clicked()),
- this, SLOT(historyPrevToolButtonClicked()));
+ this, SIGNAL(historyPrev()));
connect(historyShowToolButton, SIGNAL(clicked()),
- this, SLOT(historyShowToolButtonClicked()));
+ this, SIGNAL(historyShow()));
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(setIdle()));
-
- connect(backbone, SIGNAL(htmlReady()),
- this, SLOT(setIdle()));
+ connect(&delayTimer, SIGNAL(timeout()),
+ this, SLOT(delaySearchTimeout()));
- connect(history, SIGNAL(historyChanged(bool,bool,bool)),
- this, SLOT(updateHistoryButtons(bool,bool,bool)));
-
searchWordLineEdit->setFocus();
+ historyPrevToolButton->setEnabled(false);
+ historyNextToolButton->setEnabled(false);
+ historyShowToolButton->setEnabled(false);
setEnabled(true);
}
QIcon newIcon;
newIcon.addPixmap(p);
- QPainter painter(&p);
- painter.fillRect(p.rect(), QColor(0,0,0,192));
- newIcon.addPixmap(p, QIcon::Disabled, QIcon::Off);
+ #ifdef Q_WS_MAEMO_5
+ QPainter painter(&p);
+ painter.fillRect(p.rect(), QColor(0,0,0,192));
+
+ newIcon.addPixmap(p, QIcon::Disabled, QIcon::Off);
+ #endif
return newIcon;
}
void SearchBarWidget::initializeUI() {
+
+ #ifdef Q_WS_MAEMO_5
+ setMaximumHeight(150);
+ #else
+ setMaximumHeight(100);
+ #endif
+
+
horizontalLayout = new QHBoxLayout();
verticalLayout = new QVBoxLayout();
searchPushButton = new QPushButton(tr("Search"));
- searchPushButton->setMinimumWidth(150);
-
+ searchPushButton->setMinimumWidth(125);
+ #ifndef Q_WS_MAEMO_5
+ searchPushButton->setMinimumHeight(
+ searchPushButton->sizeHint().height()*2);
+ #endif
searchWordLineEdit = new QLineEdit();
- searchWordLineEdit->setMinimumWidth(300);
+ searchWordLineEdit->setMinimumWidth(250);
+
+ #ifndef Q_WS_MAEMO_5
+ searchWordLineEdit->setMinimumHeight(
+ searchWordLineEdit->sizeHint().height()*2);
+ #endif
+
+
//create layout for lineEdit to have clear button on it
QHBoxLayout* lineEditLayout = new QHBoxLayout;
searchWordLineEdit->setLayout(lineEditLayout);
clearSearchWordToolButton = new QToolButton();
- clearSearchWordToolButton->setIcon(QIcon::fromTheme("general_stop"));
- //tool buttons will have size 2 times smaller
- clearSearchWordToolButton->setMaximumSize(
- clearSearchWordToolButton->sizeHint().width()/2,
- clearSearchWordToolButton->sizeHint().height()/2);
+ #ifdef Q_WS_MAEMO_5
+ clearSearchWordToolButton->setIcon(QIcon::fromTheme("general_stop"));
+ //tool buttons will have size 2 times smaller
+ clearSearchWordToolButton->setMaximumSize(
+ clearSearchWordToolButton->sizeHint().height()/2,
+ clearSearchWordToolButton->sizeHint().height()/2);
+ #else
+ clearSearchWordToolButton->setIcon(QIcon::fromTheme("edit-clear"));
+ clearSearchWordToolButton->setMinimumSize(
+ clearSearchWordToolButton->sizeHint().height(),
+ clearSearchWordToolButton->sizeHint().height());
+ #endif
historyNextToolButton = new QToolButton();
- historyNextToolButton->setIcon(
- generateIcon(QIcon::fromTheme("general_forward")));
+ #ifdef Q_WS_MAEMO_5
+ historyNextToolButton->setIcon(
+ generateIcon(QIcon::fromTheme("general_forward")));
+ #else
+ historyNextToolButton->setIcon(
+ generateIcon(QIcon::fromTheme("go-next")));
+ historyNextToolButton->setMinimumSize(
+ clearSearchWordToolButton->sizeHint().height()*2,
+ clearSearchWordToolButton->sizeHint().height()*2);
+ #endif
+
+
historyPrevToolButton = new QToolButton();
- historyPrevToolButton->setIcon(
- generateIcon(QIcon::fromTheme("general_back")));
+ #ifdef Q_WS_MAEMO_5
+ historyPrevToolButton->setIcon(
+ generateIcon(QIcon::fromTheme("general_back")));
+ #else
+ historyPrevToolButton->setIcon(
+ generateIcon(QIcon::fromTheme("go-previous")));
+ historyPrevToolButton->setMinimumSize(
+ clearSearchWordToolButton->sizeHint().height()*2,
+ clearSearchWordToolButton->sizeHint().height()*2);
+ #endif
- historyShowToolButton = new QToolButton();
- historyShowToolButton->setIcon(
- generateIcon(QIcon::fromTheme("general_back"), 90));
+ historyShowToolButton = new QToolButton();
+ #ifdef Q_WS_MAEMO_5
+ historyShowToolButton->setIcon(
+ generateIcon(QIcon::fromTheme("general_back"), 90));
+ #else
+ historyShowToolButton->setIcon(
+ generateIcon(QIcon::fromTheme("go-up")));
+ historyShowToolButton->setMinimumSize(
+ clearSearchWordToolButton->sizeHint().height()*2,
+ clearSearchWordToolButton->sizeHint().height()*2);
+ #endif
+
+ fullScreenToolButton = new QToolButton();
+ #ifdef Q_WS_MAEMO_5
+ fullScreenToolButton->setIcon(
+ generateIcon(QIcon::fromTheme("general_fullsize")));
+ #else
+ fullScreenToolButton->setIcon(
+ generateIcon(QIcon::fromTheme("view-fullscreen")));
+ fullScreenToolButton->setMinimumSize(
+ fullScreenToolButton->sizeHint().height()*2,
+ fullScreenToolButton->sizeHint().height()*2);
+ #endif
+
searchingProgressBar = new QProgressBar();
//progress bar have minimum and maximum values set to 0, which will effect
searchingProgressBar->setMinimum(0);
searchingProgressBar->setMaximum(0);
searchingProgressBar->hide();
- searchingProgressBar->setMaximumHeight(50);
+ #ifdef Q_WS_MAEMO_5
+ searchingProgressBar->setMaximumHeight(50);
+ #endif
setLayout(verticalLayout);
horizontalLayout->addWidget(historyPrevToolButton);
horizontalLayout->addWidget(historyShowToolButton);
horizontalLayout->addWidget(historyNextToolButton);
+ horizontalLayout->addWidget(fullScreenToolButton);
//adding clear toolButton to textEdit with right alignment
lineEditLayout->addWidget(clearSearchWordToolButton, 0,
void SearchBarWidget::searchPushButtonClicked() {
if(_isSearching) {
- setIdle();
emit stopSearching();
}
else {
void SearchBarWidget::search(QString word) {
if(!_isSearching && !word.isEmpty()) {
searchWordLineEdit->setText(word);
- setBusy();
- history->add(word);
emit searchForTranslations(word);
}
}
+void SearchBarWidget::searchDelay(QString word) {
+ if(!_isSearching && !word.isEmpty()) {
+ searchWordLineEdit->setText(word);
+
+
+ if(delayTimer.isActive()) {
+ delayTimer.stop();
+ }
+
+ delayString = word;
+ delayTimer.start(500);
+ }
+}
+
+void SearchBarWidget::delaySearchTimeout() {
+ delayTimer.stop();
+ if(!_isSearching) {
+ emit searchForTranslations(delayString);
+ }
+}
+
void SearchBarWidget::setEnabled(bool enabled) {
searchWordLineEdit->setEnabled(enabled);
- if(enabled) {
- historyNextToolButton->setEnabled(history->nextAvailable());
- historyPrevToolButton->setEnabled(history->prevAvailable());
- historyShowToolButton->setEnabled(history->listAvailable());
+ if(!enabled) {
+ historyPrevToolButton->setEnabled(false);
+ historyNextToolButton->setEnabled(false);
+ historyShowToolButton->setEnabled(false);
}
}
searchPushButton->setText(tr("Stop"));
setEnabled(false);
_isSearching = true;
- emit busy();
}
void SearchBarWidget::setIdle() {
searchPushButton->setText(tr("Search"));
setEnabled(true);
_isSearching = false;
- emit idle();
+ emit refreshHistoryButtons();
}
-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();
}
-bool SearchBarWidget::isSearching() const {
- return _isSearching;
-}
void SearchBarWidget::updateHistoryButtons(bool prev, bool next, bool list) {
- if(!isSearching()) {
+ if(!_isSearching) {
historyPrevToolButton->setEnabled(prev);
historyNextToolButton->setEnabled(next);
historyShowToolButton->setEnabled(list);