blob: bc37a12ac0cb2c4a389e59dec55ebec12b8cb203 [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.com7dcae672012-07-09 20:26:53 +000015SkSettingsWidget::SkSettingsWidget(QWidget *parent) : QWidget(parent)
16 , 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 , fZoomBox(&fZoomFrame)
26 , fZoomLayout(&fZoomFrame)
27{
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
62 fGLLabel.setText("OpenGL: ");
63 fGLLabel.setMinimumWidth(178);
64 fGLLabel.setMaximumWidth(178);
65
66 fRasterLayout.addWidget(&fRasterLabel);
67 fRasterLayout.addWidget(&fRasterCheckBox);
68
69 fGLLayout.addWidget(&fGLLabel);
70 fGLLayout.addWidget(&fGLCheckBox);
71
72 fCanvasLayout.setSpacing(6);
73 fCanvasLayout.setContentsMargins(11,11,11,11);
74 fCanvasLayout.addWidget(&fCanvasToggle);
75 fCanvasLayout.addLayout(&fRasterLayout);
76 fCanvasLayout.addLayout(&fGLLayout);
77
chudy@google.com7dcae672012-07-09 20:26:53 +000078 // Command Toggle
79 fCommandToggle.setText("Command Scrolling Preferences");
80 fCommandFrame.setFrameShape(QFrame::StyledPanel);
81 fCommandFrame.setFrameShadow(QFrame::Raised);
chudy@google.com902ebe52012-06-29 14:21:22 +000082
chudy@google.com7dcae672012-07-09 20:26:53 +000083 fCurrentCommandLabel.setText("Current Command: ");
84 fCurrentCommandLabel.setMinimumWidth(178);
85 fCurrentCommandLabel.setMaximumWidth(178);
86 fCurrentCommandBox.setText("0");
87 fCurrentCommandBox.setMinimumSize(QSize(50,25));
88 fCurrentCommandBox.setMaximumSize(QSize(50,25));
89 fCurrentCommandBox.setAlignment(Qt::AlignRight);
chudy@google.com902ebe52012-06-29 14:21:22 +000090
chudy@google.com7dcae672012-07-09 20:26:53 +000091 fCurrentCommandLayout.setSpacing(0);
92 fCurrentCommandLayout.setContentsMargins(0,0,0,0);
93 fCurrentCommandLayout.setAlignment(Qt::AlignLeft);
94 fCurrentCommandLayout.addWidget(&fCurrentCommandLabel);
95 fCurrentCommandLayout.addWidget(&fCurrentCommandBox);
chudy@google.com902ebe52012-06-29 14:21:22 +000096
chudy@google.come606d6e2012-07-12 14:31:25 +000097 fCommandHitLabel.setText("Command HitBox: ");
98 fCommandHitLabel.setMinimumWidth(178);
99 fCommandHitLabel.setMaximumWidth(178);
100 fCommandHitBox.setText("0");
101 fCommandHitBox.setMinimumSize(QSize(50,25));
102 fCommandHitBox.setMaximumSize(QSize(50,25));
103 fCommandHitBox.setAlignment(Qt::AlignRight);
104 fCommandHitLayout.setSpacing(0);
105 fCommandHitLayout.setContentsMargins(0,0,0,0);
106 fCommandHitLayout.setAlignment(Qt::AlignLeft);
107 fCommandHitLayout.addWidget(&fCommandHitLabel);
108 fCommandHitLayout.addWidget(&fCommandHitBox);
109
chudy@google.com7dcae672012-07-09 20:26:53 +0000110 fCommandLayout.setSpacing(6);
111 fCommandLayout.setContentsMargins(11,11,11,11);
112 fCommandLayout.addLayout(&fCurrentCommandLayout);
chudy@google.come606d6e2012-07-12 14:31:25 +0000113 fCommandLayout.addLayout(&fCommandHitLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000114
chudy@google.com7dcae672012-07-09 20:26:53 +0000115 // Zoom Info
116 fZoomSetting.setText("Zoom Level: ");
117 fZoomSetting.setMinimumWidth(178);
118 fZoomSetting.setMaximumWidth(178);
119 fZoomFrame.setFrameShape(QFrame::StyledPanel);
120 fZoomFrame.setFrameShadow(QFrame::Raised);
121 fZoomBox.setText("100%");
122 fZoomBox.setMinimumSize(QSize(50,25));
123 fZoomBox.setMaximumSize(QSize(50,25));
124 fZoomBox.setAlignment(Qt::AlignRight);
125 fZoomLayout.setSpacing(6);
126 fZoomLayout.setContentsMargins(11,11,11,11);
127 fZoomLayout.addWidget(&fZoomSetting);
128 fZoomLayout.addWidget(&fZoomBox);
chudy@google.com902ebe52012-06-29 14:21:22 +0000129
chudy@google.com7dcae672012-07-09 20:26:53 +0000130 // Adds all widgets to settings container
131 fVerticalLayout.addWidget(&fVisibileText);
132 fVerticalLayout.addWidget(&fVisibleFrame);
133 fVerticalLayout.addWidget(&fCommandToggle);
134 fVerticalLayout.addWidget(&fCommandFrame);
chudy@google.comea5488b2012-07-26 19:38:22 +0000135 fVerticalLayout.addWidget(&fCanvasToggle);
136 fVerticalLayout.addWidget(&fCanvasFrame);
chudy@google.com7dcae672012-07-09 20:26:53 +0000137 fVerticalLayout.addWidget(&fZoomFrame);
chudy@google.com902ebe52012-06-29 14:21:22 +0000138
chudy@google.come606d6e2012-07-12 14:31:25 +0000139 this->setDisabled(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000140}
141
142SkSettingsWidget::~SkSettingsWidget() {}
chudy@google.com7dcae672012-07-09 20:26:53 +0000143
144
145void SkSettingsWidget::updateCommand(int newCommand) {
146 fCurrentCommandBox.setText(QString::number(newCommand));
147}
148
chudy@google.come606d6e2012-07-12 14:31:25 +0000149void SkSettingsWidget::updateHit(int newHit) {
150 fCommandHitBox.setText(QString::number(newHit));
151}
152
chudy@google.com7dcae672012-07-09 20:26:53 +0000153QRadioButton* SkSettingsWidget::getVisibilityButton() {
154 return &fVisibleOn;
155}
156
157void SkSettingsWidget::setZoomText(int scaleFactor) {
158 if(scaleFactor == 1 || scaleFactor == -1) {
159 fZoomBox.setText("100%");
160 } else if (scaleFactor > 1) {
161 fZoomBox.setText(QString::number(scaleFactor*100).append("%"));
162 } else if (scaleFactor < -1) {
163 fZoomBox.setText(QString::number(100 / pow(2, (-scaleFactor - 1))).append("%"));
164 }
165}