Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

PhotoViewWidget Class Reference

#include <photoViewWidget.h>

Inheritance diagram for PhotoViewWidget:

Inheritance graph
[legend]
Collaboration diagram for PhotoViewWidget:

Collaboration graph
[legend]
List of all members.

Detailed Description

Display widget for photos. Used by the PhotoEditWidget.

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)

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.

PhotophotoObject
 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


Constructor & Destructor Documentation

PhotoViewWidget::PhotoViewWidget QWidget parent = 0,
const char *  name = 0
 

Creates layout.

Definition at line 28 of file photoViewWidget.cpp.

References corner1, corner2, currentlyDragging, photo, photoObject, and selectAll().

00029                                                                       : 
00030                                                    QWidget(parent,name)
00031 {
00032   photo = NULL;
00033   setPaletteBackgroundColor( QColor(255, 255, 255) );
00034   setMinimumSize(600, 400);
00035   
00036   //set default selection off screen
00037   corner1 = new QPoint(-1, -1);
00038   corner2 = new QPoint(-1, -1);
00039   
00040   //by default not in drag mode
00041   currentlyDragging = false;
00042   
00043   //no photo set yet
00044   photoObject = NULL;
00045   
00046   QAccel *keyAccel = new QAccel( this );
00047   keyAccel->connectItem( keyAccel->insertItem( CTRL + Key_A),
00048                                       this, SLOT(selectAll()) );
00049 }

PhotoViewWidget::~PhotoViewWidget  ) 
 

Deletes objects.

Definition at line 51 of file photoViewWidget.cpp.

References photo.

00052 {
00053   delete photo;
00054   photo = NULL;
00055 }


Member Function Documentation

QPoint PhotoViewWidget::cropSelectedPoint QPoint  p  )  [private]
 

crops a selected point to within the photo

Definition at line 180 of file photoViewWidget.cpp.

References Photo::actualSlideshowHeight(), Photo::actualSlideshowWidth(), and photoObject.

Referenced by mouseMoveEvent(), and mousePressEvent().

00181 {
00182   int newX = p.x();
00183   int newY = p.y();
00184   
00185   int minXAllow, maxXAllow, minYAllow, maxYAllow;
00186   int xdiff, ydiff;
00187     
00188   xdiff = width() - photoObject->actualSlideshowWidth();
00189   ydiff = height() - photoObject->actualSlideshowHeight();
00190 
00191   minXAllow = xdiff/2;
00192   minYAllow = ydiff/2;
00193   
00194   maxXAllow = minXAllow + photoObject->actualSlideshowWidth() - 1;
00195   maxYAllow = minYAllow + photoObject->actualSlideshowHeight() - 1;
00196 
00197   if(newX < minXAllow)
00198     newX = minXAllow;
00199   if(newX > maxXAllow)
00200     newX = maxXAllow;
00201   if(newY < minYAllow)
00202     newY = minYAllow;
00203   if(newY > maxYAllow)
00204     newY = maxYAllow;
00205   
00206   return QPoint(newX, newY);
00207 }

void PhotoViewWidget::getSelection QPoint &  topLeft,
QPoint &  bottomRight
 

Returns the current selected coordinates (actual slideshow image space, aka not including buffered whitespace or widget offsets).

Definition at line 230 of file photoViewWidget.cpp.

References Photo::actualSlideshowHeight(), Photo::actualSlideshowWidth(), corner1, corner2, and photoObject.

Referenced by PhotoEditWidget::findScaledSelection().

