Loading external color profiles

This commit is contained in:
Jakub Melka 2019-12-25 14:34:37 +01:00
parent 2aae9b6cf4
commit 02dda6980c
7 changed files with 375 additions and 125 deletions

View File

@ -17,6 +17,8 @@
#include "pdfcms.h"
#include <QApplication>
#pragma warning(push)
#pragma warning(disable:5033)
#include <lcms2.h>
@ -25,6 +27,46 @@
namespace pdf
{
QString getInfoFromProfile(cmsHPROFILE profile, cmsInfoType infoType)
{
QLocale locale;
QString country = QLocale::countryToString(locale.country());
QString language = QLocale::languageToString(locale.language());
char countryCode[3] = { };
char languageCode[3] = { };
if (country.size() == 2)
{
countryCode[0] = country[0].toLatin1();
countryCode[1] = country[1].toLatin1();
}
if (language.size() == 2)
{
languageCode[0] = language[0].toLatin1();
languageCode[1] = language[1].toLatin1();
}
// Jakub Melka: try to get profile info from current language/country.
// If it fails, then pick any language/any country.
cmsUInt32Number bufferSize = cmsGetProfileInfo(profile, infoType, languageCode, countryCode, nullptr, 0);
if (bufferSize)
{
std::vector<wchar_t> buffer(bufferSize, 0);
cmsGetProfileInfo(profile, infoType, languageCode, countryCode, buffer.data(), static_cast<cmsUInt32Number>(buffer.size()));
return QString::fromWCharArray(buffer.data());
}
bufferSize = cmsGetProfileInfo(profile, infoType, cmsNoLanguage, cmsNoCountry, nullptr, 0);
if (bufferSize)
{
std::vector<wchar_t> buffer(bufferSize, 0);
cmsGetProfileInfo(profile, infoType, cmsNoLanguage, cmsNoCountry, buffer.data(), static_cast<cmsUInt32Number>(buffer.size()));
return QString::fromWCharArray(buffer.data());
}
return QString();
}
bool PDFCMSGeneric::isCompatible(const PDFCMSSettings& settings) const
{
return settings.system == PDFCMSSettings::System::Generic;
@ -69,35 +111,62 @@ PDFCMSManager::PDFCMSManager(QObject* parent) :
}
const PDFColorSpaceIdentifiers& PDFCMSManager::getOutputProfiles() const
void PDFCMSManager::setSettings(const PDFCMSSettings& settings)
{
if (m_settings != settings)
{
// We must ensure, that mutex is not locked, while we are
// sending signal about CMS change.
{
QMutexLocker lock(&m_mutex);
m_settings = settings;
m_outputProfiles.dirty();
m_grayProfiles.dirty();
m_RGBProfiles.dirty();
m_CMYKProfiles.dirty();
m_externalProfiles.dirty();
}
emit colorManagementSystemChanged();
}
}
const PDFColorProfileIdentifiers& PDFCMSManager::getOutputProfiles() const
{
QMutexLocker lock(&m_mutex);
return m_outputProfiles.get(this, &PDFCMSManager::getOutputProfilesImpl);
}
const PDFColorSpaceIdentifiers& PDFCMSManager::getGrayProfiles() const
const PDFColorProfileIdentifiers& PDFCMSManager::getGrayProfiles() const
{
QMutexLocker lock(&m_mutex);
return m_grayProfiles.get(this, &PDFCMSManager::getGrayProfilesImpl);
}
const PDFColorSpaceIdentifiers& PDFCMSManager::getRGBProfiles() const
const PDFColorProfileIdentifiers& PDFCMSManager::getRGBProfiles() const
{
QMutexLocker lock(&m_mutex);
return m_RGBProfiles.get(this, &PDFCMSManager::getRGBProfilesImpl);
}
const PDFColorSpaceIdentifiers& PDFCMSManager::getCMYKProfiles() const
const PDFColorProfileIdentifiers& PDFCMSManager::getCMYKProfiles() const
{
QMutexLocker lock(&m_mutex);
return m_CMYKProfiles.get(this, &PDFCMSManager::getCMYKProfilesImpl);
}
const PDFColorProfileIdentifiers& PDFCMSManager::getExternalProfiles() const
{
// Jakub Melka: do not protect this by mutex, this function is private
// and must be called only from mutex-protected code.
return m_externalProfiles.get(this, &PDFCMSManager::getExternalProfilesImpl);
}
PDFCMSSettings PDFCMSManager::getDefaultSettings() const
{
PDFCMSSettings settings;
auto getFirstProfileId = [](const PDFColorSpaceIdentifiers& identifiers)
auto getFirstProfileId = [](const PDFColorProfileIdentifiers& identifiers)
{
if (!identifiers.empty())
{
@ -139,51 +208,145 @@ QString PDFCMSManager::getSystemName(PDFCMSSettings::System system)
return QString();
}
PDFColorSpaceIdentifiers PDFCMSManager::getOutputProfilesImpl() const
PDFColorProfileIdentifiers PDFCMSManager::getOutputProfilesImpl() const
{
// Currently, we only support sRGB output color profile.
return { PDFColorSpaceIdentifier::createSRGB() };
return { PDFColorProfileIdentifier::createSRGB() };
}
PDFColorSpaceIdentifiers PDFCMSManager::getGrayProfilesImpl() const
PDFColorProfileIdentifiers PDFCMSManager::getGrayProfilesImpl() const
{
// Jakub Melka: We create gray profiles for temperature 5000K, 6500K and 9300K.
// We also use linear gamma and gamma value 2.2.
return {
PDFColorSpaceIdentifier::createGray(tr("Gray D65, γ = 2.2"), "@GENERIC_Gray_D65_g22", 6500.0, 2.2),
PDFColorSpaceIdentifier::createGray(tr("Gray D50, γ = 2.2"), "@GENERIC_Gray_D50_g22", 5000.0, 2.2),
PDFColorSpaceIdentifier::createGray(tr("Gray D93, γ = 2.2"), "@GENERIC_Gray_D93_g22", 9300.0, 2.2),
PDFColorSpaceIdentifier::createGray(tr("Gray D65, γ = 1.0 (linear)"), "@GENERIC_Gray_D65_g10", 6500.0, 1.0),
PDFColorSpaceIdentifier::createGray(tr("Gray D50, γ = 1.0 (linear)"), "@GENERIC_Gray_D50_g10", 5000.0, 1.0),
PDFColorSpaceIdentifier::createGray(tr("Gray D93, γ = 1.0 (linear)"), "@GENERIC_Gray_D93_g10", 9300.0, 1.0)
PDFColorProfileIdentifiers result =
{
PDFColorProfileIdentifier::createGray(tr("Gray D65, γ = 2.2"), "@GENERIC_Gray_D65_g22", 6500.0, 2.2),
PDFColorProfileIdentifier::createGray(tr("Gray D50, γ = 2.2"), "@GENERIC_Gray_D50_g22", 5000.0, 2.2),
PDFColorProfileIdentifier::createGray(tr("Gray D93, γ = 2.2"), "@GENERIC_Gray_D93_g22", 9300.0, 2.2),
PDFColorProfileIdentifier::createGray(tr("Gray D65, γ = 1.0 (linear)"), "@GENERIC_Gray_D65_g10", 6500.0, 1.0),
PDFColorProfileIdentifier::createGray(tr("Gray D50, γ = 1.0 (linear)"), "@GENERIC_Gray_D50_g10", 5000.0, 1.0),
PDFColorProfileIdentifier::createGray(tr("Gray D93, γ = 1.0 (linear)"), "@GENERIC_Gray_D93_g10", 9300.0, 1.0)
};
PDFColorProfileIdentifiers externalRGBProfiles = getFilteredExternalProfiles(PDFColorProfileIdentifier::Type::FileGray);
result.insert(result.end(), externalRGBProfiles.begin(), externalRGBProfiles.end());
return result;
}
PDFColorSpaceIdentifiers PDFCMSManager::getRGBProfilesImpl() const
PDFColorProfileIdentifiers PDFCMSManager::getRGBProfilesImpl() const
{
// Jakub Melka: We create RGB profiles for common standars and also for
// default standard sRGB. See https://en.wikipedia.org/wiki/Color_spaces_with_RGB_primaries.
return {
PDFColorSpaceIdentifier::createSRGB(),
PDFColorSpaceIdentifier::createRGB(tr("HDTV (ITU-R BT.709)"), "@GENERIC_RGB_HDTV", 6500, QPointF(0.64, 0.33), QPointF(0.30, 0.60), QPointF(0.15, 0.06), 20.0 / 9.0),
PDFColorSpaceIdentifier::createRGB(tr("Adobe RGB 1998"), "@GENERIC_RGB_Adobe1998", 6500, QPointF(0.64, 0.33), QPointF(0.30, 0.60), QPointF(0.15, 0.06), 563.0 / 256.0),
PDFColorSpaceIdentifier::createRGB(tr("PAL / SECAM"), "@GENERIC_RGB_PalSecam", 6500, QPointF(0.64, 0.33), QPointF(0.29, 0.60), QPointF(0.15, 0.06), 14.0 / 5.0),
PDFColorSpaceIdentifier::createRGB(tr("NTSC"), "@GENERIC_RGB_NTSC", 6500, QPointF(0.64, 0.34), QPointF(0.31, 0.595), QPointF(0.155, 0.07), 20.0 / 9.0),
PDFColorSpaceIdentifier::createRGB(tr("Adobe Wide Gamut RGB"), "@GENERIC_RGB_AdobeWideGamut", 5000, QPointF(0.735, 0.265), QPointF(0.115, 0.826), QPointF(0.157, 0.018), 563.0 / 256.0),
PDFColorSpaceIdentifier::createRGB(tr("ProPhoto RGB"), "@GENERIC_RGB_ProPhoto", 5000, QPointF(0.7347, 0.2653), QPointF(0.1596, 0.8404), QPointF(0.0366, 0.0001), 9.0 / 5.0)
PDFColorProfileIdentifiers result =
{
PDFColorProfileIdentifier::createSRGB(),
PDFColorProfileIdentifier::createRGB(tr("HDTV (ITU-R BT.709)"), "@GENERIC_RGB_HDTV", 6500, QPointF(0.64, 0.33), QPointF(0.30, 0.60), QPointF(0.15, 0.06), 20.0 / 9.0),
PDFColorProfileIdentifier::createRGB(tr("Adobe RGB 1998"), "@GENERIC_RGB_Adobe1998", 6500, QPointF(0.64, 0.33), QPointF(0.30, 0.60), QPointF(0.15, 0.06), 563.0 / 256.0),
PDFColorProfileIdentifier::createRGB(tr("PAL / SECAM"), "@GENERIC_RGB_PalSecam", 6500, QPointF(0.64, 0.33), QPointF(0.29, 0.60), QPointF(0.15, 0.06), 14.0 / 5.0),
PDFColorProfileIdentifier::createRGB(tr("NTSC"), "@GENERIC_RGB_NTSC", 6500, QPointF(0.64, 0.34), QPointF(0.31, 0.595), QPointF(0.155, 0.07), 20.0 / 9.0),
PDFColorProfileIdentifier::createRGB(tr("Adobe Wide Gamut RGB"), "@GENERIC_RGB_AdobeWideGamut", 5000, QPointF(0.735, 0.265), QPointF(0.115, 0.826), QPointF(0.157, 0.018), 563.0 / 256.0),
PDFColorProfileIdentifier::createRGB(tr("ProPhoto RGB"), "@GENERIC_RGB_ProPhoto", 5000, QPointF(0.7347, 0.2653), QPointF(0.1596, 0.8404), QPointF(0.0366, 0.0001), 9.0 / 5.0)
};
PDFColorProfileIdentifiers externalRGBProfiles = getFilteredExternalProfiles(PDFColorProfileIdentifier::Type::FileRGB);
result.insert(result.end(), externalRGBProfiles.begin(), externalRGBProfiles.end());
return result;
}
PDFColorSpaceIdentifiers PDFCMSManager::getCMYKProfilesImpl() const
PDFColorProfileIdentifiers PDFCMSManager::getCMYKProfilesImpl() const
{
return {
};
return getFilteredExternalProfiles(PDFColorProfileIdentifier::Type::FileCMYK);
}
PDFColorSpaceIdentifier PDFColorSpaceIdentifier::createGray(QString name, QString id, PDFReal temperature, PDFReal gamma)
PDFColorProfileIdentifiers PDFCMSManager::getExternalColorProfiles(QString profileDirectory) const
{
PDFColorSpaceIdentifier result;
PDFColorProfileIdentifiers result;
QDir directory(profileDirectory);
if (!profileDirectory.isEmpty() && directory.exists())
{
QStringList iccProfiles = directory.entryList({ "*.icc" }, QDir::Files | QDir::Readable | QDir::NoDotAndDotDot, QDir::NoSort);
for (const QString& fileName : iccProfiles)
{
QString filePath = directory.absoluteFilePath(fileName);
// Try to read the profile from the file. If it fails, then do nothing.
QFile file(filePath);
if (file.open(QFile::ReadOnly))
{
QByteArray content = file.readAll();
file.close();
cmsHPROFILE profile = cmsOpenProfileFromMem(content.data(), content.size());
if (profile)
{
PDFColorProfileIdentifier::Type csiType = PDFColorProfileIdentifier::Type::Invalid;
const cmsColorSpaceSignature colorSpace = cmsGetColorSpace(profile);
switch (colorSpace)
{
case cmsSigGrayData:
csiType = PDFColorProfileIdentifier::Type::FileGray;
break;
case cmsSigRgbData:
csiType = PDFColorProfileIdentifier::Type::FileRGB;
break;
case cmsSigCmykData:
csiType = PDFColorProfileIdentifier::Type::FileCMYK;
break;
default:
break;
}
QString description = getInfoFromProfile(profile, cmsInfoDescription);
cmsCloseProfile(profile);
// If we have a valid profile, then add it
if (csiType != PDFColorProfileIdentifier::Type::Invalid)
{
result.emplace_back(PDFColorProfileIdentifier::createFile(csiType, qMove(description), filePath));
}
}
}
}
}
return result;
}
PDFColorProfileIdentifiers PDFCMSManager::getExternalProfilesImpl() const
{
PDFColorProfileIdentifiers result;
QStringList directories(m_settings.profileDirectory);
QDir applicationDirectory(QApplication::applicationDirPath());
if (applicationDirectory.cd("colorprofiles"))
{
directories << applicationDirectory.absolutePath();
}
for (const QString& directory : directories)
{
PDFColorProfileIdentifiers externalProfiles = getExternalColorProfiles(directory);
result.insert(result.end(), externalProfiles.begin(), externalProfiles.end());
}
return result;
}
PDFColorProfileIdentifiers PDFCMSManager::getFilteredExternalProfiles(PDFColorProfileIdentifier::Type type) const
{
PDFColorProfileIdentifiers result;
const PDFColorProfileIdentifiers& externalProfiles = getExternalProfiles();
std::copy_if(externalProfiles.cbegin(), externalProfiles.cend(), std::back_inserter(result), [type](const PDFColorProfileIdentifier& identifier) { return identifier.type == type; });
return result;
}
PDFColorProfileIdentifier PDFColorProfileIdentifier::createGray(QString name, QString id, PDFReal temperature, PDFReal gamma)
{
PDFColorProfileIdentifier result;
result.type = Type::Gray;
result.name = qMove(name);
result.id = qMove(id);
@ -192,18 +355,18 @@ PDFColorSpaceIdentifier PDFColorSpaceIdentifier::createGray(QString name, QStrin
return result;
}
PDFColorSpaceIdentifier PDFColorSpaceIdentifier::createSRGB()
PDFColorProfileIdentifier PDFColorProfileIdentifier::createSRGB()
{
PDFColorSpaceIdentifier result;
PDFColorProfileIdentifier result;
result.type = Type::sRGB;
result.name = PDFCMSManager::tr("sRGB");
result.id = "@GENERIC_sRGB";
return result;
}
PDFColorSpaceIdentifier PDFColorSpaceIdentifier::createRGB(QString name, QString id, PDFReal temperature, QPointF primaryR, QPointF primaryG, QPointF primaryB, PDFReal gamma)
PDFColorProfileIdentifier PDFColorProfileIdentifier::createRGB(QString name, QString id, PDFReal temperature, QPointF primaryR, QPointF primaryG, QPointF primaryB, PDFReal gamma)
{
PDFColorSpaceIdentifier result;
PDFColorProfileIdentifier result;
result.type = Type::RGB;
result.name = qMove(name);
result.id = qMove(id);
@ -215,5 +378,14 @@ PDFColorSpaceIdentifier PDFColorSpaceIdentifier::createRGB(QString name, QString
return result;
}
PDFColorProfileIdentifier PDFColorProfileIdentifier::createFile(Type type, QString name, QString id)
{
PDFColorProfileIdentifier result;
result.type = type;
result.name = qMove(name);
result.id = qMove(id);
return result;
}
} // namespace pdf

View File

@ -61,10 +61,11 @@ struct PDFCMSSettings
RenderingIntent intent = RenderingIntent::Auto;
bool isBlackPointCompensationActive = true;
bool isWhitePaperColorTransformed = false;
QString outputCS; ///< Output (rendering) color space
QString deviceGray; ///< Identifiers for color space (device gray)
QString deviceRGB; ///< Identifiers for color space (device RGB)
QString deviceCMYK; ///< Identifiers for color space (device CMYK)
QString outputCS; ///< Output (rendering) color space
QString deviceGray; ///< Identifiers for color space (device gray)
QString deviceRGB; ///< Identifiers for color space (device RGB)
QString deviceCMYK; ///< Identifiers for color space (device CMYK)
QString profileDirectory; ///< Directory containing color profiles
};
/// Color management system base class. It contains functions to transform
@ -132,14 +133,17 @@ public:
virtual QColor getColorFromXYZ(const PDFColor3& whitePoint, const PDFColor& color, RenderingIntent intent, PDFRenderErrorReporter* reporter) const override;
};
struct PDFColorSpaceIdentifier
struct PDFColorProfileIdentifier
{
enum class Type
{
Gray,
sRGB,
RGB,
CMYK
FileGray,
FileRGB,
FileCMYK,
Invalid
};
Type type = Type::sRGB;
@ -151,15 +155,15 @@ struct PDFColorSpaceIdentifier
QPointF primaryB;
PDFReal gamma = 1.0;
/// Creates gray color space identifier
/// Creates gray color profile identifier
/// \param name Name of color profile
/// \param id Identifier of color profile
/// \param temperature White point temperature
/// \param gamma Gamma correction
static PDFColorSpaceIdentifier createGray(QString name, QString id, PDFReal temperature, PDFReal gamma);
static PDFColorProfileIdentifier createGray(QString name, QString id, PDFReal temperature, PDFReal gamma);
/// Creates sRGB color space identifier
static PDFColorSpaceIdentifier createSRGB();
/// Creates sRGB color profile identifier
static PDFColorProfileIdentifier createSRGB();
/// Creates RGB color space identifier
/// \param name Name of color profile
@ -169,10 +173,13 @@ struct PDFColorSpaceIdentifier
/// \param primaryG Primary green
/// \param primaryB Primary blue
/// \param gamma Gamma correction
static PDFColorSpaceIdentifier createRGB(QString name, QString id, PDFReal temperature, QPointF primaryR, QPointF primaryG, QPointF primaryB, PDFReal gamma);
static PDFColorProfileIdentifier createRGB(QString name, QString id, PDFReal temperature, QPointF primaryR, QPointF primaryG, QPointF primaryB, PDFReal gamma);
/// Create file color profile identifier
static PDFColorProfileIdentifier createFile(Type type, QString name, QString id);
};
using PDFColorSpaceIdentifiers = std::vector<PDFColorSpaceIdentifier>;
using PDFColorProfileIdentifiers = std::vector<PDFColorProfileIdentifier>;
/// Manager, that manages current color management system and also list
/// of usable input and output color profiles. It has color profiles
@ -190,10 +197,13 @@ private:
public:
explicit PDFCMSManager(QObject* parent);
const PDFColorSpaceIdentifiers& getOutputProfiles() const;
const PDFColorSpaceIdentifiers& getGrayProfiles() const;
const PDFColorSpaceIdentifiers& getRGBProfiles() const;
const PDFColorSpaceIdentifiers& getCMYKProfiles() const;
const PDFCMSSettings& getSettings() const { return m_settings; }
void setSettings(const PDFCMSSettings& settings);
const PDFColorProfileIdentifiers& getOutputProfiles() const;
const PDFColorProfileIdentifiers& getGrayProfiles() const;
const PDFColorProfileIdentifiers& getRGBProfiles() const;
const PDFColorProfileIdentifiers& getCMYKProfiles() const;
/// Returns default color management settings
PDFCMSSettings getDefaultSettings() const;
@ -206,18 +216,34 @@ signals:
void colorManagementSystemChanged();
private:
PDFColorSpaceIdentifiers getOutputProfilesImpl() const;
PDFColorSpaceIdentifiers getGrayProfilesImpl() const;
PDFColorSpaceIdentifiers getRGBProfilesImpl() const;
PDFColorSpaceIdentifiers getCMYKProfilesImpl() const;
/// This function returns external profiles. It is not protected by mutex,
/// so it is not thread-safe. For this reason, it is not in public
/// interface.
const PDFColorProfileIdentifiers& getExternalProfiles() const;
PDFColorProfileIdentifiers getOutputProfilesImpl() const;
PDFColorProfileIdentifiers getGrayProfilesImpl() const;
PDFColorProfileIdentifiers getRGBProfilesImpl() const;
PDFColorProfileIdentifiers getCMYKProfilesImpl() const;
PDFColorProfileIdentifiers getExternalProfilesImpl() const;
/// Returns filtered list of external profiles (list are filtered by type,
/// so, for example, only CMYK profiles are returned)
/// \param type Type of profile
PDFColorProfileIdentifiers getFilteredExternalProfiles(PDFColorProfileIdentifier::Type type) const;
/// Gets list of color profiles from external directory
/// \param profileDirectory Directory with profiles
PDFColorProfileIdentifiers getExternalColorProfiles(QString profileDirectory) const;
PDFCMSSettings m_settings;
mutable QMutex m_mutex;
mutable PDFCachedItem<PDFColorSpaceIdentifiers> m_outputProfiles;
mutable PDFCachedItem<PDFColorSpaceIdentifiers> m_grayProfiles;
mutable PDFCachedItem<PDFColorSpaceIdentifiers> m_RGBProfiles;
mutable PDFCachedItem<PDFColorSpaceIdentifiers> m_CMYKProfiles;
mutable PDFCachedItem<PDFColorProfileIdentifiers> m_outputProfiles;
mutable PDFCachedItem<PDFColorProfileIdentifiers> m_grayProfiles;
mutable PDFCachedItem<PDFColorProfileIdentifiers> m_RGBProfiles;
mutable PDFCachedItem<PDFColorProfileIdentifiers> m_CMYKProfiles;
mutable PDFCachedItem<PDFColorProfileIdentifiers> m_externalProfiles;
};
} // namespace pdf

View File

@ -546,6 +546,7 @@ void PDFViewerMainWindow::readSettings()
}
m_settings->readSettings(settings, m_CMSManager->getDefaultSettings());
m_CMSManager->setSettings(m_settings->getColorManagementSystemSettings());
}
void PDFViewerMainWindow::readActionSettings()
@ -981,6 +982,7 @@ void PDFViewerMainWindow::on_actionOptions_triggered()
{
m_settings->setSettings(dialog.getSettings());
m_settings->setColorManagementSystemSettings(dialog.getCMSSettings());
m_CMSManager->setSettings(m_settings->getColorManagementSystemSettings());
}
}

