Subversion Repositories Scribus

Rev

Rev 22827 | Rev 23054 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17880 fschmid 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
7
#include "pdfimportoptions.h"
8
#include "ui_pdfimportoptions.h"
9
#include "importpdf.h"
10
#include "ui/createrange.h"
11
#include "usertaskstructs.h"
20185 craig 12
#include "iconmanager.h"
17880 fschmid 13
 
14
PdfImportOptions::PdfImportOptions(QWidget *parent) : QDialog(parent), ui(new Ui::PdfImportOptions)
15
{
16
        ui->setupUi(this);
20185 craig 17
        ui->pageSelectButton->setIcon(IconManager::instance()->loadIcon("ellipsis.png"));
22527 craig 18
        m_plugin = nullptr;
17880 fschmid 19
        m_maxPage = 0;
17885 fschmid 20
        m_resized = false;
17880 fschmid 21
}
22
 
23
PdfImportOptions::~PdfImportOptions()
24
{
25
        delete ui;
26
}
27
 
17885 fschmid 28
void PdfImportOptions::resizeEvent(QResizeEvent *e)
29
{
30
        m_resized = true;
31
        QDialog::resizeEvent(e);
32
}
33
 
34
void PdfImportOptions::paintEvent(QPaintEvent *e)
35
{
36
        if (m_resized)
37
                updatePreview(ui->pgSelect->getCurrentPage());
38
        m_resized = false;
39
        QDialog::paintEvent(e);
40
}
41
 
17880 fschmid 42
QString PdfImportOptions::getPagesString()
43
{
44
        if (ui->allPages->isChecked())
45
                return "*";
46
        if (ui->singlePage->isChecked())
47
                return QString("%1").arg(ui->spinBox->value());
48
        return ui->pageRangeString->text();
49
}
50
 
18004 fschmid 51
int PdfImportOptions::getCropBox()
52
{
53
        int ret = 0;
54
        if (ui->cropGroup->isChecked())
55
                ret = ui->cropBox->currentIndex();
56
        return ret;
57
}
58
 
20125 fschmid 59
bool PdfImportOptions::croppingEnabled()
60
{
61
        return ui->cropGroup->isChecked();
62
}
63
 
22635 craig 64
void PdfImportOptions::setUpOptions(const QString& fileName, int actPage, int numPages, bool interact, bool cropPossible, PdfPlug* plug)
17880 fschmid 65
{
66
        m_plugin = plug;
17885 fschmid 67
        ui->fileLabel->setText(fileName);
17880 fschmid 68
        ui->spinBox->setMaximum(numPages);
69
        ui->spinBox->setMinimum(actPage);
70
        ui->spinBox->setValue(actPage);
18006 fschmid 71
        ui->cropGroup->setVisible(cropPossible);
72
        ui->cropGroup->setChecked(cropPossible);
22836 jghali 73
        ui->cropBox->setCurrentIndex(3); // Use CropBox by default
17880 fschmid 74
        if (interact)
75
        {
76
                ui->allPages->setChecked(false);
77
                ui->selectedPages->setChecked(false);
78
                ui->allPages->setEnabled(false);
79
                ui->selectedPages->setEnabled(false);
80
                ui->singlePage->setChecked(true);
81
                ui->spinBox->setEnabled(true);
82
        }
83
        else
84
                ui->allPages->setChecked(true);
85
        ui->pageRangeString->setText("");
86
        ui->pgSelect->setMaximum(numPages);
18979 jghali 87
        ui->pgSelect->setGUIForPage(actPage - 1);
17880 fschmid 88
        m_maxPage = numPages;
89
        updatePreview(actPage);
90
        connect(ui->pgSelect, SIGNAL(GotoPage(int)), this, SLOT(updatePreview(int)));
17885 fschmid 91
        connect(ui->spinBox, SIGNAL(valueChanged(int)), this, SLOT(updateFromSpinBox(int)));
17880 fschmid 92
        connect(ui->spinBox, SIGNAL(valueChanged(int)), this, SLOT(updatePreview(int)));
93
        connect(ui->pageSelectButton, SIGNAL(clicked()), this, SLOT(createPageNumberRange()));
18004 fschmid 94
        connect(ui->cropGroup, SIGNAL(clicked()), this, SLOT(updateFromCrop()));
95
        connect(ui->cropBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateFromCrop()));
17880 fschmid 96
}
97
 
18004 fschmid 98
void PdfImportOptions::updateFromCrop()
99
{
100
        updatePreview(ui->pgSelect->getCurrentPage());
101
}
17885 fschmid 102
 
103
void PdfImportOptions::updateFromSpinBox(int pg)
104
{
18979 jghali 105
        ui->pgSelect->setGUIForPage(pg - 1);
17885 fschmid 106
}
107
 
17880 fschmid 108
void PdfImportOptions::updatePreview(int pg)
109
{
22827 jghali 110
        if (!m_plugin)
111
                return;
112
 
113
        int cb = 0;
114
        if (ui->cropGroup->isChecked())
115
                cb =  ui->cropBox->currentIndex();
116
        QImage img = m_plugin->readPreview(pg, ui->previewWidget->width(), ui->previewWidget->height(), cb);
117
        ui->previewWidget->setPixmap(QPixmap::fromImage(img));
118
        disconnect(ui->spinBox, SIGNAL(valueChanged(int)), this, SLOT(updateFromSpinBox(int)));
119
        disconnect(ui->spinBox, SIGNAL(valueChanged(int)), this, SLOT(updatePreview(int)));
120
        ui->spinBox->setValue(pg);
121
        connect(ui->spinBox, SIGNAL(valueChanged(int)), this, SLOT(updateFromSpinBox(int)));
122
        connect(ui->spinBox, SIGNAL(valueChanged(int)), this, SLOT(updatePreview(int)));
17880 fschmid 123
}
124
 
125
void PdfImportOptions::createPageNumberRange()
126
{
127
        CreateRange cr(ui->pageRangeString->text(), m_maxPage, this);
128
        if (cr.exec())
129
        {
130
                CreateRangeData crData;
131
                cr.getCreateRangeData(crData);
132
                ui->pageRangeString->setText(crData.pageRange);
133
        }
134
}