Exemplo n.º 1
1
AdvancedPdf::PaperSize AdvancedPdf::paperSize(QPrinter::PaperSize paperSize)
{
    QPrinter pr;
    pr.setOutputFormat(QPrinter::PdfFormat);
    pr.setPaperSize(paperSize);
    QSizeF s = pr.paperSize(QPrinter::Point);
    PaperSize p = { qRound(s.width()), qRound(s.height()) };
    return p;
}
Exemplo n.º 2
0
QSizeF QPrinterProto::paperSize(QPrinter::Unit unit) const
{
  QPrinter *item = qscriptvalue_cast<QPrinter*>(thisObject());
  if (item)
    return item->paperSize(unit);
  return QSizeF();
}
Exemplo n.º 3
0
QPrinter::PaperSize QPrinterProto::paperSize() const
{
  QPrinter *item = qscriptvalue_cast<QPrinter*>(thisObject());
  if (item)
    return item->paperSize();
  return QPrinter::Letter;
}
Exemplo n.º 4
0
void ObjectsScene::setGridSize(unsigned size)
{
	if(size >= 20 || grid.style()==Qt::NoBrush)
	{
		QImage grid_img;
		float width, height, x, y;
		int img_w, img_h;
		QSizeF aux_size;
		QPrinter printer;
		QPainter painter;
		QPen pen;

    configurePrinter(&printer);
    aux_size=printer.paperSize(QPrinter::Point);
		aux_size-=page_margins.size();

		//Calculates where the extreme width and height where delimiter lines will be drawn
		width=aux_size.width()/static_cast<float>(size) * size;
		height=aux_size.height()/static_cast<float>(size) * size;

		//Calculates the grid pixmpa size
		img_w=ceil(width/size)*size;
		img_h=ceil(height/size)*size;

		grid_size=size;
		grid_img=QImage(img_w, img_h, QImage::Format_ARGB32);
		grid_img.fill(Qt::white);
		painter.begin(&grid_img);

		if(show_grid)
		{
			pen.setColor(QColor(225, 225, 225));
			painter.setPen(pen);

			//Draws the grid
			for(x=0; x < width; x+=size)
				for(y=0; y < height; y+=size)
					painter.drawRect(QRectF(QPointF(x,y),QPointF(x + size,y + size)));
		}

		//Creates the page delimiter lines
		if(show_page_delim)
		{
			pen.setColor(QColor(75,115,195));
			pen.setStyle(Qt::DashLine);
			pen.setWidthF(1.0f);
			painter.setPen(pen);
			painter.drawLine(width-1, 0,width-1,img_h-1);
			painter.drawLine(0, height-1,img_w-1,height-1);
		}

		painter.end();
		grid.setTextureImage(grid_img);
	}
}
Exemplo n.º 5
0
bool ChequePrinter::print()
{
    // 0. Amount to readable string
    QString amount;
    QStringList vals = Utils::doubleToHumanReadableString(d->_amount);
    if (vals.count() == 0) {
        LOG_ERROR_FOR("ChecquePrinter", "Wrong amount to string values");
    } else {
        amount = vals.at(0) + " " + QLocale().currencySymbol(QLocale::CurrencyDisplayName) + "s";
        if (vals.count() == 2)
            amount += QString(" %1 %2").arg(tkTr(Trans::Constants::AND)).arg(vals.at(1));
    }

    // Method 1. use pdkcompleter
//    Internal::PdfTkWrapper *pdftk = Internal::PdfTkWrapper::instance();
//    if (!pdftk->initialize())
//        return false;
//    pdftk->beginFdfEncoding();
//    pdftk->addFdfValue("date", QLocale().toString(d->_date, QLocale::ShortFormat));
//    pdftk->addFdfValue("lieu", d->_place);
//    pdftk->addFdfValue("ordre", d->_order);

//    pdftk->addFdfValue("montant1", lines.at(0));
//    if (lines.count() >= 2)
//        pdftk->addFdfValue("montant2", lines.at(1));

//    // Amount to translated number
//    QSystemLocale::CurrencyToStringArgument arg;
//    arg.value = d->_amount;
//    QVariant var;
//    var.setValue<QSystemLocale::CurrencyToStringArgument>(arg);
//    pdftk->addFdfValue("num", QString::number(d->_amount, 'f', 2)); //QSystemLocale().query(QSystemLocale::CurrencyToString, var).toString());

//    QString filename = "/Users/eric/Desktop/cheque.pdf";
//    pdftk->endFdfEncoding(filename);
//    pdftk->fillPdfWithFdf(filename, pdftk->getFdfContent(), "/Users/eric/Desktop/test_cheque.pdf", "ISO-8859-1");

//    return true;

    // Method 2. use QPainter/QPrinter
    // try to use the default printer
    QPrintDialog dlg;
    if (dlg.exec()==QDialog::Rejected)
        return false;
    QPrinter *printer = dlg.printer();
//    printer->setPaperSource(QPrinter::PaperSource);
    printer->setFullPage(true);
    printer->setPaperSize(QPrinter::A4);
    printer->setResolution(150);
    printer->setOrientation(QPrinter::Landscape);
    d->_axisHelper.setPageSize(printer->paperRect(), printer->paperSize(QPrinter::Millimeter));

    QPainter painter;
    if (!painter.begin(printer)) { // failed to open file
        qWarning("failed to open file, is it writable?");
        return false;
    }

    painter.save();
    QFont font;
    font.setPointSize(10);
    painter.setFont(font);

    painter.translate(d->_axisHelper.pointToPixels(120, 61));
    // 25,17 pour certains
    // 45,13 pour d'autres
    QRectF amountLines(d->_axisHelper.pointToPixels(45,13), d->_axisHelper.sizeToPixels(90, 10));
    // QRect amountLine2(d->_axisHelper.pointToPixels(10,23), d->size(110, 5));
    QRectF orderLine(d->_axisHelper.pointToPixels(10,28), d->_axisHelper.sizeToPixels(110, 5));

    QRectF numberLine(d->_axisHelper.pointToPixels(133,28), d->_axisHelper.sizeToPixels(41, 10));
    QRectF placeLine(d->_axisHelper.pointToPixels(133,38), d->_axisHelper.sizeToPixels(40, 4));
    QRectF dateLine(d->_axisHelper.pointToPixels(133,42), d->_axisHelper.sizeToPixels(40, 4));

    if (DrawChequeRects) {
        painter.drawRect(amountLines);
        painter.drawRect(orderLine);
        painter.drawRect(numberLine);
        painter.drawRect(placeLine);
        painter.drawRect(dateLine);
    }

    if (amount.count() > 50)
        amount = Utils::lineWrapString(amount, 50);
    amount = QString("****%1****").arg(amount.toUpper());

    QFontMetrics metrics(font);
    while (metrics.width(amount) > amountLines.width() || font.pointSize() == 6) {
        font.setPointSizeF(font.pointSizeF() - .1);
        metrics = QFontMetrics(font);
    }
    painter.setFont(font);
    painter.drawText(amountLines, Qt::AlignLeft, amount);
    font.setPointSize(10);
    painter.setFont(font);

//    QStringList lines = amount.split("\n", QString::SkipEmptyParts);
//    painter.drawText(amountLine1, Qt::AlignLeft | Qt::AlignVCenter, lines.at(0));
//    if (lines.count() >= 2)
//        painter.drawText(amountLine2, Qt::AlignLeft | Qt::AlignVCenter, lines.at(1));
    painter.drawText(orderLine, Qt::AlignLeft | Qt::AlignVCenter, d->_order.toUpper());

    font.setBold(true);
    painter.setFont(font);
    painter.drawText(numberLine, Qt::AlignCenter | Qt::AlignVCenter,
                     QString("****%1****").arg(QLocale().toString(d->_amount, 'f', 2))
                     //.arg(QLocale().toCurrencyString(d->_amount, "*"))
                     );//QString::number(d->_amount, 'f', 2)); //QSystemLocale().query(QSystemLocale::CurrencyToString, var).toString());

    font.setPointSize(10);
    font.setBold(false);
    metrics = QFontMetrics(font);
    d->_place = d->_place.toUpper();
    while (metrics.width(d->_place) > placeLine.width() && font.pointSize() > 6) {
        font.setPointSizeF(font.pointSizeF() - .1);
        metrics = QFontMetrics(font);
    }
    painter.setFont(font);
    painter.drawText(placeLine, Qt::AlignLeft | Qt::AlignVCenter, d->_place);

    font.setPointSize(10);
    painter.setFont(font);
    painter.drawText(dateLine, Qt::AlignLeft | Qt::AlignVCenter, d->_date.toString(Qt::SystemLocaleShortDate)); //QLocale().toString(d->_date, QLocale::ShortFormat));

    painter.restore();
    painter.end();
    return true;
}
Exemplo n.º 6
0
int MUH_DEFTERI_KEBIR_BATCH::CHECK_VAR ( QObject * object )
{
    SQL_QUERY   sql_query ( DB );

    if ( object EQ m_ui->checkbox_hesap_araligi ) {

        if ( m_ui->checkbox_hesap_araligi->isChecked() EQ false ) {

            sql_query.PREPARE_SELECT("muh_hesaplar" , "tam_hesap_kodu,hesap_ismi" , "parent_id = :parent_id");
            sql_query.SET_VALUE(":parent_id" , 0);

            if ( sql_query.SELECT("tam_hesap_kodu ASC" , 0 , 1) > 0 ) {
                sql_query.NEXT();
                m_ui->search_edit_bas_hesabi->SET_TEXT ( sql_query.VALUE(0).toString() );
                m_ui->lineedit_bas_hesap_ismi->setText ( sql_query.VALUE(1).toString() );

            }


            sql_query.PREPARE_SELECT("muh_hesaplar" , "tam_hesap_kodu,hesap_ismi" , "parent_id = :parent_id");
            sql_query.SET_VALUE(":parent_id" , 0);

            if ( sql_query.SELECT("tam_hesap_kodu DESC" , 0 , 1) > 0 ) {
                 sql_query.NEXT();
                m_ui->search_edit_bts_hesabi->SET_TEXT ( sql_query.VALUE(0).toString() );
                m_ui->lineedit_bts_hesap_ismi->setText ( sql_query.VALUE(1).toString() );
            }
            m_ui->frame_hesap_araligi->setDisabled ( true );
        }
        else {
            m_ui->frame_hesap_araligi->setEnabled ( true );
            SET_FOCUS( m_ui->search_edit_bas_hesabi );
        }
    }
    else if ( object EQ m_ui->checkbox_tarih_araligi ) {

        if ( m_ui->checkbox_tarih_araligi->isChecked() EQ false ) {
            m_ui->frame_tarih_araligi->setDisabled ( true );

            m_ui->adakDate_baslangic_tarihi->SET_DATE(MALI_YIL_FIRST_DATE());
            m_ui->adakDate_bitis_tarihi->SET_DATE(MALI_YIL_FIRST_DATE());

        }
        else {
            m_ui->frame_tarih_araligi->setEnabled ( true );
            SET_FOCUS( m_ui->adakDate_baslangic_tarihi);
        }
    }
    else if (object EQ m_ui->combo_box_sayfa_boyutu) {
        int page_id = GET_PAPERSIZE_ENUM ( m_ui->combo_box_sayfa_boyutu->currentText() );
        QPrinter printer;
        printer.setPaperSize((QPrinter::PaperSize)page_id);
        QSizeF size = printer.paperSize(QPrinter::Millimeter);
        m_ui->comma_edit_genisligi->SET_DOUBLE(size.width());
        m_ui->comma_edit_yuksekligi->SET_DOUBLE(size.height());
    }
    else if (object EQ m_ui->comma_edit_genisligi OR m_ui->comma_edit_yuksekligi ) {
        m_ui->combo_box_sayfa_boyutu->setCurrentIndex(-1);
    }
    else if ( object EQ m_ui->adakDate_baslangic_tarihi OR object EQ m_ui->adakDate_bitis_tarihi ) {
        DATE_FRAME_AYARLA ( false );
    }
    else if ( object EQ m_ui->search_edit_bas_hesabi ) {

        sql_query.PREPARE_SELECT("muh_hesaplar" , "hesap_ismi" , "tam_hesap_kodu = :tam_hesap_kodu");
        sql_query.SET_VALUE      ( ":tam_hesap_kodu" , m_ui->search_edit_bas_hesabi->GET_TEXT() );

        if ( sql_query.SELECT() EQ 0 ) {
            MSG_WARNING(  tr("Hesap kodu bulunamadı." ), m_ui->search_edit_bas_hesabi );

            return ADAK_FAIL;
        }
        sql_query.NEXT();

        m_ui->lineedit_bas_hesap_ismi->setText ( sql_query.VALUE(0).toString() );

    }
    else if ( object EQ m_ui->search_edit_bts_hesabi ) {

        sql_query.PREPARE_SELECT("muh_hesaplar" , "hesap_ismi" , "tam_hesap_kodu = :tam_hesap_kodu");
        sql_query.SET_VALUE      ( ":tam_hesap_kodu" , m_ui->search_edit_bts_hesabi->GET_TEXT() );

        if ( sql_query.SELECT() EQ 0 ) {
            MSG_WARNING(  tr ( "Hesap kodu bulunamadı." ), m_ui->search_edit_bts_hesabi );

            return ADAK_FAIL;
        }
        sql_query.NEXT();

        m_ui->lineedit_bts_hesap_ismi->setText ( sql_query.VALUE(0).toString() );
    }
    return ADAK_OK;
}
Exemplo n.º 7
0
int MUH_YEVMIYE_DOKUMU_BATCH::CHECK_VAR ( QObject * object )
{
    if (object EQ m_ui->combo_box_sayfa_boyutu) {
        int page_id = GET_PAPERSIZE_ENUM ( m_ui->combo_box_sayfa_boyutu->currentText() );
        QPrinter printer;
        printer.setPaperSize((QPrinter::PaperSize)page_id);
        QSizeF size = printer.paperSize(QPrinter::Millimeter);
        m_ui->comma_edit_genisligi->SET_DOUBLE(size.width());
        m_ui->comma_edit_sayfa_yuksekligi->SET_DOUBLE(size.height());
    }

    if (object EQ m_ui->comma_edit_genisligi OR m_ui->comma_edit_sayfa_yuksekligi ) {
        m_ui->combo_box_sayfa_boyutu->setCurrentIndex(-1);
    }

    if ( object EQ m_ui->adak_date_bas_tarihi OR object EQ m_ui->adak_date_bts_tarihi ) {
        DATE_FRAME_AYARLA ( false );
    }
    else if ( object EQ m_ui->search_edit_baslangic_yevmiye_no ) {
        QRegExp non_digit ( " ( \\D+ ) " );
        if ( m_ui->search_edit_baslangic_yevmiye_no->GET_TEXT().contains ( non_digit ) EQ true ) {
            MSG_WARNING( tr ( "Yevmiye numarasına rakam dışında bir giriş yapılamaz" ), m_ui->search_edit_baslangic_yevmiye_no );

            return ADAK_FAIL;
        }

        YEVMIYE_NO_FRAME_AYARLA ( false );
    }
    else if ( object EQ m_ui->search_edit_bitis_yevmiye_no  ) {

        QRegExp non_digit ( " (\\D+) " );

        if ( m_ui->search_edit_bitis_yevmiye_no->GET_TEXT().contains ( non_digit ) EQ true ) {
            MSG_WARNING( tr ( "Yevmiye numarasına rakam dışında bir giriş yapılamaz" ), m_ui->search_edit_bitis_yevmiye_no );

            return ADAK_FAIL;
        }

        YEVMIYE_NO_FRAME_AYARLA ( false );
    }

    if ( object EQ m_ui->checkbox_tarih_araligi ) {
        if ( m_ui->checkbox_tarih_araligi->isChecked() EQ false ) {
             m_ui->frame_tarih_araligi->setDisabled ( true );
             m_ui->frame_yevmiye_no_araligi->setEnabled ( true );
             m_ui->checkbox_yvm_no_araligi->setChecked ( true );
             YEVMIYE_NO_FRAME_AYARLA();
        }
        else {
            m_ui->frame_tarih_araligi->setEnabled ( true );
            m_ui->frame_yevmiye_no_araligi->setDisabled ( true );
            m_ui->checkbox_yvm_no_araligi->setChecked ( false );
            DATE_FRAME_AYARLA();
            SET_FOCUS( m_ui->adak_date_bas_tarihi );
        }
    }

    if ( object EQ m_ui->checkbox_sadece_ana_hesaplari_goster ) {
        if (m_ui->checkbox_sadece_ana_hesaplari_goster->isChecked() EQ false ) {
            m_ui->frame_ozet->setDisabled ( true );
            SET_FOCUS( m_ui->search_edit_baslangic_yevmiye_no );
        }
        else {
            m_ui->frame_ozet->setDisabled ( false );
        }
    }

    if ( object EQ m_ui->checkbox_yvm_no_araligi ) {
        if ( m_ui->checkbox_yvm_no_araligi->isChecked() EQ false ) {
             m_ui->search_edit_baslangic_yevmiye_no->SET_TEXT ( "1" );
             m_ui->search_edit_bitis_yevmiye_no->SET_TEXT ( "" );
            m_ui->frame_yevmiye_no_araligi->setDisabled ( true );
            m_ui->frame_tarih_araligi->setEnabled ( true );
            m_ui->checkbox_tarih_araligi->setChecked ( true );
            DATE_FRAME_AYARLA();
        }
        else {
            m_ui->frame_yevmiye_no_araligi->setEnabled ( true );
            m_ui->frame_tarih_araligi->setEnabled ( false );
            m_ui->checkbox_tarih_araligi->setChecked ( false);
            YEVMIYE_NO_FRAME_AYARLA();
            SET_FOCUS( m_ui->search_edit_baslangic_yevmiye_no );
        }
    }
    return ADAK_OK;
}