View File

@ -65,6 +65,7 @@ void PDFViewerSettings::readSettings(QSettings& settings, const pdf::PDFCMSSetti
m_colorManagementSystemSettings.deviceGray = settings.value("deviceGray", defaultCMSSettings.deviceGray).toString();
m_colorManagementSystemSettings.deviceRGB = settings.value("deviceRGB", defaultCMSSettings.deviceRGB).toString();
m_colorManagementSystemSettings.deviceCMYK = settings.value("deviceCMYK", defaultCMSSettings.deviceCMYK).toString();
m_colorManagementSystemSettings.profileDirectory = settings.value("profileDirectory", defaultCMSSettings.profileDirectory).toString();
settings.endGroup();
emit settingsChanged();
@ -100,6 +101,7 @@ void PDFViewerSettings::writeSettings(QSettings& settings)
settings.setValue("deviceGray", m_colorManagementSystemSettings.deviceGray);
settings.setValue("deviceRGB", m_colorManagementSystemSettings.deviceRGB);
settings.setValue("deviceCMYK", m_colorManagementSystemSettings.deviceCMYK);
settings.setValue("profileDirectory", m_colorManagementSystemSettings.profileDirectory);
settings.endGroup();
}

View File

@ -24,6 +24,7 @@
#include <QAction>
#include <QLineEdit>
#include <QMessageBox>
#include <QFileDialog>
#include <QListWidgetItem>
namespace pdfviewer
@ -72,9 +73,9 @@ PDFViewerSettingsDialog::PDFViewerSettingsDialog(const PDFViewerSettings::Settin
ui->cmsAccuracyComboBox->addItem(tr("Medium"), int(pdf::PDFCMSSettings::Accuracy::Medium));
ui->cmsAccuracyComboBox->addItem(tr("High"), int(pdf::PDFCMSSettings::Accuracy::High));
auto fillColorProfileList = [](QComboBox* comboBox, const pdf::PDFColorSpaceIdentifiers& identifiers)
auto fillColorProfileList = [](QComboBox* comboBox, const pdf::PDFColorProfileIdentifiers& identifiers)
{
for (const pdf::PDFColorSpaceIdentifier& identifier : identifiers)
for (const pdf::PDFColorProfileIdentifier& identifier : identifiers)
{
comboBox->addItem(identifier.name, identifier.id);
}
@ -105,6 +106,10 @@ PDFViewerSettingsDialog::PDFViewerSettingsDialog(const PDFViewerSettings::Settin
{
connect(spinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &PDFViewerSettingsDialog::saveData);
}
for (QLineEdit* lineEdit : findChildren<QLineEdit*>())
{
connect(lineEdit, &QLineEdit::editingFinished, this, &PDFViewerSettingsDialog::saveData);
}
for (QAction* action : actions)
{
@ -239,6 +244,9 @@ void PDFViewerSettingsDialog::loadData()
ui->cmsDeviceRGBColorProfileComboBox->setCurrentIndex(ui->cmsDeviceRGBColorProfileComboBox->findData(m_cmsSettings.deviceRGB));
ui->cmsDeviceCMYKColorProfileComboBox->setEnabled(true);
ui->cmsDeviceCMYKColorProfileComboBox->setCurrentIndex(ui->cmsDeviceCMYKColorProfileComboBox->findData(m_cmsSettings.deviceCMYK));
ui->cmsProfileDirectoryButton->setEnabled(true);
ui->cmsProfileDirectoryEdit->setEnabled(true);
ui->cmsProfileDirectoryEdit->setText(m_cmsSettings.profileDirectory);
}
else
{
@ -258,6 +266,9 @@ void PDFViewerSettingsDialog::loadData()
ui->cmsDeviceRGBColorProfileComboBox->setCurrentIndex(-1);
ui->cmsDeviceCMYKColorProfileComboBox->setEnabled(false);
ui->cmsDeviceCMYKColorProfileComboBox->setCurrentIndex(-1);
ui->cmsProfileDirectoryButton->setEnabled(false);
ui->cmsProfileDirectoryEdit->setEnabled(false);
ui->cmsProfileDirectoryEdit->setText(QString());
}
}
@ -382,6 +393,10 @@ void PDFViewerSettingsDialog::saveData()
{
m_cmsSettings.deviceCMYK = ui->cmsDeviceCMYKColorProfileComboBox->currentData().toString();
}
else if (sender == ui->cmsProfileDirectoryEdit)
{
m_cmsSettings.profileDirectory = ui->cmsProfileDirectoryEdit->text();
}
loadData();
}
@ -446,4 +461,14 @@ void PDFViewerSettingsDialog::accept()
}
}
void PDFViewerSettingsDialog::on_cmsProfileDirectoryButton_clicked()
{
QString directory = QFileDialog::getExistingDirectory(this, tr("Select color profile directory"));
if (!directory.isEmpty())
{
m_cmsSettings.profileDirectory = directory;
loadData();
}
}
} // namespace pdfviewer

