blob: dc40b40a9e42052ae51510af122c819950cc2ecc [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
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000065#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +000066 fGLLabel.setText("OpenGL: ");
67 fGLLabel.setMinimumWidth(178);
68 fGLLabel.setMaximumWidth(178);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +000069
70 fGLMSAAButtonGroup.setTitle("MSAA");
71 fGLMSAAButtonGroup.setMinimumWidth(178);
72 fGLMSAAButtonGroup.setMaximumWidth(178);
73 fGLMSAAButtonGroup.setEnabled(fGLCheckBox.isChecked());
74
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000075 fGLMSAACombo.addItem("Off", QVariant(0));
76 fGLMSAACombo.addItem("4", QVariant(4));
77 fGLMSAACombo.addItem("16", QVariant(16));
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +000078
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000079 fGLMSAALayout.addWidget(&fGLMSAACombo);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +000080 fGLMSAAButtonGroup.setLayout(&fGLMSAALayout);
81
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000082 connect(&fGLCheckBox, SIGNAL(toggled(bool)), &fGLMSAAButtonGroup,
83 SLOT(setEnabled(bool)));
84 connect(&fGLCheckBox, SIGNAL(toggled(bool)), this,
85 SIGNAL(glSettingsChanged()));
86 connect(&fGLMSAACombo, SIGNAL(activated(int)), this,
87 SIGNAL(glSettingsChanged()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000088#endif
chudy@google.comea5488b2012-07-26 19:38:22 +000089
robertphillips@google.com32bbcf82013-10-17 17:56:10 +000090 {
91 // set up filter buttons
92 fFilterButtonGroup.setTitle("Filtering");
93 fFilterButtonGroup.setMinimumWidth(178);
94 fFilterButtonGroup.setMaximumWidth(178);
95
commit-bot@chromium.org22d39332013-11-21 15:37:29 +000096 fFilterCombo.addItem("As encoded", QVariant(SkPaint::kNone_FilterLevel));
97 fFilterCombo.addItem("None", QVariant(SkPaint::kNone_FilterLevel));
98 fFilterCombo.addItem("Low", QVariant(SkPaint::kLow_FilterLevel));
99 fFilterCombo.addItem("Medium", QVariant(SkPaint::kMedium_FilterLevel));
100 fFilterCombo.addItem("High", QVariant(SkPaint::kHigh_FilterLevel));
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000101
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000102 fFilterLayout.addWidget(&fFilterCombo);
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000103 fFilterButtonGroup.setLayout(&fFilterLayout);
104
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000105 connect(&fFilterCombo, SIGNAL(activated(int)), this,
106 SIGNAL(texFilterSettingsChanged()));
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000107 }
108
chudy@google.comea5488b2012-07-26 19:38:22 +0000109 fRasterLayout.addWidget(&fRasterLabel);
110 fRasterLayout.addWidget(&fRasterCheckBox);
111
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000112 fOverdrawVizLayout.addWidget(&fOverdrawVizLabel);
113 fOverdrawVizLayout.addWidget(&fOverdrawVizCheckBox);
114
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000115#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +0000116 fGLLayout.addWidget(&fGLLabel);
117 fGLLayout.addWidget(&fGLCheckBox);
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000118#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000119
120 fCanvasLayout.setSpacing(6);
121 fCanvasLayout.setContentsMargins(11,11,11,11);
chudy@google.comea5488b2012-07-26 19:38:22 +0000122 fCanvasLayout.addLayout(&fRasterLayout);
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000123 fCanvasLayout.addLayout(&fOverdrawVizLayout);
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000124#if SK_SUPPORT_GPU
chudy@google.comea5488b2012-07-26 19:38:22 +0000125 fCanvasLayout.addLayout(&fGLLayout);
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000126 fCanvasLayout.addWidget(&fGLMSAAButtonGroup);
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000127#endif
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000128 fCanvasLayout.addWidget(&fFilterButtonGroup);
chudy@google.comea5488b2012-07-26 19:38:22 +0000129
chudy@google.com7dcae672012-07-09 20:26:53 +0000130 // Command Toggle
131 fCommandToggle.setText("Command Scrolling Preferences");
132 fCommandFrame.setFrameShape(QFrame::StyledPanel);
133 fCommandFrame.setFrameShadow(QFrame::Raised);
chudy@google.com902ebe52012-06-29 14:21:22 +0000134
chudy@google.com7dcae672012-07-09 20:26:53 +0000135 fCurrentCommandLabel.setText("Current Command: ");
136 fCurrentCommandLabel.setMinimumWidth(178);
137 fCurrentCommandLabel.setMaximumWidth(178);
138 fCurrentCommandBox.setText("0");
139 fCurrentCommandBox.setMinimumSize(QSize(50,25));
140 fCurrentCommandBox.setMaximumSize(QSize(50,25));
141 fCurrentCommandBox.setAlignment(Qt::AlignRight);
chudy@google.com902ebe52012-06-29 14:21:22 +0000142
chudy@google.com7dcae672012-07-09 20:26:53 +0000143 fCurrentCommandLayout.setSpacing(0);
144 fCurrentCommandLayout.setContentsMargins(0,0,0,0);
145 fCurrentCommandLayout.setAlignment(Qt::AlignLeft);
146 fCurrentCommandLayout.addWidget(&fCurrentCommandLabel);
147 fCurrentCommandLayout.addWidget(&fCurrentCommandBox);
chudy@google.com902ebe52012-06-29 14:21:22 +0000148
chudy@google.come606d6e2012-07-12 14:31:25 +0000149 fCommandHitLabel.setText("Command HitBox: ");
150 fCommandHitLabel.setMinimumWidth(178);
151 fCommandHitLabel.setMaximumWidth(178);
152 fCommandHitBox.setText("0");
153 fCommandHitBox.setMinimumSize(QSize(50,25));
154 fCommandHitBox.setMaximumSize(QSize(50,25));
155 fCommandHitBox.setAlignment(Qt::AlignRight);
156 fCommandHitLayout.setSpacing(0);
157 fCommandHitLayout.setContentsMargins(0,0,0,0);
158 fCommandHitLayout.setAlignment(Qt::AlignLeft);
159 fCommandHitLayout.addWidget(&fCommandHitLabel);
160 fCommandHitLayout.addWidget(&fCommandHitBox);
161
chudy@google.com7dcae672012-07-09 20:26:53 +0000162 fCommandLayout.setSpacing(6);
163 fCommandLayout.setContentsMargins(11,11,11,11);
164 fCommandLayout.addLayout(&fCurrentCommandLayout);
chudy@google.come606d6e2012-07-12 14:31:25 +0000165 fCommandLayout.addLayout(&fCommandHitLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000166
chudy@google.com7dcae672012-07-09 20:26:53 +0000167 // Zoom Info
168 fZoomSetting.setText("Zoom Level: ");
169 fZoomSetting.setMinimumWidth(178);
170 fZoomSetting.setMaximumWidth(178);
171 fZoomFrame.setFrameShape(QFrame::StyledPanel);
172 fZoomFrame.setFrameShadow(QFrame::Raised);
173 fZoomBox.setText("100%");
174 fZoomBox.setMinimumSize(QSize(50,25));
175 fZoomBox.setMaximumSize(QSize(50,25));
176 fZoomBox.setAlignment(Qt::AlignRight);
177 fZoomLayout.setSpacing(6);
178 fZoomLayout.setContentsMargins(11,11,11,11);
179 fZoomLayout.addWidget(&fZoomSetting);
180 fZoomLayout.addWidget(&fZoomBox);
chudy@google.com902ebe52012-06-29 14:21:22 +0000181
chudy@google.com7dcae672012-07-09 20:26:53 +0000182 // Adds all widgets to settings container
commit-bot@chromium.org22d39332013-11-21 15:37:29 +0000183 fVerticalLayout.addWidget(&fVisibleText);
chudy@google.com7dcae672012-07-09 20:26:53 +0000184 fVerticalLayout.addWidget(&fVisibleFrame);
185 fVerticalLayout.addWidget(&fCommandToggle);
186 fVerticalLayout.addWidget(&fCommandFrame);
chudy@google.comea5488b2012-07-26 19:38:22 +0000187 fVerticalLayout.addWidget(&fCanvasToggle);
188 fVerticalLayout.addWidget(&fCanvasFrame);
chudy@google.com7dcae672012-07-09 20:26:53 +0000189 fVerticalLayout.addWidget(&fZoomFrame);
chudy@google.com902ebe52012-06-29 14:21:22 +0000190
chudy@google.come606d6e2012-07-12 14:31:25 +0000191 this->setDisabled(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000192}
193
chudy@google.com7dcae672012-07-09 20:26:53 +0000194
195void SkSettingsWidget::updateCommand(int newCommand) {
196 fCurrentCommandBox.setText(QString::number(newCommand));
197}
198
chudy@google.come606d6e2012-07-12 14:31:25 +0000199void SkSettingsWidget::updateHit(int newHit) {
200 fCommandHitBox.setText(QString::number(newHit));
201}
202
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000203void SkSettingsWidget::setZoomText(float scale) {
204 fZoomBox.setText(QString::number(scale*100, 'f', 0).append("%"));
chudy@google.com7dcae672012-07-09 20:26:53 +0000205}