• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

history.cpp

Go to the documentation of this file.
00001 // history.cpp
00002 //
00003 // (C) 2001 Stefan Kebekus
00004 // Distributed under the GPL
00005 
00006 #include <config.h>
00007 
00008 #include <kdebug.h>
00009 
00010 #include "history.h"
00011 
00012 HistoryItem::HistoryItem(Q_UINT32 p, Q_UINT32 y)
00013   : page(p), ypos(y)
00014 {
00015 }
00016 
00017 bool HistoryItem::operator== (const HistoryItem& item) const
00018 {
00019   return page == item.page && ypos == item.ypos;
00020 }
00021 
00022 History::History()
00023 {
00024 }
00025 
00026 void History::add(Q_UINT32 page, Q_UINT32 ypos)
00027 {
00028   HistoryItem item(page, ypos);
00029 
00030   if (historyList.empty())
00031   {
00032     currentItem = historyList.append(item);
00033   }
00034   else
00035   {
00036     // Don't add the same item several times in a row
00037     if (item == *currentItem)
00038       return;
00039 
00040       currentItem++;
00041     if (currentItem == historyList.end())
00042     {
00043       currentItem = historyList.append(item);
00044     }
00045     else
00046     {
00047       currentItem = historyList.insert(currentItem, item);
00048     }
00049     // Delete items starting after currentItem to the end of the list.
00050     QValueList<HistoryItem>::iterator deleteItemsStart = currentItem;
00051     deleteItemsStart++;
00052     historyList.erase(deleteItemsStart, historyList.end()); 
00053 
00054     if (historyList.size() > HISTORYLENGTH)
00055       historyList.pop_front();
00056   }
00057   emit backItem(currentItem != historyList.begin());
00058   emit forwardItem(false);
00059 }
00060 
00061 HistoryItem* History::forward()
00062 {
00063   if (historyList.empty() || currentItem == historyList.fromLast())
00064     return 0;
00065     
00066     currentItem++;
00067   emit backItem(true);
00068   emit forwardItem(currentItem != historyList.fromLast());
00069   return &(*currentItem);
00070 }
00071 
00072 HistoryItem* History::back()
00073 {
00074   if (historyList.empty() || currentItem == historyList.begin())
00075     return 0;
00076   
00077     currentItem--;
00078   emit backItem(currentItem != historyList.begin());
00079   emit forwardItem(true);
00080   return &(*currentItem);
00081 }
00082 
00083 void History::clear()
00084 {
00085   historyList.clear();
00086   currentItem = historyList.begin();
00087   emit backItem(false);
00088   emit forwardItem(false);
00089 }
00090 
00091 #include "history.moc"

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal