SubalbumPreviewWidget Class Reference

Displays subalbum icon and name. More...

#include <subalbumPreviewWidget.h>

Inheritance diagram for SubalbumPreviewWidget:
[legend]
Collaboration diagram for SubalbumPreviewWidget:
[legend]

List of all members.

Public Member Functions

 SubalbumPreviewWidget (SubalbumsIconView *parent, Subalbum *salbum)
 Sets subalbum pointer.
SubalbumgetSubalbum ()
 Returns subalbum pointer.
void paintFocus (QPainter *p, const QColorGroup &cg)
bool acceptDrop (const QMimeSource *e) const
int compare (QIconViewItem *i) const
void setText (const QString &text)
void setMousedOver (bool val)
void paint (QPainter *p)

Static Public Member Functions

static QPixmap * createSubalbumPixmap (QString imageName)

Protected Member Functions

void calcRect (const QString &text_=QString::null)
void paintItem (QPainter *p, const QColorGroup &cg)

Private Member Functions

void dropped (QDropEvent *e, const QValueList< QIconDragItem > &lst)
QColor blendColors (QColor a, QColor b, double alpha)
void initializeItemRect ()

Private Attributes

Subalbumsubalbum
 Pointer to subalbum backend object.
QPixmap * subalbumPreviewImage
 Representative Image for Subalbum.
QString * subalbumName
 Subalbum's Name.
SubalbumsIconViewparent
 parent icon view
bool mousedOver
 is the mouse over the widget

Detailed Description

Displays subalbum icon and name.

Definition at line 29 of file subalbumPreviewWidget.h.


Constructor & Destructor Documentation

SubalbumPreviewWidget::SubalbumPreviewWidget ( SubalbumsIconView parent,
Subalbum salbum 
)

Sets subalbum pointer.

Definition at line 34 of file subalbumPreviewWidget.cpp.

References initializeItemRect(), mousedOver, and subalbum.

00035           : QIconViewItem(parent, 
00036                           clipText( salbum->getName(), 2, parent->getTextWidth()),
00037                           *salbum->getRepresentativeImage(MEDIUM) )
00038 {         
00039   mousedOver = false;
00040   this->parent = parent;
00041   subalbum = salbum;
00042   
00043   //initialize item rectangle
00044   initializeItemRect();
00045 }


Member Function Documentation

bool SubalbumPreviewWidget::acceptDrop ( const QMimeSource *  e  )  const

Definition at line 246 of file subalbumPreviewWidget.cpp.

00247 {
00248   return true;
00249 }

QColor SubalbumPreviewWidget::blendColors ( QColor  a,
QColor  b,
double  alpha 
) [private]

Definition at line 380 of file subalbumPreviewWidget.cpp.

Referenced by paintItem().

00381 {
00382   double alpha2 = 1-alpha;
00383   return QColor( (int)(alpha*a.red() + alpha2*b.red()),
00384                           (int)(alpha*a.green() + alpha2*b.green()),
00385                           (int)(alpha*a.blue() + alpha2*b.blue()) );
00386 }

void SubalbumPreviewWidget::calcRect ( const QString &  text_ = QString::null  )  [protected]

Definition at line 336 of file subalbumPreviewWidget.cpp.

References initializeItemRect().

00337 {  
00338   //setup default dimensions
00339   QIconViewItem::calcRect( text_ );  
00340 
00341   //update using init method
00342   initializeItemRect();
00343 }  

int SubalbumPreviewWidget::compare ( QIconViewItem i  )  const

Definition at line 251 of file subalbumPreviewWidget.cpp.

00252 {
00253   if(pos().y() >= i->pos().y())
00254   {  return 1; }
00255   else
00256   { return -1; }
00257 }

QPixmap * SubalbumPreviewWidget::createSubalbumPixmap ( QString  imageName  )  [static]

Definition at line 259 of file subalbumPreviewWidget.cpp.

References calcScaledImageDimensions().

Referenced by Subalbum::setRepresentativeImage(), and Subalbum::Subalbum().

