Added settings widget
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Wed, 18 Aug 2010 07:09:19 +0000 (09:09 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Wed, 18 Aug 2010 07:09:19 +0000 (09:09 +0200)
trunk/src/base/base.pro
trunk/src/base/gui/DictManagerWidget.cpp
trunk/src/base/gui/MainWindow.cpp
trunk/src/base/gui/MainWindow.h
trunk/src/base/gui/MenuWidget.cpp
trunk/src/base/gui/SettingsWidget.cpp [new file with mode: 0644]
trunk/src/base/gui/SettingsWidget.h [new file with mode: 0644]
trunk/src/base/gui/TranslationWidget.cpp
trunk/src/base/gui/WordListWidget.cpp
trunk/src/base/gui/WordListWidget.h
trunk/src/includes/GUIInterface.h

index 9600dc0..4c6b86e 100644 (file)
@@ -34,7 +34,8 @@ SOURCES += gui/main.cpp\
     backbone/History.cpp \
     gui/HistoryListDialog.cpp \
     gui/WordListProxyStyle.cpp \
-    backbone/Bookmarks.cpp
+    backbone/Bookmarks.cpp \
+    gui/SettingsWidget.cpp
 
 HEADERS  += gui/MainWindow.h \
     gui/SearchBarWidget.h \
@@ -54,7 +55,8 @@ HEADERS  += gui/MainWindow.h \
     ../includes/GUIInterface.h \
     gui/WordListProxyStyle.h \
     backbone/Bookmarks.h \
-    backbone/BookmarkTranslations.h
+    backbone/BookmarkTranslations.h \
+    gui/SettingsWidget.h
 
 FORMS    += gui/MainWindow.ui
 
index 7e793ad..236aa35 100644 (file)
@@ -73,6 +73,9 @@ DictManagerWidget::DictManagerWidget(GUIInterface *parent) :
 
     refreshDictsList();
 
+    #ifndef Q_WS_MAEMO_5
+        setMinimumSize(500,300);
+    #endif
 }
 
 
index e67ce7c..b7622ce 100644 (file)
@@ -90,16 +90,24 @@ void MainWindow::initializeUI() {
 
     dictManagerWidget = new DictManagerWidget(this);
     dictManagerWidget->hide();
+
+    settingsWidget = new SettingsWidget(this);
+    settingsWidget->hide();
+
     #ifdef Q_WS_MAEMO_5
         menuWidget = new MenuWidget(this);
+        menuWidget->addSubMenu(tr("Settings"), settingsWidget);
         menuWidget->addSubMenu(tr("Dictionaries"), dictManagerWidget);
-        menuWidget->addSubMenu(tr("Settings"), new QPushButton("Settings"));
         menuWidget->addSubMenu(tr("About"), new QPushButton("About"));
         ui->menuBar->addAction(menuWidget);
     #else
         dictionariesAction = ui->menuBar->addAction(tr("Dictionaries"));
         connect(dictionariesAction, SIGNAL(triggered()),
                 dictManagerWidget, SLOT(show()));
+
+        settingsAction = ui->menuBar->addAction(tr("Settings"));
+        connect(settingsAction, SIGNAL(triggered()),
+                settingsWidget, SLOT(show()));
     #endif
 
 }
