tests/arthur/lance/main.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 #include "interactivewidget.h"
       
    42 #include "widgets.h"
       
    43 #include "paintcommands.h"
       
    44 
       
    45 #include <QtCore>
       
    46 #include <QtGui>
       
    47 #include <qimage.h>
       
    48 #include <QPicture>
       
    49 
       
    50 #include <private/qmath_p.h>
       
    51 
       
    52 #ifdef USE_CUSTOM_DEVICE
       
    53 #include "customdevice.h"
       
    54 #endif
       
    55 
       
    56 #ifndef QT_NO_OPENGL
       
    57 #include <qgl.h>
       
    58 #include <QGLPixelBuffer>
       
    59 #endif
       
    60 
       
    61 // #define DO_QWS_DEBUGGING
       
    62 
       
    63 #ifdef DO_QWS_DEBUGGING
       
    64 extern bool qt_show_painter_debug_output = false;
       
    65 #endif
       
    66 
       
    67 //#define CONSOLE_APPLICATION
       
    68 
       
    69 static const struct {
       
    70     const char *name;
       
    71     QImage::Format format;
       
    72 } imageFormats[] = {
       
    73     { "mono", QImage::Format_Mono },
       
    74     { "monolsb", QImage::Format_MonoLSB },
       
    75     { "indexed8", QImage::Format_Indexed8 },
       
    76     { "rgb32", QImage::Format_RGB32 },
       
    77     { "argb32", QImage::Format_ARGB32 },
       
    78     { "argb32_premultiplied", QImage::Format_ARGB32_Premultiplied },
       
    79     { "rgb16", QImage::Format_RGB16 },
       
    80     { "argb8565_premultiplied", QImage::Format_ARGB8565_Premultiplied },
       
    81     { "rgb666", QImage::Format_RGB666 },
       
    82     { "argb6666_premultiplied", QImage::Format_ARGB6666_Premultiplied },
       
    83     { "rgb555", QImage::Format_RGB555 },
       
    84     { "argb8555_premultiplied", QImage::Format_ARGB8555_Premultiplied },
       
    85     { "rgb888", QImage::Format_RGB888 },
       
    86     { "rgb444", QImage::Format_RGB444 },
       
    87     { "argb4444_premultiplied", QImage::Format_ARGB4444_Premultiplied }
       
    88 };
       
    89 
       
    90 static void printHelp()
       
    91 {
       
    92     printf("\nUsage:\n\n"
       
    93            "  paintcmd [options] files\n"
       
    94            "\n"
       
    95            "  Options:\n"
       
    96            "    -widget         Paints the files to a widget on screen\n"
       
    97            "    -pixmap         Paints the files to a pixmap\n"
       
    98            "    -bitmap         Paints the files to a bitmap\n"
       
    99            "    -image          Paints the files to an image\n"
       
   100            "    -imageformat    Set the format of the image when painting to an image\n"
       
   101            "    -imagemono      Paints the files to a monochrome image\n"
       
   102            "    -imagewidget    same as image, but with interacion...\n"
       
   103 #ifndef QT_NO_OPENGL
       
   104            "    -opengl         Paints the files to an OpenGL on screen\n"
       
   105 #endif
       
   106 #ifdef USE_CUSTOM_DEVICE
       
   107            "    -customdevice   Paints the files to the custom paint device\n"
       
   108            "    -customwidget   Paints the files to a custom widget on screen\n"
       
   109 #endif
       
   110            "    -pdf            Paints to a pdf\n"
       
   111            "    -ps             Paints to a ps\n"
       
   112            "    -picture        Prints into a picture, then shows the result in a label\n"
       
   113            "    -printer        Prints the commands to a file called output.ps|pdf\n"
       
   114            "    -highres        Prints in highres mode\n"
       
   115            "    -printdialog    Opens a print dialog, then prints to the selected printer\n"
       
   116            "    -grab           Paints the files to an image called filename_qps.png\n"
       
   117            "    -i              Interactive mode.\n"
       
   118            "    -v              Verbose.\n"
       
   119            "    -bg-white       No checkers background\n"
       
   120            "    -commands       Displays all available commands\n");
       
   121 }
       
   122 
       
   123 static void displayCommands()
       
   124 {
       
   125     printf("Drawing operations:\n"
       
   126            "  drawArc x y width height angle sweep\n"
       
   127            "  drawChord x y width height angle sweep\n"
       
   128            "  drawEllipse x y width height\n"
       
   129            "  drawLine x1 y1 x2 y2\n"
       
   130            "  drawPath pathname\n"
       
   131            "  drawPie x y width height angle sweep\n"
       
   132            "  drawPixmap pixmapfile x y width height sx sy sw sh\n"
       
   133            "  drawPolygon [ x1 y1 x2 y2 ... ] winding|oddeven\n"
       
   134            "  drawPolyline [ x1 y1 x2 y2 ... ]\n"
       
   135            "  drawRect x y width height\n"
       
   136            "  drawRoundRect x y width height xfactor yfactor\n"
       
   137            "  drawText x y \"text\"\n"
       
   138            "  drawTiledPixmap pixmapfile x y width height sx sy\n"
       
   139            "\n"
       
   140            "Compat functions for Qt 3:\n"
       
   141            "  qt3_drawArc x y width height angle sweep\n"
       
   142            "  qt3_drawChord x y width height angle sweep\n"
       
   143            "  qt3_drawEllipse x y width height\n"
       
   144            "  qt3_drawPie x y width height angle sweep\n"
       
   145            "  qt3_drawRect x y width height\n"
       
   146            "  qt3_drawRoundRect x y width height xfactor yfactor\n"
       
   147            "\n"
       
   148            "Path commands:\n"
       
   149            "  path_addEllipse pathname x y width height\n"
       
   150            "  path_addPolygon pathname [ x1 y1 x2 y2 ... ] winding?\n"
       
   151            "  path_addRect pathname x y width height\n"
       
   152            "  path_addText pathname x y \"text\"                        Uses current font\n"
       
   153            "  path_arcTo pathname x y width hegiht\n"
       
   154            "  path_closeSubpath pathname\n"
       
   155            "  path_createOutline pathname newoutlinename                Uses current pen\n"
       
   156            "  path_cubicTo pathname c1x c1y c2x c2y endx endy\n"
       
   157            "  path_lineTo pathname x y\n"
       
   158            "  path_moveTo pathname x y\n"
       
   159            "  path_setFillRule pathname winding?\n"
       
   160            "\n"
       
   161            "Painter configuration:\n"
       
   162            "  resetMatrix\n"
       
   163            "  restore\n"
       
   164            "  save\n"
       
   165            "  rotate degrees\n"
       
   166            "  translate dx dy\n"
       
   167            "  scale sx sy\n"
       
   168            "  mapQuadToQuad x0 y0 x1 y1 x2 y2 x3 y3  x4 y4 x5 y5 x6 y6 x7 y7"
       
   169            "  setMatrix m11 m12 m13 m21 m22 m23 m31 m32 m33"
       
   170            "  setBackground color pattern?\n"
       
   171            "  setBackgroundMode TransparentMode|OpaqueMode\n"
       
   172            "  setBrush pixmapfile\n"
       
   173            "  setBrush nobrush\n"
       
   174            "  setBrush color pattern\n"
       
   175            "  setBrush x1 y1 color1 x2 y2 color2                        gradient brush\n"
       
   176            "  setBrushOrigin x y\n"
       
   177            "  setFont \"fontname\" pointsize bold? italic?\n"
       
   178            "  setPen style color\n"
       
   179            "  setPen color width style capstyle joinstyle\n"
       
   180            "  setRenderHint LineAntialiasing\n"
       
   181            "  gradient_clearStops\n"
       
   182            "  gradient_appendStop pos color"
       
   183            "  gradient_setSpread [PadSpread|ReflectSpread|RepeatSpread]\n"
       
   184            "  gradient_setLinear x1 y1 x2 y2\n"
       
   185            "  gradient_setRadial center_x center_y radius focal_x focal_y\n"
       
   186            "  gradient_setConical center_x center_y angle\n"
       
   187            "\n"
       
   188            "Clipping commands:\n"
       
   189            "  region_addRect regionname x y width height\n"
       
   190            "  region_getClipRegion regionname\n"
       
   191            "  setClipRect x y width height\n"
       
   192            "  setClipRegion regionname\n"
       
   193            "  setClipping true|false\n"
       
   194            "  setClipPath pathname\n"
       
   195            "\n"
       
   196            "Various commands:\n"
       
   197            "  surface_begin x y width height\n"
       
   198            "  surface_end\n"
       
   199            "  pixmap_load filename name_in_script\n"
       
   200            "  image_load filename name_in_script\n");
       
   201 }
       
   202 static InteractiveWidget *interactive_widget = 0;
       
   203 
       
   204 static void runInteractive()
       
   205 {
       
   206     interactive_widget = new InteractiveWidget;
       
   207     interactive_widget->show();
       
   208 }
       
   209 
       
   210 static QLabel* createLabel()
       
   211 {
       
   212     QLabel *label = new QLabel;
       
   213     QPalette palette = label->palette();
       
   214     palette.setBrush(QPalette::Window, QBrush(Qt::white));
       
   215     label->setPalette(palette);
       
   216     return label;
       
   217 }
       
   218 
       
   219 int main(int argc, char **argv)
       
   220 {
       
   221 #ifdef CONSOLE_APPLICATION
       
   222     QApplication app(argc, argv, QApplication::Tty);
       
   223 #else
       
   224     QApplication app(argc, argv);
       
   225 #endif
       
   226 #ifdef DO_QWS_DEBUGGING
       
   227     qt_show_painter_debug_output = false;
       
   228 #endif
       
   229 
       
   230     DeviceType type = WidgetType;
       
   231     bool checkers_background = true;
       
   232 
       
   233     QImage::Format imageFormat = QImage::Format_ARGB32_Premultiplied;
       
   234 
       
   235     QLocale::setDefault(QLocale::c());
       
   236 
       
   237     QStringList files;
       
   238 
       
   239     bool interactive = false;
       
   240     bool printdlg = false;
       
   241     bool highres = false;
       
   242     bool show_cmp = false;
       
   243     int width = 800, height = 800;
       
   244     bool verboseMode = false;
       
   245 
       
   246 #ifndef QT_NO_OPENGL
       
   247     QGLFormat f = QGLFormat::defaultFormat();
       
   248     f.setSampleBuffers(true);
       
   249     f.setStencil(true);
       
   250     f.setAlpha(true);
       
   251     f.setAlphaBufferSize(8);
       
   252     QGLFormat::setDefaultFormat(f);
       
   253 #endif
       
   254 
       
   255     char *arg;
       
   256     for (int i=1; i<argc; ++i) {
       
   257         arg = argv[i];
       
   258         if (*arg == '-') {
       
   259             QString option = QString(arg + 1).toLower();
       
   260             if (option == "widget")
       
   261                 type = WidgetType;
       
   262             else if (option == "bitmap")
       
   263                 type = BitmapType;
       
   264             else if (option == "pixmap")
       
   265                 type = PixmapType;
       
   266             else if (option == "image")
       
   267                 type = ImageType;
       
   268             else if (option == "imageformat") {
       
   269                 Q_ASSERT_X(i + 1 < argc, "main", "-imageformat must be followed by a value");
       
   270                 QString format = QString(argv[++i]).toLower();
       
   271 
       
   272                 imageFormat = QImage::Format_Invalid;
       
   273                 static const int formatCount =
       
   274                     sizeof(imageFormats) / sizeof(imageFormats[0]);
       
   275                 for (int ff = 0; ff < formatCount; ++ff) {
       
   276                     if (QLatin1String(imageFormats[ff].name) == format) {
       
   277                         imageFormat = imageFormats[ff].format;
       
   278                         break;
       
   279                     }
       
   280                 }
       
   281 
       
   282                 if (imageFormat == QImage::Format_Invalid) {
       
   283                     printf("Invalid image format.  Available formats are:\n");
       
   284                     for (int ff = 0; ff < formatCount; ++ff)
       
   285                         printf("\t%s\n", imageFormats[ff].name);
       
   286                     return -1;
       
   287                 }
       
   288             } else if (option == "imagemono")
       
   289                 type = ImageMonoType;
       
   290             else if (option == "imagewidget")
       
   291                 type = ImageWidgetType;
       
   292 #ifndef QT_NO_OPENGL
       
   293             else if (option == "opengl")
       
   294                 type = OpenGLType;
       
   295             else if (option == "pbuffer")
       
   296                 type = OpenGLPBufferType;
       
   297 #endif
       
   298 #ifdef USE_CUSTOM_DEVICE
       
   299             else if (option == "customdevice")
       
   300                 type = CustomDeviceType;
       
   301             else if (option == "customwidget")
       
   302                 type = CustomWidgetType;
       
   303 #endif
       
   304             else if (option == "pdf")
       
   305                 type = PdfType;
       
   306             else if (option == "ps")
       
   307                 type = PsType;
       
   308             else if (option == "picture")
       
   309                 type = PictureType;
       
   310             else if (option == "printer")
       
   311                 type = PrinterType;
       
   312             else if (option == "highres") {
       
   313                 type = PrinterType;
       
   314                 highres = true;
       
   315             } else if (option == "printdialog") {
       
   316                 type = PrinterType;
       
   317                 printdlg = true;
       
   318             }
       
   319             else if (option == "grab")
       
   320                 type = GrabType;
       
   321             else if (option == "i")
       
   322                 interactive = true;
       
   323             else if (option == "v")
       
   324                 verboseMode = true;
       
   325             else if (option == "commands") {
       
   326                 displayCommands();
       
   327                 return 0;
       
   328             } else if (option == "w") {
       
   329                 Q_ASSERT_X(i + 1 < argc, "main", "-w must be followed by a value");
       
   330                 width = atoi(argv[++i]);
       
   331             } else if (option == "h") {
       
   332                 Q_ASSERT_X(i + 1 < argc, "main", "-h must be followed by a value");
       
   333                 height = atoi(argv[++i]);
       
   334             } else if (option == "cmp") {
       
   335                 show_cmp = true;
       
   336             } else if (option == "bg-white") {
       
   337                 checkers_background = false;
       
   338             }
       
   339         } else {
       
   340 #if defined (Q_WS_WIN)
       
   341             QString input = QString::fromLocal8Bit(argv[i]);
       
   342             if (input.indexOf('*') >= 0) {
       
   343                 QFileInfo info(input);
       
   344                 QDir dir = info.dir();
       
   345                 QFileInfoList infos = dir.entryInfoList(QStringList(info.fileName()));
       
   346                 for (int ii=0; ii<infos.size(); ++ii)
       
   347                     files.append(infos.at(ii).absoluteFilePath());
       
   348             } else {
       
   349                 files.append(input);
       
   350             }
       
   351 #else
       
   352             files.append(QString(argv[i]));
       
   353 #endif
       
   354         }
       
   355     }
       
   356 
       
   357     PaintCommands pcmd(QStringList(), 800, 800);
       
   358     pcmd.setVerboseMode(verboseMode);
       
   359     pcmd.setType(type);
       
   360     pcmd.setCheckersBackground(checkers_background);
       
   361 
       
   362     QWidget *activeWidget = 0;
       
   363 
       
   364     if (interactive) {
       
   365         runInteractive();
       
   366         if (!files.isEmpty())
       
   367             interactive_widget->load(files.at(0));
       
   368     } else if (files.isEmpty()) {
       
   369         printHelp();
       
   370         return 0;
       
   371     } else {
       
   372         for (int j=0; j<files.size(); ++j) {
       
   373             const QString &fileName = files.at(j);
       
   374             QStringList content;
       
   375 
       
   376             QFile file(fileName);
       
   377             QFileInfo fileinfo(file);
       
   378             if (file.open(QIODevice::ReadOnly)) {
       
   379                 QTextStream textFile(&file);
       
   380                 QString script = textFile.readAll();
       
   381                 content = script.split("\n", QString::SkipEmptyParts);
       
   382             } else {
       
   383                 printf("failed to read file: '%s'\n", qPrintable(fileinfo.absoluteFilePath()));
       
   384                 continue;
       
   385             }
       
   386             pcmd.setContents(content);
       
   387 
       
   388             if (show_cmp) {
       
   389                 QString pmFile = QString(files.at(j)).replace(".qps", "_qps") + ".png";
       
   390                 qDebug() << pmFile << QFileInfo(pmFile).exists();
       
   391                 QPixmap pixmap(pmFile);
       
   392                 if (!pixmap.isNull()) {
       
   393                     QLabel *label = createLabel();
       
   394                     label->setWindowTitle("VERIFY: " + pmFile);
       
   395                     label->setPixmap(pixmap);
       
   396                     label->show();
       
   397                 }
       
   398             }
       
   399 
       
   400             switch (type) {
       
   401 
       
   402             case WidgetType:
       
   403             {
       
   404                 OnScreenWidget<QWidget> *qWidget =
       
   405                     new OnScreenWidget<QWidget>(files.at(j));
       
   406                 qWidget->setVerboseMode(verboseMode);
       
   407                 qWidget->setType(type);
       
   408                 qWidget->setCheckersBackground(checkers_background);
       
   409                 qWidget->m_commands = content;
       
   410                 qWidget->resize(width, height);
       
   411                 qWidget->show();
       
   412                 activeWidget = qWidget;
       
   413                 break;
       
   414             }
       
   415 
       
   416             case ImageWidgetType:
       
   417             {
       
   418                 OnScreenWidget<QWidget> *qWidget = new OnScreenWidget<QWidget>(files.at(j));
       
   419                 qWidget->setVerboseMode(verboseMode);
       
   420                 qWidget->setType(type);
       
   421                 qWidget->setCheckersBackground(checkers_background);
       
   422                 qWidget->m_commands = content;
       
   423                 qWidget->resize(width, height);
       
   424                 qWidget->show();
       
   425                 activeWidget = qWidget;
       
   426                 break;
       
   427 
       
   428             }
       
   429 #ifndef QT_NO_OPENGL
       
   430             case OpenGLPBufferType:
       
   431             {
       
   432                 QGLPixelBuffer pbuffer(QSize(width, height));
       
   433                 QPainter pt(&pbuffer);
       
   434                 pcmd.setPainter(&pt);
       
   435                 pcmd.setFilePath(fileinfo.absolutePath());
       
   436                 pcmd.runCommands();
       
   437                 pt.end();
       
   438 
       
   439                 QImage image = pbuffer.toImage();
       
   440 
       
   441                 QLabel *label = createLabel();
       
   442                 label->setPixmap(QPixmap::fromImage(image));
       
   443                 label->resize(label->sizeHint());
       
   444                 label->show();
       
   445                 activeWidget = label;
       
   446                 break;
       
   447             }
       
   448             case OpenGLType:
       
   449             {
       
   450                 OnScreenWidget<QGLWidget> *qGLWidget = new OnScreenWidget<QGLWidget>(files.at(j));
       
   451                 qGLWidget->setVerboseMode(verboseMode);
       
   452                 qGLWidget->setType(type);
       
   453                 qGLWidget->setCheckersBackground(checkers_background);
       
   454                 qGLWidget->m_commands = content;
       
   455                 qGLWidget->resize(width, height);
       
   456                 qGLWidget->show();
       
   457                 activeWidget = qGLWidget;
       
   458                 break;
       
   459             }
       
   460 #else
       
   461             case OpenGLType:
       
   462                 printf("OpenGL type not supported in this Qt build\n");
       
   463                 break;
       
   464 #endif
       
   465 #ifdef USE_CUSTOM_DEVICE
       
   466             case CustomDeviceType:
       
   467             {
       
   468                 CustomPaintDevice custom(width, height);
       
   469                 QPainter pt;
       
   470                 pt.begin(&custom);
       
   471                 pcmd.setPainter(&pt);
       
   472                 pcmd.setFilePath(fileinfo.absolutePath());
       
   473                 pcmd.runCommands();
       
   474                 pt.end();
       
   475                 QImage *img = custom.image();
       
   476                 if (img) {
       
   477                     QLabel *label = createLabel();
       
   478                     label->setPixmap(QPixmap::fromImage(*img));
       
   479                     label->resize(label->sizeHint());
       
   480                     label->show();
       
   481                     activeWidget = label;
       
   482                     img->save("custom_output_pixmap.png", "PNG");
       
   483                 } else {
       
   484                     custom.save("custom_output_pixmap.png", "PNG");
       
   485                 }
       
   486                 break;
       
   487             }
       
   488             case CustomWidgetType:
       
   489             {
       
   490                 OnScreenWidget<CustomWidget> *cWidget = new OnScreenWidget<CustomWidget>;
       
   491                 cWidget->setVerboseMode(verboseMode);
       
   492                 cWidget->setType(type);
       
   493                 cWidget->setCheckersBackground(checkers_background);
       
   494                 cWidget->m_filename = files.at(j);
       
   495                 cWidget->setWindowTitle(fileinfo.filePath());
       
   496                 cWidget->m_commands = content;
       
   497                 cWidget->resize(width, height);
       
   498                 cWidget->show();
       
   499                 activeWidget = cWidget;
       
   500                 break;
       
   501             }
       
   502 #endif
       
   503             case PixmapType:
       
   504             {
       
   505                 QPixmap pixmap(width, height);
       
   506                 pixmap.fill(Qt::white);
       
   507                 QPainter pt(&pixmap);
       
   508                 pcmd.setPainter(&pt);
       
   509                 pcmd.setFilePath(fileinfo.absolutePath());
       
   510                 pcmd.runCommands();
       
   511                 pt.end();
       
   512                 pixmap.save("output_pixmap.png", "PNG");
       
   513                 break;
       
   514             }
       
   515 
       
   516             case BitmapType:
       
   517             {
       
   518                 QBitmap bitmap(width, height);
       
   519                 QPainter pt(&bitmap);
       
   520                 pcmd.setPainter(&pt);
       
   521                 pcmd.setFilePath(fileinfo.absolutePath());
       
   522                 pcmd.runCommands();
       
   523                 pt.end();
       
   524                 bitmap.save("output_bitmap.png", "PNG");
       
   525 
       
   526                 QLabel *label = createLabel();
       
   527                 label->setPixmap(bitmap);
       
   528                 label->resize(label->sizeHint());
       
   529                 label->show();
       
   530                 activeWidget = label;
       
   531                 break;
       
   532             }
       
   533 
       
   534             case ImageMonoType:
       
   535             case ImageType:
       
   536             {
       
   537                 qDebug() << "Creating image";
       
   538                 QImage image(width, height, type == ImageMonoType
       
   539                              ? QImage::Format_MonoLSB
       
   540                              : imageFormat);
       
   541                 image.fill(0);
       
   542                 QPainter pt(&image);
       
   543                 pcmd.setPainter(&pt);
       
   544                 pcmd.setFilePath(fileinfo.absolutePath());
       
   545                 pcmd.runCommands();
       
   546                 pt.end();
       
   547                 image.convertToFormat(QImage::Format_ARGB32).save("output_image.png", "PNG");
       
   548 #ifndef CONSOLE_APPLICATION
       
   549                 QLabel *label = createLabel();
       
   550                 label->setPixmap(QPixmap::fromImage(image));
       
   551                 label->resize(label->sizeHint());
       
   552                 label->show();
       
   553                 activeWidget = label;
       
   554 #endif
       
   555                 break;
       
   556             }
       
   557 
       
   558             case PictureType:
       
   559             {
       
   560                 QPicture pic;
       
   561                 QPainter pt(&pic);
       
   562                 pcmd.setPainter(&pt);
       
   563                 pcmd.setFilePath(fileinfo.absolutePath());
       
   564                 pcmd.runCommands();
       
   565                 pt.end();
       
   566 
       
   567                 QImage image(width, height, QImage::Format_ARGB32_Premultiplied);
       
   568                 image.fill(0);
       
   569                 pt.begin(&image);
       
   570                 pt.drawPicture(0, 0, pic);
       
   571                 pt.end();
       
   572                 QLabel *label = createLabel();
       
   573                 label->setWindowTitle(fileinfo.absolutePath());
       
   574                 label->setPixmap(QPixmap::fromImage(image));
       
   575                 label->resize(label->sizeHint());
       
   576                 label->show();
       
   577                 activeWidget = label;
       
   578                 break;
       
   579             }
       
   580 
       
   581             case PrinterType:
       
   582             {
       
   583 #ifndef QT_NO_PRINTER
       
   584                 PaintCommands pcmd(QStringList(), 800, 800);
       
   585                 pcmd.setVerboseMode(verboseMode);
       
   586                 pcmd.setType(type);
       
   587                 pcmd.setCheckersBackground(checkers_background);
       
   588                 pcmd.setContents(content);
       
   589                 QString file = QString(files.at(j)).replace(".", "_") + ".ps";
       
   590 
       
   591                 QPrinter p(highres ? QPrinter::HighResolution : QPrinter::ScreenResolution);
       
   592                 if (printdlg) {
       
   593                     QPrintDialog printDialog(&p, 0);
       
   594                     if (printDialog.exec() != QDialog::Accepted)
       
   595                         break;
       
   596                 } else {
       
   597                     p.setOutputFileName(file);
       
   598                 }
       
   599 
       
   600                 QPainter pt(&p);
       
   601                 pcmd.setPainter(&pt);
       
   602                 pcmd.setFilePath(fileinfo.absolutePath());
       
   603                 pcmd.runCommands();
       
   604                 pt.end();
       
   605 
       
   606                 if (!printdlg) {
       
   607                     printf("wrote file: %s\n", qPrintable(file));
       
   608                 }
       
   609 
       
   610                 Q_ASSERT(!p.paintingActive());
       
   611 #endif
       
   612                 break;
       
   613             }
       
   614             case PsType:
       
   615             case PdfType:
       
   616             {
       
   617 #ifndef QT_NO_PRINTER
       
   618                 PaintCommands pcmd(QStringList(), 800, 800);
       
   619                 pcmd.setVerboseMode(verboseMode);
       
   620                 pcmd.setType(type);
       
   621                 pcmd.setCheckersBackground(checkers_background);
       
   622                 pcmd.setContents(content);
       
   623                 bool ps = type == PsType;
       
   624                 QPrinter p(highres ? QPrinter::HighResolution : QPrinter::ScreenResolution);
       
   625                 QFileInfo input(files.at(j));
       
   626                 QString file = QString("%1_%2.%3")
       
   627                                .arg(input.baseName())
       
   628                                .arg(input.suffix())
       
   629                                .arg(ps ? "ps" : "pdf");
       
   630                 p.setOutputFormat(ps ? QPrinter::PdfFormat : QPrinter::PostScriptFormat);
       
   631                 p.setOutputFileName(file);
       
   632                 p.setPageSize(QPrinter::A4);
       
   633                 QPainter pt(&p);
       
   634                 pcmd.setPainter(&pt);
       
   635                 pcmd.setFilePath(fileinfo.absolutePath());
       
   636                 pcmd.runCommands();
       
   637                 pt.end();
       
   638 
       
   639                 printf("write file: %s\n", qPrintable(file));
       
   640 #endif
       
   641                 break;
       
   642             }
       
   643             case GrabType:
       
   644             {
       
   645                 QImage image(width, height, QImage::Format_ARGB32_Premultiplied);
       
   646                 image.fill(QColor(Qt::white).rgb());
       
   647                 QPainter pt(&image);
       
   648                 pcmd.setPainter(&pt);
       
   649                 pcmd.setFilePath(fileinfo.absolutePath());
       
   650                 pcmd.runCommands();
       
   651                 pt.end();
       
   652                 QImage image1(width, height, QImage::Format_RGB32);
       
   653                 image1.fill(QColor(Qt::white).rgb());
       
   654                 QPainter pt1(&image1);
       
   655                 pt1.drawImage(QPointF(0, 0), image);
       
   656                 pt1.end();
       
   657 
       
   658                 QString filename = QString(files.at(j)).replace(".qps", "_qps") + ".png";
       
   659                 image1.save(filename, "PNG");
       
   660                 printf("%s grabbed to %s\n", qPrintable(files.at(j)), qPrintable(filename));
       
   661                 break;
       
   662             }
       
   663             default:
       
   664                 break;
       
   665             }
       
   666         }
       
   667     }
       
   668 #ifndef CONSOLE_APPLICATION
       
   669     if (activeWidget || interactive) {
       
   670         QObject::connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
       
   671         app.exec();
       
   672     }
       
   673     delete activeWidget;
       
   674 #endif
       
   675     delete interactive_widget;
       
   676     return 0;
       
   677 }
       
   678