SkCanvasWidget.h revision 830b8793bb1646bb76817bdc228dd8e2a92bef7d
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
19class SkCanvasWidget : public QWidget {
20    Q_OBJECT
21
22public:
23    SkCanvasWidget();
24
25    ~SkCanvasWidget();
26
27    enum WidgetType {
28        kRaster_8888_WidgetType = 1 << 0,
29        kGPU_WidgetType         = 1 << 1,
30    };
31
32    /**
33        Returns the visibility of the command at the specified index.
34        @param index  The index of the draw command
35     */
36    bool commandIsVisibleAtIndex(int index) {
37        return fDebugCanvas->getDrawCommandVisibilityAt(index);
38    }
39
40    /**
41        Toggles the visibility / execution of the draw command at index i with
42        the value of toggle.
43     */
44    void setCommandVisibliltyAtIndex(int index, bool toggle) {
45        fDebugCanvas->toggleCommand(index, toggle);
46    }
47
48    /**
49          Returns a vector of strings with all the current canvas draw
50          commands.
51     */
52    std::vector<std::string>* getDrawCommands() {
53        return fDebugCanvas->getDrawCommandsAsStrings();
54    }
55
56    SkDebugCanvas* getCurrentDebugCanvas() {
57        return fDebugCanvas;
58    }
59
60    void drawTo(int index);
61
62    void setWidgetVisibility(WidgetType type, bool isHidden);
63
64    /**
65        Toggles drawing filter on all drawing commands previous to current.
66     */
67    void toggleCurrentCommandFilter(bool toggle) {
68        fDebugCanvas->toggleFilter(toggle);
69    }
70
71    /**
72        TODO(chudy): Refactor into a struct of char**
73        Returns parameter information about the ith draw command.
74        @param: i  The index of the draw command we are accessing
75     */
76    std::vector<std::string>* getCurrentCommandInfo(int i) {
77        return fDebugCanvas->getCommandInfoAt(i);
78    }
79
80    const SkMatrix& getCurrentMatrix() {
81        return fRasterWidget.getCurrentMatrix();
82    }
83
84    const SkIRect& getCurrentClip() {
85        return fRasterWidget.getCurrentClip();
86    }
87
88    void loadPicture(QString filename);
89
90    // TODO(chudy): Not full proof since fRasterWidget isn't always drawn to.
91    int getBitmapHeight() {
92        return fRasterWidget.getBitmapHeight();
93    }
94
95    int getBitmapWidth() {
96        return fRasterWidget.getBitmapWidth();
97    }
98
99    SkRasterWidget* getRasterWidget() {
100        return &fRasterWidget;
101    }
102
103    void zoom(float zoomIncrement);
104
105signals:
106    void scaleFactorChanged(float newScaleFactor);
107    void commandChanged(int newCommand);
108    void hitChanged(int hit);
109
110private slots:
111    void keyZoom(int zoomIncrement) {
112        zoom(zoomIncrement);
113    }
114
115private:
116    QHBoxLayout fHorizontalLayout;
117    SkRasterWidget fRasterWidget;
118    SkGLWidget fGLWidget;
119    SkDebugCanvas* fDebugCanvas;
120    SkIPoint fPreviousPoint;
121    SkIPoint fUserOffset;
122    float fUserScaleFactor;
123    int fIndex;
124
125    void resetWidgetTransform();
126
127    void mouseMoveEvent(QMouseEvent* event);
128
129    void mousePressEvent(QMouseEvent* event);
130
131    void mouseDoubleClickEvent(QMouseEvent* event);
132
133    void wheelEvent(QWheelEvent* event) {
134        zoom(event->delta()/120);
135    }
136};
137
138
139#endif /* SKCANVASWIDGET_H_ */
140