Krita Source Code Documentation
Loading...
Searching...
No Matches
KisThresholdConfigWidget Class Reference

#include <threshold.h>

+ Inheritance diagram for KisThresholdConfigWidget:

Public Member Functions

KisPropertiesConfigurationSP configuration () const override
 
 KisThresholdConfigWidget (QWidget *parent, KisPaintDeviceSP dev)
 
void setConfiguration (const KisPropertiesConfigurationSP config) override
 
 ~KisThresholdConfigWidget () override
 
- Public Member Functions inherited from KisConfigWidget
virtual KoCanvasResourcesInterfaceSP canvasResourcesInterface () const
 
virtual void setCanvasResourcesInterface (KoCanvasResourcesInterfaceSP canvasResourcesInterface)
 
virtual void setView (KisViewManager *view)
 
 ~KisConfigWidget () override
 

Public Attributes

Ui::WdgThreshold m_page
 

Protected Attributes

bool m_histlog
 
QScopedPointer< KisHistogramm_histogram
 

Private Slots

void slotDrawHistogram (bool logarithmic=false)
 
void slotSetThreshold (int)
 

Additional Inherited Members

- Signals inherited from KisConfigWidget
void sigConfigurationItemChanged ()
 
void sigConfigurationUpdated ()
 
void sigDropLockedConfig (KisPropertiesConfigurationSP p)
 
void sigSaveLockedConfig (KisPropertiesConfigurationSP p)
 
- Protected Member Functions inherited from KisConfigWidget
 KisConfigWidget (QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags(), int delay=200)
 

Detailed Description

Definition at line 55 of file threshold.h.

Constructor & Destructor Documentation

◆ KisThresholdConfigWidget()

KisThresholdConfigWidget::KisThresholdConfigWidget ( QWidget * parent,
KisPaintDeviceSP dev )

Definition at line 107 of file threshold.cpp.

108 : KisConfigWidget(parent)
109{
110 Q_ASSERT(dev);
111 m_page.setupUi(this);
112
113 m_page.thresholdGradient->setThreshold(0.5);
114 m_page.intThreshold->setValue(128);
115
116 connect(m_page.intThreshold, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged()));
117 connect(m_page.intThreshold, QOverload<int>::of(&QSpinBox::valueChanged),
118 [this](int value)
119 {
120 KisSignalsBlocker blocker(m_page.thresholdGradient);
121 m_page.thresholdGradient->setThreshold(static_cast<qreal>(value) / 255.0);
122 }
123 );
124 connect(m_page.thresholdGradient, SIGNAL(thresholdChanged(qreal)), SIGNAL(sigConfigurationItemChanged()));
126 [this](qreal value)
127 {
128 KisSignalsBlocker blocker(m_page.intThreshold);
129 m_page.intThreshold->setValue(static_cast<int>(qRound(value * 255.0)));
130 }
131 );
132
133 connect((QObject*)(m_page.chkLogarithmic), SIGNAL(toggled(bool)), this, SLOT(slotDrawHistogram(bool)));
134
136 m_histogram.reset( new KisHistogram(dev, dev->exactBounds(), producer, LINEAR) );
137 m_histlog = false;
138 m_page.histview->resize(288,100);
140
141}
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void sigConfigurationItemChanged()
KisConfigWidget(QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags(), int delay=200)
QRect exactBounds() const
void slotDrawHistogram(bool logarithmic=false)
Ui::WdgThreshold m_page
Definition threshold.h:64
QScopedPointer< KisHistogram > m_histogram
Definition threshold.h:73
void thresholdChanged(qreal newThreshold)
Signal emitted when the threshold value changes.
@ LINEAR
Definition nugrid.h:26

References connect(), KisPaintDevice::exactBounds(), LINEAR, m_histlog, m_histogram, m_page, KisConfigWidget::sigConfigurationItemChanged(), slotDrawHistogram(), KisThresholdSlider::thresholdChanged(), and value().

◆ ~KisThresholdConfigWidget()

KisThresholdConfigWidget::~KisThresholdConfigWidget ( )
override

Definition at line 143 of file threshold.cpp.

144{
145}

Member Function Documentation

