[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/work/kviewshell-0.7/kviewshell/shell
From: Wilfried Huss <Wilfried.Huss () gmx ! at>
Date: 2006-10-21 17:16:37
Message-ID: 1161450997.554364.21730.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 597807 by whuss:
Fix another regression. History navigation now works again.
M +29 -7 anchor.h
M +17 -26 history.cpp
M +7 -26 history.h
M +17 -16 pageView.cpp
--- branches/work/kviewshell-0.7/kviewshell/shell/anchor.h #597806:597807
@@ -32,7 +32,10 @@
class Anchor {
public:
/** \brief Constructs an anchor that points to an invalid page. The target is not \
a link. */
- Anchor() {page = 0; isLinkTarget = false;}
+ Anchor()
+ : isLinkTarget(false), isHistoryLink(false)
+ {
+ }
/** \brief Constructs an snchor that points to the top of a given
page
@@ -43,7 +46,10 @@
@param pg number of the page
*/
- Anchor(const PageNumber& pg): page(pg), distance_from_top() {isLinkTarget = \
false;} + Anchor(const PageNumber& pg)
+ : page(pg), distance_from_top(), isLinkTarget(false), isHistoryLink(false)
+ {
+ }
/** \brief Constructs an snchor that points to a given position on a
given page
@@ -56,14 +62,24 @@
@param _distance_from_top distance from the top of the page
@param _islink set to true if the anchor is the target of a link
*/
- Anchor(const PageNumber& pg, const Length& _distance_from_top, bool _isLink=true): \
page(pg), distance_from_top(_distance_from_top), isLinkTarget(_isLink) {} + \
Anchor(const PageNumber& pg, const Length& _distance_from_top, bool _isLink=true) + \
: page(pg), distance_from_top(_distance_from_top), isLinkTarget(_isLink), \
isHistoryLink(false) + {}
/** \brief quick validity check for anchors
@returns true if the page number is valid, and 0mm <= distance_from_top <= 2m
*/
- bool isValid() const {return page.isValid() && (0.0 <= \
distance_from_top.getLength_in_mm()) && (distance_from_top.getLength_in_mm() <= \
2000.0);} + bool isValid() const
+ {
+ return page.isValid() && (0.0 <= distance_from_top.getLength_in_mm()) && \
(distance_from_top.getLength_in_mm() <= 2000.0); + }
+ bool operator== (const Anchor& anchor) const
+ {
+ return page == anchor.page && \
distance_from_top.isNearlyEqual(anchor.distance_from_top); + }
+
/** \brief Page number that this anchor point to */
PageNumber page;
@@ -71,15 +87,21 @@
Length distance_from_top;
/** \brief indicates if the anchor is the target of a link
-
- This flas is used by the GUI. For instance, if the user goes to
+
+ This flag is used by the GUI. For instance, if the user goes to
the target of a link, there is a flashing frame that indicates
where the anchor is.
*/
bool isLinkTarget;
+ /** \brief indicates that the anchor comes from the navigation history */
+ bool isHistoryLink;
+
/** \brief This method implements typecasts to QString */
- operator QString() const { return QString("(page=%1, %2 from top, \
isLink=%3)").arg(page.toQString()).arg(distance_from_top).arg(isLinkTarget); } + \
operator QString() const + {
+ return QString("(page=%1, %2 from top, \
isLink=%3)").arg(page.toQString()).arg(distance_from_top).arg(isLinkTarget); + }
};
--- branches/work/kviewshell-0.7/kviewshell/shell/history.cpp #597806:597807
@@ -8,47 +8,36 @@
#include "history.h"
-
-History::History()
-{}
-
-
-HistoryItem::HistoryItem(Q_UINT32 p, Q_UINT32 y)
- : page(p), ypos(y)
-{}
-
-
-bool HistoryItem::operator==(const HistoryItem& item) const
+void History::add(Anchor a)
{
- return page == item.page && ypos == item.ypos;
-}
+ // Don't change the history when we are navigating throu the history
+ if (a.isHistoryLink)
+ return;
+ // Make the anchor a history item
+ a.isHistoryLink = true;
-void History::add(Q_UINT32 page, Q_UINT32 ypos)
-{
- HistoryItem item(page, ypos);
-
if (historyList.empty())
{
- currentItem = historyList.append(item);
+ currentItem = historyList.append(a);
}
else
{
// Don't add the same item several times in a row
- if (item == *currentItem)
+ if (a == *currentItem)
return;
currentItem++;
if (currentItem == historyList.end())
{
- currentItem = historyList.append(item);
+ currentItem = historyList.append(a);
}
else
{
- currentItem = historyList.insert(currentItem, item);
+ currentItem = historyList.insert(currentItem, a);
}
// Delete items starting after currentItem to the end of the list.
- QValueList<HistoryItem>::iterator deleteItemsStart = currentItem;
+ QValueList<Anchor>::iterator deleteItemsStart = currentItem;
deleteItemsStart++;
historyList.erase(deleteItemsStart, historyList.end());
@@ -60,24 +49,26 @@
}
-HistoryItem* History::forward()
+Anchor* History::forward()
{
if (historyList.empty() || currentItem == historyList.fromLast())
return 0;
- currentItem++;
+ currentItem++;
+
emit backItem(true);
emit forwardItem(currentItem != historyList.fromLast());
return &(*currentItem);
}
-HistoryItem* History::back()
+Anchor* History::back()
{
if (historyList.empty() || currentItem == historyList.begin())
return 0;
- currentItem--;
+ currentItem--;
+
emit backItem(currentItem != historyList.begin());
emit forwardItem(true);
return &(*currentItem);
--- branches/work/kviewshell-0.7/kviewshell/shell/history.h #597806:597807
@@ -7,43 +7,24 @@
// (C) 2001 Stefan Kebekus
// Distributed under the GPL
+#include "anchor.h"
+
#include <qobject.h>
#include <qvaluelist.h>
#define HISTORYLENGTH 10
-class HistoryItem
-{
- public:
- HistoryItem(Q_UINT32, Q_UINT32);
- HistoryItem() {}
-
- bool operator== (const HistoryItem& item) const;
-
- Q_UINT32 page;
- Q_UINT32 ypos;
-};
-
-inline
-bool operator!=(const HistoryItem& lhs, const HistoryItem& rhs)
-{
- return !(lhs == rhs);
-}
-
-
class History : public QObject
{
Q_OBJECT
public:
- History();
-
- void add(Q_UINT32 page, Q_UINT32 ypos);
+ void add(Anchor);
void clear();
- HistoryItem* forward();
- HistoryItem* back();
+ Anchor* forward();
+ Anchor* back();
signals:
void backItem(bool);
@@ -51,9 +32,9 @@
private:
// List of history items. First item is the oldest.
- QValueList<HistoryItem> historyList;
+ QValueList<Anchor> historyList;
- QValueList<HistoryItem>::iterator currentItem;
+ QValueList<Anchor>::iterator currentItem;
};
#endif
--- branches/work/kviewshell-0.7/kviewshell/shell/pageView.cpp #597806:597807
@@ -1064,10 +1064,13 @@
}
PageNumber page = a.page;
+
int y = (int)(a.distance_from_top.getLength_in_inch() * dataModel->resolution() + \
0.5);
- if (a.isLinkTarget)
- dataModel->history()->add(page, y);
+ if (!a.isHistoryLink)
+ {
+ dataModel->history()->add(a);
+ }
DocumentWidget* _pageWidget;
@@ -1264,27 +1267,25 @@
void PageView::goBack()
{
- HistoryItem* it = dataModel->history()->back();
- if (it != 0) {
- Length l;
- l.setLength_in_mm(it->ypos);
- dataModel->setCurrentPageNumber(Anchor(it->page, l, false)); // Do not add a \
history item.
- } else
+ Anchor* anchor = dataModel->history()->back();
+ if (anchor)
+ {
+ dataModel->setCurrentPageNumber(*anchor); // Do not add a history item.
+ }
+ else
kdDebug(kvs::shell) << "Faulty return -- bad history buffer" << endl;
- return;
}
void PageView::goForward()
{
- HistoryItem* it = dataModel->history()->forward();
- if (it != 0) {
- Length l;
- l.setLength_in_mm(it->ypos);
- dataModel->setCurrentPageNumber(Anchor(it->page, l, false)); // Do not add a \
history item.
- } else
+ Anchor* anchor = dataModel->history()->forward();
+ if (anchor)
+ {
+ dataModel->setCurrentPageNumber(*anchor); // Do not add a history item.
+ }
+ else
kdDebug(kvs::shell) << "Faulty return -- bad history buffer" << endl;
- return;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic