blob: 3f64e6f1a521912ec068b6326e011fec081f9f53 [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.com2f891792012-07-03 16:05:59 +000013SkInspectorWidget::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.com902ebe52012-06-29 14:21:22 +000024
chudy@google.com2f891792012-07-03 16:05:59 +000025 fHorizontalLayout.setSpacing(6);
26 fHorizontalLayout.setContentsMargins(11, 11, 11, 11);
chudy@google.com902ebe52012-06-29 14:21:22 +000027
chudy@google.com2f891792012-07-03 16:05:59 +000028 fOverviewLayout.setSpacing(6);
29 fOverviewLayout.setContentsMargins(11, 11, 11, 11);
chudy@google.com902ebe52012-06-29 14:21:22 +000030
chudy@google.com2f891792012-07-03 16:05:59 +000031 fOverviewText.setReadOnly(true);
32 fOverviewLayout.addWidget(&fOverviewText);
chudy@google.com902ebe52012-06-29 14:21:22 +000033
chudy@google.com2f891792012-07-03 16:05:59 +000034 fDetailLayout.setSpacing(6);
35 fDetailLayout.setContentsMargins(11,11,11,11);
chudy@google.com902ebe52012-06-29 14:21:22 +000036
chudy@google.com2f891792012-07-03 16:05:59 +000037 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.com902ebe52012-06-29 14:21:22 +000045
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.com2f891792012-07-03 16:05:59 +000053 fMatrixAndClipWidget.setFixedSize(260,300);
54 fMatrixAndClipWidget.setDisabled(true);
chudy@google.com902ebe52012-06-29 14:21:22 +000055
chudy@google.com2f891792012-07-03 16:05:59 +000056 fVerticalLayout.setAlignment(Qt::AlignVCenter);
57 fVerticalLayout.addLayout(setupMatrix());
58 fVerticalLayout.addLayout(setupClip());
59 fHorizontalLayout.addWidget(&fMatrixAndClipWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +000060}
61
62SkInspectorWidget::~SkInspectorWidget() {}
63
chudy@google.com902ebe52012-06-29 14:21:22 +000064void SkInspectorWidget::setDetailText(QString text) {
chudy@google.com2f891792012-07-03 16:05:59 +000065 fDetailText.setHtml(text);
chudy@google.com902ebe52012-06-29 14:21:22 +000066}
67
68void SkInspectorWidget::setOverviewText(QString text) {
chudy@google.com2f891792012-07-03 16:05:59 +000069 fOverviewText.setHtml(text);
chudy@google.com902ebe52012-06-29 14:21:22 +000070}
71
chudy@google.com2f891792012-07-03 16:05:59 +000072void 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
78void 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
85QVBoxLayout* 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.com902ebe52012-06-29 14:21:22 +000093
94 for(int i =0; i<9; i++) {
chudy@google.com2f891792012-07-03 16:05:59 +000095 fMatrixEntry[i].setMinimumSize(QSize(70,25));
96 fMatrixEntry[i].setMaximumSize(QSize(70,16777215));
97 fMatrixEntry[i].setReadOnly(true);
chudy@google.com902ebe52012-06-29 14:21:22 +000098
chudy@google.com2f891792012-07-03 16:05:59 +000099 fMatrixRow[i/3].addWidget(&fMatrixEntry[i]);
100 if(i%3 == 2) {
101 fMatrixLayout.addLayout(&fMatrixRow[i/3]);
102 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000103 }
104
chudy@google.com2f891792012-07-03 16:05:59 +0000105 return &fMatrixLayout;
chudy@google.com902ebe52012-06-29 14:21:22 +0000106}
107
chudy@google.com2f891792012-07-03 16:05:59 +0000108QVBoxLayout* 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.com902ebe52012-06-29 14:21:22 +0000116
117 for(int i =0; i<4; i++) {
chudy@google.com2f891792012-07-03 16:05:59 +0000118 fClipEntry[i].setMinimumSize(QSize(70,25));
119 fClipEntry[i].setMaximumSize(QSize(70,16777215));
120 fClipEntry[i].setReadOnly(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000121
chudy@google.com2f891792012-07-03 16:05:59 +0000122 fClipRow[i/2].addWidget(&fClipEntry[i]);
123 if(i%2 == 1) {
124 fClipLayout.addLayout(&fClipRow[i/2]);
125 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000126 }
127
chudy@google.com2f891792012-07-03 16:05:59 +0000128 return &fClipLayout;
chudy@google.com902ebe52012-06-29 14:21:22 +0000129}