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"
|
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)
|
|
|
|
, fGLWidget(debugger)
|
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);
|
|
|
|
fGLWidget.setSizePolicy(QSizePolicy::Expanding,
|
|
|
|
QSizePolicy::Expanding);
|
|
|
|
|
|
|
|
fHorizontalLayout.addWidget(&fRasterWidget);
|
|
|
|
fHorizontalLayout.addWidget(&fGLWidget);
|
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
|
|
|
|
2012-07-26 19:38:22 +00:00
|
|
|
setWidgetVisibility(kGPU_WidgetType, true);
|
2012-08-03 17:32:05 +00:00
|
|
|
connect(&fRasterWidget, SIGNAL(drawComplete()),
|
|
|
|
this->parentWidget(), SLOT(drawComplete()));
|
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);
|
|
|
|
fRasterWidget.draw();
|
|
|
|
fGLWidget.draw();
|
|
|
|
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());
|
2012-08-07 16:12:23 +00:00
|
|
|
emit hitChanged(fDebugger->getCommandAtPoint(event->x(), event->y(),
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
} else if (type == kGPU_WidgetType) {
|
|
|
|
fGLWidget.setHidden(isHidden);
|
|
|
|
}
|
|
|
|
}
|
2012-07-03 16:05:59 +00:00
|
|
|
|
2013-01-17 16:30:56 +00:00
|
|
|
void SkCanvasWidget::zoom(float scale, int px, int py) {
|
|
|
|
fUserMatrix.postScale(scale, scale, px, py);
|
|
|
|
emit scaleFactorChanged(fUserMatrix.getScaleX());
|
|
|
|
fDebugger->setUserMatrix(fUserMatrix);
|
2012-08-07 16:12:23 +00:00
|
|
|
drawTo(fDebugger->index());
|
2012-07-03 16:05:59 +00:00
|
|
|
}
|