// $Id: formcover.ui.h,v 1.2 2003/06/15 09:07:39 calicant Exp $ /* * This file is part of Mapagi * Copyright (C) 2003 calicant * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. * * The GNU General Public License is contained in the file COPYING. * * */ #include #include #include #include #include #include #include #include #include #include #include "mapagi.h" void FormCover::pbSetVerso_clicked() { if (lastVisitedDir.isNull() || lastVisitedDir.isEmpty()) lastVisitedDir = QDir::currentDirPath(); else if (!QDir(lastVisitedDir).exists()) lastVisitedDir = QDir::currentDirPath(); QString s = QFileDialog::getOpenFileName( lastVisitedDir, QString::null, this, "setting verso page dialog", "Choose an image file to open" ); if (s.isNull()) return; QFileInfo fi (s); lastVisitedDir = fi.dirPath(TRUE); tlVerso->setPixmap(s); } void FormCover::pbClose_clicked() { accept(); } void FormCover::pbSetFront_clicked() { if (lastVisitedDir.isNull() || lastVisitedDir.isEmpty()) lastVisitedDir = QDir::currentDirPath(); else if (!QDir(lastVisitedDir).exists()) lastVisitedDir = QDir::currentDirPath(); QString s = QFileDialog::getOpenFileName( lastVisitedDir, QString::null, this, "setting front page dialog", "Choose an image file to open" ); if (s.isNull()) return; QFileInfo fi (s); lastVisitedDir = fi.dirPath(TRUE); tlFront->setPixmap(s); } void FormCover::pbPrint_clicked() { if ( ! tlVerso->pixmap() || ! tlFront->pixmap()) { QMessageBox::warning( this, "Printing error", "Please, set an image for back and front cover", QMessageBox::Ok, QMessageBox::NoButton ); return; } if ( tlVerso->pixmap()->isNull() || tlFront->pixmap()->isNull()) { QMessageBox::warning( this, "Printing error", "Please, set an image for back and front cover", QMessageBox::Ok, QMessageBox::NoButton ); return; } QPrinter *printer; printer = new QPrinter; printer->setOutputFileName("mapagi_cover.ps"); printer->setOutputToFile(FALSE); printer->setOrientation(QPrinter::Landscape); printer->setMinMax(1, 1); printer->setResolution(sbDPI->value()); printer->setMargins(5, 5, 5, 5); unsigned int totpages = 0; int nsheet = 1; bool statusabort = false; if (printer->setup(this)) { qApp->processEvents(); QPainter pp; if (!pp.begin(printer)) { qDebug("Unexpected error: sorry unable to print"); QMessageBox::warning( this, "Unexpected error", "Unexpected error: sorry unable to print", QMessageBox::Ok, QMessageBox::NoButton ); return; } QPaintDeviceMetrics metrics (printer); QFontMetrics fm = pp.fontMetrics(); unsigned int npagetoprint = 1; int currentpage = 0; int pageWidth = ((FORMAT_TANKOBON_W_MM - sbGapMM->value() / 2) * metrics.width()) / metrics.widthMM(); int pageHeight = (FORMAT_TANKOBON_H_MM * metrics.height()) / metrics.heightMM(); int pageDistGap = ((sbGapMM->value() / 2) * metrics.width()) / metrics.widthMM(); QString pmessage; if (printer->outputToFile()) pmessage = "file " + printer->outputFileName(); else pmessage = printer->printerName(); // some check on unsupported options QString somewarning = ""; if (printer->pageSize() != QPrinter::A4) { printer->setPageSize(QPrinter::A4); somewarning = somewarning + "\n" + "A4 page size only."; } if (printer->orientation() != QPrinter::Landscape) { printer->setOrientation(QPrinter::Landscape); somewarning = somewarning + "\n" + "Landscape page orientation only."; } if (printer->pageOrder() != QPrinter::FirstPageFirst) { printer->setPageOrder(QPrinter::FirstPageFirst); somewarning = somewarning + "\n" + "'First Page First' order only."; } if (!somewarning.isEmpty()) QMessageBox::warning(this, "Unsupported options", somewarning, QMessageBox::Ok, QMessageBox::NoButton); #ifdef DEBUG uint top, left, bottom, right; printer->margins(&top, &left, &bottom, &right); qDebug("margin: top = %d, left = %d, bottom = %d, right = %d", top, left, bottom, right); #endif QProgressDialog progressP( QString( "number of copies: %1 - number of sheets: %2

Printing to %3..."). arg(printer->numCopies()).arg(npagetoprint).arg(pmessage), "Cancel", npagetoprint * printer->numCopies(), this, "progress", TRUE ); for (int ncopies = 0; ncopies < printer->numCopies(); ncopies++) { for (int i = 0; i < nsheet; i++) { currentpage++; progressP.setProgress(totpages); qApp->processEvents(); if (progressP.wasCancelled()) { i = nsheet; ncopies = printer->numCopies(); printer->abort(); statusabort = true; break; } QPainter p; int hmax, hmin; int wmax, wmin; if (tlVerso->pixmap()->height() > tlFront->pixmap()->height()) { hmax = tlVerso->pixmap()->height(); hmin = tlFront->pixmap()->height(); } else { hmax = tlFront->pixmap()->height(); hmin = tlVerso->pixmap()->height(); } if (tlVerso->pixmap()->width() > tlFront->pixmap()->width()) { wmax = tlVerso->pixmap()->width(); wmin = tlFront->pixmap()->width(); } else { wmax = tlFront->pixmap()->width(); wmin = tlVerso->pixmap()->width(); } QPixmap target1 (wmax, hmax); QPixmap target2 (wmax, hmax); target1.fill(QColor(PRINT_SHEET_BG_COLOR)); target2.fill(QColor(PRINT_SHEET_BG_COLOR)); if (tlVerso->pixmap()) { p.begin(&target1); p.drawPixmap(0, 0, (*tlVerso->pixmap())); p.end(); } if (tlFront->pixmap()) { p.begin(&target2); p.drawPixmap(0, 0, (*tlFront->pixmap())); p.end(); } QImage imagePage1 = (target1.convertToImage()).smoothScale( pageWidth, pageHeight, QImage::ScaleMin); QImage imagePage2 = (target2.convertToImage()).smoothScale( pageWidth, pageHeight, QImage::ScaleMin); if (totpages) printer->newPage(); uint pwpos = ( metrics.width() - imagePage1.width() - imagePage2.width() - pageDistGap * 2) / 2; uint phpos = ( metrics.height() - imagePage1.height() ) / 2; pp.drawPixmap(pwpos, phpos, imagePage1); pp.drawPixmap(pwpos + imagePage1.width() + pageDistGap * 2, phpos, imagePage2); pp.drawRect ( pwpos, phpos, imagePage1.width() + pageDistGap * 2 + imagePage2.width(), imagePage1.height() ); totpages++; } // for j } // for ncopies progressP.setProgress(npagetoprint); pp.end(); } // if (printer->setup(this)) if (statusabort == false) { QString finalmessage; if (printer->outputToFile()) finalmessage = QString("%1 sheets(s) saved in %2").arg(totpages).arg(printer->outputFileName()); else finalmessage = QString("%1 sheet(s) processed").arg(totpages); QMessageBox::warning( this, "Printing cover", finalmessage, QMessageBox::Ok, QMessageBox::NoButton ); } delete printer; }