• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegraphics API Reference
  • KDE Home
  • Contact Us
 

libs/libksane/libksane

  • sources
  • kde-4.14
  • kdegraphics
  • libs
  • libksane
  • libksane
  • widgets
labeled_gamma.cpp
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is part of the KDE project
4  *
5  * Date : 2007-09-13
6  * Description : Sane interface for KDE
7  *
8  * Copyright (C) 2007-2011 by Kare Sars <kare.sars@iki .fi>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) version 3, or any
14  * later version accepted by the membership of KDE e.V. (or its
15  * successor approved by the membership of KDE e.V.), which shall
16  * act as a proxy defined in Section 6 of version 3 of the license.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License along with this program. If not, see <http://www.gnu.org/licenses/>.
25  *
26  * ============================================================ */
27 
28 // Local includes
29 #include "labeled_gamma.h"
30 #include "labeled_gamma.moc"
31 
32 // C++ includes
33 #include <cmath>
34 
35 // Qt includes
36 #include <QGroupBox>
37 
38 // KDE includes
39 #include <klocale.h>
40 
41 namespace KSaneIface
42 {
43 
44 LabeledGamma::LabeledGamma(QWidget *parent, const QString& text, int size)
45 : KSaneOptionWidget(parent, text)
46 {
47  m_bri_slider = new LabeledSlider(this, i18n("Brightness"), -50, 50, 1);
48  m_bri_slider->setValue(0);
49 
50  m_con_slider = new LabeledSlider(this, i18n("Contrast"), -50, 50, 1);
51  m_con_slider->setValue(0);
52 
53  m_gam_slider = new LabeledSlider(this, i18n("Gamma"), 30, 300, 1);
54  m_gam_slider->setValue(100);
55 
56  // Calculate the size of the widgets in the sliders
57  int labelMax = m_bri_slider->labelWidthHint();
58  labelMax = qMax(labelMax, m_con_slider->labelWidthHint());
59  labelMax = qMax(labelMax, m_gam_slider->labelWidthHint());
60  // set the calculated widths
61  m_bri_slider->setLabelWidth(labelMax);
62  m_con_slider->setLabelWidth(labelMax);
63  m_gam_slider->setLabelWidth(labelMax);
64 
65  m_gam_tbl.resize(size);
66  for (int i=0; i<m_gam_tbl.size(); i++) {
67  m_gam_tbl[i] = i;
68  }
69  m_max_val = size-1; // assume a gamma table 0 -> max
70 
71  m_gamma_disp = new GammaDisp(this, &m_gam_tbl);
72 
73  QGroupBox *groupBox = new QGroupBox(text, this);
74  QGridLayout *gr_lay = new QGridLayout(groupBox);
75 
76  gr_lay->addWidget(m_bri_slider, 0, 0);
77  gr_lay->addWidget(m_con_slider, 1, 0);
78  gr_lay->addWidget(m_gam_slider, 2, 0);
79  gr_lay->addWidget(m_gamma_disp, 0, 1, 3, 1);
80 
81  m_label->hide();
82  m_layout->addWidget(groupBox, 1, 0, 1,3);
83 
84  connect(m_bri_slider, SIGNAL(valueChanged(int)), this, SLOT(calculateGT()));
85  connect(m_con_slider, SIGNAL(valueChanged(int)), this, SLOT(calculateGT()));
86  connect(m_gam_slider, SIGNAL(valueChanged(int)), this, SLOT(calculateGT()));
87 }
88 
89 LabeledGamma::~LabeledGamma()
90 {
91 }
92 
93 void LabeledGamma::setColor(const QColor &color)
94 {
95  if (m_gamma_disp != 0) {
96  m_gamma_disp->setColor(color);
97  }
98 }
99 
100 void LabeledGamma::setValues(int bri, int con, int gam)
101 {
102  m_bri_slider->blockSignals(true);
103  m_con_slider->blockSignals(true);
104  m_gam_slider->blockSignals(true);
105 
106  m_bri_slider->setValue(bri);
107  m_con_slider->setValue(con);
108  m_gam_slider->setValue(gam);
109 
110  calculateGT();
111 
112  m_bri_slider->blockSignals(false);
113  m_con_slider->blockSignals(false);
114  m_gam_slider->blockSignals(false);
115 }
116 
117 void LabeledGamma::setValues(const QString &values)
118 {
119  m_bri_slider->blockSignals(true);
120  m_con_slider->blockSignals(true);
121  m_gam_slider->blockSignals(true);
122 
123  QStringList gammaValues;
124  int bri;
125  int con;
126  int gam;
127  bool ok = true;
128 
129  gammaValues = values.split(':');
130  bri = gammaValues.at(0).toInt(&ok);
131  if (ok) con = gammaValues.at(1).toInt(&ok);
132  if (ok) gam = gammaValues.at(2).toInt(&ok);
133 
134  if (ok) {
135  m_bri_slider->setValue(bri);
136  m_con_slider->setValue(con);
137  m_gam_slider->setValue(gam);
138  calculateGT();
139  }
140 
141  m_bri_slider->blockSignals(false);
142  m_con_slider->blockSignals(false);
143  m_gam_slider->blockSignals(false);
144 }
145 
146 
147 bool LabeledGamma::getValues(int &bri, int &con, int &gam)
148 {
149 
150  bri = m_bri_slider->value();
151  con = m_con_slider->value();
152  gam = m_gam_slider->value();
153  return true;
154 }
155 
156 void LabeledGamma::setSize(int size)
157 {
158  m_gam_tbl.resize(size);
159  for (int i=0; i<m_gam_tbl.size(); i++) {
160  m_gam_tbl[i] = i;
161  }
162  m_bri_slider->setValue(0);
163  m_con_slider->setValue(0);
164  m_gam_slider->setValue(0);
165 }
166 
167 
168 void LabeledGamma::calculateGT()
169 {
170  double gam = 100.0/m_gam_slider->value();
171  double con = (200.0/(100.0 - m_con_slider->value()))-1;
172  double half_max = m_max_val/2.0;
173  double bri = (m_bri_slider->value()/half_max) * m_max_val;
174  double x;
175 
176  for (int i = 0; i<m_gam_tbl.size(); i++) {
177  // apply gamma
178  x = std::pow(i/m_max_val, gam) * m_max_val;
179 
180  // apply contrast
181  x = (con*(x-half_max)) + half_max;
182 
183  // apply brightness + rounding
184  x += bri + 0.5;
185 
186  // ensure correct value
187  if (x > m_max_val) x = m_max_val;
188  if (x < 0) x = 0;
189 
190  m_gam_tbl[i] = (int)x;
191  }
192 
193  m_gamma_disp->update();
194  emit gammaChanged(m_bri_slider->value(), m_con_slider->value(), m_gam_slider->value());
195  emit gammaTableChanged(m_gam_tbl);
196 }
197 
198 
199 } // NameSpace KSaneIface
QWidget
QGridLayout::addWidget
void addWidget(QWidget *widget, int row, int column, QFlags< Qt::AlignmentFlag > alignment)
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
KSaneIface::LabeledSlider
A combination of a label a slider and a spinbox.
Definition: labeled_slider.h:50
QList::at
const T & at(int i) const
KSaneIface::LabeledSlider::setValue
void setValue(int)
Set the slider value.
Definition: labeled_slider.cpp:87
QGridLayout
QWidget::update
void update()
KSaneIface::GammaDisp::setColor
void setColor(const QColor &color)
Definition: gamma_disp.cpp:55
KSaneIface::KSaneOptionWidget::m_label
QLabel * m_label
Definition: ksane_option_widget.h:64
KSaneIface::KSaneOptionWidget::labelWidthHint
int labelWidthHint()
Definition: ksane_option_widget.cpp:64
KSaneIface::LabeledGamma::setValues
void setValues(int bri, int con, int gam)
Definition: labeled_gamma.cpp:100
KSaneIface::LabeledGamma::gammaChanged
void gammaChanged(int bri, int con, int gam)
QVector::resize
void resize(int size)
KSaneIface::KSaneOptionWidget::m_layout
QGridLayout * m_layout
Definition: ksane_option_widget.h:65
QGroupBox
QWidget::x
int x() const
KSaneIface::KSaneOptionWidget
A wrapper for a checkbox.
Definition: ksane_option_widget.h:45
QString
QWidget::hide
void hide()
QColor
KSaneIface::LabeledGamma::setColor
void setColor(const QColor &color)
Definition: labeled_gamma.cpp:93
QStringList
KSaneIface::LabeledGamma::~LabeledGamma
~LabeledGamma()
Definition: labeled_gamma.cpp:89
QObject::blockSignals
bool blockSignals(bool block)
KSaneIface::GammaDisp
Definition: gamma_disp.h:44
KSaneIface::KSaneOptionWidget::setLabelWidth
void setLabelWidth(int labelWidth)
Definition: ksane_option_widget.cpp:69
KSaneIface::LabeledGamma::gammaTableChanged
void gammaTableChanged(const QVector< int > &gamma_tbl)
KSaneIface::LabeledGamma::LabeledGamma
LabeledGamma(QWidget *parent, const QString &text, int elements)
Create the checkbox.
Definition: labeled_gamma.cpp:44
KSaneIface::LabeledSlider::value
int value() const
Definition: labeled_slider.h:70
labeled_gamma.h
KSaneIface::LabeledGamma::setSize
void setSize(int size)
Definition: labeled_gamma.cpp:156
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QVector::size
int size() const
KSaneIface::LabeledGamma::getValues
bool getValues(int &bri, int &con, int &gam)
Definition: labeled_gamma.cpp:147
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:19:47 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libs/libksane/libksane

Skip menu "libs/libksane/libksane"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegraphics API Reference

Skip menu "kdegraphics API Reference"
  •     libkdcraw
  •     libkexiv2
  •     libkipi
  •     libksane
  • okular

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal