summaryrefslogtreecommitdiffstats
path: root/kviewshell/history.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit47d455dd55be855e4cc691c32f687f723d9247ee (patch)
tree52e236aaa2576bdb3840ebede26619692fed6d7d /kviewshell/history.cpp
downloadtdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.tar.gz
tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kviewshell/history.cpp')
-rw-r--r--kviewshell/history.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/kviewshell/history.cpp b/kviewshell/history.cpp
new file mode 100644
index 00000000..a8765220
--- /dev/null
+++ b/kviewshell/history.cpp
@@ -0,0 +1,91 @@
+// history.cpp
+//
+// (C) 2001 Stefan Kebekus
+// Distributed under the GPL
+
+#include <config.h>
+
+#include <kdebug.h>
+
+#include "history.h"
+
+HistoryItem::HistoryItem(Q_UINT32 p, Q_UINT32 y)
+ : page(p), ypos(y)
+{
+}
+
+bool HistoryItem::operator== (const HistoryItem& item) const
+{
+ return page == item.page && ypos == item.ypos;
+}
+
+History::History()
+{
+}
+
+void History::add(Q_UINT32 page, Q_UINT32 ypos)
+{
+ HistoryItem item(page, ypos);
+
+ if (historyList.empty())
+ {
+ currentItem = historyList.append(item);
+ }
+ else
+ {
+ // Don't add the same item several times in a row
+ if (item == *currentItem)
+ return;
+
+ currentItem++;
+ if (currentItem == historyList.end())
+ {
+ currentItem = historyList.append(item);
+ }
+ else
+ {
+ currentItem = historyList.insert(currentItem, item);
+ }
+ // Delete items starting after currentItem to the end of the list.
+ QValueList<HistoryItem>::iterator deleteItemsStart = currentItem;
+ deleteItemsStart++;
+ historyList.erase(deleteItemsStart, historyList.end());
+
+ if (historyList.size() > HISTORYLENGTH)
+ historyList.pop_front();
+ }
+ emit backItem(currentItem != historyList.begin());
+ emit forwardItem(false);
+}
+
+HistoryItem* History::forward()
+{
+ if (historyList.empty() || currentItem == historyList.fromLast())
+ return 0;
+
+ currentItem++;
+ emit backItem(true);
+ emit forwardItem(currentItem != historyList.fromLast());
+ return &(*currentItem);
+}
+
+HistoryItem* History::back()
+{
+ if (historyList.empty() || currentItem == historyList.begin())
+ return 0;
+
+ currentItem--;
+ emit backItem(currentItem != historyList.begin());
+ emit forwardItem(true);
+ return &(*currentItem);
+}
+
+void History::clear()
+{
+ historyList.clear();
+ currentItem = historyList.begin();
+ emit backItem(false);
+ emit forwardItem(false);
+}
+
+#include "history.moc"