00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include "panningPreviewInterface.h"
00013
00014
00015 PanningPreviewInterface::PanningPreviewInterface( QString imageFilename,
00016
QWidget *parent,
const char* name ) :
00017
SplitViewInterface (parent, name )
00018 {
00019
00020
fullSizeImage = QImage( imageFilename );
00021
00022
00023
00024
00025
selection.setWidth( 0 );
00026 }
00027
00028 QSize
PanningPreviewInterface::sizeHint()
const
00029
{
00030
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
00043 QPoint center;
00044
00045
00046
if(
selection.width() == 0)
00047 {
00048
00049 center = QPoint(
fullSizeImage.width() / 2,
00050
fullSizeImage.height() / 2 );
00051 }
00052
00053
else
00054 {
00055
00056 center = QPoint(
selection.left() +
selection.width()/2,
00057
selection.top() +
selection.height()/2 );
00058 }
00059
00060
00061 QSize actualSize =
paintingSize();
00062
00063
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
00071
setSelection( newSelection );
00072 }
00073
00074 void PanningPreviewInterface::setSelection( QRect s )
00075 {
00076
00077
selection = s;
00078
00079
00080 QSize actualSize =
paintingSize();
00081
00082
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
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
00102
generateOrigImage();
00103 }
00104
00105 void PanningPreviewInterface::generateOrigImage()
00106 {
00107
00108
00109 setImages(
fullSizeImage.copy(
selection.left(),
selection.top(),
00110
selection.width(),
selection.height() ),
00111 QImage() );
00112
00113
00114 emit
selectionChanged();
00115 }
00116
00117 QRect
PanningPreviewInterface::getSelection()
00118 {
return selection; }
00119
00120