blob: 0dcb470405e3b60082ed1c7bc75b56228c0d6f0f [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001
2/*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
chudy@google.comea5488b2012-07-26 19:38:22 +000010#ifndef SKCANVASWIDGET_H_
11#define SKCANVASWIDGET_H_
chudy@google.com902ebe52012-06-29 14:21:22 +000012
chudy@google.com902ebe52012-06-29 14:21:22 +000013#include <QWidget>
chudy@google.comea5488b2012-07-26 19:38:22 +000014#include <QHBoxLayout>
15#include "SkStream.h"
16#include "SkRasterWidget.h"
17#include "SkGLWidget.h"
chudy@google.com607357f2012-08-07 16:12:23 +000018#include "SkDebugger.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000019
chudy@google.com902ebe52012-06-29 14:21:22 +000020class SkCanvasWidget : public QWidget {
21 Q_OBJECT
22
23public:
chudy@google.com607357f2012-08-07 16:12:23 +000024 SkCanvasWidget(QWidget* parent, SkDebugger* debugger);
chudy@google.com902ebe52012-06-29 14:21:22 +000025
chudy@google.com2d537a12012-07-31 12:49:52 +000026 ~SkCanvasWidget();
chudy@google.com902ebe52012-06-29 14:21:22 +000027
chudy@google.comea5488b2012-07-26 19:38:22 +000028 enum WidgetType {
29 kRaster_8888_WidgetType = 1 << 0,
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000030#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +000031 kGPU_WidgetType = 1 << 1,
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000032#endif
chudy@google.comea5488b2012-07-26 19:38:22 +000033 };
chudy@google.com902ebe52012-06-29 14:21:22 +000034
chudy@google.comea5488b2012-07-26 19:38:22 +000035 void drawTo(int index);
36
37 void setWidgetVisibility(WidgetType type, bool isHidden);
38
bungeman@google.come8cc6e82013-01-17 16:30:56 +000039 /** Zooms the canvas by scale with the transformation centered at the widget point (px, py). */
40 void zoom(float scale, int px, int py);
chudy@google.com902ebe52012-06-29 14:21:22 +000041
chudy@google.com686e6802012-08-14 16:00:32 +000042 void resetWidgetTransform();
43
bungeman@google.come8cc6e82013-01-17 16:30:56 +000044 enum ZoomCommandTypes {
45 kIn_ZoomCommand,
46 kOut_ZoomCommand,
47 };
48public slots:
49 /**
50 * Zooms in or out (see ZoomCommandTypes) by the standard zoom factor
51 * with the transformation centered in the middle of the widget.
52 */
53 void zoom(int zoomCommand);
54
chudy@google.com7dcae672012-07-09 20:26:53 +000055signals:
56 void scaleFactorChanged(float newScaleFactor);
57 void commandChanged(int newCommand);
chudy@google.come606d6e2012-07-12 14:31:25 +000058 void hitChanged(int hit);
chudy@google.com7dcae672012-07-09 20:26:53 +000059
chudy@google.com902ebe52012-06-29 14:21:22 +000060private:
chudy@google.comea5488b2012-07-26 19:38:22 +000061 QHBoxLayout fHorizontalLayout;
62 SkRasterWidget fRasterWidget;
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000063#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +000064 SkGLWidget fGLWidget;
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000065#endif
chudy@google.com607357f2012-08-07 16:12:23 +000066 SkDebugger* fDebugger;
chudy@google.com2f891792012-07-03 16:05:59 +000067 SkIPoint fPreviousPoint;
bungeman@google.come8cc6e82013-01-17 16:30:56 +000068 SkMatrix fUserMatrix;
chudy@google.comea5488b2012-07-26 19:38:22 +000069
chudy@google.comea5488b2012-07-26 19:38:22 +000070 void mouseMoveEvent(QMouseEvent* event);
71
72 void mousePressEvent(QMouseEvent* event);
73
74 void mouseDoubleClickEvent(QMouseEvent* event);
75
bungeman@google.come8cc6e82013-01-17 16:30:56 +000076 void wheelEvent(QWheelEvent* event);
77
78 void snapWidgetTransform();
chudy@google.com902ebe52012-06-29 14:21:22 +000079};
80
chudy@google.comea5488b2012-07-26 19:38:22 +000081
82#endif /* SKCANVASWIDGET_H_ */