13 #include <qapplication.h> 20 #include <QPaintEvent> 21 #include <QResizeEvent> 23 #include <QMouseEvent> 25 #include <QDesktopWidget> 29 #include "../cursors.h" 30 #include "../../config.h" 31 #include "../../backend/tools/imageTools.h" 32 #include "../window.h" 33 #include "../../configuration/configuration.h" 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(),
258 topLeft.x()-xOffset, topLeft.y()-yOffset,
259 bottomRight.x() - topLeft.x(),
260 bottomRight.y() - topLeft.y() );
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();
316 textX =
MAX( xOffset + TEXT_MARGIN,
317 topLeft.x() - TEXT_MARGIN - stringWidth );
323 bottomRight.y() + TEXT_MARGIN + stringHeight);
327 textY =
MAX( yOffset + TEXT_MARGIN + stringHeight,
332 pen.setColor( selectionColor );
333 bufferPainter.setPen( pen);
334 QRect selection( topLeft, bottomRight );
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() );
377 QPoint center( (topLeft.x() + bottomRight.x()) / 2,
378 (topLeft.y() + bottomRight.y()) / 2);
383 if(p.x() < xOffset || p.x() >=
scaledImage.width() + xOffset ||
384 p.y() < yOffset || p.y() >=
scaledImage.height() + yOffset )
390 ( bottomRight.x() - topLeft.x() ==
origImageSize.width() - 1 &&
391 bottomRight.y() - topLeft.y() ==
origImageSize.height() - 1 )
424 p.y() >= topLeft.y() &&
425 p.y() <= bottomRight.y() )
429 p.y() >= topLeft.y() &&
430 p.y() <= bottomRight.y() )
434 p.x() >= topLeft.x() &&
435 p.x() <= bottomRight.x() )
439 p.x() >= topLeft.x() &&
440 p.x() <= bottomRight.x() )
497 mouseDragPoint = QPoint( topLeft.x(), bottomRight.y() );
570 setCursor( Qt::ArrowCursor );
584 int curSelectionWidth = bottomRight.x() - topLeft.x() + 1;
585 int curSelectionHeight = bottomRight.y()- topLeft.y() + 1;
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;
626 bottomRight = QPoint( topLeft.x() + newSelectionWidth - 1,
627 topLeft.y() + newSelectionHeight - 1 );
633 topLeft.setX( topLeft.x() - diff );
634 bottomRight.setX( bottomRight.x() - diff );
645 topLeft.setY( topLeft.y() - diff );
646 bottomRight.setY( bottomRight.y() - diff );
673 if(
CTRL_Pressed && !(e->state() & Qt::ControlModifier) )
716 bottomRight.x() > topLeft.x() &&
717 bottomRight.y() > topLeft.y() )
745 if(offset.x() < 0 && topLeft.x() + offset.x() < 0 )
746 offset.setX( -topLeft.x() );
749 if(offset.x() > 0 && bottomRight.x() + offset.x() >=
origImageSize.width() )
753 if(offset.y() < 0 && topLeft.y() + offset.y() < 0 )
754 offset.setY( -topLeft.y() );
757 if(offset.y() > 0 && bottomRight.y() + offset.y() >=
origImageSize.height() )
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 ) );
1008 topLeft.setX(-1); topLeft.setY(-1);
1009 bottomRight.setX(-1); bottomRight.setY(-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 )
1136 dx = QMAX( topLeft.x() - moveBy, 0) - topLeft.x();
1139 dx =
MIN( bottomRight.x() + moveBy,
origImageSize.width() - 1) - bottomRight.x();
1142 dy =
MAX( topLeft.y() - moveBy, 0) - topLeft.y();
1145 dy =
MIN( bottomRight.y() + moveBy,
origImageSize.height() - 1) - bottomRight.y();
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 origImageSize
original image dimensions
void mousePressEvent(QMouseEvent *e)
void updateCursorShape(QPoint p)
update mouse cursor based on position over widget and selected region
void keyPressEvent(QKeyEvent *e)
QString origImageFilename
original image filename
~SelectionInterface()
Deletes objects.
Top level widget, encapsulates the title widget, the layout widget, and the toolbar widget...
void selectionChanged()
emitted when the user changed the selected region
void constructDisplayImages()
construct scaled image and unselected images for drawing purposes
QPoint mousePressPoint
first corner of selection, where mouse first clicked
DRAG_MODE
current drag mode, effect of mouse movement on selected range
double cropMaxDimen
Current crop max dimension (in inches)
QPoint mouseDragPoint
second corner of selection, where mouse moved to
void keyReleaseEvent(QKeyEvent *e)
void enterDrawLineMode()
enter draw line mode - used for tilt correction
bool SHIFT_Pressed
state of SHIFT button, effects if mouse drags adjust or scale the current selection ...
void setPhoto(QString imageFilename, bool resetSelection=true)
Updates displayed photo.
DRAG_MODE currentDragMode
method of dragging out, either new selection or resizing selection corner or side ...
QPoint cropSelectedPoint(QPoint p)
crops a selected point to within the photo
void selectAll()
selects all of the image
QPoint ConvertDisplayToImageCoordinate(QPoint p)
converts a point from display coordinates to original image coordinates
void mouseReleaseEvent(QMouseEvent *)
void paintEvent(QPaintEvent *e)
void getSelection(QPoint &topLeft, QPoint &bottomRight)
Returns the current selected coordinates (actual slideshow image space, aka not including buffered wh...
bool CTRL_Pressed
state of CTRL button, effects if mouse clicks rotate current selection
QPoint cachedSelctionCenter
cache the aspect ratio when pressing the control buttion, this helps aleviate numerical error that bu...
void getDisplaySize(int &width, int &height)
returns the current photo display size (in screen pixels)
void setSelection(QPoint topLeft, QPoint bottomRight, double cropMaxDimen=-1.0)
Sets the current selection cropMaxDimen specifies the idealized dimension in dominant direction in in...
const QCursor & getCursor(CUSTOM_CURSOR_TYPE type)
DRAG_MODE currentMouseShape
current mouse shape.
void aspectRatioChanged()
emitted when the user changed the aspect ratio of the selected region
#define MINIMUM_SELECTION_SIZE
QPoint cachedMousePosition
cached mouse position, used to scale or drag around selection area
void resizeEvent(QResizeEvent *)
void selectNone()
selects none of the image
void ctrlClick()
emitted when a user CTRL-clicks a selection indicating the selection needs to be rotated intelligentl...
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 ...
bool scaleSelection(int delta)
increase/decrease selection while maintaining aspect ratio by changing selected width by delta ...
QSize cachedSelectionSize
QImage unselectedScaledImage
Grayscale version of scaled image, used for drawing non-selected regions.
void mouseMoveEvent(QMouseEvent *e)
QPoint ConvertImageToDisplayCoordinate(QPoint p)
converts a point from original image coordinates to display coordinates
bool selectionEmpty()
returns true if selection is empty
DRAG_MODE mouseActionByPosition(QPoint p)
determine action based on mouse position
SelectionInterface(QWidget *parent=0, const char *name=0)
Creates layout.
QImage scaledImage
Scaled image used for display purposes.
QImage fullScreenImage
Full screen version of image.