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)
{
*******************************************************************************/
-//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
*******************************************************************************/
-//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"
GUIInterface(parent),
ui(new Ui::MainWindow) {
- #ifdef Q_WS_MAEMO_5
- setAttribute(Qt::WA_Maemo5StackedWindow);
- #endif
-
this->backbone = backbone;
initializeUI();
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;
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);
aboutWidget->hide();
+ //creating menus
#ifdef Q_WS_MAEMO_5
menuWidget = new MenuWidget(this);
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
}
else {
#ifndef Q_WS_MAEMO_5
+ //on desktop we show word list in exact search
emit showWordList(searchResult);
#endif
bool foundExactMatch = false;
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());
s->insertWidget(1,translationWidget);
s->setStretchFactor(1, 150);
welcomeScreenWidget->deleteLater();
- qDebug()<<"changed";
}
#endif
}
-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()));
*/
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*);
void breakSearching();
- void showAllBookmarks();
-
-
protected:
/*! When user wants to close application, we first sends signal to stop all
ongoing searches.
void removeSubMenu(QString title);
public Q_SLOTS:
+ /*!
+ Hides menu
+ */
void hideMenu();
protected:
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));
verticalLayout->addWidget(searchInBookmarksCheckBox);
-
#ifndef Q_WS_MAEMO_5
setMinimumWidth(250);
setMaximumWidth(250);
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)) {
*******************************************************************************/
-//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:
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
#include <QScrollArea>
#include <QtGui>
+//! Displays wlecome screen with logo and name of application
class WelcomeScreenWidget : public QScrollArea
{
Q_OBJECT
WordListProxyStyle::WordListProxyStyle() :
QProxyStyle()
{
+ //load pixmap from resources
starPixmapOn = QPixmap(":/icons/staron.png");
starPixmapOff = QPixmap(":/icons/staroff.png");
}
/*******************************************************************************
+
This file is part of mDictionary.
mDictionary is free software: you can redistribute it and/or modify
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,
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
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]) {
else
itemCheckBox->setCheckState(Qt::Unchecked);
+ //add item to model
model->setItem(row,0, item);
model->setItem(row,1, itemCheckBox);
}
void WordListWidget::showSearchResults(
QHash<QString, QList<Translation *> > result) {
+
model->clear();
searchResult.clear();
}
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()]);
}
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);
}
//! 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
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;
};