SkSettingsWidget.cpp revision e606d6e210b17dd9dd582d4d3ec70acb4f3213d5
1
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"
11#include <iostream>
12#include <math.h>
13
14SkSettingsWidget::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)
22    , fCommandHitBox(&fCommandFrame)
23    , 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);
33
34    // Vertical Layout is the alignment inside of the main frame.
35    fVerticalLayout.setContentsMargins(11,11,11,11);
36    fVerticalLayout.setAlignment(Qt::AlignTop);
37
38    // 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);
49
50    // Command Toggle
51    fCommandToggle.setText("Command Scrolling Preferences");
52    fCommandFrame.setFrameShape(QFrame::StyledPanel);
53    fCommandFrame.setFrameShadow(QFrame::Raised);
54
55    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);
62
63    fCurrentCommandLayout.setSpacing(0);
64    fCurrentCommandLayout.setContentsMargins(0,0,0,0);
65    fCurrentCommandLayout.setAlignment(Qt::AlignLeft);
66    fCurrentCommandLayout.addWidget(&fCurrentCommandLabel);
67    fCurrentCommandLayout.addWidget(&fCurrentCommandBox);
68
69    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
82    fCommandCheckBox.setText("Pause");
83    fCommandLayout.setSpacing(6);
84    fCommandLayout.setContentsMargins(11,11,11,11);
85    fCommandLayout.addLayout(&fCurrentCommandLayout);
86    fCommandLayout.addLayout(&fCommandHitLayout);
87    fCommandLayout.addWidget(&fCommandCheckBox);
88
89    // 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);
103
104    // 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);
110
111    this->setDisabled(true);
112}
113
114SkSettingsWidget::~SkSettingsWidget() {}
115
116
117void SkSettingsWidget::updateCommand(int newCommand) {
118    fCurrentCommandBox.setText(QString::number(newCommand));
119}
120
121void SkSettingsWidget::updateHit(int newHit) {
122    fCommandHitBox.setText(QString::number(newHit));
123}
124
125QCheckBox* 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}
142