00260 {
00261   //load image
00262   QImage icon(imageName);
00263 
00264   //if null then bail immediately
00265   if( icon.isNull() )
00266     return NULL;
00267   
00268   //----------------------------------------------
00269   //resize image based on text properties. Find ideal hight
00270   QFontMetrics fm( qApp->font() );
00271 
00272   //ideal image height is two text lines, 1 pixel inbetween
00273   int idealImageHeight = fm.leading() + 2*fm.height();
00274 
00275  //ideal image width assuming 4:3 aspect ratio
00276  int idealImageWidth = (4 * idealImageHeight ) / 3;
00277  //----------------------------------------------
00278  //resize image to fit within bounding rectangle, pad and center as necessary
00279  int actualImageWidth = 0;
00280  int actualImageHeight = 0;
00281  calcScaledImageDimensions( icon.width(), icon.height(),
00282                             idealImageWidth, idealImageHeight,
00283                             actualImageWidth, actualImageHeight );
00284 
00285   //if off by one pixel fudge it so icon perfectly cenetered
00286   if(actualImageHeight == idealImageHeight - 1)
00287   {
00288     actualImageHeight = idealImageHeight;
00289   }
00290 
00291   QImage scaledIcon= icon.smoothScale( actualImageWidth, actualImageHeight );
00292   QImage* paddedScaledIcon = new QImage(idealImageWidth, idealImageHeight, scaledIcon.depth());
00293   paddedScaledIcon->setAlphaBuffer(true);
00294 
00295   //make entire image transparent
00296   int x, y;
00297   for(x=0; x< idealImageWidth; x++)
00298   {
00299     for(y=0; y<idealImageHeight; y++)
00300     {
00301       paddedScaledIcon->setPixel(x,y, qRgba(255, 255, 255,0) );
00302     }
00303   }
00304 
00305   //paint image in center of padded region
00306   int xDiff = idealImageWidth - actualImageWidth;
00307   int yDiff = idealImageHeight  - actualImageHeight;
00308   int x2 = 0;
00309   for(x= xDiff/2; x < (xDiff/2) + actualImageWidth; x++)
00310   {
00311     int y2 = 0;
00312     for(y= yDiff/2; y < (yDiff/2) + actualImageHeight; y++)
00313     {
00314       paddedScaledIcon->setPixel(x, y, scaledIcon.pixel(x2, y2));
00315        y2++;
00316     }
00317     x2++;
00318   }
00319 
00320   //clip corners if image takes up full width
00321   if(xDiff == 0)
00322   {
00323       paddedScaledIcon->setPixel(0, 0, qRgba(255, 0,0,0) );
00324       paddedScaledIcon->setPixel(idealImageWidth-1, 0, qRgba(255, 0,0,0) );
00325       paddedScaledIcon->setPixel(0, idealImageHeight-1, qRgba(255, 0,0,0) );
00326       paddedScaledIcon->setPixel(idealImageWidth-1, idealImageHeight-1, qRgba(255, 0,0,0) );
00327   }
00328 
00329   QPixmap* padddedScaledPix = new QPixmap( paddedScaledIcon->width(), paddedScaledIcon->height() );
00330   padddedScaledPix->convertFromImage( *paddedScaledIcon );
00331   delete paddedScaledIcon;
00332   return padddedScaledPix;
00333  //----------------------------------------------
00334 }

void SubalbumPreviewWidget::dropped ( QDropEvent *  e,
const QValueList< QIconDragItem > &  lst 
) [private]

Definition at line 175 of file subalbumPreviewWidget.cpp.

References Subalbum::addPhoto(), SubalbumWidget::getPhotos(), SubalbumWidget::getSubalbum(), height, parent, Subalbum::photoMoved(), and subalbum.

00176 {
00177   //if source is not from the application then ignore
00178   if(e->source() == NULL)
00179     return;
00180     
00181   //if source of drop event is from this widget when user is attempting to
00182   //rearrange subalbums, move currently selected item to
00183   //approximately where the cursor is before rearranging items
00184   if(e->source()->parentWidget() == parent)
00185   {
00186     if(e->pos().y() < (y() + (height()/2)))
00187     {
00188       parent->currentItem()->move(x(), y() - 1);
00189     }
00190     else
00191     {
00192       parent->currentItem()->move(x(), y() + (height()/2) + 1);
00193     }
00194   }
00195   //else check to see if user dropped photo(s) on subalbum
00196   else
00197   {
00198     //if the source of the items is the current subalbum icon view and
00199     //this is a different subalbum then
00200     //move photos from that subalbum to this one
00201     if(
00202          !isSelected() &&
00203          (
00204            e->source()->parentWidget() ==
00205            ((LayoutWidget*)(parent->parentWidget()->parentWidget()))->getSubalbum()->getPhotos()
00206          )
00207        )
00208     {
00209       //iterate over all selected photos, inserting each
00210       //into this subalbum, removing from old subalbum,
00211       //and deleting old photo widgets
00212       SubalbumWidget* oldSubalbumWidget = ((LayoutWidget*)(parent->parentWidget()->parentWidget()))->getSubalbum();
00213       Subalbum* oldSubalbum = oldSubalbumWidget->getSubalbum();
00214       QIconViewItem* current = oldSubalbumWidget->getPhotos()->firstItem();
00215       while(current != NULL)
00216       {
00217        //found a selected photo
00218         if(current->isSelected())
00219         {
00220           //get pointer to photo
00221           Photo* photo = ((PhotoPreviewWidget*)current)->getPhoto();
00222 
00223           //remove photo from that subalbum
00224           oldSubalbum->photoMoved(photo);
00225 
00226           //add photo to this subalbum
00227           subalbum->addPhoto(photo);
00228 
00229           //delete photo widget and rearrange photos
00230           QIconViewItem* temp = current;
00231           current = current->nextItem();
00232           delete temp;
00233         }
00234         else
00235         {
00236           current = current->nextItem();
00237         }
00238       } //end while
00239 
00240       //reannarge photos once all photos have been removed
00241       oldSubalbumWidget->getPhotos()->arrangeItemsInGrid();
00242     }
00243   }
00244 }

