Added inline completer for line edit in search bar widget. Fixed some "this" bugs
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Mon, 30 Aug 2010 07:28:19 +0000 (09:28 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Mon, 30 Aug 2010 07:28:19 +0000 (09:28 +0200)
trunk/src/base/gui/AboutWidget.cpp
trunk/src/base/gui/DictManagerWidget.cpp
trunk/src/base/gui/MainWindow.cpp
trunk/src/base/gui/SearchBarWidget.cpp
trunk/src/base/gui/SearchBarWidget.h
trunk/src/base/gui/SettingsWidget.cpp

index 73df15f..1e3be9d 100644 (file)
@@ -49,19 +49,19 @@ AboutWidget::AboutWidget(GUIInterface *parent): QDialog(parent)
                   QString("</p></font>");
 
     setWindowTitle(tr("About"));
-    mainLayout = new QVBoxLayout(this);
+    mainLayout = new QVBoxLayout;
 
     #ifndef Q_WS_MAEMO_5
-        scrollLayout = new QVBoxLayout(this);
-        scroll = new QScrollArea(this);
+        scrollLayout = new QVBoxLayout;
+        scroll = new QScrollArea;
         w = new QWidget(this);
 
     #endif
 
 
-    imageLabel = new QLabel(this);
-    mainLabel = new QLabel(this);
-    licenseLabel = new QLabel(this);
+    imageLabel = new QLabel;
+    mainLabel = new QLabel;
+    licenseLabel = new QLabel;
 
 
     QImage img(":/icons/logo/mdictionary.png");
index 157aa2f..c718908 100644 (file)
@@ -36,23 +36,23 @@ DictManagerWidget::DictManagerWidget(GUIInterface *parent) :
     setWindowTitle(tr("Dictionaries"));
     this->guiInterface = parent;
 
-    verticalLayout = new QVBoxLayout(this);
+    verticalLayout = new QVBoxLayout;
     setLayout(verticalLayout);
 
-    dictListWidget = new QListWidget(this);
+    dictListWidget = new QListWidget;
     verticalLayout->addWidget(dictListWidget);
 
     dictListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
     dictListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
-    addNewDictButton = new QPushButton(tr("Add"),this);
-    removeDictButton = new QPushButton(tr("Remove"),this);
-    settingsButton = new QPushButton(tr("Settings"),this);
+    addNewDictButton = new QPushButton(tr("Add"));
+    removeDictButton = new QPushButton(tr("Remove"));
+    settingsButton = new QPushButton(tr("Settings"));
 
     removeDictButton->setEnabled(false);
     settingsButton->setEnabled(false);
 
-    buttonGroup = new QHBoxLayout(this);
+    buttonGroup = new QHBoxLayout;
 
     buttonGroup->addWidget(addNewDictButton);
     buttonGroup->addWidget(removeDictButton);
@@ -157,6 +157,7 @@ void DictManagerWidget::saveChanges() {
 
 void DictManagerWidget::hideEvent(QHideEvent *e)
 {
+    qDebug()<<"hide";
     saveChanges();
     QWidget::hideEvent(e);
 }
index 5179780..aa48cc2 100644 (file)
@@ -332,7 +332,7 @@ void MainWindow::showNotify(Notify::NotifyType type, QString text) {
     switch(type) {
     case Notify::Info:
         #ifdef Q_WS_MAEMO_5
-            QMaemo5InformationBox::information(this,
+            QMaemo5InformationBox::information(0,
                                 text,
                                 QMaemo5InformationBox::DefaultTimeout);
         #else
@@ -344,13 +344,11 @@ void MainWindow::showNotify(Notify::NotifyType type, QString text) {
         #ifndef Q_WS_MAEMO_5
                 QMessageBox::warning(this, "Warning", text);
                 break;
-        #else
-            QMessageBox::information(this, "Warning", text);
         #endif
 
     case Notify::Error:
         #ifdef Q_WS_MAEMO_5
-            QMaemo5InformationBox::information(this,
+            QMaemo5InformationBox::information(0,
                                 text,
                                 QMaemo5InformationBox::NoTimeout);
         #else
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);
     }
index 6fed28f..388c468 100644 (file)
@@ -112,6 +112,8 @@ private Q_SLOTS:
 
 private:
     QLineEdit* searchWordLineEdit;
+    QCompleter* lineEditCompleter;
+    QStringListModel* completerModel;
     QToolButton* clearSearchWordToolButton;
     QPushButton* searchPushButton;
     QToolButton* historyPrevToolButton;
index 854d5c3..15e3e40 100644 (file)
@@ -31,16 +31,16 @@ SettingsWidget::SettingsWidget(GUIInterface *parent) :
 
     setWindowTitle(tr("Settings"));
 
-    verticalLayout = new QVBoxLayout(this);
+    verticalLayout = new QVBoxLayout;
     setLayout(verticalLayout);
 
-    historySizeSpinBox = new QSpinBox(this);
-    searchResultSizeSpinBox = new QSpinBox(this);
+    historySizeSpinBox = new QSpinBox;
+    searchResultSizeSpinBox = new QSpinBox;
     limitTip = "Limit maximal number of finded words, affect only when "
                 "searching in file.";
     searchResultSizeSpinBox->setToolTip(limitTip);
 
-    spinBoxesFormLayout = new QFormLayout(this);
+    spinBoxesFormLayout = new QFormLayout;
 
     spinBoxesFormLayout->addRow(tr("Search result size"),
                                 searchResultSizeSpinBox);
@@ -83,7 +83,7 @@ SettingsWidget::SettingsWidget(GUIInterface *parent) :
     #ifndef Q_WS_MAEMO_5
         setMinimumWidth(250);
         setMaximumWidth(250);
-        footerLayout = new QHBoxLayout(this);
+        footerLayout = new QHBoxLayout;
         closeButton = new QPushButton(tr("Save"));
         footerLayout->addStretch(0);
         footerLayout->addWidget(closeButton);