@@ -149,7 +157,9 @@ void MainWindow::wordListReady() {
             emit showWordList(searchResult);
         }
         else {
-
+            #ifndef Q_WS_MAEMO_5
+                emit showWordList(searchResult);
+            #endif
             bool foundExactMatch = false;
             QHash<QString, QList<Translation*> >::iterator j;
             for(j = searchResult.begin(); j != searchResult.end(); j++) {
@@ -212,12 +222,18 @@ void MainWindow::addToHistory(QList<Translation *> trans) {
 void MainWindow::historyNext() {
     if(backbone->history()->nextAvailable()) {
         QString next = backbone->history()->next();
+        #ifndef Q_WS_MAEMO_5
+            setExactSearch(true);
+        #endif
         searchBarWidget->searchDelay(next);
     }
 }
 
 void MainWindow::historyPrev() {
     if(backbone->history()->prevAvailable()) {
+        #ifndef Q_WS_MAEMO_5
+            setExactSearch(true);
+        #endif
         QString prev = backbone->history()->previous();
         searchBarWidget->searchDelay(prev);
     }
@@ -251,6 +267,14 @@ void MainWindow::showHistory() {
     }
 }
 
+void MainWindow::setSettings(Settings *s) {
+    backbone->setSettings(s);
+}
+
+Settings* MainWindow::settings() {
+    return backbone->settings();
+}
+
 void MainWindow::connectBackbone() {
     connect(this, SIGNAL(quit()),
             backbone, SLOT(quit()));
index 7ee6614..0af6159 100644 (file)
 
 #include <QMainWindow>
 #include "../../includes/GUIInterface.h"
+#include "../../includes/settings.h"
 #include "../backbone/backbone.h"
 #include "TranslationWidget.h"
 #include "WordListWidget.h"
 #include "SearchBarWidget.h"
 #include "MenuWidget.h"
 #include "DictManagerWidget.h"
+#include "SettingsWidget.h"
 #include "HistoryListDialog.h"
 
 namespace Ui {
@@ -94,6 +96,10 @@ public:
     */
     void setExactSearch(bool);
 
+    Settings* settings();
+
+    void setSettings(Settings*);
+
 
  public Q_SLOTS:
     //! Search in exact mode for given word
@@ -184,12 +190,13 @@ private:
     WordListWidget* wordListWidget;
     MenuWidget* menuWidget;
     DictManagerWidget* dictManagerWidget;
+    SettingsWidget* settingsWidget;
 
     #ifndef Q_WS_MAEMO_5
         QSplitter* splitter;
         QAction* dictionariesAction;
         //QAction* edit;
-       // QAction* settingsAction;
+        QAction* settingsAction;
         //QAction* aboutAction;
     #endif
 
index e516b71..af8cacd 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "MenuWidget.h"
 #include <QDebug>
+#include <QtGui>
 
 MenuWidget::MenuWidget(QWidget *parent) :
     QWidgetAction(parent) {
@@ -39,7 +40,11 @@ MenuWidget::~MenuWidget() {
 }
 
 void MenuWidget::addSubMenu(QString title, QWidget *widget) {
-    tabWidget->addTab(widget, title);
+    QScrollArea* sa = new QScrollArea(tabWidget);
+    sa->setWidget(widget);
+    sa->setWidgetResizable(true);
+    sa->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    tabWidget->addTab(sa, title);
 }
 
 
diff --git a/trunk/src/base/gui/SettingsWidget.cpp b/trunk/src/base/gui/SettingsWidget.cpp
new file mode 100644 (file)
index 0000000..f0de440
--- /dev/null
@@ -0,0 +1,115 @@
+/*******************************************************************************
+
+    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 "SettingsWidget.h"
+
+SettingsWidget::SettingsWidget(GUIInterface *parent) :
+    QDialog(parent)
+{
+    setWindowTitle(tr("Settings"));
+
+    verticalLayout = new QVBoxLayout;
+    setLayout(verticalLayout);
+
+    historySizeSpinBox = new QSpinBox;
+    searchResultSizeSpinBox = new QSpinBox;
+
+    spinBoxesFormLayout = new QFormLayout;
+
+    spinBoxesFormLayout->addRow(tr("Search result size"),
+                                searchResultSizeSpinBox);
+
+    spinBoxesFormLayout->addRow(tr("History size"),
+                                historySizeSpinBox);
+
+    #ifdef Q_WS_MAEMO_5
+        verticalLayout->addSpacing(20);
+    #endif
+    verticalLayout->addLayout(spinBoxesFormLayout);
+
+
+    checkBoxesLabel = new QLabel(tr("Search in:"));
+
+    searchInBookmarksCheckBox = new QCheckBox(tr("Bookmarks"));
+    searchInDictionariesCheckBox = new QCheckBox(tr("Dictionaries"));
+
+    verticalLayout->addSpacing(20);
+    verticalLayout->addWidget(checkBoxesLabel);
+    verticalLayout->addWidget(searchInDictionariesCheckBox);
+    verticalLayout->addWidget(searchInBookmarksCheckBox);
+
+    #ifndef Q_WS_MAEMO_5
+        setMinimumWidth(250);
+        setMaximumWidth(250);
+    #endif
+}
+
+void SettingsWidget::showEvent(QShowEvent *e) {
+    settings = guiInterface->getSettings();
+
+    historySizeSpinBox->setValue(
+            settings->value("history_size").toInt());
+
+    searchResultSizeSpinBox->setValue(
+            settings->value("search_limit").toInt());
+
+    if(settings->value("search_bookmarks") == "true")
+        searchInBookmarksCheckBox->setChecked(true);
+    else
+        searchInBookmarksCheckBox->setChecked(false);
+
+    if(settings->value("search_dictionaries") == "true")
+        searchInDictionariesCheckBox->setChecked(true);
+    else
+        searchInDictionariesCheckBox->setChecked(false);
+
+    QDialog::showEvent(e);
+}
+
+void SettingsWidget::hideEvent(QHideEvent *e) {
+    Settings* newSettings;
+    newSettings->setValue("history_size",
+                          QString::number(historySizeSpinBox->value()));
+    newSettings->setValue("search_limit",
+                          QString::number(searchResultSizeSpinBox->value()));
+
+    if(searchInDictionariesCheckBox->isChecked())
+        newSettings->setValue("search_dictionaries", "true");
+    else
+        newSettings->setValue("search_dictionaries", "false");
+
+    if(searchInBookmarksCheckBox->isChecked())
+        newSettings->setValue("search_bookmarks", "true");
+    else
+        newSettings->setValue("search_bookmarks", "false");
+
+    QString key;
+    foreach(key, newSettings->keys()) {
+        if(settings->value(key) != newSettings->value(key)) {
+            guiInterface->setSettings(newSettings);
+            break;
+        }
+    }
+
+    QDialog::hideEvent(e);
+}
diff --git a/trunk/src/base/gui/SettingsWidget.h b/trunk/src/base/gui/SettingsWidget.h
new file mode 100644 (file)
index 0000000..defb521
--- /dev/null
@@ -0,0 +1,56 @@
+/*******************************************************************************
+
+    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
+
+#ifndef SETTINGSWIDGET_H
+#define SETTINGSWIDGET_H
+
+#include <QWidget>
+#include <QtGui>
+#include "../../includes/GUIInterface.h"
+#include "../../includes/settings.h"
+
+class SettingsWidget : public QDialog
+{
+    Q_OBJECT
+public:
+    explicit SettingsWidget(GUIInterface *parent = 0);
+
+protected:
+    void showEvent(QShowEvent *);
+    void hideEvent(QHideEvent *);
+
+private:
+    QSpinBox* historySizeSpinBox;
+    QSpinBox* searchResultSizeSpinBox;
+    QVBoxLayout* verticalLayout;
+    QFormLayout* spinBoxesFormLayout;
+
+    QLabel* checkBoxesLabel;
+    QCheckBox* searchInDictionariesCheckBox;
+    QCheckBox* searchInBookmarksCheckBox;
+
+    GUIInterface* guiInterface;
+    Settings* settings;
+};
+
+#endif // SETTINGSWIDGET_H
index 7befd4c..04c7565 100644 (file)
@@ -85,9 +85,12 @@ void TranslationWidget::initializeUI() {
 
     QWidget*w = new QWidget;
     verticalLayout = new QVBoxLayout(w);
-    //verticalLayout->addLayout(horizontalLayout);
     verticalLayout->addWidget(textEdit);
 
+    textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+
     this->setWidget(w);
     this->setWidgetResizable(true);
 
index fed3397..3e284a5 100644 (file)
@@ -39,16 +39,15 @@ WordListWidget::WordListWidget(QWidget *parent):
     setModel(model);
     setHeaderHidden(true);
     setRootIsDecorated(false);
+    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+    setStyle(new WordListProxyStyle);
 
     #ifdef Q_WS_MAEMO_5
         checkBoxWidth = 70;
     #else
         checkBoxWidth = 25;
     #endif
-
-
-    setStyle(new WordListProxyStyle);
-
 }
 
 void WordListWidget::addWord(QString word, int row) {
@@ -92,9 +91,7 @@ void WordListWidget::showSearchResults(
            addWord(i.key(), row++);
     }
 
-    setColumnWidth(0, width()-checkBoxWidth - 20);
-    setColumnWidth(1, checkBoxWidth);
-    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    resizeColumns();
 }
 
 void WordListWidget::wordClicked(QModelIndex index) {
@@ -106,14 +103,13 @@ void WordListWidget::wordChecked(QModelIndex index) {
     Qt::CheckState state =
             Qt::CheckState(index.data(Qt::CheckStateRole).toInt());
 
-     QModelIndex item = selectedIndexes().at(0);
+    QModelIndex item = selectedIndexes().at(0);
+    if(!item.isValid()) return;
 
     if(state == Qt::Checked) {
-        qDebug()<<"Added  "<<item.data().toString();
         emit addBookmark(searchResult[item.data().toString()]);
     }
     else {
-        qDebug()<<"Removed  "<<item.data().toString();
         emit removeBookmark(searchResult[item.data().toString()]);
     }
 }
@@ -133,11 +129,15 @@ void WordListWidget::mouseReleaseEvent(QMouseEvent *event) {
 }
 
 void WordListWidget::resizeEvent(QResizeEvent *event) {
-    setColumnWidth(0, width()-checkBoxWidth - 20);
-    setColumnWidth(1, checkBoxWidth);
+    resizeColumns();
     QTreeView::resizeEvent(event);
 }
 
+void WordListWidget::resizeColumns() {
+    setColumnWidth(0, viewport()->width() -checkBoxWidth - 20);
+    setColumnWidth(1, checkBoxWidth);
+}
+
 void WordListWidget::lockList() {
     setEnabled(false);
 }
index 51e7c73..7ad634d 100644 (file)
@@ -46,8 +46,11 @@ Q_SIGNALS:
     //! objects
     void showTranslation(QList<Translation*>);
 
+
+    //! Request to add selected word to bookmarks
     void addBookmark(QList<Translation*>);
 
+    //! Request to remove selected word from bookmarks
     void removeBookmark(QList<Translation*>);
 
 
@@ -76,8 +79,8 @@ private:
     void addWord(QString word, int row);
     QStandardItemModel* model;
     int checkBoxWidth;
+    void resizeColumns();
 
-    Qt::CheckState itemState;
     QHash<QString, QList<Translation*> > searchResult;
 };
 
index 1d8e9fb..2d5292c 100644 (file)
@@ -32,6 +32,8 @@
 #include "translation.h"
 #include "CommonDictInterface.h"
 
+class Settings;
+
 //! Interface for different GUIs
 /*!
   Default base class for all GUIs is QMainWindow
@@ -73,6 +75,10 @@ public:
     /*! \sa exactSearch() */
     void setExactSearch(bool exactSearch);
 
+    Settings* getSettings() = 0;
+
+    void settings(Settings*) = 0;
+
 
 public Q_SLOTS:
     //! Search in exact mode for given word