1 /*
2     dspdfviewer - Dual Screen PDF Viewer for LaTeX-Beamer
3     Copyright (C) 2012  Danny Edel <mail@danny-edel.de>
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 
21 #include "renderingidentifier.h"
22 #include <QApplication>
23 #include <QHash>
24 #include <sstream>
25 
26 #if defined ( POPPLER_QT5 )
27 #include <QDebugStateSaver>
28 #else
29 #include <QDebug>
30 #endif
31 
operator ==(const RenderingIdentifier & other) const32 bool RenderingIdentifier::operator==(const RenderingIdentifier& other) const
33 {
34   return
35     thePageNumber == other.thePageNumber
36     && thePagePart == other.thePagePart
37     && theRequestedPageSize == other.theRequestedPageSize;
38 }
39 
40 #if 0
41 RenderingIdentifier::operator QString() const
42 {
43   QString s( "page%1_%2_size%3x%4" ) ;
44   QString partId;
45   switch( pagePart() ) {
46     case PagePart::LeftHalf:
47       partId= "LeftHalf";
48       break;
49     case PagePart::RightHalf:
50       partId="RightHalf";
51       break;
52     case PagePart::FullPage:
53 	partId="FullPage";
54 	break;
55   }
56   return s.arg(pageNumber()).arg(partId).arg(requestedPageSize().width()).arg(requestedPageSize().height());
57 }
58 #endif
59 
pageNumber() const60 unsigned RenderingIdentifier::pageNumber() const
61 {
62   return thePageNumber;
63 }
64 
pagePart() const65 PagePart RenderingIdentifier::pagePart() const
66 {
67   return thePagePart;
68 }
69 
requestedPageSize() const70 QSize RenderingIdentifier::requestedPageSize() const
71 {
72   return theRequestedPageSize;
73 }
74 
RenderingIdentifier(unsigned pagenum,PagePart pagepart,QSize pagesize)75 RenderingIdentifier::RenderingIdentifier(unsigned pagenum, PagePart pagepart, QSize pagesize):
76 	thePageNumber(pagenum),
77 	thePagePart(pagepart),
78 	theRequestedPageSize(pagesize),
79 	theVersion(1)
80 {
81 
82 }
83 
84 
qHash(const RenderingIdentifier & ri)85 uint qHash(const RenderingIdentifier& ri)
86 {
87   return qHash(ri.pageNumber()) ^ qHash(ri.requestedPageSize().height()) ^ qHash(ri.requestedPageSize().width());
88 }
89 
operator <<(QDebug d,const RenderingIdentifier & ri)90 QDebug operator << (QDebug d, const RenderingIdentifier& ri) {
91 #if defined ( POPPLER_QT5 )
92 	// QDebugStateSaver only exists in Qt5.1
93 	QDebugStateSaver s(d);
94 #endif
95 	std::ostringstream oss;
96 	oss << ri.pagePart();
97 	d.nospace() << "[page " << ri.pageNumber() << '/' << oss.str().c_str() << '/' <<
98 		ri.requestedPageSize().width() << 'x' << ri.requestedPageSize().height() << ']';
99 	return d;
100 }
101