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 13SkInspectorWidget::SkInspectorWidget() : QWidget() 14 , fHorizontalLayout(this) 15 , fMatrixAndClipWidget(this) 16 , fVerticalLayout(&fMatrixAndClipWidget) 17 , fMatrixLabel(this) 18 , fClipLabel(this) { 19 20 fHorizontalLayout.setSpacing(6); 21 fHorizontalLayout.setContentsMargins(11, 11, 11, 11); 22 23 QString tabNames[kTotalTabCount]; 24 tabNames[kOverview_TabType] = "Overview"; 25 tabNames[kDetail_TabType] = "Details"; 26 tabNames[kClipStack_TabType] = "Clip Stack"; 27 28 for (int i = 0; i < kTotalTabCount; i++) { 29 fTabTexts[i].setReadOnly(true); 30 fTabLayouts[i].setSpacing(6); 31 fTabLayouts[i].setContentsMargins(11, 11, 11, 11); 32 fTabLayouts[i].addWidget(&fTabTexts[i]); 33 fTabs[i].setLayout(&fTabLayouts[i]); 34 fTabWidget.addTab(&fTabs[i], tabNames[i]); 35 } 36 37 fHorizontalLayout.setAlignment(Qt::AlignTop); 38 fHorizontalLayout.addWidget(&fTabWidget); 39 40 /* NOTE(chudy): We add all the line edits to (this). Then we lay them out 41 * by adding them to horizontal layouts. 42 * 43 * We will have 1 big vertical layout, 3 horizontal layouts and then 3 44 * line edits in each horizontal layout. */ 45 fMatrixAndClipWidget.setFixedSize(260,300); 46 fMatrixAndClipWidget.setDisabled(true); 47 48 fVerticalLayout.setAlignment(Qt::AlignVCenter); 49 fVerticalLayout.addLayout(setupMatrix()); 50 fVerticalLayout.addLayout(setupClip()); 51 fHorizontalLayout.addWidget(&fMatrixAndClipWidget); 52} 53 54void SkInspectorWidget::setText(QString text, TabType type) { 55 fTabTexts[type].setHtml(text); 56} 57 58void SkInspectorWidget::setMatrix(const SkMatrix& matrix) { 59 for(int i=0; i<9; i++) { 60 fMatrixEntry[i].setText(QString::number(matrix.get(i))); 61 } 62} 63 64void SkInspectorWidget::setClip(const SkIRect& clip) { 65 fClipEntry[0].setText(QString::number(clip.left())); 66 fClipEntry[1].setText(QString::number(clip.top())); 67 fClipEntry[2].setText(QString::number(clip.right())); 68 fClipEntry[3].setText(QString::number(clip.bottom())); 69} 70 71QVBoxLayout* SkInspectorWidget::setupMatrix() { 72 fMatrixLabel.setText("Current Matrix"); 73 fMatrixLabel.setAlignment(Qt::AlignHCenter); 74 75 fMatrixLayout.setSpacing(6); 76 fMatrixLayout.setContentsMargins(11,11,11,0); 77 fMatrixLayout.setAlignment(Qt::AlignTop | Qt::AlignHCenter); 78 fMatrixLayout.addWidget(&fMatrixLabel); 79 80 for(int i =0; i<9; i++) { 81 fMatrixEntry[i].setMinimumSize(QSize(70,25)); 82 fMatrixEntry[i].setMaximumSize(QSize(70,16777215)); 83 fMatrixEntry[i].setReadOnly(true); 84 85 fMatrixRow[i/3].addWidget(&fMatrixEntry[i]); 86 if(i%3 == 2) { 87 fMatrixLayout.addLayout(&fMatrixRow[i/3]); 88 } 89 } 90 91 return &fMatrixLayout; 92} 93 94QVBoxLayout* SkInspectorWidget::setupClip() { 95 fClipLabel.setText("Current Clip"); 96 fClipLabel.setAlignment(Qt::AlignHCenter); 97 98 fClipLayout.setSpacing(6); 99 fClipLayout.setContentsMargins(11,11,11,0); 100 fClipLayout.setAlignment(Qt::AlignTop | Qt::AlignHCenter); 101 fClipLayout.addWidget(&fClipLabel); 102 103 for(int i =0; i<4; i++) { 104 fClipEntry[i].setMinimumSize(QSize(70,25)); 105 fClipEntry[i].setMaximumSize(QSize(70,16777215)); 106 fClipEntry[i].setReadOnly(true); 107 108 fClipRow[i/2].addWidget(&fClipEntry[i]); 109 if(i%2 == 1) { 110 fClipLayout.addLayout(&fClipRow[i/2]); 111 } 112 } 113 114 return &fClipLayout; 115} 116