blob: f6bc6186c9e82f8b521bbe71f78f3b36bc76e2c5 [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,
30 kGPU_WidgetType = 1 << 1,
31 };
chudy@google.com902ebe52012-06-29 14:21:22 +000032
chudy@google.comea5488b2012-07-26 19:38:22 +000033 void drawTo(int index);
34
35 void setWidgetVisibility(WidgetType type, bool isHidden);
36
bungeman@google.come8cc6e82013-01-17 16:30:56 +000037 /** Zooms the canvas by scale with the transformation centered at the widget point (px, py). */
38 void zoom(float scale, int px, int py);
chudy@google.com902ebe52012-06-29 14:21:22 +000039
chudy@google.com686e6802012-08-14 16:00:32 +000040 void resetWidgetTransform();
41
bungeman@google.come8cc6e82013-01-17 16:30:56 +000042 enum ZoomCommandTypes {
43 kIn_ZoomCommand,
44 kOut_ZoomCommand,
45 };
46public slots:
47 /**
48 * Zooms in or out (see ZoomCommandTypes) by the standard zoom factor
49 * with the transformation centered in the middle of the widget.
50 */
51 void zoom(int zoomCommand);
52
chudy@google.com7dcae672012-07-09 20:26:53 +000053signals:
54 void scaleFactorChanged(float newScaleFactor);
55 void commandChanged(int newCommand);
chudy@google.come606d6e2012-07-12 14:31:25 +000056 void hitChanged(int hit);
chudy@google.com7dcae672012-07-09 20:26:53 +000057
chudy@google.com902ebe52012-06-29 14:21:22 +000058private:
chudy@google.comea5488b2012-07-26 19:38:22 +000059 QHBoxLayout fHorizontalLayout;
60 SkRasterWidget fRasterWidget;
61 SkGLWidget fGLWidget;
chudy@google.com607357f2012-08-07 16:12:23 +000062 SkDebugger* fDebugger;
chudy@google.com2f891792012-07-03 16:05:59 +000063 SkIPoint fPreviousPoint;
bungeman@google.come8cc6e82013-01-17 16:30:56 +000064 SkMatrix fUserMatrix;
chudy@google.comea5488b2012-07-26 19:38:22 +000065
chudy@google.comea5488b2012-07-26 19:38:22 +000066 void mouseMoveEvent(QMouseEvent* event);
67
68 void mousePressEvent(QMouseEvent* event);
69
70 void mouseDoubleClickEvent(QMouseEvent* event);
71
bungeman@google.come8cc6e82013-01-17 16:30:56 +000072 void wheelEvent(QWheelEvent* event);
73
74 void snapWidgetTransform();
chudy@google.com902ebe52012-06-29 14:21:22 +000075};
76
chudy@google.comea5488b2012-07-26 19:38:22 +000077
78#endif /* SKCANVASWIDGET_H_ */