aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/mdbviz/mainwindow.cpp
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-09-06 13:07:21 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-09-06 20:46:01 +0000
commitdeaf568e07f0b63c84c5909f14e2b7261b1653ae (patch)
tree6c4e8023f34d2019772c22edff65fe9afb45949b /tools/mdbviz/mainwindow.cpp
parent2880421c724e7b45ed13b784a36aa81a09fe62e5 (diff)
Solidify Model/View split
Change-Id: Iecf034feaa009002b5f09c47052c915d22aec0e4 Reviewed-on: https://skia-review.googlesource.com/43040 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'tools/mdbviz/mainwindow.cpp')
-rw-r--r--tools/mdbviz/mainwindow.cpp58
1 files changed, 21 insertions, 37 deletions
diff --git a/tools/mdbviz/mainwindow.cpp b/tools/mdbviz/mainwindow.cpp
index 5fb1e7e344..c09ad091fa 100644
--- a/tools/mdbviz/mainwindow.cpp
+++ b/tools/mdbviz/mainwindow.cpp
@@ -9,11 +9,6 @@
#include "MainWindow.h"
-#include "SkBitmap.h"
-#include "SkCanvas.h"
-#include "SkPicture.h"
-#include "SkStream.h"
-
MainWindow::MainWindow() {
this->createActions();
this->createStatusBar();
@@ -35,16 +30,21 @@ void MainWindow::openFile() {
void MainWindow::setupOpListWidget() {
fOpListWidget->clear();
- for (int i = 0; i < fDebugCanvas->getSize(); i++) {
+ for (int i = 0; i < fModel.numOps(); i++) {
QListWidgetItem *item = new QListWidgetItem();
- const SkDrawCommand* command = fDebugCanvas->getDrawCommandAt(i);
-
- SkString commandString = command->toString();
- item->setData(Qt::DisplayRole, commandString.c_str());
+ item->setData(Qt::DisplayRole, fModel.getOpName(i));
fOpListWidget->addItem(item);
}
+
+ fOpListWidget->setCurrentRow(fModel.numOps()-1);
+}
+
+void MainWindow::presentCurrentRenderState() {
+ fImage = QImage((uchar*)fModel.getPixels(), fModel.width(), fModel.height(),
+ QImage::Format_RGBA8888);
+ fImageLabel->setPixmap(QPixmap::fromImage(fImage));
}
void MainWindow::loadFile(const QString &fileName) {
@@ -63,37 +63,14 @@ void MainWindow::loadFile(const QString &fileName) {
std::string str = file.fileName().toLocal8Bit().constData();
- std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(str.c_str());
- if (!stream) {
- this->statusBar()->showMessage(tr("Couldn't read file"));
- return;
- }
- sk_sp<SkPicture> pic(SkPicture::MakeFromStream(stream.get()));
- if (!pic) {
- this->statusBar()->showMessage(tr("Couldn't decode picture"));
+ Model::ErrorCode err = fModel.load(str.c_str());
+ if (Model::ErrorCode::kOK != err) {
+ this->statusBar()->showMessage(Model::ErrorString(err));
return;
}
- fDebugCanvas.reset(new SkDebugCanvas(SkScalarCeilToInt(pic->cullRect().width()),
- SkScalarCeilToInt(pic->cullRect().height())));
-
- fDebugCanvas->setPicture(pic.get());
- pic->playback(fDebugCanvas.get());
- fDebugCanvas->setPicture(nullptr);
-
this->setupOpListWidget();
-
- SkBitmap bm;
-
- SkImageInfo ii = SkImageInfo::MakeN32Premul(1024, 1024);
- bm.allocPixels(ii, 0);
-
- SkCanvas canvas(bm);
-
- fDebugCanvas->draw(&canvas);
-
- fImage = QImage((uchar*)bm.getPixels(), bm.width(), bm.height(), QImage::Format_RGBA8888);
- fImageLabel->setPixmap(QPixmap::fromImage(fImage));
+ this->presentCurrentRenderState();
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
@@ -138,6 +115,11 @@ void MainWindow::createActions() {
aboutAct->setStatusTip(tr("Show the application's About box"));
}
+void MainWindow::onCurrentRowChanged(int currentRow) {
+ fModel.setCurOp(currentRow);
+ this->presentCurrentRenderState();
+}
+
void MainWindow::createStatusBar() {
this->statusBar()->showMessage(tr("Ready"));
}
@@ -155,6 +137,8 @@ void MainWindow::createDockWindows() {
this->addDockWidget(Qt::LeftDockWidgetArea, opListDock);
fViewMenu->addAction(opListDock->toggleViewAction());
+
+ connect(fOpListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(onCurrentRowChanged(int)));
}
// Main canvas Window