00231 {
00232   //if none selected just return that
00233   if(corner1->x() == -1)
00234   {
00235     topLeft.setX(corner1->x());
00236     topLeft.setY(corner1->y());
00237     bottomRight.setX(corner2->x());
00238     bottomRight.setY(corner2->y());
00239     return;
00240   }
00241 
00242   //--
00243   //set coordinates based on raw selection
00244   //--
00245   if(corner1->x() < corner2->x())
00246   {
00247     topLeft.setX( corner1->x() );
00248     bottomRight.setX( corner2->x() );
00249   }
00250   else
00251   {
00252     topLeft.setX( corner2->x() );
00253     bottomRight.setX( corner1->x() );
00254   }
00255   //--
00256   if(corner1->y() < corner2->y())
00257   {
00258     topLeft.setY( corner1->y() );
00259     bottomRight.setY( corner2->y() );
00260   }
00261   else
00262   {
00263     topLeft.setY( corner2->y() );
00264     bottomRight.setY( corner1->y() );
00265   }
00266   //--
00267   //subtract offsets from coordinates
00268   int xbuff = (width() - photoObject->actualSlideshowWidth()) / 2;
00269   int ybuff = (height() - photoObject->actualSlideshowHeight()) / 2;
00270   topLeft.setX( topLeft.x() - xbuff );
00271   topLeft.setY( topLeft.y() - ybuff );
00272   bottomRight.setX( bottomRight.x() - xbuff );
00273   bottomRight.setY( bottomRight.y() - ybuff );
00274   //--
00275 }

void PhotoViewWidget::mouseMoveEvent QMouseEvent *  e  )  [protected]
 

Definition at line 163 of file photoViewWidget.cpp.

References corner2, cropSelectedPoint(), and currentlyDragging.

00164 {
00165   if(!currentlyDragging)
00166     return;
00167     
00168   QPoint p = cropSelectedPoint(e->pos());
00169   corner2->setX( p.x() );
00170   corner2->setY( p.y() );
00171   
00172   repaint(false);
00173 }

void PhotoViewWidget::mousePressEvent QMouseEvent *  e  )  [protected]
 

Definition at line 149 of file photoViewWidget.cpp.

References corner1, corner2, cropSelectedPoint(), currentlyDragging, and photo.

00150 {
00151   if(photo == NULL)
00152     return;
00153     
00154   currentlyDragging = true;
00155   QPoint p = cropSelectedPoint(e->pos());
00156   corner1->setX( p.x() );
00157   corner1->setY( p.y() );
00158   corner2->setX( corner1->x() );
00159   corner2->setY( corner1->y() );
00160   repaint(false);
00161 }

void PhotoViewWidget::mouseReleaseEvent QMouseEvent *   )  [protected]
 

Definition at line 175 of file photoViewWidget.cpp.

References currentlyDragging.

00176 {
00177   currentlyDragging = false;
00178 }

void PhotoViewWidget::paintEvent QPaintEvent *  e  )  [protected]
 

Definition at line 78 of file photoViewWidget.cpp.

References corner1, corner2, and photo.

00079 {  
00080     //if no photo just paint white
00081     if(photo == NULL)
00082     {
00083       QPainter p;
00084       p.begin(this);
00085       p.fillRect(e->rect(), Qt::white);
00086       p.end();
00087       return;
00088     }
00089     
00090     //create buffer to draw in
00091     QRect rct = rect();
00092     rct.moveBy(-x(), -y());
00093     QPixmap buffer( size() );
00094     
00095     //create a painter pointing to the buffer
00096     QPainter bufferPainter( &buffer );
00097 
00098     //first flood entire region with white
00099     buffer.fill( white );
00100     
00101     //next paint the image
00102     QRect pr(0, 0, photo->width(), photo->height());
00103     bufferPainter.drawPixmap(pr, *photo);
00104     
00105     //next draw selection rectangle
00106     int xmin, xmax, ymin, ymax;
00107     
00108     if(corner1->x() < corner2->x())
00109       xmin = corner1->x();
00110     else
00111       xmin = corner2->x();
00112     if(corner1->x() > corner2->x())
00113       xmax = corner1->x();
00114     else
00115       xmax = corner2->x();
00116     if(corner1->y() < corner2->y())
00117       ymin = corner1->y();
00118     else
00119       ymin = corner2->y();
00120     if(corner1->y() > corner2->y())
00121       ymax = corner1->y();
00122     else
00123       ymax = corner2->y();
00124       
00125     QRect selection( xmin, ymin, xmax-xmin+1, ymax-ymin+1 );
00126     
00127     //construct a pen for selection drawing purposes
00128     QPen selectionPen;
00129 
00130     //draw selection in white    
00131     selectionPen.setStyle( Qt::SolidLine );
00132     selectionPen.setColor( white );
00133     bufferPainter.setPen( selectionPen);
00134     bufferPainter.drawRect(selection); 
00135     
00136     //draw selection a second time with dashed black, thus 
00137     //producing an alternating black-white selection rectangle
00138     selectionPen.setStyle( Qt::DotLine );
00139     selectionPen.setColor( black );
00140     bufferPainter.setPen( selectionPen);
00141     bufferPainter.drawRect(selection); 
00142     
00143     bufferPainter.end();
00144     
00145     //paint buffer to widget
00146     bitBlt( this, e->rect().topLeft(), &buffer, e->rect() );
00147 }

