qt 6.5.1 original

This commit is contained in:
kleuter
2023-10-29 23:33:08 +01:00
parent 71d22ab6b0
commit 85d238dfda
21202 changed files with 5499099 additions and 0 deletions

View File

@ -0,0 +1,84 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## lance Binary:
#####################################################################
qt_internal_add_manual_test(lance
SOURCES
../../baseline/shared/paintcommands.cpp ../../baseline/shared/paintcommands.h
interactivewidget.cpp interactivewidget.h
main.cpp
widgets.h
INCLUDE_DIRECTORIES
.
../../baseline/shared
LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
Qt::OpenGLWidgets
Qt::PrintSupport
Qt::Widgets
)
# Resources:
set(icons_resource_files
"enum.png"
"tools.png"
)
qt_internal_add_resource(lance "icons"
PREFIX
"/icons"
FILES
${icons_resource_files}
)
set(images_resource_files
"../../baseline/painting/images/alpha.png"
"../../baseline/painting/images/alpha2x2.png"
"../../baseline/painting/images/bitmap.png"
"../../baseline/painting/images/border.png"
"../../baseline/painting/images/borderimage.png"
"../../baseline/painting/images/dome_argb32.png"
"../../baseline/painting/images/dome_indexed.png"
"../../baseline/painting/images/dome_indexed_mask.png"
"../../baseline/painting/images/dome_mono.png"
"../../baseline/painting/images/dome_mono_128.png"
"../../baseline/painting/images/dome_mono_palette.png"
"../../baseline/painting/images/dome_rgb32.png"
"../../baseline/painting/images/dot.png"
"../../baseline/painting/images/face.png"
"../../baseline/painting/images/gam030.png"
"../../baseline/painting/images/gam045.png"
"../../baseline/painting/images/gam056.png"
"../../baseline/painting/images/gam100.png"
"../../baseline/painting/images/gam200.png"
"../../baseline/painting/images/image.png"
"../../baseline/painting/images/mask.png"
"../../baseline/painting/images/mask_100.png"
"../../baseline/painting/images/masked.png"
"../../baseline/painting/images/sign.png"
"../../baseline/painting/images/solid.png"
"../../baseline/painting/images/solid2x2.png"
"../../baseline/painting/images/struct-image-01.jpg"
"../../baseline/painting/images/struct-image-01.png"
"../../baseline/painting/images/zebra.png"
)
qt_internal_add_resource(lance "images"
PREFIX
"/"
BASE
"../../baseline/painting"
FILES
${images_resource_files}
)
## Scopes:
#####################################################################
qt_internal_extend_target(lance CONDITION TARGET Qt::OpenGL
LIBRARIES
Qt::OpenGL
)

View File

@ -0,0 +1,6 @@
The "lance" tool can be used to edit and run QPainter script (.qps)
files. They are used in the "lancelot" qpainter regression autotest.
A collection of scripts can be found in the directory
tests/auto/lancelot/scripts
See lance -help for options.

BIN
tests/manual/lance/enum.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/icons" >
<file>enum.png</file>
<file>tools.png</file>
</qresource>
</RCC>

View File

