robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 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 | #include <QtGui> |
| 10 | |
| 11 | #include "SkDebugger.h" |
| 12 | #include "SkImageWidget.h" |
| 13 | |
skia.committer@gmail.com | 1c9c0d3 | 2012-11-22 02:02:41 +0000 | [diff] [blame] | 14 | SkImageWidget::SkImageWidget(SkDebugger *debugger) |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 15 | : QWidget() |
| 16 | , fDebugger(debugger) { |
| 17 | this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}"); |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 18 | |
| 19 | SkImage::Info info; |
| 20 | info.fWidth = kImageWidgetWidth; |
| 21 | info.fHeight = kImageWidgetHeight; |
| 22 | info.fColorType = SkImage::kPMColor_ColorType; |
reed@google.com | beb0c2a | 2013-09-20 20:05:01 +0000 | [diff] [blame] | 23 | info.fAlphaType = kPremul_SkAlphaType; |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 24 | |
| 25 | fSurface = SkSurface::NewRasterDirect(info, fPixels, 4 * kImageWidgetWidth); |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | void SkImageWidget::paintEvent(QPaintEvent* event) { |
| 29 | if (this->isHidden()) { |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | QPainter painter(this); |
| 34 | QStyleOption opt; |
| 35 | opt.init(this); |
| 36 | |
| 37 | style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); |
| 38 | |
| 39 | const SkTDArray<SkDrawCommand*>& commands = fDebugger->getDrawCommands(); |
| 40 | if (0 != commands.count()) { |
| 41 | SkDrawCommand* command = commands[fDebugger->index()]; |
| 42 | |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 43 | if (command->render(fSurface->getCanvas())) { |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 44 | QPoint origin(0,0); |
skia.committer@gmail.com | a009083 | 2013-06-07 07:01:06 +0000 | [diff] [blame] | 45 | QImage image((uchar*) fPixels, |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 46 | kImageWidgetWidth, |
skia.committer@gmail.com | a009083 | 2013-06-07 07:01:06 +0000 | [diff] [blame] | 47 | kImageWidgetHeight, |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 48 | QImage::Format_ARGB32_Premultiplied); |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 49 | |
| 50 | painter.drawImage(origin, image); |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 51 | } else { |
| 52 | painter.drawRect(0, 0, kImageWidgetWidth, kImageWidgetHeight); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | painter.end(); |
| 57 | emit drawComplete(); |
| 58 | } |