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 | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 14 | // TODO(chudy): See if the layout can't be attached to the frame post construction. |
chudy@google.com | 2d537a1 | 2012-07-31 12:49:52 +0000 | [diff] [blame] | 15 | SkSettingsWidget::SkSettingsWidget() : QWidget() |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 16 | , mainFrameLayout(this) |
| 17 | , fVerticalLayout(&mainFrame) |
| 18 | , fVisibleFrameLayout(&fVisibleFrame) |
| 19 | , fVisibleOn(&fVisibleFrame) |
| 20 | , fVisibleOff(&fVisibleFrame) |
| 21 | , fCommandLayout(&fCommandFrame) |
| 22 | , fCurrentCommandBox(&fCommandFrame) |
chudy@google.com | e606d6e | 2012-07-12 14:31:25 +0000 | [diff] [blame] | 23 | , fCommandHitBox(&fCommandFrame) |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 24 | , fCanvasLayout(&fCanvasFrame) |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 25 | , fZoomLayout(&fZoomFrame) |
chudy@google.com | 2d537a1 | 2012-07-31 12:49:52 +0000 | [diff] [blame] | 26 | , fZoomBox(&fZoomFrame) |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 27 | { |
| 28 | // Sets up the container and it's alignment around the settings widget. |
| 29 | mainFrame.setFrameShape(QFrame::StyledPanel); |
| 30 | mainFrame.setFrameShadow(QFrame::Raised); |
| 31 | mainFrameLayout.setSpacing(6); |
| 32 | mainFrameLayout.setContentsMargins(0,0,0,0); |
| 33 | mainFrameLayout.addWidget(&mainFrame); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 34 | |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 35 | // Vertical Layout is the alignment inside of the main frame. |
| 36 | fVerticalLayout.setContentsMargins(11,11,11,11); |
| 37 | fVerticalLayout.setAlignment(Qt::AlignTop); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 38 | |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 39 | // Visible Toggle |
| 40 | fVisibileText.setText("Visibility Filter"); |
| 41 | fVisibleFrame.setFrameShape(QFrame::StyledPanel); |
| 42 | fVisibleFrame.setFrameShadow(QFrame::Raised); |
| 43 | fVisibleOn.setText("On"); |
| 44 | fVisibleOff.setText("Off"); |
| 45 | fVisibleOff.setChecked(true); |
| 46 | fVisibleFrameLayout.setSpacing(6); |
| 47 | fVisibleFrameLayout.setContentsMargins(11,11,11,11); |
| 48 | fVisibleFrameLayout.addWidget(&fVisibleOn); |
| 49 | fVisibleFrameLayout.addWidget(&fVisibleOff); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 50 | |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 51 | // Canvas |
| 52 | fCanvasToggle.setText("Render Targets"); |
| 53 | fCanvasFrame.setFrameShape(QFrame::StyledPanel); |
| 54 | fCanvasFrame.setFrameShadow(QFrame::Raised); |
| 55 | |
| 56 | fRasterLabel.setText("Raster: "); |
| 57 | fRasterLabel.setMinimumWidth(178); |
| 58 | fRasterLabel.setMaximumWidth(178); |
| 59 | |
| 60 | fRasterCheckBox.setChecked(true); |
| 61 | |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 62 | fOverdrawVizLabel.setText(" Overdraw Viz: "); |
| 63 | fOverdrawVizLabel.setMinimumWidth(178); |
| 64 | fOverdrawVizLabel.setMaximumWidth(178); |
| 65 | |
robertphillips@google.com | e8fe4bc | 2013-02-13 13:26:13 +0000 | [diff] [blame] | 66 | #if SK_SUPPORT_GPU |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 67 | fGLLabel.setText("OpenGL: "); |
| 68 | fGLLabel.setMinimumWidth(178); |
| 69 | fGLLabel.setMaximumWidth(178); |
robertphillips@google.com | e8fe4bc | 2013-02-13 13:26:13 +0000 | [diff] [blame] | 70 | #endif |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 71 | |
| 72 | fRasterLayout.addWidget(&fRasterLabel); |
| 73 | fRasterLayout.addWidget(&fRasterCheckBox); |
| 74 | |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 75 | fOverdrawVizLayout.addWidget(&fOverdrawVizLabel); |
| 76 | fOverdrawVizLayout.addWidget(&fOverdrawVizCheckBox); |
| 77 | |
robertphillips@google.com | e8fe4bc | 2013-02-13 13:26:13 +0000 | [diff] [blame] | 78 | #if SK_SUPPORT_GPU |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 79 | fGLLayout.addWidget(&fGLLabel); |
| 80 | fGLLayout.addWidget(&fGLCheckBox); |
robertphillips@google.com | e8fe4bc | 2013-02-13 13:26:13 +0000 | [diff] [blame] | 81 | #endif |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 82 | |
| 83 | fCanvasLayout.setSpacing(6); |
| 84 | fCanvasLayout.setContentsMargins(11,11,11,11); |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 85 | fCanvasLayout.addLayout(&fRasterLayout); |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 86 | fCanvasLayout.addLayout(&fOverdrawVizLayout); |
robertphillips@google.com | e8fe4bc | 2013-02-13 13:26:13 +0000 | [diff] [blame] | 87 | #if SK_SUPPORT_GPU |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 88 | fCanvasLayout.addLayout(&fGLLayout); |
robertphillips@google.com | e8fe4bc | 2013-02-13 13:26:13 +0000 | [diff] [blame] | 89 | #endif |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 90 | |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 91 | // Command Toggle |
| 92 | fCommandToggle.setText("Command Scrolling Preferences"); |
| 93 | fCommandFrame.setFrameShape(QFrame::StyledPanel); |
| 94 | fCommandFrame.setFrameShadow(QFrame::Raised); |
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 | fCurrentCommandLabel.setText("Current Command: "); |
| 97 | fCurrentCommandLabel.setMinimumWidth(178); |
| 98 | fCurrentCommandLabel.setMaximumWidth(178); |
| 99 | fCurrentCommandBox.setText("0"); |
| 100 | fCurrentCommandBox.setMinimumSize(QSize(50,25)); |
| 101 | fCurrentCommandBox.setMaximumSize(QSize(50,25)); |
| 102 | fCurrentCommandBox.setAlignment(Qt::AlignRight); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 103 | |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 104 | fCurrentCommandLayout.setSpacing(0); |
| 105 | fCurrentCommandLayout.setContentsMargins(0,0,0,0); |
| 106 | fCurrentCommandLayout.setAlignment(Qt::AlignLeft); |
| 107 | fCurrentCommandLayout.addWidget(&fCurrentCommandLabel); |
| 108 | fCurrentCommandLayout.addWidget(&fCurrentCommandBox); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 109 | |
chudy@google.com | e606d6e | 2012-07-12 14:31:25 +0000 | [diff] [blame] | 110 | fCommandHitLabel.setText("Command HitBox: "); |
| 111 | fCommandHitLabel.setMinimumWidth(178); |
| 112 | fCommandHitLabel.setMaximumWidth(178); |
| 113 | fCommandHitBox.setText("0"); |
| 114 | fCommandHitBox.setMinimumSize(QSize(50,25)); |
| 115 | fCommandHitBox.setMaximumSize(QSize(50,25)); |
| 116 | fCommandHitBox.setAlignment(Qt::AlignRight); |
| 117 | fCommandHitLayout.setSpacing(0); |
| 118 | fCommandHitLayout.setContentsMargins(0,0,0,0); |
| 119 | fCommandHitLayout.setAlignment(Qt::AlignLeft); |
| 120 | fCommandHitLayout.addWidget(&fCommandHitLabel); |
| 121 | fCommandHitLayout.addWidget(&fCommandHitBox); |
| 122 | |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 123 | fCommandLayout.setSpacing(6); |
| 124 | fCommandLayout.setContentsMargins(11,11,11,11); |
| 125 | fCommandLayout.addLayout(&fCurrentCommandLayout); |
chudy@google.com | e606d6e | 2012-07-12 14:31:25 +0000 | [diff] [blame] | 126 | fCommandLayout.addLayout(&fCommandHitLayout); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 127 | |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 128 | // Zoom Info |
| 129 | fZoomSetting.setText("Zoom Level: "); |
| 130 | fZoomSetting.setMinimumWidth(178); |
| 131 | fZoomSetting.setMaximumWidth(178); |
| 132 | fZoomFrame.setFrameShape(QFrame::StyledPanel); |
| 133 | fZoomFrame.setFrameShadow(QFrame::Raised); |
| 134 | fZoomBox.setText("100%"); |
| 135 | fZoomBox.setMinimumSize(QSize(50,25)); |
| 136 | fZoomBox.setMaximumSize(QSize(50,25)); |
| 137 | fZoomBox.setAlignment(Qt::AlignRight); |
| 138 | fZoomLayout.setSpacing(6); |
| 139 | fZoomLayout.setContentsMargins(11,11,11,11); |
| 140 | fZoomLayout.addWidget(&fZoomSetting); |
| 141 | fZoomLayout.addWidget(&fZoomBox); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 142 | |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 143 | // Adds all widgets to settings container |
| 144 | fVerticalLayout.addWidget(&fVisibileText); |
| 145 | fVerticalLayout.addWidget(&fVisibleFrame); |
| 146 | fVerticalLayout.addWidget(&fCommandToggle); |
| 147 | fVerticalLayout.addWidget(&fCommandFrame); |
chudy@google.com | ea5488b | 2012-07-26 19:38:22 +0000 | [diff] [blame] | 148 | fVerticalLayout.addWidget(&fCanvasToggle); |
| 149 | fVerticalLayout.addWidget(&fCanvasFrame); |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 150 | fVerticalLayout.addWidget(&fZoomFrame); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 151 | |
chudy@google.com | e606d6e | 2012-07-12 14:31:25 +0000 | [diff] [blame] | 152 | this->setDisabled(true); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 153 | } |
| 154 | |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 155 | |
| 156 | void SkSettingsWidget::updateCommand(int newCommand) { |
| 157 | fCurrentCommandBox.setText(QString::number(newCommand)); |
| 158 | } |
| 159 | |
chudy@google.com | e606d6e | 2012-07-12 14:31:25 +0000 | [diff] [blame] | 160 | void SkSettingsWidget::updateHit(int newHit) { |
| 161 | fCommandHitBox.setText(QString::number(newHit)); |
| 162 | } |
| 163 | |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 164 | QRadioButton* SkSettingsWidget::getVisibilityButton() { |
| 165 | return &fVisibleOn; |
| 166 | } |
| 167 | |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 168 | void SkSettingsWidget::setZoomText(float scale) { |
| 169 | fZoomBox.setText(QString::number(scale*100, 'f', 0).append("%")); |
chudy@google.com | 7dcae67 | 2012-07-09 20:26:53 +0000 | [diff] [blame] | 170 | } |