kis_dlg_image_properties.cc 6.53 KB
Newer Older
1
/*
2
 *  Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
3 4 5 6 7 8 9 10 11 12 13 14 15
 *
 *  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 2 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, write to the Free Software
16
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
 */
Adrian Page's avatar
Adrian Page committed
18

Boudewijn Rempt's avatar
Boudewijn Rempt committed
19 20
#include "kis_dlg_image_properties.h"

21
#include <QPushButton>
22
#include <QRadioButton>
23 24 25
#include <QLayout>
#include <QLabel>
#include <QSpinBox>
26
#include <QSlider>
27
#include <QCheckBox>
28
#include <QPlainTextEdit>
29
#include <QTextEdit>
30

31
#include <klocalizedstring.h>
Boudewijn Rempt's avatar
Boudewijn Rempt committed
32

33

34
#include <KoColorSpace.h>
35
#include "KoColorProfile.h"
36
#include "KoColorSpaceRegistry.h"
37
#include "KoColor.h"
38
#include "KoColorConversionTransformation.h"
39
#include "KoColorPopupAction.h"
40
#include "kis_icon_utils.h"
41
#include "KoID.h"
42
#include "kis_image.h"
43
#include "kis_annotation.h"
44
#include "kis_config.h"
45
#include "kis_signal_compressor.h"
46 47
#include "widgets/kis_cmb_idlist.h"
#include "widgets/squeezedcombobox.h"
48
#include "kis_layer_utils.h"
49

50
KisDlgImageProperties::KisDlgImageProperties(KisImageWSP image, QWidget *parent, const char *name)
Boudewijn Rempt's avatar
Boudewijn Rempt committed
51
    : KoDialog(parent)
52
{
Boudewijn Rempt's avatar
Boudewijn Rempt committed
53 54
    setButtons(Ok | Cancel);
    setDefaultButton(Ok);
55
    setObjectName(name);
56
    setCaption(i18n("Image Properties"));
57
    m_page = new WdgImageProperties(this);
58

59
    m_image = image;
60

61
    setMainWidget(m_page);
62
    resize(m_page->sizeHint());
63

64
    KisConfig cfg;
65

66 67
    m_page->lblWidthValue->setText(QString::number(image->width()));
    m_page->lblHeightValue->setText(QString::number(image->height()));
68

69
    m_page->lblResolutionValue->setText(QLocale().toString(image->xRes()*72, 2)); // XXX: separate values for x & y?
70

71
    //Set the canvas projection color:
72 73 74 75 76 77 78 79 80 81 82
    m_defaultColorAction = new KoColorPopupAction(this);
    m_defaultColorAction->setCurrentColor(m_image->defaultProjectionColor());
    m_defaultColorAction->setToolTip(i18n("Change the background color of the image"));
    m_page->bnBackgroundColor->setDefaultAction(m_defaultColorAction);

    KisSignalCompressor *compressor = new KisSignalCompressor(500 /* ms */, KisSignalCompressor::POSTPONE, this);
    connect(m_defaultColorAction, SIGNAL(colorChanged(const KoColor&)), compressor, SLOT(start()));
    connect(compressor, SIGNAL(timeout()), this, SLOT(setCurrentColor()));

    connect(m_defaultColorAction, SIGNAL(colorChanged(const KoColor&)), this, SLOT(setCurrentColor()));

83
    //Set the color space
84 85
    m_page->colorSpaceSelector->setCurrentColorSpace(image->colorSpace());

86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
    //set the proofing space
    m_proofingConfig = m_image->proofingConfiguration();
    m_page->proofSpaceSelector->setCurrentColorSpace(KoColorSpaceRegistry::instance()->colorSpace(m_proofingConfig->proofingModel, m_proofingConfig->proofingDepth,m_proofingConfig->proofingProfile));

    m_page->cmbIntent->setCurrentIndex((int)m_proofingConfig->intent);

    m_page->ckbBlackPointComp->setChecked(m_proofingConfig->conversionFlags.testFlag(KoColorConversionTransformation::BlackpointCompensation));

    m_gamutWarning = new KoColorPopupAction(this);
    m_gamutWarning->setCurrentColor(m_proofingConfig->warningColor);
    m_gamutWarning->setToolTip(i18n("Set color used for warning"));
    m_page->gamutAlarm->setDefaultAction(m_gamutWarning);

    KisSignalCompressor *softProofConfigCompressor = new KisSignalCompressor(500, KisSignalCompressor::POSTPONE,this);

    connect(m_gamutWarning, SIGNAL(colorChanged(KoColor)), softProofConfigCompressor, SLOT(start()));
    connect(m_page->proofSpaceSelector, SIGNAL(colorSpaceChanged(const KoColorSpace*)), softProofConfigCompressor, SLOT(start()));
    connect(m_page->cmbIntent, SIGNAL(currentIndexChanged(int)), softProofConfigCompressor, SLOT(start()));
    connect(m_page->ckbBlackPointComp, SIGNAL(stateChanged(int)), softProofConfigCompressor, SLOT(start()));

    connect(softProofConfigCompressor, SIGNAL(timeout()), this, SLOT(setProofingConfig()));

    //annotations
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    vKisAnnotationSP_it beginIt = image->beginAnnotations();
    vKisAnnotationSP_it endIt = image->endAnnotations();

    vKisAnnotationSP_it it = beginIt;
    while (it != endIt) {

        if (!(*it) || (*it)->type().isEmpty()) {
            dbgFile << "Warning: empty annotation";
            it++;
            continue;
        }

        m_page->cmbAnnotations->addItem((*it) -> type());
        it++;
    }
    connect(m_page->cmbAnnotations, SIGNAL(activated(QString)), SLOT(setAnnotation(QString)));
    setAnnotation(m_page->cmbAnnotations->currentText());

127 128 129 130
}

