#include <photoViewWidget.h>
Definition at line 33 of file photoViewWidget.h.
Public Member Functions | |
| PhotoViewWidget (QWidget *parent=0, const char *name=0) | |
| Creates layout. | |
| ~PhotoViewWidget () | |
| Deletes objects. | |
| void | setPhoto (Photo *photo) |
| Updates displayed photo. | |
| void | getSelection (QPoint &topLeft, QPoint &bottomRight) |
| Returns the current selected coordinates (actual slideshow image space, aka not including buffered whitespace or widget offsets). | |
Protected Member Functions | |
| void | paintEvent (QPaintEvent *e) |
| void | mousePressEvent (QMouseEvent *e) |
| void | mouseReleaseEvent (QMouseEvent *) |
| void | mouseMoveEvent (QMouseEvent *e) |
| void | keyReleaseEvent (QKeyEvent *e) |
Private Slots | |
| void | selectAll () |
Private Member Functions | |
| QPoint | cropSelectedPoint (QPoint p) |
| crops a selected point to within the photo | |
Private Attributes | |
| QPixmap * | photo |
| Photo pixmap. | |
| Photo * | photoObject |
| Photo object handle. | |
| QPoint * | corner1 |
| first corner of selection, where mouse first clicked | |
| QPoint * | corner2 |
| second corner of selection, where mouse moved to | |
| bool | currentlyDragging |
| currently dragging out selection, handle mouse move events | |
|
||||||||||||
|
Creates layout.
Definition at line 30 of file photoViewWidget.cpp. References corner1, corner2, currentlyDragging, photo, photoObject, and selectAll().
00031 :
00032 QWidget(parent,name)
00033 {
00034 photo = NULL;
00035 setPaletteBackgroundColor( QColor(255, 255, 255) );
00036 setMinimumSize(600, 400);
00037
00038 //set default selection off screen
00039 corner1 = new QPoint(-1, -1);
00040 corner2 = new QPoint(-1, -1);
00041
00042 //by default not in drag mode
00043 currentlyDragging = false;
00044
00045 //no photo set yet
00046 photoObject = NULL;
00047
00048 QAccel *keyAccel = new QAccel( this );
00049 keyAccel->connectItem( keyAccel->insertItem( CTRL + Key_A),
00050 this, SLOT(selectAll()) );
00051 }
|
|
|
Deletes objects.
Definition at line 53 of file photoViewWidget.cpp. References photo.
|
|
|
crops a selected point to within the photo
Definition at line 187 of file photoViewWidget.cpp. References Photo::actualSlideshowHeight(), Photo::actualSlideshowWidth(), and photoObject. Referenced by mouseMoveEvent(), and mousePressEvent().
00188 {
00189 int newX = p.x();
00190 int newY = p.y();
00191
00192 int minXAllow, maxXAllow, minYAllow, maxYAllow;
00193 int xdiff, ydiff;
00194
00195 xdiff = width() - photoObject->actualSlideshowWidth();
00196 ydiff = height() - photoObject->actualSlideshowHeight();
00197
00198 minXAllow = xdiff/2;
00199 minYAllow = ydiff/2;
00200
00201 maxXAllow = minXAllow + photoObject->actualSlideshowWidth() - 1;
00202 maxYAllow = minYAllow + photoObject->actualSlideshowHeight() - 1;
00203
00204 if(newX < minXAllow)
00205 newX = minXAllow;
00206 if(newX > maxXAllow)
00207 newX = maxXAllow;
00208 if(newY < minYAllow)
00209 newY = minYAllow;
00210 if(newY > maxYAllow)
00211 newY = maxYAllow;
00212
00213 return QPoint(newX, newY);
00214 }
|
|
||||||||||||
|
Returns the current selected coordinates (actual slideshow image space, aka not including buffered whitespace or widget offsets).
Definition at line 237 of file photoViewWidget.cpp. References Photo::actualSlideshowHeight(), Photo::actualSlideshowWidth(), corner1, corner2, and photoObject. Referenced by PhotoEditWidget::cropToRegion(), and PhotoEditWidget::invertSelection().
00238 {
00239 //if none selected just return that
00240 if(corner1->x() == -1)
00241 {
00242 topLeft.setX(corner1->x());
00243 topLeft.setY(corner1->y());
00244 bottomRight.setX(corner2->x());
00245 bottomRight.setY(corner2->y());
00246 return;
00247 }
00248
00249 //--
00250 //set coordinates based on raw selection
00251 //--
00252 if(corner1->x() < corner2->x())
00253 {
00254 topLeft.setX( corner1->x() );
00255 bottomRight.setX( corner2->x() );
00256 }
00257 else
00258 {
00259 topLeft.setX( corner2->x() );
00260 bottomRight.setX( corner1->x() );
00261 }
00262 //--
00263 if(corner1->y() < corner2->y())
00264 {
00265 topLeft.setY( corner1->y() );
00266 bottomRight.setY( corner2->y() );
00267 }
00268 else
00269 {
00270 topLeft.setY( corner2->y() );
00271 bottomRight.setY( corner1->y() );
00272 }
00273 //--
00274 //subtract offsets from coordinates
00275 int xbuff = (width() - photoObject->actualSlideshowWidth()) / 2;
00276 int ybuff = (height() - photoObject->actualSlideshowHeight()) / 2;
00277 topLeft.setX( topLeft.x() - xbuff );
00278 topLeft.setY( topLeft.y() - ybuff );
00279 bottomRight.setX( bottomRight.x() - xbuff );
00280 bottomRight.setY( bottomRight.y() - ybuff );
00281 //--
00282 }
|
|
|
Definition at line 151 of file photoViewWidget.cpp.
00152 {
00153 cout << "Key Pressed: " << e->ascii() << endl;
00154 }
|
|
|
Definition at line 170 of file photoViewWidget.cpp. References corner2, cropSelectedPoint(), and currentlyDragging.
00171 {
00172 if(!currentlyDragging)
00173 return;
00174
00175 QPoint p = cropSelectedPoint(e->pos());
00176 corner2->setX( p.x() );
00177 corner2->setY( p.y() );
00178
00179 repaint(false);
00180 }
|
|
|
Definition at line 156 of file photoViewWidget.cpp. References corner1, corner2, cropSelectedPoint(), currentlyDragging, and photo.
00157 {
00158 if(photo == NULL)
00159 return;
00160
00161 currentlyDragging = true;
00162 QPoint p = cropSelectedPoint(e->pos());
00163 corner1->setX( p.x() );
00164 corner1->setY( p.y() );
00165 corner2->setX( corner1->x() );
00166 corner2->setY( corner1->y() );
00167 repaint(false);
00168 }
|
|
|
Definition at line 182 of file photoViewWidget.cpp. References currentlyDragging.
00183 {
00184 currentlyDragging = false;
00185 }
|
|
|
Definition at line 80 of file photoViewWidget.cpp. References corner1, corner2, and photo.
00081 {
00082 //if no photo just paint white
00083 if(photo == NULL)
00084 {
00085 QPainter p;
00086 p.begin(this);
00087 p.fillRect(e->rect(), Qt::white);
00088 p.end();
00089 return;
00090 }
00091
00092 //create buffer to draw in
00093 QRect rct = rect();
00094 rct.moveBy(-x(), -y());
00095 QPixmap buffer( size() );
00096
00097 //create a painter pointing to the buffer
00098 QPainter bufferPainter( &buffer );
00099
00100 //first flood entire region with white
00101 buffer.fill( white );
00102
00103 //next paint the image
00104 QRect pr(0, 0, photo->width(), photo->height());
00105 bufferPainter.drawPixmap(pr, *photo);
00106
00107 //next draw selection rectangle
00108 int xmin, xmax, ymin, ymax;
00109
00110 if(corner1->x() < corner2->x())
00111 xmin = corner1->x();
00112 else
00113 xmin = corner2->x();
00114 if(corner1->x() > corner2->x())
00115 xmax = corner1->x();
00116 else
00117 xmax = corner2->x();
00118 if(corner1->y() < corner2->y())
00119 ymin = corner1->y();
00120 else
00121 ymin = corner2->y();
00122 if(corner1->y() > corner2->y())
00123 ymax = corner1->y();
00124 else
00125 ymax = corner2->y();
00126
00127 QRect selection( xmin, ymin, xmax-xmin+1, ymax-ymin+1 );
00128
00129 //construct a pen for selection drawing purposes
00130 QPen selectionPen;
00131
00132 //draw selection in white
00133 selectionPen.setStyle( Qt::SolidLine );
00134 selectionPen.setColor( white );
00135 bufferPainter.setPen( selectionPen);
00136 bufferPainter.drawRect(selection);
00137
00138 //draw selection a second time with dashed black, thus
00139 //producing an alternating black-white selection rectangle
00140 selectionPen.setStyle( Qt::DotLine );
00141 selectionPen.setColor( black );
00142 bufferPainter.setPen( selectionPen);
00143 bufferPainter.drawRect(selection);
00144
00145 bufferPainter.end();
00146
00147 //paint buffer to widget
00148 bitBlt( this, e->rect().topLeft(), &buffer, e->rect() );
00149 }
|
|
|
Definition at line 216 of file photoViewWidget.cpp. References Photo::actualSlideshowHeight(), Photo::actualSlideshowWidth(), corner1, corner2, and photoObject. Referenced by PhotoViewWidget().
00217 {
00218 int minXAllow, maxXAllow, minYAllow, maxYAllow;
00219 int xdiff, ydiff;
00220
00221 xdiff = width() - photoObject->actualSlideshowWidth();
00222 ydiff = height() - photoObject->actualSlideshowHeight();
00223
00224 minXAllow = xdiff/2;
00225 minYAllow = ydiff/2;
00226 maxXAllow = minXAllow + photoObject->actualSlideshowWidth() - 1;
00227 maxYAllow = minYAllow + photoObject->actualSlideshowHeight() - 1;
00228
00229 corner1->setX( minXAllow );
00230 corner1->setY( minYAllow );
00231 corner2->setX( maxXAllow );
00232 corner2->setY( maxYAllow );
00233
00234 repaint(false);
00235 }
|
|
|
Updates displayed photo.
Definition at line 59 of file photoViewWidget.cpp. References corner1, corner2, Photo::getSlideshowFilename(), photo, and photoObject. Referenced by PhotoEditWidget::adjustExposure(), PhotoEditWidget::cropToRegion(), PhotoEditWidget::invertSelection(), PhotoEditWidget::resetImageAction(), and PhotoEditWidget::setPhoto().
00060 {
00061 //delete pixmap
00062 delete photo;
00063
00064 //construct new pixmap
00065 photo = new QPixmap(phto->getSlideshowFilename());
00066
00067 //save photo object handle
00068 photoObject = phto;
00069
00070 //reset selection area to nothing
00071 corner1->setX(-1);
00072 corner1->setY(-1);
00073 corner2->setX(-1);
00074 corner2->setY(-1);
00075
00076 //repaint
00077 repaint(false);
00078 }
|
|
|
first corner of selection, where mouse first clicked
Definition at line 73 of file photoViewWidget.h. Referenced by getSelection(), mousePressEvent(), paintEvent(), PhotoViewWidget(), selectAll(), and setPhoto(). |
|
|
second corner of selection, where mouse moved to
Definition at line 76 of file photoViewWidget.h. Referenced by getSelection(), mouseMoveEvent(), mousePressEvent(), paintEvent(), PhotoViewWidget(), selectAll(), and setPhoto(). |
|
|
currently dragging out selection, handle mouse move events
Definition at line 79 of file photoViewWidget.h. Referenced by mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), and PhotoViewWidget(). |
|
|
Photo pixmap.
Definition at line 67 of file photoViewWidget.h. Referenced by mousePressEvent(), paintEvent(), PhotoViewWidget(), setPhoto(), and ~PhotoViewWidget(). |
|
|
Photo object handle.
Definition at line 70 of file photoViewWidget.h. Referenced by cropSelectedPoint(), getSelection(), PhotoViewWidget(), selectAll(), and setPhoto(). |
1.3.1