12 #include <qapplication.h> 19 #include <QPaintEvent> 20 #include <QResizeEvent> 21 #include <QMouseEvent> 22 #include <QDesktopWidget> 27 #include "../../backend/tools/imageTools.h" 28 #include "../cursors.h" 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;
164 buffer.fill( Qt::white );
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 );
268 bufferPainter.fillRect( QRect(x, histogramHeight +
COLOR_BAR_MARGIN + COLOR_BAR_BORDER,
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)
int redVals[256]
color and luminosity histograms
void resizeEvent(QResizeEvent *)
void paintEvent(QPaintEvent *e)
HistogramInterface(QString imageFilename, QWidget *parent=0, const char *name=0)
Creates layout.
int maxRcount
max r,g,b, and gray counts
~HistogramInterface()
Deletes objects.
void setDisplayChannel(DISPLAYED_CHANNEL channel)
Sets currently displayed channel.
QSize origImageSize
original image dimensions, needed for painting
double displayToIndex(int val)
convert screen coordinate to index in 0-255 range
DISPLAYED_CHANNEL
chanel histogram displays
void selectedRangeChanged()
void mousePressEvent(QMouseEvent *e)
int indexToDisplay(int val)
converts index in 0-255 ranges to screen coordinate
const QCursor & getCursor(CUSTOM_CURSOR_TYPE type)
virtual QSize minimumSizeHint() const
int lumClick
left and right bounds for each channel
void getSelectedRange(int &left, int &right)
this utility function finds currently selected range
void mouseReleaseEvent(QMouseEvent *)
DRAG_MODE dragMode
effect of mouse drags
bool nearBoundary(QPoint p)
determines if mouse is near boundary
DISPLAYED_CHANNEL displayedChannel
Currently displayed channel.
void getHistBoundaries(int &lumLeft, int &lumRight, int &redLeft, int &redRight, int &greenLeft, int &greenRight, int &blueLeft, int &blueRight)
returns histogram boundaries
void resetBoundaries()
resets all boundaries
void mouseMoveEvent(QMouseEvent *e)
DRAG_MODE currentMouseShape
current mouse shape.