13#include <qapplication.h>
21#include <QResizeEvent>
25#include <QDesktopWidget>
35#define MIN(x,y) ((x) < (y) ? (x) : (y))
36#define MAX(x,y) ((x) > (y) ? (x) : (y))
41#define DRAG_THRESHOLD 8
45#define MOVE_THRESHOLD 150
48#define MINIMUM_SELECTION_SIZE 3
54 setWindowFlags(Qt::WNoAutoErase);
64 Q3Accel *keyAccel =
new Q3Accel(
this );
65 keyAccel->connectItem( keyAccel->insertItem( Qt::CTRL + Qt::Key_A),
67 keyAccel->connectItem( keyAccel->insertItem( Qt::CTRL + Qt::SHIFT + Qt::Key_A ),
71 setMouseTracking(
true);
74 setFocusPolicy( Qt::ClickFocus );
95 QRect screenSize = qApp->desktop()->availableGeometry();
115 repaint(resetSelection);
144 rgb = ((QRgb*)scanLine+x);
146 double r = ((double)qRed(*rgb) )/255.0;
147 double g = ((double)qGreen(*rgb) )/255.0;
148 double b = ((double)qBlue(*rgb) )/255.0;
159 int rp = (int)
MIN(
MAX((r*255), 0), 255 );
160 int gp = (int)
MIN(
MAX((g*255), 0), 255 );
161 int bp = (int)
MIN(
MAX((
b*255), 0), 255 );
164 *rgb = qRgb(rp,gp,bp);
178 rct.moveBy(-x(), -y());
182 QPainter bufferPainter( &
buffer );
185 bufferPainter.setClipping(
false);
188 bufferPainter.fillRect(
buffer.rect(), backgroundBrush() );
199 bufferPainter.drawImage( QPoint(xOffset, yOffset),
scaledImage );
212 pen.setStyle( Qt::SolidLine );
213 pen.setCapStyle( Qt::RoundCap );
215 pen.setColor( Qt::green );
216 bufferPainter.setPen( pen);
219 bufferPainter.drawLine( p1.x(), p1.y(), p2.x(), p2.y() );
235 bufferPainter.drawImage( QPoint(xOffset, yOffset),
scaledImage );
255 bufferPainter.drawImage(
topLeft.x(),
268 QColor selectionColor = Qt::gray;
269 QColor textColor = Qt::white;
272 if(selectedWidth == 1) selectedWidth = 0;
273 if(selectedHeight == 1) selectedHeight = 0;
280 int maxDimen = QMAX( selectedWidth, selectedHeight );
284 minDPI = ((
Window*)qApp->mainWidget())->getConfig()->getInt(
"misc",
"minDPI" );
286 { selectionColor = QColor( 200, 0, 0 ); }
288 else { selectionColor = QColor( 0, 200, 0 ); }
290 pen.setStyle( Qt::SolidLine );
292 bufferPainter.setPen( pen);
295 QString selectionText;
298 selectionText = QString(
"%1 x %2 (DPI: %3!)").arg(selectedWidth).arg(selectedHeight).arg(DPI);
300 selectionText = QString(
"%1 x %2").arg(selectedWidth).arg(selectedHeight);
302 QFontMetrics fm( this->font() );
303 int stringWidth = fm.width(selectionText);
304 int stringHeight = fm.ascent();
332 pen.setColor( selectionColor );
333 bufferPainter.setPen( pen);
335 bufferPainter.drawRect(selection);
338 bufferPainter.drawImage( textX, textY-stringHeight,
340 textX - xOffset, textY-stringHeight-yOffset,
341 stringWidth, fm.height() );
345 pen.setColor( textColor );
346 bufferPainter.setPen( pen);
347 bufferPainter.drawText( textX, textY, selectionText );
355 e->rect().x(), e->rect().y(),
357 e->rect().x(), e->rect().y(),
358 e->rect().width(), e->rect().height() );
383 if(p.x() < xOffset || p.x() >=
scaledImage.width() + xOffset ||
384 p.y() < yOffset || p.y() >=
scaledImage.height() + yOffset )
570 setCursor( Qt::ArrowCursor );
586 int newSelectionWidth = -1;
587 int newSelectionHeight = -1;
590 if( curSelectionWidth > curSelectionHeight )
592 newSelectionWidth =
MIN( curSelectionWidth + delta,
origImageSize.width() );
597 newSelectionHeight =
MIN( curSelectionHeight + delta,
origImageSize.height() );
617 if(newSelectionWidth <= 0 || newSelectionHeight <= 0)
619 newSelectionWidth = curSelectionWidth;
620 newSelectionHeight = curSelectionHeight;
627 topLeft.y() + newSelectionHeight - 1 );
673 if(
CTRL_Pressed && !(e->state() & Qt::ControlModifier) )
745 if(offset.x() < 0 &&
topLeft.x() + offset.x() < 0 )
753 if(offset.y() < 0 &&
topLeft.y() + offset.y() < 0 )
891 newPoint.setX( newPoint.x() - xOffset );
892 newPoint.setY( newPoint.y() - yOffset );
929 newPoint.setX( newPoint.x() + xOffset );
930 newPoint.setY( newPoint.y() + yOffset );
942 croppedPoint.setX(
MIN(
MAX(xOffset, p.x()), xOffset +
scaledImage.width() - 1 ) );
943 croppedPoint.setY(
MIN(
MAX(yOffset, p.y()), yOffset +
scaledImage.height() - 1 ) );
1033 if(e->key() == Qt::Key_Escape )
1086 if( e->key() == Qt::Key_Plus ||
1087 e->key() == Qt::Key_Equal ||
1088 e->key() == Qt::Key_Minus ||
1089 e->key() == Qt::Key_Underscore )
1096 if( e->key() == Qt::Key_Minus ||
1097 e->key() == Qt::Key_Underscore )
1120 if( e->key() == Qt::Key_Left ||
1121 e->key() == Qt::Key_Right )
1165 if(dx != 0 || dy != 0)
1176 if(e->key() == Qt::Key_Shift)
1183 else if(e->key() == Qt::Key_Control)
1189 else { e->ignore(); }
QSize cachedSelectionSize
QPoint mousePressPoint
first corner of selection, where mouse first clicked
void ctrlClick()
emitted when a user CTRL-clicks a selection indicating the selection needs to be rotated intelligentl...
bool selectionEmpty()
returns true if selection is empty
void lineSelected(QPoint p1, QPoint p2)
emitted once line has been selected, on or the other points will be set to -1,-1 if the user escaped ...
SelectionInterface(QWidget *parent=0, const char *name=0)
Creates layout.
void selectNone()
selects none of the image
void setPhoto(QString imageFilename, bool resetSelection=true)
Updates displayed photo.
void selectAll()
selects all of the image
bool scaleSelection(int delta)
increase/decrease selection while maintaining aspect ratio by changing selected width by delta
~SelectionInterface()
Deletes objects.
void aspectRatioChanged()
emitted when the user changed the aspect ratio of the selected region
double cropMaxDimen
Current crop max dimension (in inches)
void keyReleaseEvent(QKeyEvent *e)
QPoint ConvertDisplayToImageCoordinate(QPoint p)
converts a point from display coordinates to original image coordinates
QSize origImageSize
original image dimensions
QString origImageFilename
original image filename
DRAG_MODE currentDragMode
method of dragging out, either new selection or resizing selection corner or side
void mouseMoveEvent(QMouseEvent *e)
QPoint ConvertImageToDisplayCoordinate(QPoint p)
converts a point from original image coordinates to display coordinates
void getDisplaySize(int &width, int &height)
returns the current photo display size (in screen pixels)
void paintEvent(QPaintEvent *e)
void updateCursorShape(QPoint p)
update mouse cursor based on position over widget and selected region
void resizeEvent(QResizeEvent *)
void enterDrawLineMode()
enter draw line mode - used for tilt correction
void mousePressEvent(QMouseEvent *e)
QPoint cachedSelctionCenter
cache the aspect ratio when pressing the control buttion, this helps aleviate numerical error that bu...
DRAG_MODE mouseActionByPosition(QPoint p)
determine action based on mouse position
bool SHIFT_Pressed
state of SHIFT button, effects if mouse drags adjust or scale the current selection
void constructDisplayImages()
construct scaled image and unselected images for drawing purposes
void setSelection(QPoint topLeft, QPoint bottomRight, double cropMaxDimen=-1.0)
Sets the current selection cropMaxDimen specifies the idealized dimension in dominant direction in in...
DRAG_MODE currentMouseShape
current mouse shape.
QImage unselectedScaledImage
Grayscale version of scaled image, used for drawing non-selected regions.
QPoint cropSelectedPoint(QPoint p)
crops a selected point to within the photo
void getSelection(QPoint &topLeft, QPoint &bottomRight)
Returns the current selected coordinates (actual slideshow image space, aka not including buffered wh...
QImage scaledImage
Scaled image used for display purposes.
QPoint mouseDragPoint
second corner of selection, where mouse moved to
void keyPressEvent(QKeyEvent *e)
bool CTRL_Pressed
state of CTRL button, effects if mouse clicks rotate current selection
QPoint cachedMousePosition
cached mouse position, used to scale or drag around selection area
void mouseReleaseEvent(QMouseEvent *)
void selectionChanged()
emitted when the user changed the selected region
QImage fullScreenImage
Full screen version of image.
Top level widget, encapsulates the title widget, the layout widget, and the toolbar widget.
const QCursor & getCursor(CUSTOM_CURSOR_TYPE type)
#define MINIMUM_SELECTION_SIZE
DRAG_MODE
current drag mode, effect of mouse movement on current selection
@ MOVE_BOTTOM_RIGHT_CORNER
@ MOVE_BOTTOM_LEFT_CORNER