@ -0,0 +1,164 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "interactivewidget.h"
#include <QtWidgets>
InteractiveWidget::InteractiveWidget()
{
m_onScreenWidget = new OnScreenWidget<QWidget>("");
m_onScreenWidget->setMinimumSize(320, 240);
setCentralWidget(m_onScreenWidget);
ui_textEdit = new QTextEdit();
ui_textEdit->installEventFilter(this);
QWidget *panelContent = new QWidget();
QVBoxLayout *vlayout = new QVBoxLayout(panelContent);
vlayout->setContentsMargins(0, 0, 0, 0);
vlayout->setSpacing(0);
// create and populate the command toolbox
m_commandsToolBox = new QToolBox();
QListWidget *currentListWidget = nullptr;
foreach (PaintCommands::PaintCommandInfos paintCommandInfo, PaintCommands::s_commandInfoTable) {
if (paintCommandInfo.isSectionHeader()) {
currentListWidget = new QListWidget();
m_commandsToolBox->addItem(currentListWidget, QIcon(":/icons/tools.png"), "commands - "+paintCommandInfo.identifier);
connect(currentListWidget, SIGNAL(itemActivated(QListWidgetItem*)), SLOT(cmdSelected(QListWidgetItem*)));
} else {
(new QListWidgetItem(paintCommandInfo.identifier, currentListWidget))->setToolTip(paintCommandInfo.syntax);
}
}
// create and populate the enumerations toolbox
m_enumsToolBox = new QToolBox();
typedef QPair<QString,QStringList> EnumListType;
foreach (EnumListType enumInfos, PaintCommands::s_enumsTable) {
currentListWidget = new QListWidget();
m_commandsToolBox->addItem(currentListWidget, QIcon(":/icons/enum.png"), "enums - "+enumInfos.first);
connect(currentListWidget, SIGNAL(itemActivated(QListWidgetItem*)), SLOT(enumSelected(QListWidgetItem*)));
foreach (QString enumItem, enumInfos.second)
new QListWidgetItem(enumItem, currentListWidget);
}
// add other widgets and layout
vlayout->addWidget(m_commandsToolBox);
vlayout->addWidget(m_enumsToolBox);
QPushButton *run = new QPushButton("&Run");
QPushButton *load = new QPushButton("&Load");
QPushButton *save = new QPushButton("&Save");
run->setFocusPolicy(Qt::NoFocus);
vlayout->addSpacing(20);
vlayout->addWidget(run);
vlayout->addWidget(load);
vlayout->addWidget(save);
QDockWidget *panel = new QDockWidget("Commands");
panel->setWidget(panelContent);
addDockWidget(Qt::LeftDockWidgetArea, panel);
QDockWidget *editor = new QDockWidget("Editor");
editor->setWidget(ui_textEdit);
addDockWidget(Qt::RightDockWidgetArea, editor);
// connect gui signals
connect(run, SIGNAL(clicked()), SLOT(run()));
connect(load, SIGNAL(clicked()), SLOT(load()));
connect(save, SIGNAL(clicked()), SLOT(save()));
}
/***************************************************************************************************/
void InteractiveWidget::run()
{
m_onScreenWidget->m_commands.clear();
QString script = ui_textEdit->toPlainText();
QStringList lines = script.split("\n");
for (int i = 0; i < lines.size(); ++i)
m_onScreenWidget->m_commands.append(lines.at(i));
m_onScreenWidget->repaint();
}
/***************************************************************************************************/
void InteractiveWidget::cmdSelected(QListWidgetItem *item)
{
if (ui_textEdit->textCursor().atBlockStart()) {
ui_textEdit->insertPlainText(PaintCommands::findCommandById(item->text())->sample + "\n");
} else {
ui_textEdit->moveCursor(QTextCursor::EndOfLine);
ui_textEdit->insertPlainText("\n" + PaintCommands::findCommandById(item->text())->sample);
}
ui_textEdit->setFocus();
}
/***************************************************************************************************/
void InteractiveWidget::enumSelected(QListWidgetItem *item)
{
ui_textEdit->insertPlainText(item->text());
ui_textEdit->setFocus();
}
/***************************************************************************************************/
void InteractiveWidget::load()
{
QString fname = QFileDialog::getOpenFileName(
this,
QString("Load QPaintEngine Script"),
QFileInfo(m_filename).absoluteFilePath(),
QString("QPaintEngine Script (*.qps);;All files (*.*)"));
load(fname);
}
/***************************************************************************************************/
void InteractiveWidget::load(const QString &fname)
{
if (!fname.isEmpty()) {
m_filename = fname;
ui_textEdit->clear();
QFile file(fname);
file.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream textFile(&file);
QString script = textFile.readAll();
ui_textEdit->setPlainText(script);
m_onScreenWidget->m_filename = fname;
}
}
/***************************************************************************************************/
void InteractiveWidget::save()
{
QString script = ui_textEdit->toPlainText();
if (!script.endsWith("\n"))
script += QString("\n");
QString fname = QFileDialog::getSaveFileName(this,
QString("Save QPaintEngine Script"),
QFileInfo(m_filename).absoluteFilePath(),
QString("QPaintEngine Script (*.qps);;All files (*.*)"));
if (!fname.isEmpty()) {
m_filename = fname;
QFile file(fname);
file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
QTextStream textFile(&file);
textFile << script;
m_onScreenWidget->m_filename = fname;
}
}
/***************************************************************************************************/
bool InteractiveWidget::eventFilter(QObject *o, QEvent *e)
{
if (qobject_cast<QTextEdit *>(o) && e->type() == QEvent::KeyPress) {
QKeyEvent *ke = static_cast<QKeyEvent *>(e);
if (ke->key() == Qt::Key_Tab) {
m_commandsToolBox->currentWidget()->setFocus();
return true;
} else if (ke->key() == Qt::Key_Return && ke->modifiers() == Qt::ControlModifier) {
run();
return true;
}
}
return false;
}

View File

@ -0,0 +1,42 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef INTERACTIVEWIDGET_H
#define INTERACTIVEWIDGET_H
#include "widgets.h"
#include "paintcommands.h"
#include <QMainWindow>
#include <private/qmath_p.h>
QT_FORWARD_DECLARE_CLASS(QToolBox)
class InteractiveWidget : public QMainWindow
{
Q_OBJECT
public:
InteractiveWidget();
public slots:
void run();
void load();
void load(const QString &fname);
void save();
protected:
bool eventFilter(QObject *o, QEvent *e) override;
protected slots:
void cmdSelected(QListWidgetItem *item);
void enumSelected(QListWidgetItem *item);
private:
QToolBox *m_commandsToolBox;
QToolBox *m_enumsToolBox;
OnScreenWidget<QWidget> *m_onScreenWidget;
QTextEdit *ui_textEdit;
QString m_filename;
};
#endif

View File