Subalbum * SubalbumPreviewWidget::getSubalbum (  ) 

Returns subalbum pointer.

Definition at line 47 of file subalbumPreviewWidget.cpp.

References subalbum.

Referenced by Album::syncSubalbumList().

00048 {
00049   return subalbum;
00050 }

void SubalbumPreviewWidget::initializeItemRect (  )  [private]

Definition at line 345 of file subalbumPreviewWidget.cpp.

References SubalbumsIconView::getTextWidth(), and parent.

Referenced by calcRect(), and SubalbumPreviewWidget().

00346 {
00347   //reset pixmap rect
00348   QRect pr = pixmapRect();
00349   int prWidth  = pr.width();
00350   int prHeight = pr.height();
00351   pr.setTopLeft( QPoint(3,3) );
00352   pr.setBottomRight( QPoint(pr.left()+prWidth, pr.top()+prHeight) );
00353   setPixmapRect( pr );
00354   
00355   //reset text rect
00356   int textWidth = parent->getTextWidth();
00357   QRect tr = textRect();
00358   tr.setTop( pixmapRect().top() );
00359   tr.setBottom( pixmapRect().bottom() );
00360   tr.setLeft( pixmapRect().right() + 2 );
00361   tr.setRight( tr.left() + textWidth );
00362   setTextRect( tr );
00363   
00364   //reset item rect using pixmap and text rect dimensions
00365   int itemW = 3 + pixmapRect().width() + (tr.left() - pr.right()) + textRect().width() + 3;
00366   int itemH = 3 + pixmapRect().height() + 3;
00367   setItemRect( QRect( pixmapRect().left() - 3, pixmapRect().top() - 3, itemW, itemH ) );
00368 }

void SubalbumPreviewWidget::paint ( QPainter *  p  ) 

Definition at line 54 of file subalbumPreviewWidget.cpp.

References paintItem().

00055 {
00056   paintItem( p, QColorGroup() );
00057 }

void SubalbumPreviewWidget::paintFocus ( QPainter *  p,
const QColorGroup &  cg 
)

Definition at line 52 of file subalbumPreviewWidget.cpp.

00052 { }

void SubalbumPreviewWidget::paintItem ( QPainter *  p,
const QColorGroup &  cg 
) [protected]

Definition at line 59 of file subalbumPreviewWidget.cpp.

References blendColors(), buffer, height, mousedOver, and width.

Referenced by paint().

