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