3333#include < QMessageBox>
3434#include < QFileInfo>
3535#include < QPainter>
36+ #include < QPrinter>
37+ #include < QPrintDialog>
3638#include < QDesktopWidget>
3739#include < QSettings>
3840#include < QClipboard>
@@ -55,11 +57,11 @@ Window:: Window()
5557 fileMenu->addAction (" Save As..." , this , SLOT (saveAs ()));
5658 fileMenu->addAction (" Save by File Size" , this , SLOT (autoResizeAndSave ()));
5759 fileMenu->addSeparator ();
60+ fileMenu->addAction (" Print" , this , SLOT (printImage ()));
5861 fileMenu->addAction (" Export to PDF" , this , SLOT (exportToPdf ()));
59- fileMenu->addAction (" Copy to Clipboard" , this , SLOT (copyToClipboard ()));
6062 fileMenu->addSeparator ();
6163 fileMenu->addAction (" Open Image" , this , SLOT (openFile ()));
62- fileMenu->addAction (" Open from Clipboard " , this , SLOT (openFromClipboard ()));
64+ fileMenu->addAction (" Paste Image " , this , SLOT (openFromClipboard ()));
6365 fileBtn->setMenu (fileMenu);
6466 QMenu *transformMenu = new QMenu (transformBtn);
6567 transformMenu->addAction (" Mirror Image" , this , SLOT (mirror ()));
@@ -108,6 +110,10 @@ Window:: Window()
108110 infoMenu->addAction (" Image Info" , this , SLOT (imageInfo ()));
109111 infoBtn->setMenu (infoMenu);
110112
113+ QAction *action = new QAction (this );
114+ action->setShortcut (QString (" Ctrl+C" ));
115+ connect (action, SIGNAL (triggered ()), this , SLOT (copyToClipboard ()));
116+ this ->addAction (action);
111117 QAction *escapeAction = new QAction (this );
112118 escapeAction->setShortcut (QString (" Esc" ));
113119 connect (escapeAction, SIGNAL (triggered ()), this , SLOT (onEscPress ()));
@@ -500,6 +506,32 @@ Window:: autoResizeAndSave()
500506 }
501507}
502508
509+ void
510+ Window:: printImage()
511+ {
512+ QPrinter printer (QPrinter::HighResolution);
513+ QPrintDialog *dlg = new QPrintDialog (&printer, this );
514+ // disable some options (PrintSelection, PrintCurrentPage are disabled by default)
515+ dlg->setOption (QAbstractPrintDialog::PrintPageRange, false );
516+ dlg->setOption (QAbstractPrintDialog::PrintCollateCopies, false );
517+ if (dlg->exec () == QDialog::Accepted) {
518+ QImage img = data.image ;
519+ if (img.width () > img.height ()) {// paper is always portrait, so rotate image
520+ QTransform transform;
521+ transform.rotate (90 );
522+ img = img.transformed (transform);
523+ }
524+ QPainter painter (&printer);
525+ QRect rect = painter.viewport ();// area inside margin
526+ // align the photo to top, and fit inside margin
527+ int out_w, out_h;
528+ fitToSize (img.width (), img.height (), rect.width (), rect.height (), out_w, out_h);
529+ QRect out_rect (rect.x (), rect.y (), out_w, out_h);
530+ painter.drawImage (out_rect, img, img.rect ());
531+ painter.end ();
532+ }
533+ }
534+
503535bool isMonochrome (QImage img)
504536{
505537 for (int y=0 ; y<img.height (); y++) {
0 commit comments