AlbumShaper  1.0a3
subalbumsIconView.cpp
Go to the documentation of this file.
1 //==============================================
2 // copyright : (C) 2003-2005 by Will Stokes
3 //==============================================
4 // This program is free software; you can redistribute it
5 // and/or modify it under the terms of the GNU General
6 // Public License as published by the Free Software
7 // Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //==============================================
10 
11 //Systemwide includes
12 #include <qpixmap.h>
13 #include <qimage.h>
14 #include <qpainter.h>
15 #include <qcursor.h>
16 #include <qapplication.h>
17 //Added by qt3to4:
18 #include <QDropEvent>
19 #include <QMouseEvent>
20 #include <QDragMoveEvent>
21 
22 //#include <qscrollbar.h>
23 
24 //Projectwide includes
25 #include "subalbumsIconView.h"
26 #include "subalbumPreviewWidget.h"
27 #include "layoutWidget.h"
28 #include "subalbumWidget.h"
29 #include "photoPreviewWidget.h"
30 
31 //==============================================
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 }
52 //==============================================
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 }
61 //==============================================
62  void SubalbumsIconView::drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph )
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 }
74 //==============================================
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 }
83 //==============================================
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 }
114 //==============================================
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 }
159 //==============================================
161 {
162  //if old pseudo selection unselect it
164 
165  //paint new selection
166  currentPseudoSelection = (SubalbumPreviewWidget*)pseudoSelection;
168  repaintItem(currentPseudoSelection);
169 }
170 //==============================================
172 {
173  //if old pseudo selection unselect it
174  if(currentPseudoSelection != NULL)
175  {
177  repaintItem(currentPseudoSelection);
178  currentPseudoSelection = NULL;
179  }
180 }
181 //==============================================
183 { return textWidth; }
184 //==============================================
185 QSize SubalbumsIconView::minimumSizeHint() const { return sizeHint(); }
186 //==============================================
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 }
202 //==============================================
203 
204 
SubalbumsIconView(QWidget *parent)
void contentsDropEvent(QDropEvent *e)
Q3DragObject * dragObject()
Displays list of subalbums and a particular subalbum layout.
Definition: layoutWidget.h:39
void contentsDragMoveEvent(QDragMoveEvent *e)
Displays subalbum icon and name.
void contentsMousePressEvent(QMouseEvent *e)
float * buffer
Definition: blur.cpp:80
void repaintGroup(Q3IconViewItem *pseudoSelection)
void drawContents(QPainter *p, int clipx, int clipy, int clipw, int cliph)
SubalbumPreviewWidget * currentPseudoSelection
QSize minimumSizeHint() const