Changed history behaviour, history next and prev buttons now start searching after...
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Fri, 13 Aug 2010 06:21:00 +0000 (08:21 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Fri, 13 Aug 2010 06:21:00 +0000 (08:21 +0200)
trunk/src/base/backbone/backbone.cpp
trunk/src/base/gui/MainWindow.cpp
trunk/src/base/gui/MainWindow.h
trunk/src/base/gui/SearchBarWidget.cpp
trunk/src/base/gui/SearchBarWidget.h

index fac41a7..6270791 100644 (file)
@@ -157,6 +157,9 @@ QMultiHash<QString, Translation*> Backbone::result() {
 
 
 void Backbone::stopSearching() {
+    if(stopped)
+        return;
+
     foreach(CommonDictInterface* dict, _dicts.keys())
         dict->stop();
     stopped = true;
index c26fb8f..252d816 100644 (file)
@@ -171,6 +171,8 @@ void MainWindow::searchExact(QString word) {
     searchBarWidget->search(word);
 }
 
+
+
 void MainWindow::breakSearching() {
     //make sure to unset exact search mode
     setExactSearch(false);
@@ -186,14 +188,14 @@ void MainWindow::addToHistory(QList<Translation *> trans) {
 void MainWindow::historyNext() {
     if(backbone->history()->nextAvailable()) {
         QString next = backbone->history()->next();
-        searchExact(next);
+        searchBarWidget->searchDelay(next);
     }
 }
 
 void MainWindow::historyPrev() {
     if(backbone->history()->prevAvailable()) {
         QString prev = backbone->history()->previous();
-        searchExact(prev);
+        searchBarWidget->searchDelay(prev);
     }
 }
 
@@ -256,6 +258,9 @@ void MainWindow::connectBackbone() {
     connect(backbone, SIGNAL(htmlReady()),
             this, SLOT(translationsReady()));
 
+    connect(backbone, SIGNAL(searchCanceled()),
+            this, SIGNAL(setIdle()));
+
 
 
 
index 5901634..644cc04 100644 (file)
@@ -104,6 +104,7 @@ public:
       */
     void searchExact(QString);
 
+
     //! Gets word list from backbone and prepares received list to display
     /*!
       Checks if received list is empty, in that case displays suitable
@@ -185,6 +186,7 @@ private:
     bool _exactSearch;
     QString searchString;
 
+
     void connectBackbone();
     void connectSearchBar();
     void connectWordList();
index afdceb4..80541e9 100644 (file)
@@ -56,6 +56,10 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) :
             this, SLOT(clearSearchWordToolButtonClicked()));
 
 
+    connect(&delayTimer, SIGNAL(timeout()),
+            this, SLOT(delaySearchTimeout()));
+
+
     searchWordLineEdit->setFocus();
 
     historyPrevToolButton->setEnabled(false);
@@ -176,6 +180,27 @@ void SearchBarWidget::search(QString 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);
 
index b3b8f18..2bf1ee0 100644 (file)
@@ -93,12 +93,21 @@ public Q_SLOTS:
       */
     void search(QString word);
 
+    //! Start to search for given word after 500 ms
+    /*!
+      Sets word as text in search word line edit, and wait 500 ms to start
+      search. If in meanwhile this slot is called again it will stop previous
+      timers.
+      */
+    void searchDelay(QString word);
+
     //! Updates state of history buttons
     void updateHistoryButtons(bool prev, bool next, bool list);
 
 private Q_SLOTS:
     void clearSearchWordToolButtonClicked();
     void searchPushButtonClicked();
+    void delaySearchTimeout();
 
 
 private:
@@ -117,6 +126,9 @@ private:
 
     bool _isSearching;
 
+    QTimer delayTimer;
+    QString delayString;
+
     void initializeUI();
 };