1 /*******************************************************************************
3 This file is part of mDictionary.
5 mDictionary is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 mDictionary is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
22 //Created by Mateusz Półrola
24 #include "../../includes/History.h"
27 History::History(QObject *parent) :
32 _prevAvailable = false;
33 _nextAvailable = false;
34 _listAvailable = false;
38 void History::add(QString word) {
39 if(currentElement != -1) {
40 //we search the same word so we don't add it again
41 if(_history[currentElement] == word)
45 //if we are not in head, we deleted everything ahed us
46 if(currentElement > 0) {
47 _history.remove(0, currentElement);
51 if(_history.contains(word)) {
52 _history.remove(_history.indexOf(word));
55 //add new word to head
56 _history.push_front(word);
59 while(_history.size() > _maxSize) {
65 if(_history.size() > 1) {
66 _prevAvailable = true;
67 _nextAvailable = false;
68 _listAvailable = true;
71 _prevAvailable = false;
72 _nextAvailable = false;
73 _listAvailable = true;
76 emit historyChanged(_prevAvailable,
81 QString History::previous() {
85 _nextAvailable = true;
87 if(currentElement+1 == _history.size()) {
88 _prevAvailable = false;
91 emit historyChanged(_prevAvailable,
95 return _history[currentElement];
100 QString History::next() {
104 _prevAvailable = true;
106 if(currentElement == 0) {
107 _nextAvailable = false;
110 emit historyChanged(_prevAvailable,
114 return _history[currentElement];
119 QStringList History::list() {
123 for(int i=0; i<_history.size(); i++) {
124 result << _history[i];
130 bool History::nextAvailable() {
131 return _nextAvailable;
134 bool History::prevAvailable() {
135 return _prevAvailable;
138 bool History::listAvailable() {
139 return _listAvailable;
142 void History::setCurrentElement(int element) {
143 if(element < 0 || element >= _history.size()) return;
145 currentElement = element;
147 if(currentElement > 0) {
148 _nextAvailable = true;
151 _nextAvailable = false;
154 if(currentElement+1 < _history.size()) {
155 _prevAvailable = true;
158 _prevAvailable = false;
161 emit historyChanged(_prevAvailable,