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