From 38b08ce020f451a66263110b32e70f5022df4f83 Mon Sep 17 00:00:00 2001 From: "chudy@google.com" Date: Sat, 28 Jul 2012 23:26:10 +0000 Subject: [PATCH] Added missing files to fix build. TBR Review URL: https://codereview.appspot.com/6455058 git-svn-id: http://skia.googlecode.com/svn/trunk@4822 2bbb7eff-a529-9590-31e7-b0007b416f81 --- debugger/QT/SkDebuggerGUI.cpp | 2 +- debugger/QT/SkRasterWidget.cpp | 64 +++++++++++++++++++++++++++++++++ debugger/QT/SkRasterWidget.h | 80 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 debugger/QT/SkRasterWidget.cpp create mode 100644 debugger/QT/SkRasterWidget.h diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp index 830f0f6..e497ff7 100644 --- a/debugger/QT/SkDebuggerGUI.cpp +++ b/debugger/QT/SkDebuggerGUI.cpp @@ -217,7 +217,7 @@ void SkDebuggerGUI::actionSave() { void SkDebuggerGUI::actionSaveAs() { QString filename = QFileDialog::getSaveFileName(this, "Save File", "", "Skia Picture (*skp)"); - if (!filename.endsWith(".skp", Qt::CaseInsensitive)) + if (!filename.endsWith(".skp", Qt::CaseInsensitive)) { filename.append(".skp"); } saveToFile(filename); diff --git a/debugger/QT/SkRasterWidget.cpp b/debugger/QT/SkRasterWidget.cpp new file mode 100644 index 0000000..0549649 --- /dev/null +++ b/debugger/QT/SkRasterWidget.cpp @@ -0,0 +1,64 @@ + +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + + +#include "SkRasterWidget.h" + +SkRasterWidget::SkRasterWidget(QWidget* parent) : QWidget(parent) { + fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 800, 800); + fBitmap.allocPixels(); + fBitmap.eraseColor(0); + fTransform.set(0,0); + fScaleFactor = 1.0; + fIndex = 0; + + fDebugCanvas = new SkDebugCanvas(); + this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}"); +} + +SkRasterWidget::~SkRasterWidget() { + delete fDevice; + delete fDebugCanvas; +} + +void SkRasterWidget::resizeEvent(QResizeEvent* event) { + fBitmap.setConfig(SkBitmap::kARGB_8888_Config, event->size().width(), event->size().height()); + fBitmap.allocPixels(); + delete fDevice; + fDevice = new SkDevice(fBitmap); + fDebugCanvas->setBounds(event->size().width(), event->size().height()); + this->update(); +} + +void SkRasterWidget::paintEvent(QPaintEvent* event) { + fBitmap.eraseColor(0); + SkCanvas canvas(fDevice); + canvas.translate(fTransform.fX, fTransform.fY); + if (fScaleFactor < 0) { + canvas.scale((1.0 / -fScaleFactor), (1.0 / -fScaleFactor)); + } else if (fScaleFactor > 0) { + canvas.scale(fScaleFactor, fScaleFactor); + } + + fMatrix = canvas.getTotalMatrix(); + fClip = canvas.getTotalClip().getBounds(); + fDebugCanvas->drawTo(&canvas, fIndex+1, &fBitmap); + + QPainter painter(this); + QStyleOption opt; + opt.init(this); + + style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); + + QPoint origin(0,0); + QImage image((uchar *)fBitmap.getPixels(), fBitmap.width(), + fBitmap.height(), QImage::Format_ARGB32_Premultiplied); + + painter.drawImage(origin, image); + painter.end(); +} diff --git a/debugger/QT/SkRasterWidget.h b/debugger/QT/SkRasterWidget.h new file mode 100644 index 0000000..af65792 --- /dev/null +++ b/debugger/QT/SkRasterWidget.h @@ -0,0 +1,80 @@ +/* + * SkRasterWidget.h + * + * Created on: Jul 28, 2012 + * Author: chudy + */ + + +#ifndef SKRASTERWIDGET_H_ +#define SKRASTERWIDGET_H_ + +#include "SkGpuDevice.h" +#include "SkDevice.h" +#include "SkDebugCanvas.h" + +#include +#include +#include + +class SkRasterWidget : public QWidget { + +public: + SkRasterWidget(QWidget* parent = NULL); + + ~SkRasterWidget(); + + void drawTo(int index) { + fIndex = index; + this->update(); + } + + void setDebugCanvas(SkDebugCanvas* debugCanvas) { + fDebugCanvas = debugCanvas; + fIndex = debugCanvas->getSize(); + this->update(); + } + + int getBitmapHeight() { + return fBitmap.height(); + } + + int getBitmapWidth() { + return fBitmap.width(); + } + + const SkMatrix& getCurrentMatrix() { + return fMatrix; + } + + const SkIRect& getCurrentClip() { + return fClip; + } + + void setTranslate(SkIPoint transform) { + fTransform = transform; + } + + void setScale(float scale) { + fScaleFactor = scale; + } + +protected: + void paintEvent(QPaintEvent* event); + + void resizeEvent(QResizeEvent* event); + +private: + SkBitmap fBitmap; + SkDebugCanvas* fDebugCanvas; + SkDevice* fDevice; + + SkMatrix fMatrix; + SkIRect fClip; + + int fIndex; + SkIPoint fTransform; + float fScaleFactor; +}; + +#endif /* SKRASTERWIDGET_H_ */ -- 2.7.4