Fix manual lance test: avoid using deprecated api

...and other slight modernizations and minor fixes.

Change-Id: Ide587d9fe59ca9113ae775882c99a50debaf9000
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
Eirik Aavitsland 2019-04-10 11:21:56 +02:00
parent 0dff40adf8
commit ecfda0d523
4 changed files with 30 additions and 47 deletions

View File

@ -1200,7 +1200,10 @@ void PaintCommands::command_drawRoundRect(QRegularExpressionMatch re)
if (m_verboseMode) if (m_verboseMode)
printf(" -(lance) drawRoundRect(%d, %d, %d, %d, [%d, %d])\n", x, y, w, h, xs, ys); printf(" -(lance) drawRoundRect(%d, %d, %d, %d, [%d, %d])\n", x, y, w, h, xs, ys);
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
m_painter->drawRoundRect(x, y, w, h, xs, ys); m_painter->drawRoundRect(x, y, w, h, xs, ys);
QT_WARNING_POP
} }
/***************************************************************************************************/ /***************************************************************************************************/

View File

@ -45,7 +45,7 @@ InteractiveWidget::InteractiveWidget()
// create and populate the command toolbox // create and populate the command toolbox
m_commandsToolBox = new QToolBox(); m_commandsToolBox = new QToolBox();
QListWidget *currentListWidget = 0; QListWidget *currentListWidget = nullptr;
foreach (PaintCommands::PaintCommandInfos paintCommandInfo, PaintCommands::s_commandInfoTable) { foreach (PaintCommands::PaintCommandInfos paintCommandInfo, PaintCommands::s_commandInfoTable) {
if (paintCommandInfo.isSectionHeader()) { if (paintCommandInfo.isSectionHeader()) {
currentListWidget = new QListWidget(); currentListWidget = new QListWidget();

View File

@ -185,7 +185,7 @@ static void displayCommands()
" pixmap_load filename name_in_script\n" " pixmap_load filename name_in_script\n"
" image_load filename name_in_script\n"); " image_load filename name_in_script\n");
} }
static InteractiveWidget *interactive_widget = 0; static InteractiveWidget *interactive_widget = nullptr;
static void runInteractive() static void runInteractive()
{ {
@ -350,15 +350,15 @@ int main(int argc, char **argv)
#endif #endif
} }
} }
scaledWidth = width * scalefactor; scaledWidth = int(width * scalefactor);
scaledHeight = height * scalefactor; scaledHeight = int(height * scalefactor);
PaintCommands pcmd(QStringList(), 800, 800, imageFormat); PaintCommands pcmd(QStringList(), 800, 800, imageFormat);
pcmd.setVerboseMode(verboseMode); pcmd.setVerboseMode(verboseMode);
pcmd.setType(type); pcmd.setType(type);
pcmd.setCheckersBackground(checkers_background); pcmd.setCheckersBackground(checkers_background);
QWidget *activeWidget = 0; QWidget *activeWidget = nullptr;
if (interactive) { if (interactive) {
runInteractive(); runInteractive();
@ -610,7 +610,7 @@ int main(int argc, char **argv)
QPrinter p(highres ? QPrinter::HighResolution : QPrinter::ScreenResolution); QPrinter p(highres ? QPrinter::HighResolution : QPrinter::ScreenResolution);
if (printdlg) { if (printdlg) {
QPrintDialog printDialog(&p, 0); QPrintDialog printDialog(&p, nullptr);
if (printDialog.exec() != QDialog::Accepted) if (printDialog.exec() != QDialog::Accepted)
break; break;
} else { } else {

View File

@ -45,31 +45,12 @@
#include <QPaintEngine> #include <QPaintEngine>
#include <QSignalMapper> #include <QSignalMapper>
#include <QAction> #include <QAction>
#include <QDebug>
#include <qmath.h> #include <qmath.h>
const int CP_RADIUS = 10; const int CP_RADIUS = 10;
class StupidWorkaround : public QObject
{
Q_OBJECT
public:
StupidWorkaround(QWidget *widget, int *value)
: QObject(widget), w(widget), mode(value)
{
}
public slots:
void setViewMode(int m) {
*mode = m;
w->update();
}
private:
QWidget *w;
int *mode;
};
template <class T> template <class T>
class OnScreenWidget : public T class OnScreenWidget : public T
{ {
@ -81,7 +62,7 @@ public:
DifferenceView DifferenceView
}; };
OnScreenWidget(const QString &file, QWidget *parent = 0) OnScreenWidget(const QString &file, QWidget *parent = nullptr)
: T(parent), : T(parent),
m_filename(file), m_filename(file),
m_view_mode(RenderView) m_view_mode(RenderView)
@ -108,33 +89,20 @@ public:
} else { } else {
T::setWindowTitle("Rendering: '" + file + "'. Shortcuts: 1=render, 2=baseline, 3=difference"); T::setWindowTitle("Rendering: '" + file + "'. Shortcuts: 1=render, 2=baseline, 3=difference");
StupidWorkaround *workaround = new StupidWorkaround(this, &m_view_mode);
QSignalMapper *mapper = new QSignalMapper(this);
T::connect(mapper, SIGNAL(mapped(int)), workaround, SLOT(setViewMode(int)));
T::connect(mapper, SIGNAL(mapped(QString)), this, SLOT(setWindowTitle(QString)));
QAction *renderViewAction = new QAction("Render View", this); QAction *renderViewAction = new QAction("Render View", this);
renderViewAction->setShortcut(Qt::Key_1); renderViewAction->setShortcut(Qt::Key_1);
T::connect(renderViewAction, SIGNAL(triggered()), mapper, SLOT(map())); T::connect(renderViewAction, &QAction::triggered, [&] { setMode(RenderView); });
mapper->setMapping(renderViewAction, RenderView);
mapper->setMapping(renderViewAction, "Render View: " + file);
T::addAction(renderViewAction); T::addAction(renderViewAction);
QAction *baselineAction = new QAction("Baseline", this); QAction *baselineAction = new QAction("Baseline", this);
baselineAction->setShortcut(Qt::Key_2); baselineAction->setShortcut(Qt::Key_2);
T::connect(baselineAction, SIGNAL(triggered()), mapper, SLOT(map())); T::connect(baselineAction, &QAction::triggered, [&] { setMode(BaselineView); });
mapper->setMapping(baselineAction, BaselineView);
mapper->setMapping(baselineAction, "Baseline View: " + file);
T::addAction(baselineAction); T::addAction(baselineAction);
QAction *differenceAction = new QAction("Differenfe View", this); QAction *differenceAction = new QAction("Difference View", this);
differenceAction->setShortcut(Qt::Key_3); differenceAction->setShortcut(Qt::Key_3);
T::connect(differenceAction, SIGNAL(triggered()), mapper, SLOT(map())); T::connect(differenceAction, &QAction::triggered, [&] { setMode(DifferenceView); });
mapper->setMapping(differenceAction, DifferenceView);
mapper->setMapping(differenceAction, "Difference View" + file);
T::addAction(differenceAction); T::addAction(differenceAction);
} }
} }
@ -148,6 +116,18 @@ public:
settings.sync(); 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 setVerboseMode(bool v) { m_verboseMode = v; }
void setCheckersBackground(bool b) { m_checkersBackground = b; } void setCheckersBackground(bool b) { m_checkersBackground = b; }
void setType(DeviceType t) { m_deviceType = t; } void setType(DeviceType t) { m_deviceType = t; }
@ -205,7 +185,7 @@ public:
pt.begin(this); pt.begin(this);
pt.setRenderHint(QPainter::Antialiasing); pt.setRenderHint(QPainter::Antialiasing);
pt.setFont(this->font()); pt.setFont(this->font());
pt.resetMatrix(); pt.resetTransform();
pt.setPen(QColor(127, 127, 127, 191)); pt.setPen(QColor(127, 127, 127, 191));
pt.setBrush(QColor(191, 191, 255, 63)); pt.setBrush(QColor(191, 191, 255, 63));
for (int i=0; i<m_controlPoints.size(); ++i) { for (int i=0; i<m_controlPoints.size(); ++i) {
@ -239,7 +219,7 @@ public:
p.drawPixmap(0, 0, m_baseline); p.drawPixmap(0, 0, m_baseline);
p.setPen(QColor::fromRgb(0, 0, 0, 0.1)); p.setPen(QColor::fromRgbF(0, 0, 0, 0.1));
p.setFont(QFont("Arial", 128)); p.setFont(QFont("Arial", 128));
p.rotate(45); p.rotate(45);
p.drawText(100, 0, "BASELINE"); p.drawText(100, 0, "BASELINE");
@ -251,7 +231,7 @@ public:
img.fill(0); img.fill(0);
QPainter p(&img); QPainter p(&img);
p.drawPixmap(0, 0, m_render_view); p.drawImage(0, 0, m_image);
p.setCompositionMode(QPainter::RasterOp_SourceXorDestination); p.setCompositionMode(QPainter::RasterOp_SourceXorDestination);
p.drawPixmap(0, 0, m_baseline); p.drawPixmap(0, 0, m_baseline);