12#include <qapplication.h>
20#include <QResizeEvent>
22#include <QDesktopWidget>
33#define DRAG_THRESHOLD 5
35#define COLOR_BAR_MARGIN 2
36#define COLOR_BAR_BORDER 2
37#define COLOR_BAR_HEIGHT 6
38#define HISTOGRAM_HEIGHT ( height() - COLOR_BAR_BORDER - 2*COLOR_BAR_MARGIN - COLOR_BAR_HEIGHT )
42 QWidget *parent,
const char* name ) :
43 QWidget (parent, name, Qt::WNoAutoErase)
54 QRect screenSize = qApp->desktop()->availableGeometry();
56 scaleImage( imageFilename, image, screenSize.width()/4, screenSize.height()/4 );
69 for( y=0; y<image.height(); y++)
71 scanLine = image.scanLine(y);
72 for( x=0; x<image.width(); x++)
74 rgb = ((QRgb*)scanLine+x);
100 setMouseTracking(
true);
103 setFocusPolicy( Qt::ClickFocus );
106 Q3Accel *keyAccel =
new Q3Accel(
this );
107 keyAccel->connectItem( keyAccel->insertItem( Qt::CTRL + Qt::Key_A),
147 { left = 0; right = 0; }
152 return (255.0*coordinate) / (
width()-1 );
157 return (index* (
width()-1) ) / 255;
167 QPainter bufferPainter( &
buffer );
170 bufferPainter.setClipping(
false);
173 bufferPainter.fillRect(
buffer.rect(), backgroundBrush() );
177 QColor color = Qt::black;
185 int indexLeft, indexRight;
194 for(x=0; x<
width(); x++)
197 int indexL = (int)index;
198 double scaleR = index - indexL;
203 h = (int) ((1-scaleR)*data[indexL] + scaleR*data[indexL+1]);
211 double scaledH = (histogramHeight*h)/maxCount;
214 if( h == 0 && scaledH > h) h++;
219 QColor usedColor = color;
220 if(x < displayLeft || x > displayRight) { usedColor = Qt::gray; }
222 bufferPainter.fillRect( QRect(x, histogramHeight - h,
229 if( (x == displayLeft || x == displayLeft+1 ||
230 x == displayRight || x == displayRight-1) )
232 bufferPainter.drawLine( x, 0, x, histogramHeight-1 );
248 if(x <= displayLeft )
250 else if(x >= displayRight)
253 index = (int) (255.0*(x-displayLeft))/(displayRight - displayLeft);
256 int g = color.green();
257 int b = color.blue();
259 if( r != 0) r = index;
260 if( g != 0) g = index;
261 if(
b != 0)
b = index;
264 if( color == Qt::black )
265 { r = g =
b = index; }
267 scaledColor.setRgb( r,g,
b );
270 QBrush(scaledColor) );
278 e->rect().x(), e->rect().y(),
280 e->rect().x(), e->rect().y(),
281 e->rect().width(), e->rect().height() );
393 int x = QMAX( QMIN( e->pos().x(),
width()-1 ), 0 );
440 int &redLeft,
int &redRight,
441 int &greenLeft,
int &greenRight,
442 int &blueLeft,
int &blueRight)
DISPLAYED_CHANNEL displayedChannel
Currently displayed channel.
void mousePressEvent(QMouseEvent *e)
void selectedRangeChanged()
int redVals[256]
color and luminosity histograms
QSize origImageSize
original image dimensions, needed for painting
bool nearBoundary(QPoint p)
determines if mouse is near boundary
HistogramInterface(QString imageFilename, QWidget *parent=0, const char *name=0)
Creates layout.
void resizeEvent(QResizeEvent *)
void mouseMoveEvent(QMouseEvent *e)
DRAG_MODE dragMode
effect of mouse drags
double displayToIndex(int val)
convert screen coordinate to index in 0-255 range
void setDisplayChannel(DISPLAYED_CHANNEL channel)
Sets currently displayed channel.
DRAG_MODE currentMouseShape
current mouse shape.
int indexToDisplay(int val)
converts index in 0-255 ranges to screen coordinate
void resetBoundaries()
resets all boundaries
void mouseReleaseEvent(QMouseEvent *)
void getSelectedRange(int &left, int &right)
this utility function finds currently selected range
int maxRcount
max r,g,b, and gray counts
~HistogramInterface()
Deletes objects.
void getHistBoundaries(int &lumLeft, int &lumRight, int &redLeft, int &redRight, int &greenLeft, int &greenRight, int &blueLeft, int &blueRight)
returns histogram boundaries
virtual QSize minimumSizeHint() const
int lumClick
left and right bounds for each channel
void paintEvent(QPaintEvent *e)
const QCursor & getCursor(CUSTOM_CURSOR_TYPE type)
DISPLAYED_CHANNEL
chanel histogram displays