View File

@ -69,6 +69,8 @@ public:
private slots:
void on_optionsPagesWidget_currentItemChanged(QListWidgetItem* current, QListWidgetItem* previous);
void on_cmsProfileDirectoryButton_clicked();
private:
void loadData();
void saveData();

View File

@ -585,35 +585,18 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QGridLayout" name="cmsWidgetsLayout">
<item row="0" column="1">
<widget class="QComboBox" name="cmsTypeComboBox"/>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="cmsWhitePaperColorTransformedCheckBox">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="cmsWhitePaperColorTransformedLabel">
<property name="text">
<string>White paper color transformed</string>
</property>
</widget>
</item>
<layout class="QGridLayout" name="cmsWidgetsLayout" columnstretch="1,1">
<item row="7" column="0">
<widget class="QLabel" name="cmsDeviceRGBProfileLabel">
<widget class="QLabel" name="cmsDeviceGrayColorProfileLabel">
<property name="text">
<string>Device RGB color profile</string>
<string>Device gray color profile</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="cmsOutputProfileLabel">
<item row="9" column="0">
<widget class="QLabel" name="cmsDeviceCMYKColorProfileLabel">
<property name="text">
<string>Output color profile</string>
<string>Device CMYK color profile</string>
</property>
</widget>
</item>
@ -625,36 +608,9 @@
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="cmsDeviceGrayColorProfileLabel">
<widget class="QLabel" name="cmsOutputProfileLabel">
<property name="text">
<string>Device gray color profile</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cmsRenderingIntentComboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="cmsRenderingIntentLabel">
<property name="text">
<string>Rendering intent</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="cmsAccuracyComboBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="cmsAccuracyLabel">
<property name="text">
<string>Accuracy</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="cmsLabel">
<property name="text">
<string>Color management system</string>
<string>Output color profile</string>
</property>
</widget>
</item>
@ -665,24 +621,89 @@
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="cmsDeviceCMYKColorProfileLabel">
<item row="1" column="1">
<widget class="QComboBox" name="cmsRenderingIntentComboBox"/>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="cmsAccuracyComboBox"/>
</item>
<item row="7" column="1">
<widget class="QComboBox" name="cmsDeviceGrayColorProfileComboBox"/>
</item>
<item row="6" column="1">
<widget class="QComboBox" name="cmsOutputColorProfileComboBox"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="cmsWhitePaperColorTransformedLabel">
<property name="text">
<string>Device CMYK color profile</string>
<string>White paper color transformed</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QComboBox" name="cmsDeviceRGBColorProfileComboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="cmsRenderingIntentLabel">
<property name="text">
<string>Rendering intent</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="cmsDeviceRGBProfileLabel">
<property name="text">
<string>Device RGB color profile</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cmsTypeComboBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="cmsAccuracyLabel">
<property name="text">
<string>Accuracy</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="cmsWhitePaperColorTransformedCheckBox">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QComboBox" name="cmsDeviceCMYKColorProfileComboBox"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="cmsLabel">
<property name="text">
<string>Color management system</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="cmsProfileDirectoryLabel">
<property name="text">
<string>Additional color profile directory</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="cmsOutputColorProfileComboBox"/>
</item>
<item row="6" column="1">
<widget class="QComboBox" name="cmsDeviceGrayColorProfileComboBox"/>
</item>
<item row="7" column="1">
<widget class="QComboBox" name="cmsDeviceRGBColorProfileComboBox"/>
</item>
<item row="8" column="1">
<widget class="QComboBox" name="cmsDeviceCMYKColorProfileComboBox"/>
<layout class="QHBoxLayout" name="cmsProfileDirectoryLayout">
<item>
<widget class="QLineEdit" name="cmsProfileDirectoryEdit"/>
</item>
<item>
<widget class="QToolButton" name="cmsProfileDirectoryButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>