00060 {
00061   QColor lightLightBlue( 152, 180, 226 );
00062   QColor darkLightBlue(193, 210, 238);
00063   QColor darkBlue(35, 75, 139);
00064   QColor background = darkLightBlue;
00065   
00066   //resize old static buffer to new needed size, fill with widget background color
00067   static QPixmap buffer;
00068   QRect r = rect();
00069   QSize newSize = r.size().expandedTo(buffer.size() );
00070   buffer.resize(newSize);
00071   buffer.fill( background );
00072 
00073   //construct painter for buffer
00074   QPainter bufferPainter(&buffer, this);
00075   bufferPainter.translate( -r.x(), -r.y() );
00076 
00077   //turn off clipping to make painting operations faster
00078   bufferPainter.setClipping(false);
00079   
00080   //paint mouse over or actual selection color
00081   bool paintRect = false;
00082   QColor paintColor;
00083   if(isSelected()) { paintColor = darkBlue; paintRect = true; }
00084   else if(mousedOver) { paintColor = lightLightBlue; paintRect = true; }
00085 
00086   if(paintRect)
00087   {
00088      //first paint alpha blended edges
00089 
00090      //-------------------------
00091      //top and bottom edges
00092      QRect r2 = r;
00093      r2.setLeft( r.left() + 4);
00094      r2.setRight( r.right() - 4);
00095      r2.setTop( r.top() );
00096      r2.setBottom( r.bottom() );
00097      bufferPainter.fillRect( r2, blendColors( paintColor, background, 0.40 ) );
00098 
00099      r2.setLeft( r2.left() + 1);
00100      r2.setRight( r2.right() - 1);
00101      bufferPainter.fillRect( r2, blendColors( paintColor, background, 0.67 ) );
00102      //-------------------------
00103      //inner top and bottom edges
00104      r2.setLeft( r2.left() - 3);
00105      r2.setRight( r2.right() + 3);
00106      r2.setTop( r2.top() + 1 );
00107      r2.setBottom( r2.bottom() - 1);
00108      bufferPainter.fillRect( r2, blendColors( paintColor, background, 0.40 ) );
00109 
00110      r2.setLeft( r2.left() + 1);
00111      r2.setRight( r2.right() - 1);
00112      bufferPainter.fillRect( r2, blendColors( paintColor, background, 0.67 ) );
00113      //-------------------------
00114      //left and right inner edges
00115      r2.setLeft( r2.left() - 2);
00116      r2.setRight( r2.right() + 2);
00117      r2.setTop( r2.top() + 1 );
00118      r2.setBottom( r2.bottom() - 1);
00119      bufferPainter.fillRect( r2, blendColors( paintColor, background, 0.40) );
00120 
00121      r2.setTop( r2.top() + 1);
00122      r2.setBottom( r2.bottom() - 1);
00123      bufferPainter.fillRect( r2, blendColors( paintColor, background, 0.67) );
00124      //-------------------------
00125      // middle region
00126      r2.setLeft( r2.left() - 1 );
00127      r2.setRight( r2.right() + 1 );
00128      r2.setTop( r2.top() + 1);
00129      r2.setBottom( r2.bottom() - 1);
00130      bufferPainter.fillRect( r2, blendColors( paintColor, background, 0.40) );
00131 
00132      r2.setTop( r2.top() + 1);
00133      r2.setBottom( r2.bottom() - 1);
00134      bufferPainter.fillRect( r2, blendColors( paintColor, background, 0.67) );
00135      //-------------------------
00136      //second paint inner selection
00137      r2 = r;
00138      r2.setLeft( r.left() + 1);
00139      r2.setRight( r.right() - 1);
00140      r2.setTop( r.top() + 4 );
00141      r2.setBottom( r.bottom() - 4);
00142      bufferPainter.fillRect( r2, paintColor );
00143 
00144      r2.setLeft( r2.left() + 1);
00145      r2.setRight( r2.right() - 1);
00146      r2.setTop( r2.top() - 2 );
00147      r2.setBottom( r2.bottom() + 2 );
00148      bufferPainter.fillRect( r2, paintColor );
00149 
00150      r2.setLeft( r2.left() + 2);
00151      r2.setRight( r2.right() - 2);
00152      r2.setTop( r2.top() - 1 );
00153      r2.setBottom( r2.bottom() + 1 );
00154      bufferPainter.fillRect( r2, paintColor );
00155   }
00156 
00157   //paint pixmap
00158   bufferPainter.drawPixmap( x()+4 , y() + 4, *pixmap());
00159 
00160   //paint text
00161   int align = AlignLeft | AlignTop | BreakAnywhere;
00162   if(isSelected())
00163     bufferPainter.setPen( white );
00164   else
00165     bufferPainter.setPen( black );
00166   bufferPainter.drawText( x() + 4 + pixmapRect().width(),
00167                                         y() + 4,
00168                                         textRect().width(), textRect().height(),
00169                                         align, text() );
00170 
00171   //draw buffer to screen
00172   p->drawPixmap( x(), y(), buffer );
00173 }

void SubalbumPreviewWidget::setMousedOver ( bool  val  ) 
void SubalbumPreviewWidget::setText ( const QString &  text  ) 

Definition at line 370 of file subalbumPreviewWidget.cpp.

References clipText(), SubalbumsIconView::getTextWidth(), and parent.

00371 {
00372   QIconViewItem::setText( clipText(text, 2, parent->getTextWidth()), false );
00373 }


Member Data Documentation

is the mouse over the widget

Definition at line 74 of file subalbumPreviewWidget.h.

Referenced by paintItem(), setMousedOver(), and SubalbumPreviewWidget().

parent icon view

Definition at line 71 of file subalbumPreviewWidget.h.

Referenced by dropped(), initializeItemRect(), and setText().

Pointer to subalbum backend object.

Definition at line 62 of file subalbumPreviewWidget.h.

Referenced by dropped(), getSubalbum(), and SubalbumPreviewWidget().

Subalbum's Name.

Definition at line 68 of file subalbumPreviewWidget.h.

Representative Image for Subalbum.

Definition at line 65 of file subalbumPreviewWidget.h.


The documentation for this class was generated from the following files:
Generated on Sun Dec 5 14:44:58 2010 for AlbumShaper by  doxygen 1.6.3