Back to index

texmacs  1.0.7.15
QTMPrintDialog.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * MODULE     : QTMPrintDialog.cpp
00003  * DESCRIPTION: 
00004  * COPYRIGHT  : (C) 2010 Miguel de Benito Delgado
00005  *******************************************************************************
00006  * This software falls under the GNU general public license version 3 or later.
00007  * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00008  * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00009  ******************************************************************************/
00010 
00011 #include "QTMPrintDialog.hpp"
00012 
00024 QTMPrintDialog::QTMPrintDialog(QTMPrinterSettings* s, QDialog* parent) 
00025   : QDialog(parent), _settings(s) {
00026     
00027   setupUi(this);
00028     
00029   QObject::connect(_settings, SIGNAL(doneReading()), 
00030                    this, SLOT(updatePrinterCapabilities()));
00031   QObject::connect(printerCombo, SIGNAL(currentIndexChanged(const QString)),
00032                    _settings, SLOT(startReadingSystemConfig(const QString&)));
00033     
00034 
00035 }
00036 
00037 
00045 void
00046 QTMPrintDialog::updatePrinterCapabilities() {
00047   int idx = 0;
00048   
00049   paperSizeCombo->clear();
00050   paperSizeCombo->addItems(_settings->getChoices(QTMPrinterSettings::PageSize, idx));
00051   paperSizeCombo->setCurrentIndex(idx);
00052   paperSizeLabel->setEnabled(paperSizeCombo->count() > 1);
00053   paperSizeCombo->setEnabled(paperSizeCombo->count() > 1);
00054 
00055   resolutionCombo->clear();
00056   resolutionCombo->addItems(_settings->getChoices(QTMPrinterSettings::Resolution, idx));
00057   resolutionCombo->setCurrentIndex(idx);
00058   resolutionLabel->setEnabled(resolutionCombo->count() > 1);
00059   resolutionCombo->setEnabled(resolutionCombo->count() > 1);
00060 
00061   if (_settings->getChoices(QTMPrinterSettings::Duplex, idx).size() > 1) {
00062     duplexCheck->setEnabled(true);
00063   } else {
00064     duplexCheck->setEnabled(false);
00065     duplexCheck->setChecked(false);
00066   }
00067   
00068   blackWhiteCheck->setEnabled(_settings->getChoices(QTMPrinterSettings::ColorModel, 
00069                                                     idx).size() > 1);
00070 }
00071 
00077 void
00078 QTMPrintDialog::setupUi(QDialog *dia) {
00079 
00080   Ui::QTMPrintDialog::setupUi(dia);
00081   typedef QPair<QString, QString> printerPair;
00082   foreach (printerPair printer, _settings->availablePrinters())
00083     printerCombo->addItem(printer.first, printer.second);
00084   
00085   if(printerCombo->count() == 0)
00086     printerCombo->addItem("No printers available"); // TODO hide everything else
00087 
00088   // We use the QVariant field to retrieve the correct value later.
00089   orientationCombo->addItem("Portrait", QTMPrinterSettings::Portrait);
00090   orientationCombo->addItem("Landscape", QTMPrinterSettings::Landscape);
00091   orientationCombo->addItem("Reverse portrait", QTMPrinterSettings::ReversePortrait);
00092   orientationCombo->addItem("Reverse landscape", QTMPrinterSettings::ReverseLandscape);
00093   
00094   // We use the QVariant field to retrieve the correct value later.
00095   orderPagesCombo->addItem("Left-Right, Top-Bottom", QTMPrinterSettings::LR_TB);
00096   orderPagesCombo->addItem("Right-Left, Top-Bottom", QTMPrinterSettings::RL_TB);
00097   orderPagesCombo->addItem("Top-Bottom, Left-Right", QTMPrinterSettings::TB_LR);
00098   orderPagesCombo->addItem("Top-Bottom, Right-Left", QTMPrinterSettings::TB_RL);  
00099   orderPagesCombo->addItem("Left-Right, Bottom-Top", QTMPrinterSettings::LR_BT);
00100   orderPagesCombo->addItem("Right-Left, Bottom-Top", QTMPrinterSettings::RL_BT);
00101   orderPagesCombo->addItem("Bottom-Top, Left-Right", QTMPrinterSettings::BT_LR);
00102   orderPagesCombo->addItem("Bottom-Top, Right-Left", QTMPrinterSettings::BT_RL);
00103   
00104   // Force reading the printer settings for the first printer in the list. 
00105   _settings->startReadingSystemConfig(printerCombo->currentText());
00106 }
00107 
00108 
00113 void 
00114 QTMPrintDialog::accept() {
00115   
00116   _settings->printerName   = printerCombo->currentText();
00117   _settings->copyCount     = copiesInput->text().toInt();
00118   _settings->collateCopies = collatedCheck->isChecked();
00119   
00120   if (allPagesRadio->isChecked())
00121     _settings->firstPage = _settings->lastPage = 0;
00122   else {
00123     _settings->firstPage   = fromPageInput->text().toInt();
00124     _settings->lastPage    = toPageInput->text().toInt();  
00125   }
00126   _settings->printOddPages  = oddPagesCheck->isChecked();
00127   _settings->printEvenPages = evenPagesCheck->isChecked();
00128   _settings->paperSize      = paperSizeCombo->currentText();
00129   _settings->orientation    = (QTMPrinterSettings::PageOrientation)
00130             orientationCombo->itemData(orderPagesCombo->currentIndex()).toInt();
00131   _settings->duplex         = duplexCheck->isChecked();
00132   _settings->blackWhite     = blackWhiteCheck->isChecked();
00133   _settings->pagesPerSide   = pagesPerSideCombo->currentText().toInt();
00134   _settings->pagesOrder     = (QTMPrinterSettings::PagePrintingOrder) 
00135              orderPagesCombo->itemData(orderPagesCombo->currentIndex()).toInt();
00136   _settings->fitToPage      = fitToPageCheck->isChecked();
00137   _settings->blackWhite     = blackWhiteCheck->isChecked();
00138   
00139   QDialog::accept();
00140 }
00141 
00145 void QTMPrintDialog::reject()
00146 {
00147   QDialog::reject();
00148 }
00149 
00150 
00152 
00153 
00160 void QTMPrintDialog::on_allPagesRadio_clicked(bool on)
00161 {
00162   if(on) {
00163     fromPageInput->setText("");
00164     toPageInput->setText("");
00165   }
00166   allPagesRadio->setChecked(on);
00167 }
00168 
00172 void QTMPrintDialog::on_rangePagesRadio_clicked(bool on)
00173 {
00174   if (on) {
00175     int f = (_settings->firstPage < 1) ? 1 : _settings->firstPage;
00176     int l = (_settings->lastPage < 1) ? 1 : _settings->lastPage;
00177     fromPageInput->setText(QString("%1").arg(f));
00178     toPageInput->setText(QString("%1").arg(l));
00179   }
00180   rangePagesRadio->setChecked(on);
00181 }
00182 
00183 void QTMPrintDialog::on_copiesInput_textChanged(const QString& text)
00184 {
00185   (void) text;
00186   collatedCheck->setEnabled(text.toInt() > 1);
00187 }
00188 
00189 void QTMPrintDialog::on_fromPageInput_textChanged(const QString& text)
00190 {
00191   (void) text;
00192   if (allPagesRadio->isChecked())
00193     rangePagesRadio->setChecked(true);
00194 }
00195 
00196 void QTMPrintDialog::on_toPageInput_textChanged(const QString& text) {
00197   (void) text;
00198   if (allPagesRadio->isChecked())
00199     rangePagesRadio->setChecked(true);
00200 }
00201 
00202 void QTMPrintDialog::on_oddPagesCheck_stateChanged(int state) {
00203   evenPagesCheck->setEnabled(state == Qt::Checked);
00204 }
00205 
00206 void QTMPrintDialog::on_evenPagesCheck_stateChanged(int state) {
00207   oddPagesCheck->setEnabled(state == Qt::Checked);
00208 }