[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdegraphics/kviewshell/shell
From: Wilfried Huss <Wilfried.Huss () gmx ! at>
Date: 2006-10-21 17:35:13
Message-ID: 1161452113.601297.22728.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 597808 by whuss:
port of commit 597807:
Fix another regression. History navigation now works again.
M +29 -7 anchor.h
M +17 -25 history.cpp
M +7 -26 history.h
M +18 -18 pageView.cpp
--- trunk/KDE/kdegraphics/kviewshell/shell/anchor.h #597807:597808
@@ -34,7 +34,10 @@
/** \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 anchor that points to the top of a given
page
@@ -45,7 +48,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
@@ -58,14 +64,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;
@@ -73,15 +89,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); + }
};
--- trunk/KDE/kdegraphics/kviewshell/shell/history.cpp #597807:597808
@@ -11,49 +11,39 @@
#include <QList>
-History::History()
-{}
-
-
-HistoryItem::HistoryItem(const PageNumber& p, int 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(const PageNumber& page, int ypos)
-{
- HistoryItem item(page, ypos);
-
if (historyList.empty())
{
- historyList.append(item);
+ historyList.append(a);
currentItem = historyList.begin();
}
else
{
// Don't add the same item several times in a row
- if (item == *currentItem)
+ if (a == *currentItem)
return;
currentItem++;
if (currentItem == historyList.end())
{
- historyList.append(item);
+ historyList.append(a);
currentItem = historyList.end();
--currentItem; // last element of the list
}
else
{
- currentItem = historyList.insert(currentItem, item);
+ currentItem = historyList.insert(currentItem, a);
}
// Delete items starting after currentItem to the end of the list.
- QList<HistoryItem>::iterator deleteItemsStart = currentItem;
+ QList<Anchor>::iterator deleteItemsStart = currentItem;
deleteItemsStart++;
historyList.erase(deleteItemsStart, historyList.end());
@@ -65,29 +55,31 @@
}
-HistoryItem* History::forward()
+Anchor* History::forward()
{
- QList<HistoryItem>::iterator lastItem = historyList.end();
+ QList<Anchor>::iterator lastItem = historyList.end();
--lastItem;
if (historyList.empty() || currentItem == lastItem)
return 0;
currentItem++;
+
emit backItem(true);
emit forwardItem(currentItem != lastItem);
return &(*currentItem);
}
-HistoryItem* History::back()
+Anchor* History::back()
{
- QList<HistoryItem>::iterator lastItem = historyList.end();
+ QList<Anchor>::iterator lastItem = historyList.end();
if (historyList.empty() || currentItem == lastItem)
return 0;
currentItem--;
+
emit backItem(currentItem != historyList.begin());
emit forwardItem(true);
return &(*currentItem);
--- trunk/KDE/kdegraphics/kviewshell/shell/history.h #597807:597808
@@ -7,6 +7,7 @@
// (C) 2001 Stefan Kebekus
// Distributed under the GPL
+#include "anchor.h"
#include "kviewshell_export.h"
#include "pageNumber.h"
@@ -17,47 +18,27 @@
#define HISTORYLENGTH 10
-class HistoryItem
-{
- public:
- HistoryItem(const PageNumber&, int);
- HistoryItem() {}
- bool operator== (const HistoryItem& item) const;
-
- PageNumber page;
- int ypos;
-};
-
-inline
-bool operator!=(const HistoryItem& lhs, const HistoryItem& rhs)
-{
- return !(lhs == rhs);
-}
-
-
class KVIEWSHELL_EXPORT History : public QObject
{
Q_OBJECT
public:
- History();
+ void add(Anchor);
+ void clear();
- void add(const PageNumber& page, int ypos);
- void clear();
+ Anchor* forward();
+ Anchor* back();
- HistoryItem* forward();
- HistoryItem* back();
-
signals:
void backItem(bool);
void forwardItem(bool);
private:
// List of history items. First item is the oldest.
- QList<HistoryItem> historyList;
+ QList<Anchor> historyList;
- QList<HistoryItem>::iterator currentItem;
+ QList<Anchor>::iterator currentItem;
};
#endif
--- trunk/KDE/kdegraphics/kviewshell/shell/pageView.cpp #597807:597808
@@ -1081,12 +1081,14 @@
kError(kvs::shell) << "PageView::gotoAnchor() called, but widgetList is empty" \
<< endl; return;
}
-
+
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;
@@ -1283,27 +1285,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
kDebug(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
kDebug(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