AlbumShaper 1.0a3
panningPreviewInterface.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//Projectwide includes
13//Added by qt3to4:
14#include <QResizeEvent>
15
16//==============================================
18 QWidget *parent, const char* name ) :
19 SplitViewInterface (parent, name )
20{
21 //load full size image
22 fullSizeImage = QImage( imageFilename );
23
24 //a 0-width selection is invalid and prevents
25 //resize events from triggering painting
26 //until the true selection region is set
27 selection.setWidth( 0 );
28}
29//==============================================
31{
32 //subjetively chosen default size :)
33 return QSize( 500, 400 );
34}
35//==============================================
37{
38 return QSize( QMIN( fullSizeImage.width(), size().width() ),
39 QMIN( fullSizeImage.height(), size().height() ) );
40}
41//==============================================
43{
44 //center of new selection...
45 QPoint center;
46
47 //if selection not set then default to center of image
48 if( selection.width() == 0)
49 {
50 //compute center selection center
51 center = QPoint( fullSizeImage.width() / 2,
52 fullSizeImage.height() / 2 );
53 }
54 //else construct new selection that is centered over old selection
55 else
56 {
57 //compute center selection center
58 center = QPoint( selection.left() + selection.width()/2,
59 selection.top() + selection.height()/2 );
60 }
61
62 //determine width/height that will be used for painting
63 QSize actualSize = paintingSize();
64
65 //compute new selection area centerd over old selection region
66 QRect newSelection;
67 newSelection.setLeft( center.x() - actualSize.width() /2 );
68 newSelection.setTop ( center.y() - actualSize.height()/2 );
69 newSelection.setRight( newSelection.left() + actualSize.width() - 1 );
70 newSelection.setBottom( newSelection.top() + actualSize.height() - 1 );
71
72 //set selection which will result in regenerating of orig and adjusted images
73 setSelection( newSelection );
74}
75//==============================================
77{
78 //set the selection
79 selection = s;
80
81 //get the available painting size
82 QSize actualSize = paintingSize();
83
84 //if too wide or tall shrink selection
85 if( selection.width() > actualSize.width() )
86 selection.setRight( selection.left() + actualSize.width() - 1 );
87 if( selection.height() > actualSize.height() )
88 selection.setBottom( selection.top() + actualSize.height() - 1 );
89
90 //shift selection area if it extends beyond image boundary
91 if( selection.left() < 0 )
92 selection.moveBy( -selection.left(), 0 );
93
94 if( selection.top() < 0 )
95 selection.moveBy( 0, -selection.top() );
96
97 if( selection.right() > fullSizeImage.width()-1 )
98 selection.moveBy( (fullSizeImage.width()-1) - selection.right(), 0 );
99
100 if( selection.bottom() > fullSizeImage.height()-1 )
101 selection.moveBy( 0, (fullSizeImage.height()-1) - selection.bottom() );
102
103 //regenerate orig and adjusted images
105}
106//==============================================
108{
109 //generate orig image
110 //set adjusted image to null so repain won't occur until it is reset
111 setImages( fullSizeImage.copy( selection.left(), selection.top(),
112 selection.width(), selection.height() ),
113 QImage() );
114
115 //emit signal indicating adjusted image is out of date
116 emit selectionChanged();
117}
118//==============================================
121//==============================================
122
int width
Definition blur.cpp:79
int height
Definition blur.cpp:79
QRect selection
Current selection.
PanningPreviewInterface(QString imageFilename, QWidget *parent=0, const char *name=0)
Creates layout.
void setSelection(QRect selection)
QImage fullSizeImage
Full size image.
A split view interface provides a means to show before and after versions of an image while adjustmen...
void setImages(QImage origImage, QImage adjustedImage)