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