-void Backbone::search(QStringList words) {
+void Backbone::search(QString word) {
_timerSearch.stop();
_result.clear();
_innerResult.clear();
_timerSearch.start(_interval);
- foreach(QString word, words)
- foreach(CommonDictInterface* dict, _dicts.keys())
- if(_dicts[dict] == 1) {
- QFuture<QList<Translation*> > tr =
- QtConcurrent::run(dict,
- &CommonDictInterface::searchWordList,word,
- searchLimit());
- _innerResult.append(tr);
- }
+
+ foreach(CommonDictInterface* dict, _dicts.keys())
+ if(_dicts[dict] == 1) {
+ QFuture<QList<Translation*> > tr =
+ QtConcurrent::run(dict,
+ &CommonDictInterface::searchWordList,word,
+ searchLimit());
+ _innerResult.append(tr);
+ }
}
void stopSearching();
/*! search for a word translation
- \param word list of words to be translated
+ \param word to be translated
*/
- void search(QStringList word);
+ void search(QString word);
/*! sets active dictionaries (searches are performed only in active dicts
\param List of dictionaris to be activated
#
#-------------------------------------------------
-QT += core gui
+QT += core gui
+
+maemo5 {
+ QT += maemo5
+}
TARGET = mdictionary
TEMPLATE = app
while(i.hasNext()) {
i.next();
- qDebug()<<i.key();
QListWidgetItem* item = new QListWidgetItem;
QString name = i.key()->langFrom() + " - " + i.key()->langTo() + " (" +
i.key()->type() + " " + i.key()->name() + ")";
CommonDictInterface* selectedPlugin =
DictTypeSelectDialog::addNewDict(backbone->getPlugins(),this);
if(selectedPlugin != NULL) {
- qDebug()<< selectedPlugin->type();
Settings* settings =
selectedPlugin->dictDialog()->addNewDictionary(this);
wordListWidget = new WordListWidget(backbone);
translationWidget = new TranslationWidget(backbone, this);
- searchBarWidget->setFocus();
menuWidget = new MenuWidget(this);
-
-
menuWidget->addSubMenu(tr("Dictionaries"),
new DictManagerWidget(backbone, this));
menuWidget->addSubMenu(tr("Settings"), new QPushButton("Settings"));
ui->menuBar->addAction(menuWidget);
- connect(this, SIGNAL(searchWordList(QStringList)),
- searchBarWidget, SLOT(searchWordList(QStringList)));
+ connect(this, SIGNAL(search(QString)),
+ searchBarWidget, SLOT(search(QString)));
- connect(searchBarWidget, SIGNAL(searchForTranslations(QStringList)),
+ connect(searchBarWidget, SIGNAL(searchForTranslations(QString)),
wordListWidget, SLOT(lockList()));
connect(searchBarWidget, SIGNAL(stopSearching()),
close();*/
}
-void MainWindow::search(QStringList words) {
- emit searchWordList(words);
+void MainWindow::searchExactWord(QString word) {
+ wordListWidget->setExactMatchString(word);
+ emit search(word);
}
void MainWindow::enableMenu(bool enabled) {
ui->menuBar->setVisible(enabled);
- qDebug()<<enabled;
}
public:
explicit MainWindow(Backbone* backbone, QWidget *parent = 0);
~MainWindow();
- void search(QStringList);
+ void searchExactWord(QString);
public Q_SLOTS:
Q_SIGNALS:
//! Request to backbone to stop all it's activities
void quit();
- void searchWordList(QStringList);
+ void search(QString);
protected:
/*! When user wants to close application, we first sends signal to stop all
//connects request to backbone
- connect(this, SIGNAL(searchForTranslations(QStringList)),
- backbone, SLOT(search(QStringList)));
+ connect(this, SIGNAL(searchForTranslations(QString)),
+ backbone, SLOT(search(QString)));
connect(this, SIGNAL(stopSearching()),
backbone, SLOT(stopSearching()));
}
+QIcon SearchBarWidget::generateIcon(QIcon oryginal, qreal rotation) {
+ QPixmap p = oryginal.pixmap(64);
+
+ QIcon newIcon;
+ newIcon.addPixmap(p);
+
+ QPainter painter(&p);
+ painter.fillRect(p.rect(), QColor(0,0,0,192));
+
+ newIcon.addPixmap(p, QIcon::Disabled, QIcon::Off);
+
+ return newIcon;
+}
+
void SearchBarWidget::initializeUI() {
horizontalLayout = new QHBoxLayout();
historyNextToolButton = new QToolButton();
- historyNextToolButton->setIcon(QIcon::fromTheme("general_forward"));
+ historyNextToolButton->setIcon(
+ generateIcon(QIcon::fromTheme("general_forward")));
historyPrevToolButton = new QToolButton();
- historyPrevToolButton->setIcon(QIcon::fromTheme("general_back"));
+ historyPrevToolButton->setIcon(
+ generateIcon(QIcon::fromTheme("general_back")));
historyShowToolButton = new QToolButton();
- historyShowToolButton->setIcon(QIcon::fromTheme("general_back"));
+ historyShowToolButton->setIcon(
+ generateIcon(QIcon::fromTheme("general_back")));
+
QPixmap p = historyShowToolButton->icon().pixmap(256);
+ qDebug()<<p.size();
QMatrix m;
m.rotate(90);
+ QPixmap p2 = p.transformed(m);
+ qDebug()<<p2.size();
+
- QIcon temp;
- temp.addPixmap(p.transformed(m));
+ QIcon temp(p2);
historyShowToolButton->setIcon(temp);
emit stopSearching();
}
else {
- if(searchWordLineEdit->text().isEmpty()) return;
- setBusy();
- QStringList searchWord;
- searchWord << searchWordLineEdit->text();
- emit searchForTranslations(searchWord);
+ search(searchWordLineEdit->text());
}
}
-void SearchBarWidget::searchWordList(QStringList words) {
- if(!_isSearching) {
+
+void SearchBarWidget::search(QString word) {
+ if(!_isSearching && !word.isEmpty()) {
+ searchWordLineEdit->setText(word);
setBusy();
- emit searchForTranslations(words);
+ emit searchForTranslations(word);
}
}
Q_SIGNALS:
//! Requests to search for translation of word passed as parameter
- void searchForTranslations(QStringList);
+ void searchForTranslations(QString);
//! Request to stop all active searchings
void stopSearching();
*/
void setEnabled(bool);
- //! Search for all words in list
- /*!
- Used only when program starts with parameters.
- Perform search of all words in list.
- */
- void searchWordList(QStringList words);
//! Sets search bar in busy state
/*!
void setIdle();
+ //! Search for given word
+ void search(QString word);
+
private Q_SLOTS:
void clearSearchWordToolButtonClicked();
void searchPushButtonClicked();
void historyNextToolButtonClicked();
void historyShowToolButtonClicked();
+
private:
Backbone* backbone;
QLineEdit* searchWordLineEdit;
QHBoxLayout* horizontalLayout;
QProgressBar* searchingProgressBar;
+ QIcon generateIcon(QIcon oryginal, qreal rotation=0);
+
QVBoxLayout* verticalLayout;
bool _isSearching;
update(this->rect());
+ emit updateSize();
}
void TranslationWidget::initializeUI() {
+ zoomInToolButton = new QToolButton;
+ zoomInToolButton->setIcon(QIcon::fromTheme("pdf_zoomin"));
+
+ zoomOutToolButton = new QToolButton;
+ zoomOutToolButton->setIcon(QIcon::fromTheme("pdf_zoomout"));
+
+ horizontalLayout = new QHBoxLayout;
+ horizontalLayout->addWidget(zoomInToolButton);
+ horizontalLayout->addWidget(zoomOutToolButton);
+
textEdit = new QTextEdit;
textEdit->setReadOnly(true);
- new TranslationWidgetAutoResizer(textEdit);
+ resizer = new TranslationWidgetAutoResizer(textEdit);
+ connect(this, SIGNAL(updateSize()),
+ resizer, SLOT(textEditChanged()));
QWidget*w = new QWidget;
verticalLayout = new QVBoxLayout(w);
+ verticalLayout->addLayout(horizontalLayout);
verticalLayout->addWidget(textEdit);
this->setWidget(w);
this->setWidgetResizable(true);
+ connect(zoomInToolButton, SIGNAL(clicked()),
+ textEdit, SLOT(zoomIn()));
+
+ connect(zoomInToolButton, SIGNAL(clicked()),
+ this, SIGNAL(updateSize()));
+
+ connect(zoomOutToolButton, SIGNAL(clicked()),
+ textEdit, SLOT(zoomOut()));
+
+ connect(zoomInToolButton, SIGNAL(clicked()),
+ this, SIGNAL(updateSize()));
+
}
void TranslationWidget::showContextMenu(QPoint pos) {
#include <QModelIndex>
#include <QtGui>
#include "../backbone/backbone.h"
+#include "TranslationWidgetAutoResizer.h"
//! Displays translation of word found in dictionaries
/*!
explicit TranslationWidget(Backbone* backbone, QWidget *parent = 0);
Q_SIGNALS:
+ void updateSize();
public Q_SLOTS:
//! Request to show translation widget.
Backbone *backbone;
QMenu *contextMenu;
QTextEdit *textEdit;
+ QToolButton* zoomInToolButton;
+ QToolButton* zoomOutToolButton;
QVBoxLayout *verticalLayout;
+ QHBoxLayout* horizontalLayout;
+ TranslationWidgetAutoResizer* resizer;
+
void initializeUI();
this, SLOT(textEditChanged()));
}
-private Q_SLOTS:
+public Q_SLOTS:
inline void textEditChanged();
private:
edit->setMinimumHeight(qMax(70, s.height() + (fr.height() - cr.height()) -
1));
+
+ edit->setMinimumHeight(qMax(70, s.height() + (fr.height() - cr.height()) -
+ 1));
}
#endif // TRANSLATIONWIDGETAUTORESIZER_H
#include "../../includes/translation.h"
#include <QMultiHash>
+#ifdef Q_WS_MAEMO_5
+ #include <QMaemo5InformationBox>
+#endif
WordListWidget::WordListWidget(Backbone *backbone, QWidget *parent):
QListView(parent) {
this->backbone = backbone;
+ _exactMatchString = QString();
+
wordListModel = new QStringListModel();
connect(backbone, SIGNAL(ready()),
searchResult.clear();
QMultiHash<QString, Translation*> result = backbone->result();
- QMultiHash<QString, Translation*>::iterator i;
- for(i = result.begin(); i != result.end(); i++) {
- if(!searchResult.contains(i.key())) {
- addWord(i.key());
- }
- searchResult[i.key()].push_back(i.value());
+ if(result.count() == 0) {
+ #ifdef Q_WS_MAEMO_5
+ QMaemo5InformationBox::information(this,
+ tr("Can't find any matching words"),
+ QMaemo5InformationBox::DefaultTimeout);
+ #endif
}
+ else
+ {
+ QMultiHash<QString, Translation*>::iterator i;
+ for(i = result.begin(); i != result.end(); i++) {
+
+ if(!searchResult.contains(i.key())) {
+ addWord(i.key());
+ }
- wordListModel->sort(0, Qt::AscendingOrder);
+ searchResult[i.key()].push_back(i.value());
+ }
- scrollTo(model()->index(0,0));
+ bool foundExactMatch = false;
+
+ if(!_exactMatchString.isEmpty()) {
+ QHash<QString, QList<Translation*> >::iterator j;
+ for(j = searchResult.begin(); j != searchResult.end(); j++) {
+ if(j.key() == _exactMatchString && !foundExactMatch) {
+ foundExactMatch = true;
+ clear();
+ backbone->searchHtml(j.value());
+ emit selectedWord(j.key());
+ break;
+ }
+ }
+ if(!foundExactMatch) {
+ #ifdef Q_WS_MAEMO_5
+ QMaemo5InformationBox::information(this,
+ tr("Can't find exactly matching word"),
+ QMaemo5InformationBox::DefaultTimeout);
+ #endif
+ }
+ setExactMatchString(QString());
+ }
+ wordListModel->sort(0, Qt::AscendingOrder);
+
+ scrollTo(model()->index(0,0));
+ }
unlockList();
}
void WordListWidget::unlockList() {
setEnabled(true);
}
+
+void WordListWidget::setExactMatchString(QString exactMatchString) {
+ _exactMatchString = exactMatchString;
+}
+
+QString WordListWidget::exactMatchString() {
+ return _exactMatchString;
+}
/*! Request to show search results, requested by backbone when it finished
search*/
void showSearchResults();
+
+ //! Lock words list, while backbone is doing somethig in background
void lockList();
+
+ //! Unlocks words list
void unlockList();
+ //! Sets string which exact match will be searched
+ /*!
+ When exactMatchString is not empty, widget will not display found words,
+ but when in found words is exactMatchString it will direct display it's
+ translation. When exactMatchString isn't in list widget will display
+ suitable information, and list of found words
+ */
+ void setExactMatchString(QString exactMatchString);
+ QString exactMatchString();
+
private Q_SLOTS:
void itemClicked(QModelIndex index);
//clears all list of words
void clear();
QHash<QString, QList<Translation*> > searchResult;
+ QString _exactMatchString;
};
#endif // WORDLISTWIDGET_H
for(int i=1; i<argc; i++) {
QString argument(argv[i]);
if(!wordListStarted) {
- if(argument == "-s") {
+ if(argument == "-s" || argument == "--search") {
wordListStarted = true;
}
}
w->show();
if(search.count() > 0) {
- w->search(search);
+ w->searchExactWord(search[0]);
}
return a.exec();
setPath("/usr/lib/mdictionary/dict.xdxf");
stopped = false;
-
-
- qDebug()<<removeAccents(QString::fromUtf8("Słońce"));
}
QString XdxfPlugin::langFrom() const {
QFile dictionaryFile(path);
word = removeAccents(word);
- qDebug()<<word;
stopped = false;
if(word.indexOf("*")==-1)