AlbumShaper  1.0a3
Signals | Public Member Functions | Protected Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
SubalbumsIconView Class Reference

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>

Inheritance diagram for SubalbumsIconView:
Inheritance graph
[legend]
Collaboration diagram for SubalbumsIconView:
Collaboration graph
[legend]

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)
 
Q3DragObject * dragObject ()
 
void contentsMousePressEvent (QMouseEvent *e)
 
void contentsDragMoveEvent (QDragMoveEvent *e)
 

Private Slots

void repaintGroup (Q3IconViewItem *pseudoSelection)
 
void clearPseudoSelection ()
 

Private Member Functions

void contentsDropEvent (QDropEvent *e)
 

Private Attributes

QPixmap bufferPixmap
 
QPoint dragStartPos
 
SubalbumPreviewWidgetcurrentPseudoSelection
 
int textWidth
 

Detailed Description

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 36 of file subalbumsIconView.h.

Constructor & Destructor Documentation

§ SubalbumsIconView()

SubalbumsIconView::SubalbumsIconView ( QWidget parent)

Definition at line 32 of file subalbumsIconView.cpp.

References clearPseudoSelection(), currentPseudoSelection, repaintGroup(), and textWidth.

32  : Q3IconView( parent )
33 {
34 // setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum);
35  setMouseTracking(true);
36 
38 
39  //connect mouse over events to paint pseudo selection in ligher blue
40  connect( this, SIGNAL(onItem(Q3IconViewItem*)),
41  this, SLOT(repaintGroup(Q3IconViewItem*)) );
42 
43  //clear any pseudo selection when mouse moves off icons
44  connect( this, SIGNAL(onViewport()),
45  this, SLOT(clearPseudoSelection()) );
46 
47  //compute textWidth for collection names using a calibration string
48  QString calibrationString( qApp->translate("SubalbumPreviewWidget", "Calibration String") );
49  QFontMetrics fm( qApp->font() );
50  textWidth = fm.width( calibrationString );
51 }
void repaintGroup(Q3IconViewItem *pseudoSelection)
SubalbumPreviewWidget * currentPseudoSelection

Member Function Documentation

§ clearPseudoSelection

void SubalbumsIconView::clearPseudoSelection ( )
privateslot

Definition at line 171 of file subalbumsIconView.cpp.

References currentPseudoSelection, and SubalbumPreviewWidget::setMousedOver().

Referenced by repaintGroup(), and SubalbumsIconView().

172 {
173  //if old pseudo selection unselect it
174  if(currentPseudoSelection != NULL)
175  {
177  repaintItem(currentPseudoSelection);
178  currentPseudoSelection = NULL;
179  }
180 }
SubalbumPreviewWidget * currentPseudoSelection

§ contentsDragMoveEvent()

void SubalbumsIconView::contentsDragMoveEvent ( QDragMoveEvent *  e)
protected

Definition at line 115 of file subalbumsIconView.cpp.

References currentPseudoSelection, and SubalbumPreviewWidget::setMousedOver().

116 {
117  Q3IconView::contentsDragMoveEvent( e );
118  e->accept(true);
119 
120  //if source of drag is not from application then return
121  if(e->source() == NULL)
122  return;
123 
124  //if source of drag is from within this view then return, in the future we'll put
125  //drag code in here to drag indicators for rearranging the items of the iconview
126  if(e->source() == viewport() )
127  {
128 
129  }
130  //else if source is from photos iconview
131  else if(e->source()->parentWidget() == ((LayoutWidget*)parentWidget()->parentWidget())->getSubalbum()->getPhotos() )
132  {
133  SubalbumPreviewWidget* item = (SubalbumPreviewWidget*)findItem( e->pos() );
134 
135  //if item pointer same as current pseudo selection ignore
136  if(item == currentPseudoSelection)
137  {
138  return;
139  }
140 
141  //unpaint old selection
142  if(currentPseudoSelection != NULL)
143  {
145  repaintItem(currentPseudoSelection);
146  }
147 
148  //set new selection
149  currentPseudoSelection = item;
150 
151  //repaint new selection
152  if(currentPseudoSelection != NULL)
153  {
155  repaintItem(currentPseudoSelection);
156  }
157  }
158 }
Displays list of subalbums and a particular subalbum layout.
Definition: layoutWidget.h:39
Displays subalbum icon and name.
SubalbumPreviewWidget * currentPseudoSelection

§ contentsDropEvent()

void SubalbumsIconView::contentsDropEvent ( QDropEvent *  e)
private

Definition at line 53 of file subalbumsIconView.cpp.

References itemHasMoved().

54 {
55  Q3IconView::contentsDropEvent( e );
56 
57  //if drop originated from this viewport then emit item moved signal
58  if(e->source() == viewport() )
59  emit itemHasMoved();
60 }

§ contentsMousePressEvent()

void SubalbumsIconView::contentsMousePressEvent ( QMouseEvent *  e)
protected

Definition at line 75 of file subalbumsIconView.cpp.

