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 | |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 39 | /** 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.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 41 | |
chudy@google.com | 686e680 | 2012-08-14 16:00:32 +0000 | [diff] [blame] | 42 | void resetWidgetTransform(); |
| 43 | |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 44 | enum ZoomCommandTypes { |
| 45 | kIn_ZoomCommand, |
| 46 | kOut_ZoomCommand, |
| 47 | }; |
| 48 | public 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.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 55 | signals: |
| 56 | void scaleFactorChanged(float newScaleFactor); |
| 57 | void commandChanged(int newCommand); |
chudy@google.com | e606d6e | 2012-07-12 14:31:25 +0000 | [diff] [blame] | 58 | void hitChanged(int hit); |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 59 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 60 | private: |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 61 | QHBoxLayout fHorizontalLayout; |
| 62 | SkRasterWidget fRasterWidget; |
robertphillips@google.com | e8fe4bc | 2013-02-13 13:26:13 +0000 | [diff] [blame] | 63 | #if SK_SUPPORT_GPU |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 64 | SkGLWidget fGLWidget; |
robertphillips@google.com | e8fe4bc | 2013-02-13 13:26:13 +0000 | [diff] [blame] | 65 | #endif |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 66 | SkDebugger* fDebugger; |
chudy@google.com | 2f89179 | 2012-07-03 16:05:59 +0000 | [diff] [blame] | 67 | SkIPoint fPreviousPoint; |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 68 | SkMatrix fUserMatrix; |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 69 | |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 70 | void mouseMoveEvent(QMouseEvent* event); |
| 71 | |
| 72 | void mousePressEvent(QMouseEvent* event); |
| 73 | |
| 74 | void mouseDoubleClickEvent(QMouseEvent* event); |
| 75 | |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 76 | void wheelEvent(QWheelEvent* event); |
| 77 | |
| 78 | void snapWidgetTransform(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 81 | |
| 82 | #endif /* SKCANVASWIDGET_H_ */ |