Merge branch 'master' of ssh://drop.maemo.org/git/mdictionary
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Thu, 19 Aug 2010 07:02:16 +0000 (09:02 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Thu, 19 Aug 2010 07:02:16 +0000 (09:02 +0200)
14 files changed:
trunk/src/base/gui/BookmarksWidget.cpp
trunk/src/base/gui/BookmarksWidget.h
trunk/src/base/gui/DictManagerWidget.cpp
trunk/src/base/gui/MainWindow.cpp
trunk/src/base/gui/MainWindow.h
trunk/src/base/gui/MenuWidget.h
trunk/src/base/gui/SearchBarWidget.cpp
trunk/src/base/gui/SettingsWidget.cpp
trunk/src/base/gui/SettingsWidget.h
trunk/src/base/gui/WelcomeScreenWidget.h
trunk/src/base/gui/WordListProxyStyle.cpp
trunk/src/base/gui/WordListProxyStyle.h
trunk/src/base/gui/WordListWidget.cpp
trunk/src/base/gui/WordListWidget.h

index 7bbe036..047bad7 100644 (file)
     Copyright 2010 Comarch S.A.
 
 *******************************************************************************/
-
-//Created by Mateusz Półrola
+//! \file BookmarksWidget.cpp
+//! \brief Bookmarks management widget
+//! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
 
 #include "BookmarksWidget.h"
 
+
 BookmarksWidget::BookmarksWidget(GUIInterface *parent) :
     QDialog(parent)
 {
index 87b909c..fcc0c97 100644 (file)
@@ -19,7 +19,9 @@
 
 *******************************************************************************/
 
-//Created by Mateusz Półrola
+//! \file BookmarksWidget.h
+//! \brief Bookmarks management widget
+//! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
 
 #ifndef BOOKMARKSWIDGET_H
 #define BOOKMARKSWIDGET_H
 #include <QtGui>
 #include "../../includes/GUIInterface.h"
 
+//! Implements bookmarks management widget
+/*!
+  Allow user to show all or remove all bookmarks
+  */
 class BookmarksWidget : public QDialog
 {
     Q_OBJECT
index 236aa35..6209364 100644 (file)
@@ -19,7 +19,9 @@
 
 *******************************************************************************/
 
-//Created by Mateusz Półrola
+//! \file DictManagerWidget.cpp
+//! \brief Dicrionaries management widget
+//! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
 
 #include "DictManagerWidget.h"
 #include "DictTypeSelectDialog.h"
index 8dc1f47..a9a70d9 100644 (file)
@@ -33,10 +33,6 @@ MainWindow::MainWindow(Backbone *backbone, QWidget *parent):
     GUIInterface(parent),
     ui(new Ui::MainWindow) {
 
-    #ifdef Q_WS_MAEMO_5
-        setAttribute(Qt::WA_Maemo5StackedWindow);
-    #endif
-
     this->backbone = backbone;
 
     initializeUI();
@@ -65,10 +61,9 @@ MainWindow::~MainWindow() {
 void MainWindow::initializeUI() {
     ui->setupUi(this);
 
-    //showFullScreen();
-    //sets attribute to maemo's stacked window
-
-
+    #ifdef Q_WS_MAEMO_5
+        setAttribute(Qt::WA_Maemo5StackedWindow);
+    #endif
 
     searchBarWidget = new SearchBarWidget;
 
@@ -80,12 +75,15 @@ void MainWindow::initializeUI() {
 
     welcomeScreenWidget = new WelcomeScreenWidget;
 
+
     #ifdef Q_WS_MAEMO_5
+    //At start we set widget as welcome screen widget
         ui->centralWidget->layout()->addWidget(welcomeScreenWidget);
         QVBoxLayout* vl = (QVBoxLayout*)(ui->centralWidget->layout());
         vl->addWidget(searchBarWidget, 0, Qt::AlignBottom);
     #else
         translationWidget->hide();
+        //we add to splitter word list and welcome screen
         splitter = new QSplitter(Qt::Horizontal);
         splitter->addWidget(wordListWidget);
         splitter->addWidget(welcomeScreenWidget);
@@ -109,6 +107,7 @@ void MainWindow::initializeUI() {
     aboutWidget->hide();
 
 
+    //creating menus
 
     #ifdef Q_WS_MAEMO_5
         menuWidget = new MenuWidget(this);
@@ -165,13 +164,13 @@ void MainWindow::wordListReady() {
     QHash<QString, QList<Translation*> > searchResult;
 
     #ifdef Q_WS_MAEMO_5
+    //switch welcome screen with word list
     if(!wordListWidget->isVisible()) {
         int i = ui->centralWidget->layout()->indexOf(welcomeScreenWidget);
         QBoxLayout* l = (QBoxLayout*)(ui->centralWidget->layout());
         l->removeWidget(welcomeScreenWidget);
         welcomeScreenWidget->deleteLater();
         l->insertWidget(0, wordListWidget);
-        qDebug()<<"changed";
     }
     #endif
 
@@ -198,6 +197,7 @@ void MainWindow::wordListReady() {
         }
         else {
             #ifndef Q_WS_MAEMO_5
+            //on desktop we show word list in exact search
                 emit showWordList(searchResult);
             #endif
             bool foundExactMatch = false;
@@ -227,6 +227,7 @@ void MainWindow::wordListReady() {
 
 void MainWindow::translationsReady() {
     #ifndef Q_WS_MAEMO_5
+    //switch welcome screen with translation widget
     if(!translationWidget->isVisible()) {
         int i = ui->centralWidget->layout()->indexOf(welcomeScreenWidget);
         QBoxLayout* l = (QBoxLayout*)(ui->centralWidget->layout());
@@ -234,7 +235,6 @@ void MainWindow::translationsReady() {
         s->insertWidget(1,translationWidget);
         s->setStretchFactor(1, 150);
         welcomeScreenWidget->deleteLater();
-        qDebug()<<"changed";
     }
     #endif
 
@@ -471,23 +471,23 @@ void MainWindow::connectMenu() {
 }
 
 
-void MainWindow::showAllBookmarks() {
-    #ifdef Q_WS_MAEMO_5
-        menuWidget->hideMenu();
-    #endif
-    backbone->fetchBookmarks();
-}
-
 void MainWindow::connectBookmarksWidget() {
     #ifdef Q_WS_MAEMO_5
+        //after removing bookmarks we search for it once again to clear word list
         connect(bookmarksWidget, SIGNAL(removeAllBookmarks()),
                 backbone, SLOT(removeAllBookmark()));
 
+        connect(bookmarksWidget, SIGNAL(removeAllBookmarks()),
+                backbone, SLOT(fetchBookmarks()));
+
+
         connect(bookmarksWidget, SIGNAL(showAllBookmarks()),
-                this, SLOT(showAllBookmarks()));
+                menuWidget, SLOT(hideMenu()));
 
-        connect(bookmarksWidget, SIGNAL(removeAllBookmarks()),
+        connect(bookmarksWidget, SIGNAL(showAllBookmarks()),
                 backbone, SLOT(fetchBookmarks()));
+
+
     #else
         connect(bookmarksShowAllAction, SIGNAL(triggered()),
                 backbone, SLOT(fetchBookmarks()));
index 6032269..7f570b0 100644 (file)
@@ -99,8 +99,18 @@ public:
     */
     void setExactSearch(bool);
 
+
+    //! Returns current settings.
+    /*!
+       \returns Settings object containing curren application settings
+      */
     Settings* settings();
 
+
+    //! Sets new settings.
+    /*!
+       \param Settings object containing new application settings
+      */
     void setSettings(Settings*);
 
 
@@ -174,9 +184,6 @@ private Q_SLOTS:
     void breakSearching();
 
 
-    void showAllBookmarks();
-
-
 protected:
     /*! When user wants to close application, we first sends signal to stop all
         ongoing searches.
index fafc63b..37ec77b 100644 (file)
@@ -52,6 +52,9 @@ public:
     void removeSubMenu(QString title);
 
 public Q_SLOTS:
+    /*!
+      Hides menu
+      */
     void hideMenu();
 
 protected:
index 4731d6e..82ccd2e 100644 (file)
@@ -81,10 +81,10 @@ QIcon SearchBarWidget::generateIcon(QIcon oryginal, qreal rotation) {
         p = p.transformed(m);
     }
 
-
     QIcon newIcon;
     newIcon.addPixmap(p);
 
+
     #ifdef Q_WS_MAEMO_5
         QPainter painter(&p);
         painter.fillRect(p.rect(), QColor(0,0,0,192));
index 5b34ee5..937aee1 100644 (file)
@@ -65,7 +65,6 @@ SettingsWidget::SettingsWidget(GUIInterface *parent) :
     verticalLayout->addWidget(searchInBookmarksCheckBox);
 
 
-
     #ifndef Q_WS_MAEMO_5
         setMinimumWidth(250);
         setMaximumWidth(250);
@@ -112,6 +111,7 @@ void SettingsWidget::hideEvent(QHideEvent *e) {
     else
         newSettings->setValue("search_bookmarks", "false");
 
+    //setting new settings only if their are different that old ones
     QString key;
     foreach(key, newSettings->keys()) {
         if(settings->value(key) != newSettings->value(key)) {
index defb521..f7ed38d 100644 (file)
@@ -19,7 +19,9 @@
 
 *******************************************************************************/
 
-//Created by Mateusz Półrola
+//! \file DictManagerWidget.h
+//! \brief Settings widget
+//! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
 
 #ifndef SETTINGSWIDGET_H
 #define SETTINGSWIDGET_H
 #include "../../includes/GUIInterface.h"
 #include "../../includes/settings.h"
 
+//! Implements applications settings widget
+/*!
+  Shows settings that user can change.
+  It allow to change limit of searches and limit of history.
+  Also it allow to select if application have to search in dictionaries or in
+  bookmarks or in both of them. All changes are saved automatically after
+  hiding of this widget.
+  */
 class SettingsWidget : public QDialog
 {
     Q_OBJECT
 public:
+    //! Constructor
+    /*!
+      \param parent parent of this widget, which must be subclass of
+      GUIInterface, because it will use it to get current settings and
+      sets new ones.
+      */
     explicit SettingsWidget(GUIInterface *parent = 0);
 
 protected:
index 8a06634..463d979 100644 (file)
@@ -18,8 +18,9 @@
     Copyright 2010 Comarch S.A.
 
 *******************************************************************************/
-
-//Created by Mateusz Półrola
+//! \file WelcomeScreenWidget.h
+//! \brief Implements widget that display welcome screen to user
+//! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
 
 #ifndef WELCOMESCREENWIDGET_H
 #define WELCOMESCREENWIDGET_H
@@ -28,6 +29,7 @@
 #include <QScrollArea>
 #include <QtGui>
 
+//! Displays wlecome screen with logo and name of application
 class WelcomeScreenWidget : public QScrollArea
 {
     Q_OBJECT
index 57d03c4..571ba9b 100644 (file)
@@ -27,6 +27,7 @@
 WordListProxyStyle::WordListProxyStyle() :
     QProxyStyle()
 {
+    //load pixmap from resources
     starPixmapOn = QPixmap(":/icons/staron.png");
     starPixmapOff = QPixmap(":/icons/staroff.png");
 }
index dd76e73..4a1647c 100644 (file)
@@ -1,5 +1,6 @@
 /*******************************************************************************
 
+
     This file is part of mDictionary.
 
     mDictionary is free software: you can redistribute it and/or modify
@@ -18,8 +19,9 @@
     Copyright 2010 Comarch S.A.
 
 *******************************************************************************/
-
-//Created by Mateusz Półrola
+//! \file WordListProxyStyle.h
+//! \brief Implements custom style which draw checkboxes as stars
+//! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
 
 #ifndef WORDLISTPROXYSTYLE_H
 #define WORDLISTPROXYSTYLE_H
 #include <QProxyStyle>
 #include <QtGui>
 
+//! Custom proxy style that draw checkboxes as stars.
+//! It will automatically wrap setted style and change only
+//! checkboxes drawing.
 class WordListProxyStyle : public QProxyStyle
 {
 public:
     WordListProxyStyle();
+    //! Reimplemented drawPrimitive method which only draw different
+    //! PE_IndicatorCheckBox elements
+    //! \sa QProxyStyle::drawPrimitive()
     void drawPrimitive(PrimitiveElement element,
                        const QStyleOption *option,
                        QPainter *painter,
index 60cf791..f44af27 100644 (file)
 WordListWidget::WordListWidget(QWidget *parent):
     QTreeView(parent) {
 
+    //creating new model to store words and stars
     model = new QStandardItemModel(this);
     setModel(model);
     setHeaderHidden(true);
     setRootIsDecorated(false);
     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
+    //set our custom style to draw checkboxes as stars
     setStyle(new WordListProxyStyle);
 
+    //setting size of star in pixels, on maemo checboxes are much bigger
     #ifdef Q_WS_MAEMO_5
         checkBoxWidth = 70;
     #else
@@ -53,11 +56,18 @@ WordListWidget::WordListWidget(QWidget *parent):
 
 void WordListWidget::addWord(QString word, int row) {
     QStandardItem* item = new QStandardItem(word);
+
+    //we don't want to allow user to edit word
     item->setFlags(item->flags() ^ Qt::ItemIsEditable);
+
     QStandardItem* itemCheckBox = new QStandardItem();
+    //creating checkbox item
     itemCheckBox->setFlags(itemCheckBox->flags() ^ Qt::ItemIsEditable |
                            Qt::ItemIsUserCheckable);
 
+    /*checking if word is already in bookmarks, information about that is
+    stored in it's translation object (not all translation have to be in
+    bookmarks)*/
     bool bookmark = false;
     Translation* t;
     foreach(t, searchResult[word]) {
@@ -72,6 +82,7 @@ void WordListWidget::addWord(QString word, int row) {
     else
         itemCheckBox->setCheckState(Qt::Unchecked);
 
+    //add item to model
     model->setItem(row,0, item);
     model->setItem(row,1, itemCheckBox);
 }
@@ -79,6 +90,7 @@ void WordListWidget::addWord(QString word, int row) {
 
 void WordListWidget::showSearchResults(
         QHash<QString, QList<Translation *> > result) {
+
     model->clear();
     searchResult.clear();
 
@@ -97,20 +109,28 @@ void WordListWidget::showSearchResults(
 }
 
 void WordListWidget::wordClicked(QModelIndex index) {
+    //we're getting translation based on data in index
     emit showTranslation(
             searchResult[index.data().toString()]);
 }
 
 void WordListWidget::wordChecked(QModelIndex index) {
+
+    //save new item state
     Qt::CheckState state =
             Qt::CheckState(index.data(Qt::CheckStateRole).toInt());
 
-    if(selectedIndexes().count()==0) return;
+
+
+    //getting index of item which contains word which should be added/removed
+    //from bookmarks
     QModelIndex item = selectedIndexes().at(0);
     if(!item.isValid()) return;
 
+    //to shorten lag between clicking on star and it's change
     repaint();
 
+    //depending on new state emit suitable signal
     if(state == Qt::Checked) {
         emit addBookmark(searchResult[item.data().toString()]);
     }
@@ -121,20 +141,29 @@ void WordListWidget::wordChecked(QModelIndex index) {
 
 
 void WordListWidget::mouseReleaseEvent(QMouseEvent *event) {
-    QTreeView::mouseReleaseEvent(event);
 
+    //firstly we normally handle this event
+    QTreeView::mouseReleaseEvent(event);
 
+    //then we checking at which item user clicked
     QModelIndex index = indexAt(event->pos());
     if(!index.isValid()) return;
+
+    /*if there are no selected items we return, that occurs sometimes
+    on maemo, when user is scrolling list and click to stop the scroll,
+    system don't select item but emitting mouseReleaseEvent*/
     if(selectedIndexes().count() == 0) return;
 
+    //if user don't click on word either on star return
     if(selectedIndexes().at(0) != index && selectedIndexes().at(1) != index)
         return;
 
     int c = index.column();
     if(c==0)
+        //if column is 0 user clicked word
         wordClicked(index);
     else
+        //else user clicked star
         wordChecked(index);
 }
 
index 7ad634d..9dc011f 100644 (file)
 
 //! Displays list of words found in dictionaries
 /*!
-    It allow user to select word to see it's translation or to mark it as "star"
+    It allow user to select word to see it's translation or to mark or unmark
+    it as "star" (add/remove from bookmarks). It inherit from QTreeView
+    to allow display two columns, one with words and second with stars.
+    Star is normal checkable item. To get effect of star we need to set
+    style (WordListProxyStyle) for this widget.
   */
 class WordListWidget : public QTreeView {
     Q_OBJECT
@@ -68,19 +72,35 @@ public Q_SLOTS:
     void unlockList();
 
 protected:
+    //! Reimplemented standard mouseReleaseEvent to check if user clicked on
+    //! word on it's star to emit suitable signal
     void mouseReleaseEvent(QMouseEvent *event);
+
+    //! Resize the size of columns to assure that stars are always on right
+    //! side next to scroll bar
     void resizeEvent(QResizeEvent *event);
 
 private Q_SLOTS:
+    //! Emits signal to show translation of clicked item. Signal is emitted
+    //! only when word was clicked.
     void wordClicked(QModelIndex index);
+
+    //! Emits signal to show add or remove word from bookmarks.
+    //! Signal is emitted only when star was clicked.
     void wordChecked(QModelIndex index);
 
 private:
+    //! Adds word to model. Row is row in the model
     void addWord(QString word, int row);
+
     QStandardItemModel* model;
+    //! Describes width of star checkbox in pixels
     int checkBoxWidth;
+
+    //! Resizes sizes of colums after adding new words or after resize event.
     void resizeColumns();
 
+    //! Association between words and their's translations
     QHash<QString, QList<Translation*> > searchResult;
 };