filters

kis_pdf_import_widget.cpp
1/*
2 * Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#include "kis_pdf_import_widget.h"
21
22// poppler's headers
23#include <poppler-qt.h>
24
25// TQt's headers
26#include <tqradiobutton.h>
27
28// KDE's headers
29#include <kdebug.h>
30#include <tdelistbox.h>
31#include <knuminput.h>
32
33KisPDFImportWidget::KisPDFImportWidget(Poppler::Document* pdfDoc, TQWidget * parent, const char * name)
34 : PDFImportWidgetBase(parent, name), m_pdfDoc(pdfDoc)
35{
36 m_pages.push_back(0); // The first page is selected
37 updateMaxCanvasSize();
38
39 for(int i = 1; i <= m_pdfDoc->getNumPages(); i++)
40 {
41 listPages->insertItem(TQString::number( i ) );
42 }
43
44 connect(intWidth, TQ_SIGNAL( valueChanged ( int ) ), this, TQ_SLOT( updateHRes() ) );
45 connect(intHeight, TQ_SIGNAL( valueChanged ( int ) ), this, TQ_SLOT( updateHVer() ) );
46 connect(intHorizontal, TQ_SIGNAL( valueChanged ( int ) ), this, TQ_SLOT( updateWidth() ) );
47 connect(intVertical, TQ_SIGNAL( valueChanged ( int ) ), this, TQ_SLOT( updateHeight() ) );
48 connect(boolAllPages, TQ_SIGNAL( toggled ( bool ) ), this, TQ_SLOT( selectAllPages( bool ) ) );
49 connect(boolFirstPage, TQ_SIGNAL( toggled ( bool ) ), this, TQ_SLOT( selectFirstPage( bool ) ) );
50 connect(boolSelectionPage, TQ_SIGNAL( toggled ( bool ) ), this, TQ_SLOT( selectSelectionOfPages( bool ) ) );
51 connect(listPages, TQ_SIGNAL(selectionChanged () ), this, TQ_SLOT(updateSelectionOfPages()));
52}
53
54
55KisPDFImportWidget::~KisPDFImportWidget()
56{
57}
58
59void KisPDFImportWidget::selectAllPages(bool v)
60{
61 if(v)
62 {
63 m_pages.clear();
64 for(int i = 0; i < m_pdfDoc->getNumPages(); i++)
65 {
66 m_pages.push_back(i);
67 }
68 updateMaxCanvasSize();
69 }
70}
71void KisPDFImportWidget::selectFirstPage(bool v)
72{
73 if(v)
74 {
75 m_pages.clear();
76 m_pages.push_back(0); // The first page is selected
77 }
78}
79void KisPDFImportWidget::selectSelectionOfPages(bool v)
80{
81 if(v)
82 {
83 updateSelectionOfPages();
84 updateMaxCanvasSize();
85 }
86
87}
88
89void KisPDFImportWidget::updateSelectionOfPages()
90{
91 if(! boolSelectionPage->isChecked ()) boolSelectionPage->toggle();
92 m_pages.clear();
93 for(int i = 0; i < m_pdfDoc->getNumPages(); i++)
94 {
95 if(listPages->isSelected(i)) m_pages.push_back(i);
96 }
97}
98
99
100void KisPDFImportWidget::updateMaxCanvasSize() {
101 m_maxWidthInch = 0., m_maxHeightInch =0.;
102 for(TQValueList<int>::const_iterator it = m_pages.begin(); it != m_pages.end(); ++it)
103 {
104 Poppler::Page *p = m_pdfDoc->getPage(*it );
105 TQSize size = p->pageSize();
106 if(size.width() > m_maxWidthInch)
107 {
108 m_maxWidthInch = size.width();
109 }
110 if(size.height() > m_maxHeightInch)
111 {
112 m_maxHeightInch = size.height();
113 }
114 }
115 m_maxWidthInch /= 72.;
116 m_maxHeightInch /= 72.;
117 kdDebug() << m_maxWidthInch << " " << m_maxHeightInch << endl;
118 updateWidth();
119 updateHeight();
120}
121
122void KisPDFImportWidget::updateWidth()
123{
124 intWidth->blockSignals(true);
125 intWidth->setValue( (int) m_maxWidthInch * intHorizontal->value() + 1 );
126 intWidth->blockSignals(false);
127}
128void KisPDFImportWidget::updateHeight()
129{
130 intHeight->blockSignals(true);
131 intHeight->setValue( (int) m_maxHeightInch * intVertical->value() + 1 );
132 intHeight->blockSignals(false);
133}
134void KisPDFImportWidget::updateHRes()
135{
136 intHorizontal->blockSignals(true);
137 intHorizontal->setValue( (int) (intWidth->value() / m_maxWidthInch ) );
138 intHorizontal->blockSignals(false);
139}
140void KisPDFImportWidget::updateHVer()
141{
142 intVertical->blockSignals(true);
143 intVertical->setValue( (int) (intHeight->value() / m_maxHeightInch ) );
144 intVertical->blockSignals(false);
145}
146
147#include "kis_pdf_import_widget.moc"