filters

kis_pdf_import_widget.cpp

00001 /*
00002  *  Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #include "kis_pdf_import_widget.h"
00021 
00022 // poppler's headers
00023 #include <poppler-qt.h>
00024 
00025 // Qt's headers
00026 #include <qradiobutton.h>
00027 
00028 // KDE's headers
00029 #include <kdebug.h>
00030 #include <klistbox.h>
00031 #include <knuminput.h>
00032 
00033 KisPDFImportWidget::KisPDFImportWidget(Poppler::Document* pdfDoc, QWidget * parent, const char * name)
00034     : PDFImportWidgetBase(parent, name), m_pdfDoc(pdfDoc)
00035 {
00036     m_pages.push_back(0); // The first page is selected
00037     updateMaxCanvasSize();
00038     
00039     for(int i = 1; i <= m_pdfDoc->getNumPages(); i++)
00040     {
00041         listPages->insertItem(QString::number( i ) );
00042     }
00043     
00044     connect(intWidth, SIGNAL(  valueChanged ( int ) ), this, SLOT( updateHRes() ) );
00045     connect(intHeight, SIGNAL(  valueChanged ( int ) ), this, SLOT( updateHVer() ) );
00046     connect(intHorizontal, SIGNAL(  valueChanged ( int ) ), this, SLOT( updateWidth() ) );
00047     connect(intVertical, SIGNAL(  valueChanged ( int ) ), this, SLOT( updateHeight() ) );
00048     connect(boolAllPages, SIGNAL(  toggled ( bool ) ), this, SLOT( selectAllPages( bool ) ) );
00049     connect(boolFirstPage, SIGNAL(  toggled ( bool ) ), this, SLOT( selectFirstPage( bool ) ) );
00050     connect(boolSelectionPage, SIGNAL(  toggled ( bool ) ), this, SLOT( selectSelectionOfPages( bool ) ) );
00051     connect(listPages, SIGNAL(selectionChanged () ), this, SLOT(updateSelectionOfPages()));
00052 }
00053 
00054 
00055 KisPDFImportWidget::~KisPDFImportWidget()
00056 {
00057 }
00058 
00059 void KisPDFImportWidget::selectAllPages(bool v)
00060 {
00061     if(v)
00062     {
00063         m_pages.clear();
00064         for(int i = 0; i < m_pdfDoc->getNumPages(); i++)
00065         {
00066             m_pages.push_back(i);
00067         }
00068         updateMaxCanvasSize();
00069     }
00070 }
00071 void KisPDFImportWidget::selectFirstPage(bool v)
00072 {
00073     if(v)
00074     {
00075         m_pages.clear();
00076         m_pages.push_back(0); // The first page is selected
00077     }
00078 }
00079 void KisPDFImportWidget::selectSelectionOfPages(bool v)
00080 {
00081     if(v)
00082     {
00083         updateSelectionOfPages();
00084         updateMaxCanvasSize();
00085     }
00086 
00087 }
00088 
00089 void KisPDFImportWidget::updateSelectionOfPages()
00090 {
00091     if(! boolSelectionPage->isChecked ()) boolSelectionPage->toggle();
00092     m_pages.clear();
00093     for(int i = 0; i < m_pdfDoc->getNumPages(); i++)
00094     {
00095         if(listPages->isSelected(i)) m_pages.push_back(i);
00096     }
00097 }
00098 
00099 
00100 void KisPDFImportWidget::updateMaxCanvasSize() {
00101     m_maxWidthInch = 0., m_maxHeightInch =0.;
00102     for(QValueList<int>::const_iterator it = m_pages.begin(); it != m_pages.end(); ++it)
00103     {
00104         Poppler::Page *p = m_pdfDoc->getPage(*it );
00105         QSize size = p->pageSize();
00106         if(size.width() > m_maxWidthInch)
00107         {
00108             m_maxWidthInch = size.width();
00109         }
00110         if(size.height() > m_maxHeightInch)
00111         {
00112             m_maxHeightInch = size.height();
00113         }
00114     }
00115     m_maxWidthInch /= 72.;
00116     m_maxHeightInch /= 72.;
00117     kdDebug() << m_maxWidthInch << " " << m_maxHeightInch << endl;
00118     updateWidth();
00119     updateHeight();
00120 }
00121 
00122 void KisPDFImportWidget::updateWidth()
00123 {
00124     intWidth->blockSignals(true);
00125     intWidth->setValue( (int) m_maxWidthInch * intHorizontal->value() + 1 );
00126     intWidth->blockSignals(false);
00127 }
00128 void KisPDFImportWidget::updateHeight()
00129 {
00130     intHeight->blockSignals(true);
00131     intHeight->setValue( (int) m_maxHeightInch * intVertical->value() + 1  );
00132     intHeight->blockSignals(false);
00133 }
00134 void KisPDFImportWidget::updateHRes()
00135 {
00136     intHorizontal->blockSignals(true);
00137     intHorizontal->setValue( (int) (intWidth->value() / m_maxWidthInch ) );
00138     intHorizontal->blockSignals(false);
00139 }
00140 void KisPDFImportWidget::updateHVer()
00141 {
00142     intVertical->blockSignals(true);
00143     intVertical->setValue( (int) (intHeight->value() / m_maxHeightInch ) );
00144     intVertical->blockSignals(false);
00145 }
00146 
00147 #include "kis_pdf_import_widget.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys