830b8793bb
Review URL: https://codereview.appspot.com/6458056 git-svn-id: http://skia.googlecode.com/svn/trunk@4891 2bbb7eff-a529-9590-31e7-b0007b416f81
61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
|
|
/*
|
|
* 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() {
|
|
fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 800, 800);
|
|
fBitmap.allocPixels();
|
|
fBitmap.eraseColor(0);
|
|
fTransform.set(0,0);
|
|
fScaleFactor = 1.0;
|
|
fIndex = 0;
|
|
fDevice = new SkDevice(fBitmap);
|
|
fDebugCanvas = NULL;
|
|
fCanvas = new SkCanvas(fDevice);
|
|
this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}");
|
|
}
|
|
|
|
SkRasterWidget::~SkRasterWidget() {
|
|
SkSafeUnref(fCanvas);
|
|
SkSafeUnref(fDevice);
|
|
}
|
|
|
|
void SkRasterWidget::resizeEvent(QResizeEvent* event) {
|
|
fBitmap.setConfig(SkBitmap::kARGB_8888_Config, event->size().width(), event->size().height());
|
|
fBitmap.allocPixels();
|
|
SkSafeUnref(fCanvas);
|
|
SkSafeUnref(fDevice);
|
|
fDevice = new SkDevice(fBitmap);
|
|
fCanvas = new SkCanvas(fDevice);
|
|
this->update();
|
|
}
|
|
|
|
void SkRasterWidget::paintEvent(QPaintEvent* event) {
|
|
if (fDebugCanvas) {
|
|
fDebugCanvas->drawTo(fCanvas, fIndex);
|
|
// TODO(chudy): Refactor into SkDebugCanvas.
|
|
fMatrix = fCanvas->getTotalMatrix();
|
|
fClip = fCanvas->getTotalClip().getBounds();
|
|
|
|
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();
|
|
}
|
|
}
|