1 /************************************************************************
2  *									*
3  *  This file is part of Kooka, a scanning/OCR application using	*
4  *  Qt <http://www.qt.io> and KDE Frameworks <http://www.kde.org>.	*
5  *									*
6  *  Copyright (C) 2000-2016 Klaas Freitag <freitag@suse.de>		*
7  *                          Jonathan Marten <jjm@keelhaul.me.uk>	*
8  *									*
9  *  Kooka is free software; you can redistribute it and/or modify it	*
10  *  under the terms of the GNU Library General Public License as	*
11  *  published by the Free Software Foundation and appearing in the	*
12  *  file COPYING included in the packaging of this file;  either	*
13  *  version 2 of the License, or (at your option) any later version.	*
14  *									*
15  *  As a special exception, permission is given to link this program	*
16  *  with any version of the KADMOS OCR/ICR engine (a product of		*
17  *  reRecognition GmbH, Kreuzlingen), and distribute the resulting	*
18  *  executable without including the source code for KADMOS in the	*
19  *  source distribution.						*
20  *									*
21  *  This program is distributed in the hope that it will be useful,	*
22  *  but WITHOUT ANY WARRANTY; without even the implied warranty of	*
23  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the	*
24  *  GNU General Public License for more details.			*
25  *									*
26  *  You should have received a copy of the GNU General Public		*
27  *  License along with this program;  see the file COPYING.  If		*
28  *  not, see <http://www.gnu.org/licenses/>.				*
29  *									*
30  ************************************************************************/
31 
32 #include "gammadialog.h"
33 
34 #include <qlabel.h>
35 #include <qgridlayout.h>
36 #include <qdebug.h>
37 #include <qdialogbuttonbox.h>
38 #include <qpushbutton.h>
39 
40 #include <klocalizedstring.h>
41 #include <kgammatable.h>
42 
43 #include "kscancontrols.h"
44 #include "gammawidget.h"
45 
46 
GammaDialog(const KGammaTable * table,QWidget * parent)47 GammaDialog::GammaDialog(const KGammaTable *table, QWidget *parent)
48     : DialogBase(parent)
49 {
50     setObjectName("GammaDialog");
51 
52     setModal(true);
53     setButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Apply|QDialogButtonBox::Reset);
54     setWindowTitle(i18n("Edit Gamma Table"));
55 
56     mTable = new KGammaTable(*table);			// take our own copy
57 
58     QWidget *page = new QWidget(this);
59     QGridLayout *gl = new QGridLayout(page);
60 
61     // Sliders for brightness, contrast, gamma
62     mSetBright = new KScanSlider(page, i18n("Brightness"), -50, 50);
63     mSetBright->setValue(mTable->getBrightness());
64     connect(mSetBright, SIGNAL(settingChanged(int)), mTable, SLOT(setBrightness(int)));
65     QLabel *l = new QLabel(mSetBright->label(), page);
66     l->setBuddy(mSetBright);
67     gl->setRowMinimumHeight(0, verticalSpacing());
68     gl->addWidget(l, 1, 0, Qt::AlignRight);
69     gl->addWidget(mSetBright, 1, 1);
70 
71     mSetContrast = new KScanSlider(page, i18n("Contrast"), -50, 50);
72     mSetContrast->setValue(mTable->getContrast());
73     connect(mSetContrast, SIGNAL(settingChanged(int)), mTable, SLOT(setContrast(int)));
74     l = new QLabel(mSetContrast->label(), page);
75     l->setBuddy(mSetContrast);
76     gl->setRowMinimumHeight(2, verticalSpacing());
77     gl->addWidget(l, 3, 0, Qt::AlignRight);
78     gl->addWidget(mSetContrast, 3, 1);
79 
80     mSetGamma = new KScanSlider(page, i18n("Gamma"), 30, 300);
81     mSetGamma->setValue(mTable->getGamma());
82     connect(mSetGamma, SIGNAL(settingChanged(int)), mTable, SLOT(setGamma(int)));
83     l = new QLabel(mSetGamma->label(), page);
84     l->setBuddy(mSetGamma);
85     gl->setRowMinimumHeight(4, verticalSpacing());
86     gl->addWidget(l, 5, 0, Qt::AlignRight);
87     gl->addWidget(mSetGamma, 5, 1);
88 
89     // Explanation label
90     gl->setRowMinimumHeight(6, verticalSpacing());
91     gl->setRowStretch(7, 1);
92 
93     l = new QLabel(i18n("This gamma table is passed to the scanner hardware."), page);
94     l->setWordWrap(true);
95     gl->addWidget(l, 8, 0, 1, 2, Qt::AlignLeft);
96 
97     // Gamma curve display
98     mGtDisplay = new GammaWidget(mTable, page);
99     mGtDisplay->resize(280, 280);
100     gl->setColumnMinimumWidth(2, horizontalSpacing());
101     gl->addWidget(mGtDisplay, 0, 3, -1, 1);
102     gl->setColumnStretch(3, 1);
103 //    gl->setColumnStretch(1, 1);
104 
105     setMainWidget(page);
106     connect(buttonBox()->button(QDialogButtonBox::Apply), SIGNAL(clicked()), SLOT(slotApply()));
107     connect(buttonBox()->button(QDialogButtonBox::Reset), SIGNAL(clicked()), SLOT(slotReset()));
108 }
109 
110 
slotApply()111 void GammaDialog::slotApply()
112 {
113     qDebug();
114     emit gammaToApply(gammaTable());
115 }
116 
117 
slotReset()118 void GammaDialog::slotReset()
119 {
120     qDebug();
121     KGammaTable defaultGamma;				// construct with default values
122     int b = defaultGamma.getBrightness();		// retrieve those values
123     int c = defaultGamma.getContrast();
124     int g = defaultGamma.getGamma();
125 
126     mSetBright->setValue(b);
127     mSetContrast->setValue(c);
128     mSetGamma->setValue(g);
129 
130     mTable->setAll(g, b, c);
131 }
132