References dragStartPos.

76 {
77  //ignore all clicks other than left-clicks
78  if( e->button() != Qt::LeftButton ) return;
79 
80  dragStartPos = e->pos();
81  Q3IconView::contentsMousePressEvent( e );
82 }

§ dragObject()

Q3DragObject * SubalbumsIconView::dragObject ( )
protected

Definition at line 84 of file subalbumsIconView.cpp.

References buffer, and dragStartPos.

85 {
86  //no item selected?
87  if( !currentItem() )
88  return 0;
89 
90  //create drag object
91  Q3IconDrag *drag = new Q3IconDrag( viewport() );
92 
93  //create buffer and paint item to buffer
94  QRect r = currentItem()->rect();
95  QPixmap buffer( r.width(), r.height() );
96  QPainter painter( &buffer );
97  painter.translate( -r.x(), -r.y() );
98  ((SubalbumPreviewWidget*)currentItem())->paint( &painter );
99 
100  //clip off background color around edges which was used for anti-aliasing edges.
101  //result image will have semi-selection oval around it.
102  QBitmap bit = buffer.createHeuristicMask();
103  buffer.setMask( bit );
104 
105  //set pixmap to use buffer
106  drag->setPixmap( buffer, QPoint( dragStartPos.x() - r.x(), dragStartPos.y() - r.y() ) );
107 
108  //we don't want to show any rectangles, but if we don't append two null rectangles the last drag rectangles this iconview displayed
109  //possibly form objects dropped onto it from outside the viewport, aka photos, will be drawn! :(
110  drag->append( Q3IconDragItem(), QRect(), QRect() );
111 
112  return drag;
113 }
Displays subalbum icon and name.
float * buffer
Definition: blur.cpp:80

§ drawContents()

void SubalbumsIconView::drawContents ( QPainter *  p,
int  clipx,
int  clipy,
int  clipw,
int  cliph 
)
protected

Definition at line 62 of file subalbumsIconView.cpp.

References bufferPixmap.

63 {
64  if( bufferPixmap.size() != size())
65  { bufferPixmap.resize( size() ); }
66  QPainter bufferPainter( &bufferPixmap );
67  int xOffset = clipx - contentsX();
68  int yOffset = clipy - contentsY();
69 
70  bufferPainter.translate( -contentsX(), -contentsY() );
71  Q3IconView::drawContents( &bufferPainter, clipx, clipy, clipw, cliph );
72  bitBlt(p->device(), xOffset, yOffset, &bufferPixmap, xOffset, yOffset, clipw, cliph );
73 }

§ getTextWidth()

int SubalbumsIconView::getTextWidth ( )

§ itemHasMoved

void SubalbumsIconView::itemHasMoved ( )
signal

Referenced by contentsDropEvent().

§ minimumSizeHint()

QSize SubalbumsIconView::minimumSizeHint ( ) const

Definition at line 185 of file subalbumsIconView.cpp.

References sizeHint().

185 { return sizeHint(); }

§ repaintGroup

void SubalbumsIconView::repaintGroup ( Q3IconViewItem pseudoSelection)
privateslot

Definition at line 160 of file subalbumsIconView.cpp.

References clearPseudoSelection(), currentPseudoSelection, and SubalbumPreviewWidget::setMousedOver().

Referenced by SubalbumsIconView().

161 {
162  //if old pseudo selection unselect it
164 
165  //paint new selection
166  currentPseudoSelection = (SubalbumPreviewWidget*)pseudoSelection;
168  repaintItem(currentPseudoSelection);
169 }
Displays subalbum icon and name.
SubalbumPreviewWidget * currentPseudoSelection

§ sizeHint()

QSize SubalbumsIconView::sizeHint ( ) const

Definition at line 187 of file subalbumsIconView.cpp.

Referenced by minimumSizeHint().

188 {
189  QSize s = Q3IconView::sizeHint();
190 
191  //find max item width
192  s.setWidth(0);
193  Q3IconViewItem *item;
194  for( item = firstItem(); item != NULL; item = item->nextItem() )
195  {
196  if(item->width() > s.width() )
197  s.setWidth( item->width() );
198  }
199  s.setWidth( s.width() + 2*spacing() + verticalScrollBar()->sizeHint().width() );
200  return s;
201 }

Member Data Documentation

§ bufferPixmap

QPixmap SubalbumsIconView::bufferPixmap
private

Definition at line 64 of file subalbumsIconView.h.

Referenced by drawContents().

§ currentPseudoSelection

SubalbumPreviewWidget* SubalbumsIconView::currentPseudoSelection
private

§ dragStartPos

QPoint SubalbumsIconView::dragStartPos
private

Definition at line 65 of file subalbumsIconView.h.

Referenced by contentsMousePressEvent(), and dragObject().

§ textWidth

int SubalbumsIconView::textWidth
private

Definition at line 70 of file subalbumsIconView.h.

Referenced by getTextWidth(), and SubalbumsIconView().


The documentation for this class was generated from the following files: