blob: 117e7bf71e1d558c73199317cfc15a1a850b61ef [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)
22 , fCommandCheckBox(&fCommandFrame)
23 , 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.com7dcae672012-07-09 20:26:53 +000068 fCommandCheckBox.setText("Pause");
69 fCommandLayout.setSpacing(6);
70 fCommandLayout.setContentsMargins(11,11,11,11);
71 fCommandLayout.addLayout(&fCurrentCommandLayout);
72 fCommandLayout.addWidget(&fCommandCheckBox);
chudy@google.com902ebe52012-06-29 14:21:22 +000073
chudy@google.com7dcae672012-07-09 20:26:53 +000074 // Zoom Info
75 fZoomSetting.setText("Zoom Level: ");
76 fZoomSetting.setMinimumWidth(178);
77 fZoomSetting.setMaximumWidth(178);
78 fZoomFrame.setFrameShape(QFrame::StyledPanel);
79 fZoomFrame.setFrameShadow(QFrame::Raised);
80 fZoomBox.setText("100%");
81 fZoomBox.setMinimumSize(QSize(50,25));
82 fZoomBox.setMaximumSize(QSize(50,25));
83 fZoomBox.setAlignment(Qt::AlignRight);
84 fZoomLayout.setSpacing(6);
85 fZoomLayout.setContentsMargins(11,11,11,11);
86 fZoomLayout.addWidget(&fZoomSetting);
87 fZoomLayout.addWidget(&fZoomBox);
chudy@google.com902ebe52012-06-29 14:21:22 +000088
chudy@google.com7dcae672012-07-09 20:26:53 +000089 // Adds all widgets to settings container
90 fVerticalLayout.addWidget(&fVisibileText);
91 fVerticalLayout.addWidget(&fVisibleFrame);
92 fVerticalLayout.addWidget(&fCommandToggle);
93 fVerticalLayout.addWidget(&fCommandFrame);
94 fVerticalLayout.addWidget(&fZoomFrame);
chudy@google.com902ebe52012-06-29 14:21:22 +000095
chudy@google.com7dcae672012-07-09 20:26:53 +000096 //this->setDisabled(true);
chudy@google.com902ebe52012-06-29 14:21:22 +000097}
98
99SkSettingsWidget::~SkSettingsWidget() {}
chudy@google.com7dcae672012-07-09 20:26:53 +0000100
101
102void SkSettingsWidget::updateCommand(int newCommand) {
103 fCurrentCommandBox.setText(QString::number(newCommand));
104}
105
106QCheckBox* SkSettingsWidget::getCommandCheckBox() {
107 return &fCommandCheckBox;
108}
109
110QRadioButton* SkSettingsWidget::getVisibilityButton() {
111 return &fVisibleOn;
112}
113
114void SkSettingsWidget::setZoomText(int scaleFactor) {
115 if(scaleFactor == 1 || scaleFactor == -1) {
116 fZoomBox.setText("100%");
117 } else if (scaleFactor > 1) {
118 fZoomBox.setText(QString::number(scaleFactor*100).append("%"));
119 } else if (scaleFactor < -1) {
120 fZoomBox.setText(QString::number(100 / pow(2, (-scaleFactor - 1))).append("%"));
121 }
122}