Merge branch 'master' of ssh://drop.maemo.org/git/mdictionary
[mdictionary] / trunk / src / base / gui / SearchBarWidget.cpp
index 6921e26..b8c823a 100644 (file)
@@ -101,21 +101,33 @@ void SearchBarWidget::initializeUI() {
     #ifdef Q_WS_MAEMO_5
         setMaximumHeight(150);
     #else
-        setMaximumHeight(70);
+        setMaximumHeight(100);
     #endif
 
 
-    horizontalLayout = new QHBoxLayout();
-    verticalLayout = new QVBoxLayout();
+    horizontalLayout = new QHBoxLayout;
+    verticalLayout = new QVBoxLayout;
 
 
     searchPushButton = new QPushButton(tr("Search"));
     searchPushButton->setMinimumWidth(125);
 
 
-    searchWordLineEdit = new QLineEdit();
+    searchWordLineEdit = new QLineEdit;
     searchWordLineEdit->setMinimumWidth(250);
 
+
+
+    completerModel = new QStringListModel;
+
+
+    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);
@@ -123,11 +135,11 @@ void SearchBarWidget::initializeUI() {
 
 
     //create layout for lineEdit to have clear button on it
-    QHBoxLayout* lineEditLayout = new QHBoxLayout();
+    QHBoxLayout* lineEditLayout = new QHBoxLayout;
     searchWordLineEdit->setLayout(lineEditLayout);
 
 
-    clearSearchWordToolButton = new QToolButton();
+    clearSearchWordToolButton = new QToolButton;
     #ifdef Q_WS_MAEMO_5
         clearSearchWordToolButton->setIcon(QIcon::fromTheme("general_stop"));
         //tool buttons will have size 2 times smaller
@@ -144,7 +156,7 @@ void SearchBarWidget::initializeUI() {
     #endif
 
 
-    historyNextToolButton = new QToolButton();
+    historyNextToolButton = new QToolButton;
     #ifdef Q_WS_MAEMO_5
         historyNextToolButton->setIcon(
                 generateIcon(QIcon::fromTheme("general_forward")));
@@ -155,7 +167,7 @@ void SearchBarWidget::initializeUI() {
 
 
 
-    historyPrevToolButton = new QToolButton();
+    historyPrevToolButton = new QToolButton;
     #ifdef Q_WS_MAEMO_5
         historyPrevToolButton->setIcon(
                 generateIcon(QIcon::fromTheme("general_back")));
@@ -166,7 +178,7 @@ void SearchBarWidget::initializeUI() {
 
 
 
-    historyShowToolButton = new QToolButton();
+    historyShowToolButton = new QToolButton;
     #ifdef Q_WS_MAEMO_5
         historyShowToolButton->setIcon(
                 generateIcon(QIcon::fromTheme("general_back"), 90));
@@ -175,27 +187,15 @@ void SearchBarWidget::initializeUI() {
                 generateIcon(QIcon::fromTheme("go-up")));
     #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();
+    searchingProgressBar = new QProgressBar;
     //progress bar have minimum and maximum values set to 0, which will effect
     //with "I'm alive" bar
     searchingProgressBar->setMinimum(0);
     searchingProgressBar->setMaximum(0);
-    searchingProgressBar->hide();
     #ifdef Q_WS_MAEMO_5
         searchingProgressBar->setMaximumHeight(50);
     #endif
+    searchingProgressBar->hide();
 
 
     setLayout(verticalLayout);
@@ -208,7 +208,6 @@ void SearchBarWidget::initializeUI() {
     horizontalLayout->addWidget(historyPrevToolButton);
     horizontalLayout->addWidget(historyShowToolButton);
     horizontalLayout->addWidget(historyNextToolButton);
-   // horizontalLayout->addWidget(fullScreenToolButton);
 
     //adding clear toolButton to textEdit with right alignment
     lineEditLayout->addWidget(clearSearchWordToolButton, 0, Qt::AlignRight);
@@ -230,6 +229,13 @@ void SearchBarWidget::searchPushButtonClicked() {
 
 void SearchBarWidget::search(QString word) {
     if(!_isSearching && !word.isEmpty()) {
+        completerModel->insertRow(completerModel->rowCount());
+        QModelIndex index =
+                completerModel->index(completerModel->rowCount() -1);
+
+        completerModel->setData(index, word);
+
+
         searchWordLineEdit->setText(word);
         Q_EMIT searchForTranslations(word);
     }