Skia Debugger can now save modified pictures.
authorchudy@google.com <chudy@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Sat, 28 Jul 2012 20:16:11 +0000 (20:16 +0000)
committerchudy@google.com <chudy@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Sat, 28 Jul 2012 20:16:11 +0000 (20:16 +0000)
Review URL: https://codereview.appspot.com/6442055

git-svn-id: http://skia.googlecode.com/svn/trunk@4821 2bbb7eff-a529-9590-31e7-b0007b416f81

debugger/QT/SkDebuggerGUI.cpp
debugger/QT/SkDebuggerGUI.h
debugger/QT/moc_SkDebuggerGUI.cpp
debugger/SkDebugCanvas.cpp

index 823fffc..830f0f6 100644 (file)
@@ -25,6 +25,8 @@ SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
     , fActionPlay(this)
     , fActionPause(this)
     , fActionRewind(this)
+    , fActionSave(this)
+    , fActionSaveAs(this)
     , fActionShowDeletes(this)
     , fActionStepBack(this)
     , fActionStepForward(this)
@@ -78,6 +80,8 @@ SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
     connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
     connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
     connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
+    connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
+    connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
 
     fMapper.setMapping(&fActionZoomIn, 1);
     fMapper.setMapping(&fActionZoomOut, -1);
@@ -202,6 +206,23 @@ void SkDebuggerGUI::actionRewind() {
     fListWidget.setCurrentRow(0);
 }
 
+void SkDebuggerGUI::actionSave() {
+    QString filename;
+    filename.append(fPath);
+    filename.append("/");
+    filename.append(fDirectoryWidget.currentItem()->text());
+    saveToFile(filename);
+}
+
+void SkDebuggerGUI::actionSaveAs() {
+    QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
+            "Skia Picture (*skp)");
+    if (!filename.endsWith(".skp", Qt::CaseInsensitive))
+        filename.append(".skp");
+    }
+    saveToFile(filename);
+}
+
 void SkDebuggerGUI::actionScale(float scaleFactor) {
     fSettingsWidget.setZoomText(scaleFactor);
 }
@@ -230,6 +251,15 @@ void SkDebuggerGUI::actionStepForward() {
     }
 }
 
