"Fossies" - the Fresh Open Source Software Archive

Member "poppler-0.82.0/qt5/demos/pageview.cpp" (25 Oct 2019, 2770 Bytes) of package /linux/misc/poppler-0.82.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * Copyright (C) 2008-2009, Pino Toscano <pino@kde.org>
    3  * Copyright (C) 2013, Fabio D'Urso <fabiodurso@hotmail.it>
    4  * Copyright (C) 2017, Albert Astals Cid <aacid@kde.org>
    5  *
    6  * This program is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation; either version 2, or (at your option)
    9  * any later version.
   10  *
   11  * This program 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
   14  * GNU General Public License for more details.
   15  *
   16  * You should have received a copy of the GNU General Public License
   17  * along with this program; if not, write to the Free Software
   18  * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
   19  */
   20 
   21 #include "pageview.h"
   22 
   23 #include <poppler-qt5.h>
   24 
   25 #include <QtWidgets/QApplication>
   26 #include <QtWidgets/QDesktopWidget>
   27 #include <QtGui/QImage>
   28 #include <QtWidgets/QLabel>
   29 #include <QtGui/QPixmap>
   30 #include <QDebug>
   31 
   32 PageView::PageView(QWidget *parent)
   33     : QScrollArea(parent)
   34     , m_zoom(1.0)
   35     , m_rotation(0)
   36     , m_dpiX(QApplication::desktop()->physicalDpiX())
   37     , m_dpiY(QApplication::desktop()->physicalDpiY())
   38 {
   39     m_imageLabel = new QLabel(this);
   40     m_imageLabel->resize(0, 0);
   41     setWidget(m_imageLabel);
   42 }
   43 
   44 PageView::~PageView()
   45 {
   46 }
   47 
   48 void PageView::documentLoaded()
   49 {
   50 }
   51 
   52 void PageView::documentClosed()
   53 {
   54     m_imageLabel->clear();
   55     m_imageLabel->resize(0, 0);
   56 }
   57 
   58 void PageView::pageChanged(int page)
   59 {
   60     Poppler::Page *popplerPage = document()->page(page);
   61 
   62     if (!popplerPage) {
   63         qDebug() << "Page" << page << "is malformed";
   64         return;
   65     }
   66     const double resX = m_dpiX * m_zoom;
   67     const double resY = m_dpiY * m_zoom;
   68 
   69     Poppler::Page::Rotation rot;
   70     if (m_rotation == 0)
   71         rot = Poppler::Page::Rotate0;
   72     else if (m_rotation == 90)
   73         rot = Poppler::Page::Rotate90;
   74     else if (m_rotation == 180)
   75         rot = Poppler::Page::Rotate180;
   76     else // m_rotation == 270
   77         rot = Poppler::Page::Rotate270;
   78 
   79     QImage image = popplerPage->renderToImage(resX, resY, -1, -1, -1, -1, rot);
   80     if (!image.isNull()) {
   81         m_imageLabel->resize(image.size());
   82         m_imageLabel->setPixmap(QPixmap::fromImage(image));
   83     } else {
   84         m_imageLabel->resize(0, 0);
   85         m_imageLabel->setPixmap(QPixmap());
   86     }
   87     delete popplerPage;
   88 }
   89 
   90 void PageView::slotZoomChanged(qreal value)
   91 {
   92     m_zoom = value;
   93     if (!document()) {
   94         return;
   95     }
   96     reloadPage();
   97 }
   98 
   99 void PageView::slotRotationChanged(int value)
  100 {
  101     m_rotation = value;
  102     if (!document()) {
  103         return;
  104     }
  105     reloadPage();
  106 }
  107