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