X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fmdictionary%2Fgui%2FSearchBarWidget.cpp;h=9dc1450a528eaf59fc896e850678b2cd498e6941;hb=ac86fa7a460e6fb10126eb63372d18a5dd1e1f4d;hp=b53d664bf45882462ed45b5b9394cd2aeef9087c;hpb=be63f2df3539bacf2ee5bf0a4f21eee5c0a18314;p=mdictionary diff --git a/src/mdictionary/gui/SearchBarWidget.cpp b/src/mdictionary/gui/SearchBarWidget.cpp index b53d664..9dc1450 100644 --- a/src/mdictionary/gui/SearchBarWidget.cpp +++ b/src/mdictionary/gui/SearchBarWidget.cpp @@ -33,42 +33,99 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) { + qDebug()<<"test1"; +#ifndef Q_WS_MAEMO_5 + this->setMaximumHeight(50); + busyTimer=new QTimer; + + progressBar = new QDeclarativeView(); + progressBar->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/ProgressBar.qml")); + progressBar->setResizeMode(QDeclarativeView::SizeRootObjectToView); + progressBar->setAlignment(Qt::AlignCenter); + progressBar->hide(); + + view= new QDeclarativeView(); + view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/SearchBarWidget.qml")); + view->setResizeMode(QDeclarativeView::SizeRootObjectToView); + view->setAlignment(Qt::AlignCenter); + view->show(); + + mainLayout = new QVBoxLayout; + mainLayout->addWidget(progressBar); + mainLayout->addWidget(view); + setLayout(mainLayout); + + QGraphicsObject *rootObject = view->rootObject(); + QGraphicsObject *rootObject2 = progressBar->rootObject(); + + connect(rootObject, SIGNAL(searchButtonClicked(QString)), + this, SLOT(searchButtonClicked(QString))); + connect(rootObject, SIGNAL(historyNextToolButtonClicked()), + this, SIGNAL(historyNext())); + connect(rootObject, SIGNAL(historyPrevToolButtonClicked()), + this, SIGNAL(historyPrev())); + connect(rootObject, SIGNAL(historyShowToolButtonClicked()), + this, SLOT(showHistoryButtonClicked())); - initializeUI(); + connect(this, SIGNAL(progresSetMax(QVariant)), + rootObject2, SLOT(setMax(QVariant))); + connect(this, SIGNAL(progresSetMin(QVariant)), + rootObject2, SLOT(setMin(QVariant))); + connect(this, SIGNAL(progresSetValue(QVariant)), + rootObject2, SLOT(setValue(QVariant))); + connect(this, SIGNAL(progresSetValue2(QVariant)), + rootObject2, SLOT(setValue2(QVariant))); + + connect(this, SIGNAL(setEnableHistoryNext(QVariant)), + rootObject, SLOT(setEnableHistoryNext(QVariant))); + connect(this, SIGNAL(setEnableHistoryShow(QVariant)), + rootObject, SLOT(setEnableHistoryShow(QVariant))); + connect(this, SIGNAL(setEnableHistoryPrev(QVariant)), + rootObject, SLOT(setEnableHistoryPrev(QVariant))); + connect(this, SIGNAL(setButtonText(QVariant)), + rootObject, SLOT(setButtonText(QVariant))); + connect(this, SIGNAL(setLineEditText(QVariant)), + rootObject, SLOT(setLineEditText(QVariant))); + connect(this, SIGNAL(setLineEditEnables(QVariant)), + rootObject, SLOT(setEnableLineEdit(QVariant))); + + connect(busyTimer, SIGNAL(timeout()), + this, SLOT(updateBusyTimer())); + + emit setEnableHistoryNext(false); + emit setEnableHistoryShow(false); + emit setEnableHistoryPrev(false); + completerModel = new QStringListModel(this); + connect(&delayTimer, SIGNAL(timeout()), + this, SLOT(delaySearchTimeout())); - busy = false; + view->setFocus(); +#else + initializeUI(); connect(searchPushButton, SIGNAL(clicked()), this, SLOT(searchPushButtonClicked())); - connect(searchWordLineEdit, SIGNAL(returnPressed()), this, SLOT(searchPushButtonClicked())); - connect(historyNextToolButton, SIGNAL(clicked()), this, SIGNAL(historyNext())); - connect(historyPrevToolButton, SIGNAL(clicked()), this, SIGNAL(historyPrev())); - connect(historyShowToolButton, SIGNAL(clicked()), this, SLOT(showHistoryButtonClicked())); - connect(clearSearchWordToolButton, SIGNAL(clicked()), this, SLOT(clearSearchWordToolButtonClicked())); - - connect(&delayTimer, SIGNAL(timeout()), this, SLOT(delaySearchTimeout())); searchWordLineEdit->setFocus(); +#endif - historyPrevToolButton->setEnabled(false); - historyNextToolButton->setEnabled(false); - historyShowToolButton->setEnabled(false); - + busy = false; setEnabled(true); + updateHistoryButtons(false,false,false); } SearchBarWidget::~SearchBarWidget() { @@ -76,9 +133,9 @@ SearchBarWidget::~SearchBarWidget() { } QIcon SearchBarWidget::generateIcon(QIcon original, qreal rotation) { + qDebug()<<"test2"; QPixmap p = original.pixmap(64); - if(rotation != 0) { QMatrix m; m.rotate(rotation); @@ -112,49 +169,42 @@ QIcon SearchBarWidget::generateIcon(QIcon original, qreal rotation) { return newIcon; } - void SearchBarWidget::setFocus() { - searchWordLineEdit->setFocus(); + qDebug()<<"test3"; +#ifndef Q_WS_MAEMO_5 + view->setFocus(); +#else + searchWordLineEdit->setFocus(); +#endif } void SearchBarWidget::initializeUI() { - - #ifdef Q_WS_MAEMO_5 - setMaximumHeight(150); - #else - setMaximumHeight(100); - #endif - + qDebug()<<"test4"; +#ifdef Q_WS_MAEMO_5 + setMaximumHeight(150); horizontalLayout = new QHBoxLayout; verticalLayout = new QVBoxLayout; - searchPushButton = new QPushButton(tr("Search")); searchPushButton->setMinimumWidth(125); - searchWordLineEdit = new QLineEdit; searchWordLineEdit->setMinimumWidth(250); - - completerModel = new QStringListModel(this); - lineEditCompleter = new QCompleter(searchWordLineEdit); lineEditCompleter->setModel(completerModel); lineEditCompleter->setCaseSensitivity(Qt::CaseInsensitive); lineEditCompleter->setCompletionMode(QCompleter::InlineCompletion); searchWordLineEdit->setCompleter(lineEditCompleter); - #ifndef Q_WS_MAEMO_5 searchWordLineEdit->setMinimumHeight( searchWordLineEdit->sizeHint().height()*3/2); #endif - //create layout for lineEdit to have clear button on it QHBoxLayout* lineEditLayout = new QHBoxLayout; searchWordLineEdit->setLayout(lineEditLayout); @@ -217,7 +267,6 @@ void SearchBarWidget::initializeUI() { #endif searchingProgressBar->hide(); - setLayout(verticalLayout); verticalLayout->addWidget(searchingProgressBar); @@ -232,50 +281,65 @@ void SearchBarWidget::initializeUI() { //adding clear toolButton to textEdit with right alignment lineEditLayout->addWidget(clearSearchWordToolButton, 0, Qt::AlignRight); - verticalLayout->addLayout(horizontalLayout); +#endif } +void SearchBarWidget::searchButtonClicked(QString text) { + qDebug()<<"test5"; + if(busy) + Q_EMIT stopSearching(); + else + search(text); +} void SearchBarWidget::searchPushButtonClicked() { + qDebug()<<"test6"; +#ifdef Q_WS_MAEMO_5 if(busy) { Q_EMIT stopSearching(); } else { search(searchWordLineEdit->text()); } +#endif } - void SearchBarWidget::search(QString word) { + qDebug()<<"test7"; + qDebug()<insertRow(completerModel->rowCount()); - QModelIndex index = - completerModel->index(completerModel->rowCount() -1); - + QModelIndex index=completerModel->index(completerModel->rowCount() -1); completerModel->setData(index, word); - +#ifndef Q_WS_MAEMO_5 + emit setLineEditText(word); +#else searchWordLineEdit->setText(word); +#endif Q_EMIT searchForTranslations(word); } } void SearchBarWidget::searchDelay(QString word) { + qDebug()<<"test8"; if(!busy && !word.isEmpty()) { - searchWordLineEdit->setText(word); - + #ifndef Q_WS_MAEMO_5 + emit setLineEditText(word); + #else + searchWordLineEdit->setText(word); + #endif + if(delayTimer.isActive()) + delayTimer.stop(); + delayString = word; + delayTimer.start(500); - if(delayTimer.isActive()) { - delayTimer.stop(); - } - - delayString = word; - delayTimer.start(500); } } void SearchBarWidget::delaySearchTimeout() { + qDebug()<<"test9"; delayTimer.stop(); if(!busy) { Q_EMIT searchForTranslations(delayString); @@ -283,27 +347,75 @@ void SearchBarWidget::delaySearchTimeout() { } void SearchBarWidget::setEnabled(bool enabled) { + qDebug()<<"test10"; +#ifndef Q_WS_MAEMO_5 + emit setLineEditEnables(enabled); + if(!enabled) { + qDebug()<<"tu???"; + emit setEnableHistoryNext(false); + emit setEnableHistoryShow(false); + emit setEnableHistoryPrev(false); + } +#else searchWordLineEdit->setEnabled(enabled); - if(!enabled) { historyPrevToolButton->setEnabled(false); historyNextToolButton->setEnabled(false); historyShowToolButton->setEnabled(false); } +#endif +qDebug()<<"tu2???"; } void SearchBarWidget::setBusy() { + qDebug()<<"test11"; if(busy) return; + +#ifndef Q_WS_MAEMO_5 + busyTimer->start(50); + emit setButtonText(tr("Stop")); + this->setMaximumHeight(88); + progressBar->show(); + emit progresSetMax(100); + emit progresSetMin(0); + emit progresSetValue(-1); + emit progresSetValue2(100); + progressMax=true; +#else searchingProgressBar->show(); searchPushButton->setText(tr("Stop")); +#endif + setEnabled(false); busy = true; } +void SearchBarWidget::updateBusyTimer(){ + qDebug()<<"test12"; + if(progressMax==true){ + emit progresSetValue2(0); + progressMax=false; + } + else{ + emit progresSetValue2(100); + progressMax=true; + } + busyTimer->start(50); +} + void SearchBarWidget::setIdle() { + qDebug()<<"test13"; if(!busy) return; +#ifndef Q_WS_MAEMO_5 + progressBar->hide(); + busyTimer->stop(); + emit progresSetValue2(0); + this->setMaximumHeight(50); + emit setButtonText(tr("Search")); +#else searchingProgressBar->hide(); searchPushButton->setText(tr("Search")); +#endif setEnabled(true); busy = false; Q_EMIT refreshHistoryButtons(); @@ -311,25 +423,37 @@ void SearchBarWidget::setIdle() { void SearchBarWidget::clearSearchWordToolButtonClicked() { + qDebug()<<"test14"; +#ifdef Q_WS_MAEMO_5 searchWordLineEdit->clear(); +#endif } void SearchBarWidget::updateHistoryButtons(bool prev, bool next, bool list) { + qDebug()<<"test15"; if(!busy) { - historyPrevToolButton->setEnabled(prev); - historyNextToolButton->setEnabled(next); - historyShowToolButton->setEnabled(list); + #ifndef Q_WS_MAEMO_5 + emit setEnableHistoryNext(next); + emit setEnableHistoryShow(list); + emit setEnableHistoryPrev(prev); + #else + historyPrevToolButton->setEnabled(prev); + historyNextToolButton->setEnabled(next); + historyShowToolButton->setEnabled(list); + #endif } } void SearchBarWidget::showHistoryButtonClicked() { - #ifdef Q_WS_MAEMO_5 - emit historyShow(); - #else - QPoint p = historyShowToolButton->pos(); - p.setY(p.y()); - emit historyShow(mapToGlobal(p)); - #endif + qDebug()<<"test16"; +#ifndef Q_WS_MAEMO_5 + QPoint p=view->pos(); // = historyShowToolButton->pos(); + p=mapToGlobal(p); + p.setX(p.x()+view->width()); + emit historyShow(p); +#else + emit historyShow(); +#endif }