+void SkDebuggerGUI::saveToFile(QString filename) {
+    SkFILEWStream file(filename.toAscii());
+    SkPicture picture;
+    SkCanvas* canvas = picture.beginRecording(100,100);
+    fCanvasWidget.getCurrentDebugCanvas()->draw(canvas);
+    picture.endRecording();
+    picture.serialize(&file);
+}
+
 void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
     if (fDirectoryWidgetActive) {
         QString fileName;
@@ -406,6 +436,13 @@ void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
     fActionRewind.setIcon(rewind);
     fActionRewind.setText("Rewind");
 
+    fActionSave.setShortcut(QKeySequence::Save);
+    fActionSave.setText("Save");
+    fActionSave.setDisabled(true);
+    fActionSaveAs.setShortcut(QKeySequence::SaveAs);
+    fActionSaveAs.setText("Save As");
+    fActionSaveAs.setDisabled(true);
+
     fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
     fActionShowDeletes.setText("Deleted Commands");
 
@@ -472,8 +509,7 @@ void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
     fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
     SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
 
-    QWidget *spacer = new QWidget();
-    spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+    fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
     fToolBar.addAction(&fActionRewind);
     fToolBar.addAction(&fActionStepBack);
@@ -483,7 +519,7 @@ void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
     fToolBar.addSeparator();
     fToolBar.addAction(&fActionInspector);
     fToolBar.addSeparator();
-    fToolBar.addWidget(spacer);
+    fToolBar.addWidget(&fSpacer);
     fToolBar.addWidget(&fFilter);
     fToolBar.addAction(&fActionCancel);
 
@@ -496,6 +532,8 @@ void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
     // Menu Bar
     fMenuFile.setTitle("File");
     fMenuFile.addAction(&fActionOpen);
+    fMenuFile.addAction(&fActionSave);
+    fMenuFile.addAction(&fActionSaveAs);
     fMenuFile.addAction(&fActionClose);
 
     fMenuEdit.setTitle("Edit");
@@ -563,6 +601,8 @@ void SkDebuggerGUI::loadPicture(QString fileName) {
     fMenuEdit.setDisabled(false);
     fMenuNavigate.setDisabled(false);
     fMenuView.setDisabled(false);
+    fActionSave.setDisabled(false);
+    fActionSaveAs.setDisabled(false);
     fLoading = false;
     actionPlay();
 }
index fcbf3b7..3e4d319 100644 (file)
@@ -117,6 +117,16 @@ private slots:
     void actionRewind();
 
     /**
+        Saves the current SKP with all modifications.
+     */
+    void actionSave();
+
+    /**
+        Saves the current SKP under a different name and/or location.
+     */
+    void actionSaveAs();
+
+    /**
         Sends the scale factor information to the settings widget.
      */
     void actionScale(float scaleFactor);
@@ -199,6 +209,8 @@ private:
     QAction fActionPlay;
     QAction fActionPause;
     QAction fActionRewind;
+    QAction fActionSave;
+    QAction fActionSaveAs;
     QAction fActionShowDeletes;
     QAction fActionStepBack;
     QAction fActionStepForward;
@@ -206,7 +218,7 @@ private:
     QAction fActionZoomOut;
     QSignalMapper fMapper;
     QWidget fCentralWidget;
-
+    QWidget fSpacer;
     QComboBox fFilter;
 
     QVBoxLayout fLeftColumnLayout;
@@ -251,6 +263,11 @@ private:
     void loadPicture(QString fileName);
 
     /**
+        Creates a picture of the current canvas.
+     */
+    void saveToFile(QString filename);
+
+    /**
         Populates the list widget with the vector of strings passed in.
      */
     void setupListWidget(std::vector<std::string>* cv);
index cb1e571..0d207aa 100644 (file)
@@ -1,7 +1,7 @@
 /****************************************************************************
 ** Meta object code from reading C++ file 'SkDebuggerGUI.h'
 **
-** Created: Wed Jul 25 15:04:14 2012
+** Created: Thu Jul 26 16:33:10 2012
 **      by: The Qt Meta Object Compiler version 62 (Qt 4.6.2)
 **
 ** WARNING! All changes made in this file will be lost!
@@ -23,7 +23,7 @@ static const uint qt_meta_data_SkDebuggerGUI[] = {
        4,       // revision
        0,       // classname
        0,    0, // classinfo
-      27,   14, // methods
+      29,   14, // methods
        0,    0, // properties
        0,    0, // enums/sets
        0,    0, // constructors
@@ -46,20 +46,22 @@ static const uint qt_meta_data_SkDebuggerGUI[] = {
      224,   14,   14,   14, 0x08,
      237,  175,   14,   14, 0x08,
      262,   14,   14,   14, 0x08,
-     289,  277,   14,   14, 0x08,
-     308,   14,   14,   14, 0x08,
-     325,   14,   14,   14, 0x08,
-     342,   14,   14,   14, 0x08,
-     367,  362,   14,   14, 0x08,
-     394,   14,   14,   14, 0x08,
-     414,  405,   14,   14, 0x08,
-     433,   14,   14,   14, 0x28,
-     448,  362,   14,   14, 0x08,
-     484,   15,   14,   14, 0x08,
-     503,   14,   14,   14, 0x08,
-     517,   14,   14,   14, 0x08,
-     536,   14,   14,   14, 0x08,
-     561,  554,   14,   14, 0x08,
+     277,   14,   14,   14, 0x08,
+     290,   14,   14,   14, 0x08,
+     317,  305,   14,   14, 0x08,
+     336,   14,   14,   14, 0x08,
+     353,   14,   14,   14, 0x08,
+     370,   14,   14,   14, 0x08,
+     395,  390,   14,   14, 0x08,
+     422,   14,   14,   14, 0x08,
+     442,  433,   14,   14, 0x08,
+     461,   14,   14,   14, 0x28,
+     476,  390,   14,   14, 0x08,
+     512,   15,   14,   14, 0x08,
+     531,   14,   14,   14, 0x08,
+     545,   14,   14,   14, 0x08,
+     564,   14,   14,   14, 0x08,
+     589,  582,   14,   14, 0x08,
 
        0        // eod
 };
@@ -69,15 +71,15 @@ static const char qt_meta_stringdata_SkDebuggerGUI[] = {
     "actionBreakpoints()\0actionCancel()\0"
     "actionClearBreakpoints()\0actionClearDeletes()\0"
     "actionCommandFilter()\0actionClose()\0"
-    "actionDelete()\0setHidden\0actionGLWidget(bool)\0"
+    "actionDelete()\0isToggled\0actionGLWidget(bool)\0"
     "actionInspector()\0actionPlay()\0"
     "actionRasterWidget(bool)\0actionRewind()\0"
-    "scaleFactor\0actionScale(float)\0"
-    "actionSettings()\0actionStepBack()\0"
-    "actionStepForward()\0item\0"
-    "loadFile(QListWidgetItem*)\0openFile()\0"
-    "isPaused\0pauseDrawing(bool)\0pauseDrawing()\0"
-    "registerListClick(QListWidgetItem*)\0"
+    "actionSave()\0actionSaveAs()\0scaleFactor\0"
+    "actionScale(float)\0actionSettings()\0"
+    "actionStepBack()\0actionStepForward()\0"
+    "item\0loadFile(QListWidgetItem*)\0"
+    "openFile()\0isPaused\0pauseDrawing(bool)\0"
+    "pauseDrawing()\0registerListClick(QListWidgetItem*)\0"
     "selectCommand(int)\0showDeletes()\0"
     "toggleBreakpoint()\0toggleDirectory()\0"
     "string\0toggleFilter(QString)\0"
@@ -125,23 +127,25 @@ int SkDebuggerGUI::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
         case 10: actionPlay(); break;
         case 11: actionRasterWidget((*reinterpret_cast< bool(*)>(_a[1]))); break;
         case 12: actionRewind(); break;
-        case 13: actionScale((*reinterpret_cast< float(*)>(_a[1]))); break;
-        case 14: actionSettings(); break;
-        case 15: actionStepBack(); break;
-        case 16: actionStepForward(); break;
-        case 17: loadFile((*reinterpret_cast< QListWidgetItem*(*)>(_a[1]))); break;
-        case 18: openFile(); break;
-        case 19: pauseDrawing((*reinterpret_cast< bool(*)>(_a[1]))); break;
-        case 20: pauseDrawing(); break;
-        case 21: registerListClick((*reinterpret_cast< QListWidgetItem*(*)>(_a[1]))); break;
-        case 22: selectCommand((*reinterpret_cast< int(*)>(_a[1]))); break;
-        case 23: showDeletes(); break;
-        case 24: toggleBreakpoint(); break;
-        case 25: toggleDirectory(); break;
-        case 26: toggleFilter((*reinterpret_cast< QString(*)>(_a[1]))); break;
+        case 13: actionSave(); break;
+        case 14: actionSaveAs(); break;
+        case 15: actionScale((*reinterpret_cast< float(*)>(_a[1]))); break;
+        case 16: actionSettings(); break;
+        case 17: actionStepBack(); break;
+        case 18: actionStepForward(); break;
+        case 19: loadFile((*reinterpret_cast< QListWidgetItem*(*)>(_a[1]))); break;
+        case 20: openFile(); break;
+        case 21: pauseDrawing((*reinterpret_cast< bool(*)>(_a[1]))); break;
+        case 22: pauseDrawing(); break;
+        case 23: registerListClick((*reinterpret_cast< QListWidgetItem*(*)>(_a[1]))); break;
+        case 24: selectCommand((*reinterpret_cast< int(*)>(_a[1]))); break;
+        case 25: showDeletes(); break;
+        case 26: toggleBreakpoint(); break;
+        case 27: toggleDirectory(); break;
+        case 28: toggleFilter((*reinterpret_cast< QString(*)>(_a[1]))); break;
         default: ;
         }
-        _id -= 27;
+        _id -= 29;
     }
     return _id;
 }
index c5f0c2d..9510e65 100644 (file)
@@ -29,7 +29,9 @@ void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) {
 void SkDebugCanvas::draw(SkCanvas* canvas) {
     if(!commandVector.empty()) {
         for(it = commandVector.begin(); it != commandVector.end(); ++it) {
-            (*it)->execute(canvas);
+            if ((*it)->getVisibility()) {
+                (*it)->execute(canvas);
+            }
         }
     }
 }