forked from qt-creator/qt-creator
QmlProfiler: Remove custom canvas implementation
The canvas integrated in QtQuick does the same thing. We can remove a lot of code like this. Change-Id: I6425ae4e1b542107defd9d76fa5755712a0f8613 Reviewed-by: Ulf Hermann <ulf.hermann@digia.com> Reviewed-by: Christian Stenger <christian.stenger@digia.com> Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
@@ -1,9 +0,0 @@
|
|||||||
HEADERS += $$PWD/qdeclarativecontext2d_p.h \
|
|
||||||
$$PWD/qdeclarativecanvas_p.h \
|
|
||||||
$$PWD/qmlprofilercanvas.h \
|
|
||||||
$$PWD/qdeclarativecanvastimer_p.h
|
|
||||||
|
|
||||||
SOURCES += $$PWD/qdeclarativecontext2d.cpp \
|
|
||||||
$$PWD/qdeclarativecanvas.cpp \
|
|
||||||
$$PWD/qmlprofilercanvas.cpp \
|
|
||||||
$$PWD/qdeclarativecanvastimer.cpp
|
|
@@ -1,242 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
|
||||||
** Contact: http://www.qt-project.org/legal
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and Digia. For licensing terms and
|
|
||||||
** conditions see http://qt.digia.com/licensing. For further information
|
|
||||||
** use the contact form at http://qt.digia.com/contact-us.
|
|
||||||
**
|
|
||||||
** 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, Digia gives you certain additional
|
|
||||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
||||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "qdeclarativecanvas_p.h"
|
|
||||||
#include "qdeclarativecanvastimer_p.h"
|
|
||||||
#include "qdeclarativecontext2d_p.h"
|
|
||||||
|
|
||||||
#include <qpainter.h>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
|
|
||||||
Canvas::Canvas(QQuickPaintedItem *parent)
|
|
||||||
: QQuickPaintedItem(parent),
|
|
||||||
m_context(new Context2D(this)),
|
|
||||||
m_canvasWidth(0),
|
|
||||||
m_canvasHeight(0),
|
|
||||||
m_fillMode(Canvas::Stretch),
|
|
||||||
m_color(Qt::white)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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();
|
|
||||||
QQuickItem::componentComplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Canvas::paint(QPainter *painter)
|
|
||||||
{
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
QQuickItem::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 QJSValue &handler, long timeout)
|
|
||||||
{
|
|
||||||
if (handler.isCallable())
|
|
||||||
CanvasTimer::createTimer(this, handler, timeout, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Canvas::setInterval(const QJSValue &handler, long interval)
|
|
||||||
{
|
|
||||||
if (handler.isCallable())
|
|
||||||
CanvasTimer::createTimer(this, handler, interval, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Canvas::clearTimeout(const QJSValue &handler)
|
|
||||||
{
|
|
||||||
CanvasTimer::removeTimer(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Canvas::clearInterval(const QJSValue &handler)
|
|
||||||
{
|
|
||||||
CanvasTimer::removeTimer(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
|
@@ -1,107 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
|
||||||
** Contact: http://www.qt-project.org/legal
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and Digia. For licensing terms and
|
|
||||||
** conditions see http://qt.digia.com/licensing. For further information
|
|
||||||
** use the contact form at http://qt.digia.com/contact-us.
|
|
||||||
**
|
|
||||||
** 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, Digia gives you certain additional
|
|
||||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
||||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef QDECLARATIVECANVAS_P_H
|
|
||||||
#define QDECLARATIVECANVAS_P_H
|
|
||||||
|
|
||||||
#include <QQuickPaintedItem>
|
|
||||||
|
|
||||||
#include "qdeclarativecontext2d_p.h"
|
|
||||||
#include "qdeclarativecanvastimer_p.h"
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
|
|
||||||
class Canvas : public QQuickPaintedItem
|
|
||||||
{
|
|
||||||
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(QQuickPaintedItem *parent = 0);
|
|
||||||
enum FillMode { Stretch, PreserveAspectFit, PreserveAspectCrop, Tile, TileVertically, TileHorizontally };
|
|
||||||
|
|
||||||
|
|
||||||
void paint(QPainter *);
|
|
||||||
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 & = QLatin1String("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 QJSValue &handler, long timeout);
|
|
||||||
void setTimeout(const QJSValue &handler, long timeout);
|
|
||||||
void clearInterval(const QJSValue &handler);
|
|
||||||
void clearTimeout(const QJSValue &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
|
|
||||||
|
|
||||||
#endif //QDECLARATIVECANVAS_P_H
|
|
@@ -1,85 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
|
||||||
** Contact: http://www.qt-project.org/legal
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and Digia. For licensing terms and
|
|
||||||
** conditions see http://qt.digia.com/licensing. For further information
|
|
||||||
** use the contact form at http://qt.digia.com/contact-us.
|
|
||||||
**
|
|
||||||
** 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, Digia gives you certain additional
|
|
||||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
||||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "qdeclarativecanvastimer_p.h"
|
|
||||||
|
|
||||||
#include <QJSEngine>
|
|
||||||
#include <QJSValue>
|
|
||||||
#include <qtimer.h>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(QList<CanvasTimer*> , activeTimers);
|
|
||||||
|
|
||||||
CanvasTimer::CanvasTimer(QObject *parent, const QJSValue &data)
|
|
||||||
: QTimer(parent), m_value(data)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CanvasTimer::handleTimeout()
|
|
||||||
{
|
|
||||||
Q_ASSERT(m_value.isCallable());
|
|
||||||
m_value.call();
|
|
||||||
if (isSingleShot())
|
|
||||||
removeTimer(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CanvasTimer::createTimer(QObject *parent, const QJSValue &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 QJSValue &val)
|
|
||||||
{
|
|
||||||
if (!val.isCallable())
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (int i = 0 ; i < activeTimers()->count() ; ++i) {
|
|
||||||
CanvasTimer *timer = activeTimers()->at(i);
|
|
||||||
if (timer->equals(val)) {
|
|
||||||
removeTimer(timer);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
@@ -1,62 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
|
||||||
** Contact: http://www.qt-project.org/legal
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and Digia. For licensing terms and
|
|
||||||
** conditions see http://qt.digia.com/licensing. For further information
|
|
||||||
** use the contact form at http://qt.digia.com/contact-us.
|
|
||||||
**
|
|
||||||
** 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, Digia gives you certain additional
|
|
||||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
||||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef QDECLARATIVECANVASTIMER_P_H
|
|
||||||
#define QDECLARATIVECANVASTIMER_P_H
|
|
||||||
|
|
||||||
#include <QJSValue>
|
|
||||||
#include <qtimer.h>
|
|
||||||
#include <qlist.h>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
|
|
||||||
class CanvasTimer : public QTimer
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
CanvasTimer(QObject *parent, const QJSValue &data);
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void handleTimeout();
|
|
||||||
bool equals(const QJSValue &value){return m_value.equals(value);}
|
|
||||||
|
|
||||||
public:
|
|
||||||
static void createTimer(QObject *parent, const QJSValue &val, long timeout, bool singleshot);
|
|
||||||
static void removeTimer(CanvasTimer *timer);
|
|
||||||
static void removeTimer(const QJSValue &);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QJSValue m_value;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
#endif // QDECLARATIVECANVASTIMER_P_H
|
|
File diff suppressed because it is too large
Load Diff
@@ -1,326 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
|
||||||
** Contact: http://www.qt-project.org/legal
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and Digia. For licensing terms and
|
|
||||||
** conditions see http://qt.digia.com/licensing. For further information
|
|
||||||
** use the contact form at http://qt.digia.com/contact-us.
|
|
||||||
**
|
|
||||||
** 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, Digia gives you certain additional
|
|
||||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
||||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef QDECLARATIVECONTEXT2D_P_H
|
|
||||||
#define QDECLARATIVECONTEXT2D_P_H
|
|
||||||
|
|
||||||
#include <qpainter.h>
|
|
||||||
#include <qpainterpath.h>
|
|
||||||
#include <qpixmap.h>
|
|
||||||
#include <qstring.h>
|
|
||||||
#include <qstack.h>
|
|
||||||
#include <qmetatype.h>
|
|
||||||
#include <qcoreevent.h>
|
|
||||||
#include <qvariant.h>
|
|
||||||
|
|
||||||
#include <QJSValue>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
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 {
|
|
||||||
QJSValue callback;
|
|
||||||
QJSValue 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 QJSValue &, const QJSValue & = QJSValue());
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void onScheduleChange(int interval);
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(CanvasImage*)
|
|
||||||
Q_DECLARE_METATYPE(CanvasGradient*)
|
|
||||||
|
|
||||||
#endif // QDECLARATIVECONTEXT2D_P_H
|
|
@@ -1,105 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
|
||||||
** Contact: http://www.qt-project.org/legal
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and Digia. For licensing terms and
|
|
||||||
** conditions see http://qt.digia.com/licensing. For further information
|
|
||||||
** use the contact form at http://qt.digia.com/contact-us.
|
|
||||||
**
|
|
||||||
** 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, Digia gives you certain additional
|
|
||||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
||||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "qmlprofilercanvas.h"
|
|
||||||
|
|
||||||
#include "qdeclarativecontext2d_p.h"
|
|
||||||
|
|
||||||
#include <qpixmap.h>
|
|
||||||
#include <qpainter.h>
|
|
||||||
|
|
||||||
namespace QmlProfiler {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
QmlProfilerCanvas::QmlProfilerCanvas()
|
|
||||||
: m_context2d(new Context2D(this))
|
|
||||||
{
|
|
||||||
setAcceptedMouseButtons(Qt::LeftButton);
|
|
||||||
m_drawTimer.setSingleShot(true);
|
|
||||||
connect(&m_drawTimer, SIGNAL(timeout()), this, SLOT(draw()));
|
|
||||||
|
|
||||||
m_drawTimer.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlProfilerCanvas::requestPaint()
|
|
||||||
{
|
|
||||||
if (m_context2d->size().width() != width()
|
|
||||||
|| m_context2d->size().height() != height()) {
|
|
||||||
m_drawTimer.start();
|
|
||||||
} else {
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlProfilerCanvas::requestRedraw()
|
|
||||||
{
|
|
||||||
m_drawTimer.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
// called from GUI thread. Draws into m_context2d.
|
|
||||||
void QmlProfilerCanvas::draw()
|
|
||||||
{
|
|
||||||
QMutexLocker lock(&m_pixmapMutex);
|
|
||||||
m_context2d->reset();
|
|
||||||
m_context2d->setSize(width(), height());
|
|
||||||
|
|
||||||
if (width() > 0 && height() > 0)
|
|
||||||
emit drawRegion(m_context2d, QRect(0, 0, width(), height()));
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
// called from OpenGL thread. Renders m_context2d into OpenGL buffer.
|
|
||||||
void QmlProfilerCanvas::paint(QPainter *p)
|
|
||||||
{
|
|
||||||
QMutexLocker lock(&m_pixmapMutex);
|
|
||||||
p->drawPixmap(0, 0, m_context2d->pixmap());
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlProfilerCanvas::componentComplete()
|
|
||||||
{
|
|
||||||
const QMetaObject *metaObject = this->metaObject();
|
|
||||||
int propertyCount = metaObject->propertyCount();
|
|
||||||
int requestPaintMethod = metaObject->indexOfMethod("requestPaint()");
|
|
||||||
for (int ii = QmlProfilerCanvas::staticMetaObject.propertyCount(); ii < propertyCount; ++ii) {
|
|
||||||
QMetaProperty p = metaObject->property(ii);
|
|
||||||
if (p.hasNotifySignal())
|
|
||||||
QMetaObject::connect(this, p.notifySignalIndex(), this, requestPaintMethod, 0, 0);
|
|
||||||
}
|
|
||||||
QQuickItem::componentComplete();
|
|
||||||
requestRedraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlProfilerCanvas::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
|
|
||||||
{
|
|
||||||
QQuickItem::geometryChanged(newGeometry, oldGeometry);
|
|
||||||
requestRedraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,76 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
|
||||||
** Contact: http://www.qt-project.org/legal
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and Digia. For licensing terms and
|
|
||||||
** conditions see http://qt.digia.com/licensing. For further information
|
|
||||||
** use the contact form at http://qt.digia.com/contact-us.
|
|
||||||
**
|
|
||||||
** 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, Digia gives you certain additional
|
|
||||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
||||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef QMLPROFILERCANVAS_H
|
|
||||||
#define QMLPROFILERCANVAS_H
|
|
||||||
|
|
||||||
#include <QQuickPaintedItem>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QMutex>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class Context2D;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace QmlProfiler {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class QmlProfilerCanvas : public QQuickPaintedItem
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
QmlProfilerCanvas();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void drawRegion(Context2D *ctxt, const QRect ®ion);
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void requestPaint();
|
|
||||||
void requestRedraw();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void draw();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void paint(QPainter *);
|
|
||||||
virtual void componentComplete();
|
|
||||||
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Context2D *m_context2d;
|
|
||||||
|
|
||||||
QTimer m_drawTimer;
|
|
||||||
QMutex m_pixmapMutex;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // QMLPROFILERCANVAS_H
|
|
@@ -47,7 +47,7 @@ Item {
|
|||||||
|
|
||||||
onExpandedChanged: {
|
onExpandedChanged: {
|
||||||
qmlProfilerModelProxy.setExpanded(modelIndex, categoryIndex, expanded);
|
qmlProfilerModelProxy.setExpanded(modelIndex, categoryIndex, expanded);
|
||||||
backgroundMarks.requestRedraw();
|
backgroundMarks.requestPaint();
|
||||||
getDescriptions();
|
getDescriptions();
|
||||||
updateHeight();
|
updateHeight();
|
||||||
}
|
}
|
||||||
|
@@ -31,9 +31,10 @@ import QtQuick 2.1
|
|||||||
import Monitor 1.0
|
import Monitor 1.0
|
||||||
import "Overview.js" as Plotter
|
import "Overview.js" as Plotter
|
||||||
|
|
||||||
Canvas2D {
|
Canvas {
|
||||||
id: canvas
|
id: canvas
|
||||||
objectName: "Overview"
|
objectName: "Overview"
|
||||||
|
contextType: "2d"
|
||||||
|
|
||||||
// ***** properties
|
// ***** properties
|
||||||
height: 50
|
height: 50
|
||||||
@@ -45,7 +46,7 @@ Canvas2D {
|
|||||||
function clearDisplay()
|
function clearDisplay()
|
||||||
{
|
{
|
||||||
dataReady = false;
|
dataReady = false;
|
||||||
requestRedraw();
|
requestPaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateRange() {
|
function updateRange() {
|
||||||
@@ -84,18 +85,18 @@ Canvas2D {
|
|||||||
target: qmlProfilerModelProxy
|
target: qmlProfilerModelProxy
|
||||||
onDataAvailable: {
|
onDataAvailable: {
|
||||||
dataReady = true;
|
dataReady = true;
|
||||||
requestRedraw();
|
requestPaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ***** slots
|
// ***** slots
|
||||||
onDrawRegion: {
|
onPaint: {
|
||||||
Plotter.qmlProfilerModelProxy = qmlProfilerModelProxy;
|
Plotter.qmlProfilerModelProxy = qmlProfilerModelProxy;
|
||||||
if (dataReady) {
|
if (dataReady) {
|
||||||
Plotter.plot(canvas, ctxt, region);
|
Plotter.plot(canvas, context, region);
|
||||||
} else {
|
} else {
|
||||||
Plotter.drawGraph(canvas, ctxt, region) //just draw the background
|
Plotter.drawGraph(canvas, context, region) //just draw the background
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,9 +30,10 @@
|
|||||||
import QtQuick 2.1
|
import QtQuick 2.1
|
||||||
import Monitor 1.0
|
import Monitor 1.0
|
||||||
|
|
||||||
Canvas2D {
|
Canvas {
|
||||||
id: timeDisplay
|
id: timeDisplay
|
||||||
objectName: "TimeDisplay"
|
objectName: "TimeDisplay"
|
||||||
|
contextType: "2d"
|
||||||
|
|
||||||
property real startTime : 0
|
property real startTime : 0
|
||||||
property real endTime : 0
|
property real endTime : 0
|
||||||
@@ -43,13 +44,13 @@ Canvas2D {
|
|||||||
onRangeChanged: {
|
onRangeChanged: {
|
||||||
startTime = zoomControl.startTime();
|
startTime = zoomControl.startTime();
|
||||||
endTime = zoomControl.endTime();
|
endTime = zoomControl.endTime();
|
||||||
requestRedraw();
|
requestPaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onDrawRegion: {
|
onPaint: {
|
||||||
ctxt.fillStyle = "white";
|
context.fillStyle = "white";
|
||||||
ctxt.fillRect(0, 0, width, height);
|
context.fillRect(0, 0, width, height);
|
||||||
|
|
||||||
var totalTime = endTime - startTime;
|
var totalTime = endTime - startTime;
|
||||||
var spacing = width / totalTime;
|
var spacing = width / totalTime;
|
||||||
@@ -67,50 +68,50 @@ Canvas2D {
|
|||||||
|
|
||||||
var initialColor = Math.floor(realStartTime/timePerBlock) % 2;
|
var initialColor = Math.floor(realStartTime/timePerBlock) % 2;
|
||||||
|
|
||||||
ctxt.fillStyle = "#000000";
|
context.fillStyle = "#000000";
|
||||||
ctxt.font = "8px sans-serif";
|
context.font = "8px sans-serif";
|
||||||
for (var ii = 0; ii < blockCount+1; ii++) {
|
for (var ii = 0; ii < blockCount+1; ii++) {
|
||||||
var x = Math.floor(ii*pixelsPerBlock - realStartPos);
|
var x = Math.floor(ii*pixelsPerBlock - realStartPos);
|
||||||
|
|
||||||
ctxt.fillStyle = (ii+initialColor)%2 ? "#E6E6E6":"white";
|
context.fillStyle = (ii+initialColor)%2 ? "#E6E6E6":"white";
|
||||||
ctxt.fillRect(x, 0, pixelsPerBlock, height);
|
context.fillRect(x, 0, pixelsPerBlock, height);
|
||||||
|
|
||||||
ctxt.strokeStyle = "#B0B0B0";
|
context.strokeStyle = "#B0B0B0";
|
||||||
ctxt.beginPath();
|
context.beginPath();
|
||||||
ctxt.moveTo(x, 0);
|
context.moveTo(x, 0);
|
||||||
ctxt.lineTo(x, height);
|
context.lineTo(x, height);
|
||||||
ctxt.stroke();
|
context.stroke();
|
||||||
|
|
||||||
ctxt.fillStyle = "#000000";
|
context.fillStyle = "#000000";
|
||||||
ctxt.fillText(prettyPrintTime(ii*timePerBlock + realStartTime), x + 5, height/2 + 5);
|
context.fillText(prettyPrintTime(ii*timePerBlock + realStartTime), x + 5, height/2 + 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxt.strokeStyle = "#525252";
|
context.strokeStyle = "#525252";
|
||||||
ctxt.beginPath();
|
context.beginPath();
|
||||||
ctxt.moveTo(0, height-1);
|
context.moveTo(0, height-1);
|
||||||
ctxt.lineTo(width, height-1);
|
context.lineTo(width, height-1);
|
||||||
ctxt.stroke();
|
context.stroke();
|
||||||
|
|
||||||
// gradient borders
|
// gradient borders
|
||||||
var gradientDark = "rgba(0, 0, 0, 0.53125)";
|
var gradientDark = "rgba(0, 0, 0, 0.53125)";
|
||||||
var gradientClear = "rgba(0, 0, 0, 0)";
|
var gradientClear = "rgba(0, 0, 0, 0)";
|
||||||
var grad = ctxt.createLinearGradient(0, 0, 0, 6);
|
var grad = context.createLinearGradient(0, 0, 0, 6);
|
||||||
grad.addColorStop(0,gradientDark);
|
grad.addColorStop(0,gradientDark);
|
||||||
grad.addColorStop(1,gradientClear);
|
grad.addColorStop(1,gradientClear);
|
||||||
ctxt.fillStyle = grad;
|
context.fillStyle = grad;
|
||||||
ctxt.fillRect(0, 0, width, 6);
|
context.fillRect(0, 0, width, 6);
|
||||||
|
|
||||||
grad = ctxt.createLinearGradient(0, 0, 6, 0);
|
grad = context.createLinearGradient(0, 0, 6, 0);
|
||||||
grad.addColorStop(0,gradientDark);
|
grad.addColorStop(0,gradientDark);
|
||||||
grad.addColorStop(1,gradientClear);
|
grad.addColorStop(1,gradientClear);
|
||||||
ctxt.fillStyle = grad;
|
context.fillStyle = grad;
|
||||||
ctxt.fillRect(0, 0, 6, height);
|
context.fillRect(0, 0, 6, height);
|
||||||
|
|
||||||
grad = ctxt.createLinearGradient(width, 0, width-6, 0);
|
grad = context.createLinearGradient(width, 0, width-6, 0);
|
||||||
grad.addColorStop(0,gradientDark);
|
grad.addColorStop(0,gradientDark);
|
||||||
grad.addColorStop(1,gradientClear);
|
grad.addColorStop(1,gradientClear);
|
||||||
ctxt.fillStyle = grad;
|
context.fillStyle = grad;
|
||||||
ctxt.fillRect(width-6, 0, 6, height);
|
context.fillRect(width-6, 0, 6, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
function prettyPrintTime( t )
|
function prettyPrintTime( t )
|
||||||
|
@@ -30,9 +30,10 @@
|
|||||||
import QtQuick 2.1
|
import QtQuick 2.1
|
||||||
import Monitor 1.0
|
import Monitor 1.0
|
||||||
|
|
||||||
Canvas2D {
|
Canvas {
|
||||||
id: timeDisplay
|
id: timeMarks
|
||||||
objectName: "TimeMarks"
|
objectName: "TimeMarks"
|
||||||
|
contextType: "2d"
|
||||||
|
|
||||||
property real startTime
|
property real startTime
|
||||||
property real endTime
|
property real endTime
|
||||||
@@ -40,11 +41,13 @@ Canvas2D {
|
|||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: labels
|
target: labels
|
||||||
onHeightChanged: { requestRedraw(); }
|
onHeightChanged: requestPaint()
|
||||||
}
|
}
|
||||||
|
|
||||||
onDrawRegion: {
|
onYChanged: requestPaint()
|
||||||
drawBackgroundBars( ctxt, region );
|
|
||||||
|
onPaint: {
|
||||||
|
drawBackgroundBars( context, region );
|
||||||
|
|
||||||
var totalTime = endTime - startTime;
|
var totalTime = endTime - startTime;
|
||||||
var spacing = width / totalTime;
|
var spacing = width / totalTime;
|
||||||
@@ -63,23 +66,23 @@ Canvas2D {
|
|||||||
var lineStart = y < 0 ? -y : 0;
|
var lineStart = y < 0 ? -y : 0;
|
||||||
var lineEnd = Math.min(height, labels.height - y);
|
var lineEnd = Math.min(height, labels.height - y);
|
||||||
|
|
||||||
ctxt.fillStyle = "#000000";
|
context.fillStyle = "#000000";
|
||||||
ctxt.font = "8px sans-serif";
|
context.font = "8px sans-serif";
|
||||||
for (var ii = 0; ii < blockCount+1; ii++) {
|
for (var ii = 0; ii < blockCount+1; ii++) {
|
||||||
var x = Math.floor(ii*pixelsPerBlock - realStartPos);
|
var x = Math.floor(ii*pixelsPerBlock - realStartPos);
|
||||||
ctxt.strokeStyle = "#B0B0B0";
|
context.strokeStyle = "#B0B0B0";
|
||||||
ctxt.beginPath();
|
context.beginPath();
|
||||||
ctxt.moveTo(x, lineStart);
|
context.moveTo(x, lineStart);
|
||||||
ctxt.lineTo(x, lineEnd);
|
context.lineTo(x, lineEnd);
|
||||||
ctxt.stroke();
|
context.stroke();
|
||||||
|
|
||||||
ctxt.strokeStyle = "#CCCCCC";
|
context.strokeStyle = "#CCCCCC";
|
||||||
for (var jj=1; jj < 5; jj++) {
|
for (var jj=1; jj < 5; jj++) {
|
||||||
var xx = Math.floor(ii*pixelsPerBlock + jj*pixelsPerSection - realStartPos);
|
var xx = Math.floor(ii*pixelsPerBlock + jj*pixelsPerSection - realStartPos);
|
||||||
ctxt.beginPath();
|
context.beginPath();
|
||||||
ctxt.moveTo(xx, lineStart);
|
context.moveTo(xx, lineStart);
|
||||||
ctxt.lineTo(xx, lineEnd);
|
context.lineTo(xx, lineEnd);
|
||||||
ctxt.stroke();
|
context.stroke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,19 +91,19 @@ Canvas2D {
|
|||||||
if (startTime !== start || endTime !== end) {
|
if (startTime !== start || endTime !== end) {
|
||||||
startTime = start;
|
startTime = start;
|
||||||
endTime = end;
|
endTime = end;
|
||||||
requestRedraw();
|
requestPaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawBackgroundBars( ctxt, region ) {
|
function drawBackgroundBars( context, region ) {
|
||||||
var colorIndex = true;
|
var colorIndex = true;
|
||||||
|
|
||||||
// row background
|
// row background
|
||||||
var backgroundOffset = y < 0 ? -y : -(y % (2 * root.singleRowHeight));
|
var backgroundOffset = y < 0 ? -y : -(y % (2 * root.singleRowHeight));
|
||||||
for (var currentY= backgroundOffset; currentY < Math.min(height, labels.height - y); currentY += root.singleRowHeight) {
|
for (var currentY= backgroundOffset; currentY < Math.min(height, labels.height - y); currentY += root.singleRowHeight) {
|
||||||
ctxt.fillStyle = colorIndex ? "#f0f0f0" : "white";
|
context.fillStyle = colorIndex ? "#f0f0f0" : "white";
|
||||||
ctxt.strokeStyle = colorIndex ? "#f0f0f0" : "white";
|
context.strokeStyle = colorIndex ? "#f0f0f0" : "white";
|
||||||
ctxt.fillRect(0, currentY, width, root.singleRowHeight);
|
context.fillRect(0, currentY, width, root.singleRowHeight);
|
||||||
colorIndex = !colorIndex;
|
colorIndex = !colorIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,18 +115,18 @@ Canvas2D {
|
|||||||
if (cumulatedHeight < y)
|
if (cumulatedHeight < y)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ctxt.strokeStyle = "#B0B0B0";
|
context.strokeStyle = "#B0B0B0";
|
||||||
ctxt.beginPath();
|
context.beginPath();
|
||||||
ctxt.moveTo(0, cumulatedHeight - y);
|
context.moveTo(0, cumulatedHeight - y);
|
||||||
ctxt.lineTo(width, cumulatedHeight - y);
|
context.lineTo(width, cumulatedHeight - y);
|
||||||
ctxt.stroke();
|
context.stroke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bottom
|
// bottom
|
||||||
if (height > labels.height - y) {
|
if (height > labels.height - y) {
|
||||||
ctxt.fillStyle = "#f5f5f5";
|
context.fillStyle = "#f5f5f5";
|
||||||
ctxt.fillRect(0, labels.height - y, width, Math.min(height - labels.height + y, labelsTail.height));
|
context.fillRect(0, labels.height - y, width, Math.min(height - labels.height + y, labelsTail.height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,6 @@ DEFINES += QMLPROFILER_LIBRARY
|
|||||||
QT += network qml quick
|
QT += network qml quick
|
||||||
|
|
||||||
include(../../qtcreatorplugin.pri)
|
include(../../qtcreatorplugin.pri)
|
||||||
include(canvas/canvas.pri)
|
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
qmlprofilerplugin.cpp \
|
qmlprofilerplugin.cpp \
|
||||||
|
@@ -55,17 +55,6 @@ QtcPlugin {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
Group {
|
|
||||||
name: "Canvas"
|
|
||||||
prefix: "canvas/"
|
|
||||||
files: [
|
|
||||||
"qdeclarativecanvas.cpp", "qdeclarativecanvas_p.h",
|
|
||||||
"qdeclarativecanvastimer.cpp", "qdeclarativecanvastimer_p.h",
|
|
||||||
"qdeclarativecontext2d.cpp", "qdeclarativecontext2d_p.h",
|
|
||||||
"qmlprofilercanvas.cpp", "qmlprofilercanvas.h"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
Group {
|
Group {
|
||||||
name: "QML"
|
name: "QML"
|
||||||
prefix: "qml/"
|
prefix: "qml/"
|
||||||
|
@@ -41,9 +41,6 @@
|
|||||||
#include <analyzerbase/analyzermanager.h>
|
#include <analyzerbase/analyzermanager.h>
|
||||||
#include <analyzerbase/analyzerruncontrol.h>
|
#include <analyzerbase/analyzerruncontrol.h>
|
||||||
|
|
||||||
#include "canvas/qdeclarativecontext2d_p.h"
|
|
||||||
#include "canvas/qmlprofilercanvas.h"
|
|
||||||
|
|
||||||
#include <utils/fancymainwindow.h>
|
#include <utils/fancymainwindow.h>
|
||||||
#include <utils/fileinprojectfinder.h>
|
#include <utils/fileinprojectfinder.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
@@ -119,9 +116,6 @@ QmlProfilerTool::QmlProfilerTool(QObject *parent)
|
|||||||
d->m_profilerState = 0;
|
d->m_profilerState = 0;
|
||||||
d->m_viewContainer = 0;
|
d->m_viewContainer = 0;
|
||||||
|
|
||||||
qmlRegisterType<QmlProfilerCanvas>("Monitor", 1, 0, "Canvas2D");
|
|
||||||
qmlRegisterType<Context2D>();
|
|
||||||
qmlRegisterType<CanvasGradient>();
|
|
||||||
qmlRegisterType<TimelineRenderer>("Monitor", 1, 0,"TimelineRenderer");
|
qmlRegisterType<TimelineRenderer>("Monitor", 1, 0,"TimelineRenderer");
|
||||||
|
|
||||||
d->m_profilerState = new QmlProfilerStateManager(this);
|
d->m_profilerState = new QmlProfilerStateManager(this);
|
||||||
|
Reference in New Issue
Block a user