Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

panningPreviewInterface.cpp

Go to the documentation of this file.
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 //Projectwide includes 00012 #include "panningPreviewInterface.h" 00013 00014 //============================================== 00015 PanningPreviewInterface::PanningPreviewInterface( QString imageFilename, 00016 QWidget *parent, const char* name ) : 00017 SplitViewInterface (parent, name ) 00018 { 00019 //load full size image 00020 fullSizeImage = QImage( imageFilename ); 00021 00022 //a 0-width selection is invalid and prevents 00023 //resize events from triggering painting 00024 //until the true selection region is set 00025 selection.setWidth( 0 ); 00026 } 00027 //============================================== 00028 QSize PanningPreviewInterface::sizeHint() const 00029 { 00030 //subjetively chosen default size :) 00031 return QSize( 500, 400 ); 00032 } 00033 //============================================== 00034 QSize PanningPreviewInterface::paintingSize() 00035 { 00036 return QSize( QMIN( fullSizeImage.width(), size().width() ), 00037 QMIN( fullSizeImage.height(), size().height() ) ); 00038 } 00039 //============================================== 00040 void PanningPreviewInterface::resizeEvent( QResizeEvent * ) 00041 { 00042 //center of new selection... 00043 QPoint center; 00044 00045 //if selection not set then default to center of image 00046 if( selection.width() == 0) 00047 { 00048 //compute center selection center 00049 center = QPoint( fullSizeImage.width() / 2, 00050 fullSizeImage.height() / 2 ); 00051 } 00052 //else construct new selection that is centered over old selection 00053 else 00054 { 00055 //compute center selection center 00056 center = QPoint( selection.left() + selection.width()/2, 00057 selection.top() + selection.height()/2 ); 00058 } 00059 00060 //determine width/height that will be used for painting 00061 QSize actualSize = paintingSize(); 00062 00063 //compute new selection area centerd over old selection region 00064 QRect newSelection; 00065 newSelection.setLeft( center.x() - actualSize.width() /2 ); 00066 newSelection.setTop ( center.y() - actualSize.height()/2 ); 00067 newSelection.setRight( newSelection.left() + actualSize.width() - 1 ); 00068 newSelection.setBottom( newSelection.top() + actualSize.height() - 1 ); 00069 00070 //set selection which will result in regenerating of orig and adjusted images 00071 setSelection( newSelection ); 00072 } 00073 //============================================== 00074 void PanningPreviewInterface::setSelection( QRect s ) 00075 { 00076 //set the selection 00077 selection = s; 00078 00079 //get the available painting size 00080 QSize actualSize = paintingSize(); 00081 00082 //if too wide or tall shrink selection 00083 if( selection.width() > actualSize.width() ) 00084 selection.setRight( selection.left() + actualSize.width() - 1 ); 00085 if( selection.height() > actualSize.height() ) 00086 selection.setBottom( selection.top() + actualSize.height() - 1 ); 00087 00088 //shift selection area if it extends beyond image boundary 00089 if( selection.left() < 0 ) 00090 selection.moveBy( -selection.left(), 0 ); 00091 00092 if( selection.top() < 0 ) 00093 selection.moveBy( 0, -selection.top() ); 00094 00095 if( selection.right() > fullSizeImage.width()-1 ) 00096 selection.moveBy( (fullSizeImage.width()-1) - selection.right(), 0 ); 00097 00098 if( selection.bottom() > fullSizeImage.height()-1 ) 00099 selection.moveBy( 0, (fullSizeImage.height()-1) - selection.bottom() ); 00100 00101 //regenerate orig and adjusted images 00102 generateOrigImage(); 00103 } 00104 //============================================== 00105 void PanningPreviewInterface::generateOrigImage() 00106 { 00107 //generate orig image 00108 //set adjusted image to null so repain won't occur until it is reset 00109 setImages( fullSizeImage.copy( selection.left(), selection.top(), 00110 selection.width(), selection.height() ), 00111 QImage() ); 00112 00113 //emit signal indicating adjusted image is out of date 00114 emit selectionChanged(); 00115 } 00116 //============================================== 00117 QRect PanningPreviewInterface::getSelection() 00118 { return selection; } 00119 //============================================== 00120

Generated on Sun Mar 4 19:42:56 2007 for AlbumShaper by doxygen 1.3.7