void Bookmarks::add(Translation* translation) {
+ qDebug()<<"added";
QSqlQuery cur(db);
cur.prepare("insert into bookmarks values (?,?)");
cur.addBindValue(translation->key());
gui/DictTypeSelectDialog.cpp \
backbone/History.cpp \
gui/HistoryListDialog.cpp \
+ gui/WordListProxyStyle.cpp \
backbone/Bookmarks.cpp
HEADERS += gui/MainWindow.h \
../includes/History.h \
gui/HistoryListDialog.h \
../includes/GUIInterface.h \
+ gui/WordListProxyStyle.h \
backbone/Bookmarks.h \
backbone/BookmarkTranslations.h
target.path =$$BINDIR
+maemo5 {
desktop.path = $$DATADIR/applications/hildon
- desktop.files += ../../../data/other/$${TARGET}.desktop
-
icon64.path = $$DATADIR/icons/hicolor/64x64/hildon
+}
+
+!maemo5 {
+ desktop.path = $$DATADIR/applications
+ icon64.path = $$DATADIR/icons
+}
+ desktop.files += ../../../data/other/$${TARGET}.desktop
icon64.files += ../../../data/icons/64x64/$${TARGET}.png
}
+
+RESOURCES += \
+ gui/gui.qrc
#include "../../includes/DictDialog.h"
DictManagerWidget::DictManagerWidget(GUIInterface *parent) :
- QWidget(parent) {
+ QDialog(parent) {
+
- this->guiInterface = parent;
+ setWindowTitle(tr("Dictionaries"));
+ this->guiInterface = parent;
verticalLayout = new QVBoxLayout;
setLayout(verticalLayout);
change settings of selected dict. All changes are saved automatically after
hiding of this widget.
*/
-class DictManagerWidget : public QWidget {
+class DictManagerWidget : public QDialog {
Q_OBJECT
public:
//! Constructor
setExactSearch(false);
setWindowTitle("mDictionary");
+
+ showMaximized();
}
MainWindow::~MainWindow() {
searchBarWidget = new SearchBarWidget;
+
wordListWidget = new WordListWidget;
//translationWidget is antoher stacked window, so we don't add it to layout
//only create it with this widget as parent
translationWidget = new TranslationWidget(this);
- ui->centralWidget->layout()->addWidget(wordListWidget);
+ #ifdef Q_WS_MAEMO_5
+ ui->centralWidget->layout()->addWidget(wordListWidget);
+ #else
+ splitter = new QSplitter(Qt::Horizontal);
+ splitter->addWidget(wordListWidget);
+ splitter->addWidget(translationWidget);
+ splitter->setStretchFactor(1, 150);
+ ui->centralWidget->layout()->addWidget(splitter);
+ #endif
ui->centralWidget->layout()->addWidget(searchBarWidget);
dictManagerWidget = new DictManagerWidget(this);
+ dictManagerWidget->hide();
+ #ifdef Q_WS_MAEMO_5
+ menuWidget = new MenuWidget(this);
+ 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()));
+ #endif
- menuWidget = new MenuWidget(this);
- menuWidget->addSubMenu(tr("Dictionaries"), dictManagerWidget);
- menuWidget->addSubMenu(tr("Settings"), new QPushButton("Settings"));
- menuWidget->addSubMenu(tr("About"), new QPushButton("About"));
-
- ui->menuBar->addAction(menuWidget);
}
void MainWindow::closeEvent(QCloseEvent *event) {
}
void MainWindow::disableMenu() {
- if(ui->menuBar->actions().contains(menuWidget)) {
- ui->menuBar->removeAction(menuWidget);
- }
+ #ifdef Q_WS_MAEMO_5
+ if(ui->menuBar->actions().contains(menuWidget)) {
+ ui->menuBar->removeAction(menuWidget);
+ }
+ #else
+ ui->menuBar->setEnabled(false);
+ #endif
}
void MainWindow::enableMenu() {
- if(!ui->menuBar->actions().contains(menuWidget)) {
- ui->menuBar->addAction(menuWidget);
- }
+ #ifdef Q_WS_MAEMO_5
+ if(!ui->menuBar->actions().contains(menuWidget)) {
+ ui->menuBar->addAction(menuWidget);
+ }
+ #else
+ ui->menuBar->setEnabled(true);
+ #endif
}
void MainWindow::showHistory() {
connect(wordListWidget, SIGNAL(showTranslation(QList<Translation*>)),
this, SIGNAL(searchTranslations(QList<Translation*>)));
- //TODO TEMP
- connect(wordListWidget, SIGNAL(showTranslation(QList<Translation*>)),
- backbone, SLOT(addBookmark(QList<Translation*>)));
connect(this, SIGNAL(setIdle()),
wordListWidget, SLOT(unlockList()));
+
+ connect(wordListWidget, SIGNAL(addBookmark(QList<Translation*>)),
+ backbone, SLOT(addBookmark(QList<Translation*>)));
+
+ connect(wordListWidget, SIGNAL(removeBookmark(QList<Translation*>)),
+ backbone, SLOT(removeBookmark(QList<Translation*>)));
}
void MainWindow::connectTranslationWidget() {
MenuWidget* menuWidget;
DictManagerWidget* dictManagerWidget;
+ #ifndef Q_WS_MAEMO_5
+ QSplitter* splitter;
+ QAction* dictionariesAction;
+ //QAction* edit;
+ // QAction* settingsAction;
+ //QAction* aboutAction;
+ #endif
+
bool _exactSearch;
QString searchString;
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
- <property name="palette">
- <palette>
- <active>
- <colorrole role="Base">
- <brush brushstyle="SolidPattern">
- <color alpha="255">
- <red>255</red>
- <green>255</green>
- <blue>255</blue>
- </color>
- </brush>
- </colorrole>
- <colorrole role="Window">
- <brush brushstyle="SolidPattern">
- <color alpha="255">
- <red>0</red>
- <green>0</green>
- <blue>0</blue>
- </color>
- </brush>
- </colorrole>
- </active>
- <inactive>
- <colorrole role="Base">
- <brush brushstyle="SolidPattern">
- <color alpha="255">
- <red>255</red>
- <green>255</green>
- <blue>255</blue>
- </color>
- </brush>
- </colorrole>
- <colorrole role="Window">
- <brush brushstyle="SolidPattern">
- <color alpha="255">
- <red>0</red>
- <green>0</green>
- <blue>0</blue>
- </color>
- </brush>
- </colorrole>
- </inactive>
- <disabled>
- <colorrole role="Base">
- <brush brushstyle="SolidPattern">
- <color alpha="255">
- <red>0</red>
- <green>0</green>
- <blue>0</blue>
- </color>
- </brush>
- </colorrole>
- <colorrole role="Window">
- <brush brushstyle="SolidPattern">
- <color alpha="255">
- <red>0</red>
- <green>0</green>
- <blue>0</blue>
- </color>
- </brush>
- </colorrole>
- </disabled>
- </palette>
- </property>
<property name="autoFillBackground">
- <bool>true</bool>
+ <bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout"/>
</widget>
</rect>
</property>
</widget>
- <widget class="QToolBar" name="mainToolBar">
- <attribute name="toolBarArea">
- <enum>TopToolBarArea</enum>
- </attribute>
- <attribute name="toolBarBreak">
- <bool>false</bool>
- </attribute>
- </widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
initializeUI();
- setMaximumHeight(150);
_isSearching = false;
void SearchBarWidget::initializeUI() {
+
+ #ifdef Q_WS_MAEMO_5
+ setMaximumHeight(150);
+ #else
+ setMaximumHeight(100);
+ #endif
+
+
horizontalLayout = new QHBoxLayout();
verticalLayout = new QVBoxLayout();
#endif
-
//create layout for lineEdit to have clear button on it
QHBoxLayout* lineEditLayout = new QHBoxLayout;
searchWordLineEdit->setLayout(lineEditLayout);
clearSearchWordToolButton = new QToolButton();
-
#ifdef Q_WS_MAEMO_5
clearSearchWordToolButton->setIcon(QIcon::fromTheme("general_stop"));
//tool buttons will have size 2 times smaller
clearSearchWordToolButton->sizeHint().height()*2);
#endif
+
+
historyPrevToolButton = new QToolButton();
#ifdef Q_WS_MAEMO_5
historyPrevToolButton->setIcon(
clearSearchWordToolButton->sizeHint().height()*2);
#endif
+
+
historyShowToolButton = new QToolButton();
#ifdef Q_WS_MAEMO_5
historyShowToolButton->setIcon(
searchingProgressBar->setMinimum(0);
searchingProgressBar->setMaximum(0);
searchingProgressBar->hide();
- searchingProgressBar->setMaximumHeight(50);
+ #ifdef Q_WS_MAEMO_5
+ searchingProgressBar->setMaximumHeight(50);
+ #endif
setLayout(verticalLayout);
--- /dev/null
+/*******************************************************************************
+
+ 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 "WordListProxyStyle.h"
+
+
+WordListProxyStyle::WordListProxyStyle() :
+ QProxyStyle()
+{
+ starPixmapOn = QPixmap(":/icons/staron.png");
+ starPixmapOff = QPixmap(":/icons/staroff.png");
+}
+
+
+void WordListProxyStyle::drawPrimitive(PrimitiveElement element,
+ const QStyleOption *option,
+ QPainter *painter,
+ const QWidget *widget) const {
+ if(element == PE_IndicatorCheckBox) {
+ if(option->state & QStyle::State_On)
+ painter->drawPixmap(option->rect, starPixmapOn);
+ else
+ painter->drawPixmap(option->rect, starPixmapOff);
+ }
+ else {
+ QProxyStyle::drawPrimitive(element, option, painter, widget);
+ }
+}
+
+
--- /dev/null
+/*******************************************************************************
+
+ 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 WORDLISTPROXYSTYLE_H
+#define WORDLISTPROXYSTYLE_H
+
+#include <QProxyStyle>
+#include <QtGui>
+
+class WordListProxyStyle : public QProxyStyle
+{
+public:
+ WordListProxyStyle();
+ void drawPrimitive(PrimitiveElement element,
+ const QStyleOption *option,
+ QPainter *painter,
+ const QWidget *widget) const;
+
+private:
+ QPixmap starPixmapOn;
+ QPixmap starPixmapOff;
+};
+
+#endif // WORDLISTPROXYSTYLE_H
#include <QDebug>
#include "../../includes/translation.h"
#include <QMultiHash>
+#include "WordListProxyStyle.h"
+
#ifdef Q_WS_MAEMO_5
#include <QMaemo5InformationBox>
#endif
WordListWidget::WordListWidget(QWidget *parent):
- QListView(parent) {
-
- wordListModel = new QStringListModel();
+ QListWidget(parent) {
+ connect(this, SIGNAL(itemPressed(QListWidgetItem*)),
+ this, SLOT(wordPressed(QListWidgetItem*)));
- connect(this, SIGNAL(clicked(QModelIndex)),
- this, SLOT(itemClicked(QModelIndex)));
- setModel(wordListModel);
-}
+ connect(this, SIGNAL(itemClicked(QListWidgetItem*)),
+ this, SLOT(wordClicked(QListWidgetItem*)));
-void WordListWidget::addWord(QString word) {
- int wordsCount = wordListModel->rowCount();
- wordListModel->insertRow(wordsCount);
+ setStyle(new WordListProxyStyle);
- QModelIndex newWordIndex = wordListModel->index(wordsCount);
+ setLayoutDirection(Qt::RightToLeft);
- wordListModel->setData(newWordIndex, word);
}
-void WordListWidget::clear() {
- int wordsCount = wordListModel->rowCount();
-
- for(int i = 0; i < wordsCount; i++) {
- wordListModel->removeRow(0);
- }
+void WordListWidget::addWord(QString word) {
+ QListWidgetItem* item = new QListWidgetItem(word, this);
+ item->setCheckState(Qt::Unchecked);
+ item->setTextAlignment(Qt::AlignRight);
}
+
void WordListWidget::showSearchResults(
- QHash<QString, QList<Translation *> > result) {
+ QHash<QString, QList<Translation *> > result) {
clear();
searchResult.clear();
for(i = result.begin(); i != result.end(); i++) {
addWord(i.key());
}
+}
- wordListModel->sort(0, Qt::AscendingOrder);
-
- scrollTo(model()->index(0,0));
-
+void WordListWidget::wordClicked(QListWidgetItem *item) {
+ if(itemState == item->checkState()) {
+ emit showTranslation(
+ searchResult[item->data(Qt::DisplayRole).toString()]);
+ }
+ else {
+ if(item->checkState() == Qt::Checked) {
+ emit addBookmark(
+ searchResult[item->data(Qt::DisplayRole).toString()]);
+ }
+ else {
+ emit removeBookmark(
+ searchResult[item->data(Qt::DisplayRole).toString()]);
+ }
+ }
}
-void WordListWidget::itemClicked(QModelIndex index) {
- emit showTranslation(searchResult[index.model()->data(index).toString()]);
+void WordListWidget::wordPressed(QListWidgetItem *item) {
+ itemState = item->checkState();
}
+
void WordListWidget::lockList() {
setEnabled(false);
}
/*!
It allow user to select word to see it's translation or to mark it as "star"
*/
-class WordListWidget : public QListView {
+class WordListWidget : public QListWidget {
Q_OBJECT
public:
explicit WordListWidget(QWidget *parent = 0);
//! objects
void showTranslation(QList<Translation*>);
+ void addBookmark(QList<Translation*>);
+
+ void removeBookmark(QList<Translation*>);
+
public Q_SLOTS:
//! Shows search results
//! Unlocks words list
void unlockList();
-
private Q_SLOTS:
- void itemClicked(QModelIndex index);
+ void wordClicked(QListWidgetItem* item);
+ void wordPressed(QListWidgetItem* item);
private:
- //Backbone *backbone;
- //words are keeping as QStringListModel which allow to sort them
- QStringListModel *wordListModel;
void addWord(QString word);
- //clears all list of words
- void clear();
+
+ Qt::CheckState itemState;
QHash<QString, QList<Translation*> > searchResult;
- //QString _exactMatchString;
};
#endif // WORDLISTWIDGET_H
--- /dev/null
+<RCC>
+ <qresource prefix="/icons">
+ <file>staroff.png</file>
+ <file>staron.png</file>
+ </qresource>
+</RCC>
/*! \param list of only active dictionaries
*/
void selectedDictionaries(QList<CommonDictInterface* >);
+
+ void addToBookmarks(QList<Translation*>);
};
#endif // GUIINTERFACE_H
cancelButton = new QPushButton(tr("Cancel"));
+ cachingLabel = new QLabel();
+ cachingLabel->hide();
+
+
+ verticalLayout->addWidget(cachingLabel);
verticalLayout->addWidget(cachingProgressBar);
verticalLayout->addWidget(cancelButton);
void XdxfCachingDialog::updateCachingProgress(int progress, int time) {
cachingProgressBar->setValue(progress);
+ if(!cachingLabel->isVisible())
+ cachingLabel->show();
int seconds = float((100 - progress)*time) / (5*1000);
- setWindowTitle(tr("Caching dictionary, please wait ") + "( " +
- QString::number(seconds) + tr(" seconds left") + " )");
+ cachingLabel->setText(tr("Estimated time left: ") +
+ QString::number(seconds) + tr(" seconds"));
}
QXmlStreamReader reader(&dictionaryFile);
-
db.setDatabaseName(cachePathN);
if(!db.open()) {
- qDebug() << "Database error" << endl;
+ qDebug() << "Database error" << db.lastError().text() << endl;
return false;
}
QCoreApplication::processEvents();
while (!reader.atEnd() && !stopped) {
QCoreApplication::processEvents();
- // usleep(50);
reader.readNext();
if(reader.tokenType() == QXmlStreamReader::StartElement) {
#
#-------------------------------------------------
-QT += testlib core
+QT += testlib core sql
TARGET = mDictionaryTests
SOURCES += tst_Backbone.cpp \
../../src/base/backbone/backbone.cpp \
- ../../src/base/backbone/History.cpp
+ ../../src/base/backbone/History.cpp \
+ ../../src/base/backbone/Bookmarks.cpp
DEFINES += SRCDIR=\\\"$$PWD/\\\"
HEADERS += \
../../src/includes/settings.h \
../../src/includes/CommonDictInterface.h \
../../src/includes/History.h \
- TranslationMock.h
+ TranslationMock.h \
+ ../../src/base/backbone/BookmarkTranslations.h \
+ ../../src/base/backbone/Bookmarks.h
check.target = check
check.commands += ./mDictionaryTests
QMAKE_EXTRA_TARGETS += check
-
check.target = check
check.CONFIG = recursive
-check.recurse = tests src
+check.recurse = src
QMAKE_EXTRA_TARGETS += check