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

A widget that can display different KisHistograms. It renders a somewhat smooth shape with different colors (for rgb, cmyk and xyz channels). It can also display the different channels of a colorspace overlapped. More...

#include <KisHistogramView.h>

+ Inheritance diagram for KisHistogramView:

Classes

class  Private
 

Public Slots

void clearChannels ()
 This clears the channel selection. The widget will show a null symbol in it's center when there are no activated channels.
 
void setChannel (int channel, int histogramIndex=0)
 Activates the given channel of the given histogram. This allows to change the view between the different histograms and channels passed to the setup function.
 
void setChannels (const QVector< int > &channels, int histogramIndex=0)
 Activates the given channels of the given histogram. This allows to change the view between the different histograms and channels passed to the setup function. This function activates multiple channels that will be displayed at once in the widget.
 
void setDefaultColor (const QColor &newDefaultColor)
 Set the default color used when there is no preference to color the selected histogram.
 
void setLogarithmic (bool logarithmic)
 Set if the histogram shape being shown is formed by the logarithmic mapping of the original histogram values instead of the values themselves.
 
void setScale (qreal newScale)
 Set the scale used to paint the widget. The scale can also be changed by clicking and dragging up/down in the widget.
 
void setScaleToCutLongPeaks ()
 Sometimes there can be some outliers in the histogram that show in the widget as long vertical peaks. Since a scale of 1 will show all the histogram, this can make its interesting parts too small to take any valuable information from them. This function will try to come up with a scale value that favors those interesting parts over the long peaks, which will be pushed and will look cut.
 
void setScaleToFit ()
 Set the scale used to paint the widget to 1. You can also return to a scale of 1 by double clicking on the widget if the current scale is other than 1. If you double click when the scale is one the effect will be the same as calling setScaleToCutLongPeaks.
 

Public Member Functions

const QVector< int > & channels () const
 Returns the channels that are available for the currently selected histogram.
 
QColor defaultColor () const
 Returns the color that is being used to paint a generic histogram. All the histogram channels will use this color with the exception of the red, green and blue channels in a rgba histogram; the cyan, magenta, yellow and black channels in a cmyka histogram; and the x, y, and z channels in a xyz histogram.
 
bool isLogarithmic () const
 Returns true if the histogram shape being shown is formed by the logarithmic mapping of the original histogram values instead of the values themselves.
 
 KisHistogramView (QWidget *parent)
 
qreal scale () const
 Return the vertical scale that is used to paint the histogram shape. A scale of 1 will show all the histogram in the widget area. Scales less that 1 are not allowed.
 
void setup (const QVector< KisHistogram * > &histograms, const QVector< const KoColorSpace * > &colorSpaces, const QVector< QVector< int > > &channels={})
 Sets up the widget by passing a collection of KisHistograms, the color space for each histogram and the channels that must be set up for each histogram.
 
 ~KisHistogramView ()
 

Protected Member Functions

void mouseDoubleClickEvent (QMouseEvent *e) override
 
void mouseMoveEvent (QMouseEvent *e) override
 
void mousePressEvent (QMouseEvent *e) override
 
void paintEvent (QPaintEvent *e) override
 

Private Attributes

QScopedPointer< Privatem_d
 

Detailed Description

A widget that can display different KisHistograms. It renders a somewhat smooth shape with different colors (for rgb, cmyk and xyz channels). It can also display the different channels of a colorspace overlapped.

Definition at line 25 of file KisHistogramView.h.

Constructor & Destructor Documentation

◆ KisHistogramView()

KisHistogramView::KisHistogramView ( QWidget * parent)

Definition at line 28 of file KisHistogramView.cpp.

29 : QWidget(parent)
30 , m_d(new Private)
31{}
QScopedPointer< Private > m_d

◆ ~KisHistogramView()

KisHistogramView::~KisHistogramView ( )

Definition at line 33 of file KisHistogramView.cpp.

34{
35 qDeleteAll(m_d->histogramPainters);
36}

References m_d.

Member Function Documentation

◆ channels()

const QVector< int > & KisHistogramView::channels ( ) const

Returns the channels that are available for the currently selected histogram.

See also
setChannel
setChannels

Definition at line 69 of file KisHistogramView.cpp.

70{
71 return m_d->histogramPainters[m_d->histogramIndex]->channels();
72}

References m_d.

◆ clearChannels

void KisHistogramView::clearChannels ( )
slot

This clears the channel selection. The widget will show a null symbol in it's center when there are no activated channels.

Definition at line 96 of file KisHistogramView.cpp.

97{
98 setChannels({});
99}
void setChannels(const QVector< int > &channels, int histogramIndex=0)
Activates the given channels of the given histogram. This allows to change the view between the diffe...

References setChannels().

◆ defaultColor()

QColor KisHistogramView::defaultColor ( ) const

Returns the color that is being used to paint a generic histogram. All the histogram channels will use this color with the exception of the red, green and blue channels in a rgba histogram; the cyan, magenta, yellow and black channels in a cmyka histogram; and the x, y, and z channels in a xyz histogram.

See also
setDefaultColor

Definition at line 101 of file KisHistogramView.cpp.

102{
103 Q_ASSERT(m_d->histogramPainters.size() > 0);
104
105 return m_d->histogramPainters[m_d->histogramIndex]->defaultColor();
106}

References m_d.

◆ isLogarithmic()

bool KisHistogramView::isLogarithmic ( ) const

Returns true if the histogram shape being shown is formed by the logarithmic mapping of the original histogram values instead of the values themselves.

See also
setLogarithmic

Definition at line 144 of file KisHistogramView.cpp.

145{
146 Q_ASSERT(m_d->histogramPainters.size() > 0);
147
148 return m_d->histogramPainters[m_d->histogramIndex]->isLogarithmic();
149}

References m_d.

◆ mouseDoubleClickEvent()

void KisHistogramView::mouseDoubleClickEvent ( QMouseEvent * e)
overrideprotected

Definition at line 211 of file KisHistogramView.cpp.

212{
213 if (m_d->histogramPainters.size() == 0 ||
214 m_d->histogramPainters[m_d->histogramIndex]->channels().size() == 0) {
215 return;
216 }
217
218 if (e->button() != Qt::LeftButton) {
219 return;
220 }
221
222 if (qFuzzyCompare(scale(), 1.0)) {
224 } else {
226 }
227}
void setScaleToCutLongPeaks()
Sometimes there can be some outliers in the histogram that show in the widget as long vertical peaks....
void setScaleToFit()
Set the scale used to paint the widget to 1. You can also return to a scale of 1 by double clicking o...
qreal scale() const
Return the vertical scale that is used to paint the histogram shape. A scale of 1 will show all the h...
static bool qFuzzyCompare(half p1, half p2)

References m_d, qFuzzyCompare(), scale(), setScaleToCutLongPeaks(), and setScaleToFit().

◆ mouseMoveEvent()

void KisHistogramView::mouseMoveEvent ( QMouseEvent * e)
overrideprotected

Definition at line 245 of file KisHistogramView.cpp.

246{
247 if (m_d->histogramPainters.size() == 0 ||
248 m_d->histogramPainters[m_d->histogramIndex]->channels().size() == 0) {
249 return;
250 }
251
252 if (!(e->buttons() & Qt::LeftButton)) {
253 return;
254 }
255
256 if (m_d->isScaling) {
257 const qreal newScale =
258 m_d->preDraggingScale * static_cast<qreal>(height() - e->y()) /
259 static_cast<qreal>(height() - m_d->draggingStartMouseY);
260 setScale(qMax(newScale, 1.0));
261 } else {
262 if (qAbs(e->y() - m_d->draggingStartMouseY) > 4) {
263 m_d->isScaling = true;
264 }
265 }
266
267}
void setScale(qreal newScale)
Set the scale used to paint the widget. The scale can also be changed by clicking and dragging up/dow...

References m_d, and setScale().

◆ mousePressEvent()

void KisHistogramView::mousePressEvent ( QMouseEvent * e)
overrideprotected

Definition at line 229 of file KisHistogramView.cpp.

230{
231 if (m_d->histogramPainters.size() == 0 ||
232 m_d->histogramPainters[m_d->histogramIndex]->channels().size() == 0) {
233 return;
234 }
235
236 if (e->button() != Qt::LeftButton) {
237 return;
238 }
239
240 m_d->preDraggingScale = scale();
241 m_d->draggingStartMouseY = e->y();
242 m_d->isScaling = false;
243}

References m_d, and scale().

◆ paintEvent()

void KisHistogramView::paintEvent ( QPaintEvent * e)
overrideprotected

Definition at line 160 of file KisHistogramView.cpp.

161{
162 Q_UNUSED(e);
163
164 QPainter painter(this);
165
166 // Background
167 painter.fillRect(rect(), palette().base());
168
169 // Histogram
170 if (m_d->histogramPainters.size() > 0 &&
171 m_d->histogramPainters[m_d->histogramIndex]->channels().size() > 0) {
172 // Histogram
173 QImage histogramImage = m_d->histogramPainters[m_d->histogramIndex]->paint(size());
174 // Shadow
175 QLinearGradient shadowGradient(QPointF(0.0, 0.0), QPointF(0.0, static_cast<qreal>(height()) * 0.2));
176 shadowGradient.setColorAt(0.00, QColor(0, 0, 0, 64));
177 shadowGradient.setColorAt(0.25, QColor(0, 0, 0, 36));
178 shadowGradient.setColorAt(0.50, QColor(0, 0, 0, 16));
179 shadowGradient.setColorAt(0.75, QColor(0, 0, 0, 4));
180 shadowGradient.setColorAt(1.00, QColor(0, 0, 0, 0));
181 QPainter histogramPainter(&histogramImage);
182 histogramPainter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
183 histogramPainter.fillRect(histogramImage.rect(), shadowGradient);
184 if (!isEnabled()) {
185 painter.setOpacity(0.5);
186 }
187 painter.drawImage(0, 0, histogramImage);
188 painter.setOpacity(1.0);
189 } else {
190 const qreal w = static_cast<qreal>(width());
191 const qreal h = static_cast<qreal>(height());
192 const qreal radius = qMin(w, h) * 0.3;
193 const QPointF center = QPointF(w / 2.0, h / 2.0);
194 const int penWidth = static_cast<int>(qRound(radius / 8));
195 painter.setPen(QPen(palette().alternateBase(), penWidth, Qt::SolidLine, Qt::FlatCap));
196 painter.setBrush(Qt::NoBrush);
197 painter.setRenderHint(QPainter::Antialiasing);
198 painter.drawEllipse(center, radius, radius);
199 painter.drawLine(center + QPointF(radius, -radius), center + QPointF(-radius, radius));
200 }
201
202 // Border
203 QColor c = palette().text().color();
204 c.setAlpha(64);
205 painter.setPen(QPen(c, 1));
206 painter.setBrush(Qt::NoBrush);
207 painter.setRenderHint(QPainter::Antialiasing, false);
208 painter.drawRect(0, 0, width() - 1, height() - 1);
209}
int size(const Forest< T > &forest)
Definition KisForest.h:1232
rgba palette[MAX_PALETTE]
Definition palette.c:35

References m_d, and palette.

◆ scale()

qreal KisHistogramView::scale ( ) const

Return the vertical scale that is used to paint the histogram shape. A scale of 1 will show all the histogram in the widget area. Scales less that 1 are not allowed.

See also
setScale
setScaleToFit
setScaleToCutLongPeaks

Definition at line 116 of file KisHistogramView.cpp.

117{
118 Q_ASSERT(m_d->histogramPainters.size() > 0);
119
120 return m_d->histogramPainters[m_d->histogramIndex]->scale();
121}

References m_d.

◆ setChannel

void KisHistogramView::setChannel ( int channel,
int histogramIndex = 0 )
slot

Activates the given channel of the given histogram. This allows to change the view between the different histograms and channels passed to the setup function.

See also
channel
setChannels
setup

Definition at line 74 of file KisHistogramView.cpp.

75{
76 setChannels({channel}, histogramIndex);
77}

References setChannels().

◆ setChannels

void KisHistogramView::setChannels ( const QVector< int > & channels,
int histogramIndex = 0 )
slot

Activates the given channels of the given histogram. This allows to change the view between the different histograms and channels passed to the setup function. This function activates multiple channels that will be displayed at once in the widget.

See also
channel
setChannel
setup

Definition at line 79 of file KisHistogramView.cpp.

80{
81 Q_ASSERT(m_d->histogramPainters.size() > 0);
82 Q_ASSERT(histogramIndex >= 0 && histogramIndex < m_d->histogramPainters.size());
83
84 const QColor defaultColor = m_d->histogramPainters[m_d->histogramIndex]->defaultColor();
85 const bool isLogarithmic = m_d->histogramPainters[m_d->histogramIndex]->isLogarithmic();
86
87 m_d->histogramIndex = histogramIndex;
88 m_d->histogramPainters[m_d->histogramIndex]->setChannels(channels);
89 m_d->histogramPainters[m_d->histogramIndex]->setDefaultColor(defaultColor);
90 m_d->histogramPainters[m_d->histogramIndex]->setLogarithmic(isLogarithmic);
92
93 update();
94}
const QVector< int > & channels() const
Returns the channels that are available for the currently selected histogram.
QColor defaultColor() const
Returns the color that is being used to paint a generic histogram. All the histogram channels will us...
bool isLogarithmic() const
Returns true if the histogram shape being shown is formed by the logarithmic mapping of the original ...
bool update(QSpinBox *spinBox)

References channels(), defaultColor(), isLogarithmic(), m_d, and setScaleToFit().

◆ setDefaultColor

void KisHistogramView::setDefaultColor ( const QColor & newDefaultColor)
slot

Set the default color used when there is no preference to color the selected histogram.

See also
defaultColor

Definition at line 108 of file KisHistogramView.cpp.

109{
110 Q_ASSERT(m_d->histogramPainters.size() > 0);
111
112 m_d->histogramPainters[m_d->histogramIndex]->setDefaultColor(newDefaultColor);
113 update();
114}

