File indexing completed on 2024-05-19 05:40:36

0001 /***************************************************************************
0002  *  Copyright (C) 2020 by Renaud Guezennec                               *
0003  *   http://www.rolisteam.org/contact                                      *
0004  *                                                                         *
0005  *   This software is free software; you can redistribute it and/or modify *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #include "controller/view_controller/pdfcontroller.h"
0021 
0022 #include "utils/iohelper.h"
0023 
0024 #include <QApplication>
0025 #include <QBuffer>
0026 #include <QClipboard>
0027 
0028 PdfController::PdfController(const QString& id, const QUrl& path, const QByteArray& data, QObject* parent)
0029     : MediaControllerBase(id, Core::ContentType::PDF, parent)
0030 {
0031     if(!path.isEmpty())
0032     {
0033         setData(utils::IOHelper::loadFile(path.toLocalFile()));
0034     }
0035     else if(!data.isEmpty())
0036     {
0037         setData(data);
0038     }
0039 }
0040 
0041 PdfController::~PdfController()= default;
0042 
0043 QByteArray PdfController::data() const
0044 {
0045     return m_data;
0046 }
0047 
0048 QBuffer* PdfController::buffer()
0049 {
0050     return new QBuffer(&m_data);
0051 }
0052 
0053 qreal PdfController::zoomFactor() const
0054 {
0055     return m_zoom;
0056 }
0057 
0058 void PdfController::zoomIn()
0059 {
0060     setZoomFactor(m_zoom + 0.02);
0061 }
0062 
0063 void PdfController::zoomOut()
0064 {
0065     setZoomFactor(m_zoom - 0.02);
0066 }
0067 
0068 void PdfController::setData(const QByteArray& data)
0069 {
0070     if(data == m_data)
0071         return;
0072     m_data= data;
0073     emit dataChanged(m_data);
0074 }
0075 
0076 void PdfController::setZoomFactor(qreal zoom)
0077 {
0078     if(qFuzzyCompare(m_zoom, zoom))
0079         return;
0080 
0081     m_zoom= zoom;
0082     emit zoomFactorChanged(m_zoom);
0083 }
0084 
0085 // void PdfController::shareImageIntoImage(const QPixmap& image) {}
0086 
0087 void PdfController::copyImage(const QPixmap& image)
0088 {
0089     auto clip= QApplication::clipboard();
0090     clip->setPixmap(image, QClipboard::Clipboard);
0091 }
0092 
0093 void PdfController::copyText(const QString& text)
0094 {
0095     // TODO wait to fix it from the view
0096 }
0097 
0098 void PdfController::shareAsPdf()
0099 {
0100     if(!m_data.isEmpty())
0101         emit sharePdf(m_uuid);
0102 }