1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include "PrinterController.h"
#include "PrintRunner.h"
#include "PagePrinter.h"
#include "HerculesStudio.h"
/*
* PrinterController ---> runner -+-> PrinterSocket.connect
* V A V
* | | |
* | +---newData----- +
* |
* +-----------> Printer.print
*/
PrinterController::PrinterController(PrinterItemConstPtr printerItem, PdfPrinterPtr printer) :
mPrinterItem(printerItem), mPrinter(printer), mRunner(NULL)
{
}
PrinterController::~PrinterController()
{
}
void PrinterController::exec()
{
if (mRunner.isNull())
{
mRunner = PrintRunnerPtr(new PrintRunner(mQueue, mPrinterItem, 132*80*2));
connect(mRunner.data(), SIGNAL(newData()), this, SLOT(lineReceived()));
connect(mRunner.data(), SIGNAL(connected()), this, SIGNAL(connected()));
connect(mRunner.data(), SIGNAL(disconnected()), this, SIGNAL(disconnected()));
connect(mRunner.data(), SIGNAL(waiting()), this, SIGNAL(waiting()));
connect(mRunner.data(), SIGNAL(stoppedWaiting()), this, SIGNAL(stoppedWaiting()));
}
mRunner->start();
hOutDebug(0,"Print runner started");
}
void PrinterController::stop()
{
if (!mRunner.isNull()) {
if (mRunner->isRunning())
{
mRunner->stop();
}
for (int i=0; i<10 && !mRunner->isFinished(); i++)
QThread::msleep(50);
mPrinter->close();
}
}
void PrinterController::lineReceived()
{
while(!mQueue.empty())
{
mPrinter->print(mQueue.front());
mQueue.pop_front();
}
}
|