References m_d.

◆ setLogarithmic

void KisHistogramView::setLogarithmic ( bool logarithmic)
slot

Set if the histogram shape being shown is formed by the logarithmic mapping of the original histogram values instead of the values themselves.

See also
isLogarithmic

Definition at line 151 of file KisHistogramView.cpp.

152{
153 Q_ASSERT(m_d->histogramPainters.size() > 0);
154
155 m_d->histogramPainters[m_d->histogramIndex]->setLogarithmic(logarithmic);
157 update();
158}

References m_d, and setScaleToFit().

◆ setScale

void KisHistogramView::setScale ( qreal newScale)
slot

Set the scale used to paint the widget. The scale can also be changed by clicking and dragging up/down in the widget.

See also
scale
setScaleToFit
setScaleToCutLongPeaks

Definition at line 123 of file KisHistogramView.cpp.

124{
125 Q_ASSERT(m_d->histogramPainters.size() > 0);
126
127 m_d->histogramPainters[m_d->histogramIndex]->setScale(newScale);
128 update();
129}

References m_d.

◆ setScaleToCutLongPeaks

void KisHistogramView::setScaleToCutLongPeaks ( )
slot

Sometimes there can be some outliers in the histogram that show in the widget as long vertical peaks. Since a scale of 1 will show all the histogram, this can make its interesting parts too small to take any valuable information from them. This function will try to come up with a scale value that favors those interesting parts over the long peaks, which will be pushed and will look cut.

See also
scale
setScale
setScaleToFit

Definition at line 136 of file KisHistogramView.cpp.

137{
138 Q_ASSERT(m_d->histogramPainters.size() > 0);
139
140 m_d->histogramPainters[m_d->histogramIndex]->setScaleToCutLongPeaks();
141 update();
142}

References m_d.

◆ setScaleToFit

void KisHistogramView::setScaleToFit ( )
slot

Set the scale used to paint the widget to 1. You can also return to a scale of 1 by double clicking on the widget if the current scale is other than 1. If you double click when the scale is one the effect will be the same as calling setScaleToCutLongPeaks.

See also
scale
setScale
setScaleToCutLongPeaks

Definition at line 131 of file KisHistogramView.cpp.

132{
133 setScale(1.0);
134}

References setScale().

◆ setup()

void KisHistogramView::setup ( const QVector< KisHistogram * > & histograms,
const QVector< const KoColorSpace * > & colorSpaces,
const QVector< QVector< int > > & channels = {} )

Sets up the widget by passing a collection of KisHistograms, the color space for each histogram and the channels that must be set up for each histogram.

Parameters
histogramsA collection of KisHistogram pointers to take the info from. You can add several histograms and later select which histogram is used at any given moment. This prevents calling multiple times the setup function with different histograms. That way the shaped to draw are computed only once. The histogram pointers are not stored or owned internally, so you can safely delete them if you don't need them
colorSpacesThe collection of color spaces associated with each histogram. They are used to color different channels. For example, the histogram for the red channel of a rgb histogram will be painted as a red shape
channelsA collection of vectors that contain the channel number for the channels that must be used to compute the histograms. For example, if the second histogram is a Lab histogram, and you are interested only in the lightness channel, the second vector in the collection should have only one element, the number 0 (index of the lightness channel). If the collection is empty or if the vector of channels for any given histogram is empty, then all the channels will be used

Definition at line 38 of file KisHistogramView.cpp.

41{
42 Q_ASSERT(colorSpaces.size() == histograms.size());
43 Q_ASSERT(channels.size() == 0 || channels.size() == histograms.size());
44
45 m_d->histogramIndex = 0;
46 qDeleteAll(m_d->histogramPainters);
47 m_d->histogramPainters.clear();
48
49 if (histograms.size() == 0) {
50 return;
51 }
52
53 QVector<QVector<int>> autoGeneratedChannels;
54 if (channels.size() == 0) {
55 for (int i = 0; i < histograms.size(); ++i) {
56 autoGeneratedChannels.append(QVector<int>());
57 }
58 }
59
60 const QVector<QVector<int>> &finalChannels =
61 channels.size() == 0 ? autoGeneratedChannels : channels;
62
63 for (int i = 0; i < histograms.size(); ++i) {
64 m_d->histogramPainters.append(new KisHistogramPainter());
65 m_d->histogramPainters[i]->setup(histograms[i], colorSpaces[i], finalChannels[i]);
66 }
67}
A class that can render different KisHistograms. It renders a somewhat smooth shape (with different c...

References channels(), and m_d.

Member Data Documentation

◆ m_d

QScopedPointer<Private> KisHistogramView::m_d
private

Definition at line 168 of file KisHistogramView.h.


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