KisDlgImageProperties::~KisDlgImageProperties()
{
131
    delete m_page;
132 133
}

134
const KoColorSpace * KisDlgImageProperties::colorSpace()
135
{
136
    return m_page->colorSpaceSelector->currentColorSpace();
137 138
}

139 140
void KisDlgImageProperties::setCurrentColor()
{
141
    KisLayerUtils::changeImageDefaultProjectionColor(m_image, m_defaultColorAction->currentKoColor());
142 143
}

144 145 146 147 148 149 150 151 152 153 154 155 156 157
void KisDlgImageProperties::setProofingConfig()
{
    m_proofingConfig->conversionFlags = KoColorConversionTransformation::HighQuality;
    if (m_page->ckbBlackPointComp) m_proofingConfig->conversionFlags |= KoColorConversionTransformation::BlackpointCompensation;
    m_proofingConfig->intent = (KoColorConversionTransformation::Intent)m_page->cmbIntent->currentIndex();
    m_proofingConfig->proofingProfile = m_page->proofSpaceSelector->currentColorSpace()->profile()->name();
    m_proofingConfig->proofingModel = m_page->proofSpaceSelector->currentColorSpace()->colorModelId().id();
    m_proofingConfig->proofingDepth = "U8";//default to this
    m_proofingConfig->warningColor = m_gamutWarning->currentKoColor();

    qDebug()<<"set proofing config in properties: "<<m_proofingConfig->proofingProfile;
    m_image->setProofingConfiguration(m_proofingConfig);
}

158 159 160 161 162 163 164
void KisDlgImageProperties::setAnnotation(const QString &type)
{
    KisAnnotationSP annotation = m_image->annotation(type);
    if (annotation) {
        m_page->lblDescription->clear();
        m_page->txtAnnotation->clear();
        m_page->lblDescription->setText(annotation->description());
165
        m_page->txtAnnotation->appendPlainText(annotation->displayText());
166 167 168 169 170 171 172
    }
    else {
        m_page->lblDescription->clear();
        m_page->txtAnnotation->clear();
    }
}