PrintPlugin.cc 4.79 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
*                                                                            *
*                              OpenFlipper                                   *
*      Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen       *
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper 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 Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
33 34 35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36 37 38 39 40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42

Jan Möbius's avatar
 
Jan Möbius committed
43 44 45 46 47
#include <QtGui>

#include "PrintPlugin.hh"

#include <iostream>
Jan Möbius's avatar
 
Jan Möbius committed
48
#include <ACG/GL/GLState.hh>
Jan Möbius's avatar
 
Jan Möbius committed
49 50 51 52 53 54 55 56

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>

void PrintPlugin::pluginsInitialized()
{
  // color menu
  QMenu *printMenu = new QMenu(tr("&Printing"));
Jan Möbius's avatar
 
Jan Möbius committed
57 58 59 60 61

  printMenu->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"document-print.png"));

  emit addMenubarAction(printMenu->menuAction(), FILEMENU );

Jan Möbius's avatar
 
Jan Möbius committed
62 63
  QAction* AC_Print = new QAction(tr("&Print"), this);;
  AC_Print->setStatusTip(tr("Print the current view"));
Jan Möbius's avatar
 
Jan Möbius committed
64 65
  AC_Print->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"document-print.png"));

Jan Möbius's avatar
 
Jan Möbius committed
66 67 68 69 70
  connect(AC_Print, SIGNAL(triggered()), this, SLOT(printView()));
  printMenu->addAction(AC_Print);
}

void PrintPlugin::printView () {
Jan Möbius's avatar
 
Jan Möbius committed
71 72


Jan Möbius's avatar
 
Jan Möbius committed
73
  QPrinter printer(QPrinter::HighResolution);
Jan Möbius's avatar
 
Jan Möbius committed
74

Jan Möbius's avatar
 
Jan Möbius committed
75
  QPrintDialog *dialog = new QPrintDialog(&printer);
Jan Möbius's avatar
Jan Möbius committed
76
  dialog->setWindowTitle(tr("Print Current View"));
Jan Möbius's avatar
 
Jan Möbius committed
77 78
  if (dialog->exec() != QDialog::Accepted)
      return;
Jan Möbius's avatar
 
Jan Möbius committed
79

Jan Möbius's avatar
 
Jan Möbius committed
80
  QImage image;
Jan Möbius's avatar
 
Jan Möbius committed
81

Jan Möbius's avatar
 
Jan Möbius committed
82 83
  // create the snapshot
  PluginFunctions::getCurrentViewImage(image);
Jan Möbius's avatar
 
Jan Möbius committed
84

Jan Möbius's avatar
 
Jan Möbius committed
85 86 87 88
  QPainter painter;
  painter.begin(&printer);

  painter.save();
Jan Möbius's avatar
 
Jan Möbius committed
89

Jan Möbius's avatar
 
Jan Möbius committed
90 91 92 93 94
  QRect rect = painter.viewport();
  QSize size = image.size();
  size.scale(rect.size(), Qt::KeepAspectRatio);
  painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
  painter.setWindow(image.rect());
Jan Möbius's avatar
 
Jan Möbius committed
95

Jan Möbius's avatar
 
Jan Möbius committed
96 97 98 99
  painter.drawImage(0, 0, image);

  painter.restore();
  painter.end();
Jan Möbius's avatar
 
Jan Möbius committed
100 101

}
Jan Möbius's avatar
 
Jan Möbius committed
102 103 104

void PrintPlugin::slotKeyEvent( QKeyEvent* _event ) {
  if (_event->modifiers() == Qt::ControlModifier ) {
Jan Möbius's avatar
 
Jan Möbius committed
105
    switch (_event->key())
Jan Möbius's avatar
 
Jan Möbius committed
106
    {
Jan Möbius's avatar
 
Jan Möbius committed
107
      case Qt::Key_P :
Jan Möbius's avatar
 
Jan Möbius committed
108 109 110 111 112 113 114 115 116
              printView();
              return;
    }
  }
}


Q_EXPORT_PLUGIN2( printplugin , PrintPlugin );