KSane

labeledgamma.cpp
1/*
2 * SPDX-FileCopyrightText: 2007-2011 Kare Sars <kare.sars@iki .fi>
3 * SPDX-FileCopyrightText: 2014 Gregor Mitsch : port to KDE5 frameworks
4 *
5 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7
8// Local includes
9#include "labeledgamma.h"
10
11#include <QGroupBox>
12
13#include <KLocalizedString>
14#include <KSaneCore/Option>
15
16namespace KSaneIface
17{
18
19LabeledGamma::LabeledGamma(QWidget *parent, const QString &text, int max)
20 : KSaneOptionWidget(parent, text)
21{
22 initGamma(text, max);
23}
24
26 : KSaneOptionWidget(parent, option)
27{
28
29 int max = option->maximumValue().toInt();
30 initGamma(option->title(), max);
31 connect(this, &LabeledGamma::valuesChanged, option, &KSaneCore::Option::setValue);
32 connect(option, &KSaneCore::Option::valueChanged, this, &LabeledGamma::setValues);
33 setColor(color);
34 setToolTip(option->description());
35}
36
37LabeledGamma::~LabeledGamma()
38{
39}
40
41void LabeledGamma::initGamma(QString text, int max)
42{
43 m_brightSlider = new LabeledSlider(this, i18n("Brightness"), -50, 50, 1);
44 m_brightSlider->setValue(0);
45
46 m_contrastSlider = new LabeledSlider(this, i18n("Contrast"), -50, 50, 1);
47 m_contrastSlider->setValue(0);
48
49 m_gammaSlider = new LabeledSlider(this, i18n("Gamma"), 30, 300, 1);
50 m_gammaSlider->setValue(100);
51
52 // Calculate the size of the widgets in the sliders
53 int labelMax = m_brightSlider->labelWidthHint();
54 labelMax = qMax(labelMax, m_contrastSlider->labelWidthHint());
55 labelMax = qMax(labelMax, m_gammaSlider->labelWidthHint());
56 // set the calculated widths
57 m_brightSlider->setLabelWidth(labelMax);
58 m_contrastSlider->setLabelWidth(labelMax);
59 m_gammaSlider->setLabelWidth(labelMax);
60
61 m_maxValue = max;
62
63 m_gammaDisplay = new GammaDisp(this, &m_brightness, &m_contrast, &m_gamma, max);
64
65 QGroupBox *groupBox = new QGroupBox(text, this);
66 QGridLayout *gr_lay = new QGridLayout(groupBox);
67
68 gr_lay->addWidget(m_brightSlider, 0, 0);
69 gr_lay->addWidget(m_contrastSlider, 1, 0);
70 gr_lay->addWidget(m_gammaSlider, 2, 0);
71 gr_lay->addWidget(m_gammaDisplay, 0, 1, 3, 1);
72
73 m_label->hide();
74 m_layout->addWidget(groupBox, 1, 0, 1, 3);
75
76 connect(m_brightSlider, &LabeledSlider::valueChanged, this, &LabeledGamma::emitNewValues);
77 connect(m_contrastSlider, &LabeledSlider::valueChanged, this, &LabeledGamma::emitNewValues);
78 connect(m_gammaSlider, &LabeledSlider::valueChanged, this, &LabeledGamma::emitNewValues);
79
80 emitNewValues();
81}
82
83void LabeledGamma::setColor(const QColor &color)
84{
85 if (m_gammaDisplay != nullptr) {
86 m_gammaDisplay->setColor(color);
87 }
88}
89
90void LabeledGamma::setValues(const QVariant &values)
91{
92 if (static_cast<QMetaType::Type>(values.type()) == QMetaType::QVariantList) {
93 QVariantList copy = values.toList();
94 if (copy.size() != 3) {
95 return;
96 }
97
98 m_brightSlider->blockSignals(true);
99 m_contrastSlider->blockSignals(true);
100 m_gammaSlider->blockSignals(true);
101
102 m_brightness = copy.at(0).toInt();
103 m_contrast = copy.at(1).toInt();
104 m_gamma = copy.at(2).toInt();
105
106 m_brightSlider->setValue(m_brightness);
107 m_contrastSlider->setValue(m_contrast);
108 m_gammaSlider->setValue(m_gamma);
109
110 emitNewValues();
111
112 m_brightSlider->blockSignals(false);
113 m_contrastSlider->blockSignals(false);
114 m_gammaSlider->blockSignals(false);
115 }
116}
117
118void LabeledGamma::emitNewValues()
119{
120 m_brightness = m_brightSlider->value();
121 m_contrast = m_contrastSlider->value();
122 m_gamma = m_gammaSlider->value();
123 QVariantList values = { m_brightness, m_contrast, m_gamma };
124
125 m_gammaDisplay->update();
126 Q_EMIT valuesChanged(QVariant::fromValue(values));
127}
128
129bool LabeledGamma::getValues(int &brightness, int &contrast, int &gamma)
130{
131 brightness = m_brightSlider->value();
132 contrast = m_contrastSlider->value();
133 gamma = m_gammaSlider->value();
134 return true;
135}
136
137int LabeledGamma::maxValue()
138{
139 return m_maxValue;
140}
141
142} // NameSpace KSaneIface
143
144#include "moc_labeledgamma.cpp"
void valueChanged(const QVariant &value)
bool setValue(const QVariant &value)
QString title() const
QString description() const
QVariant maximumValue() const
Base class for option widgets.
LabeledGamma(QWidget *parent, const QString &text, int max)
Create the labeled gamma widget.
void setValue(const QVariant &val)
Set the slider value.
void valueChanged(const QVariant &val)
Emit the slider value changes.
QString i18n(const char *text, const TYPE &arg...)
const QList< QKeySequence > & copy()
void addWidget(QWidget *widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment)
Q_EMITQ_EMIT
bool blockSignals(bool block)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
Type type() const const
QVariant fromValue(T &&value)
QList< QVariant > toList() const const
void hide()
void setToolTip(const QString &)
void update()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:32 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.