Back to index

scribus-ng  1.3.4.dfsg+svn20071115
navigator.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008                           navigator.cpp  -  description
00009                              -------------------
00010     begin                : Fri Feb 22 2002
00011     copyright            : (C) 2002 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 #include "navigator.h"
00025 #include "navigator.moc"
00026 
00027 #include <qpainter.h>
00028 #include "scribusview.h"
00029 #include "gsutil.h"
00030 
00031 Navigator::Navigator(QWidget *parent, int Size, int Seite, ScribusView* vie, QString fn) : QLabel(parent)
00032 {
00033        setScaledContents(false);
00034        setAlignment(static_cast<int>( QLabel::AlignLeft | QLabel::AlignTop) );
00035        if (!fn.isEmpty())
00036        {
00037               QPixmap img = LoadPDF(fn, Seite, Size, &Breite, &Hoehe);
00038               if (!img.isNull())
00039                      pmx = img;
00040               else
00041                      pmx = LoadPDF(fn, 1, Size, &Breite, &Hoehe);
00042        }
00043        else
00044               pmx.convertFromImage(vie->PageToPixmap(Seite, Size));
00045        resize(pmx.width(), pmx.height());
00046        Xp = 0;
00047        Yp = 0;
00048        drawMark(0, 0);
00049        view = vie;
00050 }
00051 
00052 void Navigator::mouseMoveEvent(QMouseEvent *m)
00053 {
00054        drawMark(m->x(), m->y());
00055        emit Coords(static_cast<double>(m->x())/static_cast<double>(pmx.width()),
00056                          static_cast<double>(m->y())/static_cast<double>(pmx.height()));
00057 }
00058 
00059 void Navigator::mousePressEvent(QMouseEvent *m)
00060 {
00061        drawMark(m->x(), m->y());
00062        emit Coords(static_cast<double>(m->x())/static_cast<double>(pmx.width()),
00063                          static_cast<double>(m->y())/static_cast<double>(pmx.height()));
00064 }
00065 
00066 void Navigator::mouseReleaseEvent(QMouseEvent *m)
00067 {
00068        emit Coords(static_cast<double>(m->x())/static_cast<double>(pmx.width()),
00069                          static_cast<double>(m->y())/static_cast<double>(pmx.height()));
00070 }
00071 
00072 void Navigator::paintEvent(QPaintEvent *e)
00073 {
00074        QPainter p;
00075        p.begin(this);
00076        p.setClipRect(e->rect());
00077        drawMark(Xp, Yp);
00078        p.end();
00079 }
00080 
00081 void Navigator::drawMark(int x, int y)
00082 {
00083        QPainter p;
00084        p.begin(this);
00085        p.setBackgroundColor(QColor(255, 255, 255));
00086        p.eraseRect(pmx.rect());
00087        p.setClipRect(pmx.rect());
00088        p.drawPixmap(0, 0, pmx);
00089        p.setPen(QPen(QColor(black), 1, SolidLine, FlatCap, MiterJoin));
00090        p.drawLine(x-5, y-5, x-1, y-1);
00091        p.drawLine(x-5, y+5, x-1, y+1);
00092        p.drawLine(x+2, y+2, x+6, y+6);
00093        p.drawLine(x+2, y-2, x+6, y-6);
00094        p.end();
00095        Xp = x;
00096        Yp = y;
00097 }
00098 
00099 bool Navigator::SetSeite(int Seite, int Size, QString fn)
00100 {
00101        bool ret = false;
00102        if (!fn.isEmpty())
00103        {
00104               QPixmap img = LoadPDF(fn, Seite, Size, &Breite, &Hoehe);
00105               if (!img.isNull())
00106               {
00107                      pmx = img;
00108                      ret = true;
00109               }
00110               else
00111                      pmx = LoadPDF(fn, 1, Size, &Breite, &Hoehe);
00112        }
00113        else
00114        {
00115               pmx.convertFromImage(view->PageToPixmap(Seite, Size));
00116               ret = true;
00117        }
00118        resize(pmx.width(), pmx.height());
00119        repaint();
00120        return ret;
00121 }