blob: 10fe0b19ff7fb0b681a21baa14a6d236d5deab53 [file] [log] [blame]
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +00001
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.com1c9c0d32012-11-22 02:02:41 +000014SkImageWidget::SkImageWidget(SkDebugger *debugger)
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000015 : QWidget()
16 , fDebugger(debugger) {
17 this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}");
18}
19
20void SkImageWidget::paintEvent(QPaintEvent* event) {
21 if (this->isHidden()) {
22 return;
23 }
24
25 QPainter painter(this);
26 QStyleOption opt;
27 opt.init(this);
28
29 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
30
31 const SkTDArray<SkDrawCommand*>& commands = fDebugger->getDrawCommands();
32 if (0 != commands.count()) {
33 SkDrawCommand* command = commands[fDebugger->index()];
34
35 const SkBitmap* bitmap = command->getBitmap();
36
37 if (NULL != bitmap) {
38 bitmap->lockPixels();
39
40 QPoint origin(0,0);
41 QImage image((uchar *)bitmap->getPixels(), bitmap->width(),
42 bitmap->height(), QImage::Format_ARGB32_Premultiplied);
43
44 painter.drawImage(origin, image);
45
46 bitmap->unlockPixels();
47 } else {
48 painter.drawRect(0, 0, kImageWidgetWidth, kImageWidgetHeight);
49 }
50 }
51
52 painter.end();
53 emit drawComplete();
54}