blob: 29026cf07c17052e1188b5d6b4e11a7f7254d927 [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)
chudy@google.com7dcae672012-07-09 20:26:53 +000019 , fCommandLayout(&fCommandFrame)
20 , fCurrentCommandBox(&fCommandFrame)
chudy@google.come606d6e2012-07-12 14:31:25 +000021 , fCommandHitBox(&fCommandFrame)
chudy@google.comea5488b2012-07-26 19:38:22 +000022 , fCanvasLayout(&fCanvasFrame)
chudy@google.com7dcae672012-07-09 20:26:53 +000023 , fZoomLayout(&fZoomFrame)
chudy@google.com2d537a12012-07-31 12:49:52 +000024 , fZoomBox(&fZoomFrame)
chudy@google.com7dcae672012-07-09 20:26:53 +000025{
26 // Sets up the container and it's alignment around the settings widget.
27 mainFrame.setFrameShape(QFrame::StyledPanel);
28 mainFrame.setFrameShadow(QFrame::Raised);
29 mainFrameLayout.setSpacing(6);
30 mainFrameLayout.setContentsMargins(0,0,0,0);
31 mainFrameLayout.addWidget(&mainFrame);
chudy@google.com902ebe52012-06-29 14:21:22 +000032
chudy@google.com7dcae672012-07-09 20:26:53 +000033 // Vertical Layout is the alignment inside of the main frame.
34 fVerticalLayout.setContentsMargins(11,11,11,11);
35 fVerticalLayout.setAlignment(Qt::AlignTop);
chudy@google.com902ebe52012-06-29 14:21:22 +000036
chudy@google.com7dcae672012-07-09 20:26:53 +000037 // Visible Toggle
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000038 fVisibleText.setText("Visibility Filter");
chudy@google.com7dcae672012-07-09 20:26:53 +000039 fVisibleFrame.setFrameShape(QFrame::StyledPanel);
40 fVisibleFrame.setFrameShadow(QFrame::Raised);
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000041
42 fVisibilityCombo.addItem("Off", QVariant(false));
43 fVisibilityCombo.addItem("On", QVariant(true));
44
45 fVisibleFrameLayout.setContentsMargins(11, 5, 11, 5);
46 fVisibleFrameLayout.addWidget(&fVisibilityCombo);
47 connect(&fVisibilityCombo, SIGNAL(activated(int)), this,
48 SIGNAL(visibilityFilterChanged()));
chudy@google.com902ebe52012-06-29 14:21:22 +000049
chudy@google.comea5488b2012-07-26 19:38:22 +000050 // Canvas
51 fCanvasToggle.setText("Render Targets");
52 fCanvasFrame.setFrameShape(QFrame::StyledPanel);
53 fCanvasFrame.setFrameShadow(QFrame::Raised);
54
55 fRasterLabel.setText("Raster: ");
56 fRasterLabel.setMinimumWidth(178);
57 fRasterLabel.setMaximumWidth(178);
58
59 fRasterCheckBox.setChecked(true);
60
robertphillips@google.comf4741c12013-02-06 20:13:54 +000061 fOverdrawVizLabel.setText(" Overdraw Viz: ");
62 fOverdrawVizLabel.setMinimumWidth(178);
63 fOverdrawVizLabel.setMaximumWidth(178);
64
commit-bot@chromium.org768ac852014-03-03 16:32:17 +000065 fMegaVizLabel.setText(" Mega Viz: ");
66 fMegaVizLabel.setMinimumWidth(178);
67 fMegaVizLabel.setMaximumWidth(178);
68
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000069#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +000070 fGLLabel.setText("OpenGL: ");
71 fGLLabel.setMinimumWidth(178);
72 fGLLabel.setMaximumWidth(178);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +000073
74 fGLMSAAButtonGroup.setTitle("MSAA");
75 fGLMSAAButtonGroup.setMinimumWidth(178);
76 fGLMSAAButtonGroup.setMaximumWidth(178);
77 fGLMSAAButtonGroup.setEnabled(fGLCheckBox.isChecked());
78
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000079 fGLMSAACombo.addItem("Off", QVariant(0));
80 fGLMSAACombo.addItem("4", QVariant(4));
81 fGLMSAACombo.addItem("16", QVariant(16));
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +000082
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000083 fGLMSAALayout.addWidget(&fGLMSAACombo);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +000084 fGLMSAAButtonGroup.setLayout(&fGLMSAALayout);
85
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000086 connect(&fGLCheckBox, SIGNAL(toggled(bool)), &fGLMSAAButtonGroup,
87 SLOT(setEnabled(bool)));
88 connect(&fGLCheckBox, SIGNAL(toggled(bool)), this,
89 SIGNAL(glSettingsChanged()));
90 connect(&fGLMSAACombo, SIGNAL(activated(int)), this,
91 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
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000100 fFilterCombo.addItem("As encoded", QVariant(SkPaint::kNone_FilterLevel));
101 fFilterCombo.addItem("None", QVariant(SkPaint::kNone_FilterLevel));
102 fFilterCombo.addItem("Low", QVariant(SkPaint::kLow_FilterLevel));
103 fFilterCombo.addItem("Medium", QVariant(SkPaint::kMedium_FilterLevel));
104 fFilterCombo.addItem("High", QVariant(SkPaint::kHigh_FilterLevel));
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000105
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000106 fFilterLayout.addWidget(&fFilterCombo);
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000107 fFilterButtonGroup.setLayout(&fFilterLayout);
108
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000109 connect(&fFilterCombo, SIGNAL(activated(int)), this,
110 SIGNAL(texFilterSettingsChanged()));
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000111 }
112
chudy@google.comea5488b2012-07-26 19:38:22 +0000113 fRasterLayout.addWidget(&fRasterLabel);
114 fRasterLayout.addWidget(&fRasterCheckBox);
115
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000116 fVizLayout.addWidget(&fOverdrawVizLabel);
117 fVizLayout.addWidget(&fOverdrawVizCheckBox);
118 fVizLayout.addWidget(&fMegaVizLabel);
119 fVizLayout.addWidget(&fMegaVizCheckBox);
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000120
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000121#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +0000122 fGLLayout.addWidget(&fGLLabel);
123 fGLLayout.addWidget(&fGLCheckBox);
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000124#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000125
126 fCanvasLayout.setSpacing(6);
127 fCanvasLayout.setContentsMargins(11,11,11,11);
chudy@google.comea5488b2012-07-26 19:38:22 +0000128 fCanvasLayout.addLayout(&fRasterLayout);
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000129 fCanvasLayout.addLayout(&fVizLayout);
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000130#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +0000131 fCanvasLayout.addLayout(&fGLLayout);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000132 fCanvasLayout.addWidget(&fGLMSAAButtonGroup);
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000133#endif
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000134 fCanvasLayout.addWidget(&fFilterButtonGroup);
chudy@google.comea5488b2012-07-26 19:38:22 +0000135
chudy@google.com7dcae672012-07-09 20:26:53 +0000136 // Command Toggle
137 fCommandToggle.setText("Command Scrolling Preferences");
138 fCommandFrame.setFrameShape(QFrame::StyledPanel);
139 fCommandFrame.setFrameShadow(QFrame::Raised);
chudy@google.com902ebe52012-06-29 14:21:22 +0000140
chudy@google.com7dcae672012-07-09 20:26:53 +0000141 fCurrentCommandLabel.setText("Current Command: ");
142 fCurrentCommandLabel.setMinimumWidth(178);
143 fCurrentCommandLabel.setMaximumWidth(178);
144 fCurrentCommandBox.setText("0");
145 fCurrentCommandBox.setMinimumSize(QSize(50,25));
146 fCurrentCommandBox.setMaximumSize(QSize(50,25));
147 fCurrentCommandBox.setAlignment(Qt::AlignRight);
chudy@google.com902ebe52012-06-29 14:21:22 +0000148
chudy@google.com7dcae672012-07-09 20:26:53 +0000149 fCurrentCommandLayout.setSpacing(0);
150 fCurrentCommandLayout.setContentsMargins(0,0,0,0);
151 fCurrentCommandLayout.setAlignment(Qt::AlignLeft);
152 fCurrentCommandLayout.addWidget(&fCurrentCommandLabel);
153 fCurrentCommandLayout.addWidget(&fCurrentCommandBox);
chudy@google.com902ebe52012-06-29 14:21:22 +0000154
chudy@google.come606d6e2012-07-12 14:31:25 +0000155 fCommandHitLabel.setText("Command HitBox: ");
156 fCommandHitLabel.setMinimumWidth(178);
157 fCommandHitLabel.setMaximumWidth(178);
158 fCommandHitBox.setText("0");
159 fCommandHitBox.setMinimumSize(QSize(50,25));
160 fCommandHitBox.setMaximumSize(QSize(50,25));
161 fCommandHitBox.setAlignment(Qt::AlignRight);
162 fCommandHitLayout.setSpacing(0);
163 fCommandHitLayout.setContentsMargins(0,0,0,0);
164 fCommandHitLayout.setAlignment(Qt::AlignLeft);
165 fCommandHitLayout.addWidget(&fCommandHitLabel);
166 fCommandHitLayout.addWidget(&fCommandHitBox);
167
chudy@google.com7dcae672012-07-09 20:26:53 +0000168 fCommandLayout.setSpacing(6);
169 fCommandLayout.setContentsMargins(11,11,11,11);
170 fCommandLayout.addLayout(&fCurrentCommandLayout);
chudy@google.come606d6e2012-07-12 14:31:25 +0000171 fCommandLayout.addLayout(&fCommandHitLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000172
chudy@google.com7dcae672012-07-09 20:26:53 +0000173 // Zoom Info
174 fZoomSetting.setText("Zoom Level: ");
175 fZoomSetting.setMinimumWidth(178);
176 fZoomSetting.setMaximumWidth(178);
177 fZoomFrame.setFrameShape(QFrame::StyledPanel);
178 fZoomFrame.setFrameShadow(QFrame::Raised);
179 fZoomBox.setText("100%");
180 fZoomBox.setMinimumSize(QSize(50,25));
181 fZoomBox.setMaximumSize(QSize(50,25));
182 fZoomBox.setAlignment(Qt::AlignRight);
183 fZoomLayout.setSpacing(6);
184 fZoomLayout.setContentsMargins(11,11,11,11);
185 fZoomLayout.addWidget(&fZoomSetting);
186 fZoomLayout.addWidget(&fZoomBox);
chudy@google.com902ebe52012-06-29 14:21:22 +0000187
chudy@google.com7dcae672012-07-09 20:26:53 +0000188 // Adds all widgets to settings container
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000189 fVerticalLayout.addWidget(&fVisibleText);
chudy@google.com7dcae672012-07-09 20:26:53 +0000190 fVerticalLayout.addWidget(&fVisibleFrame);
191 fVerticalLayout.addWidget(&fCommandToggle);
192 fVerticalLayout.addWidget(&fCommandFrame);
chudy@google.comea5488b2012-07-26 19:38:22 +0000193 fVerticalLayout.addWidget(&fCanvasToggle);
194 fVerticalLayout.addWidget(&fCanvasFrame);
chudy@google.com7dcae672012-07-09 20:26:53 +0000195 fVerticalLayout.addWidget(&fZoomFrame);
chudy@google.com902ebe52012-06-29 14:21:22 +0000196
chudy@google.come606d6e2012-07-12 14:31:25 +0000197 this->setDisabled(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000198}
199
chudy@google.com7dcae672012-07-09 20:26:53 +0000200
201void SkSettingsWidget::updateCommand(int newCommand) {
202 fCurrentCommandBox.setText(QString::number(newCommand));
203}
204
chudy@google.come606d6e2012-07-12 14:31:25 +0000205void SkSettingsWidget::updateHit(int newHit) {
206 fCommandHitBox.setText(QString::number(newHit));
207}
208
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000209void SkSettingsWidget::setZoomText(float scale) {
210 fZoomBox.setText(QString::number(scale*100, 'f', 0).append("%"));
chudy@google.com7dcae672012-07-09 20:26:53 +0000211}