blob: 45ab0a4f034e8d4748b4c9e686ae108c32af3357 [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
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +000039#if SK_SUPPORT_GPU
40 void setGLSampleCount(int sampleCount);
41#endif
42
bungeman@google.come8cc6e82013-01-17 16:30:56 +000043 /** Zooms the canvas by scale with the transformation centered at the widget point (px, py). */
44 void zoom(float scale, int px, int py);
chudy@google.com902ebe52012-06-29 14:21:22 +000045
chudy@google.com686e6802012-08-14 16:00:32 +000046 void resetWidgetTransform();
47
bungeman@google.come8cc6e82013-01-17 16:30:56 +000048 enum ZoomCommandTypes {
49 kIn_ZoomCommand,
50 kOut_ZoomCommand,
51 };
robertphillips9ea8acd2016-03-01 09:34:38 -080052public Q_SLOTS:
bungeman@google.come8cc6e82013-01-17 16:30:56 +000053 /**
54 * Zooms in or out (see ZoomCommandTypes) by the standard zoom factor
55 * with the transformation centered in the middle of the widget.
56 */
57 void zoom(int zoomCommand);
58
robertphillips9ea8acd2016-03-01 09:34:38 -080059Q_SIGNALS:
chudy@google.com7dcae672012-07-09 20:26:53 +000060 void scaleFactorChanged(float newScaleFactor);
61 void commandChanged(int newCommand);
chudy@google.come606d6e2012-07-12 14:31:25 +000062 void hitChanged(int hit);
chudy@google.com7dcae672012-07-09 20:26:53 +000063
chudy@google.com902ebe52012-06-29 14:21:22 +000064private:
chudy@google.comea5488b2012-07-26 19:38:22 +000065 QHBoxLayout fHorizontalLayout;
66 SkRasterWidget fRasterWidget;
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000067#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +000068 SkGLWidget fGLWidget;
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000069#endif
chudy@google.com607357f2012-08-07 16:12:23 +000070 SkDebugger* fDebugger;
chudy@google.com2f891792012-07-03 16:05:59 +000071 SkIPoint fPreviousPoint;
bungeman@google.come8cc6e82013-01-17 16:30:56 +000072 SkMatrix fUserMatrix;
chudy@google.comea5488b2012-07-26 19:38:22 +000073
chudy@google.comea5488b2012-07-26 19:38:22 +000074 void mouseMoveEvent(QMouseEvent* event);
75
76 void mousePressEvent(QMouseEvent* event);
77
78 void mouseDoubleClickEvent(QMouseEvent* event);
79
bungeman@google.come8cc6e82013-01-17 16:30:56 +000080 void wheelEvent(QWheelEvent* event);
81
82 void snapWidgetTransform();
chudy@google.com902ebe52012-06-29 14:21:22 +000083};
84
chudy@google.comea5488b2012-07-26 19:38:22 +000085
86#endif /* SKCANVASWIDGET_H_ */