[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdegraphics/kviewshell
From: Stefan Kebekus <kebekus () kde ! org>
Date: 2006-09-14 5:49:52
Message-ID: 1158212992.514164.15204.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 584142 by kebekus:
fixes problems with links in DVI files
M +11 -7 plugins/dvi/dviRenderer.cpp
M +1 -2 plugins/pdf/pdfRenderer.cpp
M +16 -0 shell/anchor.h
M +11 -8 shell/dataModel.cpp
M +23 -1 shell/dataModel.h
M +1 -1 shell/dataView.cpp
M +3 -0 shell/documentWidget.cpp
M +3 -0 shell/hyperlink.h
M +2 -1 shell/kviewpart.cpp
M +1 -0 shell/kvs_debug.h
M +4 -2 shell/length.h
M +11 -1 shell/pageNumber.h
M +109 -14 shell/pageView.cpp
M +0 -1 shell/pageView.h
--- trunk/KDE/kdegraphics/kviewshell/plugins/dvi/dviRenderer.cpp #584141:584142
@@ -238,12 +238,12 @@
QRegExp itemExp("item\\.(.*)");
QRegExp citeExp("cite\\.(.*)");
- // And finally add anchors to the links
- for (i = page->hyperLinkList.begin(); i != page->hyperLinkList.end(); i++)
- {
- Anchor anchor = findAnchor((*i).linkText);
- (*i).anchor = anchor;
-
+ // And finally add anchors to the links, if the links are local
+ for (i = page->hyperLinkList.begin(); i != page->hyperLinkList.end(); i++) {
+#warning TODO: remove link if anchor cannot be found
+ if ((*i).linkText[0] == '#') // is local link?
+ (*i).anchor = findAnchor((*i).linkText.mid(1));
+
// Also replace the targetnames created by the hyperref package,
// with proper translatable names.
QString temp = (*i).linkText;
@@ -890,8 +890,12 @@
QMap<QString,Anchor>::Iterator it = anchorList.find(locallink);
if (it != anchorList.end())
return *it;
- else
+ else {
+#ifdef DEBUG_DVIRENDERER
+ kdDebug(kvs::dvi) << QString("dviRenderer::findAnchor(%1): no anchor \
found.").arg(locallink) << endl; +#endif
return Anchor();
+ }
}
#include "dviRenderer.moc"
--- trunk/KDE/kdegraphics/kviewshell/plugins/pdf/pdfRenderer.cpp #584141:584142
@@ -185,9 +185,8 @@
Length y;
y.setLength_in_pixel(destination.top(), res);
Anchor anchor(destination.pageNumber(), y);
- //kDebug() << "Anchor: url = " << destination.toString() << " (page = " << \
destination.pageNumber() << ", y = " << destination.top() << ")" << \
endl;
- //kDebug() << "Hyperlink: (" << area.x() << ", " << area.y() << ", " << \
area.width() << ", " << area.height() << ")" << endl; Hyperlink \
hyperlink(area.bottom(), area, url, anchor); + // kdDebug(kvs::pdf) << \
"PdfRenderer::drawPage: hyperlink added " << hyperlink << endl; \
page->hyperLinkList.push_back(hyperlink); }
else if (link->linkType() == Poppler::Link::Browse)
--- trunk/KDE/kdegraphics/kviewshell/shell/anchor.h #584141:584142
@@ -11,6 +11,8 @@
#ifndef ANCHOR_H
#define ANCHOR_H
+#include <QString>
+
#include "length.h"
#include "pageNumber.h"
@@ -32,6 +34,17 @@
/** \brief Constructs an anchor that points to an invalid page */
Anchor() {page = 0;}
+
+ /** \brief Constructs an anchor that points to the top of a given
+ page
+
+ The class contains no code to make sure in any way that the page
+ number pg exists
+
+ @param pg number of the page
+ */
+ Anchor(const PageNumber& pg): page(pg), distance_from_top() {}
+
/** \brief Constructs an snchor that points to a given position on a
given page
@@ -55,6 +68,9 @@
/** \brief Distance from the top of the page in inch */
Length distance_from_top;
+
+ /** \brief This method implements typecasts to QString */
+ operator QString() const { return QString("(page=%1, %2 from \
top)").arg(page.toQString()).arg(distance_from_top); } };
--- trunk/KDE/kdegraphics/kviewshell/shell/dataModel.cpp #584141:584142
@@ -66,15 +66,18 @@
void DataModel::setCurrentPageNumber(const PageNumber& pageNumber, bool weak)
{
- if (pageNumber != _currentPageNumber)
- {
- _currentPageNumber = pageNumber;
- emit currentPageNumberChanged();
- if (!weak)
- {
- emit gotoCurrentPage();
- }
+ if (pageNumber > numberOfPages()) {
+ kError(kvs::shell) << "DataModel::setCurrentPageNumber called with pageNumber \
higher than the number of pages in the document" << endl; + return;
}
+
+ if (pageNumber == _currentPageNumber)
+ return;
+
+ _currentPageNumber = pageNumber;
+ emit currentPageNumberChanged();
+ if (!weak)
+ emit gotoCurrentPage();
}
--- trunk/KDE/kdegraphics/kviewshell/shell/dataModel.h #584141:584142
@@ -50,7 +50,24 @@
DataModel(QObject* parent = 0);
virtual ~DataModel();
+ /** @brief get the current page number
+ */
PageNumber currentPageNumber();
+
+ /** @brief sets the current page number
+
+ This method sets the current page number. The signal
+ currentPageNumberChanged() will be emitted. The signal
+ gotoCurrentPage() might be emitted.
+
+ @param PageNumber The new page number; this number must not be
+ greater than numberOfPages(). If this number equals the
+ currentPageNumber(), this method exits immediately and nothing
+ happens.
+
+ @param weak This parameter decides if the signal
+ gotoCurrentPage() is emitted.
+ */
void setCurrentPageNumber(const PageNumber&, bool weak = false);
unsigned int numberOfPages();
@@ -183,11 +200,16 @@
signals:
void currentPageNumberChanged();
+
+ /** This signal might emitted when the method setCurrentPageNumber()
+ is called. It indicates that the current page number has changed
+ and that the display should be updated accordingly.
+ */
void gotoCurrentPage();
void numberOfPagesChanged();
void layoutChanged();
- /** This signal es emitted whenever the selected text changes.
+ /** This signal is emitted whenever the selected text changes.
The argument is false if no text is selected, true otherwise.
@ref deselectText
--- trunk/KDE/kdegraphics/kviewshell/shell/dataView.cpp #584141:584142
@@ -41,7 +41,7 @@
void DataView::setupObservers(DataModel* _dataModel)
{
if (_dataModel == 0) {
- kdError(kvs::shell) << "DataView::setupObservers called when dataModel == 0)" << \
endl; + kError(kvs::shell) << "DataView::setupObservers called when dataModel == \
0)" << endl; return;
}
--- trunk/KDE/kdegraphics/kviewshell/shell/documentWidget.cpp #584141:584142
@@ -557,6 +557,9 @@
{
if (pageData->hyperLinkList[i].box.contains(inverseMap(e->pos())))
{
+#ifdef DEBUG_DOCUMENTWIDGET
+ kDebug(kvs::shell) << "DocumentWidget::mousePressEvent(): mouse pressed on \
hyperlink " << pageData->hyperLinkList[i].linkText << endl; +#endif
emit localLink(pageData->hyperLinkList[i]);
return;
}
--- trunk/KDE/kdegraphics/kviewshell/shell/hyperlink.h #584141:584142
@@ -88,6 +88,9 @@
should be set to invalid.
*/
Anchor anchor;
+
+ /** \brief This method implements typecasts to QString */
+ operator QString() const { return QString("(name=%1, \
anchor=%2)").arg(linkText).arg(anchor); } };
--- trunk/KDE/kdegraphics/kviewshell/shell/kviewpart.cpp #584141:584142
@@ -1951,7 +1951,8 @@
QUrl Link_Url(m_file);
Link_Url.setFragment(link.linkText);
KToolInvocation::invokeBrowser(Link_Url.toString());
- }
+ }else
+ kError(kvs::shell) << "KMultiPage::handleLocalLink( ... ) with link to " << \
link << endl; }
}
--- trunk/KDE/kdegraphics/kviewshell/shell/kvs_debug.h #584141:584142
@@ -24,6 +24,7 @@
dvi = 4300,
fax = 1223,
pdf = 1223,
+ ps = 1223,
shell = 1223
};
--- trunk/KDE/kdegraphics/kviewshell/shell/length.h #584141:584142
@@ -13,9 +13,8 @@
#define _length_h_
#include <cmath>
+#include <QString>
-class QString;
-
#define mm_per_cm 10.0
#define mm_per_m 1000.0
#define mm_per_inch 25.4
@@ -181,6 +180,9 @@
It is fine to set ok to 0. */
static float convertToMM(const QString &distance, bool *ok=0);
+ /** \brief This simple method implements typecasts to QString */
+ operator QString() const { return QString::number(length_in_mm, 'f', 2)+"mm"; }
+
private:
/** Length in millimeters */
double length_in_mm;
--- trunk/KDE/kdegraphics/kviewshell/shell/pageNumber.h #584141:584142
@@ -11,8 +11,8 @@
#define PAGENUMBER_H
#include <QGlobalStatic>
+#include <QString>
-
/** \brief Class to represent a page number
The class PageNumber is really nothing but an alias for quint16, and
@@ -55,6 +55,16 @@
*/
bool isValid() const {return (pgNum != invalidPage);}
+ /** \brief This simple method represents the page number as a string
+
+ We do not implement a typecast here, because otherwise there would
+ be too many ambiguous typecasts that one would have to sort out
+ manually.
+
+ @returns the page number as a string or 'invalid'
+ */
+ QString toQString() const { return isValid() ? QString::number(pgNum) : "invalid"; \
}; +
private:
/** \brief Single number that represents the page number */
quint16 pgNum;
--- trunk/KDE/kdegraphics/kviewshell/shell/pageView.cpp #584141:584142
@@ -993,16 +993,10 @@
// If the number of widgets has changed, or the viewmode has been changed the \
widget // that displays the current page may not be visible anymore. Bring it back \
into focus. if (isWidgetListResized || !reload)
- gotoPage(startPage);
+ gotoAnchor(startPage);
}
-bool PageView::gotoPage(const PageNumber& page)
-{
- return gotoPage(page, 0, true);
-}
-
-
bool PageView::gotoPage(const PageNumber& page, int y, bool isLink)
{
kDebug(kvs::shell) << "KMultiPage::gotoPage()" << endl;
@@ -1164,10 +1158,111 @@
void PageView::gotoAnchor(const Anchor& a)
{
- if (!a.page.isValid())
+ kDebug(kvs::shell) << "PageView::gotoAnchor()" << endl;
+
+ // gotoPage(a.page, (int)(a.distance_from_top.getLength_in_inch() * \
dataModel->resolution() + 0.5), true); +
+ if (!a.page.isValid()) {
+ kError(kvs::shell) << "PageView::gotoAnchor() call when anchor had invalid \
pageNumber." << endl; + return;
+ }
+ if (dataModel->numberOfPages() == 0) {
+ kError(kvs::shell) << "PageView::gotoAnchor() called with numberOfPages == 0" << \
endl; + return;
+ }
+ if (numberOfWidgets() == 0) {
+ 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); +#warning FIX THIS
+ bool isLink = true;
+
+ if (isLink)
+ dataModel->history()->add(page, y);
+
+ DocumentWidget* _pageWidget;
+
+ // If we are in overview viewmode
+ if (dataModel->preferences()->viewMode() == KVSPrefs::EnumViewMode::Overview) {
+ unsigned int visiblePages = dataModel->preferences()->overviewModeColumns() * \
dataModel->preferences()->overviewModeRows(); + // Pagenumber of the first \
visibile Page in the current tableau + unsigned int firstPage = \
pageWidget(0)->getPageNumber(); + // Pagenumber of the first page in the new \
tableau. + unsigned int tableauStartPage = page + 1 - (page % visiblePages);
+ // If these numbers arn't equal "page" is not in the current tableu.
+ bool newTableu = false;
+ if (firstPage != tableauStartPage) { // widgets need to be updated
+ newTableu = true;
+ if ((dataModel->numberOfPages() - tableauStartPage + 1 < visiblePages) || \
(numberOfWidgets() < visiblePages)) { + // resize widgetList
+ // the pages are also set correctly by "generateDocumentWidgets"
+ generateDocumentWidgets(tableauStartPage);
+ } else {
+ // "page" is not shown in the scrollview, so we have to switch widgets.
+ // Here we don't need to resize the widgetList.
+ for (unsigned int i = 0; i < numberOfWidgets(); i++) {
+ _pageWidget = pageWidget(i);
+ if (_pageWidget != 0)
+ _pageWidget->setPageNumber(tableauStartPage + i);
+ }
+ layoutPages();
+ }
+ }
+ // move scrollview to "page".
+ // Make the widget pageWidget visible in the scrollview. Somehow this
+ // doesn't seem to trigger the signal contentsMoved in the
+ // QScrollview, so that we better call setCurrentPage() ourselves.
+ _pageWidget = pageWidget(page % visiblePages);
+
+ if (newTableu) {
+ // If we have switched to a new tableu, we don't want smooth scrolling
+ moveViewportToWidget(_pageWidget, y, false);
+ } else
+ moveViewportToWidget(_pageWidget, y);
return;
+ } else if (numberOfWidgets() == 1) {
+ // If the widget list contains only a single element, then either
+ // the document contains only one page, or we are in "single page"
+ // view mode. In either case, we set the page number of the single
+ // widget to 'page'
+ _pageWidget = pageWidget(0);
- gotoPage(a.page, (int)(a.distance_from_top.getLength_in_inch() * \
dataModel->resolution() + 0.5), true); + // Paranoia security check
+ if (_pageWidget == 0) {
+ kError(kvs::shell) << "PageView::gotoAnchor() called with widgetList.size() == \
1, but widgetList[0] == 0" << endl; + return;
+ }
+
+ _pageWidget->setPageNumber(page);
+ layoutPages();
+ moveViewportToWidget(_pageWidget, y, false);
+ } else {
+ // There are multiple widgets, then we are either in the
+ // "Continuous" or in the "Continouous-Facing" view mode. In that
+ // case, we find the widget which is supposed to display page
+ // 'page' and move the scrollview to make it visible
+
+ // Paranoia security checks
+ if (numberOfWidgets() < page) {
+ kError(kvs::shell) << "PageView::gotoAnchor() called with widgetList.size()=" \
<< numberOfWidgets() << ", and page=" << page << endl; + return;
+ }
+ _pageWidget = pageWidget(page-1);
+ if (_pageWidget == 0) {
+ kError(kvs::shell) << "PageView::gotoAnchor() called with widgetList.size() > \
1, but widgetList[page] == 0" << endl; + return;
+ }
+
+ moveViewportToWidget(_pageWidget, y);
+ }
+
+ if (isLink && y != 0)
+ _pageWidget->flash(y);
+
+ return;
}
@@ -1179,7 +1274,7 @@
np = dataModel->currentPageNumber() - nrCols*nrRows;
}
- gotoPage(np);
+ gotoAnchor(np);
}
@@ -1187,19 +1282,19 @@
{
PageNumber np = qMin(dataModel->currentPageNumber() + nrCols*nrRows, \
dataModel->numberOfPages());
- gotoPage(np);
+ gotoAnchor(np);
}
void PageView::firstPage()
{
- gotoPage(1);
+ gotoAnchor(Anchor(1));
}
void PageView::lastPage()
{
- gotoPage(dataModel->numberOfPages());
+ gotoAnchor(Anchor(dataModel->numberOfPages()));
}
@@ -1458,7 +1553,7 @@
void PageView::gotoCurrentPage()
{
- gotoPage(dataModel->currentPageNumber());
+ gotoAnchor(dataModel->currentPageNumber());
}
#include "pageView.moc"
--- trunk/KDE/kdegraphics/kviewshell/shell/pageView.h #584141:584142
@@ -54,7 +54,6 @@
// These two will probably end up private
bool gotoPage(const PageNumber& page, int y, bool isLink = true);
- bool gotoPage(const PageNumber& page);
/** Make the selection visible */
void gotoSelection(const TextSelection&);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic