// $Id: profileparms.cpp,v 1.61 2008/03/07 16:29:01 hvengel Exp $
//  Little cms - profiler construction set
//Copyright (C) 2005-2007 Hal Engel
//
// THIS SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
//
// IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
// OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
// WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
// LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
// OF THIS SOFTWARE.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

#include <q3buttongroup.h>
#include <q3groupbox.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
#include <qcombobox.h>

#include "profileparms.h"
#include <lcmsprf.h>

static PROFILERDATA sys;
static bool initialize = true;

QString sm = ProfileParms::tr("(%g) Smoothness:"),
        avdev = ProfileParms::tr("(%g) Avg. Deviation:");

QString parms_get_QTDIR()
{
    // qDebug("get_home_dir");
    const char* qtdir= "QTDIR";
    return  QString::fromLocal8Bit(getenv(qtdir));
}

vcIndex ProfileParms::getCVindex (QString text)
{
    vcIndex value;

    value = iso3664p2;
    if (text == VCqStringValues[cie1161995])
        value = cie1161995;
    else if (text == VCqStringValues[iso3664p1])
        value = iso3664p1;
    else if (text == VCqStringValues[brightOutdoors])
        value = brightOutdoors;
    else if (text == VCqStringValues[cutSheet])
        value = cutSheet;
    else if (text == VCqStringValues[iso3664p2_pcs])
        value = iso3664p2_pcs;
    else if (text == VCqStringValues[sRGB])
        value = sRGB;
    else if (text == VCqStringValues[sRGBannexD])
        value = sRGBannexD;
    else if (text == VCqStringValues[iso9241])
        value = iso9241;
    else if (text == VCqStringValues[projDim])
        value = projDim;
    else if (text == VCqStringValues[projDark])
        value = projDark;
    else if (text == VCqStringValues[brightOutdoors])
        value = brightOutdoors;
    else if (text == VCqStringValues[userdef])
        value = userdef;

    return value;
}

int ProfileParms::currItemFromIndex (int index, BOOL PCS)
{
    switch (sys.hdr.ProfilerTab)
    {
        case 0: //camera scanner tab
            if (!PCS)
            {
                switch (index)
                {
                   case iso3664p2: return 0;
                   case cie1161995: return 1;
                   case iso3664p1: return 2;
                   case brightOutdoors: return 3;
                   case cutSheet: return 4;
                   case userdef: return 5;
                   default: return 0;
                }
            }
            else
            {
                switch (index)
                {
                   case iso3664p2_pcs: return 0;
                   case cie1161995: return 1;
                   case iso3664p1: return 2;
                   case sRGB: return 3;
                   case sRGBannexD: return 4;
                   case iso9241: return 5;
                   case userdef: return 6;
                   default: return 0;
                }
            }
            return 0;
        case 1: // monitor profiler tab
            if (!PCS)
            {
                switch(index)
                {
                   case sRGB: return 0;
                   case sRGBannexD: return 1;
                   case iso9241: return 2;
                   case projDark: return 3;
                   case projDim: return 4;
                   case userdef: return 5;
                }
            }
            else
            {
               switch(index)
               {
                   case iso3664p2_pcs: return 0;
                   case userdef: return 1;
               }
            }
            return 0;
        case 2: // printer profiler tab not implemented yet
            return 0;
        default:
            return 0;
    }

}

void ProfileParms::setVCpresetList()
{
    deviceVCcomboBox -> clear();
    PCSVCcomboBox -> clear();
    source_or_dest_VC_groupBox -> setTitle (tr("Assumed viewing conditions for the captured medium"));
    deviceVCcomboBox -> insertItem (tr(VCqStringValues[iso3664p2].toLocal8Bit()), 0);
    deviceVCcomboBox -> insertItem (tr(VCqStringValues[cie1161995].toLocal8Bit()), 1);
    deviceVCcomboBox -> insertItem (tr(VCqStringValues[iso3664p1].toLocal8Bit()), 2);
    deviceVCcomboBox -> insertItem (tr(VCqStringValues[brightOutdoors].toLocal8Bit()), 3);
    deviceVCcomboBox -> insertItem (tr(VCqStringValues[cutSheet].toLocal8Bit()), 4);
    deviceVCcomboBox -> insertItem (tr(VCqStringValues[userdef].toLocal8Bit()), 5);

    PCSVCcomboBox -> insertItem (tr(VCqStringValues[iso3664p2_pcs].toLocal8Bit()), 0);
    PCSVCcomboBox -> insertItem (tr(VCqStringValues[cie1161995].toLocal8Bit()), 1);
    PCSVCcomboBox -> insertItem (tr(VCqStringValues[iso3664p1].toLocal8Bit()), 2);
    PCSVCcomboBox -> insertItem (tr(VCqStringValues[sRGB].toLocal8Bit()), 3);
    PCSVCcomboBox -> insertItem (tr(VCqStringValues[sRGBannexD].toLocal8Bit()), 4);
    PCSVCcomboBox -> insertItem (tr(VCqStringValues[iso9241].toLocal8Bit()), 5);
    PCSVCcomboBox  -> insertItem (tr(VCqStringValues[userdef].toLocal8Bit()), 6);
}

ProfileParms::ProfileParms(QWidget *parent )
    : QDialog(parent, "", 0, Qt::WStyle_SysMenu | Qt::WStyle_MinMax | Qt::WStyle_Dialog | Qt::WStyle_Title)
{
    setupUi(this);
    connect(VerboseTagsRadio, SIGNAL(toggled(bool)), this, SLOT(slotChangeStrategy()));
    connect(NormalTagsRadio, SIGNAL(toggled(bool)), this, SLOT(slotChangeStrategy()));
    connect(MinimumTagsRadio, SIGNAL(toggled(bool)), this, SLOT(slotChangeStrategy()));
    connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
    connect(buttonOk, SIGNAL(clicked()), this, SLOT(slotOK()));
    connect(buttonHelp, SIGNAL(pressed()), this, SLOT(slotHelpButton()));
    connect(PCSVCcomboBox, SIGNAL(activated(int)), this, SLOT(slotVCpresetChanged()));
    connect(deviceVCcomboBox, SIGNAL(activated(int)), this, SLOT(slotVCpresetChanged()));
    connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
    connect(radioButtonRGBPick, SIGNAL(toggled(bool)), this, SLOT(slotChangeStrategy()));
    connect(radioButtonLab, SIGNAL(toggled(bool)), this, SLOT(slotChangeStrategy()));
    connect(radioButtonXYZ, SIGNAL(toggled(bool)), this, SLOT(slotChangeStrategy()));
    connect(pushButtonPickFromImage, SIGNAL(clicked()), this, SLOT(slotPickButton()));
            

    mainLabel -> setAutoFillBackground ( true ); 
    QPalette pal = mainLabel-> palette();
    pal.setColor(mainLabel ->  backgroundRole(), Qt::white);
    mainLabel -> setPalette(pal);
    
    deviceLaSpinBox -> setMinimum(10.0);
    deviceLaSpinBox -> setSingleStep(1.0);
    deviceLaSpinBox -> setMaximum(3500.0);
    deviceLaSpinBox -> setValue(100.0);

    deviceYbSpinBox -> setMinimum(1.0);
    deviceYbSpinBox -> setSingleStep(1.0);
    deviceYbSpinBox -> setMaximum(100.0);
    deviceYbSpinBox -> setValue(20.0);

    PCSLaSpinBox -> setMinimum(10.0);
    PCSLaSpinBox -> setSingleStep(1.0);
    PCSLaSpinBox -> setMaximum(3500.0);
    PCSLaSpinBox -> setValue(100.0);

    PCSYbSpinBox -> setMinimum(1.0);
    PCSYbSpinBox -> setSingleStep(1.0);
    PCSYbSpinBox -> setMaximum(100.0);
    PCSYbSpinBox -> setValue(20.0);

    wwFloatSpinBoxLab_L -> setMinimum(0.0);
    wwFloatSpinBoxLab_L -> setSingleStep(0.01);
    wwFloatSpinBoxLab_L -> setMaximum(130.15);  // corresponds to Y=200
    wwFloatSpinBoxLab_L -> setValue(0.0);

    wwFloatSpinBoxLab_a -> setMinimum(-127.0);
    wwFloatSpinBoxLab_a -> setSingleStep(0.01);
    wwFloatSpinBoxLab_a -> setMaximum(127.0);
    wwFloatSpinBoxLab_a -> setValue(0.0);

    wwFloatSpinBoxLab_b -> setMinimum(-127.0);
    wwFloatSpinBoxLab_b -> setSingleStep(0.01);
    wwFloatSpinBoxLab_b -> setMaximum(127.0);
    wwFloatSpinBoxLab_b -> setValue(0.0);

    wwFloatSpinBoxXYZ_X -> setMinimum(0.0);
    wwFloatSpinBoxXYZ_X -> setSingleStep(0.01);
    wwFloatSpinBoxXYZ_X -> setMaximum(250.0);   // allow more than Ymax
    wwFloatSpinBoxXYZ_X -> setValue(0.0);

    wwFloatSpinBoxXYZ_Y -> setMinimum(0.0);
    wwFloatSpinBoxXYZ_Y -> setSingleStep(0.01);
    wwFloatSpinBoxXYZ_Y -> setMaximum(200.0);   // allow up to 200%
    wwFloatSpinBoxXYZ_Y -> setValue(0.0);

    wwFloatSpinBoxXYZ_Z -> setMinimum(0.0);
    wwFloatSpinBoxXYZ_Z -> setSingleStep(0.01);
    wwFloatSpinBoxXYZ_Z -> setMaximum(250.0);   // allow more than Ymax
    wwFloatSpinBoxXYZ_Z -> setValue(0.0);

    spinBoxR -> setMinimum(0.0);
    spinBoxR -> setSingleStep(0.0001);
    spinBoxR -> setMaximum(255.0);
    spinBoxR -> setValue(0.0);

    spinBoxG -> setMinimum(0.0);
    spinBoxG -> setSingleStep(0.0001);
    spinBoxG -> setMaximum(255.0);
    spinBoxG -> setValue(0.0);

    spinBoxB -> setMinimum(0.0);
    spinBoxB -> setSingleStep(0.0001);
    spinBoxB -> setMaximum(255.0);
    spinBoxB -> setValue(0.0);

    setVCpresetList();
    smoothnessButtonGroup -> setRadioButtonExclusive ( true );
    smoothnessButtonGroup -> insert(autoSmoothness, -1);
    smoothnessButtonGroup -> insert(manualSmoothness, -1);

    slotCancel();
}

ProfileParms::~ProfileParms()
{
    dialogSize ds;

    ds.put(profParms, this -> height(), this -> width());
}


void ProfileParms::slotShow()
{
    if (initialize)
    {
       // qDebug("ProfileParms::slotShow initialize = true");
       passSys a;
       a.get(&sys);
    }
    else
    {
        passPickedRGB data;

        // qDebug("ProfileParms::slotShow initialize = false");
        data.getPickedRGB(&data);
        sys.hdr.WhitePointParams.RGB[0]=data.RGB[0];
        sys.hdr.WhitePointParams.RGB[1]=data.RGB[1];
        sys.hdr.WhitePointParams.RGB[2]=data.RGB[2];
        initialize = true;
    }
   ValuesToControls();
   this -> raise();
   this -> setVisible(TRUE);
   this -> show();
}

void ProfileParms::slotCancel()
{
   this -> hide();
   // qDebug("in slotCancel");
}


void ProfileParms::ValuesToControls()
{
    // char buff[128];
    // CAMRadio        -> setChecked(sys.hdr.lUseCIECAM02);
    // VonKriesRadio   -> setChecked(!sys.hdr.lUseCIECAM02);
    setVCpresetList();

    switch (sys.hdr.CLUTPoints)
    {
        case 0: RB0 -> setChecked(TRUE); break;
        case 9: RB10 -> setChecked(TRUE); break;
        case 21: RB20 -> setChecked(TRUE); break;
        case 33: RB33 -> setChecked(TRUE); break;
        default:  RB16 -> setChecked(TRUE);
    }

    switch (sys.hdr.ProfileVerbosityLevel)
    {
        case 0: MinimumTagsRadio -> setChecked(TRUE); break;
        case 1: NormalTagsRadio  -> setChecked(TRUE); break;
        case 2:
        default: VerboseTagsRadio -> setChecked(TRUE); break;
    }

    // if (sys.lOptRGCV) qDebug("autosmoothness");
    // else qDebug("manual smoothness");

    manualSmoothness -> setChecked(!sys.lOptRGCV);
    autoSmoothness -> setChecked(sys.lOptRGCV);

    if (manualSmoothness -> isChecked())
       smoothSpinBox -> setValue(int(sys.RsplSmoothness));
    else
       autoSmoothOffset -> setValue(int(sys.RsplSmoothness));

    deviceYbSpinBox -> setValue(sys.hdr.device.Yb);
    deviceLaSpinBox -> setValue(sys.hdr.device.La);
    PCSYbSpinBox -> setValue(sys.hdr.PCS.Yb);
    PCSLaSpinBox -> setValue(sys.hdr.PCS.La);
    deviceSurroundCombo -> setCurrentItem(sys.hdr.device.surround);
    PCSSurroundCombo -> setCurrentItem(sys.hdr.PCS.surround);

    deviceVCcomboBox -> setCurrentItem(currItemFromIndex(sys.hdr.viewingConditionsPredefDevice, FALSE));
    PCSVCcomboBox -> setCurrentItem(currItemFromIndex(sys.hdr.viewingConditionsPredefPCS, TRUE));


    wwFloatSpinBoxLab_L -> setValue(sys.hdr.WhitePointParams.Lab.L);
    wwFloatSpinBoxLab_a -> setValue(sys.hdr.WhitePointParams.Lab.a);
    wwFloatSpinBoxLab_b -> setValue(sys.hdr.WhitePointParams.Lab.b);

    wwFloatSpinBoxXYZ_X -> setValue(sys.hdr.WhitePointParams.XYZ.X);
    wwFloatSpinBoxXYZ_Y -> setValue(sys.hdr.WhitePointParams.XYZ.Y);
    wwFloatSpinBoxXYZ_Z -> setValue(sys.hdr.WhitePointParams.XYZ.Z);

    spinBoxR -> setValue(sys.hdr.WhitePointParams.RGB[0]);
    spinBoxG -> setValue(sys.hdr.WhitePointParams.RGB[1]);
    spinBoxB -> setValue(sys.hdr.WhitePointParams.RGB[2]);

    if (sys.hdr.WhitePointParams.location==WP_LOC_ILLUMINANT)
        radioButtonDiffuse -> setChecked(TRUE);
    else if (sys.hdr.WhitePointParams.location==WP_LOC_DMIN)
       radioButtonDmin -> setChecked(TRUE);
    else if (sys.hdr.WhitePointParams.location==WP_LOC_RGB_255)
       radioButtonAdopt -> setChecked(TRUE);
    else if (sys.hdr.WhitePointParams.location==WP_LOC_RGB)
       radioButtonRGBPick -> setChecked (TRUE);
    else if (sys.hdr.WhitePointParams.location==WP_LOC_LAB)
       radioButtonLab -> setChecked(TRUE);
    else if (sys.hdr.WhitePointParams.location==WP_LOC_XYZ)
       radioButtonXYZ -> setChecked(TRUE);

    if (sys.hdr.WhitePointParams.scale == WP_SCALE_NONE)
        radioButtonDoNotScale -> setChecked(TRUE);
    else if (sys.hdr.WhitePointParams.scale == WP_SCALE_RGB_255_CLIP)
        radioButtonScaleRGBClip -> setChecked(TRUE);
    else // sys.hdr.WhitePointParams.scale == WP_SCALE_RGB_255_DONTCLIP
        radioButtonScaleRGBNoClip -> setChecked(TRUE);

    slotChangeStrategy();
}

void ProfileParms::ControlsToValues()
{
    // qDebug("ProfileParms:ControlsToValues())");
    QString Buff;
    // sys.hdr.lUseCIECAM02   = CAMRadio -> isChecked();
    sys.hdr.device.surround = deviceSurroundCombo -> currentItem();
    sys.hdr.PCS.surround = PCSSurroundCombo -> currentItem();
    sys.hdr.viewingConditionsPredefDevice = getCVindex (deviceVCcomboBox -> currentText());
    sys.hdr.viewingConditionsPredefPCS = getCVindex (PCSVCcomboBox -> currentText());
    // slotVCpresetChanged();

    if (manualSmoothness -> isChecked())
        sys.RsplSmoothness = smoothSpinBox -> value();
    else
        sys.RsplSmoothness = autoSmoothOffset -> value();
    sys.lOptRGCV = autoSmoothness -> isChecked();

    sys.hdr.device.Yb = deviceYbSpinBox -> value();
    sys.hdr.device.La = deviceLaSpinBox -> value();
    sys.hdr.PCS.Yb = PCSYbSpinBox -> value();
    sys.hdr.PCS.La = PCSLaSpinBox -> value();

    if (RB0 -> isChecked())
       sys.hdr.CLUTPoints = 0;
    else
    if(RB10 -> isChecked())
        sys.hdr.CLUTPoints = 9;
    else
    if (RB33 -> isChecked())
        sys.hdr.CLUTPoints = 33;
    else
    if (RB20 -> isChecked())
        sys.hdr.CLUTPoints = 21;
    else
        sys.hdr.CLUTPoints = 17;

    if (radioButtonDiffuse -> isChecked())
        sys.hdr.WhitePointParams.location=WP_LOC_ILLUMINANT;
    else if (radioButtonDmin -> isChecked())
        sys.hdr.WhitePointParams.location=WP_LOC_DMIN;
    else if (radioButtonAdopt -> isChecked())
        sys.hdr.WhitePointParams.location=WP_LOC_RGB_255;
    else if (radioButtonRGBPick -> isChecked())
        sys.hdr.WhitePointParams.location=WP_LOC_RGB;
    else if (radioButtonLab -> isChecked())
        sys.hdr.WhitePointParams.location = WP_LOC_LAB;
    else if (radioButtonXYZ -> isChecked())
        sys.hdr.WhitePointParams.location=WP_LOC_XYZ;

    sys.hdr.WhitePointParams.RGB[0] =spinBoxR -> value();
    sys.hdr.WhitePointParams.RGB[1] =spinBoxG -> value();
    sys.hdr.WhitePointParams.RGB[2] =spinBoxB -> value();

    sys.hdr.WhitePointParams.Lab.L = wwFloatSpinBoxLab_L -> value();
    sys.hdr.WhitePointParams.Lab.a = wwFloatSpinBoxLab_a -> value();
    sys.hdr.WhitePointParams.Lab.b = wwFloatSpinBoxLab_b -> value();

    sys.hdr.WhitePointParams.XYZ.X = wwFloatSpinBoxXYZ_X -> value();
    sys.hdr.WhitePointParams.XYZ.Y = wwFloatSpinBoxXYZ_Y -> value();
    sys.hdr.WhitePointParams.XYZ.Z = wwFloatSpinBoxXYZ_Z -> value();

    if (radioButtonDoNotScale -> isChecked())
        sys.hdr.WhitePointParams.scale = WP_SCALE_NONE;
    else if (radioButtonScaleRGBClip -> isChecked())
        sys.hdr.WhitePointParams.scale = WP_SCALE_RGB_255_CLIP;
    else sys.hdr.WhitePointParams.scale = WP_SCALE_RGB_255_DONTCLIP;

    sys.hdr.ProfileVerbosityLevel = 0;

    if (NormalTagsRadio -> isChecked())
	sys.hdr.ProfileVerbosityLevel = 1;
    else
        if (VerboseTagsRadio -> isChecked())
		sys.hdr.ProfileVerbosityLevel = 2;
}

void ProfileParms::slotPickButton()
{
    sys.hdr.WhitePointParams.location=WP_LOC_RGB;
    initialize = false;
    this -> hide();
    emit signalPickRGB();
}

void ProfileParms::slotChangeStrategy()
{
    // qDebug("ProfileParms::slotChangeStrategy()");
    if (deviceVCcomboBox -> currentText() == VCqStringValues[userdef])
    {
       deviceSurroundCombo -> setEnabled(TRUE);
       deviceLabelSurround -> setEnabled(TRUE);

       deviceLabelLa       -> setEnabled(TRUE);
       deviceLabelYb       -> setEnabled(TRUE);
       deviceLaSpinBox     -> setEnabled(TRUE);
       deviceYbSpinBox     -> setEnabled(TRUE);
    }
    else
    {
       deviceSurroundCombo -> setEnabled(FALSE);
       deviceLabelSurround -> setEnabled(FALSE);

       deviceLabelLa       -> setEnabled(FALSE);
       deviceLabelYb       -> setEnabled(FALSE);
       deviceLaSpinBox     -> setEnabled(FALSE);
       deviceYbSpinBox     -> setEnabled(FALSE);
    }
    if (PCSVCcomboBox -> currentText() == VCqStringValues[userdef])
    {
       PCSSurroundCombo -> setEnabled(TRUE);
       PCSLabelSurround -> setEnabled(TRUE);

       PCSLabelLa       -> setEnabled(TRUE);
       PCSLabelYb       -> setEnabled(TRUE);
       PCSLaSpinBox     -> setEnabled(TRUE);
       PCSYbSpinBox     -> setEnabled(TRUE);
    }
    else
    {
       PCSSurroundCombo -> setEnabled(FALSE);
       PCSLabelSurround -> setEnabled(FALSE);

       PCSLabelLa       -> setEnabled(FALSE);
       PCSLabelYb       -> setEnabled(FALSE);
       PCSLaSpinBox     -> setEnabled(FALSE);
       PCSYbSpinBox     -> setEnabled(FALSE);
    }

    if (radioButtonRGBPick -> isChecked())
        pushButtonPickFromImage -> setEnabled(TRUE);
    else
        pushButtonPickFromImage -> setEnabled(FALSE);

    if (radioButtonRGBPick -> isChecked())
    {
        spinBoxR -> show();
        spinBoxG -> show();
        spinBoxB -> show();
        textLabelR -> show();
        textLabelG -> show();
        textLabelB -> show();
    }
    else
    {
        spinBoxR -> hide();
        spinBoxG -> hide();
        spinBoxB -> hide();
        textLabelR -> hide();
        textLabelG -> hide();
        textLabelB -> hide();
    }

    if (radioButtonLab -> isChecked())
    {
        wwFloatSpinBoxLab_L -> show();
        wwFloatSpinBoxLab_a -> show();
        wwFloatSpinBoxLab_b -> show();
        textLabelLab_L -> show();
        textLabelLab_a -> show();
        textLabelLab_b -> show();
    }
    else
    {
        wwFloatSpinBoxLab_L -> hide();
        wwFloatSpinBoxLab_a -> hide();
        wwFloatSpinBoxLab_b -> hide();
        textLabelLab_L -> hide();
        textLabelLab_a -> hide();
        textLabelLab_b -> hide();
    }

    if (radioButtonXYZ -> isChecked())
    {
        wwFloatSpinBoxXYZ_X -> show();
        wwFloatSpinBoxXYZ_Y -> show();
        wwFloatSpinBoxXYZ_Z -> show();
        textLabelXYZ_X -> show();
        textLabelXYZ_Y -> show();
        textLabelXYZ_Z -> show();
    }
    else
    {
        wwFloatSpinBoxXYZ_X -> hide();
        wwFloatSpinBoxXYZ_Y -> hide();
        wwFloatSpinBoxXYZ_Z -> hide();
        textLabelXYZ_X -> hide();
        textLabelXYZ_Y -> hide();
        textLabelXYZ_Z -> hide();
    }
    // ControlsToValues();
}

void ProfileParms::SmoothnessChanged()
{
    smoothSpinBox -> setEnabled(manualSmoothness -> isChecked());
    autoSmoothOffset -> setEnabled(autoSmoothness -> isChecked());
}

void ProfileParms::slotVCpresetChanged()
{
    // qDebug("in slotVCpresetChanged");

    sys.hdr.viewingConditionsPredefDevice = getCVindex(deviceVCcomboBox -> currentText());

    switch (sys.hdr.viewingConditionsPredefDevice)
    {
    case iso3664p2: // ISO-3664 P2 Practical Reflection Print
           // qDebug("in slotVCpresetChanged case 0 source");
          deviceSurroundCombo -> setCurrentItem( AVG_SURROUND);    /* Average viewing conditions */
           deviceYbSpinBox -> setValue (20.0);                    /* Grey world */
           deviceLaSpinBox -> setValue (32.0);
           break;
    case iso3664p2_pcs: // ISO-3664 P2 ICC refence medium
           // qDebug("in slotVCpresetChanged case 0 source");
          deviceSurroundCombo -> setCurrentItem( AVG_SURROUND);    /* Average viewing conditions */
           deviceYbSpinBox -> setValue (20.0);                    /* Grey world */
           deviceLaSpinBox -> setValue (32.0);
           break;
    case cie1161995: // CIE 116-1995 dE color difference metric
           // qDebug("in slotVCpresetChanged case 1 source");
          deviceSurroundCombo -> setCurrentItem( AVG_SURROUND);    /* Average viewing conditions */
           deviceYbSpinBox -> setValue (18.0);                   /* Grey world */
           deviceLaSpinBox -> setValue (64.0);                  /* Bright */
           break;
    case iso3664p1:
            // ISO-3664 P1 Critical print evaluation environment
           // qDebug("in slotVCpresetChanged case 2 source");
          deviceSurroundCombo -> setCurrentItem( AVG_SURROUND);    /* Average viewing conditions */
           deviceYbSpinBox -> setValue (20.0);                   /* Grey world */
           deviceLaSpinBox -> setValue (127.0);                  /* Bright */
           break;
    case brightOutdoors: // Original scene - Bright Outdoors
            // qDebug("in slotVCpresetChanged case 8 source");
           deviceSurroundCombo -> setCurrentItem( AVG_SURROUND);    /* Average viewing conditions */
            deviceYbSpinBox -> setValue (20.0);                   /* Grey world */
            deviceLaSpinBox -> setValue (2000.0);                /* Bright Outdoors */
            break;
    case cutSheet: // Cut Sheet Transparencies on a viewing box
             // qDebug("in slotVCpresetChanged case 9 source");
            deviceSurroundCombo -> setCurrentItem( CUTSHEET_SURROUND);  /* Cut sheet viewing conditions */
             deviceYbSpinBox -> setValue (20.0);                   /* Grey world */
             deviceLaSpinBox -> setValue (53.0);                  /* Dim, adapted to slide ? */
             break;
    case sRGB: // Monitor in darkened work environment sRGB
            // qDebug("in slotVCpresetChanged case 3 source");
           deviceSurroundCombo -> setCurrentItem( DIM_SURROUND);                /* Dim viewing conditions */
            deviceYbSpinBox -> setValue (20.0);                   /* Grey world */
            deviceLaSpinBox -> setValue (4.0);                   /* Darkened work environment */
            break;
    case sRGBannexD: // Monitor in typical work environment sRGB annex D
            // qDebug("in slotVCpresetChanged case 4 source");
           deviceSurroundCombo -> setCurrentItem( AVG_SURROUND);    /* Average viewing conditions */
            deviceYbSpinBox -> setValue (20.0);                   /* Grey world */
            deviceLaSpinBox -> setValue (22.0);                  /* Typical work environment */
            break;
    case iso9241: // Monitor in bright work environment ISO 9241
            // qDebug("in slotVCpresetChanged case 5 source");
           deviceSurroundCombo -> setCurrentItem( AVG_SURROUND);    /* Average viewing conditions */
            deviceYbSpinBox -> setValue (20.0);                   /* Grey world */
            deviceLaSpinBox -> setValue (32.0);                  /* Bright work environment */
            break;
    case projDim: // Projector in dim environment
            // qDebug("in slotVCpresetChanged case 6 source");
           deviceSurroundCombo -> setCurrentItem( DIM_SURROUND);                /* Dim viewing conditions */
            deviceYbSpinBox -> setValue (20.0);                   /* Grey world */
            deviceLaSpinBox -> setValue ( 10.0);                  /* Adaptation is from display */
            break;
    case projDark: // Projector in dark environment
            // qDebug("in slotVCpresetChanged case 7 source");
           deviceSurroundCombo -> setCurrentItem( DARK_SURROUND);               /* Dark viewing conditions */
            deviceYbSpinBox -> setValue (20.0);                   /* Grey world */
            deviceLaSpinBox -> setValue (10.0);                  /* Adaptation is from display */
            break;
    case userdef: // user defined don't do anything
             // qDebug("in slotVCpresetChanged case 10 source");
             break;
    default:
           // qDebug("in slotVCpresetChanged case default");
           deviceSurroundCombo -> setCurrentItem( AVG_SURROUND);    /* Average viewing conditions */
           deviceYbSpinBox -> setValue (20.0);                    /* Grey world */
           deviceLaSpinBox -> setValue (32.0);                  /* Compromise brightness */
           break;
    }

    sys.hdr.viewingConditionsPredefPCS = getCVindex(PCSVCcomboBox -> currentText());

    switch (sys.hdr.viewingConditionsPredefPCS)
    {
    case iso3664p2: // ISO-3664 P2 Practical Reflection Print
           // qDebug("in slotVCpresetChanged case 0 source");
           PCSSurroundCombo -> setCurrentItem( AVG_SURROUND);    /* Average viewing conditions */
           PCSYbSpinBox -> setValue (20.0);                    /* Grey world */
           PCSLaSpinBox -> setValue (32.0);
           break;
    case iso3664p2_pcs: // ISO-3664 P2 ICC refence medium
           // qDebug("in slotVCpresetChanged case 0 source");
           PCSSurroundCombo -> setCurrentItem( AVG_SURROUND);    /* Average viewing conditions */
           PCSYbSpinBox -> setValue (20.0);                    /* Grey world */
           PCSLaSpinBox -> setValue (32.0);
           break;
    case cie1161995: // CIE 116-1995 dE color difference metric
           // qDebug("in slotVCpresetChanged case 1 source");
           PCSSurroundCombo -> setCurrentItem( AVG_SURROUND);    /* Average viewing conditions */
           PCSYbSpinBox -> setValue (18.0);                   /* Grey world */
           PCSLaSpinBox -> setValue (64.0);                  /* Bright */
           break;
    case iso3664p1:
            // ISO-3664 P1 Critical print evaluation environment
           // qDebug("in slotVCpresetChanged case 2 source");
           PCSSurroundCombo -> setCurrentItem( AVG_SURROUND);    /* Average viewing conditions */
           PCSYbSpinBox -> setValue (20.0);                   /* Grey world */
           PCSLaSpinBox -> setValue (127.0);                  /* Bright */
           break;
    case brightOutdoors: // Original scene - Bright Outdoors
            // qDebug("in slotVCpresetChanged case 8 source");
            PCSSurroundCombo -> setCurrentItem( AVG_SURROUND);    /* Average viewing conditions */
            PCSYbSpinBox -> setValue (20.0);                   /* Grey world */
            PCSLaSpinBox -> setValue (2000.0);                /* Bright Outdoors */
            break;
    case cutSheet: // Cut Sheet Transparencies on a viewing box
             // qDebug("in slotVCpresetChanged case 9 source");
             PCSSurroundCombo -> setCurrentItem( CUTSHEET_SURROUND);  /* Cut sheet viewing conditions */
             PCSYbSpinBox -> setValue (20.0);                   /* Grey world */
             PCSLaSpinBox -> setValue (53.0);                  /* Dim, adapted to slide ? */
             break;
    case sRGB: // Monitor in darkened work environment sRGB
            // qDebug("in slotVCpresetChanged case 3 source");
            PCSSurroundCombo -> setCurrentItem( DIM_SURROUND);                /* Dim viewing conditions */
            PCSYbSpinBox -> setValue (20.0);                   /* Grey world */
            PCSLaSpinBox -> setValue (4.0);                   /* Darkened work environment */
            break;
    case sRGBannexD: // Monitor in typical work environment sRGB annex D
            // qDebug("in slotVCpresetChanged case 4 source");
            PCSSurroundCombo -> setCurrentItem( AVG_SURROUND);    /* Average viewing conditions */
            PCSYbSpinBox -> setValue (20.0);                   /* Grey world */
            PCSLaSpinBox -> setValue (22.0);                  /* Typical work environment */
            break;
    case iso9241: // Monitor in bright work environment ISO 9241
            // qDebug("in slotVCpresetChanged case 5 source");
            PCSSurroundCombo -> setCurrentItem( AVG_SURROUND);    /* Average viewing conditions */
            PCSYbSpinBox -> setValue (20.0);                   /* Grey world */
            PCSLaSpinBox -> setValue (32.0);                  /* Bright work environment */
            break;
    case projDim: // Projector in dim environment
            // qDebug("in slotVCpresetChanged case 6 source");
            PCSSurroundCombo -> setCurrentItem( DIM_SURROUND);                /* Dim viewing conditions */
            PCSYbSpinBox -> setValue (20.0);                   /* Grey world */
            PCSLaSpinBox -> setValue ( 10.0);                  /* Adaptation is from display */
            break;
    case projDark: // Projector in dark environment
            // qDebug("in slotVCpresetChanged case 7 source");
            PCSSurroundCombo -> setCurrentItem( DARK_SURROUND);               /* Dark viewing conditions */
            PCSYbSpinBox -> setValue (20.0);                   /* Grey world */
            PCSLaSpinBox -> setValue (10.0);                  /* Adaptation is from display */
            break;
    case userdef: // user defined don't do anything
             // qDebug("in slotVCpresetChanged case 10 source");
             break;
    default:
           // qDebug("in slotVCpresetChanged case default");
           PCSSurroundCombo -> setCurrentItem( AVG_SURROUND);    /* Average viewing conditions */
           PCSYbSpinBox -> setValue (20.0);                    /* Grey world */
           PCSLaSpinBox -> setValue (32.0);                  /* Compromise brightness */
           break;
    }
    slotChangeStrategy();
}


void ProfileParms::slotOK()
{
    passSys a;
    dialogSize ds;

    ds.put(profParms, this -> height(), this -> width());
    ControlsToValues();
    a.put(sys);
    emit profileParmsOK();
    this -> hide();
}

void ProfileParms::slotHelpButton()
{
     QString path = get_global_help_path() + QString::fromLocal8Bit("/profile-parms.html");
     // qDebug(path);
     getHelp()->openAssistant ();
     getHelp()->showPage(path);
}

