QList<QPrinterInfo> QPrinterInfo::availablePrinters()
{
    QList<QPrinterInfo> printers;

    DWORD needed = 0;
    DWORD returned = 0;
    if (!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, 0, 0, &needed, &returned)) {
        LPBYTE buffer = new BYTE[needed];
        if (EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, buffer, needed, &needed, &returned)) {
            PPRINTER_INFO_4 infoList = reinterpret_cast<PPRINTER_INFO_4>(buffer);
            QPrinterInfo defPrn = defaultPrinter();
            for (uint i = 0; i < returned; ++i) {
                QString printerName(QString::fromWCharArray(infoList[i].pPrinterName));

                QPrinterInfo printerInfo(printerName);
                if (printerInfo.printerName() == defPrn.printerName())
                    printerInfo.d_ptr->isDefault = true;
                printers.append(printerInfo);
            }
        }
        delete [] buffer;
    }

    return printers;
}
Exemple #2
0
QPageSize::PageSizeId KReportPageSize::defaultSize()
{
    QPrinterInfo printerInfo = QPrinterInfo::defaultPrinter();
    QPageSize size = printerInfo.defaultPageSize();
    if (size.isValid()) {
        return size.id();
    }
    return QPageSize::A4;
}
Exemple #3
0
int main(int argc, char *argv[])
{

    QCoreApplication a(argc, argv);

//    HelloWorld helloWorld;
//    HelloWorld helloWorld2;
//    HelloWorld helloWorld3;
//
//    QThread t;
//    QThread t2;
//    QThread t3;
//
//    helloWorld.moveToThread(&t);
//    helloWorld2.moveToThread(&t2);
//    helloWorld3.moveToThread(&t3);
////
//    a.connect(&t2, SIGNAL(started()), &helloWorld2, SLOT(sayGoodBye()));
//    a.connect(&t, SIGNAL(started()), &helloWorld, SLOT(sayHello()));
//    a.connect(&t3, SIGNAL(started()), &helloWorld3, SLOT(sayHello()));
//    a.connect(&helloWorld, SIGNAL( done() ), &a, SLOT( quit() ), Qt::QueuedConnection);
//
//    t.start();
//    t2.start();
//    t3.start();

    Foo f1;
    Foo f2;

    f1.AddItem(0,"Hiya!");
    printf("\nSize: %4i",f1.getLength());

    f1.AddItem(1,"Hiya!");
    printf("\nSize: %4i",f1.getLength());

    f2.AddItem(2,"Heya");
    printf("\nSize: %4i",f2.getLength());

    f2.AddItem(3,"Heya");
    printf("\nSize: %4i",f2.getLength());
    printf("\nSize: %4i",f1.getLength());

    printf("\n%s",Foo::doWonky(0).toAscii().data());
    printf("\n%s",Foo::doWonky(1).toAscii().data());
    printf("\n%s",Foo::doWonky(2).toAscii().data());
    printf("\n%s",Foo::doWonky(3).toAscii().data());


    fprintf(stdout, "\nStarting up... 0x%08x\n",&a);

    QPrinterInfo pInfo = QPrinterInfo::defaultPrinter();

    fprintf(stdout, "\n %s\n",pInfo.printerName().toAscii().data());


    return a.exec();
}
Exemple #4
0
QString RSettings::getDefaultPrinterName() {
#if QT_VERSION >= 0x050300
    return QPrinterInfo::defaultPrinterName();
#else
    QPrinterInfo printer = QPrinterInfo::defaultPrinter();
    if (printer.isNull()) {
        return QString();
    }
    return printer.printerName();
#endif
}
Exemple #5
0
printOptions::printOptions(QWidget* parent, const char* name, bool modal, Qt::WFlags fl)
    : XDialog(parent, name, modal, fl)
{
  setupUi(this);

  connect(_buttonBox, SIGNAL(accepted()), this, SLOT(sSave()));
  connect(_printerGroup, SIGNAL(toggled(bool)), this, SLOT(sHandleCheckbox()));

  QPrinterInfo pinfo;
  QList<QPrinterInfo> plist = pinfo.availablePrinters();
  for (int i = 0; i < plist.size(); ++i)
     _printers->addItem(plist.at(i).printerName());
}
bool PrinterUtil::getPrinterMarginValues(const QString& printerName, const QString& pageSize, double& ptsTopMargin, double& ptsBottomMargin, double& ptsLeftMargin, double& ptsRightMargin)
{
	bool retVal = false;
	QPrinterInfo pInfo = QPrinterInfo::printerInfo(printerName);
	if (!pInfo.isNull())
	{
		QPrinter printer(pInfo, QPrinter::HighResolution);
		QMarginsF margs = printer.pageLayout().margins(QPageLayout::Point);
		ptsTopMargin = margs.top();
		ptsBottomMargin = margs.bottom();
		ptsLeftMargin = margs.left();
		ptsRightMargin = margs.right();
		retVal = true;
	}
	return retVal;
}
static PyObject *meth_QPrinterInfo_printerName(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QPrinterInfo *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QPrinterInfo, &sipCpp))
        {
            QString *sipRes;

            Py_BEGIN_ALLOW_THREADS
            sipRes = new QString(sipCpp->printerName());
            Py_END_ALLOW_THREADS

            return sipConvertFromNewType(sipRes,sipType_QString,NULL);
        }
    }
