blob: 8ef4e9a4101d2316c05d372e9cefcae4097df006 [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 , fZoomBox(&fZoomFrame)
24 , fZoomLayout(&fZoomFrame)
25{
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
38 fVisibileText.setText("Visibility Filter");
39 fVisibleFrame.setFrameShape(QFrame::StyledPanel);
40 fVisibleFrame.setFrameShadow(QFrame::Raised);
41 fVisibleOn.setText("On");
42 fVisibleOff.setText("Off");
43 fVisibleOff.setChecked(true);
44 fVisibleFrameLayout.setSpacing(6);
45 fVisibleFrameLayout.setContentsMargins(11,11,11,11);
46 fVisibleFrameLayout.addWidget(&fVisibleOn);
47 fVisibleFrameLayout.addWidget(&fVisibleOff);
chudy@google.com902ebe52012-06-29 14:21:22 +000048
chudy@google.com7dcae672012-07-09 20:26:53 +000049 // Command Toggle
50 fCommandToggle.setText("Command Scrolling Preferences");
51 fCommandFrame.setFrameShape(QFrame::StyledPanel);
52 fCommandFrame.setFrameShadow(QFrame::Raised);
chudy@google.com902ebe52012-06-29 14:21:22 +000053
chudy@google.com7dcae672012-07-09 20:26:53 +000054 fCurrentCommandLabel.setText("Current Command: ");
55 fCurrentCommandLabel.setMinimumWidth(178);
56 fCurrentCommandLabel.setMaximumWidth(178);
57 fCurrentCommandBox.setText("0");
58 fCurrentCommandBox.setMinimumSize(QSize(50,25));
59 fCurrentCommandBox.setMaximumSize(QSize(50,25));
60 fCurrentCommandBox.setAlignment(Qt::AlignRight);
chudy@google.com902ebe52012-06-29 14:21:22 +000061
chudy@google.com7dcae672012-07-09 20:26:53 +000062 fCurrentCommandLayout.setSpacing(0);
63 fCurrentCommandLayout.setContentsMargins(0,0,0,0);
64 fCurrentCommandLayout.setAlignment(Qt::AlignLeft);
65 fCurrentCommandLayout.addWidget(&fCurrentCommandLabel);
66 fCurrentCommandLayout.addWidget(&fCurrentCommandBox);
chudy@google.com902ebe52012-06-29 14:21:22 +000067
chudy@google.come606d6e2012-07-12 14:31:25 +000068 fCommandHitLabel.setText("Command HitBox: ");
69 fCommandHitLabel.setMinimumWidth(178);
70 fCommandHitLabel.setMaximumWidth(178);
71 fCommandHitBox.setText("0");
72 fCommandHitBox.setMinimumSize(QSize(50,25));
73 fCommandHitBox.setMaximumSize(QSize(50,25));
74 fCommandHitBox.setAlignment(Qt::AlignRight);
75 fCommandHitLayout.setSpacing(0);
76 fCommandHitLayout.setContentsMargins(0,0,0,0);
77 fCommandHitLayout.setAlignment(Qt::AlignLeft);
78 fCommandHitLayout.addWidget(&fCommandHitLabel);
79 fCommandHitLayout.addWidget(&fCommandHitBox);
80
chudy@google.com7dcae672012-07-09 20:26:53 +000081 fCommandLayout.setSpacing(6);
82 fCommandLayout.setContentsMargins(11,11,11,11);
83 fCommandLayout.addLayout(&fCurrentCommandLayout);
chudy@google.come606d6e2012-07-12 14:31:25 +000084 fCommandLayout.addLayout(&fCommandHitLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +000085
chudy@google.com7dcae672012-07-09 20:26:53 +000086 // Zoom Info
87 fZoomSetting.setText("Zoom Level: ");
88 fZoomSetting.setMinimumWidth(178);
89 fZoomSetting.setMaximumWidth(178);
90 fZoomFrame.setFrameShape(QFrame::StyledPanel);
91 fZoomFrame.setFrameShadow(QFrame::Raised);
92 fZoomBox.setText("100%");
93 fZoomBox.setMinimumSize(QSize(50,25));
94 fZoomBox.setMaximumSize(QSize(50,25));
95 fZoomBox.setAlignment(Qt::AlignRight);
96 fZoomLayout.setSpacing(6);
97 fZoomLayout.setContentsMargins(11,11,11,11);
98 fZoomLayout.addWidget(&fZoomSetting);
99 fZoomLayout.addWidget(&fZoomBox);
chudy@google.com902ebe52012-06-29 14:21:22 +0000100
chudy@google.com7dcae672012-07-09 20:26:53 +0000101 // Adds all widgets to settings container
102 fVerticalLayout.addWidget(&fVisibileText);
103 fVerticalLayout.addWidget(&fVisibleFrame);
104 fVerticalLayout.addWidget(&fCommandToggle);
105 fVerticalLayout.addWidget(&fCommandFrame);
106 fVerticalLayout.addWidget(&fZoomFrame);
chudy@google.com902ebe52012-06-29 14:21:22 +0000107
chudy@google.come606d6e2012-07-12 14:31:25 +0000108 this->setDisabled(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000109}
110
111SkSettingsWidget::~SkSettingsWidget() {}
chudy@google.com7dcae672012-07-09 20:26:53 +0000112
113
114void SkSettingsWidget::updateCommand(int newCommand) {
115 fCurrentCommandBox.setText(QString::number(newCommand));
116}
117
chudy@google.come606d6e2012-07-12 14:31:25 +0000118void SkSettingsWidget::updateHit(int newHit) {
119 fCommandHitBox.setText(QString::number(newHit));
120}
121
chudy@google.com7dcae672012-07-09 20:26:53 +0000122QRadioButton* SkSettingsWidget::getVisibilityButton() {
123 return &fVisibleOn;
124}
125
126void SkSettingsWidget::setZoomText(int scaleFactor) {
127 if(scaleFactor == 1 || scaleFactor == -1) {
128 fZoomBox.setText("100%");
129 } else if (scaleFactor > 1) {
130 fZoomBox.setText(QString::number(scaleFactor*100).append("%"));
131 } else if (scaleFactor < -1) {
132 fZoomBox.setText(QString::number(100 / pow(2, (-scaleFactor - 1))).append("%"));
133 }
134}