SkCanvasWidget.h revision e8fe4bc3efa8f18f5651c5d005fba1935a741be0
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 20class SkCanvasWidget : public QWidget { 21 Q_OBJECT 22 23public: 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 /** Zooms the canvas by scale with the transformation centered at the widget point (px, py). */ 40 void zoom(float scale, int px, int py); 41 42 void resetWidgetTransform(); 43 44 enum ZoomCommandTypes { 45 kIn_ZoomCommand, 46 kOut_ZoomCommand, 47 }; 48public 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 55signals: 56 void scaleFactorChanged(float newScaleFactor); 57 void commandChanged(int newCommand); 58 void hitChanged(int hit); 59 60private: 61 QHBoxLayout fHorizontalLayout; 62 SkRasterWidget fRasterWidget; 63#if SK_SUPPORT_GPU 64 SkGLWidget fGLWidget; 65#endif 66 SkDebugger* fDebugger; 67 SkIPoint fPreviousPoint; 68 SkMatrix fUserMatrix; 69 70 void mouseMoveEvent(QMouseEvent* event); 71 72 void mousePressEvent(QMouseEvent* event); 73 74 void mouseDoubleClickEvent(QMouseEvent* event); 75 76 void wheelEvent(QWheelEvent* event); 77 78 void snapWidgetTransform(); 79}; 80 81 82#endif /* SKCANVASWIDGET_H_ */ 83