void PhotoViewWidget::selectAll  )  [private, slot]
 

Definition at line 209 of file photoViewWidget.cpp.

References Photo::actualSlideshowHeight(), Photo::actualSlideshowWidth(), corner1, corner2, and photoObject.

Referenced by PhotoViewWidget().

00210 {
00211   int minXAllow, maxXAllow, minYAllow, maxYAllow;
00212   int xdiff, ydiff;
00213     
00214   xdiff = width() - photoObject->actualSlideshowWidth();
00215   ydiff = height() - photoObject->actualSlideshowHeight();
00216 
00217   minXAllow = xdiff/2;
00218   minYAllow = ydiff/2;  
00219   maxXAllow = minXAllow + photoObject->actualSlideshowWidth() - 1;
00220   maxYAllow = minYAllow + photoObject->actualSlideshowHeight() - 1;
00221 
00222   corner1->setX( minXAllow );
00223   corner1->setY( minYAllow );
00224   corner2->setX( maxXAllow );
00225   corner2->setY( maxYAllow );
00226 
00227   repaint(false);
00228 }

void PhotoViewWidget::setPhoto Photo photo  ) 
 

Updates displayed photo.

Definition at line 57 of file photoViewWidget.cpp.

References corner1, corner2, Photo::getSlideshowFilename(), photo, and photoObject.

Referenced by PhotoEditWidget::applyImageUpdate(), PhotoEditWidget::resetImageAction(), and PhotoEditWidget::setPhoto().

00058 {
00059   //delete pixmap
00060   delete photo;
00061   
00062   //construct new pixmap
00063   photo = new QPixmap(phto->getSlideshowFilename());  
00064   
00065   //save photo object handle
00066   photoObject = phto;
00067   
00068   //reset selection area to nothing
00069   corner1->setX(-1); 
00070   corner1->setY(-1);
00071   corner2->setX(-1); 
00072   corner2->setY(-1);
00073   
00074   //repaint
00075   repaint(false);
00076 }


Member Data Documentation

QPoint* PhotoViewWidget::corner1 [private]
 

first corner of selection, where mouse first clicked

Definition at line 72 of file photoViewWidget.h.

Referenced by getSelection(), mousePressEvent(), paintEvent(), PhotoViewWidget(), selectAll(), and setPhoto().

QPoint* PhotoViewWidget::corner2 [private]
 

second corner of selection, where mouse moved to

Definition at line 75 of file photoViewWidget.h.

Referenced by getSelection(), mouseMoveEvent(), mousePressEvent(), paintEvent(), PhotoViewWidget(), selectAll(), and setPhoto().

bool PhotoViewWidget::currentlyDragging [private]
 

currently dragging out selection, handle mouse move events

Definition at line 78 of file photoViewWidget.h.

Referenced by mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), and PhotoViewWidget().

QPixmap* PhotoViewWidget::photo [private]
 

Photo pixmap.

Definition at line 66 of file photoViewWidget.h.

Referenced by mousePressEvent(), paintEvent(), PhotoViewWidget(), setPhoto(), and ~PhotoViewWidget().

Photo* PhotoViewWidget::photoObject [private]
 

Photo object handle.

Definition at line 69 of file photoViewWidget.h.

Referenced by cropSelectedPoint(), getSelection(), PhotoViewWidget(), selectAll(), and setPhoto().


The documentation for this class was generated from the following files:
Generated on Thu Nov 13 00:11:13 2003 for AlbumShaper by doxygen 1.3.4