chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1 | |
| 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.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 10 | #ifndef SKCANVASWIDGET_H_ |
| 11 | #define SKCANVASWIDGET_H_ |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 12 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 13 | #include <QWidget> |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 14 | #include <QHBoxLayout> |
| 15 | #include "SkStream.h" |
| 16 | #include "SkRasterWidget.h" |
| 17 | #include "SkGLWidget.h" |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 18 | #include "SkDebugger.h" |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 19 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 20 | class SkCanvasWidget : public QWidget { |
| 21 | Q_OBJECT |
| 22 | |
| 23 | public: |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 24 | SkCanvasWidget(QWidget* parent, SkDebugger* debugger); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 25 | |
chudy@google.com | 2d537a1 | 2012-07-31 12:49:52 +0000 | [diff] [blame] | 26 | ~SkCanvasWidget(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 27 | |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 28 | enum WidgetType { |
| 29 | kRaster_8888_WidgetType = 1 << 0, |
robertphillips@google.com | e8fe4bc | 2013-02-13 13:26:13 +0000 | [diff] [blame] | 30 | #if SK_SUPPORT_GPU |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 31 | kGPU_WidgetType = 1 << 1, |
robertphillips@google.com | e8fe4bc | 2013-02-13 13:26:13 +0000 | [diff] [blame] | 32 | #endif |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 33 | }; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 34 | |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 35 | void drawTo(int index); |
| 36 | |
| 37 | void setWidgetVisibility(WidgetType type, bool isHidden); |
| 38 | |
commit-bot@chromium.org | fde1e7c | 2013-08-02 13:59:50 +0000 | [diff] [blame] | 39 | #if SK_SUPPORT_GPU |
| 40 | void setGLSampleCount(int sampleCount); |
| 41 | #endif |
| 42 | |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 43 | /** 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.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 45 | |
chudy@google.com | 686e680 | 2012-08-14 16:00:32 +0000 | [diff] [blame] | 46 | void resetWidgetTransform(); |
| 47 | |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 48 | enum ZoomCommandTypes { |
| 49 | kIn_ZoomCommand, |
| 50 | kOut_ZoomCommand, |
| 51 | }; |
robertphillips | 9ea8acd | 2016-03-01 09:34:38 -0800 | [diff] [blame] | 52 | public Q_SLOTS: |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 53 | /** |
| 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 | |
robertphillips | 9ea8acd | 2016-03-01 09:34:38 -0800 | [diff] [blame] | 59 | Q_SIGNALS: |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 60 | void scaleFactorChanged(float newScaleFactor); |
| 61 | void commandChanged(int newCommand); |
chudy@google.com | e606d6e | 2012-07-12 14:31:25 +0000 | [diff] [blame] | 62 | void hitChanged(int hit); |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 63 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 64 | private: |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 65 | QHBoxLayout fHorizontalLayout; |
| 66 | SkRasterWidget fRasterWidget; |
robertphillips@google.com | e8fe4bc | 2013-02-13 13:26:13 +0000 | [diff] [blame] | 67 | #if SK_SUPPORT_GPU |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 68 | SkGLWidget fGLWidget; |
robertphillips@google.com | e8fe4bc | 2013-02-13 13:26:13 +0000 | [diff] [blame] | 69 | #endif |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 70 | SkDebugger* fDebugger; |
chudy@google.com | 2f89179 | 2012-07-03 16:05:59 +0000 | [diff] [blame] | 71 | SkIPoint fPreviousPoint; |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 72 | SkMatrix fUserMatrix; |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 73 | |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 74 | void mouseMoveEvent(QMouseEvent* event); |
| 75 | |
| 76 | void mousePressEvent(QMouseEvent* event); |
| 77 | |
| 78 | void mouseDoubleClickEvent(QMouseEvent* event); |
| 79 | |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 80 | void wheelEvent(QWheelEvent* event); |
| 81 | |
| 82 | void snapWidgetTransform(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 85 | |
| 86 | #endif /* SKCANVASWIDGET_H_ */ |