1 
2 
3 // TnzCore includes
4 #include "timage_io.h"
5 
6 // TnzLib includes
7 #include "toonz/tscenehandle.h"
8 #include "toonz/tframehandle.h"
9 #include "toonz/tcamera.h"
10 #include "toonz/toonzscene.h"
11 #include "toonz/txsheethandle.h"
12 #include "toonz/sceneproperties.h"
13 
14 // TnzQt includes
15 #include "toonzqt/menubarcommand.h"
16 #include "toonzqt/gutil.h"
17 
18 // Tnz6 includes
19 #include "menubarcommandids.h"
20 #include "tapp.h"
21 
22 // Qt includes
23 #include <QPrinter>
24 #include <QPrintDialog>
25 #include <QPainter>
26 #include <QApplication>
27 
printCurrentFrame()28 static void printCurrentFrame() {
29   QPrinter printer;
30   QPrintDialog dialog(&printer, 0);
31   if (!dialog.exec()) return;
32 
33   ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();
34   int frame         = TApp::instance()->getCurrentFrame()->getFrame();
35   int lx            = TApp::instance()
36                ->getCurrentScene()
37                ->getScene()
38                ->getCurrentCamera()
39                ->getRes()
40                .lx;
41   int ly = TApp::instance()
42                ->getCurrentScene()
43                ->getScene()
44                ->getCurrentCamera()
45                ->getRes()
46                .ly;
47   TRaster32P raster(lx, ly);
48   if (scene->getFrameCount() <= 0) {
49     // Ricordarsi di usare DvMsgBox !! (se si decommenta questo codice :) )
50     // QMessageBox::warning(0,"Print",tr("It is not possible to generate an
51     // animation\nbecause the scene is empty.", "WARNING"));
52     return;
53   }
54   raster->fill(scene->getProperties()->getBgColor());
55   scene->renderFrame(raster, frame,
56                      TApp::instance()->getCurrentXsheet()->getXsheet());
57   QImage img = rasterToQImage(raster);
58   QPainter painter(&printer);
59   QRect rect = painter.viewport();
60   QSize size = img.size();
61   size.scale(rect.size(), Qt::KeepAspectRatio);
62   painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
63   painter.setWindow(img.rect());
64   painter.drawImage(0, 0, img);
65 }
66 
67 //=============================================================================
68 
69 class PrintCommand final : public MenuItemHandler {
70 public:
PrintCommand()71   PrintCommand() : MenuItemHandler(MI_Print) {}
execute()72   void execute() override {
73     qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
74     qApp->processEvents();
75     printCurrentFrame();
76     qApp->restoreOverrideCursor();
77   }
78 } printCommand;
79