serachBar + progressBar
[mdictionary] / src / mdictionary / gui / SearchBarWidget.cpp
index b53d664..0726d76 100644 (file)
 
 
 SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) {
+#ifndef Q_WS_MAEMO_5
+    this->setMaximumHeight(50);
 
-    initializeUI();
+    view= new QDeclarativeView();
+    view->setSource(QUrl("src/mdictionary/qml/SearchBarWidget.qml"));
+    view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+    view->setAlignment(Qt::AlignCenter);
+    view->show();
 
+    mainLayout = new QVBoxLayout;
+    mainLayout->addWidget(view);
+    setLayout(mainLayout);
 
-    busy = false;
+    QGraphicsObject *rootObject = view->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, SIGNAL(historyShow()));
+
+    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)));
+
+    emit setEnableHistoryNext(false);
+    emit setEnableHistoryShow(false);
+    emit setEnableHistoryPrev(false);
+
+    completerModel = new QStringListModel(this);
+    connect(&delayTimer, SIGNAL(timeout()),
+            this, SLOT(delaySearchTimeout()));
+#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() {
@@ -78,7 +110,6 @@ SearchBarWidget::~SearchBarWidget() {
 QIcon SearchBarWidget::generateIcon(QIcon original, qreal rotation) {
     QPixmap p = original.pixmap(64);
 
-
     if(rotation != 0) {
         QMatrix m;
         m.rotate(rotation);
@@ -112,49 +143,38 @@ QIcon SearchBarWidget::generateIcon(QIcon original, qreal rotation) {
     return newIcon;
 }
 
-
 void SearchBarWidget::setFocus() {
-    searchWordLineEdit->setFocus();
+#ifdef Q_WS_MAEMO_5
+        searchWordLineEdit->setFocus();
+#endif
 }
 
 void SearchBarWidget::initializeUI() {
-
-    #ifdef Q_WS_MAEMO_5
-        setMaximumHeight(150);
-    #else
-        setMaximumHeight(100);
-    #endif
-
+#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 +237,6 @@ void SearchBarWidget::initializeUI() {
     #endif
     searchingProgressBar->hide();
 
-
     setLayout(verticalLayout);
 
     verticalLayout->addWidget(searchingProgressBar);
@@ -232,46 +251,56 @@ 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) {
+    if(busy)
+        Q_EMIT stopSearching();
+    else
+        search(text);
+}
 
 void SearchBarWidget::searchPushButtonClicked() {
+#ifdef Q_WS_MAEMO_5
     if(busy) {
         Q_EMIT stopSearching();
     }
     else {
         search(searchWordLineEdit->text());
     }
+#endif
 }
 
-
 void SearchBarWidget::search(QString word) {
+    qDebug()<<word;
     if(!busy && !word.isEmpty()) {
         completerModel->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) {
     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);
     }
 }
 
@@ -283,27 +312,47 @@ void SearchBarWidget::delaySearchTimeout() {
 }
 
 void SearchBarWidget::setEnabled(bool enabled) {
+#ifndef Q_WS_MAEMO_5
+    emit setLineEditEnables(enabled);
+    if(!enabled) {
+        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
 }
 
 void SearchBarWidget::setBusy() {
     if(busy) return;
+
+#ifndef Q_WS_MAEMO_5
+    emit setButtonText(tr("Stop"));
+//  searchingProgressBar->show();
+#else
     searchingProgressBar->show();
     searchPushButton->setText(tr("Stop"));
+#endif
+
     setEnabled(false);
     busy = true;
 }
 
 void SearchBarWidget::setIdle() {
     if(!busy) return;
+#ifndef Q_WS_MAEMO_5
+//    searchingProgressBar->hide();
+    emit setButtonText(tr("Search"));
+#else
     searchingProgressBar->hide();
     searchPushButton->setText(tr("Search"));
+#endif
     setEnabled(true);
     busy = false;
     Q_EMIT refreshHistoryButtons();
@@ -311,25 +360,33 @@ void SearchBarWidget::setIdle() {
 
 
 void SearchBarWidget::clearSearchWordToolButtonClicked() {
+#ifdef Q_WS_MAEMO_5
     searchWordLineEdit->clear();
+#endif
 }
 
 
 
 void SearchBarWidget::updateHistoryButtons(bool prev, bool next, bool list) {
     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
+#ifndef Q_WS_MAEMO_5
+    QPoint p=view->pos(); // = historyShowToolButton->pos();
+    p.setY(p.y());
+    emit historyShow(mapToGlobal(p));
+ #else
+    emit historyShow();
+#endif
 }