• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2012 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #include "SkInspectorWidget.h"
11 #include <iostream>
12 
13 static const int kSignificantNumbersInFields = 5;
14 
SkInspectorWidget()15 SkInspectorWidget::SkInspectorWidget() : QWidget()
16     , fHorizontalLayout(this)
17     , fMatrixAndClipWidget(this)
18     , fVerticalLayout(&fMatrixAndClipWidget) {
19     QString tabNames[kTotalTabCount];
20     tabNames[kOverview_TabType] = "Overview";
21     tabNames[kDetail_TabType] = "Details";
22     tabNames[kClipStack_TabType] = "Clip Stack";
23 
24     for (int i = 0; i < kTotalTabCount; i++) {
25         fTabTexts[i].setReadOnly(true);
26         fTabLayouts[i].addWidget(&fTabTexts[i]);
27         fTabs[i].setLayout(&fTabLayouts[i]);
28         fTabWidget.addTab(&fTabs[i], tabNames[i]);
29     }
30 
31     fHorizontalLayout.setAlignment(Qt::AlignTop);
32     fHorizontalLayout.addWidget(&fTabWidget);
33 
34     fMatrixAndClipWidget.setFrameStyle(QFrame::Panel);
35     fMatrixAndClipWidget.setDisabled(true);
36     fVerticalLayout.setAlignment(Qt::AlignVCenter);
37     this->setupMatrix();
38     this->setupClip();
39     fVerticalLayout.addWidget(&fMatrixGroup);
40     fVerticalLayout.addWidget(&fClipGroup);
41     fHorizontalLayout.addWidget(&fMatrixAndClipWidget);
42 }
43 
setText(QString text,TabType type)44 void SkInspectorWidget::setText(QString text, TabType type) {
45     fTabTexts[type].setHtml(text);
46 }
47 
setMatrix(const SkMatrix & matrix)48 void SkInspectorWidget::setMatrix(const SkMatrix& matrix) {
49     for(int i=0; i<9; i++) {
50         fMatrixEntry[i].setText(QString::number(matrix.get(i), 'g', kSignificantNumbersInFields));
51     }
52 }
53 
setClip(const SkIRect & clip)54 void SkInspectorWidget::setClip(const SkIRect& clip) {
55     fClipEntry[0].setText(QString::number(clip.left(), 'g', kSignificantNumbersInFields));
56     fClipEntry[1].setText(QString::number(clip.top(), 'g', kSignificantNumbersInFields));
57     fClipEntry[2].setText(QString::number(clip.right(), 'g', kSignificantNumbersInFields));
58     fClipEntry[3].setText(QString::number(clip.bottom(), 'g', kSignificantNumbersInFields));
59 }
60 
setupMatrix()61 void SkInspectorWidget::setupMatrix() {
62     fMatrixGroup.setTitle("Current Matrix");
63     fMatrixGroup.setLayout(&fMatrixLayout);
64     for (int r = 0; r < 3; ++r) {
65         for(int c = 0; c < 3; c++) {
66             QLineEdit* entry = &fMatrixEntry[r * 3 + c];
67             fMatrixLayout.addWidget(entry, r, c, Qt::AlignTop | Qt::AlignHCenter);
68             entry->setReadOnly(true);
69             entry->setFixedWidth(70);
70         }
71     }
72 }
73 
setupClip()74 void SkInspectorWidget::setupClip() {
75     fClipGroup.setTitle("Current Clip");
76     fClipGroup.setLayout(&fClipLayout);
77     for(int r = 0; r < 2; r++) {
78         for(int c = 0; c < 2; c++) {
79             QLineEdit* entry = &fClipEntry[r * 2 + c];
80             fClipLayout.addWidget(entry, r, c, Qt::AlignTop | Qt::AlignHCenter);
81             entry->setReadOnly(true);
82             entry->setFixedWidth(70);
83         }
84     }
85 }
86