-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.cpp | 212 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.h | 65 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imageview.cpp | 3 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imageview.h | 3 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/mainwindow.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/mainwindow.h | 3 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/lib/oimagezoomer.cpp | 18 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/lib/oimagezoomer.h | 13 |
8 files changed, 221 insertions, 98 deletions
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp index d034ee0..3bb07a7 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.cpp +++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp | |||
@@ -1,500 +1,586 @@ | |||
1 | #include "imagescrollview.h" | 1 | #include "imagescrollview.h" |
2 | 2 | ||
3 | #include "lib/oimagezoomer.h" | ||
4 | |||
3 | #include <opie2/odebug.h> | 5 | #include <opie2/odebug.h> |
4 | #include <opie2/oapplication.h> | 6 | #include <opie2/oapplication.h> |
5 | #include <opie2/owait.h> | 7 | #include <opie2/owait.h> |
6 | 8 | ||
7 | using namespace Opie::Core; | ||
8 | |||
9 | #include <qimage.h> | 9 | #include <qimage.h> |
10 | #include <qlayout.h> | 10 | #include <qlayout.h> |
11 | #include <qpe/qcopenvelope_qws.h> | 11 | #include <qpe/qcopenvelope_qws.h> |
12 | 12 | ||
13 | ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f ) | 13 | /* for usage with the bitset */ |
14 | :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true), | 14 | #define AUTO_SCALE 0 |
15 | rotate_to_fit(true),show_zoomer(true),first_resize_done(false),m_lastName("") | 15 | #define AUTO_ROTATE 1 |
16 | #define SHOW_ZOOMER 2 | ||
17 | #define FIRST_RESIZE_DONE 3 | ||
18 | #define IMAGE_IS_JPEG 4 | ||
19 | #define IMAGE_SCALED_LOADED 5 | ||
20 | |||
21 | #define SCROLLVIEW_BITSET_SIZE 6 | ||
22 | |||
23 | namespace Opie { | ||
24 | namespace MM { | ||
25 | OImageScrollView::OImageScrollView( QWidget* parent, const char* name, WFlags f ) | ||
26 | :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(), | ||
27 | m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") | ||
16 | { | 28 | { |
29 | _zoomer = 0; | ||
30 | m_states[AUTO_SCALE]=true; | ||
31 | m_states[AUTO_ROTATE]=true; | ||
32 | m_states[FIRST_RESIZE_DONE]=false; | ||
33 | m_states[IMAGE_IS_JPEG]=false; | ||
34 | m_states[IMAGE_SCALED_LOADED]=false; | ||
35 | m_states[SHOW_ZOOMER]=true; | ||
17 | init(); | 36 | init(); |
18 | } | 37 | } |
19 | 38 | ||
20 | ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 39 | OImageScrollView::OImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) |
21 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), | 40 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img), |
22 | rotate_to_fit(rfit),show_zoomer(true),first_resize_done(false),m_lastName("") | 41 | m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") |
23 | { | 42 | { |
43 | _zoomer = 0; | ||
44 | m_states[AUTO_SCALE]=always_scale; | ||
45 | m_states[AUTO_ROTATE]=rfit; | ||
46 | m_states[FIRST_RESIZE_DONE]=false; | ||
47 | m_states[IMAGE_IS_JPEG]=false; | ||
48 | m_states[IMAGE_SCALED_LOADED]=false; | ||
49 | m_states[SHOW_ZOOMER]=true; | ||
24 | _original_data.convertDepth(QPixmap::defaultDepth()); | 50 | _original_data.convertDepth(QPixmap::defaultDepth()); |
25 | _original_data.setAlphaBuffer(false); | 51 | _original_data.setAlphaBuffer(false); |
26 | init(); | 52 | init(); |
27 | } | 53 | } |
28 | 54 | ||
29 | ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 55 | OImageScrollView::OImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) |
30 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),scale_to_fit(always_scale), | 56 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") |
31 | rotate_to_fit(rfit),show_zoomer(true),first_resize_done(false),m_lastName("") | ||
32 | { | 57 | { |
58 | _zoomer = 0; | ||
59 | m_states.resize(SCROLLVIEW_BITSET_SIZE); | ||
60 | m_states[AUTO_SCALE]=always_scale; | ||
61 | m_states[AUTO_ROTATE]=rfit; | ||
62 | m_states[FIRST_RESIZE_DONE]=false; | ||
63 | m_states[IMAGE_IS_JPEG]=false; | ||
64 | m_states[IMAGE_SCALED_LOADED]=false; | ||
65 | m_states[SHOW_ZOOMER]=true; | ||
33 | init(); | 66 | init(); |
34 | setImage(img); | 67 | setImage(img); |
35 | } | 68 | } |
36 | 69 | ||
37 | void ImageScrollView::setImage(const QImage&img) | 70 | void OImageScrollView::setImage(const QImage&img) |
38 | { | 71 | { |
39 | _image_data = QImage(); | 72 | _image_data = QImage(); |
40 | _original_data=img; | 73 | _original_data=img; |
41 | _original_data.convertDepth(QPixmap::defaultDepth()); | 74 | _original_data.convertDepth(QPixmap::defaultDepth()); |
42 | _original_data.setAlphaBuffer(false); | 75 | _original_data.setAlphaBuffer(false); |
43 | m_lastName = ""; | 76 | m_lastName = ""; |
44 | image_is_jpeg = false; | 77 | setImageIsJpeg(false); |
45 | image_scaled_loaded = false; | 78 | setImageScaledLoaded(false); |
46 | if (first_resize_done) { | 79 | if (FirstResizeDone()) { |
47 | generateImage(); | 80 | generateImage(); |
48 | } | 81 | } |
49 | } | 82 | } |
50 | 83 | ||
51 | void ImageScrollView::loadJpeg(bool interncall) | 84 | void OImageScrollView::loadJpeg(bool interncall) |
52 | { | 85 | { |
53 | if (m_lastName.isEmpty()) return; | 86 | if (m_lastName.isEmpty()) return; |
54 | QImageIO iio( m_lastName, 0l ); | 87 | QImageIO iio( m_lastName, 0l ); |
55 | QString param; | 88 | QString param; |
56 | bool real_load = false; | 89 | bool real_load = false; |
57 | if (scale_to_fit) { | 90 | if (AutoScale()) { |
58 | if (!interncall) { | 91 | if (!interncall) { |
59 | int wid, hei; | 92 | int wid, hei; |
60 | wid = QApplication::desktop()->width(); | 93 | wid = QApplication::desktop()->width(); |
61 | hei = QApplication::desktop()->height(); | 94 | hei = QApplication::desktop()->height(); |
62 | if (hei>wid) { | 95 | if (hei>wid) { |
63 | wid = hei; | 96 | wid = hei; |
64 | } else { | 97 | } else { |
65 | hei = wid; | 98 | hei = wid; |
66 | } | 99 | } |
67 | param = QString( "Fast Shrink( 7 ) Scale( %1, %2, ScaleFree)" ).arg( wid ).arg( hei ); | 100 | param = QString( "Fast Shrink( 7 ) Scale( %1, %2, ScaleFree)" ).arg( wid ).arg( hei ); |
68 | odebug << "Load jpeg scaled \"" << param << "\"" << oendl; | 101 | odebug << "Load jpeg scaled \"" << param << "\"" << oendl; |
69 | iio.setParameters(param.latin1()); | 102 | iio.setParameters(param.latin1()); |
70 | image_scaled_loaded = true; | 103 | setImageScaledLoaded(true); |
71 | real_load = true; | 104 | real_load = true; |
72 | } | 105 | } |
73 | } else { | 106 | } else { |
74 | if (image_scaled_loaded||!interncall) { | 107 | if (ImageScaledLoaded()||!interncall) { |
75 | odebug << "Load jpeg unscaled" << oendl; | 108 | odebug << "Load jpeg unscaled" << oendl; |
76 | real_load = true; | 109 | real_load = true; |
77 | } | 110 | } |
78 | image_scaled_loaded = false; | 111 | setImageScaledLoaded(false); |
79 | } | 112 | } |
80 | if (real_load) { | 113 | if (real_load) { |
81 | { | 114 | { |
82 | QCopEnvelope( "QPE/System", "busy()" ); | 115 | QCopEnvelope( "QPE/System", "busy()" ); |
83 | } | 116 | } |
84 | _original_data = iio.read() ? iio.image() : QImage(); | 117 | _original_data = iio.read() ? iio.image() : QImage(); |
85 | { | 118 | { |
86 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); | 119 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); |
87 | env << "Image loaded"; | 120 | env << "Image loaded"; |
88 | } | 121 | } |
89 | } | 122 | } |
90 | } | 123 | } |
91 | 124 | ||
92 | void ImageScrollView::setImage( const QString& path ) { | 125 | void OImageScrollView::setImage( const QString& path ) { |
93 | odebug << "load new image " << oendl; | 126 | odebug << "load new image " << oendl; |
94 | if (m_lastName == path) return; | 127 | if (m_lastName == path) return; |
95 | m_lastName = path; | 128 | m_lastName = path; |
96 | QString itype = QImage::imageFormat(m_lastName); | 129 | QString itype = QImage::imageFormat(m_lastName); |
97 | odebug << "Image type = " << itype << oendl; | 130 | odebug << "Image type = " << itype << oendl; |
98 | if (itype == "JPEG") { | 131 | if (itype == "JPEG") { |
99 | image_is_jpeg = true; | 132 | setImageIsJpeg(true); |
100 | loadJpeg(); | 133 | loadJpeg(); |
101 | } else { | 134 | } else { |
102 | { | 135 | { |
103 | QCopEnvelope( "QPE/System", "busy()" ); | 136 | QCopEnvelope( "QPE/System", "busy()" ); |
104 | } | 137 | } |
105 | image_is_jpeg = false; | 138 | setImageIsJpeg(false); |
106 | _original_data.load(path); | 139 | _original_data.load(path); |
107 | _original_data.convertDepth(QPixmap::defaultDepth()); | 140 | _original_data.convertDepth(QPixmap::defaultDepth()); |
108 | _original_data.setAlphaBuffer(false); | 141 | _original_data.setAlphaBuffer(false); |
109 | { | 142 | { |
110 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); | 143 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); |
111 | env << "Image loaded"; | 144 | env << "Image loaded"; |
112 | } | 145 | } |
113 | } | 146 | } |
114 | _image_data = QImage(); | 147 | _image_data = QImage(); |
115 | if (first_resize_done) { | 148 | if (FirstResizeDone()) { |
116 | generateImage(); | 149 | generateImage(); |
117 | } | 150 | } |
118 | } | 151 | } |
119 | 152 | ||
120 | /* should be called every time the QImage changed it content */ | 153 | /* should be called every time the QImage changed it content */ |
121 | void ImageScrollView::init() | 154 | void OImageScrollView::init() |
122 | { | 155 | { |
123 | odebug << "init " << oendl; | 156 | odebug << "init " << oendl; |
124 | 157 | ||
125 | /* | 158 | /* |
126 | * create the zoomer | 159 | * create the zoomer |
127 | * and connect ther various signals | 160 | * and connect ther various signals |
128 | */ | 161 | */ |
129 | _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" ); | 162 | _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" ); |
130 | connect(_zoomer, SIGNAL( zoomAreaRel(int,int)), | 163 | connect(_zoomer, SIGNAL( zoomAreaRel(int,int)), |
131 | this, SLOT(scrollBy(int,int)) ); | 164 | this, SLOT(scrollBy(int,int)) ); |
165 | connect(_zoomer, SIGNAL( zoomArea(int,int)), | ||
166 | this, SLOT(center(int,int)) ); | ||
132 | connect(this,SIGNAL(contentsMoving(int,int)), | 167 | connect(this,SIGNAL(contentsMoving(int,int)), |
133 | _zoomer, (SLOT(setVisiblePoint(int,int))) ); | 168 | _zoomer, (SLOT(setVisiblePoint(int,int))) ); |
134 | connect(this,SIGNAL(imageSizeChanged(const QSize&)), | 169 | connect(this,SIGNAL(imageSizeChanged(const QSize&)), |
135 | _zoomer, SLOT(setImageSize(const QSize&)) ); | 170 | _zoomer, SLOT(setImageSize(const QSize&)) ); |
136 | connect(this,SIGNAL(viewportSizeChanged(const QSize&)), | 171 | connect(this,SIGNAL(viewportSizeChanged(const QSize&)), |
137 | _zoomer, SLOT(setViewPortSize(const QSize&)) ); | 172 | _zoomer, SLOT(setViewPortSize(const QSize&)) ); |
138 | 173 | ||
139 | viewport()->setBackgroundColor(white); | 174 | viewport()->setBackgroundColor(white); |
140 | setFocusPolicy(QWidget::StrongFocus); | 175 | setFocusPolicy(QWidget::StrongFocus); |
141 | image_scaled_loaded = false; | 176 | setImageScaledLoaded(false); |
142 | image_is_jpeg = false; | 177 | setImageIsJpeg(false); |
143 | if (first_resize_done) { | 178 | if (FirstResizeDone()) { |
144 | last_rot = Rotate0; | 179 | m_last_rot = Rotate0; |
145 | generateImage(); | 180 | generateImage(); |
146 | } else if (_original_data.size().isValid()) { | 181 | } else if (_original_data.size().isValid()) { |
147 | if (image_fit_into(_original_data.size()) || !show_zoomer) _zoomer->hide(); | 182 | if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide(); |
148 | resizeContents(_original_data.width(),_original_data.height()); | 183 | resizeContents(_original_data.width(),_original_data.height()); |
149 | } | 184 | } |
150 | } | 185 | } |
151 | 186 | ||
152 | void ImageScrollView::setAutoRotate(bool how) | 187 | void OImageScrollView::setAutoRotate(bool how) |
153 | { | 188 | { |
154 | /* to avoid double repaints */ | 189 | /* to avoid double repaints */ |
155 | if (rotate_to_fit != how) { | 190 | if (AutoRotate() != how) { |
156 | rotate_to_fit = how; | 191 | m_states.setBit(AUTO_ROTATE,how); |
157 | _image_data = QImage(); | 192 | _image_data = QImage(); |
158 | generateImage(); | 193 | generateImage(); |
159 | } | 194 | } |
160 | } | 195 | } |
161 | 196 | ||
162 | void ImageScrollView::setAutoScale(bool how) | 197 | bool OImageScrollView::AutoRotate()const |
198 | { | ||
199 | return m_states.testBit(AUTO_ROTATE); | ||
200 | } | ||
201 | |||
202 | void OImageScrollView::setAutoScale(bool how) | ||
163 | { | 203 | { |
164 | scale_to_fit = how; | 204 | m_states.setBit(AUTO_SCALE,how); |
165 | if (!how) { | 205 | if (!how) { |
166 | rotate_to_fit = false; | 206 | setAutoRotate(false); |
167 | } | 207 | } |
168 | _image_data = QImage(); | 208 | _image_data = QImage(); |
169 | if (image_is_jpeg && how == false && image_scaled_loaded==true) { | 209 | if (ImageIsJpeg() && how == false && ImageScaledLoaded()==true) { |
170 | loadJpeg(true); | 210 | loadJpeg(true); |
171 | } | 211 | } |
172 | generateImage(); | 212 | generateImage(); |
173 | } | 213 | } |
174 | 214 | ||
175 | ImageScrollView::~ImageScrollView() | 215 | bool OImageScrollView::AutoScale()const |
216 | { | ||
217 | return m_states.testBit(AUTO_SCALE); | ||
218 | } | ||
219 | |||
220 | OImageScrollView::~OImageScrollView() | ||
176 | { | 221 | { |
177 | } | 222 | } |
178 | 223 | ||
179 | void ImageScrollView::rescaleImage(int w, int h) | 224 | void OImageScrollView::rescaleImage(int w, int h) |
180 | { | 225 | { |
181 | if (_image_data.width()==w && _image_data.height()==h) { | 226 | if (_image_data.width()==w && _image_data.height()==h) { |
182 | return; | 227 | return; |
183 | } | 228 | } |
184 | double hs = (double)h / (double)_image_data.height() ; | 229 | double hs = (double)h / (double)_image_data.height() ; |
185 | double ws = (double)w / (double)_image_data.width() ; | 230 | double ws = (double)w / (double)_image_data.width() ; |
186 | double scaleFactor = (hs > ws) ? ws : hs; | 231 | double scaleFactor = (hs > ws) ? ws : hs; |
187 | int smoothW = (int)(scaleFactor * _image_data.width()); | 232 | int smoothW = (int)(scaleFactor * _image_data.width()); |
188 | int smoothH = (int)(scaleFactor * _image_data.height()); | 233 | int smoothH = (int)(scaleFactor * _image_data.height()); |
189 | _image_data = _image_data.smoothScale(smoothW,smoothH); | 234 | _image_data = _image_data.smoothScale(smoothW,smoothH); |
190 | } | 235 | } |
191 | 236 | ||
192 | void ImageScrollView::rotate_into_data(Rotation r) | 237 | void OImageScrollView::rotate_into_data(Rotation r) |
193 | { | 238 | { |
194 | /* realy - we must do this that way, 'cause when acting direct on _image_data the app will | 239 | /* realy - we must do this that way, 'cause when acting direct on _image_data the app will |
195 | segfault :( */ | 240 | segfault :( */ |
196 | QImage dest; | 241 | QImage dest; |
197 | int x, y; | 242 | int x, y; |
198 | if ( _original_data.depth() > 8 ) | 243 | if ( _original_data.depth() > 8 ) |
199 | { | 244 | { |
200 | unsigned int *srcData, *destData; | 245 | unsigned int *srcData, *destData; |
201 | switch ( r ) | 246 | switch ( r ) |
202 | { | 247 | { |
203 | case Rotate90: | 248 | case Rotate90: |
204 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 249 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
205 | for ( y=0; y < _original_data.height(); ++y ) | 250 | for ( y=0; y < _original_data.height(); ++y ) |
206 | { | 251 | { |
207 | srcData = (unsigned int *)_original_data.scanLine(y); | 252 | srcData = (unsigned int *)_original_data.scanLine(y); |
208 | for ( x=0; x < _original_data.width(); ++x ) | 253 | for ( x=0; x < _original_data.width(); ++x ) |
209 | { | 254 | { |
210 | destData = (unsigned int *)dest.scanLine(x); | 255 | destData = (unsigned int *)dest.scanLine(x); |
211 | destData[_original_data.height()-y-1] = srcData[x]; | 256 | destData[_original_data.height()-y-1] = srcData[x]; |
212 | } | 257 | } |
213 | } | 258 | } |
214 | break; | 259 | break; |
215 | case Rotate180: | 260 | case Rotate180: |
216 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); | 261 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); |
217 | for ( y=0; y < _original_data.height(); ++y ) | 262 | for ( y=0; y < _original_data.height(); ++y ) |
218 | { | 263 | { |
219 | srcData = (unsigned int *)_original_data.scanLine(y); | 264 | srcData = (unsigned int *)_original_data.scanLine(y); |
220 | destData = (unsigned int *)dest.scanLine(_original_data.height()-y-1); | 265 | destData = (unsigned int *)dest.scanLine(_original_data.height()-y-1); |
221 | for ( x=0; x < _original_data.width(); ++x ) | 266 | for ( x=0; x < _original_data.width(); ++x ) |
222 | destData[_original_data.width()-x-1] = srcData[x]; | 267 | destData[_original_data.width()-x-1] = srcData[x]; |
223 | } | 268 | } |
224 | break; | 269 | break; |
225 | case Rotate270: | 270 | case Rotate270: |
226 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 271 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
227 | for ( y=0; y < _original_data.height(); ++y ) | 272 | for ( y=0; y < _original_data.height(); ++y ) |
228 | { | 273 | { |
229 | srcData = (unsigned int *)_original_data.scanLine(y); | 274 | srcData = (unsigned int *)_original_data.scanLine(y); |
230 | for ( x=0; x < _original_data.width(); ++x ) | 275 | for ( x=0; x < _original_data.width(); ++x ) |
231 | { | 276 | { |
232 | destData = (unsigned int *)dest.scanLine(_original_data.width()-x-1); | 277 | destData = (unsigned int *)dest.scanLine(_original_data.width()-x-1); |
233 | destData[y] = srcData[x]; | 278 | destData[y] = srcData[x]; |
234 | } | 279 | } |
235 | } | 280 | } |
236 | break; | 281 | break; |
237 | default: | 282 | default: |
238 | dest = _original_data; | 283 | dest = _original_data; |
239 | break; | 284 | break; |
240 | } | 285 | } |
241 | } | 286 | } |
242 | else | 287 | else |
243 | { | 288 | { |
244 | unsigned char *srcData, *destData; | 289 | unsigned char *srcData, *destData; |
245 | unsigned int *srcTable, *destTable; | 290 | unsigned int *srcTable, *destTable; |
246 | switch ( r ) | 291 | switch ( r ) |
247 | { | 292 | { |
248 | case Rotate90: | 293 | case Rotate90: |
249 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 294 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
250 | dest.setNumColors(_original_data.numColors()); | 295 | dest.setNumColors(_original_data.numColors()); |
251 | srcTable = (unsigned int *)_original_data.colorTable(); | 296 | srcTable = (unsigned int *)_original_data.colorTable(); |
252 | destTable = (unsigned int *)dest.colorTable(); | 297 | destTable = (unsigned int *)dest.colorTable(); |
253 | for ( x=0; x < _original_data.numColors(); ++x ) | 298 | for ( x=0; x < _original_data.numColors(); ++x ) |
254 | destTable[x] = srcTable[x]; | 299 | destTable[x] = srcTable[x]; |
255 | for ( y=0; y < _original_data.height(); ++y ) | 300 | for ( y=0; y < _original_data.height(); ++y ) |
256 | { | 301 | { |
257 | srcData = (unsigned char *)_original_data.scanLine(y); | 302 | srcData = (unsigned char *)_original_data.scanLine(y); |
258 | for ( x=0; x < _original_data.width(); ++x ) | 303 | for ( x=0; x < _original_data.width(); ++x ) |
259 | { | 304 | { |
260 | destData = (unsigned char *)dest.scanLine(x); | 305 | destData = (unsigned char *)dest.scanLine(x); |
261 | destData[_original_data.height()-y-1] = srcData[x]; | 306 | destData[_original_data.height()-y-1] = srcData[x]; |
262 | } | 307 | } |
263 | } | 308 | } |
264 | break; | 309 | break; |
265 | case Rotate180: | 310 | case Rotate180: |
266 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); | 311 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); |
267 | dest.setNumColors(_original_data.numColors()); | 312 | dest.setNumColors(_original_data.numColors()); |
268 | srcTable = (unsigned int *)_original_data.colorTable(); | 313 | srcTable = (unsigned int *)_original_data.colorTable(); |
269 | destTable = (unsigned int *)dest.colorTable(); | 314 | destTable = (unsigned int *)dest.colorTable(); |
270 | for ( x=0; x < _original_data.numColors(); ++x ) | 315 | for ( x=0; x < _original_data.numColors(); ++x ) |
271 | destTable[x] = srcTable[x]; | 316 | destTable[x] = srcTable[x]; |
272 | for ( y=0; y < _original_data.height(); ++y ) | 317 | for ( y=0; y < _original_data.height(); ++y ) |
273 | { | 318 | { |
274 | srcData = (unsigned char *)_original_data.scanLine(y); | 319 | srcData = (unsigned char *)_original_data.scanLine(y); |
275 | destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1); | 320 | destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1); |
276 | for ( x=0; x < _original_data.width(); ++x ) | 321 | for ( x=0; x < _original_data.width(); ++x ) |
277 | destData[_original_data.width()-x-1] = srcData[x]; | 322 | destData[_original_data.width()-x-1] = srcData[x]; |
278 | } | 323 | } |
279 | break; | 324 | break; |
280 | case Rotate270: | 325 | case Rotate270: |
281 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 326 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
282 | dest.setNumColors(_original_data.numColors()); | 327 | dest.setNumColors(_original_data.numColors()); |
283 | srcTable = (unsigned int *)_original_data.colorTable(); | 328 | srcTable = (unsigned int *)_original_data.colorTable(); |
284 | destTable = (unsigned int *)dest.colorTable(); | 329 | destTable = (unsigned int *)dest.colorTable(); |
285 | for ( x=0; x < _original_data.numColors(); ++x ) | 330 | for ( x=0; x < _original_data.numColors(); ++x ) |
286 | destTable[x] = srcTable[x]; | 331 | destTable[x] = srcTable[x]; |
287 | for ( y=0; y < _original_data.height(); ++y ) | 332 | for ( y=0; y < _original_data.height(); ++y ) |
288 | { | 333 | { |
289 | srcData = (unsigned char *)_original_data.scanLine(y); | 334 | srcData = (unsigned char *)_original_data.scanLine(y); |
290 | for ( x=0; x < _original_data.width(); ++x ) | 335 | for ( x=0; x < _original_data.width(); ++x ) |
291 | { | 336 | { |
292 | destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); | 337 | destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); |
293 | destData[y] = srcData[x]; | 338 | destData[y] = srcData[x]; |
294 | } | 339 | } |
295 | } | 340 | } |
296 | break; | 341 | break; |
297 | default: | 342 | default: |
298 | dest = _original_data; | 343 | dest = _original_data; |
299 | break; | 344 | break; |
300 | } | 345 | } |
301 | 346 | ||
302 | } | 347 | } |
303 | _image_data = dest; | 348 | _image_data = dest; |
304 | } | 349 | } |
305 | 350 | ||
306 | void ImageScrollView::generateImage() | 351 | void OImageScrollView::generateImage() |
307 | { | 352 | { |
308 | Rotation r = Rotate0; | 353 | Rotation r = Rotate0; |
354 | if (_original_data.isNull()) return; | ||
309 | { | 355 | { |
310 | QCopEnvelope( "QPE/System", "busy()" ); | 356 | QCopEnvelope( "QPE/System", "busy()" ); |
311 | } | 357 | } |
312 | if (width()>height()&&_original_data.width()<_original_data.height() || | 358 | if (width()>height()&&_original_data.width()<_original_data.height() || |
313 | width()<height()&&_original_data.width()>_original_data.height()) { | 359 | width()<height()&&_original_data.width()>_original_data.height()) { |
314 | if (rotate_to_fit) r = Rotate90; | 360 | if (AutoRotate()) r = Rotate90; |
315 | } | 361 | } |
316 | 362 | ||
317 | odebug << " r = " << r << oendl; | 363 | odebug << " r = " << r << oendl; |
318 | if (scale_to_fit) { | 364 | if (AutoScale()) { |
319 | if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { | 365 | if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { |
320 | odebug << "Rescaling data" << oendl; | 366 | odebug << "Rescaling data" << oendl; |
321 | if (r==Rotate0) { | 367 | if (r==Rotate0) { |
322 | _image_data = _original_data; | 368 | _image_data = _original_data; |
323 | } else { | 369 | } else { |
324 | rotate_into_data(r); | 370 | rotate_into_data(r); |
325 | } | 371 | } |
326 | } | 372 | } |
327 | rescaleImage(width(),height()); | 373 | rescaleImage(width(),height()); |
328 | resizeContents(_image_data.width(),_image_data.height()); | 374 | resizeContents(_image_data.width(),_image_data.height()); |
329 | } else if (!first_resize_done||r!=last_rot||_image_data.width()==0) { | 375 | } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) { |
330 | if (r==Rotate0) { | 376 | if (r==Rotate0) { |
331 | _image_data = _original_data; | 377 | _image_data = _original_data; |
332 | } else { | 378 | } else { |
333 | rotate_into_data(r); | 379 | rotate_into_data(r); |
334 | } | 380 | } |
335 | last_rot = r; | 381 | m_last_rot = r; |
336 | resizeContents(_image_data.width(),_image_data.height()); | 382 | resizeContents(_image_data.width(),_image_data.height()); |
337 | } | 383 | } |
338 | _pdata.convertFromImage(_image_data); | 384 | _pdata.convertFromImage(_image_data); |
339 | 385 | ||
340 | 386 | ||
341 | /* | 387 | /* |
342 | * update the zoomer | 388 | * update the zoomer |
343 | */ | 389 | */ |
344 | check_zoomer(); | 390 | check_zoomer(); |
345 | emit imageSizeChanged( _image_data.size() ); | 391 | emit imageSizeChanged( _image_data.size() ); |
346 | rescaleImage( 128, 128 ); | 392 | rescaleImage( 128, 128 ); |
347 | /* | 393 | /* |
348 | * move scrollbar | 394 | * move scrollbar |
349 | */ | 395 | */ |
350 | _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2, | 396 | if (_zoomer) { |
351 | _image_data.width()/2, _image_data.height()/2 ); | 397 | _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2, |
352 | 398 | _image_data.width()/2, _image_data.height()/2 ); | |
353 | _zoomer->setImage( _image_data ); | 399 | _zoomer->setImage( _image_data ); |
400 | } | ||
354 | /* | 401 | /* |
355 | * invalidate | 402 | * invalidate |
356 | */ | 403 | */ |
357 | _image_data=QImage(); | 404 | _image_data=QImage(); |
358 | { | 405 | { |
359 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); | 406 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); |
360 | env << "Image generated"; | 407 | env << "Image generated"; |
361 | } | 408 | } |
362 | } | 409 | } |
363 | 410 | ||
364 | void ImageScrollView::resizeEvent(QResizeEvent * e) | 411 | void OImageScrollView::resizeEvent(QResizeEvent * e) |
365 | { | 412 | { |
366 | odebug << "ImageScrollView resizeEvent" << oendl; | 413 | odebug << "OImageScrollView resizeEvent" << oendl; |
367 | QScrollView::resizeEvent(e); | 414 | QScrollView::resizeEvent(e); |
368 | generateImage(); | 415 | generateImage(); |
369 | first_resize_done = true; | 416 | setFirstResizeDone(true); |
370 | emit viewportSizeChanged( viewport()->size() ); | 417 | emit viewportSizeChanged( viewport()->size() ); |
371 | 418 | ||
372 | } | 419 | } |
373 | 420 | ||
374 | void ImageScrollView::keyPressEvent(QKeyEvent * e) | 421 | void OImageScrollView::keyPressEvent(QKeyEvent * e) |
375 | { | 422 | { |
376 | if (!e) return; | 423 | if (!e) return; |
377 | int dx = horizontalScrollBar()->lineStep(); | 424 | int dx = horizontalScrollBar()->lineStep(); |
378 | int dy = verticalScrollBar()->lineStep(); | 425 | int dy = verticalScrollBar()->lineStep(); |
379 | if (e->key()==Qt::Key_Right) { | 426 | if (e->key()==Qt::Key_Right) { |
380 | scrollBy(dx,0); | 427 | scrollBy(dx,0); |
381 | e->accept(); | 428 | e->accept(); |
382 | } else if (e->key()==Qt::Key_Left) { | 429 | } else if (e->key()==Qt::Key_Left) { |
383 | scrollBy(0-dx,0); | 430 | scrollBy(0-dx,0); |
384 | e->accept(); | 431 | e->accept(); |
385 | } else if (e->key()==Qt::Key_Up) { | 432 | } else if (e->key()==Qt::Key_Up) { |
386 | scrollBy(0,0-dy); | 433 | scrollBy(0,0-dy); |
387 | e->accept(); | 434 | e->accept(); |
388 | } else if (e->key()==Qt::Key_Down) { | 435 | } else if (e->key()==Qt::Key_Down) { |
389 | scrollBy(0,dy); | 436 | scrollBy(0,dy); |
390 | e->accept(); | 437 | e->accept(); |
391 | } else { | 438 | } else { |
392 | e->ignore(); | 439 | e->ignore(); |
393 | } | 440 | } |
394 | QScrollView::keyPressEvent(e); | 441 | QScrollView::keyPressEvent(e); |
395 | } | 442 | } |
396 | 443 | ||
397 | void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) | 444 | void OImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) |
398 | { | 445 | { |
399 | int w = clipw; | 446 | int w = clipw; |
400 | int h = cliph; | 447 | int h = cliph; |
401 | int x = clipx; | 448 | int x = clipx; |
402 | int y = clipy; | 449 | int y = clipy; |
403 | bool erase = false; | 450 | bool erase = false; |
404 | 451 | ||
405 | if (!_pdata.size().isValid()) { | 452 | if (!_pdata.size().isValid()) { |
406 | p->fillRect(clipx,clipy,clipw,cliph,white); | 453 | p->fillRect(clipx,clipy,clipw,cliph,white); |
407 | return; | 454 | return; |
408 | } | 455 | } |
409 | if (w>_pdata.width()) { | 456 | if (w>_pdata.width()) { |
410 | w=_pdata.width(); | 457 | w=_pdata.width(); |
411 | x = 0; | 458 | x = 0; |
412 | erase = true; | 459 | erase = true; |
413 | } else if (x+w>_pdata.width()){ | 460 | } else if (x+w>_pdata.width()){ |
414 | x = _pdata.width()-w; | 461 | x = _pdata.width()-w; |
415 | } | 462 | } |
416 | if (h>_pdata.height()) { | 463 | if (h>_pdata.height()) { |
417 | h=_pdata.height(); | 464 | h=_pdata.height(); |
418 | y = 0; | 465 | y = 0; |
419 | erase = true; | 466 | erase = true; |
420 | } else if (y+h>_pdata.height()){ | 467 | } else if (y+h>_pdata.height()){ |
421 | y = _pdata.height()-h; | 468 | y = _pdata.height()-h; |
422 | } | 469 | } |
423 | if (erase||_original_data.hasAlphaBuffer()) { | 470 | if (erase||_original_data.hasAlphaBuffer()) { |
424 | p->fillRect(clipx,clipy,clipw,cliph,white); | 471 | p->fillRect(clipx,clipy,clipw,cliph,white); |
425 | } | 472 | } |
426 | p->drawPixmap(clipx,clipy,_pdata,x,y,w,h); | 473 | p->drawPixmap(clipx,clipy,_pdata,x,y,w,h); |
427 | } | 474 | } |
428 | 475 | ||
429 | /* using the real geometry points and not the translated points is wanted! */ | 476 | /* using the real geometry points and not the translated points is wanted! */ |
430 | void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) | 477 | void OImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) |
431 | { | 478 | { |
432 | odebug << "Move X and Y " << e->x() << " " << e->y() << oendl; | 479 | odebug << "Move X and Y " << e->x() << " " << e->y() << oendl; |
433 | int mx, my; | 480 | int mx, my; |
434 | mx = e->x(); | 481 | mx = e->x(); |
435 | my = e->y(); | 482 | my = e->y(); |
436 | if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) { | 483 | if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) { |
437 | int diffx = _mouseStartPosX-mx; | 484 | int diffx = _mouseStartPosX-mx; |
438 | int diffy = _mouseStartPosY-my; | 485 | int diffy = _mouseStartPosY-my; |
439 | #if 0 | 486 | #if 0 |
440 | QScrollBar*xbar = horizontalScrollBar(); | 487 | QScrollBar*xbar = horizontalScrollBar(); |
441 | QScrollBar*ybar = verticalScrollBar(); | 488 | QScrollBar*ybar = verticalScrollBar(); |
442 | if (xbar->value()+diffx>xbar->maxValue()) { | 489 | if (xbar->value()+diffx>xbar->maxValue()) { |
443 | diffx = xbar->maxValue()-xbar->value(); | 490 | diffx = xbar->maxValue()-xbar->value(); |
444 | } else if (xbar->value()+diffx<0) { | 491 | } else if (xbar->value()+diffx<0) { |
445 | diffx=0-xbar->value(); | 492 | diffx=0-xbar->value(); |
446 | } | 493 | } |
447 | if (ybar->value()+diffy>ybar->maxValue()) { | 494 | if (ybar->value()+diffy>ybar->maxValue()) { |
448 | diffy = ybar->maxValue()-ybar->value(); | 495 | diffy = ybar->maxValue()-ybar->value(); |
449 | } else if (ybar->value()+diffy<0) { | 496 | } else if (ybar->value()+diffy<0) { |
450 | diffy=0-ybar->value(); | 497 | diffy=0-ybar->value(); |
451 | } | 498 | } |
452 | #endif | 499 | #endif |
453 | scrollBy(diffx,diffy); | 500 | scrollBy(diffx,diffy); |
454 | } | 501 | } |
455 | _mouseStartPosX=mx; | 502 | _mouseStartPosX=mx; |
456 | _mouseStartPosY=my; | 503 | _mouseStartPosY=my; |
457 | } | 504 | } |
458 | 505 | ||
459 | void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e) | 506 | void OImageScrollView::contentsMousePressEvent ( QMouseEvent * e) |
460 | { | 507 | { |
461 | odebug << " X and Y " << e->x() << " " << e->y() << oendl; | 508 | odebug << " X and Y " << e->x() << " " << e->y() << oendl; |
462 | /* this marks the beginning of a possible mouse move. Due internal reasons of QT | 509 | /* this marks the beginning of a possible mouse move. Due internal reasons of QT |
463 | the geometry values here may real differ from that set in MoveEvent (I don't know | 510 | the geometry values here may real differ from that set in MoveEvent (I don't know |
464 | why). For getting them in real context, we use the first move-event to set the start | 511 | why). For getting them in real context, we use the first move-event to set the start |
465 | position ;) | 512 | position ;) |
466 | */ | 513 | */ |
467 | _mouseStartPosX = -1; | 514 | _mouseStartPosX = -1; |
468 | _mouseStartPosY = -1; | 515 | _mouseStartPosY = -1; |
469 | } | 516 | } |
470 | 517 | ||
471 | void ImageScrollView::setDestructiveClose() { | 518 | void OImageScrollView::setDestructiveClose() { |
472 | WFlags fl = getWFlags(); | 519 | WFlags fl = getWFlags(); |
473 | /* clear it just in case */ | 520 | /* clear it just in case */ |
474 | fl &= ~WDestructiveClose; | 521 | fl &= ~WDestructiveClose; |
475 | fl |= WDestructiveClose; | 522 | fl |= WDestructiveClose; |
476 | setWFlags( fl ); | 523 | setWFlags( fl ); |
477 | } | 524 | } |
478 | 525 | ||
479 | bool ImageScrollView::image_fit_into(const QSize&s ) | 526 | bool OImageScrollView::image_fit_into(const QSize&s ) |
480 | { | 527 | { |
481 | if (s.width()>width()||s.height()>height()) { | 528 | if (s.width()>width()||s.height()>height()) { |
482 | return false; | 529 | return false; |
483 | } | 530 | } |
484 | return true; | 531 | return true; |
485 | } | 532 | } |
486 | 533 | ||
487 | void ImageScrollView::setShowZoomer(bool how) | 534 | void OImageScrollView::setShowZoomer(bool how) |
488 | { | 535 | { |
489 | show_zoomer = how; | 536 | m_states.setBit(SHOW_ZOOMER,how); |
490 | check_zoomer(); | 537 | check_zoomer(); |
491 | } | 538 | } |
492 | 539 | ||
493 | void ImageScrollView::check_zoomer() | 540 | bool OImageScrollView::ShowZoomer()const |
541 | { | ||
542 | return m_states.testBit(SHOW_ZOOMER); | ||
543 | } | ||
544 | |||
545 | void OImageScrollView::check_zoomer() | ||
494 | { | 546 | { |
495 | if ( (!show_zoomer||image_fit_into(_pdata.size()) ) && _zoomer->isVisible()) { | 547 | if (!_zoomer) return; |
548 | if ( (!ShowZoomer()||image_fit_into(_pdata.size()) ) && _zoomer->isVisible()) { | ||
496 | _zoomer->hide(); | 549 | _zoomer->hide(); |
497 | } else if ( show_zoomer && !image_fit_into(_pdata.size()) && _zoomer->isHidden()){ | 550 | } else if ( ShowZoomer() && !image_fit_into(_pdata.size()) && _zoomer->isHidden()){ |
498 | _zoomer->show(); | 551 | _zoomer->show(); |
499 | } | 552 | } |
500 | } | 553 | } |
554 | |||
555 | bool OImageScrollView::FirstResizeDone()const | ||
556 | { | ||
557 | return m_states.testBit(FIRST_RESIZE_DONE); | ||
558 | } | ||
559 | |||
560 | void OImageScrollView::setFirstResizeDone(bool how) | ||
561 | { | ||
562 | m_states.setBit(FIRST_RESIZE_DONE,how); | ||
563 | } | ||
564 | |||
565 | bool OImageScrollView::ImageIsJpeg()const | ||
566 | { | ||
567 | return m_states.testBit(IMAGE_IS_JPEG); | ||
568 | } | ||
569 | |||
570 | void OImageScrollView::setImageIsJpeg(bool how) | ||
571 | { | ||
572 | m_states.setBit(IMAGE_IS_JPEG,how); | ||
573 | } | ||
574 | |||
575 | bool OImageScrollView::ImageScaledLoaded()const | ||
576 | { | ||
577 | return m_states.testBit(IMAGE_SCALED_LOADED); | ||
578 | } | ||
579 | |||
580 | void OImageScrollView::setImageScaledLoaded(bool how) | ||
581 | { | ||
582 | m_states.setBit(IMAGE_SCALED_LOADED,how); | ||
583 | } | ||
584 | |||
585 | } // namespace MM | ||
586 | } // namespace Opie | ||
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h index f6e187d..3d2ea38 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.h +++ b/noncore/graphics/opie-eye/gui/imagescrollview.h | |||
@@ -1,78 +1,95 @@ | |||
1 | #ifndef _IMAGE_SCROLL_VIEW_H | 1 | #ifndef _IMAGE_SCROLL_VIEW_H |
2 | #define _IMAGE_SCROLL_VIEW_H | 2 | #define _IMAGE_SCROLL_VIEW_H |
3 | 3 | ||
4 | #include <lib/oimagezoomer.h> | ||
5 | |||
6 | #include <qscrollview.h> | 4 | #include <qscrollview.h> |
7 | #include <qimage.h> | 5 | #include <qimage.h> |
8 | #include <qpixmap.h> | 6 | #include <qpixmap.h> |
9 | #include <qstring.h> | 7 | #include <qstring.h> |
10 | #include <qdialog.h> | 8 | #include <qdialog.h> |
11 | 9 | #include <qbitarray.h> | |
12 | 10 | ||
13 | 11 | ||
14 | class QPainter; | 12 | class QPainter; |
15 | 13 | ||
16 | class ImageScrollView:public QScrollView | 14 | namespace Opie { namespace MM { |
15 | |||
16 | class OImageZoomer; | ||
17 | |||
18 | class OImageScrollView:public QScrollView | ||
17 | { | 19 | { |
18 | Q_OBJECT | 20 | Q_OBJECT |
19 | public: | 21 | public: |
20 | ImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 ); | 22 | enum Rotation { |
21 | ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); | 23 | Rotate0, |
22 | ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); | 24 | Rotate90, |
23 | virtual ~ImageScrollView(); | 25 | Rotate180, |
26 | Rotate270 | ||
27 | }; | ||
28 | |||
29 | OImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 ); | ||
30 | OImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); | ||
31 | OImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); | ||
32 | virtual ~OImageScrollView(); | ||
33 | |||
24 | 34 | ||
25 | virtual void setImage(const QImage&); | ||
26 | virtual void setImage( const QString& path ); | ||
27 | virtual void setDestructiveClose(); | 35 | virtual void setDestructiveClose(); |
28 | 36 | ||
29 | virtual void setAutoRotate(bool); | 37 | virtual void setAutoRotate(bool); |
30 | virtual void setAutoScale(bool); | 38 | virtual void setAutoScale(bool); |
31 | virtual void setShowZoomer(bool); | 39 | virtual void setShowZoomer(bool); |
32 | 40 | ||
33 | enum Rotation { | 41 | virtual bool AutoRotate()const; |
34 | Rotate0, | 42 | virtual bool AutoScale()const; |
35 | Rotate90, | 43 | virtual bool ShowZoomer()const; |
36 | Rotate180, | 44 | |
37 | Rotate270 | 45 | public slots: |
38 | }; | 46 | virtual void setImage(const QImage&); |
47 | virtual void setImage( const QString& path ); | ||
48 | |||
39 | 49 | ||
40 | signals: | 50 | signals: |
41 | void sig_return(); | ||
42 | void imageSizeChanged( const QSize& ); | 51 | void imageSizeChanged( const QSize& ); |
43 | void viewportSizeChanged( const QSize& ); | 52 | void viewportSizeChanged( const QSize& ); |
44 | 53 | ||
45 | protected: | 54 | protected: |
46 | virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); | 55 | virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); |
47 | void init(); | 56 | void init(); |
48 | 57 | ||
49 | Opie::MM::OImageZoomer *_zoomer; | 58 | Opie::MM::OImageZoomer *_zoomer; |
50 | QImage _image_data; | 59 | QImage _image_data; |
51 | QImage _original_data; | 60 | QImage _original_data; |
52 | QPixmap _pdata; | 61 | QPixmap _pdata; |
53 | 62 | ||
54 | int _mouseStartPosX,_mouseStartPosY; | 63 | int _mouseStartPosX,_mouseStartPosY; |
55 | 64 | ||
56 | bool scale_to_fit; | 65 | QBitArray m_states; |
57 | bool rotate_to_fit; | 66 | |
58 | bool show_zoomer; | 67 | Rotation m_last_rot; |
59 | bool first_resize_done; | ||
60 | bool image_is_jpeg; | ||
61 | bool image_scaled_loaded; | ||
62 | Rotation last_rot; | ||
63 | QString m_lastName; | 68 | QString m_lastName; |
64 | virtual void rescaleImage(int w, int h); | 69 | virtual void rescaleImage(int w, int h); |
65 | 70 | ||
66 | virtual void rotate_into_data(Rotation r); | 71 | virtual void rotate_into_data(Rotation r); |
67 | virtual void generateImage(); | 72 | virtual void generateImage(); |
68 | virtual void loadJpeg(bool interncall = false); | 73 | virtual void loadJpeg(bool interncall = false); |
69 | bool image_fit_into(const QSize&s); | 74 | bool image_fit_into(const QSize&s); |
70 | void check_zoomer(); | 75 | void check_zoomer(); |
71 | 76 | ||
77 | /* internal bitset manipulation */ | ||
78 | virtual bool ImageIsJpeg()const; | ||
79 | virtual void setImageIsJpeg(bool how); | ||
80 | virtual bool ImageScaledLoaded()const; | ||
81 | virtual void setImageScaledLoaded(bool how); | ||
82 | virtual bool FirstResizeDone()const; | ||
83 | virtual void setFirstResizeDone(bool how); | ||
84 | |||
72 | protected slots: | 85 | protected slots: |
73 | virtual void viewportMouseMoveEvent(QMouseEvent* e); | 86 | virtual void viewportMouseMoveEvent(QMouseEvent* e); |
74 | virtual void contentsMousePressEvent ( QMouseEvent * e); | 87 | virtual void contentsMousePressEvent ( QMouseEvent * e); |
75 | virtual void resizeEvent(QResizeEvent * e); | 88 | virtual void resizeEvent(QResizeEvent * e); |
76 | virtual void keyPressEvent(QKeyEvent * e); | 89 | virtual void keyPressEvent(QKeyEvent * e); |
77 | }; | 90 | }; |
91 | |||
92 | } | ||
93 | } | ||
94 | |||
78 | #endif | 95 | #endif |
diff --git a/noncore/graphics/opie-eye/gui/imageview.cpp b/noncore/graphics/opie-eye/gui/imageview.cpp index 2078b19..db3ae74 100644 --- a/noncore/graphics/opie-eye/gui/imageview.cpp +++ b/noncore/graphics/opie-eye/gui/imageview.cpp | |||
@@ -1,61 +1,60 @@ | |||
1 | #include "imageview.h" | 1 | #include "imageview.h" |
2 | 2 | ||
3 | #include <opie2/odebug.h> | 3 | #include <opie2/odebug.h> |
4 | #include <opie2/oconfig.h> | 4 | #include <opie2/oconfig.h> |
5 | #include <opie2/okeyconfigwidget.h> | 5 | #include <opie2/okeyconfigwidget.h> |
6 | 6 | ||
7 | #include <qpe/resource.h> | 7 | #include <qpe/resource.h> |
8 | 8 | ||
9 | using namespace Opie::Core; | 9 | using namespace Opie::Core; |
10 | 10 | ||
11 | ImageView::ImageView(Opie::Core::OConfig *cfg, QWidget* parent, const char* name, WFlags fl ) | 11 | ImageView::ImageView(Opie::Core::OConfig *cfg, QWidget* parent, const char* name, WFlags fl ) |
12 | : ImageScrollView(parent,name,fl) | 12 | : Opie::MM::OImageScrollView(parent,name,fl) |
13 | { | 13 | { |
14 | m_viewManager = 0; | 14 | m_viewManager = 0; |
15 | m_cfg = cfg; | 15 | m_cfg = cfg; |
16 | initKeys(); | 16 | initKeys(); |
17 | } | 17 | } |
18 | 18 | ||
19 | ImageView::~ImageView() | 19 | ImageView::~ImageView() |
20 | { | 20 | { |
21 | if (m_viewManager) { | 21 | if (m_viewManager) { |
22 | delete m_viewManager; | 22 | delete m_viewManager; |
23 | } | 23 | } |
24 | } | 24 | } |
25 | 25 | ||
26 | Opie::Core::OKeyConfigManager* ImageView::manager() | 26 | Opie::Core::OKeyConfigManager* ImageView::manager() |
27 | { | 27 | { |
28 | if (!m_viewManager) { | 28 | if (!m_viewManager) { |
29 | initKeys(); | 29 | initKeys(); |
30 | } | 30 | } |
31 | return m_viewManager; | 31 | return m_viewManager; |
32 | } | 32 | } |
33 | 33 | ||
34 | void ImageView::initKeys() | 34 | void ImageView::initKeys() |
35 | { | 35 | { |
36 | odebug << "init imageview keys" << oendl; | 36 | odebug << "init imageview keys" << oendl; |
37 | if (!m_cfg) { | 37 | if (!m_cfg) { |
38 | m_cfg = new Opie::Core::OConfig("phunkview"); | 38 | m_cfg = new Opie::Core::OConfig("phunkview"); |
39 | m_cfg->setGroup("image_view_keys" ); | 39 | m_cfg->setGroup("image_view_keys" ); |
40 | } | 40 | } |
41 | Opie::Core::OKeyPair::List lst; | 41 | Opie::Core::OKeyPair::List lst; |
42 | lst.append( Opie::Core::OKeyPair::upArrowKey() ); | 42 | lst.append( Opie::Core::OKeyPair::upArrowKey() ); |
43 | lst.append( Opie::Core::OKeyPair::downArrowKey() ); | 43 | lst.append( Opie::Core::OKeyPair::downArrowKey() ); |
44 | lst.append( Opie::Core::OKeyPair::leftArrowKey() ); | 44 | lst.append( Opie::Core::OKeyPair::leftArrowKey() ); |
45 | lst.append( Opie::Core::OKeyPair::rightArrowKey() ); | 45 | lst.append( Opie::Core::OKeyPair::rightArrowKey() ); |
46 | lst.append( Opie::Core::OKeyPair::returnKey() ); | ||
47 | 46 | ||
48 | m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "image_view_keys", | 47 | m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "image_view_keys", |
49 | lst, false,this, "image_view_keys" ); | 48 | lst, false,this, "image_view_keys" ); |
50 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("View Image Info"), "imageviewinfo", | 49 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("View Image Info"), "imageviewinfo", |
51 | Resource::loadPixmap("1to1"), ViewInfo, | 50 | Resource::loadPixmap("1to1"), ViewInfo, |
52 | Opie::Core::OKeyPair(Qt::Key_I,Qt::ShiftButton), | 51 | Opie::Core::OKeyPair(Qt::Key_I,Qt::ShiftButton), |
53 | this, SLOT(slotShowImageInfo()))); | 52 | this, SLOT(slotShowImageInfo()))); |
54 | m_viewManager->handleWidget( this ); | 53 | m_viewManager->handleWidget( this ); |
55 | m_viewManager->load(); | 54 | m_viewManager->load(); |
56 | } | 55 | } |
57 | 56 | ||
58 | void ImageView::slotShowImageInfo() | 57 | void ImageView::slotShowImageInfo() |
59 | { | 58 | { |
60 | emit dispImageInfo(m_lastName); | 59 | emit dispImageInfo(m_lastName); |
61 | } | 60 | } |
diff --git a/noncore/graphics/opie-eye/gui/imageview.h b/noncore/graphics/opie-eye/gui/imageview.h index 87e2b32..e4f899a 100644 --- a/noncore/graphics/opie-eye/gui/imageview.h +++ b/noncore/graphics/opie-eye/gui/imageview.h | |||
@@ -1,38 +1,37 @@ | |||
1 | #ifndef _IMAGE_VIEW_H | 1 | #ifndef _IMAGE_VIEW_H |
2 | #define _IMAGE_VIEW_H | 2 | #define _IMAGE_VIEW_H |
3 | 3 | ||
4 | /* must be changed when it will moved to Opie::MM */ | 4 | /* must be changed when it will moved to Opie::MM */ |
5 | #include "imagescrollview.h" | 5 | #include "imagescrollview.h" |
6 | 6 | ||
7 | namespace Opie { | 7 | namespace Opie { |
8 | namespace Core { | 8 | namespace Core { |
9 | class OConfig; | 9 | class OConfig; |
10 | class OKeyConfigManager; | 10 | class OKeyConfigManager; |
11 | } | 11 | } |
12 | } | 12 | } |
13 | 13 | ||
14 | class ImageView:public ImageScrollView | 14 | class ImageView:public Opie::MM::OImageScrollView |
15 | { | 15 | { |
16 | Q_OBJECT | 16 | Q_OBJECT |
17 | 17 | ||
18 | enum ActionIds { | 18 | enum ActionIds { |
19 | ViewInfo | 19 | ViewInfo |
20 | }; | 20 | }; |
21 | 21 | ||
22 | public: | 22 | public: |
23 | ImageView(Opie::Core::OConfig *cfg, QWidget* parent, const char* name = 0, WFlags fl = 0 ); | 23 | ImageView(Opie::Core::OConfig *cfg, QWidget* parent, const char* name = 0, WFlags fl = 0 ); |
24 | virtual ~ImageView(); | 24 | virtual ~ImageView(); |
25 | Opie::Core::OKeyConfigManager* manager(); | 25 | Opie::Core::OKeyConfigManager* manager(); |
26 | 26 | ||
27 | signals: | 27 | signals: |
28 | void dispImageInfo(const QString&); | 28 | void dispImageInfo(const QString&); |
29 | void sig_return(); | ||
30 | 29 | ||
31 | protected: | 30 | protected: |
32 | Opie::Core::OConfig * m_cfg; | 31 | Opie::Core::OConfig * m_cfg; |
33 | Opie::Core::OKeyConfigManager*m_viewManager; | 32 | Opie::Core::OKeyConfigManager*m_viewManager; |
34 | void initKeys(); | 33 | void initKeys(); |
35 | protected slots: | 34 | protected slots: |
36 | virtual void slotShowImageInfo(); | 35 | virtual void slotShowImageInfo(); |
37 | }; | 36 | }; |
38 | #endif | 37 | #endif |
diff --git a/noncore/graphics/opie-eye/gui/mainwindow.cpp b/noncore/graphics/opie-eye/gui/mainwindow.cpp index e5921d8..09f562a 100644 --- a/noncore/graphics/opie-eye/gui/mainwindow.cpp +++ b/noncore/graphics/opie-eye/gui/mainwindow.cpp | |||
@@ -1,327 +1,327 @@ | |||
1 | /* | 1 | /* |
2 | * GPLv2 zecke@handhelds.org | 2 | * GPLv2 zecke@handhelds.org |
3 | * No WArranty... | 3 | * No WArranty... |
4 | */ | 4 | */ |
5 | #include "mainwindow.h" | 5 | #include "mainwindow.h" |
6 | #include "imageview.h" | ||
6 | 7 | ||
7 | #include "iconview.h" | 8 | #include "iconview.h" |
8 | #include "filesystem.h" | 9 | #include "filesystem.h" |
9 | #include "imageinfoui.h" | 10 | #include "imageinfoui.h" |
10 | #include "imageview.h" | ||
11 | #include "viewmodebutton.h" | 11 | #include "viewmodebutton.h" |
12 | 12 | ||
13 | #include <iface/ifaceinfo.h> | 13 | #include <iface/ifaceinfo.h> |
14 | #include <iface/dirview.h> | 14 | #include <iface/dirview.h> |
15 | 15 | ||
16 | #include <opie2/odebug.h> | 16 | #include <opie2/odebug.h> |
17 | #include <opie2/owidgetstack.h> | 17 | #include <opie2/owidgetstack.h> |
18 | #include <opie2/oapplicationfactory.h> | 18 | #include <opie2/oapplicationfactory.h> |
19 | #include <opie2/otabwidget.h> | 19 | #include <opie2/otabwidget.h> |
20 | #include <opie2/okeyconfigwidget.h> | 20 | #include <opie2/okeyconfigwidget.h> |
21 | 21 | ||
22 | #include <qpe/resource.h> | 22 | #include <qpe/resource.h> |
23 | #include <qpe/config.h> | 23 | #include <qpe/config.h> |
24 | #include <qpe/ir.h> | 24 | #include <qpe/ir.h> |
25 | #include <qpe/applnk.h> | 25 | #include <qpe/applnk.h> |
26 | 26 | ||
27 | #include <qtoolbar.h> | 27 | #include <qtoolbar.h> |
28 | #include <qtoolbutton.h> | 28 | #include <qtoolbutton.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | #include <qdialog.h> | 30 | #include <qdialog.h> |
31 | #include <qmap.h> | 31 | #include <qmap.h> |
32 | #include <qtimer.h> | 32 | #include <qtimer.h> |
33 | 33 | ||
34 | 34 | ||
35 | 35 | ||
36 | 36 | ||
37 | OPIE_EXPORT_APP_V2( Opie::Core::OApplicationFactory<PMainWindow>,"Opie Eye" ) | 37 | OPIE_EXPORT_APP_V2( Opie::Core::OApplicationFactory<PMainWindow>,"Opie Eye" ) |
38 | 38 | ||
39 | PMainWindow::PMainWindow(QWidget* wid, const char* name, WFlags style) | 39 | PMainWindow::PMainWindow(QWidget* wid, const char* name, WFlags style) |
40 | : QMainWindow( wid, name, style ), m_info( 0 ), m_disp( 0 ) | 40 | : QMainWindow( wid, name, style ), m_info( 0 ), m_disp( 0 ) |
41 | { | 41 | { |
42 | setCaption( QObject::tr("Opie Eye Caramba" ) ); | 42 | setCaption( QObject::tr("Opie Eye Caramba" ) ); |
43 | m_cfg = new Opie::Core::OConfig("phunkview"); | 43 | m_cfg = new Opie::Core::OConfig("phunkview"); |
44 | m_cfg->setGroup("Zecke_view" ); | 44 | m_cfg->setGroup("Zecke_view" ); |
45 | // qDebug( "Process-wide OApplication object @ %0x", oApp ); | 45 | // qDebug( "Process-wide OApplication object @ %0x", oApp ); |
46 | /* | 46 | /* |
47 | * Initialize ToolBar and IconView | 47 | * Initialize ToolBar and IconView |
48 | * And Connect Them | 48 | * And Connect Them |
49 | */ | 49 | */ |
50 | QToolBar *bar = new QToolBar( this ); | 50 | QToolBar *bar = new QToolBar( this ); |
51 | bar->setHorizontalStretchable( true ); | 51 | bar->setHorizontalStretchable( true ); |
52 | setToolBarsMovable( false ); | 52 | setToolBarsMovable( false ); |
53 | 53 | ||
54 | m_stack = new Opie::Ui::OWidgetStack( this ); | 54 | m_stack = new Opie::Ui::OWidgetStack( this ); |
55 | setCentralWidget( m_stack ); | 55 | setCentralWidget( m_stack ); |
56 | 56 | ||
57 | m_view = new PIconView( m_stack, m_cfg ); | 57 | m_view = new PIconView( m_stack, m_cfg ); |
58 | m_stack->addWidget( m_view, IconView ); | 58 | m_stack->addWidget( m_view, IconView ); |
59 | m_stack->raiseWidget( IconView ); | 59 | m_stack->raiseWidget( IconView ); |
60 | connect(m_view, SIGNAL(sig_display(const QString&)), | 60 | connect(m_view, SIGNAL(sig_display(const QString&)), |
61 | this, SLOT(slotDisplay(const QString&))); | 61 | this, SLOT(slotDisplay(const QString&))); |
62 | connect(m_view, SIGNAL(sig_showInfo(const QString&)), | 62 | connect(m_view, SIGNAL(sig_showInfo(const QString&)), |
63 | this, SLOT(slotShowInfo(const QString&)) ); | 63 | this, SLOT(slotShowInfo(const QString&)) ); |
64 | 64 | ||
65 | m_stack->forceMode(Opie::Ui::OWidgetStack::NoForce); | 65 | m_stack->forceMode(Opie::Ui::OWidgetStack::NoForce); |
66 | 66 | ||
67 | QToolButton *btn = new QToolButton( bar ); | 67 | QToolButton *btn = new QToolButton( bar ); |
68 | btn->setIconSet( Resource::loadIconSet( "up" ) ); | 68 | btn->setIconSet( Resource::loadIconSet( "up" ) ); |
69 | connect( btn, SIGNAL(clicked()), | 69 | connect( btn, SIGNAL(clicked()), |
70 | m_view, SLOT(slotDirUp()) ); | 70 | m_view, SLOT(slotDirUp()) ); |
71 | 71 | ||
72 | btn = new PFileSystem( bar ); | 72 | btn = new PFileSystem( bar ); |
73 | connect( btn, SIGNAL( changeDir( const QString& ) ), | 73 | connect( btn, SIGNAL( changeDir( const QString& ) ), |
74 | m_view, SLOT(slotChangeDir( const QString& ) ) ); | 74 | m_view, SLOT(slotChangeDir( const QString& ) ) ); |
75 | 75 | ||
76 | btn = new QToolButton( bar ); | 76 | btn = new QToolButton( bar ); |
77 | btn->setIconSet( Resource::loadIconSet( "edit" ) ); | 77 | btn->setIconSet( Resource::loadIconSet( "edit" ) ); |
78 | connect( btn, SIGNAL(clicked()), | 78 | connect( btn, SIGNAL(clicked()), |
79 | m_view, SLOT(slotRename()) ); | 79 | m_view, SLOT(slotRename()) ); |
80 | 80 | ||
81 | if ( Ir::supported() ) { | 81 | if ( Ir::supported() ) { |
82 | btn = new QToolButton( bar ); | 82 | btn = new QToolButton( bar ); |
83 | btn->setIconSet( Resource::loadIconSet( "beam" ) ); | 83 | btn->setIconSet( Resource::loadIconSet( "beam" ) ); |
84 | connect( btn, SIGNAL(clicked()), | 84 | connect( btn, SIGNAL(clicked()), |
85 | m_view, SLOT(slotBeam()) ); | 85 | m_view, SLOT(slotBeam()) ); |
86 | } | 86 | } |
87 | 87 | ||
88 | btn = new QToolButton( bar ); | 88 | btn = new QToolButton( bar ); |
89 | btn->setIconSet( Resource::loadIconSet( "trash" ) ); | 89 | btn->setIconSet( Resource::loadIconSet( "trash" ) ); |
90 | connect( btn, SIGNAL(clicked() ), | 90 | connect( btn, SIGNAL(clicked() ), |
91 | m_view, SLOT(slotTrash() ) ); | 91 | m_view, SLOT(slotTrash() ) ); |
92 | 92 | ||
93 | 93 | ||
94 | btn = new ViewModeButton( bar ); | 94 | btn = new ViewModeButton( bar ); |
95 | connect( btn, SIGNAL(changeMode(int)), | 95 | connect( btn, SIGNAL(changeMode(int)), |
96 | m_view, SLOT(slotChangeMode(int))); | 96 | m_view, SLOT(slotChangeMode(int))); |
97 | 97 | ||
98 | btn = new QToolButton( bar ); | 98 | btn = new QToolButton( bar ); |
99 | btn->setIconSet( Resource::loadIconSet( "SettingsIcon" ) ); | 99 | btn->setIconSet( Resource::loadIconSet( "SettingsIcon" ) ); |
100 | connect( btn, SIGNAL(clicked() ), | 100 | connect( btn, SIGNAL(clicked() ), |
101 | this, SLOT(slotConfig() ) ); | 101 | this, SLOT(slotConfig() ) ); |
102 | 102 | ||
103 | rotateButton = new QToolButton(bar); | 103 | rotateButton = new QToolButton(bar); |
104 | rotateButton->setIconSet( Resource::loadIconSet( "rotate" ) ); | 104 | rotateButton->setIconSet( Resource::loadIconSet( "rotate" ) ); |
105 | rotateButton->setToggleButton(true); | 105 | rotateButton->setToggleButton(true); |
106 | 106 | ||
107 | odebug << "Mode = " << m_stack->mode() << oendl; | 107 | odebug << "Mode = " << m_stack->mode() << oendl; |
108 | if (m_stack->mode() == Opie::Ui::OWidgetStack::SmallScreen) { | 108 | if (m_stack->mode() == Opie::Ui::OWidgetStack::SmallScreen) { |
109 | rotateButton->setOn(true); | 109 | rotateButton->setOn(true); |
110 | autoRotate = true; | 110 | autoRotate = true; |
111 | } else { | 111 | } else { |
112 | rotateButton->setOn(false); | 112 | rotateButton->setOn(false); |
113 | autoRotate = false; | 113 | autoRotate = false; |
114 | } | 114 | } |
115 | 115 | ||
116 | connect(rotateButton,SIGNAL(toggled(bool)),this,SLOT(slotRotateToggled(bool))); | 116 | connect(rotateButton,SIGNAL(toggled(bool)),this,SLOT(slotRotateToggled(bool))); |
117 | 117 | ||
118 | btn = new QToolButton(bar); | 118 | btn = new QToolButton(bar); |
119 | btn->setIconSet( Resource::loadIconSet( "1to1" ) ); | 119 | btn->setIconSet( Resource::loadIconSet( "1to1" ) ); |
120 | btn->setToggleButton(true); | 120 | btn->setToggleButton(true); |
121 | btn->setOn(false); | 121 | btn->setOn(false); |
122 | connect(btn,SIGNAL(toggled(bool)),this,SLOT(slotScaleToggled(bool))); | 122 | connect(btn,SIGNAL(toggled(bool)),this,SLOT(slotScaleToggled(bool))); |
123 | autoScale = true; | 123 | autoScale = true; |
124 | 124 | ||
125 | btn = new QToolButton(bar); | 125 | btn = new QToolButton(bar); |
126 | btn->setIconSet( Resource::loadIconSet( "mag" ) ); | 126 | btn->setIconSet( Resource::loadIconSet( "mag" ) ); |
127 | btn->setToggleButton(true); | 127 | btn->setToggleButton(true); |
128 | btn->setOn(true); | 128 | btn->setOn(true); |
129 | connect(btn,SIGNAL(toggled(bool)),this,SLOT(slotZoomerToggled(bool))); | 129 | connect(btn,SIGNAL(toggled(bool)),this,SLOT(slotZoomerToggled(bool))); |
130 | zoomerOn = true; | 130 | zoomerOn = true; |
131 | } | 131 | } |
132 | 132 | ||
133 | PMainWindow::~PMainWindow() { | 133 | PMainWindow::~PMainWindow() { |
134 | odebug << "Shutting down" << oendl; | 134 | odebug << "Shutting down" << oendl; |
135 | } | 135 | } |
136 | 136 | ||
137 | void PMainWindow::slotZoomerToggled(bool how) | 137 | void PMainWindow::slotZoomerToggled(bool how) |
138 | { | 138 | { |
139 | zoomerOn = how; | 139 | zoomerOn = how; |
140 | if (m_disp) { | 140 | if (m_disp) { |
141 | m_disp->setShowZoomer(zoomerOn); | 141 | m_disp->setShowZoomer(zoomerOn); |
142 | } | 142 | } |
143 | } | 143 | } |
144 | 144 | ||
145 | void PMainWindow::slotRotateToggled(bool how) | 145 | void PMainWindow::slotRotateToggled(bool how) |
146 | { | 146 | { |
147 | autoRotate = how; | 147 | autoRotate = how; |
148 | if (m_disp) { | 148 | if (m_disp) { |
149 | m_disp->setAutoRotate(how); | 149 | m_disp->setAutoRotate(how); |
150 | } | 150 | } |
151 | } | 151 | } |
152 | 152 | ||
153 | void PMainWindow::slotScaleToggled(bool how) | 153 | void PMainWindow::slotScaleToggled(bool how) |
154 | { | 154 | { |
155 | autoScale = !how; | 155 | autoScale = !how; |
156 | if (m_disp) { | 156 | if (m_disp) { |
157 | m_disp->setAutoScale(autoScale); | 157 | m_disp->setAutoScale(autoScale); |
158 | } | 158 | } |
159 | if (!autoScale && autoRotate) { | 159 | if (!autoScale && autoRotate) { |
160 | rotateButton->setOn(false); | 160 | rotateButton->setOn(false); |
161 | } | 161 | } |
162 | rotateButton->setEnabled(!how); | 162 | rotateButton->setEnabled(!how); |
163 | } | 163 | } |
164 | 164 | ||
165 | void PMainWindow::slotConfig() { | 165 | void PMainWindow::slotConfig() { |
166 | /* | 166 | /* |
167 | * have a tab with the possible views | 167 | * have a tab with the possible views |
168 | * a tab for globals image cache size.. scaled loading | 168 | * a tab for globals image cache size.. scaled loading |
169 | * and one tab for the KeyConfigs | 169 | * and one tab for the KeyConfigs |
170 | */ | 170 | */ |
171 | QDialog dlg(this, 0, true); | 171 | QDialog dlg(this, 0, true); |
172 | dlg.setCaption( tr("Phunk View - Config" ) ); | 172 | dlg.setCaption( tr("Phunk View - Config" ) ); |
173 | 173 | ||
174 | QHBoxLayout *lay = new QHBoxLayout(&dlg); | 174 | QHBoxLayout *lay = new QHBoxLayout(&dlg); |
175 | Opie::Ui::OTabWidget *wid = new Opie::Ui::OTabWidget(&dlg ); | 175 | Opie::Ui::OTabWidget *wid = new Opie::Ui::OTabWidget(&dlg ); |
176 | lay->addWidget( wid ); | 176 | lay->addWidget( wid ); |
177 | ViewMap *vM = viewMap(); | 177 | ViewMap *vM = viewMap(); |
178 | ViewMap::Iterator _it = vM->begin(); | 178 | ViewMap::Iterator _it = vM->begin(); |
179 | QMap<PDirView*, QWidget*> lst; | 179 | QMap<PDirView*, QWidget*> lst; |
180 | 180 | ||
181 | for( ; _it != vM->end(); ++_it ) { | 181 | for( ; _it != vM->end(); ++_it ) { |
182 | PDirView *view = (_it.data())(*m_cfg); | 182 | PDirView *view = (_it.data())(*m_cfg); |
183 | PInterfaceInfo *inf = view->interfaceInfo(); | 183 | PInterfaceInfo *inf = view->interfaceInfo(); |
184 | QWidget *_wid = inf->configWidget( *m_cfg ); | 184 | QWidget *_wid = inf->configWidget( *m_cfg ); |
185 | _wid->reparent(wid, QPoint() ); | 185 | _wid->reparent(wid, QPoint() ); |
186 | lst.insert( view, _wid ); | 186 | lst.insert( view, _wid ); |
187 | wid->addTab( _wid, "fileopen", inf->name() ); | 187 | wid->addTab( _wid, "fileopen", inf->name() ); |
188 | } | 188 | } |
189 | 189 | ||
190 | /* | 190 | /* |
191 | * Add the KeyConfigWidget | 191 | * Add the KeyConfigWidget |
192 | */ | 192 | */ |
193 | Opie::Ui::OKeyConfigWidget* keyWid = new Opie::Ui::OKeyConfigWidget( wid, "key config" ); | 193 | Opie::Ui::OKeyConfigWidget* keyWid = new Opie::Ui::OKeyConfigWidget( wid, "key config" ); |
194 | keyWid->setChangeMode( Opie::Ui::OKeyConfigWidget::Queue ); | 194 | keyWid->setChangeMode( Opie::Ui::OKeyConfigWidget::Queue ); |
195 | keyWid->insert( tr("Browser Keyboard Actions"), m_view->manager() ); | 195 | keyWid->insert( tr("Browser Keyboard Actions"), m_view->manager() ); |
196 | 196 | ||
197 | if ( !m_info ) { | 197 | if ( !m_info ) { |
198 | initInfo(); | 198 | initInfo(); |
199 | } | 199 | } |
200 | keyWid->insert( tr("Imageinfo Keyboard Actions"), m_info->manager() ); | 200 | keyWid->insert( tr("Imageinfo Keyboard Actions"), m_info->manager() ); |
201 | 201 | ||
202 | if ( !m_disp ) { | 202 | if ( !m_disp ) { |
203 | initDisp(); | 203 | initDisp(); |
204 | } | 204 | } |
205 | keyWid->insert( tr("Imageview Keyboard Actions"), m_disp->manager() ); | 205 | keyWid->insert( tr("Imageview Keyboard Actions"), m_disp->manager() ); |
206 | 206 | ||
207 | keyWid->load(); | 207 | keyWid->load(); |
208 | wid->addTab( keyWid, QString::fromLatin1("AppsIcon" ), tr("Keyboard Configuration") ); | 208 | wid->addTab( keyWid, QString::fromLatin1("AppsIcon" ), tr("Keyboard Configuration") ); |
209 | 209 | ||
210 | 210 | ||
211 | bool act = ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ); | 211 | bool act = ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ); |
212 | 212 | ||
213 | /* | 213 | /* |
214 | * clean up | 214 | * clean up |
215 | *apply changes | 215 | *apply changes |
216 | */ | 216 | */ |
217 | 217 | ||
218 | QMap<PDirView*, QWidget*>::Iterator it; | 218 | QMap<PDirView*, QWidget*>::Iterator it; |
219 | for ( it = lst.begin(); it != lst.end(); ++it ) { | 219 | for ( it = lst.begin(); it != lst.end(); ++it ) { |
220 | if ( act ) | 220 | if ( act ) |
221 | it.key()->interfaceInfo()->writeConfig(it.data(), *m_cfg); | 221 | it.key()->interfaceInfo()->writeConfig(it.data(), *m_cfg); |
222 | delete it.key(); | 222 | delete it.key(); |
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
226 | if ( act ) { | 226 | if ( act ) { |
227 | m_view->resetView(); | 227 | m_view->resetView(); |
228 | keyWid->save(); | 228 | keyWid->save(); |
229 | m_disp->manager()->save(); | 229 | m_disp->manager()->save(); |
230 | m_info->manager()->save(); | 230 | m_info->manager()->save(); |
231 | m_view->manager()->save(); | 231 | m_view->manager()->save(); |
232 | } | 232 | } |
233 | delete keyWid; | 233 | delete keyWid; |
234 | } | 234 | } |
235 | 235 | ||
236 | /* | 236 | /* |
237 | * create a new image info component | 237 | * create a new image info component |
238 | * and detach the current one | 238 | * and detach the current one |
239 | * we will make the other delete on exit | 239 | * we will make the other delete on exit |
240 | */ | 240 | */ |
241 | template<class T> | 241 | template<class T> |
242 | void PMainWindow::initT( const char* name, T** ptr, int id) { | 242 | void PMainWindow::initT( const char* name, T** ptr, int id) { |
243 | if ( *ptr ) { | 243 | if ( *ptr ) { |
244 | (*ptr)->disconnect(this, SLOT(slotReturn())); | 244 | (*ptr)->disconnect(this, SLOT(slotReturn())); |
245 | (*ptr)->setDestructiveClose(); | 245 | (*ptr)->setDestructiveClose(); |
246 | m_stack->removeWidget( *ptr ); | 246 | m_stack->removeWidget( *ptr ); |
247 | } | 247 | } |
248 | *ptr = new T(m_cfg, m_stack, name ); | 248 | *ptr = new T(m_cfg, m_stack, name ); |
249 | m_stack->addWidget( *ptr, id ); | 249 | m_stack->addWidget( *ptr, id ); |
250 | 250 | ||
251 | connect(*ptr, SIGNAL(sig_return()), | 251 | connect(*ptr, SIGNAL(sig_return()), |
252 | this,SLOT(slotReturn())); | 252 | this,SLOT(slotReturn())); |
253 | 253 | ||
254 | } | 254 | } |
255 | void PMainWindow::initInfo() { | 255 | void PMainWindow::initInfo() { |
256 | initT<imageinfo>( "Image Info", &m_info, ImageInfo ); | 256 | initT<imageinfo>( "Image Info", &m_info, ImageInfo ); |
257 | connect(m_info,SIGNAL(dispImage(const QString&)),this,SLOT(slotDisplay(const QString&))); | 257 | connect(m_info,SIGNAL(dispImage(const QString&)),this,SLOT(slotDisplay(const QString&))); |
258 | } | 258 | } |
259 | void PMainWindow::initDisp() { | 259 | void PMainWindow::initDisp() { |
260 | initT<ImageView>( "Image ScrollView", &m_disp, ImageDisplay ); | 260 | initT<ImageView>( "Image ScrollView", &m_disp, ImageDisplay ); |
261 | if (m_disp) { | 261 | if (m_disp) { |
262 | if (m_stack->mode() != Opie::Ui::OWidgetStack::SmallScreen) { | 262 | if (m_stack->mode() != Opie::Ui::OWidgetStack::SmallScreen) { |
263 | m_disp->setMinimumSize(QApplication::desktop()->size()/2); | 263 | m_disp->setMinimumSize(QApplication::desktop()->size()/2); |
264 | } | 264 | } |
265 | m_disp->setAutoScale(autoScale); | 265 | m_disp->setAutoScale(autoScale); |
266 | m_disp->setAutoRotate(autoRotate); | 266 | m_disp->setAutoRotate(autoRotate); |
267 | m_disp->setShowZoomer(zoomerOn); | 267 | m_disp->setShowZoomer(zoomerOn); |
268 | connect(m_disp,SIGNAL(dispImageInfo(const QString&)),this,SLOT(slotShowInfo(const QString&))); | 268 | connect(m_disp,SIGNAL(dispImageInfo(const QString&)),this,SLOT(slotShowInfo(const QString&))); |
269 | } | 269 | } |
270 | } | 270 | } |
271 | 271 | ||
272 | /** | 272 | /** |
273 | * With big Screen the plan could be to 'detach' the image | 273 | * With big Screen the plan could be to 'detach' the image |
274 | * window if visible and to create a ne wone | 274 | * window if visible and to create a ne wone |
275 | * init* already supports it but I make no use of it for | 275 | * init* already supports it but I make no use of it for |
276 | * now. We set filename and raise | 276 | * now. We set filename and raise |
277 | * | 277 | * |
278 | * ### FIXME and talk to alwin | 278 | * ### FIXME and talk to alwin |
279 | */ | 279 | */ |
280 | void PMainWindow::slotShowInfo( const QString& inf ) { | 280 | void PMainWindow::slotShowInfo( const QString& inf ) { |
281 | if ( !m_info ) { | 281 | if ( !m_info ) { |
282 | initInfo(); | 282 | initInfo(); |
283 | } | 283 | } |
284 | m_info->setPath( inf ); | 284 | m_info->setPath( inf ); |
285 | m_stack->raiseWidget( ImageInfo ); | 285 | m_stack->raiseWidget( ImageInfo ); |
286 | } | 286 | } |
287 | 287 | ||
288 | void PMainWindow::slotDisplay( const QString& inf ) { | 288 | void PMainWindow::slotDisplay( const QString& inf ) { |
289 | if ( !m_disp ) { | 289 | if ( !m_disp ) { |
290 | initDisp(); | 290 | initDisp(); |
291 | } | 291 | } |
292 | m_disp->setImage( inf ); | 292 | m_disp->setImage( inf ); |
293 | m_stack->raiseWidget( ImageDisplay ); | 293 | m_stack->raiseWidget( ImageDisplay ); |
294 | } | 294 | } |
295 | 295 | ||
296 | void PMainWindow::slotReturn() { | 296 | void PMainWindow::slotReturn() { |
297 | raiseIconView(); | 297 | raiseIconView(); |
298 | } | 298 | } |
299 | 299 | ||
300 | 300 | ||
301 | void PMainWindow::closeEvent( QCloseEvent* ev ) { | 301 | void PMainWindow::closeEvent( QCloseEvent* ev ) { |
302 | /* | 302 | /* |
303 | * return from view | 303 | * return from view |
304 | * or properly quit | 304 | * or properly quit |
305 | */ | 305 | */ |
306 | if ( m_stack->visibleWidget() == m_info || | 306 | if ( m_stack->visibleWidget() == m_info || |
307 | m_stack->visibleWidget() == m_disp ) { | 307 | m_stack->visibleWidget() == m_disp ) { |
308 | raiseIconView(); | 308 | raiseIconView(); |
309 | ev->ignore(); | 309 | ev->ignore(); |
310 | return; | 310 | return; |
311 | } | 311 | } |
312 | ev->accept(); | 312 | ev->accept(); |
313 | QTimer::singleShot(0, qApp, SLOT(closeAllWindows())); | 313 | QTimer::singleShot(0, qApp, SLOT(closeAllWindows())); |
314 | } | 314 | } |
315 | 315 | ||
316 | void PMainWindow::raiseIconView() { | 316 | void PMainWindow::raiseIconView() { |
317 | m_stack->raiseWidget( IconView ); | 317 | m_stack->raiseWidget( IconView ); |
318 | } | 318 | } |
319 | 319 | ||
320 | void PMainWindow::setDocument( const QString& showImg ) { | 320 | void PMainWindow::setDocument( const QString& showImg ) { |
321 | QString file = showImg; | 321 | QString file = showImg; |
322 | DocLnk lnk(showImg); | 322 | DocLnk lnk(showImg); |
323 | if (lnk.isValid() ) | 323 | if (lnk.isValid() ) |
324 | file = lnk.file(); | 324 | file = lnk.file(); |
325 | 325 | ||
326 | slotDisplay( file ); | 326 | slotDisplay( file ); |
327 | } | 327 | } |
diff --git a/noncore/graphics/opie-eye/gui/mainwindow.h b/noncore/graphics/opie-eye/gui/mainwindow.h index e9b16d0..adb5dc2 100644 --- a/noncore/graphics/opie-eye/gui/mainwindow.h +++ b/noncore/graphics/opie-eye/gui/mainwindow.h | |||
@@ -1,72 +1,73 @@ | |||
1 | /* | 1 | /* |
2 | * GPLv2 zecke@handhelds.org | 2 | * GPLv2 zecke@handhelds.org |
3 | * No WArranty... | 3 | * No WArranty... |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #ifndef PHUNK_MAIN_WINDOW_H | 6 | #ifndef PHUNK_MAIN_WINDOW_H |
7 | #define PHUNK_MAIN_WINDOW_H | 7 | #define PHUNK_MAIN_WINDOW_H |
8 | 8 | ||
9 | #include <opie2/oconfig.h> | 9 | #include <opie2/oconfig.h> |
10 | 10 | ||
11 | #include <qmainwindow.h> | 11 | #include <qmainwindow.h> |
12 | 12 | ||
13 | 13 | ||
14 | 14 | ||
15 | namespace Opie { | 15 | namespace Opie { |
16 | namespace Ui{ | 16 | namespace Ui{ |
17 | class OWidgetStack; | 17 | class OWidgetStack; |
18 | } | 18 | } |
19 | namespace Core{ | 19 | namespace Core{ |
20 | class OKeyConfigManager; | 20 | class OKeyConfigManager; |
21 | } | 21 | } |
22 | } | 22 | } |
23 | 23 | ||
24 | class ImageView; | ||
24 | class PIconView; | 25 | class PIconView; |
25 | class imageinfo; | 26 | class imageinfo; |
26 | class ImageView; | 27 | |
27 | class PMainWindow : public QMainWindow { | 28 | class PMainWindow : public QMainWindow { |
28 | Q_OBJECT | 29 | Q_OBJECT |
29 | enum Views { IconView, ImageInfo, ImageDisplay }; | 30 | enum Views { IconView, ImageInfo, ImageDisplay }; |
30 | public: | 31 | public: |
31 | static QString appName() { return QString::fromLatin1("opie-eye" ); } | 32 | static QString appName() { return QString::fromLatin1("opie-eye" ); } |
32 | PMainWindow(QWidget*, const char*, WFlags ); | 33 | PMainWindow(QWidget*, const char*, WFlags ); |
33 | ~PMainWindow(); | 34 | ~PMainWindow(); |
34 | 35 | ||
35 | signals: | 36 | signals: |
36 | void configChanged(); | 37 | void configChanged(); |
37 | 38 | ||
38 | public slots: | 39 | public slots: |
39 | void slotShowInfo( const QString& inf ); | 40 | void slotShowInfo( const QString& inf ); |
40 | void slotDisplay( const QString& inf ); | 41 | void slotDisplay( const QString& inf ); |
41 | void slotReturn(); | 42 | void slotReturn(); |
42 | void slotRotateToggled(bool); | 43 | void slotRotateToggled(bool); |
43 | void slotScaleToggled(bool); | 44 | void slotScaleToggled(bool); |
44 | void slotZoomerToggled(bool); | 45 | void slotZoomerToggled(bool); |
45 | void setDocument( const QString& ); | 46 | void setDocument( const QString& ); |
46 | 47 | ||
47 | protected: | 48 | protected: |
48 | void raiseIconView(); | 49 | void raiseIconView(); |
49 | void closeEvent( QCloseEvent* ); | 50 | void closeEvent( QCloseEvent* ); |
50 | 51 | ||
51 | private: | 52 | private: |
52 | template<class T> void initT( const char* name, T**, int ); | 53 | template<class T> void initT( const char* name, T**, int ); |
53 | void initInfo(); | 54 | void initInfo(); |
54 | void initDisp(); | 55 | void initDisp(); |
55 | 56 | ||
56 | private: | 57 | private: |
57 | Opie::Core::OConfig *m_cfg; | 58 | Opie::Core::OConfig *m_cfg; |
58 | Opie::Ui::OWidgetStack *m_stack; | 59 | Opie::Ui::OWidgetStack *m_stack; |
59 | PIconView* m_view; | 60 | PIconView* m_view; |
60 | imageinfo *m_info; | 61 | imageinfo *m_info; |
61 | ImageView *m_disp; | 62 | ImageView *m_disp; |
62 | bool autoRotate; | 63 | bool autoRotate; |
63 | bool autoScale; | 64 | bool autoScale; |
64 | bool zoomerOn; | 65 | bool zoomerOn; |
65 | QToolButton*rotateButton; | 66 | QToolButton*rotateButton; |
66 | 67 | ||
67 | 68 | ||
68 | private slots: | 69 | private slots: |
69 | void slotConfig(); | 70 | void slotConfig(); |
70 | }; | 71 | }; |
71 | 72 | ||
72 | #endif | 73 | #endif |
diff --git a/noncore/graphics/opie-eye/lib/oimagezoomer.cpp b/noncore/graphics/opie-eye/lib/oimagezoomer.cpp index 00b93e2..d1eec67 100644 --- a/noncore/graphics/opie-eye/lib/oimagezoomer.cpp +++ b/noncore/graphics/opie-eye/lib/oimagezoomer.cpp | |||
@@ -1,219 +1,233 @@ | |||
1 | #include "oimagezoomer.h" | 1 | #include "oimagezoomer.h" |
2 | 2 | ||
3 | #include <opie2/odebug.h> | ||
4 | |||
3 | #include <qimage.h> | 5 | #include <qimage.h> |
4 | #include <qpixmap.h> | 6 | #include <qpixmap.h> |
5 | #include <qpainter.h> | 7 | #include <qpainter.h> |
6 | #include <qrect.h> | 8 | #include <qrect.h> |
7 | #include <qpoint.h> | 9 | #include <qpoint.h> |
8 | #include <qsize.h> | 10 | #include <qsize.h> |
9 | 11 | ||
10 | namespace Opie { | 12 | namespace Opie { |
11 | namespace MM { | 13 | namespace MM { |
12 | 14 | ||
13 | /** | 15 | /** |
14 | * \brief The most simple c'tor | 16 | * \brief The most simple c'tor |
15 | * The main c'tor. You still need to set a QPixmap/QIMage, | 17 | * The main c'tor. You still need to set a QPixmap/QIMage, |
16 | * setImageSize,setViewPortSize,setVisiblePoint | 18 | * setImageSize,setViewPortSize,setVisiblePoint |
17 | * | 19 | * |
18 | * @param parent The parent widget | 20 | * @param parent The parent widget |
19 | * @param name A name for this widget | 21 | * @param name A name for this widget |
20 | * @param fl The widget flags | 22 | * @param fl The widget flags |
21 | * | 23 | * |
22 | */ | 24 | */ |
23 | OImageZoomer::OImageZoomer( QWidget* parent, const char* name, WFlags fl ) | 25 | OImageZoomer::OImageZoomer( QWidget* parent, const char* name, WFlags fl ) |
24 | : QFrame( parent, name, fl ) { | 26 | : QFrame( parent, name, fl ) { |
25 | init(); | 27 | init(); |
26 | } | 28 | } |
27 | 29 | ||
28 | 30 | ||
29 | /** | 31 | /** |
30 | * \brief This c'tor takes a QPixmap additional | 32 | * \brief This c'tor takes a QPixmap additional |
31 | * | 33 | * |
32 | * You initially set the QPixmap but you still need to provide | 34 | * You initially set the QPixmap but you still need to provide |
33 | * the additional data to make this widget useful | 35 | * the additional data to make this widget useful |
34 | * | 36 | * |
35 | * @param pix A Pixmap it'll be converted to a QImage later! | 37 | * @param pix A Pixmap it'll be converted to a QImage later! |
36 | * @param par The parent widget | 38 | * @param par The parent widget |
37 | * @param name The name of this widget | 39 | * @param name The name of this widget |
38 | * @param fl The widget flags | 40 | * @param fl The widget flags |
39 | */ | 41 | */ |
40 | OImageZoomer::OImageZoomer( const QPixmap& pix, QWidget* par, const char* name, WFlags fl ) | 42 | OImageZoomer::OImageZoomer( const QPixmap& pix, QWidget* par, const char* name, WFlags fl ) |
41 | : QFrame( par, name, fl ) { | 43 | : QFrame( par, name, fl ) { |
42 | init(); | 44 | init(); |
43 | setImage( pix ); | 45 | setImage( pix ); |
44 | } | 46 | } |
45 | 47 | ||
46 | 48 | ||
47 | /** | 49 | /** |
48 | * \brief This c'tor takes a QImage instead | 50 | * \brief This c'tor takes a QImage instead |
49 | * You just provide a QImage which is saved. It behaves the same as the others. | 51 | * You just provide a QImage which is saved. It behaves the same as the others. |
50 | * | 52 | * |
51 | * @param img A Image which will be used for the zoomer content | 53 | * @param img A Image which will be used for the zoomer content |
52 | * @param par The parent of the widget | 54 | * @param par The parent of the widget |
53 | * @param name The name of the widget | 55 | * @param name The name of the widget |
54 | * @param fl The widgets flags | 56 | * @param fl The widgets flags |
55 | */ | 57 | */ |
56 | OImageZoomer::OImageZoomer( const QImage& img, QWidget* par, const char* name, WFlags fl) | 58 | OImageZoomer::OImageZoomer( const QImage& img, QWidget* par, const char* name, WFlags fl) |
57 | : QFrame( par, name, fl ) { | 59 | : QFrame( par, name, fl ) { |
58 | init(); | 60 | init(); |
59 | setImage( img ); | 61 | setImage( img ); |
60 | } | 62 | } |
61 | 63 | ||
62 | 64 | ||
63 | /** | 65 | /** |
64 | * \brief overloaded c'tor | 66 | * \brief overloaded c'tor |
65 | * | 67 | * |
66 | * This differs only in the arguments it takes | 68 | * This differs only in the arguments it takes |
67 | * | 69 | * |
68 | * | 70 | * |
69 | * @param pSize The size of the Page you show | 71 | * @param pSize The size of the Page you show |
70 | * @param vSize The size of the viewport. The size of the visible part of the widget | 72 | * @param vSize The size of the viewport. The size of the visible part of the widget |
71 | * @param par The parent of the widget | 73 | * @param par The parent of the widget |
72 | * @param name The name | 74 | * @param name The name |
73 | * @param fl The window flags | 75 | * @param fl The window flags |
74 | */ | 76 | */ |
75 | OImageZoomer::OImageZoomer( const QSize& pSize, const QSize& vSize, QWidget* par, | 77 | OImageZoomer::OImageZoomer( const QSize& pSize, const QSize& vSize, QWidget* par, |
76 | const char* name, WFlags fl ) | 78 | const char* name, WFlags fl ) |
77 | : QFrame( par, name, fl ), m_imgSize( pSize ),m_visSize( vSize ) { | 79 | : QFrame( par, name, fl ), m_imgSize( pSize ),m_visSize( vSize ) { |
78 | init(); | 80 | init(); |
79 | } | 81 | } |
80 | 82 | ||
81 | /** | 83 | /** |
82 | * d'tor | 84 | * d'tor |
83 | */ | 85 | */ |
84 | OImageZoomer::~OImageZoomer() { | 86 | OImageZoomer::~OImageZoomer() { |
85 | 87 | ||
86 | } | 88 | } |
87 | 89 | ||
88 | void OImageZoomer::init() { | 90 | void OImageZoomer::init() { |
91 | m_mevent = false; | ||
89 | setFrameStyle( Panel | Sunken ); | 92 | setFrameStyle( Panel | Sunken ); |
90 | } | 93 | } |
91 | 94 | ||
92 | 95 | ||
93 | /** | 96 | /** |
94 | * \brief set the page/image size | 97 | * \brief set the page/image size |
95 | * Tell us the QSize of the Data you show to the user. We need this | 98 | * Tell us the QSize of the Data you show to the user. We need this |
96 | * to do the calculations | 99 | * to do the calculations |
97 | * | 100 | * |
98 | * @param size The size of the stuff you want to zoom on | 101 | * @param size The size of the stuff you want to zoom on |
99 | */ | 102 | */ |
100 | void OImageZoomer::setImageSize( const QSize& size ) { | 103 | void OImageZoomer::setImageSize( const QSize& size ) { |
101 | m_imgSize = size; | 104 | m_imgSize = size; |
102 | repaint(); | 105 | repaint(); |
103 | } | 106 | } |
104 | 107 | ||
105 | /** | 108 | /** |
106 | * \brief Set the size of the viewport | 109 | * \brief Set the size of the viewport |
107 | * Tell us the QSize of the viewport. The viewport is the part | 110 | * Tell us the QSize of the viewport. The viewport is the part |
108 | * of the widget which is exposed on the screen | 111 | * of the widget which is exposed on the screen |
109 | * | 112 | * |
110 | * @param size Te size of the viewport | 113 | * @param size Te size of the viewport |
111 | * | 114 | * |
112 | * @see QScrollView::viewport() | 115 | * @see QScrollView::viewport() |
113 | */ | 116 | */ |
114 | void OImageZoomer::setViewPortSize( const QSize& size ) { | 117 | void OImageZoomer::setViewPortSize( const QSize& size ) { |
115 | m_visSize = size; | 118 | m_visSize = size; |
116 | repaint(); | 119 | repaint(); |
117 | } | 120 | } |
118 | 121 | ||
119 | /** | 122 | /** |
120 | * \brief the point in the topleft corner which is currently visible | 123 | * \brief the point in the topleft corner which is currently visible |
121 | * Set the visible point. This most of the times relate to QScrollView::contentsX() | 124 | * Set the visible point. This most of the times relate to QScrollView::contentsX() |
122 | * and QScrollView::contentsY() | 125 | * and QScrollView::contentsY() |
123 | * | 126 | * |
124 | * @see setVisiblePoint(int,int) | 127 | * @see setVisiblePoint(int,int) |
125 | */ | 128 | */ |
126 | void OImageZoomer::setVisiblePoint( const QPoint& pt ) { | 129 | void OImageZoomer::setVisiblePoint( const QPoint& pt ) { |
127 | m_visPt = pt; | 130 | m_visPt = pt; |
128 | repaint(); | 131 | repaint(); |
129 | } | 132 | } |
130 | 133 | ||
131 | 134 | ||
132 | /** | 135 | /** |
133 | * Set the Image. The image will be resized on resizeEvent | 136 | * Set the Image. The image will be resized on resizeEvent |
134 | * and it'll set the QPixmap background | 137 | * and it'll set the QPixmap background |
135 | * | 138 | * |
136 | * @param img The image will be stored internally and used as the background | 139 | * @param img The image will be stored internally and used as the background |
137 | */ | 140 | */ |
138 | void OImageZoomer::setImage( const QImage& img) { | 141 | void OImageZoomer::setImage( const QImage& img) { |
139 | m_img = img; | 142 | m_img = img; |
140 | resizeEvent( 0 ); | 143 | resizeEvent( 0 ); |
141 | repaint(); | 144 | repaint(); |
142 | } | 145 | } |
143 | 146 | ||
144 | /** | 147 | /** |
145 | * overloaded function it calls the QImage version | 148 | * overloaded function it calls the QImage version |
146 | */ | 149 | */ |
147 | void OImageZoomer::setImage( const QPixmap& pix) { | 150 | void OImageZoomer::setImage( const QPixmap& pix) { |
148 | setImage( pix.convertToImage() ); | 151 | setImage( pix.convertToImage() ); |
149 | } | 152 | } |
150 | 153 | ||
151 | void OImageZoomer::resizeEvent( QResizeEvent* ev ) { | 154 | void OImageZoomer::resizeEvent( QResizeEvent* ev ) { |
152 | QFrame::resizeEvent( ev ); | 155 | QFrame::resizeEvent( ev ); |
153 | setBackgroundOrigin( QWidget::WidgetOrigin ); | 156 | setBackgroundOrigin( QWidget::WidgetOrigin ); |
154 | // TODO Qt3 use PalettePixmap and use size | 157 | // TODO Qt3 use PalettePixmap and use size |
155 | QPixmap pix; pix.convertFromImage( m_img.smoothScale( size().width(), size().height() ) ); | 158 | QPixmap pix; pix.convertFromImage( m_img.smoothScale( size().width(), size().height() ) ); |
156 | setBackgroundPixmap( pix); | 159 | setBackgroundPixmap( pix); |
157 | } | 160 | } |
158 | 161 | ||
159 | void OImageZoomer::drawContents( QPainter* p ) { | 162 | void OImageZoomer::drawContents( QPainter* p ) { |
160 | /* | 163 | /* |
161 | * if the page size | 164 | * if the page size |
162 | */ | 165 | */ |
163 | if ( m_imgSize.isEmpty() ) | 166 | if ( m_imgSize.isEmpty() ) |
164 | return; | 167 | return; |
165 | 168 | ||
166 | /* | 169 | /* |
167 | * paint a red rect which represents the visible size | 170 | * paint a red rect which represents the visible size |
168 | * | 171 | * |
169 | * We need to recalculate x,y and width and height of the | 172 | * We need to recalculate x,y and width and height of the |
170 | * rect. So image size relates to contentRect | 173 | * rect. So image size relates to contentRect |
171 | * | 174 | * |
172 | */ | 175 | */ |
173 | QRect c( contentsRect() ); | 176 | QRect c( contentsRect() ); |
174 | p->setPen( Qt::red ); | 177 | p->setPen( Qt::red ); |
175 | 178 | ||
176 | /* | 179 | /* |
177 | * the contentRect is set equal to the size of the image | 180 | * the contentRect is set equal to the size of the image |
178 | * Rect/Original = NewRectORWidth/OriginalVisibleStuff and then simply we | 181 | * Rect/Original = NewRectORWidth/OriginalVisibleStuff and then simply we |
179 | * need to add the c.y/x due usage of QFrame | 182 | * need to add the c.y/x due usage of QFrame |
180 | * For x and y we use the visiblePoint | 183 | * For x and y we use the visiblePoint |
181 | * For height and width we use the size of the viewport | 184 | * For height and width we use the size of the viewport |
182 | * if width/height would be bigger than our widget we use this width/height | 185 | * if width/height would be bigger than our widget we use this width/height |
183 | * | 186 | * |
184 | */ | 187 | */ |
185 | int len = m_imgSize.width(); | 188 | int len = m_imgSize.width(); |
186 | int x = (c.width()*m_visPt.x())/len + c.x(); | 189 | int x = (c.width()*m_visPt.x())/len + c.x(); |
187 | int w = (c.width()*m_visSize.width() )/len + c.x(); | 190 | int w = (c.width()*m_visSize.width() )/len + c.x(); |
188 | if ( w > c.width() ) w = c.width(); | 191 | if ( w > c.width() ) w = c.width(); |
189 | 192 | ||
190 | len = m_imgSize.height(); | 193 | len = m_imgSize.height(); |
191 | int y = (c.height()*m_visPt.y() )/len + c.y(); | 194 | int y = (c.height()*m_visPt.y() )/len + c.y(); |
192 | int h = (c.height()*m_visSize.height() )/len + c.y(); | 195 | int h = (c.height()*m_visSize.height() )/len + c.y(); |
193 | if ( h > c.height() ) h = c.height(); | 196 | if ( h > c.height() ) h = c.height(); |
194 | 197 | ||
195 | p->drawRect( x, y, w, h ); | 198 | p->drawRect( x, y, w, h ); |
196 | } | 199 | } |
197 | 200 | ||
198 | void OImageZoomer::mousePressEvent( QMouseEvent* ) { | 201 | void OImageZoomer::mousePressEvent( QMouseEvent*ev) { |
199 | m_mouseX = m_mouseY = -1; | 202 | m_mouseX = m_mouseY = -1; |
203 | m_mevent = true; | ||
204 | } | ||
205 | |||
206 | void OImageZoomer::mouseReleaseEvent( QMouseEvent*ev) { | ||
207 | if (!m_mevent) return; | ||
208 | int mx, my; | ||
209 | mx = ev->x(); | ||
210 | my = ev->y(); | ||
211 | int diffx = (mx) * m_imgSize.width() / width(); | ||
212 | int diffy = (my) * m_imgSize.height() / height(); | ||
213 | emit zoomArea(diffx,diffy); | ||
200 | } | 214 | } |
201 | 215 | ||
202 | void OImageZoomer::mouseMoveEvent( QMouseEvent* ev ) { | 216 | void OImageZoomer::mouseMoveEvent( QMouseEvent* ev ) { |
203 | int mx, my; | 217 | int mx, my; |
204 | mx = ev->x(); | 218 | mx = ev->x(); |
205 | my = ev->y(); | 219 | my = ev->y(); |
206 | 220 | ||
207 | if ( m_mouseX != -1 && m_mouseY != -1 ) { | 221 | if ( m_mouseX != -1 && m_mouseY != -1 ) { |
222 | m_mevent = false; | ||
208 | int diffx = ( mx - m_mouseX ) * m_imgSize.width() / width(); | 223 | int diffx = ( mx - m_mouseX ) * m_imgSize.width() / width(); |
209 | int diffy = ( my - m_mouseY ) * m_imgSize.height() / height(); | 224 | int diffy = ( my - m_mouseY ) * m_imgSize.height() / height(); |
210 | emit zoomAreaRel( diffx, diffy ); | 225 | emit zoomAreaRel( diffx, diffy ); |
211 | emit zoomArea(m_visPt.x()+diffx, m_visPt.y()+diffy ); | ||
212 | } | 226 | } |
213 | m_mouseX = mx; | 227 | m_mouseX = mx; |
214 | m_mouseY = my; | 228 | m_mouseY = my; |
215 | } | 229 | } |
216 | 230 | ||
217 | 231 | ||
218 | } | 232 | } |
219 | } | 233 | } |
diff --git a/noncore/graphics/opie-eye/lib/oimagezoomer.h b/noncore/graphics/opie-eye/lib/oimagezoomer.h index 2516c61..0b356c9 100644 --- a/noncore/graphics/opie-eye/lib/oimagezoomer.h +++ b/noncore/graphics/opie-eye/lib/oimagezoomer.h | |||
@@ -1,134 +1,141 @@ | |||
1 | #ifndef OPIE_ODP_IMAGE_ZOOMER_H | 1 | #ifndef OPIE_ODP_IMAGE_ZOOMER_H |
2 | #define OPIE_ODP_IMAGE_ZOOMER_H | 2 | #define OPIE_ODP_IMAGE_ZOOMER_H |
3 | 3 | ||
4 | #include <qframe.h> | 4 | #include <qframe.h> |
5 | #include <qimage.h> | 5 | #include <qimage.h> |
6 | 6 | ||
7 | class QPixmap; | 7 | class QPixmap; |
8 | class QRect; | 8 | class QRect; |
9 | class QPoint; | 9 | class QPoint; |
10 | 10 | ||
11 | 11 | ||
12 | namespace Opie { | 12 | namespace Opie { |
13 | namespace MM { | 13 | namespace MM { |
14 | 14 | ||
15 | /** | 15 | /** |
16 | * \brief small class to zoom over a Page | 16 | * \brief small class to zoom over a Page |
17 | * | 17 | * |
18 | * This class represents your page but smaller. | 18 | * This class represents your page but smaller. |
19 | * It can draw a Rect on top of an Image/Pixmap you supply | 19 | * It can draw a Rect on top of an Image/Pixmap you supply |
20 | * and you can allow the user easily zooming/moving | 20 | * and you can allow the user easily zooming/moving |
21 | * over your widget. | 21 | * over your widget. |
22 | * All you need to do is to supply a image/pixmap, the visible size | 22 | * All you need to do is to supply a image/pixmap, the visible size |
23 | * and the original image/pixmap size and the current visible top/left | 23 | * and the original image/pixmap size and the current visible top/left |
24 | * position. | 24 | * position. |
25 | * | 25 | * |
26 | * This Image works perfectly with QScrollView as you can connect | 26 | * This Image works perfectly with QScrollView as you can connect |
27 | * QScrollView::contentsMoving to setVisiblePoint slot and the zoomAreRel | 27 | * QScrollView::contentsMoving to setVisiblePoint slot and the zoomAreRel |
28 | * to the QScrollView::scrollBy slot. Now you would only need to watch | 28 | * to the QScrollView::scrollBy slot. Now you would only need to watch |
29 | * the resize event anf give us the new information about QScrollView::viewport | 29 | * the resize event anf give us the new information about QScrollView::viewport |
30 | * | 30 | * |
31 | * You need to position and set the size of this widget! using setFixedSize() is quite | 31 | * You need to position and set the size of this widget! using setFixedSize() is quite |
32 | * a good idea for this widget | 32 | * a good idea for this widget |
33 | * | 33 | * |
34 | * @see QScrollView | 34 | * @see QScrollView |
35 | * @see QScrollView::viewport() | 35 | * @see QScrollView::viewport() |
36 | * | 36 | * |
37 | * @since 1.2 | 37 | * @since 1.2 |
38 | * | 38 | * |
39 | */ | 39 | */ |
40 | class OImageZoomer : public QFrame { | 40 | class OImageZoomer : public QFrame { |
41 | Q_OBJECT | 41 | Q_OBJECT |
42 | public: | 42 | public: |
43 | OImageZoomer( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 43 | OImageZoomer( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
44 | OImageZoomer( const QPixmap&,QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 44 | OImageZoomer( const QPixmap&,QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
45 | OImageZoomer( const QImage&, QWidget* parent = 0, const char* name= 0, WFlags fl = 0 ); | 45 | OImageZoomer( const QImage&, QWidget* parent = 0, const char* name= 0, WFlags fl = 0 ); |
46 | OImageZoomer( const QSize&, const QSize&, QWidget* par, const char*, WFlags fl ); | 46 | OImageZoomer( const QSize&, const QSize&, QWidget* par, const char*, WFlags fl ); |
47 | ~OImageZoomer(); | 47 | ~OImageZoomer(); |
48 | 48 | ||
49 | public slots: | 49 | public slots: |
50 | void setImageSize( const QSize& ); | 50 | void setImageSize( const QSize& ); |
51 | void setViewPortSize( const QSize& ); | 51 | void setViewPortSize( const QSize& ); |
52 | void setVisiblePoint( const QPoint& ); | 52 | void setVisiblePoint( const QPoint& ); |
53 | void setVisiblePoint( int x, int y ); | 53 | void setVisiblePoint( int x, int y ); |
54 | void setImage( const QImage& ); | 54 | void setImage( const QImage& ); |
55 | void setImage( const QPixmap& ); | 55 | void setImage( const QPixmap& ); |
56 | 56 | ||
57 | signals: | 57 | signals: |
58 | /** | 58 | /** |
59 | * Relative movement in the coordinates of the viewport | 59 | * Relative movement in the coordinates of the viewport |
60 | * This signal can easily be connected to QScrollView::scrollBy. | 60 | * This signal can easily be connected to QScrollView::scrollBy. |
61 | * This signal is emitted from within the mouseMoveEvent of this widget | 61 | * This signal is emitted from within the mouseMoveEvent of this widget |
62 | * | 62 | * |
63 | * | 63 | * |
64 | * @param x The way to move relative on the X-Axis | 64 | * @param x The way to move relative on the X-Axis |
65 | * @param y The way to move relative on the Y-Axis | 65 | * @param y The way to move relative on the Y-Axis |
66 | * | 66 | * |
67 | * @see setVisiblePoint | 67 | * @see setVisiblePoint |
68 | * @see QScrollView::scrollBy | 68 | * @see QScrollView::scrollBy |
69 | */ | 69 | */ |
70 | void zoomAreaRel( int x,int y); | 70 | void zoomAreaRel( int x,int y); |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * Here you get absolute coordinates. | 73 | * Here you get absolute coordinates. |
74 | * This slot will be emitted from within the mouseMoveEvent of this widget. | 74 | * This slot will be emitted from within the mouseReleaseEvent of this widget. |
75 | * if no mouse move where done. | ||
75 | * So you may not delete this widget | 76 | * So you may not delete this widget |
76 | * | 77 | * |
77 | * @param x The absolute X Coordinate to scroll to. | 78 | * @param x The absolute X Coordinate to scroll to. |
78 | * @param y The absolute Y Coordinate to scroll to. | 79 | * @param y The absolute Y Coordinate to scroll to. |
79 | * | 80 | * |
80 | */ | 81 | */ |
81 | void zoomArea( int x,int y); | 82 | void zoomArea( int x,int y); |
82 | 83 | ||
83 | public: | 84 | public: |
84 | /** | 85 | /** |
85 | * make sure to call these if you reimplement | 86 | * make sure to call these if you reimplement |
86 | * @internal | 87 | * @internal |
87 | */ | 88 | */ |
88 | void resizeEvent( QResizeEvent* ); | 89 | void resizeEvent( QResizeEvent* ); |
89 | 90 | ||
90 | protected: | 91 | protected: |
91 | /** | 92 | /** |
92 | * make sure to call these if you reimplement | 93 | * make sure to call these if you reimplement |
93 | * @internal | 94 | * @internal |
94 | */ | 95 | */ |
95 | void drawContents( QPainter* p ); | 96 | void drawContents( QPainter* p ); |
96 | 97 | ||
97 | /** | 98 | /** |
98 | * make sure to call these if you reimplememt | 99 | * make sure to call these if you reimplememt |
99 | * @internal | 100 | * @internal |
100 | */ | 101 | */ |
101 | void mousePressEvent( QMouseEvent* ev ); | 102 | virtual void mousePressEvent( QMouseEvent* ev ); |
102 | /** | 103 | /** |
103 | * make sure to call these if you reimplement | 104 | * make sure to call these if you reimplement |
104 | * @internal | 105 | * @internal |
105 | */ | 106 | */ |
106 | void mouseMoveEvent( QMouseEvent* ev ); | 107 | virtual void mouseMoveEvent( QMouseEvent* ev ); |
108 | /** | ||
109 | * make sure to call these if you reimplement | ||
110 | * @internal | ||
111 | */ | ||
112 | virtual void mouseReleaseEvent( QMouseEvent* ev ); | ||
107 | 113 | ||
108 | private: | 114 | private: |
109 | /** | 115 | /** |
110 | * @internal | 116 | * @internal |
111 | */ | 117 | */ |
112 | void init(); | 118 | void init(); |
113 | QImage m_img; | 119 | QImage m_img; |
114 | QSize m_imgSize, m_visSize; | 120 | QSize m_imgSize, m_visSize; |
115 | QPoint m_visPt; | 121 | QPoint m_visPt; |
116 | int m_mouseX, m_mouseY; | 122 | int m_mouseX, m_mouseY; |
123 | bool m_mevent; | ||
117 | }; | 124 | }; |
118 | 125 | ||
119 | /** | 126 | /** |
120 | * This slot is present for convience. You can connect the | 127 | * This slot is present for convience. You can connect the |
121 | * QScrollView::contentsMoved to this slot and it calls the QPoint | 128 | * QScrollView::contentsMoved to this slot and it calls the QPoint |
122 | * version for you | 129 | * version for you |
123 | * This realtes to QScrollView::contentsX() and QScrollView::contentsY() | 130 | * This realtes to QScrollView::contentsX() and QScrollView::contentsY() |
124 | * | 131 | * |
125 | * @param x The top left x coordinate | 132 | * @param x The top left x coordinate |
126 | * @param y The top left y coorisnate | 133 | * @param y The top left y coorisnate |
127 | */ | 134 | */ |
128 | inline void OImageZoomer::setVisiblePoint( int x, int y ) { | 135 | inline void OImageZoomer::setVisiblePoint( int x, int y ) { |
129 | setVisiblePoint( QPoint( x, y ) ); | 136 | setVisiblePoint( QPoint( x, y ) ); |
130 | } | 137 | } |
131 | 138 | ||
132 | } | 139 | } |
133 | } | 140 | } |
134 | #endif | 141 | #endif |