| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 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" |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 11 | #include <iostream> |
| 12 | #include <math.h> |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 13 | |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 14 | SkSettingsWidget::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.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 32 | |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 33 | // Vertical Layout is the alignment inside of the main frame. |
| 34 | fVerticalLayout.setContentsMargins(11,11,11,11); |
| 35 | fVerticalLayout.setAlignment(Qt::AlignTop); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 36 | |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 37 | // 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.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 48 | |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 49 | // Command Toggle |
| 50 | fCommandToggle.setText("Command Scrolling Preferences"); |
| 51 | fCommandFrame.setFrameShape(QFrame::StyledPanel); |
| 52 | fCommandFrame.setFrameShadow(QFrame::Raised); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 53 | |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 54 | 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.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 61 | |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 62 | 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.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 67 | |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 68 | fCommandCheckBox.setText("Pause"); |
| 69 | fCommandLayout.setSpacing(6); |
| 70 | fCommandLayout.setContentsMargins(11,11,11,11); |
| 71 | fCommandLayout.addLayout(&fCurrentCommandLayout); |
| 72 | fCommandLayout.addWidget(&fCommandCheckBox); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 73 | |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 74 | // 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.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 88 | |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 89 | // 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.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 95 | |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 96 | //this->setDisabled(true); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | SkSettingsWidget::~SkSettingsWidget() {} |
| chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 100 | |
| 101 | |
| 102 | void SkSettingsWidget::updateCommand(int newCommand) { |
| 103 | fCurrentCommandBox.setText(QString::number(newCommand)); |
| 104 | } |
| 105 | |
| 106 | QCheckBox* SkSettingsWidget::getCommandCheckBox() { |
| 107 | return &fCommandCheckBox; |
| 108 | } |
| 109 | |
| 110 | QRadioButton* SkSettingsWidget::getVisibilityButton() { |
| 111 | return &fVisibleOn; |
| 112 | } |
| 113 | |
| 114 | void 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 | } |