Commit 3b433922 authored by Gilles Caulier's avatar Gilles Caulier 🗼
Browse files

factoring

parent 83acce17
......@@ -91,7 +91,7 @@ void Plugin_PrintImages::setup( QWidget* widget )
connect ( m_printAssistantAction, SIGNAL (triggered(bool)),
this, SLOT (slotPrintAssistantActivate()) );
m_interface = dynamic_cast< Interface* > ( parent() );
m_interface = dynamic_cast<Interface*>(parent());
if ( !m_interface )
{
......@@ -131,8 +131,8 @@ void Plugin_PrintImages::slotPrintImagesActivate()
}
QWidget* parent = QApplication::activeWindow();
PrintHelper printPlugin ( parent, m_interface );
printPlugin.print ( fileList );
PrintHelper printPlugin(parent);
printPlugin.print(fileList);
}
void Plugin_PrintImages::slotPrintAssistantActivate()
......@@ -152,7 +152,7 @@ void Plugin_PrintImages::slotPrintAssistantActivate()
}
QWidget* parent = QApplication::activeWindow();
Wizard printAssistant(parent, m_interface);
Wizard printAssistant(parent);
KStandardDirs dir;
QString tempPath = dir.saveLocation("tmp", "kipi-printassistantdplugin-" + QString::number(getpid()) + '/');
printAssistant.print(fileList, tempPath);
......
......@@ -152,7 +152,7 @@ public:
int posX, posY;
// kDebug() << "alignment " << alignment << " image size " << imageSize << " viewport size " << viewportSize;
if ( alignment & Qt::AlignLeft )
{
posX = 0;
......@@ -185,7 +185,7 @@ public:
// ----------------------------------------------------------------------------
PrintHelper::PrintHelper ( QWidget* parent , KIPI::Interface* )
PrintHelper::PrintHelper(QWidget* parent)
: d ( new PrintHelperPrivate )
{
d->mParent = parent;
......@@ -198,189 +198,189 @@ PrintHelper::~PrintHelper()
void PrintHelper::print ( const KUrl::List& fileList )
{
QPrinter printer;
for (int i = 0; i < d->m_photos.count(); ++i)
{
delete d->m_photos.at(i);
KApplication::kApplication()->processEvents();
}
d->m_photos.clear();
for (int i = 0; i < fileList.count(); ++i)
{
TPhoto *photo = new TPhoto(150);
photo->filename = fileList[i];
photo->pAddInfo = new AdditionalInfo();
d->m_photos.append(photo);
KApplication::kApplication()->processEvents();
}
PrintOptionsPage* optionsPage = new PrintOptionsPage(d->mParent, &d->m_photos);
optionsPage->loadConfig();
std::auto_ptr<PrintHelperDialog> dialog(new PrintHelperDialog(&printer, optionsPage, d->mParent));
dialog->setOptionTabs(QList<QWidget*>() << optionsPage);
QPrinter printer;
for (int i = 0; i < d->m_photos.count(); ++i)
{
delete d->m_photos.at(i);
KApplication::kApplication()->processEvents();
}
d->m_photos.clear();
for (int i = 0; i < fileList.count(); ++i)
{
TPhoto *photo = new TPhoto(150);
photo->filename = fileList[i];
photo->pAddInfo = new AdditionalInfo();
d->m_photos.append(photo);
KApplication::kApplication()->processEvents();
}
PrintOptionsPage* optionsPage = new PrintOptionsPage(d->mParent, &d->m_photos);
optionsPage->loadConfig();
std::auto_ptr<PrintHelperDialog> dialog(new PrintHelperDialog(&printer, optionsPage, d->mParent));
dialog->setOptionTabs(QList<QWidget*>() << optionsPage);
#if 0
connect(dialog, SIGNAL(accepted(QPrinter*)),
optionsPage, SLOT(ogChanges(QPrinter*)));
std::auto_ptr<QPrintDialog> dialog(
KdePrint::createPrintDialog(&printer,
QList<QWidget*>() << optionsPage,
d->mParent)
);
connect(dialog, SIGNAL(accepted(QPrinter*)),
optionsPage, SLOT(ogChanges(QPrinter*)));
std::auto_ptr<QPrintDialog> dialog(
KdePrint::createPrintDialog(&printer,
QList<QWidget*>() << optionsPage,
d->mParent)
);
#endif
dialog->setWindowTitle(i18n("Kipi-plugins image printing"));
bool wantToPrint = dialog->exec();
//optionsPage->saveConfig();
if (!wantToPrint)
{
return;
}
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
QPainter painter;
/// painter viewport
QRect rect;
QPrinter::Orientation oldOrientation = printer.orientation();
QProgressDialog pbar(d->mParent);
pbar.setRange(0, fileList.count());
for (int i = 0; i < fileList.count();)
{
if (i == 0) // first photo
{
//read ahead to fix setOrientation before new page
TPhoto *pPhoto = d->m_photos.at(i);
if (!optionsPage->printUsingAtkinsLayout() &&
optionsPage->mp_horPages() <= 0)
{
if (pPhoto->pAddInfo->mAutoRotate)
{
kDebug() << "image size " << pPhoto->size() ;
printer.setOrientation(pPhoto->width() <= pPhoto->height() ? QPrinter::Portrait
: QPrinter::Landscape);
}
}
painter.begin(&printer);
rect = painter.viewport();
}
KApplication::kApplication()->processEvents();
dialog->setWindowTitle(i18n("Kipi-plugins image printing"));
bool wantToPrint = dialog->exec();
if (optionsPage->printUsingAtkinsLayout())
//optionsPage->saveConfig();
if (!wantToPrint)
{
int pages = optionsPage->photoXPage();
int j = 0;
// create AtkinsPageLayout
AtkinsPageLayout layout(rect);
// add all items
for (j = 0; i + j < fileList.count() && j < pages; ++j)
{
layout.addLayoutItem(j, d->m_photos.at(i + j)->size());
}
// retrieve rectangles for all items
for (j = 0; i + j < fileList.count() && j < pages; ++j)
{
QImage image = d->m_photos.at(i + j)->loadPhoto();
painter.drawImage(layout.itemRect(j) , image);
}
i += pages;
if (i < fileList.count())
printer.newPage();
return;
}
else
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
QPainter painter;
/// painter viewport
QRect rect;
QPrinter::Orientation oldOrientation = printer.orientation();
QProgressDialog pbar(d->mParent);
pbar.setRange(0, fileList.count());
for (int i = 0; i < fileList.count();)
{
TPhoto *pPhoto = d->m_photos.at(i);
QImage image = pPhoto->loadPhoto();
// kDebug() << "Img size " << image.size() << " viewportSize " << rect.size();
// if horPages is > 0 vertPages is as well
bool multipagePrinting = optionsPage->mp_horPages() > 0;
if (multipagePrinting)
{
int horPages = optionsPage->mp_horPages();
int vertPages = optionsPage->mp_verPages();
QRect imageRec = image.rect();
int x1;
int y1;
int x2;
int y2;
imageRec.getCoords(&x1, &y1, &x2, &y2);
// kDebug() << "Img coords (" << x1 << ", " << y1 << ", " << x2 << ", " << y2 << ")";
QRect destRec = QRect(QPoint(0, 0), QPoint(x2 / horPages, y2 / vertPages));
for (int px = 1; px <= horPages; ++px)
if (i == 0) // first photo
{
for (int py = 1; py <= vertPages; ++py)
{
int sx = ((px - 1) * x2 / horPages);
int sy = ((py - 1) * y2 / vertPages);
int ex = (px * x2 / horPages);
int ey = (py * y2 / vertPages);
// kDebug() << "Img part coords (" << sx << ", " << sy << ", " << ex << ", " << ey << ")";
QImage destImage = image.copy(QRect(QPoint(sx, sy), QPoint(ex, ey)));
QSize destSize = destImage.size();
destSize.scale(rect.size(), Qt::KeepAspectRatio);
painter.setViewport(rect.x(), rect.y(), destSize.width(), destSize.height());
// painter.setViewport (destRec);
painter.setWindow(destRec);
painter.drawImage(0, 0, destImage);
// painter.drawImage ( /*destRec*/ QPoint(0,0),
// image,
// QRect(QPoint(sx, sy), QPoint(ex, ey)));
if (!(px == horPages && py == vertPages))
printer.newPage();
}
//read ahead to fix setOrientation before new page
TPhoto *pPhoto = d->m_photos.at(i);
if (!optionsPage->printUsingAtkinsLayout() &&
optionsPage->mp_horPages() <= 0)
{
if (pPhoto->pAddInfo->mAutoRotate)
{
kDebug() << "image size " << pPhoto->size() ;
printer.setOrientation(pPhoto->width() <= pPhoto->height() ? QPrinter::Portrait
: QPrinter::Landscape);
}
}
painter.begin(&printer);
rect = painter.viewport();
}
}
else
{
// trying to fix size at the moment
QSize size = d->adjustSize(*pPhoto, printer.resolution(), rect.size());
QPoint pos = d->adjustPosition(*pPhoto, size, rect.size());
// kDebug() << " pos " << pos << " size " << size;
painter.setViewport(pos.x(), pos.y(), size.width(), size.height());
painter.setWindow(image.rect());
painter.drawImage(0, 0, image);
}
if ((++i) < fileList.count())
{
//read ahead to fix setOrientation before new page
pPhoto = d->m_photos.at(i);
if (pPhoto->pAddInfo->mAutoRotate)
KApplication::kApplication()->processEvents();
if (optionsPage->printUsingAtkinsLayout())
{
printer.setOrientation(pPhoto->width() <= pPhoto->height() ? QPrinter::Portrait
: QPrinter::Landscape);
int pages = optionsPage->photoXPage();
int j = 0;
// create AtkinsPageLayout
AtkinsPageLayout layout(rect);
// add all items
for (j = 0; i + j < fileList.count() && j < pages; ++j)
{
layout.addLayoutItem(j, d->m_photos.at(i + j)->size());
}
// retrieve rectangles for all items
for (j = 0; i + j < fileList.count() && j < pages; ++j)
{
QImage image = d->m_photos.at(i + j)->loadPhoto();
painter.drawImage(layout.itemRect(j) , image);
}
i += pages;
if (i < fileList.count())
printer.newPage();
}
else
{
printer.setOrientation(oldOrientation);
TPhoto* pPhoto = d->m_photos.at(i);
QImage image = pPhoto->loadPhoto();
// kDebug() << "Img size " << image.size() << " viewportSize " << rect.size();
// if horPages is > 0 vertPages is as well
bool multipagePrinting = optionsPage->mp_horPages() > 0;
if (multipagePrinting)
{
int horPages = optionsPage->mp_horPages();
int vertPages = optionsPage->mp_verPages();
QRect imageRec = image.rect();
int x1;
int y1;
int x2;
int y2;
imageRec.getCoords(&x1, &y1, &x2, &y2);
// kDebug() << "Img coords (" << x1 << ", " << y1 << ", " << x2 << ", " << y2 << ")";
QRect destRec = QRect(QPoint(0, 0), QPoint(x2 / horPages, y2 / vertPages));
for (int px = 1; px <= horPages; ++px)
{
for (int py = 1; py <= vertPages; ++py)
{
int sx = ((px - 1) * x2 / horPages);
int sy = ((py - 1) * y2 / vertPages);
int ex = (px * x2 / horPages);
int ey = (py * y2 / vertPages);
// kDebug() << "Img part coords (" << sx << ", " << sy << ", " << ex << ", " << ey << ")";
QImage destImage = image.copy(QRect(QPoint(sx, sy), QPoint(ex, ey)));
QSize destSize = destImage.size();
destSize.scale(rect.size(), Qt::KeepAspectRatio);
painter.setViewport(rect.x(), rect.y(), destSize.width(), destSize.height());
// painter.setViewport (destRec);
painter.setWindow(destRec);
painter.drawImage(0, 0, destImage);
// painter.drawImage ( /*destRec*/ QPoint(0,0),
// image,
// QRect(QPoint(sx, sy), QPoint(ex, ey)));
if (!(px == horPages && py == vertPages))
printer.newPage();
}
}
}
else
{
// trying to fix size at the moment
QSize size = d->adjustSize(*pPhoto, printer.resolution(), rect.size());
QPoint pos = d->adjustPosition(*pPhoto, size, rect.size());
// kDebug() << " pos " << pos << " size " << size;
painter.setViewport(pos.x(), pos.y(), size.width(), size.height());
painter.setWindow(image.rect());
painter.drawImage(0, 0, image);
}
if ((++i) < fileList.count())
{
//read ahead to fix setOrientation before new page
pPhoto = d->m_photos.at(i);
if (pPhoto->pAddInfo->mAutoRotate)
{
printer.setOrientation(pPhoto->width() <= pPhoto->height() ? QPrinter::Portrait
: QPrinter::Landscape);
}
else
{
printer.setOrientation(oldOrientation);
}
printer.newPage();
rect = printer.pageRect();
}
}
//TODO manage a cancel signal instead
if (pbar.wasCanceled())
{
KApplication::kApplication()->processEvents();
break;
}
printer.newPage();
rect = printer.pageRect();
}
pbar.setValue(i);
}
//TODO manage a cancel signal instead
if (pbar.wasCanceled())
{
KApplication::kApplication()->processEvents();
break;
}
pbar.setValue(i);
}
painter.end();
QApplication::restoreOverrideCursor();
painter.end();
QApplication::restoreOverrideCursor();
}
} // namespace KIPIPrintImagesPlugin
......@@ -30,11 +30,6 @@
class QWidget;
namespace KIPI
{
class Interface;
}
namespace KIPIPrintImagesPlugin
{
......@@ -43,7 +38,7 @@ class PrintHelper
public:
PrintHelper(QWidget* parent, KIPI::Interface*);
PrintHelper(QWidget* parent);
~PrintHelper();
void print(const KUrl::List& fileList);
......
......@@ -125,7 +125,6 @@ struct Wizard::Private
CropPage* m_cropPage;
ImageCollectionSelector* m_collectionSelector;
Interface* m_interface;
// Page Size in mm
QSizeF m_pageSize;
......@@ -146,10 +145,9 @@ struct Wizard::Private
KPImagesList* m_imagesFilesListBox;
};
Wizard::Wizard(QWidget* const parent, Interface* const interface)
Wizard::Wizard(QWidget* const parent)
: KPWizardDialog(parent), d(new Private)
{
d->m_interface = interface;
//d->m_printDialog = NULL;
d->m_pDlg = NULL;
d->m_printer = NULL;
......
......@@ -33,11 +33,6 @@
#include "kpimageslist.h"
#include "kptooldialog.h"
namespace KIPI
{
class Interface;
}
using namespace KIPI;
using namespace KIPIPlugins;
......@@ -64,7 +59,7 @@ class Wizard : public KPWizardDialog
public:
Wizard(QWidget* const, Interface* const);
Wizard(QWidget* const);
~Wizard();
void print(const KUrl::List& fileList, const QString& tempPath);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment