<commit_before>//  Natron
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
 *Created by <NAME> on 6/1/2012.
 *contact: immarespond at gmail dot com
 *
 */

// TODO: split into KnobGui.cpp, KnobGuiFile.cpp and KnobGuiTypes.cpp

#include "Gui/KnobGui.h"

#include <cassert>
#ifdef __NATRON_UNIX__
#include <dlfcn.h>
#endif
#include <climits>
#include <cfloat>
#include <QtCore/QString>
#include <QHBoxLayout>
#include <QPushButton>
#include <QCheckBox>
#include <QLabel>
#include <QFileDialog>
#include <QTextEdit>
#if QT_VERSION < 0x050000
CLANG_DIAG_OFF(unused-private-field);
#include <QtGui/qmime.h>
CLANG_DIAG_ON(unused-private-field);
#endif
#include <QKeyEvent>
#include <QColorDialog>
#include <QGroupBox>
#include <QtGui/QVector4D>
#include <QStyleFactory>


#include "Global/AppManager.h"
#include "Global/LibraryBinary.h"
#include "Global/GlobalDefines.h"

#include "Engine/Node.h"
#include "Engine/VideoEngine.h"
#include "Engine/ViewerInstance.h"
#include "Engine/Settings.h"
#include "Engine/Knob.h"
#include "Engine/KnobFile.h"
#include "Engine/KnobTypes.h"
#include "Engine/TimeLine.h"

#include "Gui/Button.h"
#include "Gui/DockablePanel.h"
#include "Gui/ViewerTab.h"
#include "Gui/TimeLineGui.h"
#include "Gui/Gui.h"
#include "Gui/SequenceFileDialog.h"
#include "Gui/TabWidget.h"
#include "Gui/NodeGui.h"
#include "Gui/SpinBox.h"
#include "Gui/ComboBox.h"
#include "Gui/LineEdit.h"
#include "Gui/CurveEditor.h"
#include "Gui/ScaleSlider.h"

#include "Readers/Reader.h"


#define SLIDER_MAX_RANGE 100000

using namespace Natron;
using std::make_pair;

KnobGui::KnobGui(Knob* knob,DockablePanel* container)
    : _knob(knob)
    , _triggerNewLine(true)
    , _spacingBetweenItems(0)
    , _widgetCreated(false)
    , _container(container)
    , _animationMenu(NULL)
    , _animationButton(NULL)
{
    QObject::connect(knob,SIGNAL(valueChanged(int)),this,SLOT(onInternalValueChanged(int)));
    QObject::connect(this,SIGNAL(valueChanged(int,const Variant&)),knob,SLOT(onValueChanged(int,const Variant&)));
    QObject::connect(knob,SIGNAL(secretChanged()),this,SLOT(setSecret()));
    QObject::connect(knob,SIGNAL(enabledChanged()),this,SLOT(setEnabled()));
    QObject::connect(knob,SIGNAL(deleted()),this,SLOT(deleteKnob()));
    // QObject::connect(this, SIGNAL(knobUndoneChange()), knob, SLOT(onKnobUndoneChange()));
    //QObject::connect(this, SIGNAL(knobRedoneChange()), knob, SLOT(onKnobRedoneChange()));
}

KnobGui::~KnobGui(){
    
    emit deleted(this);
    delete _animationButton;
    delete _animationMenu;
}

void KnobGui::pushUndoCommand(QUndoCommand* cmd){
    if(_knob->canBeUndone() && !_knob->isInsignificant()){
        _container->pushUndoCommand(cmd);
    }else{
        cmd->redo();
    }
}



void KnobGui::moveToLayout(QVBoxLayout* layout){
    QWidget* container = new QWidget(layout->parentWidget());
    QHBoxLayout* containerLayout = new QHBoxLayout(container);
    container->setLayout(containerLayout);
    containerLayout->setContentsMargins(0, 0, 0, 0);
    addToLayout(containerLayout);
    layout->addWidget(container);
}

void KnobGui::createGUI(QGridLayout* layout,int row){
    createWidget(layout, row);
    if(_knob->isAnimationEnabled() && !_knob->isSecret()){
        createAnimationButton(layout,row);
    }
    _widgetCreated = true;
    const std::map<int,Variant>& values = _knob->getValueForEachDimension();
    for(std::map<int,Variant>::const_iterator it = values.begin();it!=values.end();++it){
        updateGUI(it->first,it->second);
    }
    setEnabled();
    setSecret();
}

void KnobGui::createAnimationButton(QGridLayout* layout,int row){
    createAnimationMenu(layout->parentWidget());
    _animationButton = new Button("A",layout->parentWidget());
    _animationButton->setToolTip("Animation menu");
    QObject::connect(_animationButton,SIGNAL(clicked()),this,SLOT(showAnimationMenu()));
    layout->addWidget(_animationButton, row, 3,Qt::AlignLeft);
}

void KnobGui::createAnimationMenu(QWidget* parent){
    _animationMenu = new QMenu(parent);
    QAction* setKeyAction = new QAction(tr("Set Key"),_animationMenu);
    QObject::connect(setKeyAction,SIGNAL(triggered()),this,SLOT(onSetKeyActionTriggered()));
    _animationMenu->addAction(setKeyAction);
    
    QAction* showInCurveEditorAction = new QAction(tr("Show in curve editor"),_animationMenu);
    QObject::connect(showInCurveEditorAction,SIGNAL(triggered()),this,SLOT(onShowInCurveEditorActionTriggered()));
    _animationMenu->addAction(showInCurveEditorAction);
    
}

void KnobGui::setSecret() {
    if (!_knob->isSecret()) {
        if(_knob->getParentKnob() && _knob->getParentKnob()->isSecret()){
            return;
        }
        show();
    } else {
        hide();
    }
}

