SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) {
+
+ completerModel = new QStringList;
+ lineEditCompleter = new QCompleter(this);
+ lineEditCompleter->setModel(new QStringListModel(*completerModel));
+ lineEditCompleter->setCaseSensitivity(Qt::CaseInsensitive);
+ lineEditCompleter->setCompletionMode(QCompleter::InlineCompletion);
+
#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("src/mdictionary/qml/SearchBarWidget.qml"));
+ ctxt = view->rootContext();
+
+ 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(historyPrevToolButtonClicked()),
this, SIGNAL(historyPrev()));
connect(rootObject, SIGNAL(historyShowToolButtonClicked()),
- this, SIGNAL(historyShow()));
+ this, SLOT(showHistoryButtonClicked()));
+ connect(rootObject, SIGNAL(textChange(QString)),
+ this, SLOT(textChange(QString)));
+ connect(rootObject, SIGNAL(nextCompleter()),
+ this, SLOT(nextCompleter()));
+ connect(rootObject, SIGNAL(prevCompleter()),
+ this, SLOT(prevCompleter()));
+
+ 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(setLineEditEnables(QVariant)),
rootObject, SLOT(setEnableLineEdit(QVariant)));
+ connect(this, SIGNAL(setCompleterText(QVariant)),
+ rootObject, SLOT(setCompleterText(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()));
+
+ view->setFocus();
+
#else
initializeUI();
connect(searchPushButton, SIGNAL(clicked()),
connect(&delayTimer, SIGNAL(timeout()),
this, SLOT(delaySearchTimeout()));
-
searchWordLineEdit->setFocus();
#endif
}
+void SearchBarWidget::textChange(QString text){
+ QLineEdit line;
+ QString toSend="";
+ QString tempString;
+ actualString=text;
+ completerActualList.clear();
+
+ line.setCompleter(lineEditCompleter);
+ line.completer()->setCompletionPrefix(text);
+ for (int i = 0; lineEditCompleter->setCurrentRow(i); i++)
+ completerActualList.append(lineEditCompleter->currentCompletion());
+
+ completerActualList.sort();
+ if(completerActualList.contains(preferedCompliter)){
+ tempString = preferedCompliter;
+ toSend = tempString.remove(0,text.size());
+ emit setCompleterText(toSend);
+ }
+ else if(completerActualList.size()>0 && text.size()>0){
+ toSend = completerActualList.at(0);
+ preferedCompliter= toSend;
+ toSend=toSend.remove(0,text.size());
+ if(toSend.size()>0)
+ emit setCompleterText(toSend);
+ else if(completerActualList.size()>1){
+ toSend = completerActualList.at(1);
+ preferedCompliter= toSend;
+ toSend=toSend.remove(0,text.size());
+ emit setCompleterText(toSend);
+ }
+ }
+ else{
+ preferedCompliter="";
+ emit setCompleterText(toSend);
+ }
+}
+
+void SearchBarWidget::prevCompleter(){
+ QString tempString;
+ if(!preferedCompliter.isEmpty()){
+ int index = completerActualList.indexOf(preferedCompliter);
+ qDebug()<<"index"<<index<<"size"<<completerActualList.size()<<"+1";
+ if(index!=-1 && completerActualList.size()>index+1){
+ preferedCompliter = completerActualList.at(index+1);
+ tempString=preferedCompliter;
+ QString toSend = tempString.remove(0,actualString.size());
+ emit setCompleterText(toSend);
+ }
+ }
+}
+
+void SearchBarWidget::nextCompleter(){
+ QString tempString;
+ if(!preferedCompliter.isEmpty()){
+ int index = completerActualList.indexOf(preferedCompliter);
+ if(index>0){
+ preferedCompliter = completerActualList.at(index-1);
+ tempString=preferedCompliter;
+ QString toSend = tempString.remove(0,actualString.size());
+ emit setCompleterText(toSend);
+ }
+ }
+}
+
+
QIcon SearchBarWidget::generateIcon(QIcon original, qreal rotation) {
+ qDebug()<<"test2";
QPixmap p = original.pixmap(64);
if(rotation != 0) {
}
void SearchBarWidget::setFocus() {
-#ifdef Q_WS_MAEMO_5
+ qDebug()<<"test3";
+#ifndef Q_WS_MAEMO_5
+ view->setFocus();
+#else
searchWordLineEdit->setFocus();
#endif
}
void SearchBarWidget::initializeUI() {
+ qDebug()<<"test4";
#ifdef Q_WS_MAEMO_5
setMaximumHeight(150);
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
}
void SearchBarWidget::searchButtonClicked(QString text) {
+ qDebug()<<"test5";
if(busy)
Q_EMIT stopSearching();
else
}
void SearchBarWidget::searchPushButtonClicked() {
+ qDebug()<<"test6";
#ifdef Q_WS_MAEMO_5
if(busy) {
Q_EMIT stopSearching();
}
void SearchBarWidget::search(QString word) {
- qDebug()<<word;
if(!busy && !word.isEmpty()) {
- completerModel->insertRow(completerModel->rowCount());
- QModelIndex index=completerModel->index(completerModel->rowCount() -1);
- completerModel->setData(index, word);
-
+ while(word.lastIndexOf(" ")==word.size()-1 && word.size()>0)
+ word=word.remove(word.size()-1,1);
+ if(!completerModel->contains(word))
+ completerModel->append(word);
+ QAbstractItemModel *temp=lineEditCompleter->model();
+ lineEditCompleter->setModel(new QStringListModel(*completerModel));
+ delete temp;
#ifndef Q_WS_MAEMO_5
emit setLineEditText(word);
#else
}
void SearchBarWidget::searchDelay(QString word) {
+ qDebug()<<"test8";
if(!busy && !word.isEmpty()) {
#ifndef Q_WS_MAEMO_5
emit setLineEditText(word);
}
void SearchBarWidget::delaySearchTimeout() {
+ qDebug()<<"test9";
delayTimer.stop();
if(!busy) {
Q_EMIT searchForTranslations(delayString);
}
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);
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"));
-// searchingProgressBar->show();
+ 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"));
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
-// searchingProgressBar->hide();
+ progressBar->hide();
+ busyTimer->stop();
+ emit progresSetValue2(0);
+ this->setMaximumHeight(50);
emit setButtonText(tr("Search"));
#else
searchingProgressBar->hide();
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) {
#ifndef Q_WS_MAEMO_5
emit setEnableHistoryNext(next);
}
void SearchBarWidget::showHistoryButtonClicked() {
+ qDebug()<<"test16";
#ifndef Q_WS_MAEMO_5
QPoint p=view->pos(); // = historyShowToolButton->pos();
- p.setY(p.y());
- emit historyShow(mapToGlobal(p));
- #else
+ p=mapToGlobal(p);
+ p.setX(p.x()+view->width());
+ emit historyShow(p);
+#else
emit historyShow();
#endif
}