Home | History | Annotate | Download | only in QT
      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 
     14 // TODO(chudy): See if the layout can't be attached to the frame post construction.
     15 SkSettingsWidget::SkSettingsWidget() : QWidget()
     16     , mainFrameLayout(this)
     17     , fVerticalLayout(&mainFrame)
     18     , fVisibleFrameLayout(&fVisibleFrame)
     19     , fCommandLayout(&fCommandFrame)
     20     , fCurrentCommandBox(&fCommandFrame)
     21     , fCommandHitBox(&fCommandFrame)
     22     , fCanvasLayout(&fCanvasFrame)
     23     , fZoomLayout(&fZoomFrame)
     24     , fZoomBox(&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);
     32 
     33     // Vertical Layout is the alignment inside of the main frame.
     34     fVerticalLayout.setContentsMargins(11,11,11,11);
     35     fVerticalLayout.setAlignment(Qt::AlignTop);
     36 
     37     // Visible Toggle
     38     fVisibleText.setText("Visibility Filter");
     39     fVisibleFrame.setFrameShape(QFrame::StyledPanel);
     40     fVisibleFrame.setFrameShadow(QFrame::Raised);
     41 
     42     fVisibilityCombo.addItem("Off", QVariant(false));
     43     fVisibilityCombo.addItem("On", QVariant(true));
     44 
     45     fVisibleFrameLayout.setContentsMargins(11, 5, 11, 5);
     46     fVisibleFrameLayout.addWidget(&fVisibilityCombo);
     47     connect(&fVisibilityCombo, SIGNAL(activated(int)), this,
     48             SIGNAL(visibilityFilterChanged()));
     49 
     50     // Canvas
     51     fCanvasToggle.setText("Render Targets");
     52     fCanvasFrame.setFrameShape(QFrame::StyledPanel);
     53     fCanvasFrame.setFrameShadow(QFrame::Raised);
     54 
     55     fRasterLabel.setText("Raster: ");
     56     fRasterLabel.setMinimumWidth(178);
     57     fRasterLabel.setMaximumWidth(178);
     58 
     59     fPathOpsLabel.setText("PathOps: ");
     60     fPathOpsLabel.setMinimumWidth(178);
     61     fPathOpsLabel.setMaximumWidth(178);
     62 
     63     fRasterCheckBox.setChecked(true);
     64 
     65     fOverdrawVizLabel.setText("     Overdraw Viz: ");
     66     fOverdrawVizLabel.setMinimumWidth(178);
     67     fOverdrawVizLabel.setMaximumWidth(178);
     68 
     69     fMegaVizLabel.setText("         Mega Viz: ");
     70     fMegaVizLabel.setMinimumWidth(178);
     71     fMegaVizLabel.setMaximumWidth(178);
     72 
     73 #if SK_SUPPORT_GPU
     74     fGLLabel.setText("OpenGL: ");
     75     fGLLabel.setMinimumWidth(178);
     76     fGLLabel.setMaximumWidth(178);
     77 
     78     fGLMSAAButtonGroup.setTitle("MSAA");
     79     fGLMSAAButtonGroup.setMinimumWidth(178);
     80     fGLMSAAButtonGroup.setMaximumWidth(178);
     81     fGLMSAAButtonGroup.setEnabled(fGLCheckBox.isChecked());
     82 
     83     fGLMSAACombo.addItem("Off", QVariant(0));
     84     fGLMSAACombo.addItem("4", QVariant(4));
     85     fGLMSAACombo.addItem("16", QVariant(16));
     86 
     87     fGLMSAALayout.addWidget(&fGLMSAACombo);
     88     fGLMSAAButtonGroup.setLayout(&fGLMSAALayout);
     89 
     90     connect(&fGLCheckBox, SIGNAL(toggled(bool)), &fGLMSAAButtonGroup,
     91             SLOT(setEnabled(bool)));
     92     connect(&fGLCheckBox, SIGNAL(toggled(bool)), this,
     93             SIGNAL(glSettingsChanged()));
     94     connect(&fGLMSAACombo, SIGNAL(activated(int)), this,
     95             SIGNAL(glSettingsChanged()));
     96 #endif
     97 
     98     {
     99         // set up filter buttons
    100         fFilterButtonGroup.setTitle("Filtering");
    101         fFilterButtonGroup.setMinimumWidth(178);
    102         fFilterButtonGroup.setMaximumWidth(178);
    103 
    104         fFilterCombo.addItem("As encoded", QVariant(SkPaint::kNone_FilterLevel));
    105         fFilterCombo.addItem("None", QVariant(SkPaint::kNone_FilterLevel));
    106         fFilterCombo.addItem("Low", QVariant(SkPaint::kLow_FilterLevel));
    107         fFilterCombo.addItem("Medium", QVariant(SkPaint::kMedium_FilterLevel));
    108         fFilterCombo.addItem("High", QVariant(SkPaint::kHigh_FilterLevel));
    109 
    110         fFilterLayout.addWidget(&fFilterCombo);
    111         fFilterButtonGroup.setLayout(&fFilterLayout);
    112 
    113         connect(&fFilterCombo, SIGNAL(activated(int)), this,
    114                 SIGNAL(texFilterSettingsChanged()));
    115     }
    116 
    117     fRasterLayout.addWidget(&fRasterLabel);
    118     fRasterLayout.addWidget(&fRasterCheckBox);
    119     fRasterLayout.addWidget(&fPathOpsLabel);
    120     fRasterLayout.addWidget(&fPathOpsCheckBox);
    121 
    122     fVizLayout.addWidget(&fOverdrawVizLabel);
    123     fVizLayout.addWidget(&fOverdrawVizCheckBox);
    124     fVizLayout.addWidget(&fMegaVizLabel);
    125     fVizLayout.addWidget(&fMegaVizCheckBox);
    126 
    127 #if SK_SUPPORT_GPU
    128     fGLLayout.addWidget(&fGLLabel);
    129     fGLLayout.addWidget(&fGLCheckBox);
    130 #endif
    131 
    132     fCanvasLayout.setSpacing(6);
    133     fCanvasLayout.setContentsMargins(11,11,11,11);
    134     fCanvasLayout.addLayout(&fRasterLayout);
    135     fCanvasLayout.addLayout(&fVizLayout);
    136 #if SK_SUPPORT_GPU
    137     fCanvasLayout.addLayout(&fGLLayout);
    138     fCanvasLayout.addWidget(&fGLMSAAButtonGroup);
    139 #endif
    140     fCanvasLayout.addWidget(&fFilterButtonGroup);
    141 
    142     // Command Toggle
    143     fCommandToggle.setText("Command Scrolling Preferences");
    144     fCommandFrame.setFrameShape(QFrame::StyledPanel);
    145     fCommandFrame.setFrameShadow(QFrame::Raised);
    146 
    147     fCurrentCommandLabel.setText("Current Command: ");
    148     fCurrentCommandLabel.setMinimumWidth(178);
    149     fCurrentCommandLabel.setMaximumWidth(178);
    150     fCurrentCommandBox.setText("0");
    151     fCurrentCommandBox.setMinimumSize(QSize(50,25));
    152     fCurrentCommandBox.setMaximumSize(QSize(50,25));
    153     fCurrentCommandBox.setAlignment(Qt::AlignRight);
    154 
    155     fCurrentCommandLayout.setSpacing(0);
    156     fCurrentCommandLayout.setContentsMargins(0,0,0,0);
    157     fCurrentCommandLayout.setAlignment(Qt::AlignLeft);
    158     fCurrentCommandLayout.addWidget(&fCurrentCommandLabel);
    159     fCurrentCommandLayout.addWidget(&fCurrentCommandBox);
    160 
    161     fCommandHitLabel.setText("Command HitBox: ");
    162     fCommandHitLabel.setMinimumWidth(178);
    163     fCommandHitLabel.setMaximumWidth(178);
    164     fCommandHitBox.setText("0");
    165     fCommandHitBox.setMinimumSize(QSize(50,25));
    166     fCommandHitBox.setMaximumSize(QSize(50,25));
    167     fCommandHitBox.setAlignment(Qt::AlignRight);
    168     fCommandHitLayout.setSpacing(0);
    169     fCommandHitLayout.setContentsMargins(0,0,0,0);
    170     fCommandHitLayout.setAlignment(Qt::AlignLeft);
    171     fCommandHitLayout.addWidget(&fCommandHitLabel);
    172     fCommandHitLayout.addWidget(&fCommandHitBox);
    173 
    174     fCommandLayout.setSpacing(6);
    175     fCommandLayout.setContentsMargins(11,11,11,11);
    176     fCommandLayout.addLayout(&fCurrentCommandLayout);
    177     fCommandLayout.addLayout(&fCommandHitLayout);
    178 
    179     // Zoom Info
    180     fZoomSetting.setText("Zoom Level: ");
    181     fZoomSetting.setMinimumWidth(178);
    182     fZoomSetting.setMaximumWidth(178);
    183     fZoomFrame.setFrameShape(QFrame::StyledPanel);
    184     fZoomFrame.setFrameShadow(QFrame::Raised);
    185     fZoomBox.setText("100%");
    186     fZoomBox.setMinimumSize(QSize(50,25));
    187     fZoomBox.setMaximumSize(QSize(50,25));
    188     fZoomBox.setAlignment(Qt::AlignRight);
    189     fZoomLayout.setSpacing(6);
    190     fZoomLayout.setContentsMargins(11,11,11,11);
    191     fZoomLayout.addWidget(&fZoomSetting);
    192     fZoomLayout.addWidget(&fZoomBox);
    193 
    194     // Adds all widgets to settings container
    195     fVerticalLayout.addWidget(&fVisibleText);
    196     fVerticalLayout.addWidget(&fVisibleFrame);
    197     fVerticalLayout.addWidget(&fCommandToggle);
    198     fVerticalLayout.addWidget(&fCommandFrame);
    199     fVerticalLayout.addWidget(&fCanvasToggle);
    200     fVerticalLayout.addWidget(&fCanvasFrame);
    201     fVerticalLayout.addWidget(&fZoomFrame);
    202 
    203     this->setDisabled(true);
    204 }
    205 
    206 
    207 void SkSettingsWidget::updateCommand(int newCommand) {
    208     fCurrentCommandBox.setText(QString::number(newCommand));
    209 }
    210 
    211 void SkSettingsWidget::updateHit(int newHit) {
    212     fCommandHitBox.setText(QString::number(newHit));
    213 }
    214 
    215 void SkSettingsWidget::setZoomText(float scale) {
    216     fZoomBox.setText(QString::number(scale*100, 'f', 0).append("%"));
    217 }
    218