AlbumShaper
1.0a3
|
Extension of iconview, used to list all subalbums in album. Supports drag-n-drop within iconview such that subalbums can be reordered, as well as dropping photos from subalbums to allow photos to be moved from one subalbum to another. More...
#include <subalbumsIconView.h>
Signals | |
void | itemHasMoved () |
Public Member Functions | |
SubalbumsIconView (QWidget *parent) | |
int | getTextWidth () |
QSize | minimumSizeHint () const |
QSize | sizeHint () const |
Protected Member Functions | |
void | drawContents (QPainter *p, int clipx, int clipy, int clipw, int cliph) |
QDragObject * | dragObject () |
void | contentsMousePressEvent (QMouseEvent *e) |
void | contentsDragMoveEvent (QDragMoveEvent *e) |
Private Slots | |
void | repaintGroup (QIconViewItem *pseudoSelection) |
void | clearPseudoSelection () |
Private Member Functions | |
void | contentsDropEvent (QDropEvent *e) |
Private Attributes | |
QPixmap | bufferPixmap |
QPoint | dragStartPos |
SubalbumPreviewWidget * | currentPseudoSelection |
int | textWidth |
Extension of iconview, used to list all subalbums in album. Supports drag-n-drop within iconview such that subalbums can be reordered, as well as dropping photos from subalbums to allow photos to be moved from one subalbum to another.
Definition at line 31 of file subalbumsIconView.h.
SubalbumsIconView::SubalbumsIconView | ( | QWidget * | parent | ) |
Definition at line 28 of file subalbumsIconView.cpp.
References clearPseudoSelection(), currentPseudoSelection, repaintGroup(), and textWidth.
: QIconView( parent ) { // setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum); setMouseTracking(true); currentPseudoSelection = NULL; //connect mouse over events to paint pseudo selection in ligher blue connect( this, SIGNAL(onItem(QIconViewItem*)), this, SLOT(repaintGroup(QIconViewItem*)) ); //clear any pseudo selection when mouse moves off icons connect( this, SIGNAL(onViewport()), this, SLOT(clearPseudoSelection()) ); //compute textWidth for collection names using a calibration string QString calibrationString( qApp->translate("SubalbumPreviewWidget", "Calibration String") ); QFontMetrics fm( qApp->font() ); textWidth = fm.width( calibrationString ); }
void SubalbumsIconView::clearPseudoSelection | ( | ) | [private, slot] |
Definition at line 167 of file subalbumsIconView.cpp.
References currentPseudoSelection, and SubalbumPreviewWidget::setMousedOver().
Referenced by repaintGroup(), and SubalbumsIconView().
{ //if old pseudo selection unselect it if(currentPseudoSelection != NULL) { currentPseudoSelection->setMousedOver(false); repaintItem(currentPseudoSelection); currentPseudoSelection = NULL; } }
void SubalbumsIconView::contentsDragMoveEvent | ( | QDragMoveEvent * | e | ) | [protected] |
Definition at line 111 of file subalbumsIconView.cpp.
References currentPseudoSelection, and SubalbumPreviewWidget::setMousedOver().
{ QIconView::contentsDragMoveEvent( e ); e->accept(true); //if source of drag is not from application then return if(e->source() == NULL) return; //if source of drag is from within this view then return, in the future we'll put //drag code in here to drag indicators for rearranging the items of the iconview if(e->source() == viewport() ) { } //else if source is from photos iconview else if(e->source()->parentWidget() == ((LayoutWidget*)parentWidget()->parentWidget())->getSubalbum()->getPhotos() ) { SubalbumPreviewWidget* item = (SubalbumPreviewWidget*)findItem( e->pos() ); //if item pointer same as current pseudo selection ignore if(item == currentPseudoSelection) { return; } //unpaint old selection if(currentPseudoSelection != NULL) { currentPseudoSelection->setMousedOver(false); repaintItem(currentPseudoSelection); } //set new selection currentPseudoSelection = item; //repaint new selection if(currentPseudoSelection != NULL) { currentPseudoSelection->setMousedOver(true); repaintItem(currentPseudoSelection); } } }
void SubalbumsIconView::contentsDropEvent | ( | QDropEvent * | e | ) | [private] |
Definition at line 49 of file subalbumsIconView.cpp.
References itemHasMoved().
{ QIconView::contentsDropEvent( e ); //if drop originated from this viewport then emit item moved signal if(e->source() == viewport() ) emit itemHasMoved(); }
void SubalbumsIconView::contentsMousePressEvent | ( | QMouseEvent * | e | ) | [protected] |
Definition at line 71 of file subalbumsIconView.cpp.
References dragStartPos.
{ //ignore all clicks other than left-clicks if( e->button() != Qt::LeftButton ) return; dragStartPos = e->pos(); QIconView::contentsMousePressEvent( e ); }
QDragObject * SubalbumsIconView::dragObject | ( | ) | [protected] |
Definition at line 80 of file subalbumsIconView.cpp.
References buffer, and dragStartPos.
{ //no item selected? if( !currentItem() ) return 0; //create drag object QIconDrag *drag = new QIconDrag( viewport() ); //create buffer and paint item to buffer QRect r = currentItem()->rect(); QPixmap buffer( r.width(), r.height() ); QPainter painter( &buffer, this ); painter.translate( -r.x(), -r.y() ); ((SubalbumPreviewWidget*)currentItem())->paint( &painter ); //clip off background color around edges which was used for anti-aliasing edges. //result image will have semi-selection oval around it. QBitmap bit = buffer.createHeuristicMask(); buffer.setMask( bit ); //set pixmap to use buffer drag->setPixmap( buffer, QPoint( dragStartPos.x() - r.x(), dragStartPos.y() - r.y() ) ); //we don't want to show any rectangles, but if we don't append two null rectangles the last drag rectangles this iconview displayed //possibly form objects dropped onto it from outside the viewport, aka photos, will be drawn! :( drag->append( QIconDragItem(), QRect(), QRect() ); return drag; }
void SubalbumsIconView::drawContents | ( | QPainter * | p, |
int | clipx, | ||
int | clipy, | ||
int | clipw, | ||
int | cliph | ||
) | [protected] |
Definition at line 58 of file subalbumsIconView.cpp.
References bufferPixmap.
{ if( bufferPixmap.size() != size()) { bufferPixmap.resize( size() ); } QPainter bufferPainter( &bufferPixmap, viewport() ); int xOffset = clipx - contentsX(); int yOffset = clipy - contentsY(); bufferPainter.translate( -contentsX(), -contentsY() ); QIconView::drawContents( &bufferPainter, clipx, clipy, clipw, cliph ); bitBlt(p->device(), xOffset, yOffset, &bufferPixmap, xOffset, yOffset, clipw, cliph ); }
int SubalbumsIconView::getTextWidth | ( | ) |
Definition at line 178 of file subalbumsIconView.cpp.
References textWidth.
Referenced by SubalbumPreviewWidget::initializeItemRect(), and SubalbumPreviewWidget::setText().
{ return textWidth; }
void SubalbumsIconView::itemHasMoved | ( | ) | [signal] |
Referenced by contentsDropEvent().
QSize SubalbumsIconView::minimumSizeHint | ( | ) | const |
void SubalbumsIconView::repaintGroup | ( | QIconViewItem * | pseudoSelection | ) | [private, slot] |
Definition at line 156 of file subalbumsIconView.cpp.
References clearPseudoSelection(), currentPseudoSelection, and SubalbumPreviewWidget::setMousedOver().
Referenced by SubalbumsIconView().
{ //if old pseudo selection unselect it clearPseudoSelection(); //paint new selection currentPseudoSelection = (SubalbumPreviewWidget*)pseudoSelection; currentPseudoSelection->setMousedOver(true); repaintItem(currentPseudoSelection); }
QSize SubalbumsIconView::sizeHint | ( | ) | const |
Definition at line 183 of file subalbumsIconView.cpp.
Referenced by minimumSizeHint().
{ QSize s = QIconView::sizeHint(); //find max item width s.setWidth(0); QIconViewItem *item; for( item = firstItem(); item != NULL; item = item->nextItem() ) { if(item->width() > s.width() ) s.setWidth( item->width() ); } s.setWidth( s.width() + 2*spacing() + verticalScrollBar()->sizeHint().width() ); return s; }
QPixmap SubalbumsIconView::bufferPixmap [private] |
Definition at line 59 of file subalbumsIconView.h.
Referenced by drawContents().
Definition at line 61 of file subalbumsIconView.h.
Referenced by clearPseudoSelection(), contentsDragMoveEvent(), repaintGroup(), and SubalbumsIconView().
QPoint SubalbumsIconView::dragStartPos [private] |
Definition at line 60 of file subalbumsIconView.h.
Referenced by contentsMousePressEvent(), and dragObject().
int SubalbumsIconView::textWidth [private] |
Definition at line 65 of file subalbumsIconView.h.
Referenced by getTextWidth(), and SubalbumsIconView().