|
/* Copyright (c) 2013 Forward Systems. All rights reserved */
|
|
#include <QDebug>
|
|
#include <QImage>
|
|
#include <QPainter>
|
|
#include <Wt/WApplication>
|
|
#include <Wt/WResource>
|
|
#include <Wt/WServer>
|
|
#include <Wt/WCssTheme>
|
|
#include <Wt/WBootstrapTheme>
|
|
#include <Wt/WEnvironment>
|
|
#include <Wt/WFileResource>
|
|
#include <Wt/WImage>
|
|
#include <Wt/WContainerWidget>
|
|
#include <Wt/WMenu>
|
|
#include <Wt/WNavigationBar>
|
|
#include <Wt/WPainter>
|
|
#include <Wt/WPaintedWidget>
|
|
#include <Wt/WVBoxLayout>
|
|
#include <Wt/WHBoxLayout>
|
|
#include <Wt/WPushButton>
|
|
#include <WQApplication>
|
|
|
|
using namespace Wt;
|
|
|
|
class SomePaintedWidget: public WPaintedWidget
|
|
{
|
|
public:
|
|
SomePaintedWidget(WContainerWidget* parent = 0);
|
|
|
|
protected:
|
|
void paintEvent(WPaintDevice *paintDevice);
|
|
};
|
|
|
|
SomePaintedWidget::SomePaintedWidget(WContainerWidget *parent):
|
|
WPaintedWidget(parent)
|
|
{
|
|
resize(200, 200);
|
|
}
|
|
|
|
void
|
|
SomePaintedWidget::paintEvent(WPaintDevice *paintDevice)
|
|
{
|
|
Wt::WPainter painter(paintDevice);
|
|
painter.setRenderHint(Wt::WPainter::Antialiasing);
|
|
|
|
painter.drawRect(Wt::WRectF(10, 10, 100, 100));
|
|
}
|
|
|
|
class TestApplication: public WQApplication
|
|
{
|
|
public:
|
|
TestApplication(const WEnvironment& env);
|
|
void create();
|
|
void destroy() {}
|
|
|
|
private:
|
|
void paintWithQt();
|
|
void paintWithWt();
|
|
|
|
WVBoxLayout* mainLayout;
|
|
WPushButton* qtButton;
|
|
WPushButton* wtButton;
|
|
};
|
|
|
|
TestApplication::TestApplication(const WEnvironment& env):
|
|
WQApplication(env)
|
|
{
|
|
|
|
}
|
|
|
|
void
|
|
TestApplication::create()
|
|
{
|
|
qtButton = new WPushButton("Paint with QPainter");
|
|
qtButton->clicked().connect(this, &TestApplication::paintWithQt);
|
|
wtButton = new WPushButton("Paint with WPainter");
|
|
wtButton->clicked().connect(this, &TestApplication::paintWithWt);
|
|
WHBoxLayout* buttonsLayout = new WHBoxLayout;
|
|
buttonsLayout->addWidget(qtButton);
|
|
buttonsLayout->addWidget(wtButton);
|
|
buttonsLayout->addStretch();
|
|
|
|
mainLayout = new WVBoxLayout(root());
|
|
mainLayout->addLayout(buttonsLayout, 0, Wt::AlignTop);
|
|
setlocale(LC_NUMERIC,"C");
|
|
}
|
|
|
|
void
|
|
TestApplication::paintWithQt()
|
|
{
|
|
//qtButton->setEnabled(false);
|
|
QImage image = QImage(QSize(100,100), QImage::Format_MonoLSB);
|
|
image.fill(Qt::color0);
|
|
|
|
QString imageName = "qimage.png";
|
|
QPainter painter;
|
|
painter.begin(&image);
|
|
painter.setPen(QPen(Qt::color1));
|
|
painter.drawRect(QRect(0,0,50,50));
|
|
painter.end();
|
|
#warning comment next line and everything works
|
|
image.save(imageName);
|
|
|
|
WFileResource *imageFile = new WFileResource("image/png",
|
|
imageName.toStdString());
|
|
WImage *wImage = new WImage(imageFile, "PNG version");
|
|
mainLayout->addWidget(wImage);
|
|
}
|
|
|
|
void
|
|
TestApplication::paintWithWt()
|
|
{
|
|
//wtButton->setEnabled(false);
|
|
mainLayout->addWidget(new SomePaintedWidget);
|
|
}
|
|
|
|
WApplication*
|
|
createApplication(const WEnvironment& env)
|
|
{
|
|
WApplication *app = new TestApplication(env);
|
|
const std::string *theme = env.getParameter("theme");
|
|
if (theme)
|
|
{
|
|
app->setTheme(new Wt::WCssTheme(*theme));
|
|
}
|
|
else
|
|
{
|
|
app->setTheme(new Wt::WBootstrapTheme(app));
|
|
}
|
|
|
|
return app;
|
|
}
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
try
|
|
{
|
|
WServer server(argv[0]);
|
|
server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
|
|
server.addEntryPoint(Application, createApplication);
|
|
if (server.start())
|
|
{
|
|
WServer::waitForShutdown();
|
|
server.stop();
|
|
}
|
|
}
|
|
catch (WServer::Exception& e)
|
|
{
|
|
qDebug() << e.what();
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|