| File: | libs/dimg/filters/bw/mixersettings.cpp |
| Warning: | line 569, column 9 Read function called when stream is in EOF state. Function has no effect |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* ============================================================ | |||
| 2 | * | |||
| 3 | * This file is a part of digiKam project | |||
| 4 | * https://www.digikam.org | |||
| 5 | * | |||
| 6 | * Date : 2009-02-18 | |||
| 7 | * Description : Channel mixer settings view. | |||
| 8 | * | |||
| 9 | * SPDX-FileCopyrightText: 2010-2025 by Gilles Caulier <caulier dot gilles at gmail dot com> | |||
| 10 | * | |||
| 11 | * SPDX-License-Identifier: GPL-2.0-or-later | |||
| 12 | * | |||
| 13 | * ============================================================ */ | |||
| 14 | ||||
| 15 | #include "mixersettings.h" | |||
| 16 | ||||
| 17 | // Qt includes | |||
| 18 | ||||
| 19 | #include <QGridLayout> | |||
| 20 | #include <QLabel> | |||
| 21 | #include <QString> | |||
| 22 | #include <QFile> | |||
| 23 | #include <QTextStream> | |||
| 24 | #include <QCheckBox> | |||
| 25 | #include <QPushButton> | |||
| 26 | #include <QStandardPaths> | |||
| 27 | #include <QApplication> | |||
| 28 | #include <QStyle> | |||
| 29 | #include <QComboBox> | |||
| 30 | #include <QMessageBox> | |||
| 31 | #include <QUrl> | |||
| 32 | #include <QFontDatabase> | |||
| 33 | ||||
| 34 | // KDE includes | |||
| 35 | ||||
| 36 | #include <kconfiggroup.h> | |||
| 37 | #include <klocalizedstring.h> | |||
| 38 | ||||
| 39 | // Local includes | |||
| 40 | ||||
| 41 | #include "dnuminput.h" | |||
| 42 | #include "dfiledialog.h" | |||
| 43 | #include "dexpanderbox.h" | |||
| 44 | #include "digikam_debug.h" | |||
| 45 | #include "digikam_config.h" | |||
| 46 | ||||
| 47 | namespace Digikam | |||
| 48 | { | |||
| 49 | ||||
| 50 | class Q_DECL_HIDDEN__attribute__((visibility("hidden"))) MixerSettings::Private | |||
| 51 | { | |||
| 52 | public: | |||
| 53 | ||||
| 54 | Private() = default; | |||
| 55 | ||||
| 56 | const QString configMonochromeEntry = QLatin1String("Monochrome"); | |||
| 57 | const QString configPreserveLuminosityEntry = QLatin1String("PreserveLuminosity"); | |||
| 58 | const QString configRedRedGainEntry = QLatin1String("RedRedGain"); | |||
| 59 | const QString configRedGreenGainEntry = QLatin1String("RedGreenGain"); | |||
| 60 | const QString configRedBlueGainEntry = QLatin1String("RedBlueGain"); | |||
| 61 | const QString configGreenRedGainEntry = QLatin1String("GreenRedGain"); | |||
| 62 | const QString configGreenGreenGainEntry = QLatin1String("GreenGreenGain"); | |||
| 63 | const QString configGreenBlueGainEntry = QLatin1String("GreenBlueGain"); | |||
| 64 | const QString configBlueRedGainEntry = QLatin1String("BlueRedGain"); | |||
| 65 | const QString configBlueGreenGainEntry = QLatin1String("BlueGreenGain"); | |||
| 66 | const QString configBlueBlueGainEntry = QLatin1String("BlueBlueGain"); | |||
| 67 | const QString configBlackRedGainEntry = QLatin1String("BlackRedGain"); | |||
| 68 | const QString configBlackGreenGainEntry = QLatin1String("BlackGreenGain"); | |||
| 69 | const QString configBlackBlueGainEntry = QLatin1String("BlackBlueGain"); | |||
| 70 | ||||
| 71 | int currentChannel = RedChannel; | |||
| 72 | ||||
| 73 | QLabel* monochromeTips = nullptr; | |||
| 74 | QLabel* totalPercents = nullptr; | |||
| 75 | QLabel* outChannelLabel = nullptr; | |||
| 76 | ||||
| 77 | QPushButton* resetButton = nullptr; | |||
| 78 | ||||
| 79 | QCheckBox* preserveLuminosity = nullptr; | |||
| 80 | QCheckBox* monochrome = nullptr; | |||
| 81 | ||||
| 82 | QComboBox* outChannelCB = nullptr; | |||
| 83 | ||||
| 84 | MixerContainer mixerSettings; | |||
| 85 | ||||
| 86 | DDoubleNumInput* redGain = nullptr; | |||
| 87 | DDoubleNumInput* greenGain = nullptr; | |||
| 88 | DDoubleNumInput* blueGain = nullptr; | |||
| 89 | }; | |||
| 90 | ||||
| 91 | // -------------------------------------------------------- | |||
| 92 | ||||
| 93 | MixerSettings::MixerSettings(QWidget* const parent) | |||
| 94 | : QWidget(parent), | |||
| 95 | d (new Private) | |||
| 96 | { | |||
| 97 | const int spacing = layoutSpacing(); | |||
| 98 | QGridLayout* const grid = new QGridLayout(this); | |||
| 99 | ||||
| 100 | d->outChannelLabel = new QLabel(i18nc("@label", "Output Channel:")i18ndc("digikam", "@label", "Output Channel:")); | |||
| 101 | d->outChannelCB = new QComboBox; | |||
| 102 | d->outChannelCB->addItem(i18nc("@item: color", "Red")i18ndc("digikam", "@item: color", "Red"), QVariant(RedChannel)); | |||
| 103 | d->outChannelCB->addItem(i18nc("@item: color", "Green")i18ndc("digikam", "@item: color", "Green"), QVariant(GreenChannel)); | |||
| 104 | d->outChannelCB->addItem(i18nc("@item: color", "Blue")i18ndc("digikam", "@item: color", "Blue"), QVariant(BlueChannel)); | |||
| 105 | ||||
| 106 | QLabel* const redLabel = new QLabel(i18nc("@label: color", "Red (%):")i18ndc("digikam", "@label: color", "Red (%):")); | |||
| 107 | d->redGain = new DDoubleNumInput; | |||
| 108 | d->redGain->setDecimals(1); | |||
| 109 | d->redGain->setRange(-200.0, 200.0, 1); | |||
| 110 | d->redGain->setDefaultValue(0); | |||
| 111 | d->redGain->setWhatsThis(i18nc("@info", "Select the red color gain, as a percentage, "i18ndc("digikam", "@info", "Select the red color gain, as a percentage, " "for the current channel.") | |||
| 112 | "for the current channel.")i18ndc("digikam", "@info", "Select the red color gain, as a percentage, " "for the current channel.")); | |||
| 113 | ||||
| 114 | QLabel* const greenLabel = new QLabel(i18nc("@label: color", "Green (%):")i18ndc("digikam", "@label: color", "Green (%):")); | |||
| 115 | d->greenGain = new DDoubleNumInput; | |||
| 116 | d->greenGain->setDecimals(1); | |||
| 117 | d->greenGain->setRange(-200.0, 200.0, 1); | |||
| 118 | d->greenGain->setDefaultValue(0); | |||
| 119 | d->greenGain->setWhatsThis(i18nc("@info", "Select the green color gain, as a percentage, "i18ndc("digikam", "@info", "Select the green color gain, as a percentage, " "for the current channel.") | |||
| 120 | "for the current channel.")i18ndc("digikam", "@info", "Select the green color gain, as a percentage, " "for the current channel.")); | |||
| 121 | ||||
| 122 | QLabel* const blueLabel = new QLabel(i18nc("@label: color", "Blue (%):")i18ndc("digikam", "@label: color", "Blue (%):")); | |||
| 123 | d->blueGain = new DDoubleNumInput; | |||
| 124 | d->blueGain->setDecimals(1); | |||
| 125 | d->blueGain->setRange(-200.0, 200.0, 1); | |||
| 126 | d->blueGain->setDefaultValue(0); | |||
| 127 | d->blueGain->setWhatsThis(i18nc("@info", "Select the blue color gain, as a percentage, "i18ndc("digikam", "@info", "Select the blue color gain, as a percentage, " "for the current channel.") | |||
| 128 | "for the current channel.")i18ndc("digikam", "@info", "Select the blue color gain, as a percentage, " "for the current channel.")); | |||
| 129 | ||||
| 130 | // ------------------------------------------------------------- | |||
| 131 | ||||
| 132 | d->resetButton = new QPushButton(i18nc("@option", "&Reset")i18ndc("digikam", "@option", "&Reset")); | |||
| 133 | d->resetButton->setIcon(QIcon::fromTheme(QLatin1String("document-revert"))); | |||
| 134 | d->resetButton->setWhatsThis(i18nc("@info", "Reset color channels' gains settings from "i18ndc("digikam", "@info", "Reset color channels' gains settings from " "the currently selected channel.") | |||
| 135 | "the currently selected channel.")i18ndc("digikam", "@info", "Reset color channels' gains settings from " "the currently selected channel.")); | |||
| 136 | ||||
| 137 | d->totalPercents = new QLabel(); | |||
| 138 | d->totalPercents->setAlignment(Qt::AlignRight | Qt::AlignVCenter); | |||
| 139 | ||||
| 140 | // ------------------------------------------------------------- | |||
| 141 | ||||
| 142 | d->preserveLuminosity = new QCheckBox(i18nc("@option", "Preserve luminosity")i18ndc("digikam", "@option", "Preserve luminosity")); | |||
| 143 | d->preserveLuminosity->setWhatsThis(i18nc("@info", "Enable this option is you want preserve "i18ndc("digikam", "@info", "Enable this option is you want preserve " "the image luminosity.") | |||
| 144 | "the image luminosity.")i18ndc("digikam", "@info", "Enable this option is you want preserve " "the image luminosity.")); | |||
| 145 | ||||
| 146 | // ------------------------------------------------------------- | |||
| 147 | ||||
| 148 | d->monochrome = new QCheckBox(i18nc("@option: color", "Monochrome")i18ndc("digikam", "@option: color", "Monochrome")); | |||
| 149 | d->monochromeTips = new QLabel(i18nc("@info: help",i18ndc("digikam", "@info: help", "Use \"Monochrome\" mode to convert color picture to Black and White:\n" "The \"red channel\" modifies the contrast of photograph.\n" "The \"green channel\" enhances or reduces the details level of photograph.\n" "The \"blue channel\" affects the noise of photograph.\n" "Note: in this mode, the histogram will display only luminosity values." ) | |||
| 150 | "Use \"Monochrome\" mode to convert color picture to Black and White:\n"i18ndc("digikam", "@info: help", "Use \"Monochrome\" mode to convert color picture to Black and White:\n" "The \"red channel\" modifies the contrast of photograph.\n" "The \"green channel\" enhances or reduces the details level of photograph.\n" "The \"blue channel\" affects the noise of photograph.\n" "Note: in this mode, the histogram will display only luminosity values." ) | |||
| 151 | "The \"red channel\" modifies the contrast of photograph.\n"i18ndc("digikam", "@info: help", "Use \"Monochrome\" mode to convert color picture to Black and White:\n" "The \"red channel\" modifies the contrast of photograph.\n" "The \"green channel\" enhances or reduces the details level of photograph.\n" "The \"blue channel\" affects the noise of photograph.\n" "Note: in this mode, the histogram will display only luminosity values." ) | |||
| 152 | "The \"green channel\" enhances or reduces the details level of photograph.\n"i18ndc("digikam", "@info: help", "Use \"Monochrome\" mode to convert color picture to Black and White:\n" "The \"red channel\" modifies the contrast of photograph.\n" "The \"green channel\" enhances or reduces the details level of photograph.\n" "The \"blue channel\" affects the noise of photograph.\n" "Note: in this mode, the histogram will display only luminosity values." ) | |||
| 153 | "The \"blue channel\" affects the noise of photograph.\n"i18ndc("digikam", "@info: help", "Use \"Monochrome\" mode to convert color picture to Black and White:\n" "The \"red channel\" modifies the contrast of photograph.\n" "The \"green channel\" enhances or reduces the details level of photograph.\n" "The \"blue channel\" affects the noise of photograph.\n" "Note: in this mode, the histogram will display only luminosity values." ) | |||
| 154 | "Note: in this mode, the histogram will display only luminosity values.")i18ndc("digikam", "@info: help", "Use \"Monochrome\" mode to convert color picture to Black and White:\n" "The \"red channel\" modifies the contrast of photograph.\n" "The \"green channel\" enhances or reduces the details level of photograph.\n" "The \"blue channel\" affects the noise of photograph.\n" "Note: in this mode, the histogram will display only luminosity values." )); | |||
| 155 | ||||
| 156 | d->monochromeTips->setEnabled(false); | |||
| 157 | d->monochromeTips->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)); | |||
| 158 | d->monochromeTips->setWordWrap(true); | |||
| 159 | d->monochromeTips->setOpenExternalLinks(true); | |||
| 160 | d->monochromeTips->setFrameStyle(QFrame::StyledPanel | QFrame::Raised); | |||
| 161 | d->monochromeTips->setLineWidth(1); | |||
| 162 | ||||
| 163 | // ------------------------------------------------------------- | |||
| 164 | ||||
| 165 | grid->addWidget(d->outChannelLabel, 0, 0, 1, 1); | |||
| 166 | grid->addWidget(d->outChannelCB, 0, 3, 1, 2); | |||
| 167 | grid->addWidget(redLabel, 1, 0, 1, 1); | |||
| 168 | grid->addWidget(d->redGain, 1, 1, 1, 4); | |||
| 169 | grid->addWidget(greenLabel, 2, 0, 1, 1); | |||
| 170 | grid->addWidget(d->greenGain, 2, 1, 1, 4); | |||
| 171 | grid->addWidget(blueLabel, 3, 0, 1, 1); | |||
| 172 | grid->addWidget(d->blueGain, 3, 1, 1, 4); | |||
| 173 | grid->addWidget(d->resetButton, 4, 0, 1, 2); | |||
| 174 | grid->addWidget(d->totalPercents, 4, 3, 1, 1); | |||
| 175 | grid->addWidget(d->preserveLuminosity, 5, 0, 1, 5); | |||
| 176 | grid->addWidget(d->monochrome, 6, 0, 1, 5); | |||
| 177 | grid->addWidget(d->monochromeTips, 7, 0, 1, 5); | |||
| 178 | grid->setRowStretch(8, 10); | |||
| 179 | grid->setColumnStretch(2, 10); | |||
| 180 | grid->setContentsMargins(spacing, spacing, spacing, spacing); | |||
| 181 | grid->setSpacing(spacing); | |||
| 182 | ||||
| 183 | // ------------------------------------------------------------- | |||
| 184 | ||||
| 185 | connect(d->redGain, SIGNAL(valueChanged(double))qFlagLocation("2" "valueChanged(double)" "\0" "/home/gilles/devel/8.x/core/libs/dimg/filters/bw/mixersettings.cpp" ":" "185"), | |||
| 186 | this, SLOT(slotGainsChanged())qFlagLocation("1" "slotGainsChanged()" "\0" "/home/gilles/devel/8.x/core/libs/dimg/filters/bw/mixersettings.cpp" ":" "186")); | |||
| 187 | ||||
| 188 | connect(d->greenGain, SIGNAL(valueChanged(double))qFlagLocation("2" "valueChanged(double)" "\0" "/home/gilles/devel/8.x/core/libs/dimg/filters/bw/mixersettings.cpp" ":" "188"), | |||
| 189 | this, SLOT(slotGainsChanged())qFlagLocation("1" "slotGainsChanged()" "\0" "/home/gilles/devel/8.x/core/libs/dimg/filters/bw/mixersettings.cpp" ":" "189")); | |||
| 190 | ||||
| 191 | connect(d->blueGain, SIGNAL(valueChanged(double))qFlagLocation("2" "valueChanged(double)" "\0" "/home/gilles/devel/8.x/core/libs/dimg/filters/bw/mixersettings.cpp" ":" "191"), | |||
| 192 | this, SLOT(slotGainsChanged())qFlagLocation("1" "slotGainsChanged()" "\0" "/home/gilles/devel/8.x/core/libs/dimg/filters/bw/mixersettings.cpp" ":" "192")); | |||
| 193 | ||||
| 194 | connect(d->resetButton, SIGNAL(clicked())qFlagLocation("2" "clicked()" "\0" "/home/gilles/devel/8.x/core/libs/dimg/filters/bw/mixersettings.cpp" ":" "194"), | |||
| 195 | this, SLOT(slotResetCurrentChannel())qFlagLocation("1" "slotResetCurrentChannel()" "\0" "/home/gilles/devel/8.x/core/libs/dimg/filters/bw/mixersettings.cpp" ":" "195")); | |||
| 196 | ||||
| 197 | connect(d->monochrome, SIGNAL(toggled(bool))qFlagLocation("2" "toggled(bool)" "\0" "/home/gilles/devel/8.x/core/libs/dimg/filters/bw/mixersettings.cpp" ":" "197"), | |||
| 198 | this, SLOT(slotMonochromeActived(bool))qFlagLocation("1" "slotMonochromeActived(bool)" "\0" "/home/gilles/devel/8.x/core/libs/dimg/filters/bw/mixersettings.cpp" ":" "198")); | |||
| 199 | ||||
| 200 | connect(d->preserveLuminosity, SIGNAL(toggled(bool))qFlagLocation("2" "toggled(bool)" "\0" "/home/gilles/devel/8.x/core/libs/dimg/filters/bw/mixersettings.cpp" ":" "200"), | |||
| 201 | this, SLOT(slotLuminosityChanged(bool))qFlagLocation("1" "slotLuminosityChanged(bool)" "\0" "/home/gilles/devel/8.x/core/libs/dimg/filters/bw/mixersettings.cpp" ":" "201")); | |||
| 202 | ||||
| 203 | connect(d->outChannelCB, SIGNAL(activated(int))qFlagLocation("2" "activated(int)" "\0" "/home/gilles/devel/8.x/core/libs/dimg/filters/bw/mixersettings.cpp" ":" "203"), | |||
| 204 | this, SLOT(slotOutChannelChanged())qFlagLocation("1" "slotOutChannelChanged()" "\0" "/home/gilles/devel/8.x/core/libs/dimg/filters/bw/mixersettings.cpp" ":" "204")); | |||
| 205 | } | |||
| 206 | ||||
| 207 | MixerSettings::~MixerSettings() | |||
| 208 | { | |||
| 209 | delete d; | |||
| 210 | } | |||
| 211 | ||||
| 212 | void MixerSettings::setMonochromeTipsVisible(bool b) | |||
| 213 | { | |||
| 214 | b ? d->monochromeTips->show() | |||
| 215 | : d->monochromeTips->hide(); | |||
| 216 | } | |||
| 217 | ||||
| 218 | void MixerSettings::slotOutChannelChanged() | |||
| 219 | { | |||
| 220 | int index = d->outChannelCB->currentIndex(); | |||
| 221 | d->currentChannel = (ChannelType)(d->outChannelCB->itemData(index).toInt()); | |||
| 222 | updateSettingsWidgets(); | |||
| 223 | Q_EMIT signalOutChannelChanged(); | |||
| 224 | } | |||
| 225 | ||||
| 226 | int MixerSettings::currentChannel() const | |||
| 227 | { | |||
| 228 | return d->currentChannel; | |||
| 229 | } | |||
| 230 | ||||
| 231 | void MixerSettings::slotResetCurrentChannel() | |||
| 232 | { | |||
| 233 | switch (d->currentChannel) | |||
| 234 | { | |||
| 235 | case GreenChannel: | |||
| 236 | { | |||
| 237 | d->mixerSettings.greenRedGain = 0.0; | |||
| 238 | d->mixerSettings.greenGreenGain = 1.0; | |||
| 239 | d->mixerSettings.greenBlueGain = 0.0; | |||
| 240 | break; | |||
| 241 | } | |||
| 242 | ||||
| 243 | case BlueChannel: | |||
| 244 | { | |||
| 245 | d->mixerSettings.blueRedGain = 0.0; | |||
| 246 | d->mixerSettings.blueGreenGain = 0.0; | |||
| 247 | d->mixerSettings.blueBlueGain = 1.0; | |||
| 248 | break; | |||
| 249 | } | |||
| 250 | ||||
| 251 | default: // Red or monochrome. | |||
| 252 | { | |||
| 253 | if (d->monochrome->isChecked()) | |||
| 254 | { | |||
| 255 | d->mixerSettings.blackRedGain = 1.0; | |||
| 256 | d->mixerSettings.blackGreenGain = 0.0; | |||
| 257 | d->mixerSettings.blackBlueGain = 0.0; | |||
| 258 | } | |||
| 259 | else | |||
| 260 | { | |||
| 261 | d->mixerSettings.redRedGain = 1.0; | |||
| 262 | d->mixerSettings.redGreenGain = 0.0; | |||
| 263 | d->mixerSettings.redBlueGain = 0.0; | |||
| 264 | } | |||
| 265 | ||||
| 266 | break; | |||
| 267 | } | |||
| 268 | } | |||
| 269 | ||||
| 270 | updateSettingsWidgets(); | |||
| 271 | Q_EMIT signalSettingsChanged(); | |||
| 272 | } | |||
| 273 | ||||
| 274 | void MixerSettings::slotGainsChanged() | |||
| 275 | { | |||
| 276 | switch (d->currentChannel) | |||
| 277 | { | |||
| 278 | case GreenChannel: | |||
| 279 | { | |||
| 280 | d->mixerSettings.greenRedGain = d->redGain->value() / 100.0; | |||
| 281 | d->mixerSettings.greenGreenGain = d->greenGain->value() / 100.0; | |||
| 282 | d->mixerSettings.greenBlueGain = d->blueGain->value() / 100.0; | |||
| 283 | break; | |||
| 284 | } | |||
| 285 | ||||
| 286 | case BlueChannel: | |||
| 287 | { | |||
| 288 | d->mixerSettings.blueRedGain = d->redGain->value() / 100.0; | |||
| 289 | d->mixerSettings.blueGreenGain = d->greenGain->value() / 100.0; | |||
| 290 | d->mixerSettings.blueBlueGain = d->blueGain->value() / 100.0; | |||
| 291 | break; | |||
| 292 | } | |||
| 293 | ||||
| 294 | default: // Red or monochrome. | |||
| 295 | { | |||
| 296 | if (d->monochrome->isChecked()) | |||
| 297 | { | |||
| 298 | d->mixerSettings.blackRedGain = d->redGain->value() / 100.0; | |||
| 299 | d->mixerSettings.blackGreenGain = d->greenGain->value() / 100.0; | |||
| 300 | d->mixerSettings.blackBlueGain = d->blueGain->value() / 100.0; | |||
| 301 | } | |||
| 302 | else | |||
| 303 | { | |||
| 304 | d->mixerSettings.redRedGain = d->redGain->value() / 100.0; | |||
| 305 | d->mixerSettings.redGreenGain = d->greenGain->value() / 100.0; | |||
| 306 | d->mixerSettings.redBlueGain = d->blueGain->value() / 100.0; | |||
| 307 | } | |||
| 308 | ||||
| 309 | break; | |||
| 310 | } | |||
| 311 | } | |||
| 312 | ||||
| 313 | updateTotalPercents(); | |||
| 314 | Q_EMIT signalSettingsChanged(); | |||
| 315 | } | |||
| 316 | ||||
| 317 | void MixerSettings::updateTotalPercents() | |||
| 318 | { | |||
| 319 | double total = d->redGain->value() + d->greenGain->value() + d->blueGain->value(); | |||
| 320 | QString str; | |||
| 321 | d->totalPercents->setText(i18nc("@info: progress", "Total: %1 (%)", str.asprintf("%3.1f", total))i18ndc("digikam", "@info: progress", "Total: %1 (%)", str.asprintf ("%3.1f", total))); | |||
| 322 | } | |||
| 323 | ||||
| 324 | void MixerSettings::updateSettingsWidgets() | |||
| 325 | { | |||
| 326 | d->monochrome->blockSignals(true); | |||
| 327 | d->preserveLuminosity->blockSignals(true); | |||
| 328 | d->redGain->blockSignals(true); | |||
| 329 | d->greenGain->blockSignals(true); | |||
| 330 | d->blueGain->blockSignals(true); | |||
| 331 | ||||
| 332 | switch (d->currentChannel) | |||
| 333 | { | |||
| 334 | case GreenChannel: | |||
| 335 | { | |||
| 336 | d->redGain->setDefaultValue(0); | |||
| 337 | d->greenGain->setDefaultValue(100); | |||
| 338 | d->blueGain->setDefaultValue(0); | |||
| 339 | d->redGain->setValue(d->mixerSettings.greenRedGain * 100.0); | |||
| 340 | d->greenGain->setValue(d->mixerSettings.greenGreenGain * 100.0); | |||
| 341 | d->blueGain->setValue(d->mixerSettings.greenBlueGain * 100.0); | |||
| 342 | break; | |||
| 343 | } | |||
| 344 | ||||
| 345 | case BlueChannel: | |||
| 346 | { | |||
| 347 | d->redGain->setDefaultValue(0); | |||
| 348 | d->greenGain->setDefaultValue(0); | |||
| 349 | d->blueGain->setDefaultValue(100); | |||
| 350 | d->redGain->setValue(d->mixerSettings.blueRedGain * 100.0); | |||
| 351 | d->greenGain->setValue(d->mixerSettings.blueGreenGain * 100.0); | |||
| 352 | d->blueGain->setValue(d->mixerSettings.blueBlueGain * 100.0); | |||
| 353 | break; | |||
| 354 | } | |||
| 355 | ||||
| 356 | default: // Red or monochrome. | |||
| 357 | { | |||
| 358 | if (d->monochrome->isChecked()) | |||
| 359 | { | |||
| 360 | d->redGain->setDefaultValue(100); | |||
| 361 | d->greenGain->setDefaultValue(0); | |||
| 362 | d->blueGain->setDefaultValue(0); | |||
| 363 | d->redGain->setValue(d->mixerSettings.blackRedGain * 100.0); | |||
| 364 | d->greenGain->setValue(d->mixerSettings.blackGreenGain * 100.0); | |||
| 365 | d->blueGain->setValue(d->mixerSettings.blackBlueGain * 100.0); | |||
| 366 | } | |||
| 367 | else | |||
| 368 | { | |||
| 369 | d->redGain->setDefaultValue(100); | |||
| 370 | d->greenGain->setDefaultValue(0); | |||
| 371 | d->blueGain->setDefaultValue(0); | |||
| 372 | d->redGain->setValue(d->mixerSettings.redRedGain * 100.0); | |||
| 373 | d->greenGain->setValue(d->mixerSettings.redGreenGain * 100.0); | |||
| 374 | d->blueGain->setValue(d->mixerSettings.redBlueGain * 100.0); | |||
| 375 | } | |||
| 376 | ||||
| 377 | break; | |||
| 378 | } | |||
| 379 | } | |||
| 380 | ||||
| 381 | d->monochrome->setChecked(d->mixerSettings.bMonochrome); | |||
| 382 | d->preserveLuminosity->setChecked(d->mixerSettings.bPreserveLum); | |||
| 383 | updateTotalPercents(); | |||
| 384 | ||||
| 385 | d->monochrome->blockSignals(false); | |||
| 386 | d->preserveLuminosity->blockSignals(false); | |||
| 387 | d->redGain->blockSignals(false); | |||
| 388 | d->greenGain->blockSignals(false); | |||
| 389 | d->blueGain->blockSignals(false); | |||
| 390 | } | |||
| 391 | ||||
| 392 | void MixerSettings::slotMonochromeActived(bool mono) | |||
| 393 | { | |||
| 394 | d->mixerSettings.bMonochrome = mono; | |||
| 395 | d->monochromeTips->setEnabled(mono); | |||
| 396 | ||||
| 397 | d->outChannelLabel->setEnabled(!mono); | |||
| 398 | d->outChannelCB->setEnabled(!mono); | |||
| 399 | int id = d->outChannelCB->findData(QVariant(RedChannel)); | |||
| 400 | d->outChannelCB->setCurrentIndex(id); | |||
| 401 | slotOutChannelChanged(); | |||
| 402 | ||||
| 403 | Q_EMIT signalMonochromeActived(mono); | |||
| 404 | Q_EMIT signalSettingsChanged(); | |||
| 405 | } | |||
| 406 | ||||
| 407 | void MixerSettings::slotLuminosityChanged(bool lum) | |||
| 408 | { | |||
| 409 | d->mixerSettings.bPreserveLum = lum; | |||
| 410 | ||||
| 411 | Q_EMIT signalSettingsChanged(); | |||
| 412 | } | |||
| 413 | ||||
| 414 | MixerContainer MixerSettings::settings() const | |||
| 415 | { | |||
| 416 | return d->mixerSettings; | |||
| 417 | } | |||
| 418 | ||||
| 419 | void MixerSettings::setSettings(const MixerContainer& settings) | |||
| 420 | { | |||
| 421 | blockSignals(true); | |||
| 422 | d->mixerSettings = settings; | |||
| 423 | updateSettingsWidgets(); | |||
| 424 | slotMonochromeActived(d->mixerSettings.bMonochrome); | |||
| 425 | blockSignals(false); | |||
| 426 | } | |||
| 427 | ||||
| 428 | void MixerSettings::resetToDefault() | |||
| 429 | { | |||
| 430 | setSettings(defaultSettings()); | |||
| 431 | } | |||
| 432 | ||||
| 433 | MixerContainer MixerSettings::defaultSettings() const | |||
| 434 | { | |||
| 435 | MixerContainer prm; | |||
| 436 | ||||
| 437 | prm.bMonochrome = false; | |||
| 438 | prm.bPreserveLum = true; | |||
| 439 | ||||
| 440 | prm.redRedGain = 1.0; | |||
| 441 | prm.redGreenGain = 0.0; | |||
| 442 | prm.redBlueGain = 0.0; | |||
| 443 | ||||
| 444 | prm.greenRedGain = 0.0; | |||
| 445 | prm.greenGreenGain = 1.0; | |||
| 446 | prm.greenBlueGain = 0.0; | |||
| 447 | ||||
| 448 | prm.blueRedGain = 0.0; | |||
| 449 | prm.blueGreenGain = 0.0; | |||
| 450 | prm.blueBlueGain = 1.0; | |||
| 451 | ||||
| 452 | prm.blackRedGain = 1.0; | |||
| 453 | prm.blackGreenGain = 0.0; | |||
| 454 | prm.blackBlueGain = 0.0; | |||
| 455 | ||||
| 456 | return prm; | |||
| 457 | } | |||
| 458 | ||||
| 459 | void MixerSettings::readSettings(const KConfigGroup& group) | |||
| 460 | { | |||
| 461 | MixerContainer prm; | |||
| 462 | MixerContainer defaultPrm = defaultSettings(); | |||
| 463 | ||||
| 464 | prm.bMonochrome = group.readEntry(d->configMonochromeEntry, defaultPrm.bMonochrome); | |||
| 465 | prm.bPreserveLum = group.readEntry(d->configPreserveLuminosityEntry, defaultPrm.bPreserveLum); | |||
| 466 | ||||
| 467 | prm.redRedGain = group.readEntry(d->configRedRedGainEntry, defaultPrm.redRedGain); | |||
| 468 | prm.redGreenGain = group.readEntry(d->configRedGreenGainEntry, defaultPrm.redGreenGain); | |||
| 469 | prm.redBlueGain = group.readEntry(d->configRedBlueGainEntry, defaultPrm.redBlueGain); | |||
| 470 | ||||
| 471 | prm.greenRedGain = group.readEntry(d->configGreenRedGainEntry, defaultPrm.greenRedGain); | |||
| 472 | prm.greenGreenGain = group.readEntry(d->configGreenGreenGainEntry, defaultPrm.greenGreenGain); | |||
| 473 | prm.greenBlueGain = group.readEntry(d->configGreenBlueGainEntry, defaultPrm.greenBlueGain); | |||
| 474 | ||||
| 475 | prm.blueRedGain = group.readEntry(d->configBlueRedGainEntry, defaultPrm.blueRedGain); | |||
| 476 | prm.blueGreenGain = group.readEntry(d->configBlueGreenGainEntry, defaultPrm.blueGreenGain); | |||
| 477 | prm.blueBlueGain = group.readEntry(d->configBlueBlueGainEntry, defaultPrm.blueBlueGain); | |||
| 478 | ||||
| 479 | prm.blackRedGain = group.readEntry(d->configBlackRedGainEntry, defaultPrm.blackRedGain); | |||
| 480 | prm.blackGreenGain = group.readEntry(d->configBlackGreenGainEntry, defaultPrm.blackGreenGain); | |||
| 481 | prm.blackBlueGain = group.readEntry(d->configBlackBlueGainEntry, defaultPrm.blackBlueGain); | |||
| 482 | ||||
| 483 | setSettings(prm); | |||
| 484 | } | |||
| 485 | ||||
| 486 | void MixerSettings::writeSettings(KConfigGroup& group) | |||
| 487 | { | |||
| 488 | MixerContainer prm = settings(); | |||
| 489 | ||||
| 490 | group.writeEntry(d->configMonochromeEntry, prm.bMonochrome); | |||
| 491 | group.writeEntry(d->configPreserveLuminosityEntry, prm.bPreserveLum); | |||
| 492 | ||||
| 493 | group.writeEntry(d->configRedRedGainEntry, prm.redRedGain); | |||
| 494 | group.writeEntry(d->configRedGreenGainEntry, prm.redGreenGain); | |||
| 495 | group.writeEntry(d->configRedBlueGainEntry, prm.redBlueGain); | |||
| 496 | ||||
| 497 | group.writeEntry(d->configGreenRedGainEntry, prm.greenRedGain); | |||
| 498 | group.writeEntry(d->configGreenGreenGainEntry, prm.greenGreenGain); | |||
| 499 | group.writeEntry(d->configGreenBlueGainEntry, prm.greenBlueGain); | |||
| 500 | ||||
| 501 | group.writeEntry(d->configBlueRedGainEntry, prm.blueRedGain); | |||
| 502 | group.writeEntry(d->configBlueGreenGainEntry, prm.blueGreenGain); | |||
| 503 | group.writeEntry(d->configBlueBlueGainEntry, prm.blueBlueGain); | |||
| 504 | ||||
| 505 | group.writeEntry(d->configBlackRedGainEntry, prm.blackRedGain); | |||
| 506 | group.writeEntry(d->configBlackGreenGainEntry, prm.blackGreenGain); | |||
| 507 | group.writeEntry(d->configBlackBlueGainEntry, prm.blackBlueGain); | |||
| 508 | } | |||
| 509 | ||||
| 510 | void MixerSettings::loadSettings() | |||
| 511 | { | |||
| 512 | QUrl loadGainsFileUrl; | |||
| 513 | FILE* fp = nullptr; | |||
| 514 | MixerContainer settings; | |||
| 515 | ||||
| 516 | loadGainsFileUrl = DFileDialog::getOpenFileUrl(qApp(static_cast<QApplication *>(QCoreApplication::instance ()))->activeWindow(), i18nc("@title:window", "Select Gimp Gains Mixer File to Load")i18ndc("digikam", "@title:window", "Select Gimp Gains Mixer File to Load" ), | |||
| 517 | QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)), | |||
| 518 | QLatin1String("*")); | |||
| 519 | ||||
| 520 | if (loadGainsFileUrl.isEmpty()) | |||
| ||||
| 521 | { | |||
| 522 | return; | |||
| 523 | } | |||
| 524 | ||||
| 525 | #ifdef Q_OS_WIN | |||
| 526 | ||||
| 527 | fp = _wfopen((const wchar_t*)loadGainsFileUrl.toLocalFile().utf16(), L"r"); | |||
| 528 | ||||
| 529 | #else | |||
| 530 | ||||
| 531 | fp = fopen(loadGainsFileUrl.toLocalFile().toUtf8().constData(), "r"); | |||
| 532 | ||||
| 533 | #endif | |||
| 534 | ||||
| 535 | if (fp
| |||
| 536 | { | |||
| 537 | char buf1[1024]; | |||
| 538 | char buf2[1024]; | |||
| 539 | char buf3[1024]; | |||
| 540 | ||||
| 541 | buf1[0] = '\0'; | |||
| 542 | ||||
| 543 | fgets(buf1, 1023, fp); | |||
| 544 | ||||
| 545 | fscanf(fp, "%*s %256s", buf1); | |||
| 546 | fscanf(fp, "%*s %256s", buf1); // preview flag, preserved for compatibility | |||
| 547 | fscanf(fp, "%*s %256s", buf1); | |||
| 548 | ||||
| 549 | if (strcmp(buf1, "true") == 0) | |||
| 550 | { | |||
| 551 | settings.bMonochrome = true; | |||
| 552 | } | |||
| 553 | else | |||
| 554 | { | |||
| 555 | settings.bMonochrome = false; | |||
| 556 | } | |||
| 557 | ||||
| 558 | fscanf(fp, "%*s %256s", buf1); | |||
| 559 | ||||
| 560 | if (strcmp(buf1, "true") == 0) | |||
| 561 | { | |||
| 562 | settings.bPreserveLum = true; | |||
| 563 | } | |||
| 564 | else | |||
| 565 | { | |||
| 566 | settings.bPreserveLum = false; | |||
| 567 | } | |||
| 568 | ||||
| 569 | fscanf(fp, "%*s %256s %256s %256s", buf1, buf2, buf3); | |||
| ||||
| 570 | settings.redRedGain = atof(buf1); | |||
| 571 | settings.redGreenGain = atof(buf2); | |||
| 572 | settings.redBlueGain = atof(buf3); | |||
| 573 | ||||
| 574 | fscanf(fp, "%*s %256s %256s %256s", buf1, buf2, buf3); | |||
| 575 | settings.greenRedGain = atof(buf1); | |||
| 576 | settings.greenGreenGain = atof(buf2); | |||
| 577 | settings.greenBlueGain = atof(buf3); | |||
| 578 | ||||
| 579 | fscanf(fp, "%*s %256s %256s %256s", buf1, buf2, buf3); | |||
| 580 | settings.blueRedGain = atof(buf1); | |||
| 581 | settings.blueGreenGain = atof(buf2); | |||
| 582 | settings.blueBlueGain = atof(buf3); | |||
| 583 | ||||
| 584 | fscanf(fp, "%*s %256s %256s %256s", buf1, buf2, buf3); | |||
| 585 | settings.blackRedGain = atof(buf1); | |||
| 586 | settings.blackGreenGain = atof(buf2); | |||
| 587 | settings.blackBlueGain = atof(buf3); | |||
| 588 | ||||
| 589 | fclose(fp); | |||
| 590 | ||||
| 591 | setSettings(settings); | |||
| 592 | } | |||
| 593 | else | |||
| 594 | { | |||
| 595 | QMessageBox::critical(qApp(static_cast<QApplication *>(QCoreApplication::instance ()))->activeWindow(), qApp(static_cast<QApplication *>(QCoreApplication::instance ()))->applicationName(), | |||
| 596 | i18nc("@info", "Cannot load settings from the Gains Mixer text file.")i18ndc("digikam", "@info", "Cannot load settings from the Gains Mixer text file." )); | |||
| 597 | return; | |||
| 598 | } | |||
| 599 | } | |||
| 600 | ||||
| 601 | void MixerSettings::saveAsSettings() | |||
| 602 | { | |||
| 603 | QUrl saveGainsFileUrl; | |||
| 604 | FILE* fp = nullptr; | |||
| 605 | ||||
| 606 | saveGainsFileUrl = DFileDialog::getSaveFileUrl(qApp(static_cast<QApplication *>(QCoreApplication::instance ()))->activeWindow(), i18nc("@title:window", "Gimp Gains Mixer File to Save")i18ndc("digikam", "@title:window", "Gimp Gains Mixer File to Save" ), | |||
| 607 | QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)), | |||
| 608 | QLatin1String("*")); | |||
| 609 | ||||
| 610 | if (saveGainsFileUrl.isEmpty()) | |||
| 611 | { | |||
| 612 | return; | |||
| 613 | } | |||
| 614 | ||||
| 615 | #ifdef Q_OS_WIN | |||
| 616 | ||||
| 617 | fp = _wfopen((const wchar_t*)saveGainsFileUrl.toLocalFile().utf16(), L"w"); | |||
| 618 | ||||
| 619 | #else | |||
| 620 | ||||
| 621 | fp = fopen(saveGainsFileUrl.toLocalFile().toUtf8().constData(), "w"); | |||
| 622 | ||||
| 623 | #endif | |||
| 624 | ||||
| 625 | if (fp) | |||
| 626 | { | |||
| 627 | const char* str = nullptr; | |||
| 628 | char buf1[256]; | |||
| 629 | char buf2[256]; | |||
| 630 | char buf3[256]; | |||
| 631 | ||||
| 632 | switch (d->currentChannel) | |||
| 633 | { | |||
| 634 | case RedChannel: | |||
| 635 | str = "RED"; | |||
| 636 | break; | |||
| 637 | ||||
| 638 | case GreenChannel: | |||
| 639 | str = "GREEN"; | |||
| 640 | break; | |||
| 641 | ||||
| 642 | case BlueChannel: | |||
| 643 | str = "BLUE"; | |||
| 644 | break; | |||
| 645 | ||||
| 646 | default: | |||
| 647 | qCWarning(DIGIKAM_DIMG_LOG)for (QLoggingCategoryMacroHolder<QtWarningMsg> qt_category ((DIGIKAM_DIMG_LOG)()); qt_category; qt_category.control = false ) QMessageLogger(static_cast<const char *>("/home/gilles/devel/8.x/core/libs/dimg/filters/bw/mixersettings.cpp" ), 647, static_cast<const char *>(__PRETTY_FUNCTION__), qt_category.name()).warning() << "Unknown Color channel gains"; | |||
| 648 | break; | |||
| 649 | } | |||
| 650 | ||||
| 651 | fprintf(fp, "# Channel Mixer Configuration File\n"); | |||
| 652 | ||||
| 653 | fprintf(fp, "CHANNEL: %s\n", str); | |||
| 654 | fprintf(fp, "PREVIEW: %s\n", "true"); // preserved for compatibility | |||
| 655 | fprintf(fp, "MONOCHROME: %s\n", | |||
| 656 | d->mixerSettings.bMonochrome ? "true" : "false"); | |||
| 657 | fprintf(fp, "PRESERVE_LUMINOSITY: %s\n", | |||
| 658 | d->mixerSettings.bPreserveLum ? "true" : "false"); | |||
| 659 | ||||
| 660 | snprintf(buf1, sizeof(buf1), "%5.3f", d->mixerSettings.redRedGain); | |||
| 661 | snprintf(buf2, sizeof(buf2), "%5.3f", d->mixerSettings.redGreenGain); | |||
| 662 | snprintf(buf3, sizeof(buf3), "%5.3f", d->mixerSettings.redBlueGain); | |||
| 663 | fprintf(fp, "RED: %s %s %s\n", buf1, buf2, buf3); | |||
| 664 | ||||
| 665 | snprintf(buf1, sizeof(buf1), "%5.3f", d->mixerSettings.greenRedGain); | |||
| 666 | snprintf(buf2, sizeof(buf2), "%5.3f", d->mixerSettings.greenGreenGain); | |||
| 667 | snprintf(buf3, sizeof(buf3), "%5.3f", d->mixerSettings.greenBlueGain); | |||
| 668 | fprintf(fp, "GREEN: %s %s %s\n", buf1, buf2, buf3); | |||
| 669 | ||||
| 670 | snprintf(buf1, sizeof(buf1), "%5.3f", d->mixerSettings.blueRedGain); | |||
| 671 | snprintf(buf2, sizeof(buf2), "%5.3f", d->mixerSettings.blueGreenGain); | |||
| 672 | snprintf(buf3, sizeof(buf3), "%5.3f", d->mixerSettings.blueBlueGain); | |||
| 673 | fprintf(fp, "BLUE: %s %s %s\n", buf1, buf2, buf3); | |||
| 674 | ||||
| 675 | snprintf(buf1, sizeof(buf1), "%5.3f", d->mixerSettings.blackRedGain); | |||
| 676 | snprintf(buf2, sizeof(buf2), "%5.3f", d->mixerSettings.blackGreenGain); | |||
| 677 | snprintf(buf3, sizeof(buf3), "%5.3f", d->mixerSettings.blackBlueGain); | |||
| 678 | fprintf(fp, "BLACK: %s %s %s\n", buf1, buf2, buf3); | |||
| 679 | ||||
| 680 | fclose(fp); | |||
| 681 | } | |||
| 682 | else | |||
| 683 | { | |||
| 684 | QMessageBox::critical(qApp(static_cast<QApplication *>(QCoreApplication::instance ()))->activeWindow(), qApp(static_cast<QApplication *>(QCoreApplication::instance ()))->applicationName(), | |||
| 685 | i18nc("@info", "Cannot save settings to the Gains Mixer text file.")i18ndc("digikam", "@info", "Cannot save settings to the Gains Mixer text file." )); | |||
| 686 | return; | |||
| 687 | } | |||
| 688 | } | |||
| 689 | ||||
| 690 | } // namespace Digikam | |||
| 691 | ||||
| 692 | #include "moc_mixersettings.cpp" |