Released version 6.1.3
This commit is contained in:
commit
a94503cb82
1885 changed files with 276310 additions and 0 deletions
72
playground/graphicscale/canvas.cpp
Normal file
72
playground/graphicscale/canvas.cpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
#include "canvas.h"
|
||||
#include <qwt_graphic.h>
|
||||
#include <qsvgrenderer.h>
|
||||
|
||||
Canvas::Canvas( Mode mode, QWidget *parent ):
|
||||
QWidget( parent ),
|
||||
d_mode( mode )
|
||||
{
|
||||
const int m = 10;
|
||||
setContentsMargins( m, m, m, m );
|
||||
|
||||
if ( d_mode == Svg )
|
||||
d_renderer = new QSvgRenderer( this );
|
||||
else
|
||||
d_graphic = new QwtGraphic();
|
||||
}
|
||||
|
||||
Canvas::~Canvas()
|
||||
{
|
||||
if ( d_mode == VectorGraphic )
|
||||
delete d_graphic;
|
||||
}
|
||||
|
||||
void Canvas::setSvg( const QByteArray &data )
|
||||
{
|
||||
if ( d_mode == VectorGraphic )
|
||||
{
|
||||
d_graphic->reset();
|
||||
|
||||
QSvgRenderer renderer;
|
||||
renderer.load( data );
|
||||
|
||||
QPainter p( d_graphic );
|
||||
renderer.render( &p, renderer.viewBoxF() );
|
||||
p.end();
|
||||
}
|
||||
else
|
||||
{
|
||||
d_renderer->load( data );
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void Canvas::paintEvent( QPaintEvent * )
|
||||
{
|
||||
QPainter painter( this );
|
||||
|
||||
painter.save();
|
||||
|
||||
painter.setPen( Qt::black );
|
||||
painter.setBrush( Qt::white );
|
||||
painter.drawRect( contentsRect().adjusted( 0, 0, -1, -1 ) );
|
||||
|
||||
painter.restore();
|
||||
|
||||
painter.setPen( Qt::NoPen );
|
||||
painter.setBrush( Qt::NoBrush );
|
||||
render( &painter, contentsRect() );
|
||||
}
|
||||
|
||||
void Canvas::render( QPainter *painter, const QRect &rect ) const
|
||||
{
|
||||
if ( d_mode == Svg )
|
||||
{
|
||||
d_renderer->render( painter, rect );
|
||||
}
|
||||
else
|
||||
{
|
||||
d_graphic->render( painter, rect );
|
||||
}
|
||||
}
|
33
playground/graphicscale/canvas.h
Normal file
33
playground/graphicscale/canvas.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include <qwidget.h>
|
||||
|
||||
class QByteArray;
|
||||
class QSvgRenderer;
|
||||
class QwtGraphic;
|
||||
|
||||
class Canvas: public QWidget
|
||||
{
|
||||
public:
|
||||
enum Mode
|
||||
{
|
||||
Svg,
|
||||
VectorGraphic
|
||||
};
|
||||
|
||||
Canvas( Mode, QWidget *parent = NULL );
|
||||
virtual ~Canvas();
|
||||
|
||||
void setSvg( const QByteArray & );
|
||||
|
||||
protected:
|
||||
virtual void paintEvent( QPaintEvent * );
|
||||
|
||||
private:
|
||||
void render( QPainter *, const QRect & ) const;
|
||||
|
||||
const Mode d_mode;
|
||||
union
|
||||
{
|
||||
QSvgRenderer *d_renderer;
|
||||
QwtGraphic *d_graphic;
|
||||
};
|
||||
};
|
23
playground/graphicscale/graphicscale.pro
Normal file
23
playground/graphicscale/graphicscale.pro
Normal file
|
@ -0,0 +1,23 @@
|
|||
################################################################
|
||||
# Qwt Widget Library
|
||||
# Copyright (C) 1997 Josef Wilgen
|
||||
# Copyright (C) 2002 Uwe Rathmann
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the Qwt License, Version 1.0
|
||||
################################################################
|
||||
|
||||
include( $${PWD}/../playground.pri )
|
||||
|
||||
TARGET = graphicscale
|
||||
QT += svg
|
||||
|
||||
HEADERS = \
|
||||
canvas.h \
|
||||
mainwindow.h
|
||||
|
||||
SOURCES = \
|
||||
canvas.cpp \
|
||||
mainwindow.cpp \
|
||||
main.cpp
|
||||
|
13
playground/graphicscale/main.cpp
Normal file
13
playground/graphicscale/main.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include <qapplication.h>
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
QApplication a( argc, argv );
|
||||
|
||||
MainWindow w;
|
||||
w.resize( 600, 400 );
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
109
playground/graphicscale/mainwindow.cpp
Normal file
109
playground/graphicscale/mainwindow.cpp
Normal file
|
@ -0,0 +1,109 @@
|
|||
#include "mainwindow.h"
|
||||
#include "canvas.h"
|
||||
#include <qtoolbar.h>
|
||||
#include <qtoolbutton.h>
|
||||
#include <qlayout.h>
|
||||
#include <qlabel.h>
|
||||
#include <qfiledialog.h>
|
||||
#include <qbuffer.h>
|
||||
#include <qpainter.h>
|
||||
#include <qsvggenerator.h>
|
||||
#include <qstatusbar.h>
|
||||
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
QWidget *w = new QWidget( this );
|
||||
|
||||
d_canvas[0] = new Canvas( Canvas::Svg, this );
|
||||
d_canvas[0]->setAutoFillBackground( true );
|
||||
d_canvas[0]->setPalette( Qt::gray );
|
||||
|
||||
d_canvas[1] = new Canvas( Canvas::VectorGraphic, this );
|
||||
d_canvas[1]->setAutoFillBackground( true );
|
||||
d_canvas[1]->setPalette( Qt::gray );
|
||||
|
||||
QVBoxLayout *vBox1 = new QVBoxLayout();
|
||||
vBox1->setContentsMargins( 0, 0, 0, 0 );
|
||||
vBox1->setSpacing( 5 );
|
||||
vBox1->addWidget( new QLabel( "SVG" ), 0, Qt::AlignCenter );
|
||||
vBox1->addWidget( d_canvas[0], 10 );
|
||||
|
||||
QVBoxLayout *vBox2 = new QVBoxLayout();
|
||||
vBox2->setContentsMargins( 0, 0, 0, 0 );
|
||||
vBox2->setSpacing( 5 );
|
||||
vBox2->addWidget( new QLabel( "Vector Graphic" ), 0, Qt::AlignCenter );
|
||||
vBox2->addWidget( d_canvas[1], 10 );
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout( w );
|
||||
layout->addLayout( vBox1 );
|
||||
layout->addLayout( vBox2 );
|
||||
|
||||
setCentralWidget( w );
|
||||
|
||||
QToolBar *toolBar = new QToolBar( this );
|
||||
|
||||
QToolButton *btnLoad = new QToolButton( toolBar );
|
||||
|
||||
btnLoad->setText( "Load SVG" );
|
||||
btnLoad->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
|
||||
toolBar->addWidget( btnLoad );
|
||||
|
||||
addToolBar( toolBar );
|
||||
|
||||
connect( btnLoad, SIGNAL( clicked() ), this, SLOT( loadSVG() ) );
|
||||
|
||||
#if 0
|
||||
QPainterPath path;
|
||||
path.addRect( QRectF( 1.0, 1.0, 2.0, 2.0 ) );
|
||||
loadPath( path );
|
||||
#endif
|
||||
};
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void MainWindow::loadSVG()
|
||||
{
|
||||
QString dir = "/home1/uwe/qwt/qwt/tests/svg";
|
||||
const QString fileName = QFileDialog::getOpenFileName( NULL,
|
||||
"Load a Scaleable Vector Graphic (SVG) Document",
|
||||
dir, "SVG Files (*.svg)" );
|
||||
|
||||
if ( !fileName.isEmpty() )
|
||||
loadSVG( fileName );
|
||||
|
||||
statusBar()->showMessage( fileName );
|
||||
}
|
||||
|
||||
void MainWindow::loadSVG( const QString &fileName )
|
||||
{
|
||||
QFile file( fileName );
|
||||
if ( !file.open(QIODevice::ReadOnly | QIODevice::Text) )
|
||||
return;
|
||||
|
||||
const QByteArray document = file.readAll();
|
||||
file.close();
|
||||
|
||||
d_canvas[0]->setSvg( document );
|
||||
d_canvas[1]->setSvg( document );
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::loadPath( const QPainterPath &path )
|
||||
{
|
||||
QBuffer buf;
|
||||
|
||||
QSvgGenerator generator;
|
||||
generator.setOutputDevice( &buf );
|
||||
|
||||
QPainter painter( &generator );
|
||||
painter.setRenderHint( QPainter::Antialiasing, false );
|
||||
painter.setPen( QPen( Qt::blue, 0 ) );
|
||||
painter.setBrush( Qt::darkCyan );
|
||||
painter.drawPath( path );
|
||||
painter.end();
|
||||
|
||||
d_canvas[0]->setSvg( buf.data() );
|
||||
d_canvas[1]->setSvg( buf.data() );
|
||||
}
|
22
playground/graphicscale/mainwindow.h
Normal file
22
playground/graphicscale/mainwindow.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include <qmainwindow.h>
|
||||
|
||||
class Canvas;
|
||||
class QPainterPath;
|
||||
|
||||
class MainWindow: public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow();
|
||||
virtual ~MainWindow();
|
||||
|
||||
private Q_SLOTS:
|
||||
void loadSVG();
|
||||
|
||||
private:
|
||||
void loadSVG( const QString & );
|
||||
void loadPath( const QPainterPath & );
|
||||
|
||||
Canvas *d_canvas[2];
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue