00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "printwidget.h"
00024
00025
00026 #include <QLineEdit>
00027 #include <QComboBox>
00028 #include <QPushButton>
00029 #include <QLabel>
00030 #include <QProgressBar>
00031 #include <QHBoxLayout>
00032 #include <QVBoxLayout>
00033 #include <QFileDialog>
00034 #include <QSpinBox>
00035
00036
00037 PrintWidget::PrintWidget(QWidget *parent) :
00038 QWidget(parent)
00039 {
00040
00041 filenameEdit = new QLineEdit();
00042 browseButton = new QPushButton( tr("Browse"));
00043 connect(browseButton, SIGNAL(clicked()), this, SLOT(browseFile()));
00044
00045 printerCombo = new QComboBox();
00046 printerCombo->setEnabled(false);
00047
00048 rangeEdit = new QLineEdit();
00049
00050
00051 QRegExpValidator* rangeSensor = new QRegExpValidator( QRegExp("[0-9\\-,]+"), this );
00052 rangeEdit->setValidator( rangeSensor);
00053
00054
00055 copiesSpin = new QSpinBox();
00056 copiesSpin->setRange(1,99);
00057 copiesSpin->setValue(1);
00058
00059
00060 persheetCombo = new QComboBox();
00061 persheetCombo->insertItem(0,"1",1);
00062 persheetCombo->insertItem(1,"2",2);
00063 persheetCombo->insertItem(2,"4",4);
00064
00065 printButton = new QPushButton( tr("Print"));
00066 printButton->setEnabled(false);
00067 connect( printButton, SIGNAL(clicked()), this, SLOT(doPrint()));
00068
00069 statusLabel = new QLabel();
00070 progressBar = new QProgressBar();
00071 progressBar->setRange(0,0);
00072 cancelButton = new QPushButton(tr("Cancel"));
00073 connect(cancelButton,SIGNAL(clicked()),this,SIGNAL(cancel()));
00074
00075 reconnectButton = new QPushButton( tr("Reconnect"));
00076 connect(reconnectButton, SIGNAL(clicked()), this, SIGNAL(reconnect()));
00077
00078
00079 QVBoxLayout* mainLayout = new QVBoxLayout();
00080 QHBoxLayout* fileLayout = new QHBoxLayout();
00081 fileLayout->addWidget( new QLabel( tr ("File") ));
00082 fileLayout->addWidget(filenameEdit);
00083 fileLayout->addWidget(browseButton);
00084 mainLayout->addLayout(fileLayout);
00085
00086 QHBoxLayout* printerLayout = new QHBoxLayout();
00087 printerLayout->addWidget(new QLabel( tr("Printer")));
00088 printerLayout->addWidget(printerCombo);
00089 printerLayout->addStretch();
00090 mainLayout->addLayout(printerLayout);
00091
00092 QHBoxLayout* rangeLayout = new QHBoxLayout();
00093 rangeLayout->addWidget(new QLabel(tr("Page range")));
00094 rangeLayout->addWidget(rangeEdit);
00095 mainLayout->addLayout(rangeLayout);
00096
00097 QHBoxLayout* sheetLayout = new QHBoxLayout();
00098 sheetLayout->addWidget( new QLabel(tr("Pages per sheet")) );
00099 sheetLayout->addWidget(persheetCombo);
00100 sheetLayout->addStretch();
00101 sheetLayout->addWidget(new QLabel(tr("Copies")));
00102 sheetLayout->addWidget(copiesSpin);
00103 mainLayout->addLayout(sheetLayout);
00104
00105 mainLayout->addStretch();
00106
00107 mainLayout->addWidget(statusLabel);
00108 QHBoxLayout* barLayout = new QHBoxLayout;
00109 barLayout->addWidget(progressBar);
00110 barLayout->addStretch();
00111 barLayout->addWidget(cancelButton);
00112 barLayout->addWidget(reconnectButton);
00113 barLayout->addWidget(printButton);
00114 mainLayout->addLayout(barLayout);
00115
00116 setLayout(mainLayout);
00117
00118 progressBar->setVisible(false);
00119
00120 }
00121
00122 void PrintWidget::setStatus(QString message, bool busy)
00123 {
00124 statusLabel->setText(message);
00125 if(busy)
00126 {
00127
00128 progressBar->setVisible(true);
00129 cancelButton->setEnabled(true);
00130 reconnectButton->setEnabled(false);
00131 }
00132 else
00133 {
00134 progressBar->setVisible(false);
00135 reconnectButton->setEnabled(true);
00136 cancelButton->setEnabled(false);
00137 }
00138 }
00139
00140 void PrintWidget::setPrinters(QStringList printers)
00141 {
00142 printerCombo->clear();
00143 if(printers.isEmpty())
00144 {
00145 printerCombo->setEnabled(false);
00146 }
00147 else
00148 {
00149 printerCombo->addItems(printers);
00150 printerCombo->setEnabled(true);
00151 printerCombo->setCurrentIndex(0);
00152 }
00153 }
00154
00155 void PrintWidget::setReady(bool ready)
00156 {
00157 if(ready)
00158 {
00159 setStatus( tr("Ready"), false);
00160 printButton->setEnabled(true);
00161 }
00162 else
00163 printButton->setEnabled(false);
00164 }
00165
00166
00167 void PrintWidget::browseFile()
00168 {
00169 QString path = QFileDialog::getOpenFileName(this, tr("Print file"));
00170 if(!path.isNull())
00171 filenameEdit->setText(path);
00172
00173 }
00174
00175 void PrintWidget::doPrint()
00176 {
00177
00178 QString options = QString("-d %1 -o number-up=").arg(printerCombo->currentText());
00179 options.append(persheetCombo->currentText());
00180 if( !rangeEdit->text().isEmpty())
00181 options += " -o page-ranges=" + rangeEdit->text();
00182 if( copiesSpin->value() > 1)
00183 options += QString(" -n %1").arg(copiesSpin->value());
00184 emit print(filenameEdit->text(), options);
00185 }