1 /* This file is part of the KDE project
2  * Copyright (C) 2001 David Faure <faure@kde.org>
3  * Copyright (C) 2005-2006 Thomas Zander <zander@kde.org>
4  * Copyright (C) 2010-2011 Boudewijn Rempt <boud@kogmbh.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #include "KWViewMode.h"
23 
24 #include <KoViewConverter.h>
25 
26 #include "KWDocument.h"
27 #include "KWViewModeNormal.h"
28 #include "KWViewModePreview.h"
29 
KWViewMode()30 KWViewMode::KWViewMode()
31     : m_pageManager(0)
32 {
33 }
34 
documentToView(const QRectF & rect,KoViewConverter * viewConverter) const35 QRectF KWViewMode::documentToView(const QRectF &rect, KoViewConverter *viewConverter) const
36 {
37     QRectF r;
38     QPointF topLeft(documentToView(rect.topLeft(), viewConverter));
39     QPointF bottomRight(documentToView(rect.bottomRight(), viewConverter));
40 
41     r.setCoords(topLeft.x(), topLeft.y(), bottomRight.x(), bottomRight.y());
42     return r;
43 }
44 
viewToDocument(const QRectF & rect,KoViewConverter * viewConverter) const45 QRectF KWViewMode::viewToDocument(const QRectF &rect, KoViewConverter *viewConverter) const
46 {
47     QRectF r;
48     QPointF topLeft(viewToDocument(rect.topLeft(), viewConverter));
49     QPointF bottomRight(viewToDocument(rect.bottomRight(), viewConverter));
50 
51     r.setCoords(topLeft.x(), topLeft.y(), bottomRight.x(), bottomRight.y());
52     return r;
53 }
54 
pageSetupChanged()55 void KWViewMode::pageSetupChanged()
56 {
57     updatePageCache();
58 }
59 
60 // static
create(const QString & viewModeType,KWDocument * document)61 KWViewMode *KWViewMode::create(const QString &viewModeType, KWDocument *document)
62 {
63     KWViewMode * vm = 0;
64     if (viewModeType == KWViewModePreview::viewMode())
65         vm = new KWViewModePreview();
66     if (vm == 0)
67         vm = new KWViewModeNormal();
68 
69     vm->setPageManager(document->pageManager());
70     return vm;
71 }
72 
73