◆ configuration()

KisPropertiesConfigurationSP KisThresholdConfigWidget::configuration ( ) const
overridevirtual
Returns
the configuration

Implements KisConfigWidget.

Definition at line 198 of file threshold.cpp.

199{
201 config->setProperty("threshold", m_page.intThreshold->value());
202 return config;
203}
static KisResourcesInterfaceSP instance()

References KisGlobalResourcesInterface::instance(), and m_page.

◆ setConfiguration()

void KisThresholdConfigWidget::setConfiguration ( const KisPropertiesConfigurationSP config)
overridevirtual
Parameters
configthe configuration for this configuration widget.

Implements KisConfigWidget.

Definition at line 205 of file threshold.cpp.

206{
207 QVariant value;
208 if (config->getProperty("threshold", value)) {
209 KisSignalsBlocker blocker(m_page.intThreshold, m_page.thresholdGradient);
210 m_page.intThreshold->setValue(value.toUInt());
211 m_page.thresholdGradient->setThreshold(static_cast<qreal>(value.toUInt()) / 255.0);
212 }
214}

References m_page, KisConfigWidget::sigConfigurationItemChanged(), and value().

◆ slotDrawHistogram

void KisThresholdConfigWidget::slotDrawHistogram ( bool logarithmic = false)
privateslot

Definition at line 147 of file threshold.cpp.

148{
149 int wHeight = m_page.histview->height();
150 int wHeightMinusOne = wHeight - 1;
151 int wWidth = m_page.histview->width();
152
153 if (m_histlog != logarithmic) {
154 // Update the m_histogram
155 if (logarithmic)
156 m_histogram->setHistogramType(LOGARITHMIC);
157 else
158 m_histogram->setHistogramType(LINEAR);
159 m_histlog = logarithmic;
160 }
161
162 QPalette appPalette = QApplication::palette();
163 QPixmap pix(wWidth-100, wHeight);
164
165 pix.fill(QColor(appPalette.color(QPalette::Base)));
166 QPainter p(&pix);
167
168 p.setPen(QPen(Qt::gray, 1, Qt::SolidLine));
169
170 double highest = (double)m_histogram->calculations().getHighest();
171 qint32 bins = m_histogram->producer()->numberOfBins();
172
173 // use nearest neighbour interpolation
174 if (m_histogram->getHistogramType() == LINEAR) {
175 double factor = (double)(wHeight - wHeight / 5.0) / highest;
176 for (int i = 0; i < wWidth; i++) {
177 int binNo = qRound((double)i / wWidth * (bins - 1));
178 if ((int)m_histogram->getValue(binNo) != 0)
179 p.drawLine(i, wHeightMinusOne, i, wHeightMinusOne - (int)m_histogram->getValue(binNo) * factor);
180 }
181 } else {
182 double factor = (double)(wHeight - wHeight / 5.0) / (double)log(highest);
183 for (int i = 0; i < wWidth; i++) {
184 int binNo = qRound((double)i / wWidth * (bins - 1)) ;
185 if ((int)m_histogram->getValue(binNo) != 0)
186 p.drawLine(i, wHeightMinusOne, i, wHeightMinusOne - log((double)m_histogram->getValue(binNo)) * factor);
187 }
188 }
189
190 m_page.histview->setPixmap(pix);
191}
const Params2D p
@ LOGARITHMIC

References LINEAR, LOGARITHMIC, m_histlog, m_histogram, m_page, and p.

◆ slotSetThreshold

void KisThresholdConfigWidget::slotSetThreshold ( int limit)
privateslot

Definition at line 193 of file threshold.cpp.

194{
195 m_page.intThreshold->setMaximum(limit - 1);
196}

References m_page.

Member Data Documentation

◆ m_histlog

bool KisThresholdConfigWidget::m_histlog
protected

Definition at line 74 of file threshold.h.

◆ m_histogram

QScopedPointer<KisHistogram> KisThresholdConfigWidget::m_histogram
protected

Definition at line 73 of file threshold.h.

◆ m_page

Ui::WdgThreshold KisThresholdConfigWidget::m_page

Definition at line 64 of file threshold.h.


The documentation for this class was generated from the following files: