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 10 #ifndef SKCANVASWIDGET_H_ 11 #define SKCANVASWIDGET_H_ 12 13 #include <QWidget> 14 #include <QHBoxLayout> 15 #include "SkStream.h" 16 #include "SkRasterWidget.h" 17 #include "SkGLWidget.h" 18 #include "SkDebugger.h" 19 20 class SkCanvasWidget : public QWidget { 21 Q_OBJECT 22 23 public: 24 SkCanvasWidget(QWidget* parent, SkDebugger* debugger); 25 26 ~SkCanvasWidget(); 27 28 enum WidgetType { 29 kRaster_8888_WidgetType = 1 << 0, 30 #if SK_SUPPORT_GPU 31 kGPU_WidgetType = 1 << 1, 32 #endif 33 }; 34 35 void drawTo(int index); 36 37 void setWidgetVisibility(WidgetType type, bool isHidden); 38 39 #if SK_SUPPORT_GPU 40 void setGLSampleCount(int sampleCount); 41 #endif 42 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); 45 46 void resetWidgetTransform(); 47 48 enum ZoomCommandTypes { 49 kIn_ZoomCommand, 50 kOut_ZoomCommand, 51 }; 52 public slots: 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 59 signals: 60 void scaleFactorChanged(float newScaleFactor); 61 void commandChanged(int newCommand); 62 void hitChanged(int hit); 63 64 private: 65 QHBoxLayout fHorizontalLayout; 66 SkRasterWidget fRasterWidget; 67 #if SK_SUPPORT_GPU 68 SkGLWidget fGLWidget; 69 #endif 70 SkDebugger* fDebugger; 71 SkIPoint fPreviousPoint; 72 SkMatrix fUserMatrix; 73 74 void mouseMoveEvent(QMouseEvent* event); 75 76 void mousePressEvent(QMouseEvent* event); 77 78 void mouseDoubleClickEvent(QMouseEvent* event); 79 80 void wheelEvent(QWheelEvent* event); 81 82 void snapWidgetTransform(); 83 }; 84 85 86 #endif /* SKCANVASWIDGET_H_ */ 87