Exemple #8
0
QDebug operator<<(QDebug debug, const QPrinterInfo &p)
{
    QDebugStateSaver saver(debug);
    debug.nospace();
    debug << "QPrinterInfo(";
    if (p.isNull())
        debug << "null";
    else
        p.d_ptr->m_printDevice.format(debug);
    debug << ')';
    return debug;
}
Exemple #9
0
/* prepareGeneralSettings()
 * Called : By selectFunction()
 * Performs : Sets up the General Settings Tab
 */
void Settings::prepareGeneralSettings()
{
    flag[5]=true;

    //once flag is set we need not have the signals as
    //the settings are saved only at ok
    disconnect(printersCombo,SIGNAL(currentIndexChanged( const QString &)),this,
               SLOT(setPrinterFlag( const QString&)));
    databaseRB->setChecked(settings->value("general/mode",true).toBool());
    manualRB->setChecked(!settings->value("general/mode",false).toBool());

    QList<QPrinterInfo> plist;
    QPrinterInfo pinfo;
    plist=pinfo.availablePrinters();

    QStringList printers;
    for(int i=0;i<plist.size();i++)
        printers<<plist[i].printerName();
    int index=printers.indexOf( settings->value("general/printer","Unavailable").toString());

    QString temp,dprinter=pinfo.defaultPrinter().printerName();
    temp=dprinter;
    //highlighting default printer
    temp+="(Default)";
    printers.replace(printers.indexOf(dprinter),temp);
    //inserting all the printers
    printersCombo->insertItems(0,printers);

    //checking whether the current printer is there in the list newly generated
    //if not there show a msg saying "No printer assigned"
    if(index==-1)
    {
        printersCombo->insertItem(0,"No Printer Assigned");
        QMessageBox::information(this,"DocmaQ Settings","No Printer Assingned.Select a printer from the Available Printers ");
    }
    else
        printersCombo->setCurrentIndex(index);

    connect(printersCombo,SIGNAL(currentIndexChanged( const QString &)),this,SLOT(setPrinterFlag( const QString&)),Qt::UniqueConnection);
}
Exemple #10
0
void QCupsPrintEnginePrivate::closePrintDevice()
{
    QPdfPrintEnginePrivate::closePrintDevice();

    if (!cupsTempFile.isEmpty()) {
        QString tempFile = cupsTempFile;
        cupsTempFile.clear();
        QCUPSSupport cups;

        // Set up print options.
        QByteArray prnName;
        QList<QPair<QByteArray, QByteArray> > options;
        QVector<cups_option_t> cupsOptStruct;

        if (!printerName.isEmpty()) {
            prnName = printerName.toLocal8Bit();
        } else {
            QPrinterInfo def = QPrinterInfo::defaultPrinter();
            if (def.isNull()) {
                qWarning("Could not determine printer to print to");
                QFile::remove(tempFile);
                return;
            }
            prnName = def.printerName().toLocal8Bit();
        }

        if (!cupsStringPageSize.isEmpty())
            options.append(QPair<QByteArray, QByteArray>("media", cupsStringPageSize.toLocal8Bit()));

        if (copies > 1)
            options.append(QPair<QByteArray, QByteArray>("copies", QString::number(copies).toLocal8Bit()));

        if (collate)
            options.append(QPair<QByteArray, QByteArray>("Collate", "True"));

        switch (duplex) {
        case QPrinter::DuplexNone:
            options.append(QPair<QByteArray, QByteArray>("sides", "one-sided"));
            break;
        case QPrinter::DuplexAuto:
            if (!landscape)
                options.append(QPair<QByteArray, QByteArray>("sides", "two-sided-long-edge"));
            else
                options.append(QPair<QByteArray, QByteArray>("sides", "two-sided-short-edge"));
            break;
        case QPrinter::DuplexLongSide:
            options.append(QPair<QByteArray, QByteArray>("sides", "two-sided-long-edge"));
            break;
        case QPrinter::DuplexShortSide:
            options.append(QPair<QByteArray, QByteArray>("sides", "two-sided-short-edge"));
            break;
        }

        if (QCUPSSupport::cupsVersion() >= 10300 && landscape)
            options.append(QPair<QByteArray, QByteArray>("landscape", ""));

        QStringList::const_iterator it = cupsOptions.constBegin();
        while (it != cupsOptions.constEnd()) {
            options.append(QPair<QByteArray, QByteArray>((*it).toLocal8Bit(), (*(it+1)).toLocal8Bit()));
            it += 2;
        }

        for (int c = 0; c < options.size(); ++c) {
            cups_option_t opt;
            opt.name = options[c].first.data();
            opt.value = options[c].second.data();
            cupsOptStruct.append(opt);
        }

        // Print the file.
        cups_option_t* optPtr = cupsOptStruct.size() ? &cupsOptStruct.first() : 0;
        cups.printFile(prnName.constData(), tempFile.toLocal8Bit().constData(),
                title.toLocal8Bit().constData(), cupsOptStruct.size(), optPtr);

        QFile::remove(tempFile);
    }
}
Exemple #11
0
               + "<font size=\"+2\">" + QString::number(m_totalcost, 'g', 6) + "</font>&nbsp;&nbsp;&nbsp;&nbsp;"
               + QObject::tr("总项数: &nbsp;&nbsp;") + "<font size=\"+1\">" + QString::number(m_totalitems, 'g', 6) + "</font></div>";
    m_html += "<div align=\"center\">" + QObject::tr("预收: &nbsp;&nbsp;") + "<font size=\"+2\">" + QString::number(m_totalget, 'g', 6) + "</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
               + QObject::tr("找零: &nbsp;&nbsp;") + "<font size=\"+2\">" + QString::number(m_totalget-m_totalcost, 'g', 6) + "</font></div>";
    m_html += "<p align=\"center\">" + QObject::tr("*淘米欢迎您再次光临*") + "</p>";
    m_html += "<div align=\"center\">" + QObject::tr("服务热线:&nbsp;&nbsp;88888888") + "</div>";

    //debug: to get the html content
    qDebug(m_html.toUtf8());

    //debug: to get available printer in local area
    QString m_printers = Printer::printerList();
    qDebug(m_printers.toUtf8());

    //find the wanted network printer to print
    QPrinterInfo printerInfo = QPrinterInfo();
    QPrinterInfo targetPrinterInfo = QPrinterInfo();

    foreach(QPrinterInfo item, printerInfo.availablePrinters()){
        if(item.printerName() == QString::fromStdString("HP_LaserJet_P4014.P4015_PCL6:3")){
            //m_printer = new QPrinter(item, QPrinter::HighResolution);
            targetPrinterInfo = item;
            qDebug(targetPrinterInfo.printerName().toUtf8());
            break;
        }else{
            qDebug("nothing!!!");
        }
    }

    //QPrinter m_printer(targetPrinterInfo, QPrinter::HighResolution);
    QPrinter  m_printer(QPrinter::HighResolution);
