1 /******************************************************************************
2     QtAV Player Demo:  this file is part of QtAV examples
3     Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
4 
5 *   This file is part of QtAV (from 2016)
6 
7     This program is free software: you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation, either version 3 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 ******************************************************************************/
20 #include "ShaderPage.h"
21 #include <QLabel>
22 #include <QLayout>
23 #include "common/Config.h"
24 
ShaderPage(QWidget * parent)25 ShaderPage::ShaderPage(QWidget *parent)
26     : ConfigPageBase(parent)
27 {
28     QVBoxLayout *gl = new QVBoxLayout();
29     setLayout(gl);
30     gl->setSizeConstraint(QLayout::SetMaximumSize);
31     const int mw = 600;
32     m_enable = new QCheckBox(tr("Enable"));
33     gl->addWidget(m_enable);
34     m_fbo = new QCheckBox(tr("Intermediate FBO"));
35     gl->addWidget(m_fbo);
36     gl->addWidget(new QLabel(tr("Fragment shader header")));
37     m_header = new QTextEdit();
38     //m_header->setMaximumWidth(mw);
39     m_header->setMaximumHeight(mw/6);
40     m_header->setToolTip(tr("Additional header code"));
41     gl->addWidget(m_header);
42     gl->addWidget(new QLabel(tr("Fragment shader texel sample function")));
43     m_sample = new QTextEdit();
44     //m_sample->setMaximumWidth(mw);
45     m_sample->setMaximumHeight(mw/6);
46     m_sample->setToolTip(QLatin1String("vec4 sample2d(sampler2D tex, vec2 pos, int p)"));
47     gl->addWidget(m_sample);
48     gl->addWidget(new QLabel(QLatin1String("Fragment shader RGB post process code")));
49     m_pp = new QTextEdit();
50     //m_pp->setMaximumWidth(mw);
51     m_pp->setMaximumHeight(mw/6);
52     gl->addWidget(m_pp);
53     gl->addStretch();
54 }
55 
name() const56 QString ShaderPage::name() const
57 {
58     return tr("Shader");
59 }
60 
applyToUi()61 void ShaderPage::applyToUi()
62 {
63     m_enable->setChecked(Config::instance().userShaderEnabled());
64     m_fbo->setChecked(Config::instance().intermediateFBO());
65     m_header->setText(Config::instance().fragHeader());
66     m_sample->setText(Config::instance().fragSample());
67     m_pp->setText(Config::instance().fragPostProcess());
68 }
69 
applyFromUi()70 void ShaderPage::applyFromUi()
71 {
72     Config::instance()
73             .setUserShaderEnabled(m_enable->isChecked())
74             .setIntermediateFBO(m_fbo->isChecked())
75             .setFragHeader(m_header->toPlainText())
76             .setFragSample(m_sample->toPlainText())
77             .setFragPostProcess(m_pp->toPlainText())
78             ;
79 }
80