@ -0,0 +1,17 @@
LANCELOT_DIR = $$[QT_HOST_PREFIX]/tests/baseline/shared
CONFIG += cmdline moc
TEMPLATE = app
INCLUDEPATH += . $$LANCELOT_DIR
QT += core-private gui-private widgets printsupport openglwidgets
HEADERS += widgets.h \
interactivewidget.h \
$$LANCELOT_DIR/paintcommands.h
SOURCES += interactivewidget.cpp \
main.cpp \
$$LANCELOT_DIR/paintcommands.cpp
RESOURCES += icons.qrc \
$$LANCELOT_DIR/../painting/images.qrc
qtHaveModule(opengl): QT += opengl

658
tests/manual/lance/main.cpp Normal file
View File

@ -0,0 +1,658 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "interactivewidget.h"
#include "widgets.h"
#include "paintcommands.h"
#include <QtCore>
#include <QtWidgets>
#include <QtPrintSupport>
#include <qimage.h>
#include <QPicture>
#include <private/qmath_p.h>
#ifdef USE_CUSTOM_DEVICE
#include "customdevice.h"
#endif
#ifndef QT_NO_OPENGL
#include <QtOpenGL/QOpenGLFramebufferObjectFormat>
#include <QtOpenGL/QOpenGLPaintDevice>
#include <QtOpenGLWidgets/QOpenGLWidget>
#endif
// #define DO_QWS_DEBUGGING
#ifdef DO_QWS_DEBUGGING
extern bool qt_show_painter_debug_output = false;
#endif
//#define CONSOLE_APPLICATION
static const struct {
const char *name;
QImage::Format format;
} imageFormats[] = {
{ "mono", QImage::Format_Mono },
{ "monolsb", QImage::Format_MonoLSB },
{ "indexed8", QImage::Format_Indexed8 },
{ "rgb32", QImage::Format_RGB32 },
{ "argb32", QImage::Format_ARGB32 },
{ "argb32_premultiplied", QImage::Format_ARGB32_Premultiplied },
{ "rgb16", QImage::Format_RGB16 },
{ "argb8565_premultiplied", QImage::Format_ARGB8565_Premultiplied },
{ "rgb666", QImage::Format_RGB666 },
{ "argb6666_premultiplied", QImage::Format_ARGB6666_Premultiplied },
{ "rgb555", QImage::Format_RGB555 },
{ "argb8555_premultiplied", QImage::Format_ARGB8555_Premultiplied },
{ "rgb888", QImage::Format_RGB888 },
{ "rgb444", QImage::Format_RGB444 },
{ "argb4444_premultiplied", QImage::Format_ARGB4444_Premultiplied }
};
static void printHelp()
{
printf("\nUsage:\n\n"
" paintcmd [options] files\n"
"\n"
" Options:\n"
" -widget Paints the files to a widget on screen\n"
" -pixmap Paints the files to a pixmap\n"
" -bitmap Paints the files to a bitmap\n"
" -image Paints the files to an image\n"
" -imageformat Set the format of the image when painting to an image\n"
" -imagemono Paints the files to a monochrome image\n"
" -imagewidget same as image, but with interacion...\n"
#ifndef QT_NO_OPENGL
" -opengl Paints the files to a QOpenGLWidget on screen\n"
" -glbuffer Paints the files to a QOpenGLFrameBufferObject (Qt5 style) \n"
" -coreglbuffer Paints the files to a Core Profile context QOpenGLFrameBufferObject\n"
#endif
#ifdef USE_CUSTOM_DEVICE
" -customdevice Paints the files to the custom paint device\n"
" -customwidget Paints the files to a custom widget on screen\n"
#endif
" -pdf Paints to a pdf\n"
" -ps Paints to a ps\n"
" -picture Prints into a picture, then shows the result in a label\n"
" -printer Prints the commands to a file called output.ps|pdf\n"
" -highres Prints in highres mode\n"
" -printdialog Opens a print dialog, then prints to the selected printer\n"
" -grab Paints the files to an image called filename_qps.png\n"
" -i Interactive mode.\n"
" -v Verbose.\n"
" -commands Displays all available commands\n"
" -w Width of the paintdevice\n"
" -h Height of the paintdevice\n"
" -scalefactor Scale factor (device pixel ratio) of the paintdevice\n"
" -cmp Show the reference picture\n"
" -bg-white No checkers background\n");
}
static void displayCommands()
{
printf("Drawing operations:\n"
" drawArc x y width height angle sweep\n"
" drawChord x y width height angle sweep\n"
" drawEllipse x y width height\n"
" drawLine x1 y1 x2 y2\n"
" drawPath pathname\n"
" drawPie x y width height angle sweep\n"
" drawPixmap pixmapfile x y width height sx sy sw sh\n"
" drawPolygon [ x1 y1 x2 y2 ... ] winding|oddeven\n"
" drawPolyline [ x1 y1 x2 y2 ... ]\n"
" drawRect x y width height\n"
" drawRoundRect x y width height xfactor yfactor\n"
" drawText x y \"text\"\n"
" drawTiledPixmap pixmapfile x y width height sx sy\n"
"\n"
"Path commands:\n"
" path_addEllipse pathname x y width height\n"
" path_addPolygon pathname [ x1 y1 x2 y2 ... ] winding?\n"
" path_addRect pathname x y width height\n"
" path_addText pathname x y \"text\" Uses current font\n"
" path_arcTo pathname x y width hegiht\n"
" path_closeSubpath pathname\n"
" path_createOutline pathname newoutlinename Uses current pen\n"
" path_cubicTo pathname c1x c1y c2x c2y endx endy\n"
" path_lineTo pathname x y\n"
" path_moveTo pathname x y\n"
" path_setFillRule pathname winding?\n"
"\n"
"Painter configuration:\n"
" resetMatrix\n"
" restore\n"
" save\n"
" rotate degrees\n"
" translate dx dy\n"
" scale sx sy\n"
" mapQuadToQuad x0 y0 x1 y1 x2 y2 x3 y3 x4 y4 x5 y5 x6 y6 x7 y7"
" setMatrix m11 m12 m13 m21 m22 m23 m31 m32 m33"
" setBackground color pattern?\n"
" setBackgroundMode TransparentMode|OpaqueMode\n"
" setBrush pixmapfile\n"
" setBrush nobrush\n"
" setBrush color pattern\n"
" setBrush x1 y1 color1 x2 y2 color2 gradient brush\n"
" setBrushOrigin x y\n"
" setFont \"fontname\" pointsize bold? italic?\n"
" setPen style color\n"
" setPen color width style capstyle joinstyle\n"
" setRenderHint LineAntialiasing\n"
" gradient_clearStops\n"
" gradient_appendStop pos color"
" gradient_setSpread [PadSpread|ReflectSpread|RepeatSpread]\n"
" gradient_setLinear x1 y1 x2 y2\n"
" gradient_setRadial center_x center_y radius focal_x focal_y\n"
" gradient_setConical center_x center_y angle\n"
"\n"
"Clipping commands:\n"
" region_addRect regionname x y width height\n"
" region_getClipRegion regionname\n"
" setClipRect x y width height\n"
" setClipRegion regionname\n"
" setClipping true|false\n"
" setClipPath pathname\n"
"\n"
"Various commands:\n"
" surface_begin x y width height\n"
" surface_end\n"
" pixmap_load filename name_in_script\n"
" image_load filename name_in_script\n");
}
static InteractiveWidget *interactive_widget = nullptr;
static void runInteractive()
{
interactive_widget = new InteractiveWidget;
interactive_widget->show();
}
static QLabel* createLabel()
{
QLabel *label = new QLabel;
QPalette palette = label->palette();
palette.setBrush(QPalette::Window, QBrush(Qt::white));
label->setPalette(palette);
return label;
}
int main(int argc, char **argv)
{
#ifdef CONSOLE_APPLICATION
QApplication app(argc, argv, QApplication::Tty);
#else
QApplication app(argc, argv);
#endif
#ifdef DO_QWS_DEBUGGING
qt_show_painter_debug_output = false;
#endif
DeviceType type = WidgetType;
QSurfaceFormat contextFormat;
contextFormat.setStencilBufferSize(8);
bool checkers_background = true;
QImage::Format imageFormat = QImage::Format_ARGB32_Premultiplied;
QLocale::setDefault(QLocale::c());
QStringList files;
bool interactive = false;
bool printdlg = false;
bool highres = false;
bool show_cmp = false;
int width = 800, height = 800;
int scaledWidth = width, scaledHeight = height;
qreal scalefactor = 1.0;
bool verboseMode = false;
#ifndef QT_NO_OPENGL
QSurfaceFormat f = QSurfaceFormat::defaultFormat();
f.setSamples(1);
f.setStencilBufferSize(8);
f.setAlphaBufferSize(8);
QSurfaceFormat::setDefaultFormat(f);
#endif
char *arg;
for (int i=1; i<argc; ++i) {
arg = argv[i];
if (*arg == '-') {
QString option = QString(arg + 1).toLower();
if (option == "widget")
type = WidgetType;
else if (option == "bitmap")
type = BitmapType;
else if (option == "pixmap")
type = PixmapType;
else if (option == "image")
type = ImageType;
else if (option == "imageformat") {
Q_ASSERT_X(i + 1 < argc, "main", "-imageformat must be followed by a value");
QString format = QString(argv[++i]).toLower();
imageFormat = QImage::Format_Invalid;
static const int formatCount =
sizeof(imageFormats) / sizeof(imageFormats[0]);
for (int ff = 0; ff < formatCount; ++ff) {
if (QLatin1String(imageFormats[ff].name) == format) {
imageFormat = imageFormats[ff].format;
break;
}
}
if (imageFormat == QImage::Format_Invalid) {
printf("Invalid image format. Available formats are:\n");
for (int ff = 0; ff < formatCount; ++ff)
printf("\t%s\n", imageFormats[ff].name);
return -1;
}
} else if (option == "imagemono")
type = ImageMonoType;
else if (option == "imagewidget")
type = ImageWidgetType;
#ifndef QT_NO_OPENGL
else if (option == "opengl")
type = OpenGLType;
else if (option == "glbuffer")
type = OpenGLBufferType;
else if (option == "coreglbuffer") {
type = OpenGLBufferType;
contextFormat.setVersion(3, 2);
contextFormat.setProfile(QSurfaceFormat::CoreProfile);
}
#endif
#ifdef USE_CUSTOM_DEVICE
else if (option == "customdevice")
type = CustomDeviceType;
else if (option == "customwidget")
type = CustomWidgetType;
#endif
else if (option == "pdf")
type = PdfType;
else if (option == "ps")
type = PsType;
else if (option == "picture")
type = PictureType;
else if (option == "printer")
type = PrinterType;
else if (option == "highres") {
type = PrinterType;
highres = true;
} else if (option == "printdialog") {
type = PrinterType;
printdlg = true;
}
else if (option == "grab")
type = GrabType;
else if (option == "i")
interactive = true;
else if (option == "v")
verboseMode = true;
else if (option == "commands") {
displayCommands();
return 0;
} else if (option == "w") {
Q_ASSERT_X(i + 1 < argc, "main", "-w must be followed by a value");
width = atoi(argv[++i]);
} else if (option == "h") {
Q_ASSERT_X(i + 1 < argc, "main", "-h must be followed by a value");
height = atoi(argv[++i]);
} else if (option == "scalefactor") {
Q_ASSERT_X(i + 1 < argc, "main", "-scalefactor must be followed by a value");
scalefactor = atof(argv[++i]);
} else if (option == "cmp") {
show_cmp = true;
} else if (option == "bg-white") {
checkers_background = false;
}
} else {
files.append(QString(argv[i]));
}
}
scaledWidth = int(width * scalefactor);
scaledHeight = int(height * scalefactor);
PaintCommands pcmd(QStringList(), 800, 800, imageFormat);
pcmd.setVerboseMode(verboseMode);
pcmd.setType(type);
pcmd.setCheckersBackground(checkers_background);
QWidget *activeWidget = nullptr;
if (interactive) {
runInteractive();
if (!files.isEmpty())
interactive_widget->load(files.at(0));
} else if (files.isEmpty()) {
printHelp();
return 0;
} else {
for (int j=0; j<files.size(); ++j) {
const QString &fileName = files.at(j);
QStringList content;
QFile file(fileName);
QFileInfo fileinfo(file);
if (file.open(QIODevice::ReadOnly)) {
QTextStream textFile(&file);
QString script = textFile.readAll();
content = script.split("\n", Qt::SkipEmptyParts);
} else {
printf("failed to read file: '%s'\n", qPrintable(fileinfo.absoluteFilePath()));
continue;
}
pcmd.setContents(content);
if (show_cmp) {
QString pmFile = QString(files.at(j)).replace(".qps", "_qps") + ".png";
qDebug() << pmFile << QFileInfo(pmFile).exists();
QPixmap pixmap(pmFile);
if (!pixmap.isNull()) {
QLabel *label = createLabel();
label->setWindowTitle("VERIFY: " + pmFile);
label->setPixmap(pixmap);
label->show();
}
}
switch (type) {
case WidgetType:
{
OnScreenWidget<QWidget> *qWidget =
new OnScreenWidget<QWidget>(files.at(j));
qWidget->setVerboseMode(verboseMode);
qWidget->setType(type);
qWidget->setCheckersBackground(checkers_background);
qWidget->m_commands = content;
qWidget->resize(width, height);
qWidget->show();
activeWidget = qWidget;
break;
}
case ImageWidgetType:
{
OnScreenWidget<QWidget> *qWidget = new OnScreenWidget<QWidget>(files.at(j));
qWidget->setVerboseMode(verboseMode);
qWidget->setType(type);
qWidget->setCheckersBackground(checkers_background);
qWidget->m_commands = content;
qWidget->resize(width, height);
qWidget->show();
activeWidget = qWidget;
break;
}
#ifndef QT_NO_OPENGL
case OpenGLBufferType:
{
QWindow win;
win.setSurfaceType(QSurface::OpenGLSurface);
win.setFormat(contextFormat);
win.create();
QOpenGLFramebufferObjectFormat fmt;
fmt.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
fmt.setSamples(4);
QOpenGLContext ctx;
ctx.setFormat(contextFormat);
ctx.create();
ctx.makeCurrent(&win);
QOpenGLFramebufferObject fbo(width, height, fmt);
fbo.bind();
QOpenGLPaintDevice pdev(width, height);
QPainter pt(&pdev);
pcmd.setPainter(&pt);
pcmd.setFilePath(fileinfo.absolutePath());
pcmd.runCommands();
pt.end();
QImage image = fbo.toImage();
QLabel *label = createLabel();
label->setPixmap(QPixmap::fromImage(image));
label->resize(label->sizeHint());
label->show();
activeWidget = label;
break;
}
case OpenGLType:
{
OnScreenWidget<QOpenGLWidget> *qOpenGLWidget = new OnScreenWidget<QOpenGLWidget>(files.at(j));
qOpenGLWidget->setVerboseMode(verboseMode);
qOpenGLWidget->setType(type);
qOpenGLWidget->setCheckersBackground(checkers_background);
qOpenGLWidget->m_commands = content;
qOpenGLWidget->resize(width, height);
qOpenGLWidget->show();
activeWidget = qOpenGLWidget;
break;
}
#else
case OpenGLType:
case OpenGLBufferType:
{
printf("OpenGL type not supported in this Qt build\n");
break;
}
#endif
#ifdef USE_CUSTOM_DEVICE
case CustomDeviceType:
{
CustomPaintDevice custom(width, height);
QPainter pt;
pt.begin(&custom);
pcmd.setPainter(&pt);
pcmd.setFilePath(fileinfo.absolutePath());
pcmd.runCommands();
pt.end();
QImage *img = custom.image();
if (img) {
QLabel *label = createLabel();
label->setPixmap(QPixmap::fromImage(*img));
label->resize(label->sizeHint());
label->show();
activeWidget = label;
img->save("custom_output_pixmap.png", "PNG");
} else {
custom.save("custom_output_pixmap.png", "PNG");
}
break;
}
case CustomWidgetType:
{
OnScreenWidget<CustomWidget> *cWidget = new OnScreenWidget<CustomWidget>;
cWidget->setVerboseMode(verboseMode);
cWidget->setType(type);
cWidget->setCheckersBackground(checkers_background);
cWidget->m_filename = files.at(j);
cWidget->setWindowTitle(fileinfo.filePath());
cWidget->m_commands = content;
cWidget->resize(width, height);
cWidget->show();
activeWidget = cWidget;
break;
}
#endif
case PixmapType:
{
QPixmap pixmap(scaledWidth, scaledHeight);
pixmap.setDevicePixelRatio(scalefactor);
pixmap.fill(Qt::white);
QPainter pt(&pixmap);
pcmd.setPainter(&pt);
pcmd.setFilePath(fileinfo.absolutePath());
pcmd.runCommands();
pt.end();
pixmap.save("output_pixmap.png", "PNG");
break;
}
case BitmapType:
{
QBitmap bitmap(scaledWidth, scaledHeight);
bitmap.setDevicePixelRatio(scalefactor);
QPainter pt(&bitmap);
pcmd.setPainter(&pt);
pcmd.setFilePath(fileinfo.absolutePath());
pcmd.runCommands();
pt.end();
bitmap.save("output_bitmap.png", "PNG");
QLabel *label = createLabel();
label->setPixmap(bitmap);
label->resize(label->sizeHint());
label->show();
activeWidget = label;
break;
}
case ImageMonoType:
case ImageType:
{
qDebug() << "Creating image";
QImage image(scaledWidth, scaledHeight, type == ImageMonoType
? QImage::Format_MonoLSB
: imageFormat);
image.setDevicePixelRatio(scalefactor);
image.fill(0);
QPainter pt(&image);
pcmd.setPainter(&pt);
pcmd.setFilePath(fileinfo.absolutePath());
pcmd.runCommands();
pt.end();
image.convertToFormat(QImage::Format_ARGB32).save("output_image.png", "PNG");
image.setDevicePixelRatio(1.0); // reset scale factor: display "large" image.
#ifndef CONSOLE_APPLICATION
QLabel *label = createLabel();
label->setPixmap(QPixmap::fromImage(image));
label->resize(label->sizeHint());
label->show();
activeWidget = label;
#endif
break;
}
case PictureType:
{
QPicture pic;
QPainter pt(&pic);
pcmd.setPainter(&pt);
pcmd.setFilePath(fileinfo.absolutePath());
pcmd.runCommands();
pt.end();
QImage image(width, height, QImage::Format_ARGB32_Premultiplied);
image.fill(0);
pt.begin(&image);
pt.drawPicture(0, 0, pic);
pt.end();
QLabel *label = createLabel();
label->setWindowTitle(fileinfo.absolutePath());
label->setPixmap(QPixmap::fromImage(image));
label->resize(label->sizeHint());
label->show();
activeWidget = label;
break;
}
case PrinterType:
{
#ifndef QT_NO_PRINTER
PaintCommands pcmd(QStringList(), 800, 800, imageFormat);
pcmd.setVerboseMode(verboseMode);
pcmd.setType(type);
pcmd.setCheckersBackground(checkers_background);
pcmd.setContents(content);
QString file = QString(files.at(j)).replace(QLatin1Char('.'), QLatin1Char('_')) + ".ps";
QPrinter p(highres ? QPrinter::HighResolution : QPrinter::ScreenResolution);
if (printdlg) {
QPrintDialog printDialog(&p, nullptr);
if (printDialog.exec() != QDialog::Accepted)
break;
} else {
p.setOutputFileName(file);
}
QPainter pt(&p);
pcmd.setPainter(&pt);
pcmd.setFilePath(fileinfo.absolutePath());
pcmd.runCommands();
pt.end();
if (!printdlg) {
printf("wrote file: %s\n", qPrintable(file));
}
Q_ASSERT(!p.paintingActive());
#endif
break;
}
case PsType:
case PdfType:
{
#ifndef QT_NO_PRINTER
PaintCommands pcmd(QStringList(), 800, 800, QImage::Format_ARGB32_Premultiplied);
pcmd.setVerboseMode(verboseMode);
pcmd.setType(type);
pcmd.setCheckersBackground(checkers_background);
pcmd.setContents(content);
QPrinter p(highres ? QPrinter::HighResolution : QPrinter::ScreenResolution);
QFileInfo input(files.at(j));
const QString file = input.baseName() + QLatin1Char('_')
+ input.suffix() + QStringLiteral(".pdf");
p.setOutputFormat(QPrinter::PdfFormat);
p.setOutputFileName(file);
p.setPageSize(QPageSize(QPageSize::A4));
QPainter pt(&p);
pcmd.setPainter(&pt);
pcmd.setFilePath(fileinfo.absolutePath());
pcmd.runCommands();
pt.end();
printf("write file: %s\n", qPrintable(file));
#endif
break;
}
case GrabType:
{
QImage image(width, height, QImage::Format_ARGB32_Premultiplied);
image.fill(QColor(Qt::white).rgb());
QPainter pt(&image);
pcmd.setPainter(&pt);
pcmd.setFilePath(fileinfo.absolutePath());
pcmd.runCommands();
pt.end();
QImage image1(width, height, QImage::Format_RGB32);
image1.fill(QColor(Qt::white).rgb());
QPainter pt1(&image1);
pt1.drawImage(QPointF(0, 0), image);
pt1.end();
QString filename = QString(files.at(j)).replace(".qps", "_qps") + ".png";
image1.save(filename, "PNG");
printf("%s grabbed to %s\n", qPrintable(files.at(j)), qPrintable(filename));
break;
}
default:
break;
}
}
}
#ifndef CONSOLE_APPLICATION
if (activeWidget || interactive) {
QObject::connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
app.exec();
}
delete activeWidget;
#endif
delete interactive_widget;
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -0,0 +1,289 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef WIDGETS_H
#define WIDGETS_H
#include "paintcommands.h"
#include <QWidget>
#include <QSettings>
#include <QFileInfo>
#include <QPainter>
#include <QPaintEvent>
#include <QListWidgetItem>
#include <QTextEdit>
#include <QHBoxLayout>
#include <QSplitter>
#include <QPushButton>
#include <QFileDialog>
#include <QTextStream>
#include <QPaintEngine>
#include <QAction>
#include <QDebug>
#include <qmath.h>
const int CP_RADIUS = 10;
template <class T>
class OnScreenWidget : public T
{
public:
enum ViewMode {
RenderView,
BaselineView,
DifferenceView
};
OnScreenWidget(const QString &file, QWidget *parent = nullptr)
: T(parent),
m_filename(file),
m_view_mode(RenderView)
{
QSettings settings("QtProject", "lance");
for (int i=0; i<10; ++i) {
QPointF suggestion(100 + i * 40, 100 + 100 * qSin(i * 3.1415 / 10.0));
m_controlPoints << settings.value("cp" + QString::number(i), suggestion).toPointF();
}
m_currentPoint = -1;
m_showControlPoints = false;
m_deviceType = WidgetType;
m_checkersBackground = true;
m_verboseMode = false;
m_baseline_name = QString(m_filename).replace(".qps", "_qps") + ".png";
if (QFileInfo(m_baseline_name).exists()) {
m_baseline = QPixmap(m_baseline_name);
}
if (m_baseline.isNull()) {
T::setWindowTitle("Rendering: '" + file + "'. No baseline available");
} else {
T::setWindowTitle("Rendering: '" + file + "'. Shortcuts: 1=render, 2=baseline, 3=difference");
QAction *renderViewAction = new QAction("Render View", this);
renderViewAction->setShortcut(Qt::Key_1);
T::connect(renderViewAction, &QAction::triggered, [&] { setMode(RenderView); });
T::addAction(renderViewAction);
QAction *baselineAction = new QAction("Baseline", this);
baselineAction->setShortcut(Qt::Key_2);
T::connect(baselineAction, &QAction::triggered, [&] { setMode(BaselineView); });
T::addAction(baselineAction);
QAction *differenceAction = new QAction("Difference View", this);
differenceAction->setShortcut(Qt::Key_3);
T::connect(differenceAction, &QAction::triggered, [&] { setMode(DifferenceView); });
T::addAction(differenceAction);
}
}
~OnScreenWidget()
{
QSettings settings("QtProject", "lance");
for (int i=0; i<10; ++i) {
settings.setValue("cp" + QString::number(i), m_controlPoints.at(i));
}
settings.sync();
}
void setMode(ViewMode mode) {
m_view_mode = mode;
QString title;
switch (m_view_mode) {
case RenderView: title = "Render"; break;
case BaselineView: title = "Baseline"; break;
case DifferenceView: title = "Difference"; break;
}
T::setWindowTitle(title + " View: " + m_filename);
T::update();
}
void setVerboseMode(bool v) { m_verboseMode = v; }
void setCheckersBackground(bool b) { m_checkersBackground = b; }
void setType(DeviceType t) { m_deviceType = t; }
void resizeEvent(QResizeEvent *e) override {
m_image = QImage();
T::resizeEvent(e);
}
void paintEvent(QPaintEvent *) override {
switch (m_view_mode) {
case RenderView: paintRenderView(); break;
case BaselineView: paintBaselineView(); break;
case DifferenceView: paintDifferenceView(); break;
}
}
void paintRenderView()
{
QPainter pt;
QPaintDevice *dev = this;
if (m_deviceType == ImageWidgetType) {
if (m_image.size() != T::size())
m_image = QImage(T::size(), QImage::Format_ARGB32_Premultiplied);
m_image.fill(0);
dev = &m_image;
}
pt.begin(dev);
PaintCommands paintCommands(m_commands, 800, 800, QImage::Format_ARGB32_Premultiplied);
paintCommands.setVerboseMode(m_verboseMode);
paintCommands.setCheckersBackground(m_checkersBackground);
paintCommands.setType(m_deviceType);
paintCommands.setPainter(&pt);
paintCommands.setControlPoints(m_controlPoints);
paintCommands.setFilePath(QFileInfo(m_filename).absolutePath());
#ifdef DO_QWS_DEBUGGING
qt_show_painter_debug_output = true;
#endif
pt.save();
paintCommands.runCommands();
pt.restore();
#ifdef DO_QWS_DEBUGGING
qt_show_painter_debug_output = false;
#endif
pt.end();
if (m_deviceType == ImageWidgetType) {
QPainter(this).drawImage(0, 0, m_image);
}
if (m_currentPoint >= 0 || m_showControlPoints) {
pt.begin(this);
pt.setRenderHint(QPainter::Antialiasing);
pt.setFont(this->font());
pt.resetTransform();
pt.setPen(QColor(127, 127, 127, 191));
pt.setBrush(QColor(191, 191, 255, 63));
for (int i=0; i<m_controlPoints.size(); ++i) {
if (m_showControlPoints || m_currentPoint == i) {
QPointF cp = m_controlPoints.at(i);
QRectF rect(cp.x() - CP_RADIUS, cp.y() - CP_RADIUS,
CP_RADIUS * 2, CP_RADIUS * 2);
pt.drawEllipse(rect);
pt.drawText(rect, Qt::AlignCenter, QString::number(i));
}
}
}
#if 0
// ### TBD: Make this work with Qt5
if (m_render_view.isNull()) {
m_render_view = QPixmap::grabWidget(this);
m_render_view.save("renderView.png");
}
#endif
}
void paintBaselineView() {
QPainter p(this);
if (m_baseline.isNull()) {
p.drawText(T::rect(), Qt::AlignCenter,
"No baseline found\n"
"file '" + m_baseline_name + "' does not exist...");
return;
}
p.drawPixmap(0, 0, m_baseline);
p.setPen(QColor::fromRgbF(0, 0, 0, 0.1));
p.setFont(QFont("Arial", 128));
p.rotate(45);
p.drawText(100, 0, "BASELINE");
}
QPixmap generateDifference()
{
QImage img(T::size(), QImage::Format_RGB32);
img.fill(0);
QPainter p(&img);
p.drawImage(0, 0, m_image);
p.setCompositionMode(QPainter::RasterOp_SourceXorDestination);
p.drawPixmap(0, 0, m_baseline);
p.end();
return QPixmap::fromImage(img);
}
void paintDifferenceView() {
QPainter p(this);
if (m_baseline.isNull()) {
p.drawText(T::rect(), Qt::AlignCenter,
"No baseline found\n"
"file '" + m_baseline_name + "' does not exist...");
return;
}
p.fillRect(T::rect(), Qt::black);
p.drawPixmap(0, 0, generateDifference());
}
void mouseMoveEvent(QMouseEvent *e) override
{
if (m_currentPoint == -1)
return;
if (T::rect().contains(e->pos()))
m_controlPoints[m_currentPoint] = e->pos();
T::update();
}
void mousePressEvent(QMouseEvent *e) override
{
if (e->button() == Qt::RightButton) {
m_showControlPoints = true;
}
if (e->button() == Qt::LeftButton) {
for (int i=0; i<m_controlPoints.size(); ++i) {
if (QLineF(m_controlPoints.at(i), e->pos()).length() < CP_RADIUS) {
m_currentPoint = i;
break;
}
}
}
T::update();
}
void mouseReleaseEvent(QMouseEvent *e) override
{
if (e->button() == Qt::LeftButton)
m_currentPoint = -1;
if (e->button() == Qt::RightButton)
m_showControlPoints = false;
T::update();
}
QSize sizeHint() const override { return QSize(800, 800); }
QList<QPointF> m_controlPoints;
int m_currentPoint;
bool m_showControlPoints;
QStringList m_commands;
QString m_filename;
QString m_baseline_name;
bool m_verboseMode;
bool m_checkersBackground;
DeviceType m_deviceType;
int m_view_mode;
QImage m_image;
QPixmap m_baseline;
QPixmap m_render_view;
};
#endif