Exemple #12
0
/*
static Receipts::ReceiptsPlugin *receiptsPlugin()
{
	qff::MainWindow *fwk = qff::MainWindow::frameWork();
	auto *ret = qobject_cast<Receipts::ReceiptsPlugin *>(fwk->plugin("Receipts"));
	QF_ASSERT(ret != nullptr, "Bad plugin", return 0);
	return ret;
}
*/
void ReceiptsPrinter::printReceipt(const QString &report_file_name, const QVariantMap &report_data)
{
	qfLogFuncFrame();
	QF_TIME_SCOPE("ReceiptsPrinter::printReceipt()");
	const ReceiptsPrinterOptions &printer_opts = m_printerOptions;
	QPrinter *printer = nullptr;
	QPaintDevice *paint_device = nullptr;
	if(printer_opts.printerType() == (int)ReceiptsPrinterOptions::PrinterType::GraphicPrinter) {
		QF_TIME_SCOPE("init graphics printer");
		QPrinterInfo pi = QPrinterInfo::printerInfo(printer_opts.graphicsPrinterName());
		if(pi.isNull()) {
			for(auto s : QPrinterInfo::availablePrinterNames()) {
				qfInfo() << "available printer:" << s;
			}
			pi = QPrinterInfo::defaultPrinter();
		}
		if(pi.isNull()) {
			qfWarning() << "Default printer not set";
			return;
		}
		qfInfo() << "printing on:" << pi.printerName();
		printer = new QPrinter(pi);
		paint_device = printer;
	}
	else {
		qfInfo() << "printing on:" << printer_opts.characterPrinterModel() << "at:" << printer_opts.characterPrinterDevice();
		qff::MainWindow *fwk = qff::MainWindow::frameWork();
		paint_device = fwk;
	}
	qf::qmlwidgets::reports::ReportProcessor rp(paint_device);
	{
		QF_TIME_SCOPE("setting report and data");
		rp.setReport(report_file_name);
		for(auto key : report_data.keys()) {
			rp.setTableData(key, report_data.value(key));
		}
	}
	if(printer_opts.printerType() == (int)ReceiptsPrinterOptions::PrinterType::GraphicPrinter) {
		QF_TIME_SCOPE("process graphics");
		{
			QF_TIME_SCOPE("process report");
			rp.process();
		}
		qf::qmlwidgets::reports::ReportItemMetaPaintReport *doc;
		{
			QF_TIME_SCOPE("getting processor output");
			doc = rp.processorOutput();
		}
		qf::qmlwidgets::reports::ReportItemMetaPaint *it = doc->child(0);
		if(it) {
			QF_TIME_SCOPE("draw meta-paint");
			qf::qmlwidgets::reports::ReportPainter painter(paint_device);
			painter.drawMetaPaint(it);
		}
		QF_SAFE_DELETE(printer);
	}
	else if(printer_opts.printerType() == (int)ReceiptsPrinterOptions::PrinterType::CharacterPrinter) {
		QDomDocument doc;
		doc.setContent(QLatin1String("<?xml version=\"1.0\"?><report><body/></report>"));
		QDomElement el_body = doc.documentElement().firstChildElement("body");
		qf::qmlwidgets::reports::ReportProcessor::HtmlExportOptions opts;
		opts.setConvertBandsToTables(false);
		rp.processHtml(el_body, opts);
		//qfInfo() << doc.toString();
		QList<QByteArray> data_lines = createPrinterData(el_body, printer_opts);
		auto save_file = [data_lines](const QString &fn) {
			QFile f(fn);
			if(f.open(QFile::WriteOnly)) {
				for(QByteArray ba : data_lines) {
					f.write(ba);
					f.write("\n");
				}
			}
			else {
				qfError() << "Cannot open file" << f.fileName() << "for writing!";
			}
		};
		if(!printer_opts.characterPrinterDirectory().isEmpty()) {
			QString fn = printer_opts.characterPrinterDirectory();
			qf::core::utils::FileUtils::ensurePath(fn);
			QCryptographicHash ch(QCryptographicHash::Sha1);
			for(QByteArray ba : data_lines)
				ch.addData(ba);
			fn += '/' + QString::fromLatin1(ch.result().toHex().mid(0, 8)) + ".txt";
			save_file(fn);
		}
		else if (!printer_opts.characterPrinterDevice().isEmpty()) {
			save_file(printer_opts.characterPrinterDevice());
		}
	}
}