blob: 6cf121241af07ad46bbd4564afb023d0390f2a3b [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)
chudy@google.com2f891792012-07-03 16:05:59 +000015 , fMatrixAndClipWidget(this)
16 , fVerticalLayout(&fMatrixAndClipWidget)
17 , fMatrixLabel(this)
18 , fClipLabel(this) {
chudy@google.com902ebe52012-06-29 14:21:22 +000019
chudy@google.com2f891792012-07-03 16:05:59 +000020 fHorizontalLayout.setSpacing(6);
21 fHorizontalLayout.setContentsMargins(11, 11, 11, 11);
chudy@google.com902ebe52012-06-29 14:21:22 +000022
chudy@google.com6bd109a2012-08-14 19:34:13 +000023 QString tabNames[kTotalTabCount];
24 tabNames[kOverview_TabType] = "Overview";
25 tabNames[kDetail_TabType] = "Details";
chudy@google.com902ebe52012-06-29 14:21:22 +000026
chudy@google.com6bd109a2012-08-14 19:34:13 +000027 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.com2f891792012-07-03 16:05:59 +000035
36 fHorizontalLayout.setAlignment(Qt::AlignTop);
37 fHorizontalLayout.addWidget(&fTabWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +000038
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.com6bd109a2012-08-14 19:34:13 +000043 * line edits in each horizontal layout. */
chudy@google.com2f891792012-07-03 16:05:59 +000044 fMatrixAndClipWidget.setFixedSize(260,300);
45 fMatrixAndClipWidget.setDisabled(true);
chudy@google.com902ebe52012-06-29 14:21:22 +000046
chudy@google.com2f891792012-07-03 16:05:59 +000047 fVerticalLayout.setAlignment(Qt::AlignVCenter);
48 fVerticalLayout.addLayout(setupMatrix());
49 fVerticalLayout.addLayout(setupClip());
50 fHorizontalLayout.addWidget(&fMatrixAndClipWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +000051}
52
chudy@google.com6bd109a2012-08-14 19:34:13 +000053void SkInspectorWidget::setText(QString text, TabType type) {
54 fTabTexts[type].setHtml(text);
chudy@google.com902ebe52012-06-29 14:21:22 +000055}
56
chudy@google.com2f891792012-07-03 16:05:59 +000057void 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
63void 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
70QVBoxLayout* 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.com902ebe52012-06-29 14:21:22 +000078
79 for(int i =0; i<9; i++) {
chudy@google.com2f891792012-07-03 16:05:59 +000080 fMatrixEntry[i].setMinimumSize(QSize(70,25));
81 fMatrixEntry[i].setMaximumSize(QSize(70,16777215));
82 fMatrixEntry[i].setReadOnly(true);
chudy@google.com902ebe52012-06-29 14:21:22 +000083
chudy@google.com2f891792012-07-03 16:05:59 +000084 fMatrixRow[i/3].addWidget(&fMatrixEntry[i]);
85 if(i%3 == 2) {
86 fMatrixLayout.addLayout(&fMatrixRow[i/3]);
87 }
chudy@google.com902ebe52012-06-29 14:21:22 +000088 }
89
chudy@google.com2f891792012-07-03 16:05:59 +000090 return &fMatrixLayout;
chudy@google.com902ebe52012-06-29 14:21:22 +000091}
92
chudy@google.com2f891792012-07-03 16:05:59 +000093QVBoxLayout* 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.com902ebe52012-06-29 14:21:22 +0000101
102 for(int i =0; i<4; i++) {
chudy@google.com2f891792012-07-03 16:05:59 +0000103 fClipEntry[i].setMinimumSize(QSize(70,25));
104 fClipEntry[i].setMaximumSize(QSize(70,16777215));
105 fClipEntry[i].setReadOnly(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000106
chudy@google.com2f891792012-07-03 16:05:59 +0000107 fClipRow[i/2].addWidget(&fClipEntry[i]);
108 if(i%2 == 1) {
109 fClipLayout.addLayout(&fClipRow[i/2]);
110 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000111 }
112
chudy@google.com2f891792012-07-03 16:05:59 +0000113 return &fClipLayout;
chudy@google.com902ebe52012-06-29 14:21:22 +0000114}