blob: fa619eafe501e251ae0becb5a3793856169870d8 [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 "SkSettingsWidget.h"
chudy@google.com7dcae672012-07-09 20:26:53 +000011#include <iostream>
12#include <math.h>
chudy@google.com902ebe52012-06-29 14:21:22 +000013
chudy@google.comea5488b2012-07-26 19:38:22 +000014// TODO(chudy): See if the layout can't be attached to the frame post construction.
chudy@google.com2d537a12012-07-31 12:49:52 +000015SkSettingsWidget::SkSettingsWidget() : QWidget()
chudy@google.com7dcae672012-07-09 20:26:53 +000016 , mainFrameLayout(this)
17 , fVerticalLayout(&mainFrame)
18 , fVisibleFrameLayout(&fVisibleFrame)
19 , fVisibleOn(&fVisibleFrame)
20 , fVisibleOff(&fVisibleFrame)
21 , fCommandLayout(&fCommandFrame)
22 , fCurrentCommandBox(&fCommandFrame)
chudy@google.come606d6e2012-07-12 14:31:25 +000023 , fCommandHitBox(&fCommandFrame)
chudy@google.comea5488b2012-07-26 19:38:22 +000024 , fCanvasLayout(&fCanvasFrame)
chudy@google.com7dcae672012-07-09 20:26:53 +000025 , fZoomLayout(&fZoomFrame)
chudy@google.com2d537a12012-07-31 12:49:52 +000026 , fZoomBox(&fZoomFrame)
chudy@google.com7dcae672012-07-09 20:26:53 +000027{
28 // Sets up the container and it's alignment around the settings widget.
29 mainFrame.setFrameShape(QFrame::StyledPanel);
30 mainFrame.setFrameShadow(QFrame::Raised);
31 mainFrameLayout.setSpacing(6);
32 mainFrameLayout.setContentsMargins(0,0,0,0);
33 mainFrameLayout.addWidget(&mainFrame);
chudy@google.com902ebe52012-06-29 14:21:22 +000034
chudy@google.com7dcae672012-07-09 20:26:53 +000035 // Vertical Layout is the alignment inside of the main frame.
36 fVerticalLayout.setContentsMargins(11,11,11,11);
37 fVerticalLayout.setAlignment(Qt::AlignTop);
chudy@google.com902ebe52012-06-29 14:21:22 +000038
chudy@google.com7dcae672012-07-09 20:26:53 +000039 // Visible Toggle
40 fVisibileText.setText("Visibility Filter");
41 fVisibleFrame.setFrameShape(QFrame::StyledPanel);
42 fVisibleFrame.setFrameShadow(QFrame::Raised);
43 fVisibleOn.setText("On");
44 fVisibleOff.setText("Off");
45 fVisibleOff.setChecked(true);
46 fVisibleFrameLayout.setSpacing(6);
47 fVisibleFrameLayout.setContentsMargins(11,11,11,11);
48 fVisibleFrameLayout.addWidget(&fVisibleOn);
49 fVisibleFrameLayout.addWidget(&fVisibleOff);
chudy@google.com902ebe52012-06-29 14:21:22 +000050
chudy@google.comea5488b2012-07-26 19:38:22 +000051 // Canvas
52 fCanvasToggle.setText("Render Targets");
53 fCanvasFrame.setFrameShape(QFrame::StyledPanel);
54 fCanvasFrame.setFrameShadow(QFrame::Raised);
55
56 fRasterLabel.setText("Raster: ");
57 fRasterLabel.setMinimumWidth(178);
58 fRasterLabel.setMaximumWidth(178);
59
60 fRasterCheckBox.setChecked(true);
61
robertphillips@google.comf4741c12013-02-06 20:13:54 +000062 fOverdrawVizLabel.setText(" Overdraw Viz: ");
63 fOverdrawVizLabel.setMinimumWidth(178);
64 fOverdrawVizLabel.setMaximumWidth(178);
65
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000066#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +000067 fGLLabel.setText("OpenGL: ");
68 fGLLabel.setMinimumWidth(178);
69 fGLLabel.setMaximumWidth(178);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +000070
71 fGLMSAAButtonGroup.setTitle("MSAA");
72 fGLMSAAButtonGroup.setMinimumWidth(178);
73 fGLMSAAButtonGroup.setMaximumWidth(178);
74 fGLMSAAButtonGroup.setEnabled(fGLCheckBox.isChecked());
75
76 fGLMSAAOff.setText("Off");
77 fGLMSAA4On.setText("4");
78 fGLMSAA4On.setChecked(true);
79 fGLMSAA16On.setText("16");
80
81 fGLMSAALayout.addWidget(&fGLMSAAOff);
82 fGLMSAALayout.addWidget(&fGLMSAA4On);
83 fGLMSAALayout.addWidget(&fGLMSAA16On);
84
85 fGLMSAAButtonGroup.setLayout(&fGLMSAALayout);
86
87 connect(&fGLCheckBox, SIGNAL(toggled(bool)), &fGLMSAAButtonGroup, SLOT(setEnabled(bool)));
88 connect(&fGLCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(glSettingsChanged()));
89 connect(&fGLMSAAOff, SIGNAL(toggled(bool)), this, SIGNAL(glSettingsChanged()));
90 connect(&fGLMSAA4On, SIGNAL(toggled(bool)), this, SIGNAL(glSettingsChanged()));
91 connect(&fGLMSAA16On, SIGNAL(toggled(bool)), this, SIGNAL(glSettingsChanged()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000092#endif
chudy@google.comea5488b2012-07-26 19:38:22 +000093
94 fRasterLayout.addWidget(&fRasterLabel);
95 fRasterLayout.addWidget(&fRasterCheckBox);
96
robertphillips@google.comf4741c12013-02-06 20:13:54 +000097 fOverdrawVizLayout.addWidget(&fOverdrawVizLabel);
98 fOverdrawVizLayout.addWidget(&fOverdrawVizCheckBox);
99
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000100#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +0000101 fGLLayout.addWidget(&fGLLabel);
102 fGLLayout.addWidget(&fGLCheckBox);
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000103#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000104
105 fCanvasLayout.setSpacing(6);
106 fCanvasLayout.setContentsMargins(11,11,11,11);
chudy@google.comea5488b2012-07-26 19:38:22 +0000107 fCanvasLayout.addLayout(&fRasterLayout);
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000108 fCanvasLayout.addLayout(&fOverdrawVizLayout);
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000109#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +0000110 fCanvasLayout.addLayout(&fGLLayout);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000111 fCanvasLayout.addWidget(&fGLMSAAButtonGroup);
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000112#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000113
chudy@google.com7dcae672012-07-09 20:26:53 +0000114 // Command Toggle
115 fCommandToggle.setText("Command Scrolling Preferences");
116 fCommandFrame.setFrameShape(QFrame::StyledPanel);
117 fCommandFrame.setFrameShadow(QFrame::Raised);
chudy@google.com902ebe52012-06-29 14:21:22 +0000118
chudy@google.com7dcae672012-07-09 20:26:53 +0000119 fCurrentCommandLabel.setText("Current Command: ");
120 fCurrentCommandLabel.setMinimumWidth(178);
121 fCurrentCommandLabel.setMaximumWidth(178);
122 fCurrentCommandBox.setText("0");
123 fCurrentCommandBox.setMinimumSize(QSize(50,25));
124 fCurrentCommandBox.setMaximumSize(QSize(50,25));
125 fCurrentCommandBox.setAlignment(Qt::AlignRight);
chudy@google.com902ebe52012-06-29 14:21:22 +0000126
chudy@google.com7dcae672012-07-09 20:26:53 +0000127 fCurrentCommandLayout.setSpacing(0);
128 fCurrentCommandLayout.setContentsMargins(0,0,0,0);
129 fCurrentCommandLayout.setAlignment(Qt::AlignLeft);
130 fCurrentCommandLayout.addWidget(&fCurrentCommandLabel);
131 fCurrentCommandLayout.addWidget(&fCurrentCommandBox);
chudy@google.com902ebe52012-06-29 14:21:22 +0000132
chudy@google.come606d6e2012-07-12 14:31:25 +0000133 fCommandHitLabel.setText("Command HitBox: ");
134 fCommandHitLabel.setMinimumWidth(178);
135 fCommandHitLabel.setMaximumWidth(178);
136 fCommandHitBox.setText("0");
137 fCommandHitBox.setMinimumSize(QSize(50,25));
138 fCommandHitBox.setMaximumSize(QSize(50,25));
139 fCommandHitBox.setAlignment(Qt::AlignRight);
140 fCommandHitLayout.setSpacing(0);
141 fCommandHitLayout.setContentsMargins(0,0,0,0);
142 fCommandHitLayout.setAlignment(Qt::AlignLeft);
143 fCommandHitLayout.addWidget(&fCommandHitLabel);
144 fCommandHitLayout.addWidget(&fCommandHitBox);
145
chudy@google.com7dcae672012-07-09 20:26:53 +0000146 fCommandLayout.setSpacing(6);
147 fCommandLayout.setContentsMargins(11,11,11,11);
148 fCommandLayout.addLayout(&fCurrentCommandLayout);
chudy@google.come606d6e2012-07-12 14:31:25 +0000149 fCommandLayout.addLayout(&fCommandHitLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000150
chudy@google.com7dcae672012-07-09 20:26:53 +0000151 // Zoom Info
152 fZoomSetting.setText("Zoom Level: ");
153 fZoomSetting.setMinimumWidth(178);
154 fZoomSetting.setMaximumWidth(178);
155 fZoomFrame.setFrameShape(QFrame::StyledPanel);
156 fZoomFrame.setFrameShadow(QFrame::Raised);
157 fZoomBox.setText("100%");
158 fZoomBox.setMinimumSize(QSize(50,25));
159 fZoomBox.setMaximumSize(QSize(50,25));
160 fZoomBox.setAlignment(Qt::AlignRight);
161 fZoomLayout.setSpacing(6);
162 fZoomLayout.setContentsMargins(11,11,11,11);
163 fZoomLayout.addWidget(&fZoomSetting);
164 fZoomLayout.addWidget(&fZoomBox);
chudy@google.com902ebe52012-06-29 14:21:22 +0000165
chudy@google.com7dcae672012-07-09 20:26:53 +0000166 // Adds all widgets to settings container
167 fVerticalLayout.addWidget(&fVisibileText);
168 fVerticalLayout.addWidget(&fVisibleFrame);
169 fVerticalLayout.addWidget(&fCommandToggle);
170 fVerticalLayout.addWidget(&fCommandFrame);
chudy@google.comea5488b2012-07-26 19:38:22 +0000171 fVerticalLayout.addWidget(&fCanvasToggle);
172 fVerticalLayout.addWidget(&fCanvasFrame);
chudy@google.com7dcae672012-07-09 20:26:53 +0000173 fVerticalLayout.addWidget(&fZoomFrame);
chudy@google.com902ebe52012-06-29 14:21:22 +0000174
chudy@google.come606d6e2012-07-12 14:31:25 +0000175 this->setDisabled(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000176}
177
chudy@google.com7dcae672012-07-09 20:26:53 +0000178
179void SkSettingsWidget::updateCommand(int newCommand) {
180 fCurrentCommandBox.setText(QString::number(newCommand));
181}
182
chudy@google.come606d6e2012-07-12 14:31:25 +0000183void SkSettingsWidget::updateHit(int newHit) {
184 fCommandHitBox.setText(QString::number(newHit));
185}
186
chudy@google.com7dcae672012-07-09 20:26:53 +0000187QRadioButton* SkSettingsWidget::getVisibilityButton() {
188 return &fVisibleOn;
189}
190
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000191void SkSettingsWidget::setZoomText(float scale) {
192 fZoomBox.setText(QString::number(scale*100, 'f', 0).append("%"));
chudy@google.com7dcae672012-07-09 20:26:53 +0000193}