1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/*
* 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 <QtGui>
#include "SkDebugger.h"
#include "SkImageWidget.h"
SkImageWidget::SkImageWidget(SkDebugger *debugger)
: QWidget()
, fDebugger(debugger)
{
this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}");
SkImageInfo info = SkImageInfo::MakeN32Premul(kImageWidgetWidth, kImageWidgetHeight);
fSurface = SkSurface::NewRasterDirect(info, fPixels, 4 * kImageWidgetWidth);
}
void SkImageWidget::paintEvent(QPaintEvent* event) {
if (this->isHidden()) {
return;
}
QPainter painter(this);
QStyleOption opt;
opt.init(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
const SkTDArray<SkDrawCommand*>& commands = fDebugger->getDrawCommands();
if (0 != commands.count()) {
SkDrawCommand* command = commands[fDebugger->index()];
if (command->render(fSurface->getCanvas())) {
QPoint origin(0,0);
QImage image((uchar*) fPixels,
kImageWidgetWidth,
kImageWidgetHeight,
QImage::Format_ARGB32_Premultiplied);
painter.drawImage(origin, image);
} else {
painter.drawRect(0, 0, kImageWidgetWidth, kImageWidgetHeight);
}
}
painter.end();
emit drawComplete();
}
|