Skip to content

Commit 9f3faf7

Browse files
committed
added : print support
1 parent 900aa54 commit 9f3faf7

File tree

7 files changed

+43
-7
lines changed

7 files changed

+43
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ To open image.jpg with it...
9090
### Keyboard Shortcuts
9191
Reload Image : R
9292
Delete Image : Delete
93+
Copy Image : Ctrl+C
9394

9495
### Supported Image Formats
9596
All formats supported by Qt are supported in this program.

src/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "exif.h"
66

77
#define PROG_NAME "PhotoQuick"
8-
#define PROG_VERSION "4.13.3"
8+
#define PROG_VERSION "4.14.0"
99
#define COPYRIGHT_YEAR "2017-2021"
1010
#define AUTHOR_NAME "Arindam Chaudhuri"
1111
#define AUTHOR_EMAIL "ksharindam@gmail.com"

src/main.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
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+
503535
bool isMonochrome(QImage img)
504536
{
505537
for (int y=0; y<img.height(); y++) {

src/main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public slots:
4343
void saveACopy();
4444
void autoResizeAndSave();
4545
void exportToPdf();
46+
void printImage();
4647
void deleteFile();
4748
void reloadImage();
4849
void resizeImage();

src/photoquick.pro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ QMAKE_CXXFLAGS = -fopenmp -std=c++11
66
QMAKE_LFLAGS += -s
77
LIBS += -lgomp
88

9-
QT += widgets
9+
greaterThan(QT_MAJOR_VERSION, 4) {
10+
QT += widgets printsupport
11+
}
1012
CONFIG -= debug_and_release debug
1113

1214
# build dir

src/version_info.rc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <winver.h>
22

3-
#define PROG_VERSION "4.13.0"
4-
#define FILE_VERSION 4,13,0,0
3+
#define PROG_VERSION "4.14.0"
4+
#define FILE_VERSION 4,14,0,0
55

66
IDI_ICON1 ICON "../data/photoquick.ico"
77

windows/PhotoQuick.nsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; HM NIS Edit Wizard helper defines
22
!define PROG_NAME "PhotoQuick"
3-
!define PROG_VERSION "4.13.0"
3+
!define PROG_VERSION "4.14.0"
44
!define PROG_PUBLISHER "Arindamsoft"
55
!define PROG_ICON "photoquick.ico"
66
!define PROG_EXEC "photoquick.exe"

0 commit comments

Comments
 (0)