File indexing completed on 2024-04-21 15:12:09

0001 /************************************************************************
0002  *                                  *
0003  *  This file is part of Kooka, a scanning/OCR application using    *
0004  *  Qt <http://www.qt.io> and KDE Frameworks <http://www.kde.org>.  *
0005  *                                  *
0006  *  Copyright (C) 2000-2016 Klaas Freitag <freitag@suse.de>     *
0007  *                          Jonathan Marten <jjm@keelhaul.me.uk>    *
0008  *                                  *
0009  *  Kooka is free software; you can redistribute it and/or modify it    *
0010  *  under the terms of the GNU Library General Public License as    *
0011  *  published by the Free Software Foundation and appearing in the  *
0012  *  file COPYING included in the packaging of this file;  either    *
0013  *  version 2 of the License, or (at your option) any later version.    *
0014  *                                  *
0015  *  As a special exception, permission is given to link this program    *
0016  *  with any version of the KADMOS OCR/ICR engine (a product of     *
0017  *  reRecognition GmbH, Kreuzlingen), and distribute the resulting  *
0018  *  executable without including the source code for KADMOS in the  *
0019  *  source distribution.                        *
0020  *                                  *
0021  *  This program is distributed in the hope that it will be useful, *
0022  *  but WITHOUT ANY WARRANTY; without even the implied warranty of  *
0023  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *
0024  *  GNU General Public License for more details.            *
0025  *                                  *
0026  *  You should have received a copy of the GNU General Public       *
0027  *  License along with this program;  see the file COPYING.  If     *
0028  *  not, see <http://www.gnu.org/licenses/>.                *
0029  *                                  *
0030  ************************************************************************/
0031 
0032 #include "gammadialog.h"
0033 
0034 #include <qlabel.h>
0035 #include <qgridlayout.h>
0036 #include <qdialogbuttonbox.h>
0037 #include <qpushbutton.h>
0038 
0039 #include <klocalizedstring.h>
0040 #include <kgammatable.h>
0041 
0042 #include "kscancontrols.h"
0043 #include "gammawidget.h"
0044 
0045 
0046 GammaDialog::GammaDialog(const KGammaTable *table, QWidget *parent)
0047     : DialogBase(parent)
0048 {
0049     setObjectName("GammaDialog");
0050 
0051     setModal(true);
0052     setButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Apply|QDialogButtonBox::Reset);
0053     setWindowTitle(i18n("Edit Gamma Table"));
0054 
0055     mTable = new KGammaTable(*table);           // take our own copy
0056 
0057     QWidget *page = new QWidget(this);
0058     QGridLayout *gl = new QGridLayout(page);
0059 
0060     // Sliders for brightness, contrast, gamma
0061     mSetBright = new KScanSlider(page, i18n("Brightness"));
0062     mSetBright->setRange(-50, 50);
0063     mSetBright->setValue(mTable->getBrightness());
0064     connect(mSetBright, QOverload<int>::of(&KScanSlider::settingChanged), mTable, &KGammaTable::setBrightness);
0065     QLabel *l = new QLabel(mSetBright->label(), page);
0066     l->setBuddy(mSetBright);
0067     gl->setRowMinimumHeight(0, verticalSpacing());
0068     gl->addWidget(l, 1, 0, Qt::AlignRight);
0069     gl->addWidget(mSetBright, 1, 1);
0070 
0071     mSetContrast = new KScanSlider(page, i18n("Contrast"));
0072     mSetContrast->setRange(-50, 50);
0073     mSetContrast->setValue(mTable->getContrast());
0074     connect(mSetContrast, QOverload<int>::of(&KScanSlider::settingChanged), mTable, &KGammaTable::setContrast);
0075     l = new QLabel(mSetContrast->label(), page);
0076     l->setBuddy(mSetContrast);
0077     gl->setRowMinimumHeight(2, verticalSpacing());
0078     gl->addWidget(l, 3, 0, Qt::AlignRight);
0079     gl->addWidget(mSetContrast, 3, 1);
0080 
0081     mSetGamma = new KScanSlider(page, i18n("Gamma"));
0082     mSetGamma->setRange(30, 300);
0083     mSetGamma->setValue(mTable->getGamma());
0084     connect(mSetGamma, QOverload<int>::of(&KScanSlider::settingChanged), mTable, &KGammaTable::setGamma);
0085     l = new QLabel(mSetGamma->label(), page);
0086     l->setBuddy(mSetGamma);
0087     gl->setRowMinimumHeight(4, verticalSpacing());
0088     gl->addWidget(l, 5, 0, Qt::AlignRight);
0089     gl->addWidget(mSetGamma, 5, 1);
0090 
0091     // Explanation label
0092     gl->setRowMinimumHeight(6, verticalSpacing());
0093     gl->setRowStretch(7, 1);
0094 
0095     l = new QLabel(i18n("This gamma table is passed to the scanner hardware."), page);
0096     l->setWordWrap(true);
0097     gl->addWidget(l, 8, 0, 1, 2, Qt::AlignLeft);
0098 
0099     // Gamma curve display
0100     mGtDisplay = new GammaWidget(mTable, page);
0101     mGtDisplay->resize(280, 280);
0102     gl->setColumnMinimumWidth(2, horizontalSpacing());
0103     gl->addWidget(mGtDisplay, 0, 3, -1, 1);
0104     gl->setColumnStretch(3, 1);
0105 //    gl->setColumnStretch(1, 1);
0106 
0107     setMainWidget(page);
0108     connect(buttonBox()->button(QDialogButtonBox::Apply), &QAbstractButton::clicked, this, &GammaDialog::slotApply);
0109     connect(buttonBox()->button(QDialogButtonBox::Reset), &QAbstractButton::clicked, this, &GammaDialog::slotReset);
0110 }
0111 
0112 
0113 void GammaDialog::slotApply()
0114 {
0115     emit gammaToApply(gammaTable());
0116 }
0117 
0118 
0119 void GammaDialog::slotReset()
0120 {
0121     KGammaTable defaultGamma;               // construct with default values
0122     int b = defaultGamma.getBrightness();       // retrieve those values
0123     int c = defaultGamma.getContrast();
0124     int g = defaultGamma.getGamma();
0125 
0126     mSetBright->setValue(b);
0127     mSetContrast->setValue(c);
0128     mSetGamma->setValue(g);
0129 
0130     mTable->setAll(g, b, c);
0131 }