simple gui integration with backbone and xdxf plugin
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Wed, 4 Aug 2010 13:56:17 +0000 (15:56 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Wed, 4 Aug 2010 13:56:17 +0000 (15:56 +0200)
trunk/src/base/gui/MainWindow.cpp
trunk/src/base/gui/SearchBarWidget.cpp
trunk/src/base/gui/SearchBarWidget.cpp~ [new file with mode: 0644]
trunk/src/base/gui/SearchBarWidget.h
trunk/src/base/gui/TranslationWidget.cpp
trunk/src/base/gui/WordListWidget.cpp
trunk/src/base/gui/WordListWidget.h

index 9e76657..6c2d121 100644 (file)
@@ -31,7 +31,7 @@ MainWindow::MainWindow(Backbone *backbone, QWidget *parent):
     this->backbone = backbone;
 
     ui->setupUi(this);
-   // setAttribute(Qt::WA_Maemo5StackedWindow);
+    setAttribute(Qt::WA_Maemo5StackedWindow);
 
     searchBarWidget = new SearchBarWidget(backbone);
     wordListWidget = new WordListWidget(backbone);
index 374e22a..4009da1 100644 (file)
@@ -62,7 +62,7 @@ SearchBarWidget::SearchBarWidget(Backbone* backbone, QWidget *parent) :
             backbone, SLOT(stopSearching()));
 
     connect(backbone, SIGNAL(ready()),
-            this, SLOT(setEnabled(bool)));
+            this, SLOT(searchFinished()));
 
 }
 
@@ -147,18 +147,18 @@ void SearchBarWidget::initializeUI() {
 
 void SearchBarWidget::searchPushButtonClicked() {
     if(_isSearching) {
-        emit stopSearching();
         searchingProgressBar->hide();
         searchPushButton->setText(tr("Search"));
         setEnabled(true);
         _isSearching = false;
+        emit stopSearching();
     }
     else {
-        emit searchForTranslations(searchWordLineEdit->text());
         searchingProgressBar->show();
         searchPushButton->setText(tr("Stop"));
         setEnabled(false);
         _isSearching = true;
+        emit searchForTranslations(searchWordLineEdit->text());
     }
 }
 
@@ -169,6 +169,14 @@ void SearchBarWidget::setEnabled(bool enabled) {
     historyShowToolButton->setEnabled(enabled);
 }
 
+
+void SearchBarWidget::searchFinished() {
+        searchingProgressBar->hide();
+        searchPushButton->setText(tr("Search"));
+        setEnabled(true);
+        _isSearching = false;
+}
+
 void SearchBarWidget::historyNextToolButtonClicked() {
 
 }
diff --git a/trunk/src/base/gui/SearchBarWidget.cpp~ b/trunk/src/base/gui/SearchBarWidget.cpp~
new file mode 100644 (file)
index 0000000..374e22a
--- /dev/null
@@ -0,0 +1,194 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+
+#include "SearchBarWidget.h"
+#include <QDebug>
+
+
+
+SearchBarWidget::SearchBarWidget(Backbone* backbone, QWidget *parent) :
+    QWidget(parent) {
+
+    this->backbone = backbone;
+
+    initializeUI();
+
+    setMaximumHeight(150);
+
+    _isSearching = false;
+
+    connect(searchPushButton, SIGNAL(clicked()),
+            this, SLOT(searchPushButtonClicked()));
+
+    connect(historyNextToolButton, SIGNAL(clicked()),
+            this, SLOT(historyNextToolButtonClicked()));
+
+    connect(historyPrevToolButton, SIGNAL(clicked()),
+            this, SLOT(historyPrevToolButtonClicked()));
+
+    connect(historyShowToolButton, SIGNAL(clicked()),
+            this, SLOT(historyShowToolButtonClicked()));
+
+    connect(clearSearchWordToolButton, SIGNAL(clicked()),
+            this, SLOT(clearSearchWordToolButtonClicked()));
+
+
+    //connects request to backbone
+    connect(this, SIGNAL(searchForTranslations(QString)),
+            backbone, SLOT(search(QString)));
+
+    connect(this, SIGNAL(stopSearching()),
+            backbone, SLOT(stopSearching()));
+
+    connect(backbone, SIGNAL(ready()),
+            this, SLOT(setEnabled(bool)));
+
+}
+
+SearchBarWidget::~SearchBarWidget() {
+
+}
+
+
+void SearchBarWidget::initializeUI() {
+    horizontalLayout = new QHBoxLayout();
+    verticalLayout = new QVBoxLayout();
+
+
+    searchPushButton = new QPushButton(tr("Search"));
+    searchPushButton->setMinimumWidth(200);
+
+
+    searchWordLineEdit = new QLineEdit();
+    searchWordLineEdit->setMinimumWidth(350);
+    //create layout for lineEdit to have clear button on it
+    QHBoxLayout* lineEditLayout = new QHBoxLayout;
+    searchWordLineEdit->setLayout(lineEditLayout);
+
+
+    clearSearchWordToolButton = new QToolButton();
+    clearSearchWordToolButton->setIcon(QIcon("sowa.svg"));
+    //tool buttons will have size 2 times smaller
+    clearSearchWordToolButton->setMaximumSize(
+            clearSearchWordToolButton->sizeHint().width()/2,
+            clearSearchWordToolButton->sizeHint().height()/2);
+
+
+    historyNextToolButton = new QToolButton();
+    historyNextToolButton->setIcon(QIcon("sowa.svg"));
+    historyNextToolButton->setMaximumSize(
+            historyNextToolButton->sizeHint().width()/2,
+            historyNextToolButton->sizeHint().height()/2);
+
+
+    historyPrevToolButton = new QToolButton();
+    historyPrevToolButton->setIcon(QIcon("sowa.svg"));
+    historyPrevToolButton->setMaximumSize(
+            historyPrevToolButton->sizeHint().width()/2,
+            historyPrevToolButton->sizeHint().height()/2);
+
+
+    historyShowToolButton = new QToolButton();
+    historyShowToolButton->setIcon(QIcon("sowa.svg"));
+    historyShowToolButton->setMaximumSize(
+            historyShowToolButton->sizeHint().width()/2,
+            historyShowToolButton->sizeHint().height()/2);
+
+
+    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();
+    searchingProgressBar->setMaximumHeight(50);
+
+
+
+    setLayout(verticalLayout);
+
+    verticalLayout->addWidget(searchingProgressBar);
+
+    //adding widgets to layout
+    horizontalLayout->addWidget(searchWordLineEdit);
+    horizontalLayout->addWidget(searchPushButton);
+    horizontalLayout->addWidget(historyPrevToolButton);
+    horizontalLayout->addWidget(historyShowToolButton);
+    horizontalLayout->addWidget(historyNextToolButton);
+
+    //adding clear toolButton to textEdit with right alignment
+    lineEditLayout->addWidget(clearSearchWordToolButton, 0,
+                              Qt::AlignRight | Qt::AlignVCenter);
+
+    verticalLayout->addLayout(horizontalLayout);
+}
+
+
+void SearchBarWidget::searchPushButtonClicked() {
+    if(_isSearching) {
+        emit stopSearching();
+        searchingProgressBar->hide();
+        searchPushButton->setText(tr("Search"));
+        setEnabled(true);
+        _isSearching = false;
+    }
+    else {
+        emit searchForTranslations(searchWordLineEdit->text());
+        searchingProgressBar->show();
+        searchPushButton->setText(tr("Stop"));
+        setEnabled(false);
+        _isSearching = true;
+    }
+}
+
+void SearchBarWidget::setEnabled(bool enabled) {
+    searchWordLineEdit->setEnabled(enabled);
+    historyNextToolButton->setEnabled(enabled);
+    historyPrevToolButton->setEnabled(enabled);
+    historyShowToolButton->setEnabled(enabled);
+}
+
+void SearchBarWidget::historyNextToolButtonClicked() {
+
+}
+
+void SearchBarWidget::historyPrevToolButtonClicked() {
+
+}
+
+void SearchBarWidget::historyShowToolButtonClicked() {
+
+}
+
+void SearchBarWidget::clearSearchWordToolButtonClicked() {
+    searchWordLineEdit->clear();
+}
+
+void SearchBarWidget::showHistoryListDialog() {
+
+}
+
+bool SearchBarWidget::isSearching() const {
+    return _isSearching;
+}
index 1c71672..ec93ed4 100644 (file)
@@ -59,6 +59,7 @@ public Q_SLOTS:
       Search/Stop button is always enabled
     */
     void setEnabled(bool enabled = true);
+    void searchFinished();
 
 private Q_SLOTS:
     void clearSearchWordToolButtonClicked();
index a84ea04..a14b821 100644 (file)
@@ -29,15 +29,17 @@ TranslationWidget::TranslationWidget(Backbone *backbone, QWidget *parent):
 
     this->backbone = backbone;
 
-    //setAttribute(Qt::WA_Maemo5StackedWindow);
+    setAttribute(Qt::WA_Maemo5StackedWindow);
     setWindowFlags(windowFlags() | Qt::Window);
 
     initializeUI();
 }
 
