2012-06-29 14:21:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "SkCanvasWidget.h"
|
2015-01-14 06:49:02 +00:00
|
|
|
#include <QtGui>
|
2012-07-26 19:38:22 +00:00
|
|
|
|
2012-08-07 16:12:23 +00:00
|
|
|
SkCanvasWidget::SkCanvasWidget(QWidget* parent,
|
|
|
|
SkDebugger* debugger) : QWidget(parent)
|
2012-07-26 19:38:22 +00:00
|
|
|
, fHorizontalLayout(this)
|
2012-08-07 16:12:23 +00:00
|
|
|
, fRasterWidget(debugger)
|
2013-02-13 13:26:13 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-08-07 16:12:23 +00:00
|
|
|
, fGLWidget(debugger)
|
2013-02-13 13:26:13 +00:00
|
|
|
#endif
|
2012-07-26 19:38:22 +00:00
|
|
|
{
|
2012-08-07 16:12:23 +00:00
|
|
|
|
|
|
|
fDebugger = debugger;
|
|
|
|
|
2012-07-26 19:38:22 +00:00
|
|
|
fHorizontalLayout.setSpacing(6);
|
|
|
|
fHorizontalLayout.setContentsMargins(0,0,0,0);
|
|
|
|
fRasterWidget.setSizePolicy(QSizePolicy::Expanding,
|
|
|
|
QSizePolicy::Expanding);
|
2013-02-13 13:26:13 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-07-26 19:38:22 +00:00
|
|
|
fGLWidget.setSizePolicy(QSizePolicy::Expanding,
|
|
|
|
QSizePolicy::Expanding);
|
2013-02-13 13:26:13 +00:00
|
|
|
#endif
|
2012-07-26 19:38:22 +00:00
|
|
|
|
|
|
|
fHorizontalLayout.addWidget(&fRasterWidget);
|
2013-02-13 13:26:13 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-07-26 19:38:22 +00:00
|
|
|
fHorizontalLayout.addWidget(&fGLWidget);
|
2013-02-13 13:26:13 +00:00
|
|
|
#endif
|
2012-07-03 16:05:59 +00:00
|
|
|
|
|
|
|
fPreviousPoint.set(0,0);
|
2013-01-17 16:30:56 +00:00
|
|
|
fUserMatrix.reset();
|
2012-07-03 16:05:59 +00:00
|
|
|
|
2013-02-13 13:26:13 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-07-26 19:38:22 +00:00
|
|
|
setWidgetVisibility(kGPU_WidgetType, true);
|
2013-02-13 13:26:13 +00:00
|
|
|
#endif
|
2015-01-14 06:49:02 +00:00
|
|
|
connect(&fRasterWidget, SIGNAL(drawComplete()), this->parentWidget(), SLOT(drawComplete()));
|
2015-07-31 22:46:03 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2015-01-14 06:49:02 +00:00
|
|
|
connect(&fGLWidget, SIGNAL(drawComplete()), this->parentWidget(), SLOT(drawComplete()));
|
2015-07-31 22:46:03 +00:00
|
|
|
#endif
|
2012-07-03 16:05:59 +00:00
|
|
|
}
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2012-08-07 16:12:23 +00:00
|
|
|
SkCanvasWidget::~SkCanvasWidget() {}
|
2012-07-31 12:49:52 +00:00
|
|
|
|
2012-07-26 19:38:22 +00:00
|
|
|
void SkCanvasWidget::drawTo(int index) {
|
2012-08-07 16:12:23 +00:00
|
|
|
fDebugger->setIndex(index);
|
2015-01-14 06:49:02 +00:00
|
|
|
fRasterWidget.updateImage();
|
2013-02-13 13:26:13 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2015-01-14 06:49:02 +00:00
|
|
|
fGLWidget.updateImage();
|
2013-02-13 13:26:13 +00:00
|
|
|
#endif
|
2016-03-01 17:34:38 +00:00
|
|
|
Q_EMIT commandChanged(fDebugger->index());
|
2012-07-03 16:05:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkCanvasWidget::mouseMoveEvent(QMouseEvent* event) {
|
|
|
|
SkIPoint eventPoint = SkIPoint::Make(event->globalX(), event->globalY());
|
2013-01-17 16:30:56 +00:00
|
|
|
SkIPoint eventOffset = eventPoint - fPreviousPoint;
|
2012-07-03 16:05:59 +00:00
|
|
|
fPreviousPoint = eventPoint;
|
2013-01-17 16:30:56 +00:00
|
|
|
fUserMatrix.postTranslate(eventOffset.fX, eventOffset.fY);
|
|
|
|
fDebugger->setUserMatrix(fUserMatrix);
|
2012-08-07 16:12:23 +00:00
|
|
|
drawTo(fDebugger->index());
|
2012-07-03 16:05:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkCanvasWidget::mousePressEvent(QMouseEvent* event) {
|
|
|
|
fPreviousPoint.set(event->globalX(), event->globalY());
|
2016-03-01 17:34:38 +00:00
|
|
|
Q_EMIT hitChanged(fDebugger->getCommandAtPoint(event->x(), event->y(),
|
2012-08-07 16:12:23 +00:00
|
|
|
fDebugger->index()));
|
2012-07-03 16:05:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkCanvasWidget::mouseDoubleClickEvent(QMouseEvent* event) {
|
2013-01-17 16:30:56 +00:00
|
|
|
Qt::KeyboardModifiers modifiers = event->modifiers();
|
|
|
|
if (modifiers.testFlag(Qt::ControlModifier)) {
|
|
|
|
snapWidgetTransform();
|
|
|
|
} else {
|
|
|
|
resetWidgetTransform();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ZOOM_FACTOR (1.25f)
|
|
|
|
|
|
|
|
void SkCanvasWidget::wheelEvent(QWheelEvent* event) {
|
|
|
|
Qt::KeyboardModifiers modifiers = event->modifiers();
|
|
|
|
if (modifiers.testFlag(Qt::ControlModifier)) {
|
|
|
|
zoom(event->delta() > 0 ? ZOOM_FACTOR : (1.0f / ZOOM_FACTOR), event->x(), event->y());
|
|
|
|
} else {
|
|
|
|
if (Qt::Horizontal == event->orientation()) {
|
|
|
|
fUserMatrix.postTranslate(event->delta(), 0.0f);
|
|
|
|
} else {
|
|
|
|
fUserMatrix.postTranslate(0.0f, event->delta());
|
|
|
|
}
|
|
|
|
fDebugger->setUserMatrix(fUserMatrix);
|
|
|
|
drawTo(fDebugger->index());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkCanvasWidget::zoom(int zoomCommand) {
|
|
|
|
zoom(kIn_ZoomCommand == zoomCommand ? ZOOM_FACTOR : (1.0f / ZOOM_FACTOR),
|
|
|
|
this->size().width() / 2, this->size().height() / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkCanvasWidget::snapWidgetTransform() {
|
|
|
|
double x, y;
|
|
|
|
modf(fUserMatrix.getTranslateX(), &x);
|
|
|
|
modf(fUserMatrix.getTranslateY(), &y);
|
|
|
|
fUserMatrix[SkMatrix::kMTransX] = x;
|
|
|
|
fUserMatrix[SkMatrix::kMTransY] = y;
|
|
|
|
fDebugger->setUserMatrix(fUserMatrix);
|
|
|
|
drawTo(fDebugger->index());
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2012-07-26 19:38:22 +00:00
|
|
|
void SkCanvasWidget::resetWidgetTransform() {
|
2013-01-17 16:30:56 +00:00
|
|
|
fUserMatrix.reset();
|
|
|
|
fDebugger->setUserMatrix(fUserMatrix);
|
2016-03-01 17:34:38 +00:00
|
|
|
Q_EMIT scaleFactorChanged(fUserMatrix.getScaleX());
|
2012-08-07 16:12:23 +00:00
|
|
|
drawTo(fDebugger->index());
|
2012-07-26 19:38:22 +00:00
|
|
|
}
|
2012-07-03 16:05:59 +00:00
|
|
|
|
2012-07-26 19:38:22 +00:00
|
|
|
void SkCanvasWidget::setWidgetVisibility(WidgetType type, bool isHidden) {
|
|
|
|
if (type == kRaster_8888_WidgetType) {
|
|
|
|
fRasterWidget.setHidden(isHidden);
|
2013-02-14 07:01:34 +00:00
|
|
|
}
|
2013-02-13 13:26:13 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
else if (type == kGPU_WidgetType) {
|
2012-07-26 19:38:22 +00:00
|
|
|
fGLWidget.setHidden(isHidden);
|
|
|
|
}
|
2013-02-13 13:26:13 +00:00
|
|
|
#endif
|
2012-07-26 19:38:22 +00:00
|
|
|
}
|
2012-07-03 16:05:59 +00:00
|
|
|
|
2013-08-02 13:59:50 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
void SkCanvasWidget::setGLSampleCount(int sampleCount)
|
|
|
|
{
|
|
|
|
fGLWidget.setSampleCount(sampleCount);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-17 16:30:56 +00:00
|
|
|
void SkCanvasWidget::zoom(float scale, int px, int py) {
|
|
|
|
fUserMatrix.postScale(scale, scale, px, py);
|
2016-03-01 17:34:38 +00:00
|
|
|
Q_EMIT scaleFactorChanged(fUserMatrix.getScaleX());
|
2013-01-17 16:30:56 +00:00
|
|
|
fDebugger->setUserMatrix(fUserMatrix);
|
2012-08-07 16:12:23 +00:00
|
|
|
drawTo(fDebugger->index());
|
2012-07-03 16:05:59 +00:00
|
|
|
}
|