blob: dc9dc6e45cea9c11fe2047353a4f89e0e5617a13 [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
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +000059 fPathOpsLabel.setText("PathOps: ");
60 fPathOpsLabel.setMinimumWidth(178);
61 fPathOpsLabel.setMaximumWidth(178);
62
chudy@google.comea5488b2012-07-26 19:38:22 +000063 fRasterCheckBox.setChecked(true);
64
robertphillips@google.comf4741c12013-02-06 20:13:54 +000065 fOverdrawVizLabel.setText(" Overdraw Viz: ");
66 fOverdrawVizLabel.setMinimumWidth(178);
67 fOverdrawVizLabel.setMaximumWidth(178);
68
commit-bot@chromium.org768ac852014-03-03 16:32:17 +000069 fMegaVizLabel.setText(" Mega Viz: ");
70 fMegaVizLabel.setMinimumWidth(178);
71 fMegaVizLabel.setMaximumWidth(178);
72
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000073#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +000074 fGLLabel.setText("OpenGL: ");
75 fGLLabel.setMinimumWidth(178);
76 fGLLabel.setMaximumWidth(178);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +000077
78 fGLMSAAButtonGroup.setTitle("MSAA");
79 fGLMSAAButtonGroup.setMinimumWidth(178);
80 fGLMSAAButtonGroup.setMaximumWidth(178);
81 fGLMSAAButtonGroup.setEnabled(fGLCheckBox.isChecked());
82
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000083 fGLMSAACombo.addItem("Off", QVariant(0));
84 fGLMSAACombo.addItem("4", QVariant(4));
85 fGLMSAACombo.addItem("16", QVariant(16));
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +000086
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000087 fGLMSAALayout.addWidget(&fGLMSAACombo);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +000088 fGLMSAAButtonGroup.setLayout(&fGLMSAALayout);
89
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000090 connect(&fGLCheckBox, SIGNAL(toggled(bool)), &fGLMSAAButtonGroup,
91 SLOT(setEnabled(bool)));
92 connect(&fGLCheckBox, SIGNAL(toggled(bool)), this,
93 SIGNAL(glSettingsChanged()));
94 connect(&fGLMSAACombo, SIGNAL(activated(int)), this,
95 SIGNAL(glSettingsChanged()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000096#endif
chudy@google.comea5488b2012-07-26 19:38:22 +000097
robertphillips@google.com32bbcf82013-10-17 17:56:10 +000098 {
99 // set up filter buttons
100 fFilterButtonGroup.setTitle("Filtering");
101 fFilterButtonGroup.setMinimumWidth(178);
102 fFilterButtonGroup.setMaximumWidth(178);
103
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000104 fFilterCombo.addItem("As encoded", QVariant(SkPaint::kNone_FilterLevel));
105 fFilterCombo.addItem("None", QVariant(SkPaint::kNone_FilterLevel));
106 fFilterCombo.addItem("Low", QVariant(SkPaint::kLow_FilterLevel));
107 fFilterCombo.addItem("Medium", QVariant(SkPaint::kMedium_FilterLevel));
108 fFilterCombo.addItem("High", QVariant(SkPaint::kHigh_FilterLevel));
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000109
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000110 fFilterLayout.addWidget(&fFilterCombo);
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000111 fFilterButtonGroup.setLayout(&fFilterLayout);
112
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000113 connect(&fFilterCombo, SIGNAL(activated(int)), this,
114 SIGNAL(texFilterSettingsChanged()));
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000115 }
116
chudy@google.comea5488b2012-07-26 19:38:22 +0000117 fRasterLayout.addWidget(&fRasterLabel);
118 fRasterLayout.addWidget(&fRasterCheckBox);
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000119 fRasterLayout.addWidget(&fPathOpsLabel);
120 fRasterLayout.addWidget(&fPathOpsCheckBox);
chudy@google.comea5488b2012-07-26 19:38:22 +0000121
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000122 fVizLayout.addWidget(&fOverdrawVizLabel);
123 fVizLayout.addWidget(&fOverdrawVizCheckBox);
124 fVizLayout.addWidget(&fMegaVizLabel);
125 fVizLayout.addWidget(&fMegaVizCheckBox);
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000126
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000127#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +0000128 fGLLayout.addWidget(&fGLLabel);
129 fGLLayout.addWidget(&fGLCheckBox);
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000130#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000131
132 fCanvasLayout.setSpacing(6);
133 fCanvasLayout.setContentsMargins(11,11,11,11);
chudy@google.comea5488b2012-07-26 19:38:22 +0000134 fCanvasLayout.addLayout(&fRasterLayout);
commit-bot@chromium.org768ac852014-03-03 16:32:17 +0000135 fCanvasLayout.addLayout(&fVizLayout);
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000136#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +0000137 fCanvasLayout.addLayout(&fGLLayout);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000138 fCanvasLayout.addWidget(&fGLMSAAButtonGroup);
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000139#endif
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000140 fCanvasLayout.addWidget(&fFilterButtonGroup);
chudy@google.comea5488b2012-07-26 19:38:22 +0000141
chudy@google.com7dcae672012-07-09 20:26:53 +0000142 // Command Toggle
143 fCommandToggle.setText("Command Scrolling Preferences");
144 fCommandFrame.setFrameShape(QFrame::StyledPanel);
145 fCommandFrame.setFrameShadow(QFrame::Raised);
chudy@google.com902ebe52012-06-29 14:21:22 +0000146
chudy@google.com7dcae672012-07-09 20:26:53 +0000147 fCurrentCommandLabel.setText("Current Command: ");
148 fCurrentCommandLabel.setMinimumWidth(178);
149 fCurrentCommandLabel.setMaximumWidth(178);
150 fCurrentCommandBox.setText("0");
151 fCurrentCommandBox.setMinimumSize(QSize(50,25));
152 fCurrentCommandBox.setMaximumSize(QSize(50,25));
153 fCurrentCommandBox.setAlignment(Qt::AlignRight);
chudy@google.com902ebe52012-06-29 14:21:22 +0000154
chudy@google.com7dcae672012-07-09 20:26:53 +0000155 fCurrentCommandLayout.setSpacing(0);
156 fCurrentCommandLayout.setContentsMargins(0,0,0,0);
157 fCurrentCommandLayout.setAlignment(Qt::AlignLeft);
158 fCurrentCommandLayout.addWidget(&fCurrentCommandLabel);
159 fCurrentCommandLayout.addWidget(&fCurrentCommandBox);
chudy@google.com902ebe52012-06-29 14:21:22 +0000160
chudy@google.come606d6e2012-07-12 14:31:25 +0000161 fCommandHitLabel.setText("Command HitBox: ");
162 fCommandHitLabel.setMinimumWidth(178);
163 fCommandHitLabel.setMaximumWidth(178);
164 fCommandHitBox.setText("0");
165 fCommandHitBox.setMinimumSize(QSize(50,25));
166 fCommandHitBox.setMaximumSize(QSize(50,25));
167 fCommandHitBox.setAlignment(Qt::AlignRight);
168 fCommandHitLayout.setSpacing(0);
169 fCommandHitLayout.setContentsMargins(0,0,0,0);
170 fCommandHitLayout.setAlignment(Qt::AlignLeft);
171 fCommandHitLayout.addWidget(&fCommandHitLabel);
172 fCommandHitLayout.addWidget(&fCommandHitBox);
173
chudy@google.com7dcae672012-07-09 20:26:53 +0000174 fCommandLayout.setSpacing(6);
175 fCommandLayout.setContentsMargins(11,11,11,11);
176 fCommandLayout.addLayout(&fCurrentCommandLayout);
chudy@google.come606d6e2012-07-12 14:31:25 +0000177 fCommandLayout.addLayout(&fCommandHitLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000178
chudy@google.com7dcae672012-07-09 20:26:53 +0000179 // Zoom Info
180 fZoomSetting.setText("Zoom Level: ");
181 fZoomSetting.setMinimumWidth(178);
182 fZoomSetting.setMaximumWidth(178);
183 fZoomFrame.setFrameShape(QFrame::StyledPanel);
184 fZoomFrame.setFrameShadow(QFrame::Raised);
185 fZoomBox.setText("100%");
186 fZoomBox.setMinimumSize(QSize(50,25));
187 fZoomBox.setMaximumSize(QSize(50,25));
188 fZoomBox.setAlignment(Qt::AlignRight);
189 fZoomLayout.setSpacing(6);
190 fZoomLayout.setContentsMargins(11,11,11,11);
191 fZoomLayout.addWidget(&fZoomSetting);
192 fZoomLayout.addWidget(&fZoomBox);
chudy@google.com902ebe52012-06-29 14:21:22 +0000193
chudy@google.com7dcae672012-07-09 20:26:53 +0000194 // Adds all widgets to settings container
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000195 fVerticalLayout.addWidget(&fVisibleText);
chudy@google.com7dcae672012-07-09 20:26:53 +0000196 fVerticalLayout.addWidget(&fVisibleFrame);
197 fVerticalLayout.addWidget(&fCommandToggle);
198 fVerticalLayout.addWidget(&fCommandFrame);
chudy@google.comea5488b2012-07-26 19:38:22 +0000199 fVerticalLayout.addWidget(&fCanvasToggle);
200 fVerticalLayout.addWidget(&fCanvasFrame);
chudy@google.com7dcae672012-07-09 20:26:53 +0000201 fVerticalLayout.addWidget(&fZoomFrame);
chudy@google.com902ebe52012-06-29 14:21:22 +0000202
chudy@google.come606d6e2012-07-12 14:31:25 +0000203 this->setDisabled(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000204}
205
chudy@google.com7dcae672012-07-09 20:26:53 +0000206
207void SkSettingsWidget::updateCommand(int newCommand) {
208 fCurrentCommandBox.setText(QString::number(newCommand));
209}
210
chudy@google.come606d6e2012-07-12 14:31:25 +0000211void SkSettingsWidget::updateHit(int newHit) {
212 fCommandHitBox.setText(QString::number(newHit));
213}
214
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000215void SkSettingsWidget::setZoomText(float scale) {
216 fZoomBox.setText(QString::number(scale*100, 'f', 0).append("%"));
chudy@google.com7dcae672012-07-09 20:26:53 +0000217}