[1f4adec] | 1 | /* |
---|
| 2 | |
---|
| 3 | Copyright 2012-2013 Adam Reichold |
---|
| 4 | |
---|
| 5 | This file is part of qpdfview. |
---|
| 6 | |
---|
| 7 | qpdfview is free software: you can redistribute it and/or modify |
---|
| 8 | it under the terms of the GNU General Public License as published by |
---|
| 9 | the Free Software Foundation, either version 2 of the License, or |
---|
| 10 | (at your option) any later version. |
---|
| 11 | |
---|
| 12 | qpdfview is distributed in the hope that it will be useful, |
---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | GNU General Public License for more details. |
---|
| 16 | |
---|
| 17 | You should have received a copy of the GNU General Public License |
---|
| 18 | along with qpdfview. If not, see <http://www.gnu.org/licenses/>. |
---|
| 19 | |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #include "printdialog.h" |
---|
| 23 | |
---|
| 24 | #include <QCheckBox> |
---|
| 25 | #include <QComboBox> |
---|
| 26 | #include <QFormLayout> |
---|
| 27 | #include <QLineEdit> |
---|
| 28 | |
---|
| 29 | #include "settings.h" |
---|
| 30 | |
---|
| 31 | namespace qpdfview |
---|
| 32 | { |
---|
| 33 | |
---|
| 34 | Settings* PrintDialog::s_settings = 0; |
---|
| 35 | |
---|
| 36 | QPrinter* PrintDialog::createPrinter() |
---|
| 37 | { |
---|
| 38 | QPrinter* printer = new QPrinter(); |
---|
| 39 | |
---|
| 40 | printer->setCollateCopies(Settings::instance()->printDialog().collateCopies()); |
---|
| 41 | printer->setPageOrder(Settings::instance()->printDialog().pageOrder()); |
---|
| 42 | printer->setOrientation(Settings::instance()->printDialog().orientation()); |
---|
| 43 | printer->setColorMode(Settings::instance()->printDialog().colorMode()); |
---|
| 44 | printer->setDuplex(Settings::instance()->printDialog().duplex()); |
---|
| 45 | |
---|
| 46 | return printer; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | PrintDialog::PrintDialog(QPrinter* printer, QWidget* parent) : QPrintDialog(printer, parent) |
---|
| 50 | { |
---|
| 51 | if(s_settings == 0) |
---|
| 52 | { |
---|
| 53 | s_settings = Settings::instance(); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | // print options |
---|
| 57 | |
---|
| 58 | m_printOptionsWidget = new QWidget(this); |
---|
| 59 | m_printOptionsLayout = new QFormLayout(m_printOptionsWidget); |
---|
| 60 | |
---|
| 61 | m_fitToPageCheckBox = new QCheckBox(this); |
---|
| 62 | m_fitToPageCheckBox->setChecked(s_settings->printDialog().fitToPage()); |
---|
| 63 | |
---|
| 64 | m_printOptionsLayout->addRow(tr("Fit to page:"), m_fitToPageCheckBox); |
---|
| 65 | |
---|
| 66 | m_pageRangesLineEdit = new QLineEdit(this); |
---|
| 67 | |
---|
| 68 | m_printOptionsLayout->addRow(tr("Page ranges:"), m_pageRangesLineEdit); |
---|
| 69 | |
---|
| 70 | #if QT_VERSION < QT_VERSION_CHECK(5,2,0) |
---|
| 71 | |
---|
| 72 | m_pageSetComboBox = new QComboBox(this); |
---|
| 73 | m_pageSetComboBox->addItem(tr("All pages"), static_cast< uint >(PrintOptions::AllPages)); |
---|
| 74 | m_pageSetComboBox->addItem(tr("Even pages"), static_cast< uint >(PrintOptions::EvenPages)); |
---|
| 75 | m_pageSetComboBox->addItem(tr("Odd pages"), static_cast< uint >(PrintOptions::OddPages)); |
---|
| 76 | m_pageSetComboBox->setCurrentIndex(m_pageSetComboBox->findData(static_cast< uint >(s_settings->printDialog().pageSet()))); |
---|
| 77 | |
---|
| 78 | m_printOptionsLayout->addRow(tr("Page set:"), m_pageSetComboBox); |
---|
| 79 | |
---|
| 80 | m_numberUpComboBox = new QComboBox(this); |
---|
| 81 | m_numberUpComboBox->addItem(tr("Single page"), static_cast< uint >(PrintOptions::SinglePage)); |
---|
| 82 | m_numberUpComboBox->addItem(tr("Two pages"), static_cast< uint >(PrintOptions::TwoPages)); |
---|
| 83 | m_numberUpComboBox->addItem(tr("Four pages"), static_cast< uint >(PrintOptions::FourPages)); |
---|
| 84 | m_numberUpComboBox->addItem(tr("Six pages"), static_cast< uint >(PrintOptions::SixPages)); |
---|
| 85 | m_numberUpComboBox->addItem(tr("Nine pages"), static_cast< uint >(PrintOptions::NinePages)); |
---|
| 86 | m_numberUpComboBox->addItem(tr("Sixteen pages"), static_cast< uint >(PrintOptions::SixteenPages)); |
---|
| 87 | m_numberUpComboBox->setCurrentIndex(m_numberUpComboBox->findData(static_cast< uint >(s_settings->printDialog().numberUp()))); |
---|
| 88 | |
---|
| 89 | m_printOptionsLayout->addRow(tr("Number-up:"), m_numberUpComboBox); |
---|
| 90 | |
---|
| 91 | m_numberUpLayoutComboBox = new QComboBox(this); |
---|
| 92 | m_numberUpLayoutComboBox->addItem(tr("Bottom to top and left to right"), static_cast< uint >(PrintOptions::BottomTopLeftRight)); |
---|
| 93 | m_numberUpLayoutComboBox->addItem(tr("Bottom to top and right to left"), static_cast< uint >(PrintOptions::BottomTopRightLeft)); |
---|
| 94 | m_numberUpLayoutComboBox->addItem(tr("Left to right and bottom to top"), static_cast< uint >(PrintOptions::LeftRightBottomTop)); |
---|
| 95 | m_numberUpLayoutComboBox->addItem(tr("Left to right and top to bottom"), static_cast< uint >(PrintOptions::LeftRightTopBottom)); |
---|
| 96 | m_numberUpLayoutComboBox->addItem(tr("Right to left and bottom to top"), static_cast< uint >(PrintOptions::RightLeftBottomTop)); |
---|
| 97 | m_numberUpLayoutComboBox->addItem(tr("Right to left and top to bottom"), static_cast< uint >(PrintOptions::RightLeftTopBottom)); |
---|
| 98 | m_numberUpLayoutComboBox->addItem(tr("Top to bottom and left to right"), static_cast< uint >(PrintOptions::TopBottomLeftRight)); |
---|
| 99 | m_numberUpLayoutComboBox->addItem(tr("Top to bottom and right to left"), static_cast< uint >(PrintOptions::TopBottomRightLeft)); |
---|
| 100 | m_numberUpLayoutComboBox->setCurrentIndex(m_numberUpLayoutComboBox->findData(static_cast< uint >(s_settings->printDialog().numberUpLayout()))); |
---|
| 101 | |
---|
| 102 | m_printOptionsLayout->addRow(tr("Number-up layout:"), m_numberUpLayoutComboBox); |
---|
| 103 | |
---|
| 104 | #endif // QT_VERSION |
---|
| 105 | |
---|
| 106 | m_printOptionsWidget->setWindowTitle(tr("Extended options")); |
---|
| 107 | setOptionTabs(QList< QWidget* >() << m_printOptionsWidget); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | PrintOptions PrintDialog::printOptions() const |
---|
| 111 | { |
---|
| 112 | PrintOptions printOptions; |
---|
| 113 | |
---|
| 114 | printOptions.fitToPage = m_fitToPageCheckBox->isChecked(); |
---|
| 115 | |
---|
| 116 | printOptions.pageRanges = m_pageRangesLineEdit->text(); |
---|
| 117 | |
---|
| 118 | #if QT_VERSION < QT_VERSION_CHECK(5,2,0) |
---|
| 119 | |
---|
| 120 | printOptions.pageSet = static_cast< PrintOptions::PageSet >(m_pageSetComboBox->itemData(m_pageSetComboBox->currentIndex()).toUInt()); |
---|
| 121 | |
---|
| 122 | printOptions.numberUp = static_cast< PrintOptions::NumberUp >(m_numberUpComboBox->itemData(m_numberUpComboBox->currentIndex()).toUInt()); |
---|
| 123 | printOptions.numberUpLayout = static_cast< PrintOptions::NumberUpLayout >(m_numberUpLayoutComboBox->itemData(m_numberUpLayoutComboBox->currentIndex()).toUInt()); |
---|
| 124 | |
---|
| 125 | #endif // QT_VERSION |
---|
| 126 | |
---|
| 127 | return printOptions; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | void PrintDialog::accept() |
---|
| 131 | { |
---|
| 132 | QPrintDialog::accept(); |
---|
| 133 | |
---|
| 134 | s_settings->printDialog().setCollateCopies(printer()->collateCopies()); |
---|
| 135 | s_settings->printDialog().setPageOrder(printer()->pageOrder()); |
---|
| 136 | s_settings->printDialog().setOrientation(printer()->orientation()); |
---|
| 137 | s_settings->printDialog().setColorMode(printer()->colorMode()); |
---|
| 138 | s_settings->printDialog().setDuplex(printer()->duplex()); |
---|
| 139 | |
---|
| 140 | s_settings->printDialog().setFitToPage(m_fitToPageCheckBox->isChecked()); |
---|
| 141 | |
---|
| 142 | #if QT_VERSION < QT_VERSION_CHECK(5,2,0) |
---|
| 143 | |
---|
| 144 | s_settings->printDialog().setPageSet(static_cast< PrintOptions::PageSet >(m_pageSetComboBox->itemData(m_pageSetComboBox->currentIndex()).toUInt())); |
---|
| 145 | |
---|
| 146 | s_settings->printDialog().setNumberUp(static_cast< PrintOptions::NumberUp >(m_numberUpComboBox->itemData(m_numberUpComboBox->currentIndex()).toUInt())); |
---|
| 147 | s_settings->printDialog().setNumberUpLayout(static_cast< PrintOptions::NumberUpLayout >(m_numberUpLayoutComboBox->itemData(m_numberUpLayoutComboBox->currentIndex()).toUInt())); |
---|
| 148 | |
---|
| 149 | #endif // QT_VERSION |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | } // qpdfview |
---|