void KnobGui::showAnimationMenu(){
    _animationMenu->exec(_animationButton->mapToGlobal(QPoint(0,0)));<commit_msg>secret bug is still here<commit_after>//  Natron
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
 *Created by <NAME> on 6/1/2012.
 *contact: immarespond at gmail dot com
 *
 */

// TODO: split into KnobGui.cpp, KnobGuiFile.cpp and KnobGuiTypes.cpp

#include "Gui/KnobGui.h"

#include <cassert>
#ifdef __NATRON_UNIX__
#include <dlfcn.h>
#endif
#include <climits>
#include <cfloat>
#include <QtCore/QString>
#include <QHBoxLayout>
#include <QPushButton>
#include <QCheckBox>
#include <QLabel>
#include <QFileDialog>
#include <QTextEdit>
#if QT_VERSION < 0x050000
CLANG_DIAG_OFF(unused-private-field);
#include <QtGui/qmime.h>
CLANG_DIAG_ON(unused-private-field);
#endif
#include <QKeyEvent>
#include <QColorDialog>
#include <QGroupBox>
#include <QtGui/QVector4D>
#include <QStyleFactory>


#include "Global/AppManager.h"
#include "Global/LibraryBinary.h"
#include "Global/GlobalDefines.h"

#include "Engine/Node.h"
#include "Engine/VideoEngine.h"
#include "Engine/ViewerInstance.h"
#include "Engine/Settings.h"
#include "Engine/Knob.h"
#include "Engine/KnobFile.h"
#include "Engine/KnobTypes.h"
#include "Engine/TimeLine.h"

#include "Gui/Button.h"
#include "Gui/DockablePanel.h"
#include "Gui/ViewerTab.h"
#include "Gui/TimeLineGui.h"
#include "Gui/Gui.h"
#include "Gui/SequenceFileDialog.h"
#include "Gui/TabWidget.h"
#include "Gui/NodeGui.h"
#include "Gui/SpinBox.h"
#include "Gui/ComboBox.h"
#include "Gui/LineEdit.h"
#include "Gui/CurveEditor.h"
#include "Gui/ScaleSlider.h"

#include "Readers/Reader.h"


#define SLIDER_MAX_RANGE 100000

using namespace Natron;
using std::make_pair;

KnobGui::KnobGui(Knob* knob,DockablePanel* container)
    : _knob(knob)
    , _triggerNewLine(true)
    , _spacingBetweenItems(0)
    , _widgetCreated(false)
    , _container(container)
    , _animationMenu(NULL)
    , _animationButton(NULL)
{
    QObject::connect(knob,SIGNAL(valueChanged(int)),this,SLOT(onInternalValueChanged(int)));
    QObject::connect(this,SIGNAL(valueChanged(int,const Variant&)),knob,SLOT(onValueChanged(int,const Variant&)));
    QObject::connect(knob,SIGNAL(secretChanged()),this,SLOT(setSecret()));
    QObject::connect(knob,SIGNAL(enabledChanged()),this,SLOT(setEnabled()));
    QObject::connect(knob,SIGNAL(deleted()),this,SLOT(deleteKnob()));
    // QObject::connect(this, SIGNAL(knobUndoneChange()), knob, SLOT(onKnobUndoneChange()));
    //QObject::connect(this, SIGNAL(knobRedoneChange()), knob, SLOT(onKnobRedoneChange()));
}

KnobGui::~KnobGui(){
    
    emit deleted(this);
    delete _animationButton;
    delete _animationMenu;
}

void KnobGui::pushUndoCommand(QUndoCommand* cmd){
    if(_knob->canBeUndone() && !_knob->isInsignificant()){
        _container->pushUndoCommand(cmd);
    }else{
        cmd->redo();
    }
}



void KnobGui::moveToLayout(QVBoxLayout* layout){
    QWidget* container = new QWidget(layout->parentWidget());
    QHBoxLayout* containerLayout = new QHBoxLayout(container);
    container->setLayout(containerLayout);
    containerLayout->setContentsMargins(0, 0, 0, 0);
    addToLayout(containerLayout);
    layout->addWidget(container);
}

void KnobGui::createGUI(QGridLayout* layout,int row){
    createWidget(layout, row);
    if(_knob->isAnimationEnabled() && !_knob->isSecret()){
        createAnimationButton(layout,row);
    }
    _widgetCreated = true;
    const std::map<int,Variant>& values = _knob->getValueForEachDimension();
    for(std::map<int,Variant>::const_iterator it = values.begin();it!=values.end();++it){
        updateGUI(it->first,it->second);
    }
    setEnabled();
    setSecret();
}

void KnobGui::createAnimationButton(QGridLayout* layout,int row){
    createAnimationMenu(layout->parentWidget());
    _animationButton = new Button("A",layout->parentWidget());
    _animationButton->setToolTip("Animation menu");
    QObject::connect(_animationButton,SIGNAL(clicked()),this,SLOT(showAnimationMenu()));
    layout->addWidget(_animationButton, row, 3,Qt::AlignLeft);
}

void KnobGui::createAnimationMenu(QWidget* parent){
    _animationMenu = new QMenu(parent);
    QAction* setKeyAction = new QAction(tr("Set Key"),_animationMenu);
    QObject::connect(setKeyAction,SIGNAL(triggered()),this,SLOT(onSetKeyActionTriggered()));
    _animationMenu->addAction(setKeyAction);
    
    QAction* showInCurveEditorAction = new QAction(tr("Show in curve editor"),_animationMenu);
    QObject::connect(showInCurveEditorAction,SIGNAL(triggered()),this,SLOT(onShowInCurveEditorActionTriggered()));
    _animationMenu->addAction(showInCurveEditorAction);
    
}

void KnobGui::setSecret() {
#warning "FIXME: if the Knob is within a group, only show it if the group is unfolded!"
    // FIXME: if the Knob is within a group, only show it if the group is unfolded!
    //It is not fixed.
    //try TuttlePinning: fold all groups, then switch from perspective to affine to perspective.
    //you will see that it is NOT fixed.
    //VISIBILITY is different from SECRETNESS. The code considers that both things are equivalent, which is wrong.
    // the code should also check if it is within a *group* and if the *group* is checked or not. if it is
    // not checked, don't show.
    // the problem is to get the parent GUI Knob, not the Knob itself.
    // The only way I see would be to add a _group member to KnobGui.
    // Of course, this check has to be *recursive* (in case the group is within a folded group)
    if (!_knob->isSecret()) {
        if(_knob->getParentKnob() && _knob->getParentKnob()->isSecret()){
            return;
        }
        show(); //
    } else {
        hide();
    }
}

void KnobGui::showAnimationMenu(){
    _animationMenu->exec(_animationButton->mapToGlobal(QPoint(0,0)));
{'fraction_non_alphanumeric': 0.14584870848708487, 'fraction_numerical': 0.005904059040590406, 'mean_word_length': 5.121400338791643, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6764569', 'n_tokens_mistral': 3707, 'n_tokens_neox': 3639, 'n_words': 717}