blob: ca0436e18271394d03b8513fb1dbfac4644c60e3 [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
robertphillips@google.com32bbcf82013-10-17 17:56:10 +000094 {
95 // set up filter buttons
96 fFilterButtonGroup.setTitle("Filtering");
97 fFilterButtonGroup.setMinimumWidth(178);
98 fFilterButtonGroup.setMaximumWidth(178);
99
100 fFilterDefault.setText("As encoded");
101 fFilterDefault.setChecked(true);
102 fFilterNone.setText("None");
103 fFilterLow.setText("Low");
104 fFilterMed.setText("Med");
105 fFilterHigh.setText("High");
106
107 fFilterLayout.addWidget(&fFilterDefault);
108 fFilterLayout.addWidget(&fFilterNone);
109 fFilterLayout.addWidget(&fFilterLow);
110 fFilterLayout.addWidget(&fFilterMed);
111 fFilterLayout.addWidget(&fFilterHigh);
112
113 fFilterButtonGroup.setLayout(&fFilterLayout);
114
115 connect(&fFilterDefault, SIGNAL(toggled(bool)), this, SIGNAL(texFilterSettingsChanged()));
116 connect(&fFilterNone, SIGNAL(toggled(bool)), this, SIGNAL(texFilterSettingsChanged()));
117 connect(&fFilterLow, SIGNAL(toggled(bool)), this, SIGNAL(texFilterSettingsChanged()));
118 connect(&fFilterMed, SIGNAL(toggled(bool)), this, SIGNAL(texFilterSettingsChanged()));
119 connect(&fFilterHigh, SIGNAL(toggled(bool)), this, SIGNAL(texFilterSettingsChanged()));
120 }
121
chudy@google.comea5488b2012-07-26 19:38:22 +0000122 fRasterLayout.addWidget(&fRasterLabel);
123 fRasterLayout.addWidget(&fRasterCheckBox);
124
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000125 fOverdrawVizLayout.addWidget(&fOverdrawVizLabel);
126 fOverdrawVizLayout.addWidget(&fOverdrawVizCheckBox);
127
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000128#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +0000129 fGLLayout.addWidget(&fGLLabel);
130 fGLLayout.addWidget(&fGLCheckBox);
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000131#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000132
133 fCanvasLayout.setSpacing(6);
134 fCanvasLayout.setContentsMargins(11,11,11,11);
chudy@google.comea5488b2012-07-26 19:38:22 +0000135 fCanvasLayout.addLayout(&fRasterLayout);
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000136 fCanvasLayout.addLayout(&fOverdrawVizLayout);
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000137#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +0000138 fCanvasLayout.addLayout(&fGLLayout);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000139 fCanvasLayout.addWidget(&fGLMSAAButtonGroup);
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000140#endif
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000141 fCanvasLayout.addWidget(&fFilterButtonGroup);
chudy@google.comea5488b2012-07-26 19:38:22 +0000142
chudy@google.com7dcae672012-07-09 20:26:53 +0000143 // Command Toggle
144 fCommandToggle.setText("Command Scrolling Preferences");
145 fCommandFrame.setFrameShape(QFrame::StyledPanel);
146 fCommandFrame.setFrameShadow(QFrame::Raised);
chudy@google.com902ebe52012-06-29 14:21:22 +0000147
chudy@google.com7dcae672012-07-09 20:26:53 +0000148 fCurrentCommandLabel.setText("Current Command: ");
149 fCurrentCommandLabel.setMinimumWidth(178);
150 fCurrentCommandLabel.setMaximumWidth(178);
151 fCurrentCommandBox.setText("0");
152 fCurrentCommandBox.setMinimumSize(QSize(50,25));
153 fCurrentCommandBox.setMaximumSize(QSize(50,25));
154 fCurrentCommandBox.setAlignment(Qt::AlignRight);
chudy@google.com902ebe52012-06-29 14:21:22 +0000155
chudy@google.com7dcae672012-07-09 20:26:53 +0000156 fCurrentCommandLayout.setSpacing(0);
157 fCurrentCommandLayout.setContentsMargins(0,0,0,0);
158 fCurrentCommandLayout.setAlignment(Qt::AlignLeft);
159 fCurrentCommandLayout.addWidget(&fCurrentCommandLabel);
160 fCurrentCommandLayout.addWidget(&fCurrentCommandBox);
chudy@google.com902ebe52012-06-29 14:21:22 +0000161
chudy@google.come606d6e2012-07-12 14:31:25 +0000162 fCommandHitLabel.setText("Command HitBox: ");
163 fCommandHitLabel.setMinimumWidth(178);
164 fCommandHitLabel.setMaximumWidth(178);
165 fCommandHitBox.setText("0");
166 fCommandHitBox.setMinimumSize(QSize(50,25));
167 fCommandHitBox.setMaximumSize(QSize(50,25));
168 fCommandHitBox.setAlignment(Qt::AlignRight);
169 fCommandHitLayout.setSpacing(0);
170 fCommandHitLayout.setContentsMargins(0,0,0,0);
171 fCommandHitLayout.setAlignment(Qt::AlignLeft);
172 fCommandHitLayout.addWidget(&fCommandHitLabel);
173 fCommandHitLayout.addWidget(&fCommandHitBox);
174
chudy@google.com7dcae672012-07-09 20:26:53 +0000175 fCommandLayout.setSpacing(6);
176 fCommandLayout.setContentsMargins(11,11,11,11);
177 fCommandLayout.addLayout(&fCurrentCommandLayout);
chudy@google.come606d6e2012-07-12 14:31:25 +0000178 fCommandLayout.addLayout(&fCommandHitLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000179
chudy@google.com7dcae672012-07-09 20:26:53 +0000180 // Zoom Info
181 fZoomSetting.setText("Zoom Level: ");
182 fZoomSetting.setMinimumWidth(178);
183 fZoomSetting.setMaximumWidth(178);
184 fZoomFrame.setFrameShape(QFrame::StyledPanel);
185 fZoomFrame.setFrameShadow(QFrame::Raised);
186 fZoomBox.setText("100%");
187 fZoomBox.setMinimumSize(QSize(50,25));
188 fZoomBox.setMaximumSize(QSize(50,25));
189 fZoomBox.setAlignment(Qt::AlignRight);
190 fZoomLayout.setSpacing(6);
191 fZoomLayout.setContentsMargins(11,11,11,11);
192 fZoomLayout.addWidget(&fZoomSetting);
193 fZoomLayout.addWidget(&fZoomBox);
chudy@google.com902ebe52012-06-29 14:21:22 +0000194
chudy@google.com7dcae672012-07-09 20:26:53 +0000195 // Adds all widgets to settings container
196 fVerticalLayout.addWidget(&fVisibileText);
197 fVerticalLayout.addWidget(&fVisibleFrame);
198 fVerticalLayout.addWidget(&fCommandToggle);
199 fVerticalLayout.addWidget(&fCommandFrame);
chudy@google.comea5488b2012-07-26 19:38:22 +0000200 fVerticalLayout.addWidget(&fCanvasToggle);
201 fVerticalLayout.addWidget(&fCanvasFrame);
chudy@google.com7dcae672012-07-09 20:26:53 +0000202 fVerticalLayout.addWidget(&fZoomFrame);
chudy@google.com902ebe52012-06-29 14:21:22 +0000203
chudy@google.come606d6e2012-07-12 14:31:25 +0000204 this->setDisabled(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000205}
206
chudy@google.com7dcae672012-07-09 20:26:53 +0000207
208void SkSettingsWidget::updateCommand(int newCommand) {
209 fCurrentCommandBox.setText(QString::number(newCommand));
210}
211
chudy@google.come606d6e2012-07-12 14:31:25 +0000212void SkSettingsWidget::updateHit(int newHit) {
213 fCommandHitBox.setText(QString::number(newHit));
214}
215
chudy@google.com7dcae672012-07-09 20:26:53 +0000216QRadioButton* SkSettingsWidget::getVisibilityButton() {
217 return &fVisibleOn;
218}
219
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000220void SkSettingsWidget::setZoomText(float scale) {
221 fZoomBox.setText(QString::number(scale*100, 'f', 0).append("%"));
chudy@google.com7dcae672012-07-09 20:26:53 +0000222}