blob: 5b5236a32223cd507f26b28fa66078a6499ac1b3 [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.com7dcae672012-07-09 20:26:53 +000014SkSettingsWidget::SkSettingsWidget(QWidget *parent) : QWidget(parent)
15 , mainFrameLayout(this)
16 , fVerticalLayout(&mainFrame)
17 , fVisibleFrameLayout(&fVisibleFrame)
18 , fVisibleOn(&fVisibleFrame)
19 , fVisibleOff(&fVisibleFrame)
20 , fCommandLayout(&fCommandFrame)
21 , fCurrentCommandBox(&fCommandFrame)
chudy@google.come606d6e2012-07-12 14:31:25 +000022 , fCommandHitBox(&fCommandFrame)
chudy@google.com7dcae672012-07-09 20:26:53 +000023 , fCommandCheckBox(&fCommandFrame)
24 , fZoomBox(&fZoomFrame)
25 , fZoomLayout(&fZoomFrame)
26{
27 // Sets up the container and it's alignment around the settings widget.
28 mainFrame.setFrameShape(QFrame::StyledPanel);
29 mainFrame.setFrameShadow(QFrame::Raised);
30 mainFrameLayout.setSpacing(6);
31 mainFrameLayout.setContentsMargins(0,0,0,0);
32 mainFrameLayout.addWidget(&mainFrame);
chudy@google.com902ebe52012-06-29 14:21:22 +000033
chudy@google.com7dcae672012-07-09 20:26:53 +000034 // Vertical Layout is the alignment inside of the main frame.
35 fVerticalLayout.setContentsMargins(11,11,11,11);
36 fVerticalLayout.setAlignment(Qt::AlignTop);
chudy@google.com902ebe52012-06-29 14:21:22 +000037
chudy@google.com7dcae672012-07-09 20:26:53 +000038 // Visible Toggle
39 fVisibileText.setText("Visibility Filter");
40 fVisibleFrame.setFrameShape(QFrame::StyledPanel);
41 fVisibleFrame.setFrameShadow(QFrame::Raised);
42 fVisibleOn.setText("On");
43 fVisibleOff.setText("Off");
44 fVisibleOff.setChecked(true);
45 fVisibleFrameLayout.setSpacing(6);
46 fVisibleFrameLayout.setContentsMargins(11,11,11,11);
47 fVisibleFrameLayout.addWidget(&fVisibleOn);
48 fVisibleFrameLayout.addWidget(&fVisibleOff);
chudy@google.com902ebe52012-06-29 14:21:22 +000049
chudy@google.com7dcae672012-07-09 20:26:53 +000050 // Command Toggle
51 fCommandToggle.setText("Command Scrolling Preferences");
52 fCommandFrame.setFrameShape(QFrame::StyledPanel);
53 fCommandFrame.setFrameShadow(QFrame::Raised);
chudy@google.com902ebe52012-06-29 14:21:22 +000054
chudy@google.com7dcae672012-07-09 20:26:53 +000055 fCurrentCommandLabel.setText("Current Command: ");
56 fCurrentCommandLabel.setMinimumWidth(178);
57 fCurrentCommandLabel.setMaximumWidth(178);
58 fCurrentCommandBox.setText("0");
59 fCurrentCommandBox.setMinimumSize(QSize(50,25));
60 fCurrentCommandBox.setMaximumSize(QSize(50,25));
61 fCurrentCommandBox.setAlignment(Qt::AlignRight);
chudy@google.com902ebe52012-06-29 14:21:22 +000062
chudy@google.com7dcae672012-07-09 20:26:53 +000063 fCurrentCommandLayout.setSpacing(0);
64 fCurrentCommandLayout.setContentsMargins(0,0,0,0);
65 fCurrentCommandLayout.setAlignment(Qt::AlignLeft);
66 fCurrentCommandLayout.addWidget(&fCurrentCommandLabel);
67 fCurrentCommandLayout.addWidget(&fCurrentCommandBox);
chudy@google.com902ebe52012-06-29 14:21:22 +000068
chudy@google.come606d6e2012-07-12 14:31:25 +000069 fCommandHitLabel.setText("Command HitBox: ");
70 fCommandHitLabel.setMinimumWidth(178);
71 fCommandHitLabel.setMaximumWidth(178);
72 fCommandHitBox.setText("0");
73 fCommandHitBox.setMinimumSize(QSize(50,25));
74 fCommandHitBox.setMaximumSize(QSize(50,25));
75 fCommandHitBox.setAlignment(Qt::AlignRight);
76 fCommandHitLayout.setSpacing(0);
77 fCommandHitLayout.setContentsMargins(0,0,0,0);
78 fCommandHitLayout.setAlignment(Qt::AlignLeft);
79 fCommandHitLayout.addWidget(&fCommandHitLabel);
80 fCommandHitLayout.addWidget(&fCommandHitBox);
81
chudy@google.com7dcae672012-07-09 20:26:53 +000082 fCommandCheckBox.setText("Pause");
83 fCommandLayout.setSpacing(6);
84 fCommandLayout.setContentsMargins(11,11,11,11);
85 fCommandLayout.addLayout(&fCurrentCommandLayout);
chudy@google.come606d6e2012-07-12 14:31:25 +000086 fCommandLayout.addLayout(&fCommandHitLayout);
chudy@google.com7dcae672012-07-09 20:26:53 +000087 fCommandLayout.addWidget(&fCommandCheckBox);
chudy@google.com902ebe52012-06-29 14:21:22 +000088
chudy@google.com7dcae672012-07-09 20:26:53 +000089 // Zoom Info
90 fZoomSetting.setText("Zoom Level: ");
91 fZoomSetting.setMinimumWidth(178);
92 fZoomSetting.setMaximumWidth(178);
93 fZoomFrame.setFrameShape(QFrame::StyledPanel);
94 fZoomFrame.setFrameShadow(QFrame::Raised);
95 fZoomBox.setText("100%");
96 fZoomBox.setMinimumSize(QSize(50,25));
97 fZoomBox.setMaximumSize(QSize(50,25));
98 fZoomBox.setAlignment(Qt::AlignRight);
99 fZoomLayout.setSpacing(6);
100 fZoomLayout.setContentsMargins(11,11,11,11);
101 fZoomLayout.addWidget(&fZoomSetting);
102 fZoomLayout.addWidget(&fZoomBox);
chudy@google.com902ebe52012-06-29 14:21:22 +0000103
chudy@google.com7dcae672012-07-09 20:26:53 +0000104 // Adds all widgets to settings container
105 fVerticalLayout.addWidget(&fVisibileText);
106 fVerticalLayout.addWidget(&fVisibleFrame);
107 fVerticalLayout.addWidget(&fCommandToggle);
108 fVerticalLayout.addWidget(&fCommandFrame);
109 fVerticalLayout.addWidget(&fZoomFrame);
chudy@google.com902ebe52012-06-29 14:21:22 +0000110
chudy@google.come606d6e2012-07-12 14:31:25 +0000111 this->setDisabled(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000112}
113
114SkSettingsWidget::~SkSettingsWidget() {}
chudy@google.com7dcae672012-07-09 20:26:53 +0000115
116
117void SkSettingsWidget::updateCommand(int newCommand) {
118 fCurrentCommandBox.setText(QString::number(newCommand));
119}
120
chudy@google.come606d6e2012-07-12 14:31:25 +0000121void SkSettingsWidget::updateHit(int newHit) {
122 fCommandHitBox.setText(QString::number(newHit));
123}
124
chudy@google.com7dcae672012-07-09 20:26:53 +0000125QCheckBox* SkSettingsWidget::getCommandCheckBox() {
126 return &fCommandCheckBox;
127}
128
129QRadioButton* SkSettingsWidget::getVisibilityButton() {
130 return &fVisibleOn;
131}
132
133void SkSettingsWidget::setZoomText(int scaleFactor) {
134 if(scaleFactor == 1 || scaleFactor == -1) {
135 fZoomBox.setText("100%");
136 } else if (scaleFactor > 1) {
137 fZoomBox.setText(QString::number(scaleFactor*100).append("%"));
138 } else if (scaleFactor < -1) {
139 fZoomBox.setText(QString::number(100 / pow(2, (-scaleFactor - 1))).append("%"));
140 }
141}