diff --git a/debugger/QT/SkCanvasWidget.cpp b/debugger/QT/SkCanvasWidget.cpp index 6e8265627b..c38fdbb810 100644 --- a/debugger/QT/SkCanvasWidget.cpp +++ b/debugger/QT/SkCanvasWidget.cpp @@ -10,28 +10,69 @@ #include "SkPicture.h" #include "SkStream.h" #include "SkCanvasWidget.h" +#include "SkColor.h" #include SkCanvasWidget::SkCanvasWidget(QWidget *parent) : QWidget(parent) { - fBitmap = new SkBitmap(); - fBitmap->setConfig(SkBitmap::kARGB_8888_Config, 800, 800); - fBitmap->allocPixels(); - fBitmap->eraseColor(0); - fDevice = new SkDevice(*fBitmap); + /* TODO(chudy): The 800x800 is a default number. Change it to be + * set dynamically. Also need to pass size into debugCanvas for current + * command filter. */ + fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 800, 800); + fBitmap.allocPixels(); + fBitmap.eraseColor(0); + + /* TODO(chudy): Add fCanvas, fDevice to the stack. The bitmap being + * cleared does get rid of fDevices link to it. See if there's someway around + * it so that we don't have to delete both canvas and device to clear out + * the bitmap. */ + fDevice = new SkDevice(fBitmap); fCanvas = new SkCanvas(fDevice); fDebugCanvas = new SkDebugCanvas(); + + fScaleFactor = 1; + fIndex = 0; + fPreviousPoint.set(0,0); + fTransform.set(0,0); + this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}"); } -SkCanvasWidget::~SkCanvasWidget() {} +SkCanvasWidget::~SkCanvasWidget() { + delete fCanvas; + delete fDevice; + delete fDebugCanvas; +} -void SkCanvasWidget::drawTo(int index) { +void SkCanvasWidget::resizeEvent(QResizeEvent* event) { + fBitmap.setConfig(SkBitmap::kARGB_8888_Config, event->size().width(), event->size().height()); + fBitmap.allocPixels(); + fBitmap.eraseColor(0); + + delete fCanvas; + delete fDevice; + + fDevice = new SkDevice(fBitmap); + fCanvas = new SkCanvas(fDevice); + fDebugCanvas->drawTo(fCanvas, fIndex); + this->update(); +} + +void SkCanvasWidget::drawTo(int fIndex) { delete fCanvas; fCanvas = new SkCanvas(fDevice); - fDebugCanvas->drawTo(fCanvas, index+1); + + fCanvas->translate(fTransform.fX, fTransform.fY); + if(fScaleFactor < 0) { + fCanvas->scale((1.0 / -fScaleFactor),(1.0 / -fScaleFactor)); + } else if (fScaleFactor > 0) { + fCanvas->scale(fScaleFactor, fScaleFactor); + } + + fDebugCanvas->drawTo(fCanvas, fIndex+1); this->update(); + this->fIndex = fIndex; } void SkCanvasWidget::loadPicture(QString filename) { @@ -44,6 +85,14 @@ void SkCanvasWidget::loadPicture(QString filename) { picture->draw(fDebugCanvas); fDebugCanvas->draw(fCanvas); + fIndex = fDebugCanvas->getSize(); + + SkColor color = fBitmap.getColor(fBitmap.width()-1,fBitmap.height()-1); + + int r = SkColorGetR(color); + int g = SkColorGetG(color); + int b = SkColorGetB(color); + /* NOTE(chudy): This was a test to determine if the canvas size is accurately * saved in the bounds of the recorded picture. It is not. Everyone of the * sample GM images is 1000x1000. Even the one that claims it is @@ -51,9 +100,37 @@ void SkCanvasWidget::loadPicture(QString filename) { std::cout << "Width: " << picture->width(); std::cout << " Height: " << picture->height() << std::endl; */ - /* NOTE(chudy): Updated style sheet without a background specified to - * draw over our SkCanvas. */ - this->setStyleSheet("QWidget {border: 1px solid #cccccc;}"); + /* Updated style sheet without a background specified. If not removed + * QPainter paints the specified background color on top of our canvas. */ + + QString style("QWidget {border: 1px solid #cccccc; background-color: #"); + style.append(QString::number(r, 16)); + style.append(QString::number(g, 16)); + style.append(QString::number(b, 16)); + style.append(";}"); + this->setStyleSheet(style); + this->update(); +} + +void SkCanvasWidget::mouseMoveEvent(QMouseEvent* event) { + + SkIPoint eventPoint = SkIPoint::Make(event->globalX(), event->globalY()); + fTransform += eventPoint - fPreviousPoint; + fPreviousPoint = eventPoint; + + // TODO(chudy): Fix and remove +1 from drawTo calls. + drawTo(fIndex+1); + this->update(); +} + +void SkCanvasWidget::mousePressEvent(QMouseEvent* event) { + fPreviousPoint.set(event->globalX(), event->globalY()); +} + +void SkCanvasWidget::mouseDoubleClickEvent(QMouseEvent* event) { + fTransform.set(0,0); + fScaleFactor = 0; + drawTo(fIndex+1); this->update(); } @@ -62,12 +139,28 @@ void SkCanvasWidget::paintEvent(QPaintEvent *event) { QStyleOption opt; opt.init(this); - if (fBitmap) { - const QPoint origin(0,0); - QImage image((uchar *)fBitmap->getPixels(), fBitmap->width(), fBitmap->height(), QImage::Format_ARGB32_Premultiplied); - painter.drawImage(origin,image); - } - 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(); } + +void SkCanvasWidget::wheelEvent(QWheelEvent* event) { + fScaleFactor += event->delta()/120; + + /* The range of the fScaleFactor crosses over the range -1,0,1 frequently. + * Based on the code below, -1 and 1 both scale the image to it's original + * size we do the following to never have a registered wheel scroll + * not effect the fScaleFactor. */ + if (fScaleFactor == 0) { + fScaleFactor += (event->delta()/120) * 2; + } + + // TODO(chudy): Fix and remove +1 from drawTo calls. + drawTo(fIndex+1); + this->update(); +} diff --git a/debugger/QT/SkCanvasWidget.h b/debugger/QT/SkCanvasWidget.h index a7e1c8a957..bfe517e798 100644 --- a/debugger/QT/SkCanvasWidget.h +++ b/debugger/QT/SkCanvasWidget.h @@ -18,6 +18,7 @@ #include #include #include +#include /** \class SkCanvasWidget @@ -47,13 +48,27 @@ public: /** Returns the height of the bitmap. */ - int getBitmapHeight() { return fBitmap->height(); } + int getBitmapHeight() { return fBitmap.height(); } /* Returns the width of the bitmap. */ - int getBitmapWidth() { return fBitmap->width(); } + int getBitmapWidth() { return fBitmap.width(); } + + /** + Returns an array of values of the current matrix. + */ + const SkMatrix& getCurrentMatrix() { + return fCanvas->getTotalMatrix(); + } + + /** + Returns an array of values of the current bounding clip. + */ + const SkIRect& getCurrentClip() { + return fCanvas->getTotalClip().getBounds(); + } /** TODO(chudy): Refactor into a struct of char** @@ -100,6 +115,19 @@ public: fDebugCanvas->toggleFilter(toggle); } + /** + Captures mouse clicks + @param event The event intercepted by Qt + */ + void mouseMoveEvent(QMouseEvent* event); + + void mousePressEvent(QMouseEvent* event); + + void mouseDoubleClickEvent(QMouseEvent* event); + + void resizeEvent(QResizeEvent* event); + + void wheelEvent(QWheelEvent* event); protected: /** @@ -109,10 +137,16 @@ protected: void paintEvent(QPaintEvent *event); private: - SkBitmap* fBitmap; + SkBitmap fBitmap; SkCanvas* fCanvas; SkDebugCanvas* fDebugCanvas; SkDevice* fDevice; + + SkIPoint fPreviousPoint; + SkIPoint fTransform; + + int fIndex; + int fScaleFactor; }; #endif diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp index 9c98f485a2..4c00f0ed60 100644 --- a/debugger/QT/SkDebuggerGUI.cpp +++ b/debugger/QT/SkDebuggerGUI.cpp @@ -190,7 +190,6 @@ void SkDebuggerGUI::openFile() { tr("Files (*.*)")); fDirectoryWidgetActive = false; if (!fileName.isNull()) { - QFileInfo pathInfo(fileName); fPath = pathInfo.path(); loadPicture(fileName); @@ -225,6 +224,9 @@ void SkDebuggerGUI::registerListClick(QListWidgetItem *item) { info.append("
"); } fInspectorWidget->setDetailText(info); + fInspectorWidget->setDisabled(false); + fInspectorWidget->setMatrix(fCanvasWidget->getCurrentMatrix()); + fInspectorWidget->setClip(fCanvasWidget->getCurrentClip()); } } } diff --git a/debugger/QT/SkInspectorWidget.cpp b/debugger/QT/SkInspectorWidget.cpp index 76dce914ac..3f64e6f1a5 100644 --- a/debugger/QT/SkInspectorWidget.cpp +++ b/debugger/QT/SkInspectorWidget.cpp @@ -10,35 +10,38 @@ #include "SkInspectorWidget.h" #include -SkInspectorWidget::SkInspectorWidget(QWidget *parent) : QWidget(parent) { - // NOTE(chudy): Keeps the inspector widget fully expanded. - fHorizontalLayout = new QHBoxLayout(this); - fHorizontalLayout->setSpacing(6); - fHorizontalLayout->setContentsMargins(11, 11, 11, 11); +SkInspectorWidget::SkInspectorWidget(QWidget *parent) + : QWidget(parent) + , fHorizontalLayout(this) + , fOverviewTab() + , fOverviewLayout(&fOverviewTab) + , fDetailTab() + , fDetailLayout(&fDetailTab) + , fMatrixAndClipWidget(this) + , fVerticalLayout(&fMatrixAndClipWidget) + , fMatrixLabel(this) + , fClipLabel(this) { - fTabWidget = new QTabWidget(); + fHorizontalLayout.setSpacing(6); + fHorizontalLayout.setContentsMargins(11, 11, 11, 11); - fOverviewTab = new QWidget(); - fOverviewLayout = new QHBoxLayout(fOverviewTab); - fOverviewLayout->setSpacing(6); - fOverviewLayout->setContentsMargins(11, 11, 11, 11); - fOverviewText = new QTextEdit(); - fOverviewText->setReadOnly(true); - fOverviewLayout->addWidget(fOverviewText); + fOverviewLayout.setSpacing(6); + fOverviewLayout.setContentsMargins(11, 11, 11, 11); - fDetailTab = new QWidget(); - fDetailLayout = new QHBoxLayout(fDetailTab); - fDetailLayout->setSpacing(6); - fDetailLayout->setContentsMargins(11,11,11,11); - fDetailText = new QTextEdit(); - fDetailText->setReadOnly(true); - fDetailLayout->addWidget(fDetailText); + fOverviewText.setReadOnly(true); + fOverviewLayout.addWidget(&fOverviewText); - fTabWidget->addTab(fOverviewTab, QString("Overview")); - fTabWidget->addTab(fDetailTab, QString("Details")); + fDetailLayout.setSpacing(6); + fDetailLayout.setContentsMargins(11,11,11,11); - fHorizontalLayout->setAlignment(Qt::AlignTop); - fHorizontalLayout->addWidget(fTabWidget); + fDetailText.setReadOnly(true); + fDetailLayout.addWidget(&fDetailText); + + fTabWidget.addTab(&fOverviewTab, QString("Overview")); + fTabWidget.addTab(&fDetailTab, QString("Details")); + + fHorizontalLayout.setAlignment(Qt::AlignTop); + fHorizontalLayout.addWidget(&fTabWidget); /* NOTE(chudy): We add all the line edits to (this). Then we lay them out * by adding them to horizontal layouts. @@ -47,81 +50,80 @@ SkInspectorWidget::SkInspectorWidget(QWidget *parent) : QWidget(parent) { * line edits in each horizontal layout. */ - fMatrixAndClipWidget = new QWidget(this); - fMatrixAndClipWidget->setFixedSize(200,300); - fMatrixAndClipWidget->setDisabled(true); - - fVerticalLayout = new QVBoxLayout(fMatrixAndClipWidget); - fVerticalLayout->setAlignment(Qt::AlignVCenter); - fVerticalLayout->addLayout(currentMatrix()); - fVerticalLayout->addLayout(currentClip()); - fHorizontalLayout->addWidget(fMatrixAndClipWidget); - + fMatrixAndClipWidget.setFixedSize(260,300); + fMatrixAndClipWidget.setDisabled(true); + fVerticalLayout.setAlignment(Qt::AlignVCenter); + fVerticalLayout.addLayout(setupMatrix()); + fVerticalLayout.addLayout(setupClip()); + fHorizontalLayout.addWidget(&fMatrixAndClipWidget); } SkInspectorWidget::~SkInspectorWidget() {} -QString SkInspectorWidget::getDetailText() { - return fDetailText->toHtml(); -} - -QString SkInspectorWidget::getOverviewText() { - return fOverviewText->toHtml(); -} - void SkInspectorWidget::setDetailText(QString text) { - fDetailText->setHtml(text); + fDetailText.setHtml(text); } void SkInspectorWidget::setOverviewText(QString text) { - fOverviewText->setHtml(text); + fOverviewText.setHtml(text); } -QVBoxLayout* SkInspectorWidget::currentMatrix() { - fMatrixLabel = new QLabel(this); - fMatrixLabel->setText("Current Matrix"); - fMatrixLabel->setAlignment(Qt::AlignHCenter); - fMatrixLayout = new QVBoxLayout(); - fMatrixLayout->setSpacing(6); - fMatrixLayout->setContentsMargins(11,11,11,0); - fMatrixLayout->setAlignment(Qt::AlignTop | Qt::AlignHCenter); - fMatrixLayout->addWidget(fMatrixLabel); +void SkInspectorWidget::setMatrix(const SkMatrix& matrix) { + for(int i=0; i<9; i++) { + fMatrixEntry[i].setText(QString::number(matrix.get(i))); + } +} + +void SkInspectorWidget::setClip(const SkIRect& clip) { + fClipEntry[0].setText(QString::number(clip.left())); + fClipEntry[1].setText(QString::number(clip.top())); + fClipEntry[2].setText(QString::number(clip.right())); + fClipEntry[3].setText(QString::number(clip.bottom())); +} + +QVBoxLayout* SkInspectorWidget::setupMatrix() { + fMatrixLabel.setText("Current Matrix"); + fMatrixLabel.setAlignment(Qt::AlignHCenter); + + fMatrixLayout.setSpacing(6); + fMatrixLayout.setContentsMargins(11,11,11,0); + fMatrixLayout.setAlignment(Qt::AlignTop | Qt::AlignHCenter); + fMatrixLayout.addWidget(&fMatrixLabel); for(int i =0; i<9; i++) { - fMatrixEntry[i] = new QLineEdit(); - fMatrixEntry[i]->setMinimumSize(QSize(50,25)); - fMatrixEntry[i]->setMaximumSize(QSize(50,16777215)); - fMatrixEntry[i]->setReadOnly(true); + fMatrixEntry[i].setMinimumSize(QSize(70,25)); + fMatrixEntry[i].setMaximumSize(QSize(70,16777215)); + fMatrixEntry[i].setReadOnly(true); - if(!(i%3)) fMatrixRow[i/3] = new QHBoxLayout(); - fMatrixRow[i/3]->addWidget(fMatrixEntry[i]); - if(i%3 == 2) fMatrixLayout->addLayout(fMatrixRow[i/3]); + fMatrixRow[i/3].addWidget(&fMatrixEntry[i]); + if(i%3 == 2) { + fMatrixLayout.addLayout(&fMatrixRow[i/3]); + } } - return fMatrixLayout; + return &fMatrixLayout; } -QVBoxLayout* SkInspectorWidget::currentClip() { - fClipLabel = new QLabel(this); - fClipLabel->setText("Current Clip"); - fClipLabel->setAlignment(Qt::AlignHCenter); - fClipLayout = new QVBoxLayout(); - fClipLayout->setSpacing(6); - fClipLayout->setContentsMargins(11,11,11,0); - fClipLayout->setAlignment(Qt::AlignTop | Qt::AlignHCenter); - fClipLayout->addWidget(fClipLabel); +QVBoxLayout* SkInspectorWidget::setupClip() { + fClipLabel.setText("Current Clip"); + fClipLabel.setAlignment(Qt::AlignHCenter); + + fClipLayout.setSpacing(6); + fClipLayout.setContentsMargins(11,11,11,0); + fClipLayout.setAlignment(Qt::AlignTop | Qt::AlignHCenter); + fClipLayout.addWidget(&fClipLabel); for(int i =0; i<4; i++) { - fClipEntry[i] = new QLineEdit(); - fClipEntry[i]->setMinimumSize(QSize(50,25)); - fClipEntry[i]->setMaximumSize(QSize(50,16777215)); - fClipEntry[i]->setReadOnly(true); + fClipEntry[i].setMinimumSize(QSize(70,25)); + fClipEntry[i].setMaximumSize(QSize(70,16777215)); + fClipEntry[i].setReadOnly(true); - if(!(i%2)) fClipRow[i/2] = new QHBoxLayout(); - fClipRow[i/2]->addWidget(fClipEntry[i]); - if(i%2 == 1) fClipLayout->addLayout(fClipRow[i/2]); + fClipRow[i/2].addWidget(&fClipEntry[i]); + if(i%2 == 1) { + fClipLayout.addLayout(&fClipRow[i/2]); + } } - return fClipLayout; + return &fClipLayout; } diff --git a/debugger/QT/SkInspectorWidget.h b/debugger/QT/SkInspectorWidget.h index 1025f4a5d1..3e761043f8 100644 --- a/debugger/QT/SkInspectorWidget.h +++ b/debugger/QT/SkInspectorWidget.h @@ -10,6 +10,8 @@ #ifndef SKINSPECTORWIDGET_H_ #define SKINSPECTORWIDGET_H_ +#include "SkMatrix.h" + #include #include #include @@ -34,16 +36,9 @@ public: ~SkInspectorWidget(); - /** - Returns a QString representation of the text currently in the detail tab. - */ - QString getDetailText(); - - /** - Returns a QString representation of the text currently in the overview tab. - */ - QString getOverviewText(); - + void setDisabled(bool isDisabled) { + fMatrixAndClipWidget.setDisabled(isDisabled); + } /** Sets the text in the detail tab. @param text @@ -56,31 +51,45 @@ public: */ void setOverviewText(QString text); + /** + Sets the text in the current matrix. + @param matrixValues + */ + void setMatrix(const SkMatrix& matrix); + + /** + Sets the text in the current clip. + @param clipValues + */ + void setClip(const SkIRect& clip); + private: - QWidget* fDetailTab; - QTextEdit* fDetailText; - QHBoxLayout* fDetailLayout; - QHBoxLayout* fHorizontalLayout; - QWidget* fOverviewTab; - QTextEdit* fOverviewText; - QHBoxLayout* fOverviewLayout; - QTabWidget* fTabWidget; + QHBoxLayout fHorizontalLayout; + QTabWidget fTabWidget; - QWidget* fMatrixAndClipWidget; - QVBoxLayout* fVerticalLayout; + QWidget fOverviewTab; + QHBoxLayout fOverviewLayout; + QTextEdit fOverviewText; - QVBoxLayout* fMatrixLayout; - QLabel* fMatrixLabel; - QHBoxLayout* fMatrixRow[3]; - QLineEdit* fMatrixEntry[9]; + QWidget fDetailTab; + QHBoxLayout fDetailLayout; + QTextEdit fDetailText; - QVBoxLayout* fClipLayout; - QLabel* fClipLabel; - QHBoxLayout* fClipRow[2]; - QLineEdit* fClipEntry[4]; + QWidget fMatrixAndClipWidget; + QVBoxLayout fVerticalLayout; - QVBoxLayout* currentMatrix(); - QVBoxLayout* currentClip(); + QLabel fMatrixLabel; + QVBoxLayout fMatrixLayout; + QHBoxLayout fMatrixRow[3]; + QLineEdit fMatrixEntry[9]; + + QLabel fClipLabel; + QVBoxLayout fClipLayout; + QHBoxLayout fClipRow[2]; + QLineEdit fClipEntry[4]; + + QVBoxLayout* setupMatrix(); + QVBoxLayout* setupClip(); }; #endif