AlbumShaper
1.0a3
|
00001 //============================================== 00002 // copyright : (C) 2003-2005 by Will Stokes 00003 //============================================== 00004 // This program is free software; you can redistribute it 00005 // and/or modify it under the terms of the GNU General 00006 // Public License as published by the Free Software 00007 // Foundation; either version 2 of the License, or 00008 // (at your option) any later version. 00009 //============================================== 00010 00011 //Systemwide includes 00012 #include <qpixmap.h> 00013 #include <qimage.h> 00014 #include <qpainter.h> 00015 #include <qcursor.h> 00016 #include <qapplication.h> 00017 00018 //#include <qscrollbar.h> 00019 00020 //Projectwide includes 00021 #include "subalbumsIconView.h" 00022 #include "subalbumPreviewWidget.h" 00023 #include "layoutWidget.h" 00024 #include "subalbumWidget.h" 00025 #include "photoPreviewWidget.h" 00026 00027 //============================================== 00028 SubalbumsIconView::SubalbumsIconView( QWidget *parent ) : QIconView( parent ) 00029 { 00030 // setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum); 00031 setMouseTracking(true); 00032 00033 currentPseudoSelection = NULL; 00034 00035 //connect mouse over events to paint pseudo selection in ligher blue 00036 connect( this, SIGNAL(onItem(QIconViewItem*)), 00037 this, SLOT(repaintGroup(QIconViewItem*)) ); 00038 00039 //clear any pseudo selection when mouse moves off icons 00040 connect( this, SIGNAL(onViewport()), 00041 this, SLOT(clearPseudoSelection()) ); 00042 00043 //compute textWidth for collection names using a calibration string 00044 QString calibrationString( qApp->translate("SubalbumPreviewWidget", "Calibration String") ); 00045 QFontMetrics fm( qApp->font() ); 00046 textWidth = fm.width( calibrationString ); 00047 } 00048 //============================================== 00049 void SubalbumsIconView::contentsDropEvent( QDropEvent *e ) 00050 { 00051 QIconView::contentsDropEvent( e ); 00052 00053 //if drop originated from this viewport then emit item moved signal 00054 if(e->source() == viewport() ) 00055 emit itemHasMoved(); 00056 } 00057 //============================================== 00058 void SubalbumsIconView::drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ) 00059 { 00060 if( bufferPixmap.size() != size()) 00061 { bufferPixmap.resize( size() ); } 00062 QPainter bufferPainter( &bufferPixmap, viewport() ); 00063 int xOffset = clipx - contentsX(); 00064 int yOffset = clipy - contentsY(); 00065 00066 bufferPainter.translate( -contentsX(), -contentsY() ); 00067 QIconView::drawContents( &bufferPainter, clipx, clipy, clipw, cliph ); 00068 bitBlt(p->device(), xOffset, yOffset, &bufferPixmap, xOffset, yOffset, clipw, cliph ); 00069 } 00070 //============================================== 00071 void SubalbumsIconView::contentsMousePressEvent ( QMouseEvent * e ) 00072 { 00073 //ignore all clicks other than left-clicks 00074 if( e->button() != Qt::LeftButton ) return; 00075 00076 dragStartPos = e->pos(); 00077 QIconView::contentsMousePressEvent( e ); 00078 } 00079 //============================================== 00080 QDragObject* SubalbumsIconView::dragObject() 00081 { 00082 //no item selected? 00083 if( !currentItem() ) 00084 return 0; 00085 00086 //create drag object 00087 QIconDrag *drag = new QIconDrag( viewport() ); 00088 00089 //create buffer and paint item to buffer 00090 QRect r = currentItem()->rect(); 00091 QPixmap buffer( r.width(), r.height() ); 00092 QPainter painter( &buffer, this ); 00093 painter.translate( -r.x(), -r.y() ); 00094 ((SubalbumPreviewWidget*)currentItem())->paint( &painter ); 00095 00096 //clip off background color around edges which was used for anti-aliasing edges. 00097 //result image will have semi-selection oval around it. 00098 QBitmap bit = buffer.createHeuristicMask(); 00099 buffer.setMask( bit ); 00100 00101 //set pixmap to use buffer 00102 drag->setPixmap( buffer, QPoint( dragStartPos.x() - r.x(), dragStartPos.y() - r.y() ) ); 00103 00104 //we don't want to show any rectangles, but if we don't append two null rectangles the last drag rectangles this iconview displayed 00105 //possibly form objects dropped onto it from outside the viewport, aka photos, will be drawn! :( 00106 drag->append( QIconDragItem(), QRect(), QRect() ); 00107 00108 return drag; 00109 } 00110 //============================================== 00111 void SubalbumsIconView::contentsDragMoveEvent( QDragMoveEvent* e ) 00112 { 00113 QIconView::contentsDragMoveEvent( e ); 00114 e->accept(true); 00115 00116 //if source of drag is not from application then return 00117 if(e->source() == NULL) 00118 return; 00119 00120 //if source of drag is from within this view then return, in the future we'll put 00121 //drag code in here to drag indicators for rearranging the items of the iconview 00122 if(e->source() == viewport() ) 00123 { 00124 00125 } 00126 //else if source is from photos iconview 00127 else if(e->source()->parentWidget() == ((LayoutWidget*)parentWidget()->parentWidget())->getSubalbum()->getPhotos() ) 00128 { 00129 SubalbumPreviewWidget* item = (SubalbumPreviewWidget*)findItem( e->pos() ); 00130 00131 //if item pointer same as current pseudo selection ignore 00132 if(item == currentPseudoSelection) 00133 { 00134 return; 00135 } 00136 00137 //unpaint old selection 00138 if(currentPseudoSelection != NULL) 00139 { 00140 currentPseudoSelection->setMousedOver(false); 00141 repaintItem(currentPseudoSelection); 00142 } 00143 00144 //set new selection 00145 currentPseudoSelection = item; 00146 00147 //repaint new selection 00148 if(currentPseudoSelection != NULL) 00149 { 00150 currentPseudoSelection->setMousedOver(true); 00151 repaintItem(currentPseudoSelection); 00152 } 00153 } 00154 } 00155 //============================================== 00156 void SubalbumsIconView::repaintGroup( QIconViewItem* pseudoSelection) 00157 { 00158 //if old pseudo selection unselect it 00159 clearPseudoSelection(); 00160 00161 //paint new selection 00162 currentPseudoSelection = (SubalbumPreviewWidget*)pseudoSelection; 00163 currentPseudoSelection->setMousedOver(true); 00164 repaintItem(currentPseudoSelection); 00165 } 00166 //============================================== 00167 void SubalbumsIconView::clearPseudoSelection() 00168 { 00169 //if old pseudo selection unselect it 00170 if(currentPseudoSelection != NULL) 00171 { 00172 currentPseudoSelection->setMousedOver(false); 00173 repaintItem(currentPseudoSelection); 00174 currentPseudoSelection = NULL; 00175 } 00176 } 00177 //============================================== 00178 int SubalbumsIconView::getTextWidth() 00179 { return textWidth; } 00180 //============================================== 00181 QSize SubalbumsIconView::minimumSizeHint() const { return sizeHint(); } 00182 //============================================== 00183 QSize SubalbumsIconView::sizeHint() const 00184 { 00185 QSize s = QIconView::sizeHint(); 00186 00187 //find max item width 00188 s.setWidth(0); 00189 QIconViewItem *item; 00190 for( item = firstItem(); item != NULL; item = item->nextItem() ) 00191 { 00192 if(item->width() > s.width() ) 00193 s.setWidth( item->width() ); 00194 } 00195 s.setWidth( s.width() + 2*spacing() + verticalScrollBar()->sizeHint().width() ); 00196 return s; 00197 } 00198 //============================================== 00199 00200