-void TranslationWidget::show(QModelIndex ) {
+void TranslationWidget::show(QModelIndex index) {
     QWidget::show();
-
+    QString v = index.model()->data(index, Qt::DisplayRole).toString();
+    Translation* t = backbone->result().value(v);
+    translationTextEdit->setText(t->toHtml());
 }
 
 void TranslationWidget::initializeUI() {
index 058d732..3174537 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "WordListWidget.h"
 #include <QDebug>
+#include "../../includes/translation.h"
 
 WordListWidget::WordListWidget(Backbone *backbone, QWidget *parent):
     QListView(parent) {
@@ -37,7 +38,7 @@ WordListWidget::WordListWidget(Backbone *backbone, QWidget *parent):
     setModel(wordListModel);
 }
 
-void WordListWidget::addWord(QString word) {
+void WordListWidget::addWord(QString word, Translation* trans) {
     int wordsCount = wordListModel->rowCount();
 
     wordListModel->insertRow(wordsCount);
@@ -45,6 +46,8 @@ void WordListWidget::addWord(QString word) {
     QModelIndex newWordIndex = wordListModel->index(wordsCount);
 
     wordListModel->setData(newWordIndex, word);
+    qDebug()<<wordListModel->setData(newWordIndex, QVariant::fromValue(trans),
+                           Qt::DecorationRole);
 }
 
 void WordListWidget::clear() {
@@ -57,11 +60,11 @@ void WordListWidget::clear() {
 
 void WordListWidget::showSearchResults() {
     clear();
-    QHash<QString, Translation*> searchResult = backbone->result();
+    searchResult = backbone->result();
 
     QHash<QString, Translation*>::iterator i;
     for(i = searchResult.begin(); i != searchResult.end(); i++) {
-         addWord(i.key());
+         addWord(i.key(), i.value());
     }
 
     wordListModel->sort(0, Qt::DescendingOrder);
index 430e698..0da5d76 100644 (file)
@@ -49,9 +49,10 @@ private:
     Backbone *backbone;
     //words are keeping as QStringListModel which allow to sort them
     QStringListModel *wordListModel;
-    void addWord(QString word);
+    void addWord(QString word, Translation* trans);
     //clears all list of words
     void clear();
+    QHash<QString, Translation*> searchResult;
 };
 
 #endif // WORDLISTWIDGET_H