Refactored inspector widget such that creating custom tabs for information is straigh...
authorchudy@google.com <chudy@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 14 Aug 2012 19:34:13 +0000 (19:34 +0000)
committerchudy@google.com <chudy@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 14 Aug 2012 19:34:13 +0000 (19:34 +0000)
Review URL: https://codereview.appspot.com/6463046

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

debugger/QT/SkDebuggerGUI.cpp
debugger/QT/SkInspectorWidget.cpp
debugger/QT/SkInspectorWidget.h

index 6075df0..f5c78d6 100644 (file)
@@ -310,7 +310,7 @@ void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
                     info.append(QString((*currInfo)[i]->c_str()));
                     info.append("<br/>");
                 }
-                fInspectorWidget.setDetailText(info);
+                fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
                 fInspectorWidget.setDisabled(false);
             }
         }
@@ -649,7 +649,7 @@ void SkDebuggerGUI::setupComboBox(SkTDArray<SkString*>* command) {
     overview.append("SkPicture Height: ");
     overview.append(QString::number(fDebugger.pictureHeight()));
     overview.append("px");
-    fInspectorWidget.setOverviewText(overview);
+    fInspectorWidget.setText(overview, SkInspectorWidget::kOverview_TabType);
 
     // NOTE(chudy): Makes first item unselectable.
     QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
index e09c25b..6cf1212 100644 (file)
 
 SkInspectorWidget::SkInspectorWidget() : QWidget()
     , fHorizontalLayout(this)
-    , fOverviewTab()
-    , fOverviewLayout(&fOverviewTab)
-    , fDetailTab()
-    , fDetailLayout(&fDetailTab)
     , fMatrixAndClipWidget(this)
     , fVerticalLayout(&fMatrixAndClipWidget)
     , fMatrixLabel(this)
@@ -24,20 +20,18 @@ SkInspectorWidget::SkInspectorWidget() : QWidget()
     fHorizontalLayout.setSpacing(6);
     fHorizontalLayout.setContentsMargins(11, 11, 11, 11);
 
-    fOverviewLayout.setSpacing(6);
-    fOverviewLayout.setContentsMargins(11, 11, 11, 11);
-
-    fOverviewText.setReadOnly(true);
-    fOverviewLayout.addWidget(&fOverviewText);
-
-    fDetailLayout.setSpacing(6);
-    fDetailLayout.setContentsMargins(11,11,11,11);
-
-    fDetailText.setReadOnly(true);
-    fDetailLayout.addWidget(&fDetailText);
-
-    fTabWidget.addTab(&fOverviewTab, QString("Overview"));
-    fTabWidget.addTab(&fDetailTab, QString("Details"));
+    QString tabNames[kTotalTabCount];
+    tabNames[kOverview_TabType] = "Overview";
+    tabNames[kDetail_TabType] = "Details";
+
+    for (int i = 0; i < kTotalTabCount; i++) {
+        fTabTexts[i].setReadOnly(true);
+        fTabLayouts[i].setSpacing(6);
+        fTabLayouts[i].setContentsMargins(11, 11, 11, 11);
+        fTabLayouts[i].addWidget(&fTabTexts[i]);
+        fTabs[i].setLayout(&fTabLayouts[i]);
+        fTabWidget.addTab(&fTabs[i], tabNames[i]);
+    }
 
     fHorizontalLayout.setAlignment(Qt::AlignTop);
     fHorizontalLayout.addWidget(&fTabWidget);
@@ -46,9 +40,7 @@ SkInspectorWidget::SkInspectorWidget() : QWidget()
      * by adding them to horizontal layouts.
      *
      * We will have 1 big vertical layout, 3 horizontal layouts and then 3
-     * line edits in each horizontal layout.
-     */
-
+     * line edits in each horizontal layout. */
     fMatrixAndClipWidget.setFixedSize(260,300);
     fMatrixAndClipWidget.setDisabled(true);
 
@@ -58,12 +50,8 @@ SkInspectorWidget::SkInspectorWidget() : QWidget()
     fHorizontalLayout.addWidget(&fMatrixAndClipWidget);
 }
 
-void SkInspectorWidget::setDetailText(QString text) {
-    fDetailText.setHtml(text);
-}
-
-void SkInspectorWidget::setOverviewText(QString text) {
-    fOverviewText.setHtml(text);
+void SkInspectorWidget::setText(QString text, TabType type) {
+    fTabTexts[type].setHtml(text);
 }
 
 void SkInspectorWidget::setMatrix(const SkMatrix& matrix) {
index 78a8344..1b96235 100644 (file)
@@ -28,6 +28,12 @@ class SkInspectorWidget : public QWidget {
     Q_OBJECT
 
 public:
+    enum TabType {
+        kOverview_TabType,
+        kDetail_TabType,
+        kTotalTabCount,
+    };
+
     /**
         Constructs a widget with the specified parent for layout purposes.
         @param parent  The parent container of this widget
@@ -37,17 +43,12 @@ public:
     void setDisabled(bool isDisabled) {
         fMatrixAndClipWidget.setDisabled(isDisabled);
     }
-    /**
-        Sets the text in the detail tab.
-        @param text
-     */
-    void setDetailText(QString text);
 
     /**
-        Sets the text in the overview tab.
+        Sets the text in tab at the specified index.
         @param text
      */
-    void setOverviewText(QString text);
+    void setText(QString text, TabType type);
 
     /**
         Sets the text in the current matrix.
@@ -61,17 +62,29 @@ public:
      */
     void setClip(const SkIRect& clip);
 
+    class Tab : public QWidget {
+        QWidget fTab;
+        QHBoxLayout fTabLayout;
+        QTextEdit fTabText;
+        QString fName;
+
+        Tab(const char* name) {
+            fTabText.setReadOnly(true);
+            fTabLayout.setSpacing(6);
+            fTabLayout.setContentsMargins(11, 11, 11, 11);
+            fTabLayout.addWidget(&fTabText);
+            fTab.setLayout(&fTabLayout);
+            fName = QString(name);
+        }
+    };
+
 private:
     QHBoxLayout fHorizontalLayout;
     QTabWidget fTabWidget;
 
-    QWidget fOverviewTab;
-    QHBoxLayout fOverviewLayout;
-    QTextEdit fOverviewText;
-
-    QWidget fDetailTab;
-    QHBoxLayout fDetailLayout;
-    QTextEdit fDetailText;
+    QWidget fTabs[kTotalTabCount];
+    QHBoxLayout fTabLayouts[kTotalTabCount];
+    QTextEdit fTabTexts[kTotalTabCount];
 
     QWidget fMatrixAndClipWidget;
     QVBoxLayout fVerticalLayout;