forked from qt-creator/qt-creator
QmlProfiler: first commit
This commit is contained in:
11
src/plugins/qmlprofiler/canvas/canvas.pri
Normal file
11
src/plugins/qmlprofiler/canvas/canvas.pri
Normal file
@@ -0,0 +1,11 @@
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += $$PWD/qdeclarativecontext2d_p.h \
|
||||
$$PWD/qdeclarativecanvas_p.h \
|
||||
$$PWD/qdeclarativetiledcanvas_p.h \
|
||||
$$PWD/qdeclarativecanvastimer_p.h
|
||||
|
||||
SOURCES += $$PWD/qdeclarativecontext2d.cpp \
|
||||
$$PWD/qdeclarativecanvas.cpp \
|
||||
$$PWD/qdeclarativetiledcanvas.cpp \
|
||||
$$PWD/qdeclarativecanvastimer.cpp
|
||||
257
src/plugins/qmlprofiler/canvas/qdeclarativecanvas.cpp
Normal file
257
src/plugins/qmlprofiler/canvas/qdeclarativecanvas.cpp
Normal file
@@ -0,0 +1,257 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the QtDeclarative module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** No Commercial Usage
|
||||
** This file contains pre-release code and may not be distributed.
|
||||
** You may use this file in accordance with the terms and conditions
|
||||
** contained in the Technology Preview License Agreement accompanying
|
||||
** this package.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qdeclarativecanvas_p.h"
|
||||
#include "qdeclarativecanvastimer_p.h"
|
||||
#include "qdeclarativecontext2d_p.h"
|
||||
|
||||
#include <QtGui/qpainter.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
Canvas::Canvas(QDeclarativeItem *parent)
|
||||
: QDeclarativeItem(parent),
|
||||
m_context(new Context2D(this)),
|
||||
m_canvasWidth(0),
|
||||
m_canvasHeight(0),
|
||||
m_fillMode(Canvas::Stretch),
|
||||
m_color(Qt::white)
|
||||
{
|
||||
setFlag(QGraphicsItem::ItemHasNoContents, false);
|
||||
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
|
||||
}
|
||||
|
||||
|
||||
void Canvas::componentComplete()
|
||||
{
|
||||
if (m_canvasWidth == 0 && m_canvasHeight == 0)
|
||||
m_context->setSize(width(), height());
|
||||
else
|
||||
m_context->setSize(m_canvasWidth, m_canvasHeight);
|
||||
|
||||
connect(m_context, SIGNAL(changed()), this, SLOT(requestPaint()));
|
||||
emit init();
|
||||
QDeclarativeItem::componentComplete();
|
||||
}
|
||||
|
||||
void Canvas::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
|
||||
{
|
||||
m_context->setInPaint(true);
|
||||
emit paint();
|
||||
|
||||
bool oldAA = painter->testRenderHint(QPainter::Antialiasing);
|
||||
bool oldSmooth = painter->testRenderHint(QPainter::SmoothPixmapTransform);
|
||||
if (smooth())
|
||||
painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, smooth());
|
||||
|
||||
if (m_context->pixmap().isNull()) {
|
||||
painter->fillRect(0, 0, width(), height(), m_color);
|
||||
} else if (width() != m_context->pixmap().width() || height() != m_context->pixmap().height()) {
|
||||
if (m_fillMode>= Tile) {
|
||||
if (m_fillMode== Tile) {
|
||||
painter->drawTiledPixmap(QRectF(0,0,width(),height()), m_context->pixmap());
|
||||
} else {
|
||||
qreal widthScale = width() / qreal(m_context->pixmap().width());
|
||||
qreal heightScale = height() / qreal(m_context->pixmap().height());
|
||||
|
||||
QTransform scale;
|
||||
if (m_fillMode== TileVertically) {
|
||||
scale.scale(widthScale, 1.0);
|
||||
QTransform old = painter->transform();
|
||||
painter->setWorldTransform(scale * old);
|
||||
painter->drawTiledPixmap(QRectF(0,0,m_context->pixmap().width(),height()), m_context->pixmap());
|
||||
painter->setWorldTransform(old);
|
||||
} else {
|
||||
scale.scale(1.0, heightScale);
|
||||
QTransform old = painter->transform();
|
||||
painter->setWorldTransform(scale * old);
|
||||
painter->drawTiledPixmap(QRectF(0,0,width(),m_context->pixmap().height()), m_context->pixmap());
|
||||
painter->setWorldTransform(old);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qreal widthScale = width() / qreal(m_context->pixmap().width());
|
||||
qreal heightScale = height() / qreal(m_context->pixmap().height());
|
||||
|
||||
QTransform scale;
|
||||
|
||||
if (m_fillMode== PreserveAspectFit) {
|
||||
if (widthScale <= heightScale) {
|
||||
heightScale = widthScale;
|
||||
scale.translate(0, (height() - heightScale * m_context->pixmap().height()) / 2);
|
||||
} else if (heightScale < widthScale) {
|
||||
widthScale = heightScale;
|
||||
scale.translate((width() - widthScale * m_context->pixmap().width()) / 2, 0);
|
||||
}
|
||||
} else if (m_fillMode== PreserveAspectCrop) {
|
||||
if (widthScale < heightScale) {
|
||||
widthScale = heightScale;
|
||||
scale.translate((width() - widthScale * m_context->pixmap().width()) / 2, 0);
|
||||
} else if (heightScale < widthScale) {
|
||||
heightScale = widthScale;
|
||||
scale.translate(0, (height() - heightScale * m_context->pixmap().height()) / 2);
|
||||
}
|
||||
}
|
||||
if (clip()) {
|
||||
painter->save();
|
||||
painter->setClipRect(boundingRect(), Qt::IntersectClip);
|
||||
}
|
||||
scale.scale(widthScale, heightScale);
|
||||
QTransform old = painter->transform();
|
||||
painter->setWorldTransform(scale * old);
|
||||
painter->drawPixmap(0, 0, m_context->pixmap());
|
||||
painter->setWorldTransform(old);
|
||||
if (clip()) {
|
||||
painter->restore();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
painter->drawPixmap(0, 0, m_context->pixmap());
|
||||
}
|
||||
|
||||
if (smooth()) {
|
||||
painter->setRenderHint(QPainter::Antialiasing, oldAA);
|
||||
painter->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth);
|
||||
}
|
||||
m_context->setInPaint(false);
|
||||
}
|
||||
|
||||
Context2D *Canvas::getContext(const QString &contextId)
|
||||
{
|
||||
if (contextId == QLatin1String("2d"))
|
||||
return m_context;
|
||||
qDebug("Canvas:requesting unsupported context");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Canvas::requestPaint()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
void Canvas::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
|
||||
{
|
||||
if (m_canvasWidth == 0 && m_canvasHeight == 0
|
||||
&& newGeometry.width() > 0 && newGeometry.height() > 0) {
|
||||
m_context->setSize(width(), height());
|
||||
}
|
||||
QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
|
||||
}
|
||||
|
||||
void Canvas::setCanvasWidth(int newWidth)
|
||||
{
|
||||
if (m_canvasWidth != newWidth) {
|
||||
m_canvasWidth = newWidth;
|
||||
m_context->setSize(m_canvasWidth, m_canvasHeight);
|
||||
emit canvasWidthChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::setCanvasHeight(int newHeight)
|
||||
{
|
||||
if (m_canvasHeight != newHeight) {
|
||||
m_canvasHeight = newHeight;
|
||||
m_context->setSize(m_canvasWidth, m_canvasHeight);
|
||||
emit canvasHeightChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::setFillMode(FillMode mode)
|
||||
{
|
||||
if (m_fillMode == mode)
|
||||
return;
|
||||
|
||||
m_fillMode = mode;
|
||||
update();
|
||||
emit fillModeChanged();
|
||||
}
|
||||
|
||||
QColor Canvas::color()
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
void Canvas::setColor(const QColor &color)
|
||||
{
|
||||
if (m_color !=color) {
|
||||
m_color = color;
|
||||
colorChanged();
|
||||
}
|
||||
}
|
||||
|
||||
Canvas::FillMode Canvas::fillMode() const
|
||||
{
|
||||
return m_fillMode;
|
||||
}
|
||||
|
||||
bool Canvas::save(const QString &filename) const
|
||||
{
|
||||
return m_context->pixmap().save(filename);
|
||||
}
|
||||
|
||||
CanvasImage *Canvas::toImage() const
|
||||
{
|
||||
return new CanvasImage(m_context->pixmap());
|
||||
}
|
||||
|
||||
void Canvas::setTimeout(const QScriptValue &handler, long timeout)
|
||||
{
|
||||
if (handler.isFunction())
|
||||
CanvasTimer::createTimer(this, handler, timeout, true);
|
||||
}
|
||||
|
||||
void Canvas::setInterval(const QScriptValue &handler, long interval)
|
||||
{
|
||||
if (handler.isFunction())
|
||||
CanvasTimer::createTimer(this, handler, interval, false);
|
||||
}
|
||||
|
||||
void Canvas::clearTimeout(const QScriptValue &handler)
|
||||
{
|
||||
CanvasTimer::removeTimer(handler);
|
||||
}
|
||||
|
||||
void Canvas::clearInterval(const QScriptValue &handler)
|
||||
{
|
||||
CanvasTimer::removeTimer(handler);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
124
src/plugins/qmlprofiler/canvas/qdeclarativecanvas_p.h
Normal file
124
src/plugins/qmlprofiler/canvas/qdeclarativecanvas_p.h
Normal file
@@ -0,0 +1,124 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the QtDeclarative module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** No Commercial Usage
|
||||
** This file contains pre-release code and may not be distributed.
|
||||
** You may use this file in accordance with the terms and conditions
|
||||
** contained in the Technology Preview License Agreement accompanying
|
||||
** this package.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QDECLARATIVECANVAS_P_H
|
||||
#define QDECLARATIVECANVAS_P_H
|
||||
|
||||
#include <QtDeclarative/qdeclarativeitem.h>
|
||||
|
||||
#include "qdeclarativecontext2d_p.h"
|
||||
#include "qdeclarativecanvastimer_p.h"
|
||||
|
||||
QT_BEGIN_HEADER
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QT_MODULE(Declarative)
|
||||
class Canvas : public QDeclarativeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_ENUMS(FillMode)
|
||||
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged);
|
||||
Q_PROPERTY(int canvasWidth READ canvasWidth WRITE setCanvasWidth NOTIFY canvasWidthChanged);
|
||||
Q_PROPERTY(int canvasHeight READ canvasHeight WRITE setCanvasHeight NOTIFY canvasHeightChanged);
|
||||
Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
|
||||
|
||||
public:
|
||||
Canvas(QDeclarativeItem *parent = 0);
|
||||
enum FillMode { Stretch, PreserveAspectFit, PreserveAspectCrop, Tile, TileVertically, TileHorizontally };
|
||||
|
||||
|
||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
||||
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
|
||||
void setCanvasWidth(int newWidth);
|
||||
int canvasWidth() {return m_canvasWidth;}
|
||||
|
||||
void setCanvasHeight(int canvasHeight);
|
||||
int canvasHeight() {return m_canvasHeight;}
|
||||
|
||||
void componentComplete();
|
||||
|
||||
|
||||
public Q_SLOTS:
|
||||
Context2D *getContext(const QString & = QString("2d"));
|
||||
void requestPaint();
|
||||
|
||||
FillMode fillMode() const;
|
||||
void setFillMode(FillMode);
|
||||
|
||||
QColor color();
|
||||
void setColor(const QColor &);
|
||||
|
||||
// Save current canvas to disk
|
||||
bool save(const QString& filename) const;
|
||||
|
||||
// Timers
|
||||
void setInterval(const QScriptValue &handler, long timeout);
|
||||
void setTimeout(const QScriptValue &handler, long timeout);
|
||||
void clearInterval(const QScriptValue &handler);
|
||||
void clearTimeout(const QScriptValue &handler);
|
||||
|
||||
Q_SIGNALS:
|
||||
void fillModeChanged();
|
||||
void canvasWidthChanged();
|
||||
void canvasHeightChanged();
|
||||
void colorChanged();
|
||||
void init();
|
||||
void paint();
|
||||
|
||||
private:
|
||||
// Return canvas contents as a drawable image
|
||||
CanvasImage *toImage() const;
|
||||
Context2D *m_context;
|
||||
int m_canvasWidth;
|
||||
int m_canvasHeight;
|
||||
FillMode m_fillMode;
|
||||
QColor m_color;
|
||||
|
||||
friend class Context2D;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_END_HEADER
|
||||
|
||||
#endif //QDECLARATIVECANVAS_P_H
|
||||
98
src/plugins/qmlprofiler/canvas/qdeclarativecanvastimer.cpp
Normal file
98
src/plugins/qmlprofiler/canvas/qdeclarativecanvastimer.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the QtDeclarative module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** No Commercial Usage
|
||||
** This file contains pre-release code and may not be distributed.
|
||||
** You may use this file in accordance with the terms and conditions
|
||||
** contained in the Technology Preview License Agreement accompanying
|
||||
** this package.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtScript/qscriptengine.h>
|
||||
#include <QtScript/qscriptvalue.h>
|
||||
#include <QtCore/qtimer.h>
|
||||
|
||||
#include "qdeclarativecanvastimer_p.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
Q_GLOBAL_STATIC(QList<CanvasTimer*> , activeTimers);
|
||||
|
||||
CanvasTimer::CanvasTimer(QObject *parent, const QScriptValue &data)
|
||||
: QTimer(parent), m_value(data)
|
||||
{
|
||||
}
|
||||
|
||||
void CanvasTimer::handleTimeout()
|
||||
{
|
||||
Q_ASSERT(m_value.isFunction());
|
||||
m_value.call();
|
||||
if (isSingleShot()) {
|
||||
removeTimer(this);
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasTimer::createTimer(QObject *parent, const QScriptValue &val, long timeout, bool singleshot)
|
||||
{
|
||||
|
||||
CanvasTimer *timer = new CanvasTimer(parent, val);
|
||||
timer->setInterval(timeout);
|
||||
timer->setSingleShot(singleshot);
|
||||
connect(timer, SIGNAL(timeout()), timer, SLOT(handleTimeout()));
|
||||
activeTimers()->append(timer);
|
||||
timer->start();
|
||||
}
|
||||
|
||||
void CanvasTimer::removeTimer(CanvasTimer *timer)
|
||||
{
|
||||
activeTimers()->removeAll(timer);
|
||||
timer->deleteLater();
|
||||
}
|
||||
|
||||
void CanvasTimer::removeTimer(const QScriptValue &val)
|
||||
{
|
||||
if (!val.isFunction())
|
||||
return;
|
||||
|
||||
for (int i = 0 ; i < activeTimers()->count() ; ++i) {
|
||||
CanvasTimer *timer = activeTimers()->at(i);
|
||||
if (timer->equals(val)) {
|
||||
removeTimer(timer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
80
src/plugins/qmlprofiler/canvas/qdeclarativecanvastimer_p.h
Normal file
80
src/plugins/qmlprofiler/canvas/qdeclarativecanvastimer_p.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the QtDeclarative module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** No Commercial Usage
|
||||
** This file contains pre-release code and may not be distributed.
|
||||
** You may use this file in accordance with the terms and conditions
|
||||
** contained in the Technology Preview License Agreement accompanying
|
||||
** this package.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QDECLARATIVECANVASTIMER_P_H
|
||||
#define QDECLARATIVECANVASTIMER_P_H
|
||||
|
||||
#include <QtScript/qscriptvalue.h>
|
||||
#include <QtCore/qtimer.h>
|
||||
#include <QtCore/qlist.h>
|
||||
|
||||
QT_BEGIN_HEADER
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QT_MODULE(Declarative)
|
||||
|
||||
class CanvasTimer : public QTimer
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CanvasTimer(QObject *parent, const QScriptValue &data);
|
||||
|
||||
public Q_SLOTS:
|
||||
void handleTimeout();
|
||||
bool equals(const QScriptValue &value){return m_value.equals(value);}
|
||||
|
||||
public:
|
||||
static void createTimer(QObject *parent, const QScriptValue &val, long timeout, bool singleshot);
|
||||
static void removeTimer(CanvasTimer *timer);
|
||||
static void removeTimer(const QScriptValue &);
|
||||
|
||||
private:
|
||||
QScriptValue m_value;
|
||||
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_END_HEADER
|
||||
|
||||
#endif // QDECLARATIVECANVASTIMER_P_H
|
||||
1139
src/plugins/qmlprofiler/canvas/qdeclarativecontext2d.cpp
Normal file
1139
src/plugins/qmlprofiler/canvas/qdeclarativecontext2d.cpp
Normal file
File diff suppressed because it is too large
Load Diff
342
src/plugins/qmlprofiler/canvas/qdeclarativecontext2d_p.h
Normal file
342
src/plugins/qmlprofiler/canvas/qdeclarativecontext2d_p.h
Normal file
@@ -0,0 +1,342 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the QtDeclarative module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** No Commercial Usage
|
||||
** This file contains pre-release code and may not be distributed.
|
||||
** You may use this file in accordance with the terms and conditions
|
||||
** contained in the Technology Preview License Agreement accompanying
|
||||
** this package.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QDECLARATIVECONTEXT2D_P_H
|
||||
#define QDECLARATIVECONTEXT2D_P_H
|
||||
|
||||
#include <QtGui/qpainter.h>
|
||||
#include <QtGui/qpainterpath.h>
|
||||
#include <QtGui/qpixmap.h>
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtCore/qstack.h>
|
||||
#include <QtCore/qmetatype.h>
|
||||
#include <QtCore/qcoreevent.h>
|
||||
#include <QtCore/qvariant.h>
|
||||
#include <QtScript/qscriptvalue.h>
|
||||
|
||||
QT_BEGIN_HEADER
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QT_MODULE(Declarative)
|
||||
|
||||
QColor colorFromString(const QString &name);
|
||||
|
||||
class CanvasGradient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CanvasGradient(const QGradient &gradient) : m_gradient(gradient) {}
|
||||
|
||||
public slots:
|
||||
QGradient value() { return m_gradient; }
|
||||
void addColorStop(float pos, const QString &color) { m_gradient.setColorAt(pos, colorFromString(color));}
|
||||
|
||||
public:
|
||||
QGradient m_gradient;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(CanvasGradient*)
|
||||
|
||||
|
||||
class CanvasImage: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString src READ src WRITE setSrc NOTIFY sourceChanged)
|
||||
Q_PROPERTY(int width READ width)
|
||||
Q_PROPERTY(int height READ height)
|
||||
|
||||
public:
|
||||
CanvasImage() {}
|
||||
CanvasImage(const QString &url) : m_image(url), m_src(url) {}
|
||||
CanvasImage(const QPixmap &pixmap) {m_image = pixmap;}
|
||||
|
||||
public slots:
|
||||
int width() { return m_image.width(); }
|
||||
int height() { return m_image.height(); }
|
||||
QPixmap &value() { return m_image; }
|
||||
QString src() { return m_src; }
|
||||
void setSrc(const QString &src) { m_src = src; m_image.load(src); emit sourceChanged();}
|
||||
signals:
|
||||
void sourceChanged();
|
||||
|
||||
private:
|
||||
QPixmap m_image;
|
||||
QString m_src;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(CanvasImage*)
|
||||
|
||||
|
||||
class ImageData {
|
||||
};
|
||||
|
||||
class Context2D : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
// compositing
|
||||
Q_PROPERTY(qreal globalAlpha READ globalAlpha WRITE setGlobalAlpha)
|
||||
Q_PROPERTY(QString globalCompositeOperation READ globalCompositeOperation WRITE setGlobalCompositeOperation)
|
||||
Q_PROPERTY(QVariant strokeStyle READ strokeStyle WRITE setStrokeStyle)
|
||||
Q_PROPERTY(QVariant fillStyle READ fillStyle WRITE setFillStyle)
|
||||
// line caps/joins
|
||||
Q_PROPERTY(qreal lineWidth READ lineWidth WRITE setLineWidth)
|
||||
Q_PROPERTY(QString lineCap READ lineCap WRITE setLineCap)
|
||||
Q_PROPERTY(QString lineJoin READ lineJoin WRITE setLineJoin)
|
||||
Q_PROPERTY(qreal miterLimit READ miterLimit WRITE setMiterLimit)
|
||||
// shadows
|
||||
Q_PROPERTY(qreal shadowOffsetX READ shadowOffsetX WRITE setShadowOffsetX)
|
||||
Q_PROPERTY(qreal shadowOffsetY READ shadowOffsetY WRITE setShadowOffsetY)
|
||||
Q_PROPERTY(qreal shadowBlur READ shadowBlur WRITE setShadowBlur)
|
||||
Q_PROPERTY(QString shadowColor READ shadowColor WRITE setShadowColor)
|
||||
// fonts
|
||||
Q_PROPERTY(QString font READ font WRITE setFont)
|
||||
Q_PROPERTY(QString textBaseline READ textBaseline WRITE setTextBaseline)
|
||||
Q_PROPERTY(QString textAlign READ textAlign WRITE setTextAlign)
|
||||
|
||||
enum TextBaseLine { Alphabetic=0, Top, Middle, Bottom, Hanging};
|
||||
enum TextAlign { Start=0, End, Left, Right, Center};
|
||||
|
||||
public:
|
||||
Context2D(QObject *parent = 0);
|
||||
void setSize(int width, int height);
|
||||
void setSize(const QSize &size);
|
||||
QSize size() const;
|
||||
|
||||
QPoint painterTranslate() const;
|
||||
void setPainterTranslate(const QPoint &);
|
||||
|
||||
void scheduleChange();
|
||||
void timerEvent(QTimerEvent *e);
|
||||
|
||||
void clear();
|
||||
void reset();
|
||||
|
||||
QPixmap pixmap() { return m_pixmap; }
|
||||
|
||||
// compositing
|
||||
qreal globalAlpha() const; // (default 1.0)
|
||||
QString globalCompositeOperation() const; // (default over)
|
||||
QVariant strokeStyle() const; // (default black)
|
||||
QVariant fillStyle() const; // (default black)
|
||||
|
||||
void setGlobalAlpha(qreal alpha);
|
||||
void setGlobalCompositeOperation(const QString &op);
|
||||
void setStrokeStyle(const QVariant &style);
|
||||
void setFillStyle(const QVariant &style);
|
||||
|
||||
// line caps/joins
|
||||
qreal lineWidth() const; // (default 1)
|
||||
QString lineCap() const; // "butt", "round", "square" (default "butt")
|
||||
QString lineJoin() const; // "round", "bevel", "miter" (default "miter")
|
||||
qreal miterLimit() const; // (default 10)
|
||||
|
||||
void setLineWidth(qreal w);
|
||||
void setLineCap(const QString &s);
|
||||
void setLineJoin(const QString &s);
|
||||
void setMiterLimit(qreal m);
|
||||
|
||||
void setFont(const QString &font);
|
||||
QString font();
|
||||
void setTextBaseline(const QString &font);
|
||||
QString textBaseline();
|
||||
void setTextAlign(const QString &font);
|
||||
QString textAlign();
|
||||
|
||||
// shadows
|
||||
qreal shadowOffsetX() const; // (default 0)
|
||||
qreal shadowOffsetY() const; // (default 0)
|
||||
qreal shadowBlur() const; // (default 0)
|
||||
QString shadowColor() const; // (default black)
|
||||
|
||||
void setShadowOffsetX(qreal x);
|
||||
void setShadowOffsetY(qreal y);
|
||||
void setShadowBlur(qreal b);
|
||||
void setShadowColor(const QString &str);
|
||||
|
||||
struct MouseArea {
|
||||
QScriptValue callback;
|
||||
QScriptValue data;
|
||||
QRectF rect;
|
||||
QMatrix matrix;
|
||||
};
|
||||
const QList<MouseArea> &mouseAreas() const;
|
||||
|
||||
public slots:
|
||||
void save(); // push state on state stack
|
||||
void restore(); // pop state stack and restore state
|
||||
|
||||
void fillText(const QString &text, qreal x, qreal y);
|
||||
void strokeText(const QString &text, qreal x, qreal y);
|
||||
|
||||
void setInPaint(bool val){m_inPaint = val;}
|
||||
void scale(qreal x, qreal y);
|
||||
void rotate(qreal angle);
|
||||
void translate(qreal x, qreal y);
|
||||
void transform(qreal m11, qreal m12, qreal m21, qreal m22,
|
||||
qreal dx, qreal dy);
|
||||
void setTransform(qreal m11, qreal m12, qreal m21, qreal m22,
|
||||
qreal dx, qreal dy);
|
||||
|
||||
CanvasGradient *createLinearGradient(qreal x0, qreal y0,
|
||||
qreal x1, qreal y1);
|
||||
CanvasGradient *createRadialGradient(qreal x0, qreal y0,
|
||||
qreal r0, qreal x1,
|
||||
qreal y1, qreal r1);
|
||||
|
||||
// rects
|
||||
void clearRect(qreal x, qreal y, qreal w, qreal h);
|
||||
void fillRect(qreal x, qreal y, qreal w, qreal h);
|
||||
void strokeRect(qreal x, qreal y, qreal w, qreal h);
|
||||
|
||||
// mouse
|
||||
void mouseArea(qreal x, qreal y, qreal w, qreal h, const QScriptValue &, const QScriptValue & = QScriptValue());
|
||||
|
||||
// path API
|
||||
void beginPath();
|
||||
void closePath();
|
||||
void moveTo(qreal x, qreal y);
|
||||
void lineTo(qreal x, qreal y);
|
||||
void quadraticCurveTo(qreal cpx, qreal cpy, qreal x, qreal y);
|
||||
void bezierCurveTo(qreal cp1x, qreal cp1y,
|
||||
qreal cp2x, qreal cp2y, qreal x, qreal y);
|
||||
void arcTo(qreal x1, qreal y1, qreal x2, qreal y2, qreal radius);
|
||||
void rect(qreal x, qreal y, qreal w, qreal h);
|
||||
void arc(qreal x, qreal y, qreal radius,
|
||||
qreal startAngle, qreal endAngle,
|
||||
bool anticlockwise);
|
||||
void fill();
|
||||
void stroke();
|
||||
void clip();
|
||||
bool isPointInPath(qreal x, qreal y) const;
|
||||
|
||||
CanvasImage *createImage(const QString &url);
|
||||
|
||||
// drawing images (no overloads due to QTBUG-11604)
|
||||
void drawImage(const QVariant &var, qreal dx, qreal dy, qreal dw, qreal dh);
|
||||
|
||||
// pixel manipulation
|
||||
ImageData getImageData(qreal sx, qreal sy, qreal sw, qreal sh);
|
||||
void putImageData(ImageData image, qreal dx, qreal dy);
|
||||
void endPainting();
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
private:
|
||||
void setupPainter();
|
||||
void beginPainting();
|
||||
void updateShadowBuffer();
|
||||
|
||||
int m_changeTimerId;
|
||||
QPainterPath m_path;
|
||||
|
||||
enum DirtyFlag {
|
||||
DirtyTransformationMatrix = 0x00001,
|
||||
DirtyClippingRegion = 0x00002,
|
||||
DirtyStrokeStyle = 0x00004,
|
||||
DirtyFillStyle = 0x00008,
|
||||
DirtyGlobalAlpha = 0x00010,
|
||||
DirtyLineWidth = 0x00020,
|
||||
DirtyLineCap = 0x00040,
|
||||
DirtyLineJoin = 0x00080,
|
||||
DirtyMiterLimit = 0x00100,
|
||||
MDirtyPen = DirtyStrokeStyle
|
||||
| DirtyLineWidth
|
||||
| DirtyLineCap
|
||||
| DirtyLineJoin
|
||||
| DirtyMiterLimit,
|
||||
DirtyShadowOffsetX = 0x00200,
|
||||
DirtyShadowOffsetY = 0x00400,
|
||||
DirtyShadowBlur = 0x00800,
|
||||
DirtyShadowColor = 0x01000,
|
||||
DirtyGlobalCompositeOperation = 0x2000,
|
||||
DirtyFont = 0x04000,
|
||||
DirtyTextAlign = 0x08000,
|
||||
DirtyTextBaseline = 0x10000,
|
||||
AllIsFullOfDirt = 0xfffff
|
||||
};
|
||||
|
||||
struct State {
|
||||
State() : flags(0) {}
|
||||
QMatrix matrix;
|
||||
QPainterPath clipPath;
|
||||
QBrush strokeStyle;
|
||||
QBrush fillStyle;
|
||||
qreal globalAlpha;
|
||||
qreal lineWidth;
|
||||
Qt::PenCapStyle lineCap;
|
||||
Qt::PenJoinStyle lineJoin;
|
||||
qreal miterLimit;
|
||||
qreal shadowOffsetX;
|
||||
qreal shadowOffsetY;
|
||||
qreal shadowBlur;
|
||||
QColor shadowColor;
|
||||
QPainter::CompositionMode globalCompositeOperation;
|
||||
QFont font;
|
||||
Context2D::TextAlign textAlign;
|
||||
Context2D::TextBaseLine textBaseline;
|
||||
int flags;
|
||||
};
|
||||
|
||||
int baseLineOffset(Context2D::TextBaseLine value, const QFontMetrics &metrics);
|
||||
int textAlignOffset(Context2D::TextAlign value, const QFontMetrics &metrics, const QString &string);
|
||||
|
||||
QMatrix worldMatrix() const;
|
||||
|
||||
QPoint m_painterTranslate;
|
||||
State m_state;
|
||||
QStack<State> m_stateStack;
|
||||
QPixmap m_pixmap;
|
||||
QList<MouseArea> m_mouseAreas;
|
||||
QImage m_shadowbuffer;
|
||||
QVector<QRgb> m_shadowColorIndexBuffer;
|
||||
QColor m_shadowColorBuffer;
|
||||
QPainter m_painter;
|
||||
int m_width, m_height;
|
||||
bool m_inPaint;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_END_HEADER
|
||||
|
||||
#endif // QDECLARATIVECONTEXT2D_P_H
|
||||
163
src/plugins/qmlprofiler/canvas/qdeclarativetiledcanvas.cpp
Normal file
163
src/plugins/qmlprofiler/canvas/qdeclarativetiledcanvas.cpp
Normal file
@@ -0,0 +1,163 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qdeclarativetiledcanvas_p.h"
|
||||
|
||||
#include "qdeclarativecontext2d_p.h"
|
||||
|
||||
#include <QtGui/qpixmap.h>
|
||||
#include <QtGui/qpainter.h>
|
||||
|
||||
TiledCanvas::TiledCanvas()
|
||||
: m_context2d(new Context2D(this)), m_canvasSize(-1, -1), m_tileSize(100, 100)
|
||||
{
|
||||
setFlag(QGraphicsItem::ItemHasNoContents, false);
|
||||
setAcceptedMouseButtons(Qt::LeftButton);
|
||||
}
|
||||
|
||||
QSizeF TiledCanvas::canvasSize() const
|
||||
{
|
||||
return m_canvasSize;
|
||||
}
|
||||
|
||||
void TiledCanvas::setCanvasSize(const QSizeF &v)
|
||||
{
|
||||
if (m_canvasSize != v) {
|
||||
m_canvasSize = v;
|
||||
emit canvasSizeChanged();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
QSize TiledCanvas::tileSize() const
|
||||
{
|
||||
return m_tileSize;
|
||||
}
|
||||
|
||||
void TiledCanvas::setTileSize(const QSize &v)
|
||||
{
|
||||
if (v != m_tileSize) {
|
||||
m_tileSize = v;
|
||||
emit tileSizeChanged();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
QRectF TiledCanvas::canvasWindow() const
|
||||
{
|
||||
return m_canvasWindow;
|
||||
}
|
||||
|
||||
void TiledCanvas::setCanvasWindow(const QRectF &v)
|
||||
{
|
||||
if (m_canvasWindow != v) {
|
||||
m_canvasWindow = v;
|
||||
emit canvasWindowChanged();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void TiledCanvas::requestPaint()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
void TiledCanvas::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
|
||||
{
|
||||
if (m_context2d->size() != m_tileSize)
|
||||
m_context2d->setSize(m_tileSize);
|
||||
|
||||
const int tw = m_tileSize.width();
|
||||
const int th = m_tileSize.height();
|
||||
|
||||
int h1 = m_canvasWindow.left() / tw;
|
||||
int htiles = ((m_canvasWindow.right() - h1 * tw) + tw - 1) / tw;
|
||||
|
||||
int v1 = m_canvasWindow.top() / th;
|
||||
int vtiles = ((m_canvasWindow.bottom() - v1 * th) + th - 1) / th;
|
||||
|
||||
for (int yy = 0; yy < vtiles; ++yy) {
|
||||
for (int xx = 0; xx < htiles; ++xx) {
|
||||
int ht = xx + h1;
|
||||
int vt = yy + v1;
|
||||
|
||||
m_context2d->reset();
|
||||
m_context2d->setPainterTranslate(QPoint(-ht * tw, -vt * th));
|
||||
|
||||
emit drawRegion(m_context2d, QRect(ht * tw, vt * th, tw, th));
|
||||
|
||||
p->drawPixmap(-m_canvasWindow.x() + ht * tw, -m_canvasWindow.y() + vt * th, m_context2d->pixmap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TiledCanvas::componentComplete()
|
||||
{
|
||||
const QMetaObject *metaObject = this->metaObject();
|
||||
int propertyCount = metaObject->propertyCount();
|
||||
int requestPaintMethod = metaObject->indexOfMethod("requestPaint()");
|
||||
for (int ii = TiledCanvas::staticMetaObject.propertyCount(); ii < propertyCount; ++ii) {
|
||||
QMetaProperty p = metaObject->property(ii);
|
||||
if (p.hasNotifySignal())
|
||||
QMetaObject::connect(this, p.notifySignalIndex(), this, requestPaintMethod, 0, 0);
|
||||
}
|
||||
QDeclarativeItem::componentComplete();
|
||||
}
|
||||
|
||||
|
||||
void TiledCanvas::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
qWarning("MPE");
|
||||
}
|
||||
|
||||
QPixmap TiledCanvas::getTile(int xx, int yy)
|
||||
{
|
||||
QPixmap pix(m_tileSize);
|
||||
|
||||
pix.fill(Qt::green);
|
||||
|
||||
QString text = QString::number(xx) + " " + QString::number(yy);
|
||||
|
||||
QPainter p(&pix);
|
||||
p.drawText(pix.rect(), Qt::AlignHCenter | Qt::AlignVCenter, text);
|
||||
|
||||
return pix;
|
||||
}
|
||||
|
||||
102
src/plugins/qmlprofiler/canvas/qdeclarativetiledcanvas_p.h
Normal file
102
src/plugins/qmlprofiler/canvas/qdeclarativetiledcanvas_p.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the QtDeclarative module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** No Commercial Usage
|
||||
** This file contains pre-release code and may not be distributed.
|
||||
** You may use this file in accordance with the terms and conditions
|
||||
** contained in the Technology Preview License Agreement accompanying
|
||||
** this package.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QDECLARATIVETILEDCANVAS_P_H
|
||||
#define QDECLARATIVETILEDCANVAS_P_H
|
||||
|
||||
#include <QtDeclarative/qdeclarativeitem.h>
|
||||
|
||||
QT_BEGIN_HEADER
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QT_MODULE(Declarative)
|
||||
class Context2D;
|
||||
class TiledCanvas : public QDeclarativeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QSizeF canvasSize READ canvasSize WRITE setCanvasSize NOTIFY canvasSizeChanged)
|
||||
Q_PROPERTY(QSize tileSize READ tileSize WRITE setTileSize NOTIFY tileSizeChanged)
|
||||
Q_PROPERTY(QRectF canvasWindow READ canvasWindow WRITE setCanvasWindow NOTIFY canvasWindowChanged)
|
||||
|
||||
public:
|
||||
TiledCanvas();
|
||||
|
||||
QSizeF canvasSize() const;
|
||||
void setCanvasSize(const QSizeF &);
|
||||
|
||||
QSize tileSize() const;
|
||||
void setTileSize(const QSize &);
|
||||
|
||||
QRectF canvasWindow() const;
|
||||
void setCanvasWindow(const QRectF &);
|
||||
|
||||
Q_SIGNALS:
|
||||
void canvasSizeChanged();
|
||||
void tileSizeChanged();
|
||||
void canvasWindowChanged();
|
||||
|
||||
void drawRegion(Context2D *ctxt, const QRect ®ion);
|
||||
|
||||
public Q_SLOTS:
|
||||
void requestPaint();
|
||||
|
||||
protected:
|
||||
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
||||
virtual void componentComplete();
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
private:
|
||||
QPixmap getTile(int, int);
|
||||
|
||||
Context2D *m_context2d;
|
||||
|
||||
QSizeF m_canvasSize;
|
||||
QSize m_tileSize;
|
||||
QRectF m_canvasWindow;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_END_HEADER
|
||||
|
||||
#endif // QDECLARATIVETILEDCANVAS_P_H
|
||||
Reference in New Issue
Block a user