--- /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 "../../includes/History.h"
+#include <QDebug>
+
+History::History(QObject *parent) :
+ QObject(parent)
+{
+ _maxSize = 5;
+ currentElement = -1;
+ _prevAvailable = false;
+ _nextAvailable = false;
+ _listAvailable = false;
+}
+
+
+void History::add(QString word) {
+ if(currentElement != -1) {
+ //we search the same word so we don't add it again
+ if(_history[currentElement] == word)
+ return;
+ }
+
+ //if we are not in head, we deleted everything ahed us
+ if(currentElement > 0) {
+ _history.remove(0, currentElement);
+ }
+
+
+ if(_history.contains(word)) {
+ _history.remove(_history.indexOf(word));
+ }
+
+ //add new word to head
+ _history.push_front(word);
+
+ //fit to max size
+ while(_history.size() > _maxSize) {
+ _history.pop_back();
+ }
+
+ currentElement = 0;
+
+ if(_history.size() > 1) {
+ _prevAvailable = true;
+ _nextAvailable = false;
+ _listAvailable = true;
+ }
+ else {
+ _prevAvailable = false;
+ _nextAvailable = false;
+ _listAvailable = true;
+ }
+
+ emit historyChanged(_prevAvailable,
+ _nextAvailable,
+ _listAvailable);
+}
+
+QString History::previous() {
+ if(_prevAvailable) {
+ currentElement++;
+
+ _nextAvailable = true;
+
+ if(currentElement+1 == _history.size()) {
+ _prevAvailable = false;
+ }
+
+ emit historyChanged(_prevAvailable,
+ _nextAvailable,
+ _listAvailable);
+
+ return _history[currentElement];
+ }
+ return QString();
+}
+
+QString History::next() {
+ if(_nextAvailable) {
+ currentElement--;
+
+ _prevAvailable = true;
+
+ if(currentElement == 0) {
+ _nextAvailable = false;
+ }
+
+ emit historyChanged(_prevAvailable,
+ _nextAvailable,
+ _listAvailable);
+
+ return _history[currentElement];
+ }
+ return QString();
+}
+
+QStringList History::list() {
+ QStringList result;
+
+ if(_listAvailable) {
+ for(int i=0; i<_history.size(); i++) {
+ result << _history[i];
+ }
+ }
+ return result;
+}
+
+bool History::nextAvailable() {
+ return _nextAvailable;
+}
+
+bool History::prevAvailable() {
+ return _prevAvailable;
+}
+
+bool History::listAvailable() {
+ return _listAvailable;
+}
+
+void History::setCurrentElement(int element) {
+ if(element < 0 || element >= _history.size()) return;
+
+ currentElement = element;
+
+ if(currentElement > 0) {
+ _nextAvailable = true;
+ }
+ else {
+ _nextAvailable = false;
+ }
+
+ if(currentElement+1 < _history.size()) {
+ _prevAvailable = true;
+ }
+ else {
+ _prevAvailable = false;
+ }
+
+ emit historyChanged(_prevAvailable,
+ _nextAvailable,
+ _listAvailable);
+}
connect(&_timerSearch, SIGNAL(timeout()), this, SLOT(translationReady()));
connect(&_timerHtmlSearch, SIGNAL(timeout()), this,
SLOT(htmlTranslationReady()));
+
+
+ _history = new History(this);
}
Backbone::Backbone(QString pluginPath, QString configPath, QObject *parent)
-QList<QString> Backbone::getHistory() {
- //TODO code needed
+History* Backbone::history() {
+ return _history;
}
#include "../../includes/CommonDictInterface.h"
#include "../../includes/settings.h"
#include "../../includes/translation.h"
+#include "../../includes/History.h"
/*! Inner part of dictionary - glues together GUI and plugins
QList<CommonDictInterface*> getPlugins();
//! \return history of performed searches
- QList<QString> getHistory(); //TODO implementation needed (in future)
+ History* history();
//! \return return search fesult
QMultiHash<QString, Translation*> result();
void addInternalDictionary(CommonDictInterface*, bool);
//void writeConfig(QString key, QString value);
+ History* _history;
+
};
#endif // BACKBONE_H
gui/MenuWidget.cpp \
gui/MenuTabWidget.cpp \
gui/DictManagerWidget.cpp \
- gui/DictTypeSelectDialog.cpp
+ gui/DictTypeSelectDialog.cpp \
+ backbone/History.cpp \
+ gui/HistoryListDialog.cpp
HEADERS += gui/MainWindow.h \
gui/SearchBarWidget.h \
gui/MenuTabWidget.h \
gui/DictManagerWidget.h \
gui/DictTypeSelectDialog.h \
- gui/TranslationWidgetAutoResizer.h
+ gui/TranslationWidgetAutoResizer.h \
+ ../includes/History.h \
+ gui/HistoryListDialog.h
FORMS += gui/MainWindow.ui
--- /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 "HistoryListDialog.h"
+
+HistoryListDialog::HistoryListDialog(History *history, SearchBarWidget *parent):
+ QDialog(parent)
+{
+ this->history = history;
+ searchBar = parent;
+
+ verticalLayout = new QVBoxLayout;
+ setLayout(verticalLayout);
+
+ historyListWidget = new QListWidget;
+ verticalLayout->addWidget(historyListWidget);
+
+
+ QStringList words = history->list();
+
+ for(int i=0; i<words.count(); i++) {
+ QListWidgetItem* item = new QListWidgetItem(
+ QString::number(i+1) + ". " + words[i]);
+ historyListWidget->addItem(item);
+ }
+
+ setModal(true);
+
+ setWindowTitle(tr("History"));
+
+ setMinimumHeight(300);
+
+ connect(historyListWidget, SIGNAL(clicked(QModelIndex)),
+ this, SLOT(itemClicked(QModelIndex)));
+}
+
+
+void HistoryListDialog::itemClicked(QModelIndex index) {
+ QString selectedWord = history->list()[index.row()];
+
+ history->setCurrentElement(index.row());
+
+ searchBar->search(selectedWord);
+
+ accept();
+}
+
--- /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 HISTORYLISTDIALOG_H
+#define HISTORYLISTDIALOG_H
+
+#include <QDialog>
+#include "SearchBarWidget.h"
+#include "../../includes/History.h"
+#include <QtGui>
+
+class HistoryListDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ explicit HistoryListDialog(History* history, SearchBarWidget*parent);
+
+private Q_SLOTS:
+ void itemClicked(QModelIndex);
+private:
+ History* history;
+ SearchBarWidget* searchBar;
+
+ QListWidget* historyListWidget;
+ QVBoxLayout* verticalLayout;
+
+};
+
+#endif // HISTORYLISTDIALOG_H
#include "SearchBarWidget.h"
#include <QDebug>
#include "../../includes/DictDialog.h"
+#include "HistoryListDialog.h"
SearchBarWidget::SearchBarWidget(Backbone* backbone, QWidget *parent) :
this->backbone = backbone;
+ history = backbone->history();
+
initializeUI();
setMaximumHeight(150);
connect(backbone, SIGNAL(htmlReady()),
this, SLOT(setIdle()));
+
+ connect(history, SIGNAL(historyChanged(bool,bool,bool)),
+ this, SLOT(updateHistoryButtons(bool,bool,bool)));
+
searchWordLineEdit->setFocus();
+
+ setEnabled(true);
}
SearchBarWidget::~SearchBarWidget() {
Qt::AlignRight | Qt::AlignVCenter);
verticalLayout->addLayout(horizontalLayout);
-
}
if(!_isSearching && !word.isEmpty()) {
searchWordLineEdit->setText(word);
setBusy();
+ history->add(word);
emit searchForTranslations(word);
}
}
void SearchBarWidget::setEnabled(bool enabled) {
searchWordLineEdit->setEnabled(enabled);
- historyNextToolButton->setEnabled(enabled);
- historyPrevToolButton->setEnabled(enabled);
- historyShowToolButton->setEnabled(enabled);
+
+ if(enabled) {
+ historyNextToolButton->setEnabled(history->nextAvailable());
+ historyPrevToolButton->setEnabled(history->prevAvailable());
+ historyShowToolButton->setEnabled(history->listAvailable());
+ }
}
void SearchBarWidget::setBusy() {
}
void SearchBarWidget::historyNextToolButtonClicked() {
-
+ QString next = history->next();
+ if(!next.isEmpty()) {
+ searchWordLineEdit->setText(next);
+ }
}
void SearchBarWidget::historyPrevToolButtonClicked() {
-
+ QString prev = history->previous();
+ if(!prev.isEmpty()) {
+ searchWordLineEdit->setText(prev);
+ }
}
void SearchBarWidget::historyShowToolButtonClicked() {
-
+ HistoryListDialog listDialog(history, this);
+ listDialog.exec();
}
void SearchBarWidget::clearSearchWordToolButtonClicked() {
searchWordLineEdit->clear();
}
-void SearchBarWidget::showHistoryListDialog() {
-
-}
bool SearchBarWidget::isSearching() const {
return _isSearching;
}
+
+void SearchBarWidget::updateHistoryButtons(bool prev, bool next, bool list) {
+ if(!isSearching()) {
+ historyPrevToolButton->setEnabled(prev);
+ historyNextToolButton->setEnabled(next);
+ historyShowToolButton->setEnabled(list);
+ }
+}
#include <QWidget>
#include <QtGui>
#include "../backbone/backbone.h"
-
+#include "../../includes/History.h"
//! Displays search bar
/*!
void historyPrevToolButtonClicked();
void historyNextToolButtonClicked();
void historyShowToolButtonClicked();
+ void updateHistoryButtons(bool prev, bool next, bool list);
private:
Backbone* backbone;
+ History* history;
QLineEdit* searchWordLineEdit;
QToolButton* clearSearchWordToolButton;
QPushButton* searchPushButton;
bool _isSearching;
void initializeUI();
- void showHistoryListDialog();
};
#endif // SEARCHBARWIDGET_H
--- /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 HISTORY_H
+#define HISTORY_H
+
+#include <QObject>
+#include <QVector>
+#include <QStringList>
+
+class History : public QObject
+{
+ Q_OBJECT
+public:
+ explicit History(QObject *parent = 0);
+
+Q_SIGNALS:
+ void historyChanged(bool prevAvailable,
+ bool nextAvailable,
+ bool listAvailable);
+
+public:
+ void add(QString);
+ QString previous();
+ QString next();
+ QStringList list();
+
+ bool prevAvailable();
+ bool nextAvailable();
+ bool listAvailable();
+
+ void setCurrentElement(int element);
+
+private:
+ QVector<QString> _history;
+ int _maxSize;
+ int currentElement;
+ bool _prevAvailable;
+ bool _nextAvailable;
+ bool _listAvailable;
+};
+
+#endif // HISTORY_H