1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 /***************************************************************************
8 navigator.cpp - description
9 -------------------
10 begin : Fri Feb 22 2002
11 copyright : (C) 2002 by Franz Schmid
12 email : Franz.Schmid@altmuehlnet.de
13 ***************************************************************************/
14
15 /***************************************************************************
16 * *
17 * This program is free software; you can redistribute it and/or modify *
18 * it under the terms of the GNU General Public License as published by *
19 * the Free Software Foundation; either version 2 of the License, or *
20 * (at your option) any later version. *
21 * *
22 ***************************************************************************/
23
24 #include "navigator.h"
25
26 #include <QPixmap>
27 #include <QMouseEvent>
28 #include <QLabel>
29 #include <QPaintEvent>
30 #include <QPainter>
31 #include "scribusview.h"
32 #include "util_ghostscript.h"
33
Navigator(QWidget * parent,int size,int pageNr,ScribusView * view,const QString & fn)34 Navigator::Navigator(QWidget *parent, int size, int pageNr, ScribusView* view, const QString& fn) : QLabel(parent),
35 m_view(view)
36 {
37 setScaledContents(false);
38 setAlignment(Qt::AlignLeft | Qt::AlignTop);
39 if (!fn.isEmpty())
40 {
41 QPixmap img = loadPDF(fn, pageNr, size, &Width, &Height);
42 if (!img.isNull())
43 pmx = img;
44 else
45 pmx = loadPDF(fn, 1, size, &Width, &Height);
46 }
47 else
48 pmx = QPixmap::fromImage(view->PageToPixmap(pageNr, size));
49 resize(pmx.width(), pmx.height());
50 Xp = 0;
51 Yp = 0;
52 drawMark(0, 0);
53 }
54
mouseMoveEvent(QMouseEvent * m)55 void Navigator::mouseMoveEvent(QMouseEvent *m)
56 {
57 drawMark(m->x(), m->y());
58 emit Coords(static_cast<double>(m->x()) / static_cast<double>(pmx.width()),
59 static_cast<double>(m->y()) / static_cast<double>(pmx.height()));
60 }
61
mousePressEvent(QMouseEvent * m)62 void Navigator::mousePressEvent(QMouseEvent *m)
63 {
64 drawMark(m->x(), m->y());
65 emit Coords(static_cast<double>(m->x()) / static_cast<double>(pmx.width()),
66 static_cast<double>(m->y()) / static_cast<double>(pmx.height()));
67 }
68
mouseReleaseEvent(QMouseEvent * m)69 void Navigator::mouseReleaseEvent(QMouseEvent *m)
70 {
71 emit Coords(static_cast<double>(m->x()) / static_cast<double>(pmx.width()),
72 static_cast<double>(m->y()) / static_cast<double>(pmx.height()));
73 }
74
paintEvent(QPaintEvent * e)75 void Navigator::paintEvent(QPaintEvent *e)
76 {
77 QPainter p;
78 p.begin(this);
79 p.setBackground(QColor(255, 255, 255));
80 p.eraseRect(pmx.rect());
81 p.setClipRect(pmx.rect());
82 p.drawPixmap(0, 0, pmx);
83 p.setPen(QPen(QColor(Qt::black), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
84 p.drawLine(Xp - 5, Yp - 5, Xp - 1, Yp - 1);
85 p.drawLine(Xp - 5, Yp + 5, Xp - 1, Yp + 1);
86 p.drawLine(Xp + 2, Yp + 2, Xp + 6, Yp + 6);
87 p.drawLine(Xp + 2, Yp - 2, Xp + 6, Yp - 6);
88 p.end();
89 }
90
drawMark(int x,int y)91 void Navigator::drawMark(int x, int y)
92 {
93 Xp = x;
94 Yp = y;
95 repaint();
96 }
97
setPage(int pageNr,int size,const QString & fn)98 bool Navigator::setPage(int pageNr, int size, const QString& fn)
99 {
100 bool ret = false;
101 if (!fn.isEmpty())
102 {
103 QPixmap img = loadPDF(fn, pageNr, size, &Width, &Height);
104 if (!img.isNull())
105 {
106 pmx = img;
107 ret = true;
108 }
109 else
110 pmx = loadPDF(fn, 1, size, &Width, &Height);
111 }
112 else
113 {
114 pmx = QPixmap::fromImage(m_view->PageToPixmap(pageNr, size));
115 ret = true;
116 }
117 resize(pmx.width(), pmx.height());
118 repaint();
119 return ret;
120 }
121