24#include <tqcombobox.h>
25#include <tqbuttongroup.h>
26#include <tqpushbutton.h>
27#include <tqscrollbar.h>
31#include "kis_channelinfo.h"
32#include "kis_histogram.h"
33#include "kis_global.h"
36#include "kis_colorspace.h"
37#include "kis_histogram_view.h"
38#include "kis_basic_histogram_producers.h"
39#include "kis_paint_device.h"
41KisHistogramView::KisHistogramView(TQWidget *parent,
const char *name, WFlags f)
42 : TQLabel(parent, name, f)
46 setScaledContents(
true);
47 setFrameShape(TQFrame::Box);
50KisHistogramView::~KisHistogramView()
54void KisHistogramView::setPaintDevice(KisPaintDeviceSP dev)
56 m_cs = dev->colorSpace();
60 if (!m_currentProducer)
63 m_from = m_currentProducer->viewFrom();
64 m_width = m_currentProducer->viewWidth();
66 m_histogram =
new KisHistogram(dev, m_currentProducer, LINEAR);
71void KisHistogramView::setHistogram(KisHistogramSP histogram)
74 m_histogram = histogram;
75 m_currentProducer = m_histogram->producer();
76 m_from = m_currentProducer->viewFrom();
77 m_width = m_currentProducer->viewWidth();
80 m_channelStrings.clear();
82 m_channelToOffset.clear();
84 addProducerChannels(m_currentProducer);
88 m_channels.append(m_comboInfo.at(1).channel);
89 m_channelToOffset.append(0);
94void KisHistogramView::setView(
double from,
double size)
98 if (m_from + m_width > 1.0)
99 m_from = 1.0 - m_width;
100 m_histogram->producer()->setView(m_from, m_width);
102 m_histogram->updateHistogram();
106KisHistogramProducerSP KisHistogramView::currentProducer()
108 return m_currentProducer;
111TQStringList KisHistogramView::channelStrings()
113 return m_channelStrings;
119 return KisHistogramProducerFactoryRegistry::instance()->listKeysCompatibleWith(m_cs);
126 KisHistogramProducerFactoryRegistry::instance()->get(producerID)->generate(),
132 m_currentProducer = producer;
133 m_currentProducer->setView(m_from, m_width);
134 m_histogram->setProducer(m_currentProducer);
135 m_histogram->updateHistogram();
136 m_histogram->setChannel(0);
139 m_channelToOffset.clear();
141 if (channels.count() == 0) {
146 TQValueVector<KisChannelInfo *> producerChannels = m_currentProducer->channels();
148 for (uint i = 0; i < channels.count(); i++) {
150 for (uint j = 0; j < producerChannels.count(); j++) {
151 if (channels.at(i)->name() == producerChannels.at(j)->name()) {
152 m_channelToOffset.append(m_channels.count());
153 m_channels.append(channels.at(i));
161bool KisHistogramView::hasColor()
166void KisHistogramView::setColor(
bool set)
168 if (set != m_color) {
174void KisHistogramView::setActiveChannel(
int channel)
176 ComboboxInfo info = m_comboInfo.at(channel);
177 if (info.producer.data() != m_currentProducer.data()) {
178 m_currentProducer = info.producer;
179 m_currentProducer->setView(m_from, m_width);
180 m_histogram->setProducer(m_currentProducer);
181 m_histogram->updateHistogram();
185 m_channelToOffset.clear();
187 if (!m_currentProducer) {
192 if (info.isProducer) {
194 m_channels = m_currentProducer->channels();
195 for (uint i = 0; i < m_channels.count(); i++)
196 m_channelToOffset.append(i);
197 m_histogram->setChannel(0);
200 TQValueVector<KisChannelInfo *> channels = m_currentProducer->channels();
201 for (uint i = 0; i < channels.count(); i++) {
203 if (channel->
name() == info.channel->name()) {
204 m_channels.append(channel);
205 m_channelToOffset.append(i);
214void KisHistogramView::setHistogramType(enumHistogramType type)
216 m_histogram->setHistogramType(type);
220void KisHistogramView::setChannels()
223 m_channelStrings.clear();
225 m_channelToOffset.clear();
227 KisIDList list = KisHistogramProducerFactoryRegistry::instance()->listKeysCompatibleWith(m_cs);
229 if (list.count() == 0) {
232 addProducerChannels(f.generate());
234 for (uint i = 0; i < list.count(); i++) {
235 KisID id(*(list.at(i)));
236 addProducerChannels( KisHistogramProducerFactoryRegistry::instance()->get(
id)->generate() );
240 m_currentProducer = m_comboInfo.at(0).producer;
243 m_channels.append(m_comboInfo.at(1).channel);
244 m_channelToOffset.append(0);
247void KisHistogramView::addProducerChannels(KisHistogramProducerSP producer) {
249 info.isProducer =
true;
250 info.producer = producer;
252 TQValueVector<KisChannelInfo *> channels = info.producer->channels();
253 int count = channels.count();
254 m_comboInfo.append(info);
255 m_channelStrings.append(producer->id() . name());
256 for (
int j = 0; j < count; j++) {
257 info.isProducer =
false;
258 info.channel = channels.at(j);
259 m_comboInfo.append(info);
260 m_channelStrings.append(TQString(
" ").append(info.channel->name()));
264void KisHistogramView::updateHistogram()
266 TQ_UINT32 height = this->height();
269 if (!m_currentProducer) {
273 TQ_INT32 bins = m_histogram->producer()->numberOfBins();
274 m_pix = TQPixmap(bins, height);
277 p.setBrush(TQt::black);
280 if (m_histogram->hasSelection()) {
281 double width = m_histogram->selectionTo() - m_histogram->selectionFrom();
282 double factor =
static_cast<double>(bins) / m_histogram->producer()->viewWidth();
283 selFrom =
static_cast<int>(m_histogram->selectionFrom() * factor);
284 selTo = selFrom +
static_cast<int>(width * factor);
285 p.drawRect(selFrom, 0, selTo - selFrom, height);
294 bool blackOnBlack =
false;
298 for (uint chan = 0; chan < m_channels.count(); chan++) {
299 m_histogram->setChannel(m_channelToOffset.at(chan));
300 if ((
double)m_histogram->calculations().getHighest() > highest)
301 highest = (
double)m_histogram->calculations().getHighest();
304 for (uint chan = 0; chan < m_channels.count(); chan++) {
306 m_histogram->setChannel(m_channelToOffset.at(chan));
309 color = m_channels.at(chan)->color();
314 blackOnBlack = (color == TQt::black);
316 if (m_histogram->getHistogramType() == LINEAR) {
317 double factor = (double)height / highest;
318 for( i=0; i<bins; ++i ) {
321 if (i >= selFrom && i < selTo && blackOnBlack) {
322 p.setPen(TQt::white);
326 p.drawLine(i, height, i, height -
int(m_histogram->getValue(i) * factor));
329 double factor = (double)height / (
double)log(highest);
330 for( i = 0; i < bins; ++i ) {
332 if (i >= selFrom && i < selTo && blackOnBlack) {
333 p.setPen(TQt::white);
337 p.drawLine(i, height, i,
338 height -
int(log((
double)m_histogram->getValue(i)) * factor));
346void KisHistogramView::mousePressEvent(TQMouseEvent * e) {
347 if (e->button() == TQt::RightButton)
348 emit rightClicked(e->globalPos());
350 TQLabel::mousePressEvent(e);
354#include "kis_histogram_view.moc"
This class gives some basic information about a channel, that is, one of the components that makes up...
TQString name() const
User-friendly name for this channel for presentation purposes in the gui.
KisGenericRGBHistogramProducer his special Factory that isCompatibleWith everything.
KisIDList listProducers()
Lists all producers currently available.
void setCurrentChannels(const KisID &producerID, TQValueVector< KisChannelInfo * > channels)
Sets the currently displayed channels to channels of the producer with producerID as ID.
The histogram class computes the histogram data from the specified layer for the specified channel,...
Chalk has a large number of extensible resources.