blob: e09c25bb8def78bc88328a261120abb5453038bf [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001
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.com2d537a12012-07-31 12:49:52 +000013SkInspectorWidget::SkInspectorWidget() : QWidget()
chudy@google.com2f891792012-07-03 16:05:59 +000014 , 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.com902ebe52012-06-29 14:21:22 +000023
chudy@google.com2f891792012-07-03 16:05:59 +000024 fHorizontalLayout.setSpacing(6);
25 fHorizontalLayout.setContentsMargins(11, 11, 11, 11);
chudy@google.com902ebe52012-06-29 14:21:22 +000026
chudy@google.com2f891792012-07-03 16:05:59 +000027 fOverviewLayout.setSpacing(6);
28 fOverviewLayout.setContentsMargins(11, 11, 11, 11);
chudy@google.com902ebe52012-06-29 14:21:22 +000029
chudy@google.com2f891792012-07-03 16:05:59 +000030 fOverviewText.setReadOnly(true);
31 fOverviewLayout.addWidget(&fOverviewText);
chudy@google.com902ebe52012-06-29 14:21:22 +000032
chudy@google.com2f891792012-07-03 16:05:59 +000033 fDetailLayout.setSpacing(6);
34 fDetailLayout.setContentsMargins(11,11,11,11);
chudy@google.com902ebe52012-06-29 14:21:22 +000035
chudy@google.com2f891792012-07-03 16:05:59 +000036 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.com902ebe52012-06-29 14:21:22 +000044
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.com2f891792012-07-03 16:05:59 +000052 fMatrixAndClipWidget.setFixedSize(260,300);
53 fMatrixAndClipWidget.setDisabled(true);
chudy@google.com902ebe52012-06-29 14:21:22 +000054
chudy@google.com2f891792012-07-03 16:05:59 +000055 fVerticalLayout.setAlignment(Qt::AlignVCenter);
56 fVerticalLayout.addLayout(setupMatrix());
57 fVerticalLayout.addLayout(setupClip());
58 fHorizontalLayout.addWidget(&fMatrixAndClipWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +000059}
60
chudy@google.com902ebe52012-06-29 14:21:22 +000061void SkInspectorWidget::setDetailText(QString text) {
chudy@google.com2f891792012-07-03 16:05:59 +000062 fDetailText.setHtml(text);
chudy@google.com902ebe52012-06-29 14:21:22 +000063}
64
65void SkInspectorWidget::setOverviewText(QString text) {
chudy@google.com2f891792012-07-03 16:05:59 +000066 fOverviewText.setHtml(text);
chudy@google.com902ebe52012-06-29 14:21:22 +000067}
68
chudy@google.com2f891792012-07-03 16:05:59 +000069void 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
75void 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
82QVBoxLayout* 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.com902ebe52012-06-29 14:21:22 +000090
91 for(int i =0; i<9; i++) {
chudy@google.com2f891792012-07-03 16:05:59 +000092 fMatrixEntry[i].setMinimumSize(QSize(70,25));
93 fMatrixEntry[i].setMaximumSize(QSize(70,16777215));
94 fMatrixEntry[i].setReadOnly(true);
chudy@google.com902ebe52012-06-29 14:21:22 +000095
chudy@google.com2f891792012-07-03 16:05:59 +000096 fMatrixRow[i/3].addWidget(&fMatrixEntry[i]);
97 if(i%3 == 2) {
98 fMatrixLayout.addLayout(&fMatrixRow[i/3]);
99 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000100 }
101
chudy@google.com2f891792012-07-03 16:05:59 +0000102 return &fMatrixLayout;
chudy@google.com902ebe52012-06-29 14:21:22 +0000103}
104
chudy@google.com2f891792012-07-03 16:05:59 +0000105QVBoxLayout* 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.com902ebe52012-06-29 14:21:22 +0000113
114 for(int i =0; i<4; i++) {
chudy@google.com2f891792012-07-03 16:05:59 +0000115 fClipEntry[i].setMinimumSize(QSize(70,25));
116 fClipEntry[i].setMaximumSize(QSize(70,16777215));
117 fClipEntry[i].setReadOnly(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000118
chudy@google.com2f891792012-07-03 16:05:59 +0000119 fClipRow[i/2].addWidget(&fClipEntry[i]);
120 if(i%2 == 1) {
121 fClipLayout.addLayout(&fClipRow[i/2]);
122 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000123 }
124
chudy@google.com2f891792012-07-03 16:05:59 +0000125 return &fClipLayout;
chudy@google.com902ebe52012-06-29 14:21:22 +0000126}