-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.cpp | 44 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.h | 4 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/mainwindow.cpp | 15 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/mainwindow.h | 2 |
4 files changed, 56 insertions, 9 deletions
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp index 5b12258..2f16d82 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.cpp +++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp | |||
@@ -1,400 +1,426 @@ | |||
1 | #include "imagescrollview.h" | 1 | #include "imagescrollview.h" |
2 | 2 | ||
3 | #include <opie2/odebug.h> | 3 | #include <opie2/odebug.h> |
4 | 4 | ||
5 | using namespace Opie::Core; | 5 | using namespace Opie::Core; |
6 | 6 | ||
7 | #include <qimage.h> | 7 | #include <qimage.h> |
8 | #include <qlayout.h> | 8 | #include <qlayout.h> |
9 | 9 | ||
10 | ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f ) | 10 | ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f ) |
11 | :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true), | 11 | :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true), |
12 | rotate_to_fit(true),first_resize_done(false),m_lastName("") | 12 | rotate_to_fit(true),show_zoomer(true),first_resize_done(false),m_lastName("") |
13 | { | 13 | { |
14 | init(); | 14 | init(); |
15 | } | 15 | } |
16 | 16 | ||
17 | ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 17 | ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) |
18 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), | 18 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), |
19 | rotate_to_fit(rfit),first_resize_done(false),m_lastName("") | 19 | rotate_to_fit(rfit),show_zoomer(true),first_resize_done(false),m_lastName("") |
20 | { | 20 | { |
21 | _original_data.convertDepth(QPixmap::defaultDepth()); | 21 | _original_data.convertDepth(QPixmap::defaultDepth()); |
22 | _original_data.setAlphaBuffer(false); | 22 | _original_data.setAlphaBuffer(false); |
23 | init(); | 23 | init(); |
24 | } | 24 | } |
25 | 25 | ||
26 | ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 26 | ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) |
27 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),scale_to_fit(always_scale), | 27 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),scale_to_fit(always_scale), |
28 | rotate_to_fit(rfit),first_resize_done(false),m_lastName("") | 28 | rotate_to_fit(rfit),show_zoomer(true),first_resize_done(false),m_lastName("") |
29 | { | 29 | { |
30 | init(); | 30 | init(); |
31 | setImage(img); | 31 | setImage(img); |
32 | } | 32 | } |
33 | 33 | ||
34 | void ImageScrollView::setImage(const QImage&img) | 34 | void ImageScrollView::setImage(const QImage&img) |
35 | { | 35 | { |
36 | _image_data = QImage(); | 36 | _image_data = QImage(); |
37 | _original_data=img; | 37 | _original_data=img; |
38 | _original_data.convertDepth(QPixmap::defaultDepth()); | 38 | _original_data.convertDepth(QPixmap::defaultDepth()); |
39 | _original_data.setAlphaBuffer(false); | 39 | _original_data.setAlphaBuffer(false); |
40 | m_lastName = ""; | 40 | m_lastName = ""; |
41 | if (first_resize_done) { | 41 | if (first_resize_done) { |
42 | generateImage(); | 42 | generateImage(); |
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 | ||
46 | void ImageScrollView::setImage( const QString& path ) { | 46 | void ImageScrollView::setImage( const QString& path ) { |
47 | odebug << "load new image " << oendl; | 47 | odebug << "load new image " << oendl; |
48 | if (m_lastName == path) return; | 48 | if (m_lastName == path) return; |
49 | m_lastName = path; | 49 | m_lastName = path; |
50 | _original_data.load(path); | 50 | _original_data.load(path); |
51 | _original_data.convertDepth(QPixmap::defaultDepth()); | 51 | _original_data.convertDepth(QPixmap::defaultDepth()); |
52 | _original_data.setAlphaBuffer(false); | 52 | _original_data.setAlphaBuffer(false); |
53 | _image_data = QImage(); | 53 | _image_data = QImage(); |
54 | if (first_resize_done) { | 54 | if (first_resize_done) { |
55 | generateImage(); | 55 | generateImage(); |
56 | } | 56 | } |
57 | } | 57 | } |
58 | 58 | ||
59 | /* should be called every time the QImage changed it content */ | 59 | /* should be called every time the QImage changed it content */ |
60 | void ImageScrollView::init() | 60 | void ImageScrollView::init() |
61 | { | 61 | { |
62 | odebug << "init " << oendl; | 62 | odebug << "init " << oendl; |
63 | 63 | ||
64 | /* | 64 | /* |
65 | * create the zoomer | 65 | * create the zoomer |
66 | * and connect ther various signals | 66 | * and connect ther various signals |
67 | */ | 67 | */ |
68 | _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" ); | 68 | _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" ); |
69 | connect(_zoomer, SIGNAL( zoomAreaRel(int,int)), | 69 | connect(_zoomer, SIGNAL( zoomAreaRel(int,int)), |
70 | this, SLOT(scrollBy(int,int)) ); | 70 | this, SLOT(scrollBy(int,int)) ); |
71 | connect(this,SIGNAL(contentsMoving(int,int)), | 71 | connect(this,SIGNAL(contentsMoving(int,int)), |
72 | _zoomer, (SLOT(setVisiblePoint(int,int))) ); | 72 | _zoomer, (SLOT(setVisiblePoint(int,int))) ); |
73 | connect(this,SIGNAL(imageSizeChanged(const QSize&)), | 73 | connect(this,SIGNAL(imageSizeChanged(const QSize&)), |
74 | _zoomer, SLOT(setImageSize(const QSize&)) ); | 74 | _zoomer, SLOT(setImageSize(const QSize&)) ); |
75 | connect(this,SIGNAL(viewportSizeChanged(const QSize&)), | 75 | connect(this,SIGNAL(viewportSizeChanged(const QSize&)), |
76 | _zoomer, SLOT(setViewPortSize(const QSize&)) ); | 76 | _zoomer, SLOT(setViewPortSize(const QSize&)) ); |
77 | 77 | ||
78 | viewport()->setBackgroundColor(white); | 78 | viewport()->setBackgroundColor(white); |
79 | setFocusPolicy(QWidget::StrongFocus); | 79 | setFocusPolicy(QWidget::StrongFocus); |
80 | if (first_resize_done) { | 80 | if (first_resize_done) { |
81 | last_rot = Rotate0; | 81 | last_rot = Rotate0; |
82 | generateImage(); | 82 | generateImage(); |
83 | odebug << "reinit display " << oendl; | ||
84 | } else if (_original_data.size().isValid()) { | 83 | } else if (_original_data.size().isValid()) { |
84 | if (image_fit_into(_original_data.size()) || !show_zoomer) _zoomer->hide(); | ||
85 | resizeContents(_original_data.width(),_original_data.height()); | 85 | resizeContents(_original_data.width(),_original_data.height()); |
86 | } | 86 | } |
87 | } | 87 | } |
88 | 88 | ||
89 | void ImageScrollView::setAutoRotate(bool how) | 89 | void ImageScrollView::setAutoRotate(bool how) |
90 | { | 90 | { |
91 | /* to avoid double repaints */ | 91 | /* to avoid double repaints */ |
92 | if (rotate_to_fit != how) { | 92 | if (rotate_to_fit != how) { |
93 | rotate_to_fit = how; | 93 | rotate_to_fit = how; |
94 | _image_data = QImage(); | 94 | _image_data = QImage(); |
95 | generateImage(); | 95 | generateImage(); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
99 | void ImageScrollView::setAutoScale(bool how) | 99 | void ImageScrollView::setAutoScale(bool how) |
100 | { | 100 | { |
101 | scale_to_fit = how; | 101 | scale_to_fit = how; |
102 | if (!how) { | 102 | if (!how) { |
103 | rotate_to_fit = false; | 103 | rotate_to_fit = false; |
104 | } | 104 | } |
105 | _image_data = QImage(); | 105 | _image_data = QImage(); |
106 | generateImage(); | 106 | generateImage(); |
107 | } | 107 | } |
108 | 108 | ||
109 | ImageScrollView::~ImageScrollView() | 109 | ImageScrollView::~ImageScrollView() |
110 | { | 110 | { |
111 | } | 111 | } |
112 | 112 | ||
113 | void ImageScrollView::rescaleImage(int w, int h) | 113 | void ImageScrollView::rescaleImage(int w, int h) |
114 | { | 114 | { |
115 | if (_image_data.width()==w && _image_data.height()==h) { | 115 | if (_image_data.width()==w && _image_data.height()==h) { |
116 | return; | 116 | return; |
117 | } | 117 | } |
118 | double hs = (double)h / (double)_image_data.height() ; | 118 | double hs = (double)h / (double)_image_data.height() ; |
119 | double ws = (double)w / (double)_image_data.width() ; | 119 | double ws = (double)w / (double)_image_data.width() ; |
120 | double scaleFactor = (hs > ws) ? ws : hs; | 120 | double scaleFactor = (hs > ws) ? ws : hs; |
121 | int smoothW = (int)(scaleFactor * _image_data.width()); | 121 | int smoothW = (int)(scaleFactor * _image_data.width()); |
122 | int smoothH = (int)(scaleFactor * _image_data.height()); | 122 | int smoothH = (int)(scaleFactor * _image_data.height()); |
123 | _image_data = _image_data.smoothScale(smoothW,smoothH); | 123 | _image_data = _image_data.smoothScale(smoothW,smoothH); |
124 | } | 124 | } |
125 | 125 | ||
126 | void ImageScrollView::rotate_into_data(Rotation r) | 126 | void ImageScrollView::rotate_into_data(Rotation r) |
127 | { | 127 | { |
128 | /* realy - we must do this that way, 'cause when acting direct on _image_data the app will | 128 | /* realy - we must do this that way, 'cause when acting direct on _image_data the app will |
129 | segfault :( */ | 129 | segfault :( */ |
130 | QImage dest; | 130 | QImage dest; |
131 | int x, y; | 131 | int x, y; |
132 | if ( _original_data.depth() > 8 ) | 132 | if ( _original_data.depth() > 8 ) |
133 | { | 133 | { |
134 | unsigned int *srcData, *destData; | 134 | unsigned int *srcData, *destData; |
135 | switch ( r ) | 135 | switch ( r ) |
136 | { | 136 | { |
137 | case Rotate90: | 137 | case Rotate90: |
138 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 138 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
139 | for ( y=0; y < _original_data.height(); ++y ) | 139 | for ( y=0; y < _original_data.height(); ++y ) |
140 | { | 140 | { |
141 | srcData = (unsigned int *)_original_data.scanLine(y); | 141 | srcData = (unsigned int *)_original_data.scanLine(y); |
142 | for ( x=0; x < _original_data.width(); ++x ) | 142 | for ( x=0; x < _original_data.width(); ++x ) |
143 | { | 143 | { |
144 | destData = (unsigned int *)dest.scanLine(x); | 144 | destData = (unsigned int *)dest.scanLine(x); |
145 | destData[_original_data.height()-y-1] = srcData[x]; | 145 | destData[_original_data.height()-y-1] = srcData[x]; |
146 | } | 146 | } |
147 | } | 147 | } |
148 | break; | 148 | break; |
149 | case Rotate180: | 149 | case Rotate180: |
150 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); | 150 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); |
151 | for ( y=0; y < _original_data.height(); ++y ) | 151 | for ( y=0; y < _original_data.height(); ++y ) |
152 | { | 152 | { |
153 | srcData = (unsigned int *)_original_data.scanLine(y); | 153 | srcData = (unsigned int *)_original_data.scanLine(y); |
154 | destData = (unsigned int *)dest.scanLine(_original_data.height()-y-1); | 154 | destData = (unsigned int *)dest.scanLine(_original_data.height()-y-1); |
155 | for ( x=0; x < _original_data.width(); ++x ) | 155 | for ( x=0; x < _original_data.width(); ++x ) |
156 | destData[_original_data.width()-x-1] = srcData[x]; | 156 | destData[_original_data.width()-x-1] = srcData[x]; |
157 | } | 157 | } |
158 | break; | 158 | break; |
159 | case Rotate270: | 159 | case Rotate270: |
160 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 160 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
161 | for ( y=0; y < _original_data.height(); ++y ) | 161 | for ( y=0; y < _original_data.height(); ++y ) |
162 | { | 162 | { |
163 | srcData = (unsigned int *)_original_data.scanLine(y); | 163 | srcData = (unsigned int *)_original_data.scanLine(y); |
164 | for ( x=0; x < _original_data.width(); ++x ) | 164 | for ( x=0; x < _original_data.width(); ++x ) |
165 | { | 165 | { |
166 | destData = (unsigned int *)dest.scanLine(_original_data.width()-x-1); | 166 | destData = (unsigned int *)dest.scanLine(_original_data.width()-x-1); |
167 | destData[y] = srcData[x]; | 167 | destData[y] = srcData[x]; |
168 | } | 168 | } |
169 | } | 169 | } |
170 | break; | 170 | break; |
171 | default: | 171 | default: |
172 | dest = _original_data; | 172 | dest = _original_data; |
173 | break; | 173 | break; |
174 | } | 174 | } |
175 | } | 175 | } |
176 | else | 176 | else |
177 | { | 177 | { |
178 | unsigned char *srcData, *destData; | 178 | unsigned char *srcData, *destData; |
179 | unsigned int *srcTable, *destTable; | 179 | unsigned int *srcTable, *destTable; |
180 | switch ( r ) | 180 | switch ( r ) |
181 | { | 181 | { |
182 | case Rotate90: | 182 | case Rotate90: |
183 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 183 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
184 | dest.setNumColors(_original_data.numColors()); | 184 | dest.setNumColors(_original_data.numColors()); |
185 | srcTable = (unsigned int *)_original_data.colorTable(); | 185 | srcTable = (unsigned int *)_original_data.colorTable(); |
186 | destTable = (unsigned int *)dest.colorTable(); | 186 | destTable = (unsigned int *)dest.colorTable(); |
187 | for ( x=0; x < _original_data.numColors(); ++x ) | 187 | for ( x=0; x < _original_data.numColors(); ++x ) |
188 | destTable[x] = srcTable[x]; | 188 | destTable[x] = srcTable[x]; |
189 | for ( y=0; y < _original_data.height(); ++y ) | 189 | for ( y=0; y < _original_data.height(); ++y ) |
190 | { | 190 | { |
191 | srcData = (unsigned char *)_original_data.scanLine(y); | 191 | srcData = (unsigned char *)_original_data.scanLine(y); |
192 | for ( x=0; x < _original_data.width(); ++x ) | 192 | for ( x=0; x < _original_data.width(); ++x ) |
193 | { | 193 | { |
194 | destData = (unsigned char *)dest.scanLine(x); | 194 | destData = (unsigned char *)dest.scanLine(x); |
195 | destData[_original_data.height()-y-1] = srcData[x]; | 195 | destData[_original_data.height()-y-1] = srcData[x]; |
196 | } | 196 | } |
197 | } | 197 | } |
198 | break; | 198 | break; |
199 | case Rotate180: | 199 | case Rotate180: |
200 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); | 200 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); |
201 | dest.setNumColors(_original_data.numColors()); | 201 | dest.setNumColors(_original_data.numColors()); |
202 | srcTable = (unsigned int *)_original_data.colorTable(); | 202 | srcTable = (unsigned int *)_original_data.colorTable(); |
203 | destTable = (unsigned int *)dest.colorTable(); | 203 | destTable = (unsigned int *)dest.colorTable(); |
204 | for ( x=0; x < _original_data.numColors(); ++x ) | 204 | for ( x=0; x < _original_data.numColors(); ++x ) |
205 | destTable[x] = srcTable[x]; | 205 | destTable[x] = srcTable[x]; |
206 | for ( y=0; y < _original_data.height(); ++y ) | 206 | for ( y=0; y < _original_data.height(); ++y ) |
207 | { | 207 | { |
208 | srcData = (unsigned char *)_original_data.scanLine(y); | 208 | srcData = (unsigned char *)_original_data.scanLine(y); |
209 | destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1); | 209 | destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1); |
210 | for ( x=0; x < _original_data.width(); ++x ) | 210 | for ( x=0; x < _original_data.width(); ++x ) |
211 | destData[_original_data.width()-x-1] = srcData[x]; | 211 | destData[_original_data.width()-x-1] = srcData[x]; |
212 | } | 212 | } |
213 | break; | 213 | break; |
214 | case Rotate270: | 214 | case Rotate270: |
215 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 215 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
216 | dest.setNumColors(_original_data.numColors()); | 216 | dest.setNumColors(_original_data.numColors()); |
217 | srcTable = (unsigned int *)_original_data.colorTable(); | 217 | srcTable = (unsigned int *)_original_data.colorTable(); |
218 | destTable = (unsigned int *)dest.colorTable(); | 218 | destTable = (unsigned int *)dest.colorTable(); |
219 | for ( x=0; x < _original_data.numColors(); ++x ) | 219 | for ( x=0; x < _original_data.numColors(); ++x ) |
220 | destTable[x] = srcTable[x]; | 220 | destTable[x] = srcTable[x]; |
221 | for ( y=0; y < _original_data.height(); ++y ) | 221 | for ( y=0; y < _original_data.height(); ++y ) |
222 | { | 222 | { |
223 | srcData = (unsigned char *)_original_data.scanLine(y); | 223 | srcData = (unsigned char *)_original_data.scanLine(y); |
224 | for ( x=0; x < _original_data.width(); ++x ) | 224 | for ( x=0; x < _original_data.width(); ++x ) |
225 | { | 225 | { |
226 | destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); | 226 | destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); |
227 | destData[y] = srcData[x]; | 227 | destData[y] = srcData[x]; |
228 | } | 228 | } |
229 | } | 229 | } |
230 | break; | 230 | break; |
231 | default: | 231 | default: |
232 | dest = _original_data; | 232 | dest = _original_data; |
233 | break; | 233 | break; |
234 | } | 234 | } |
235 | 235 | ||
236 | } | 236 | } |
237 | _image_data = dest; | 237 | _image_data = dest; |
238 | } | 238 | } |
239 | 239 | ||
240 | void ImageScrollView::generateImage() | 240 | void ImageScrollView::generateImage() |
241 | { | 241 | { |
242 | Rotation r = Rotate0; | 242 | Rotation r = Rotate0; |
243 | if (width()>height()&&_original_data.width()<_original_data.height() || | 243 | if (width()>height()&&_original_data.width()<_original_data.height() || |
244 | width()<height()&&_original_data.width()>_original_data.height()) { | 244 | width()<height()&&_original_data.width()>_original_data.height()) { |
245 | if (rotate_to_fit) r = Rotate90; | 245 | if (rotate_to_fit) r = Rotate90; |
246 | } | 246 | } |
247 | odebug << " r = " << r << oendl; | 247 | odebug << " r = " << r << oendl; |
248 | if (scale_to_fit) { | 248 | if (scale_to_fit) { |
249 | if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { | 249 | if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { |
250 | odebug << "Rescaling data" << oendl; | 250 | odebug << "Rescaling data" << oendl; |
251 | if (r==Rotate0) { | 251 | if (r==Rotate0) { |
252 | _image_data = _original_data; | 252 | _image_data = _original_data; |
253 | } else { | 253 | } else { |
254 | rotate_into_data(r); | 254 | rotate_into_data(r); |
255 | } | 255 | } |
256 | } | 256 | } |
257 | rescaleImage(width(),height()); | 257 | rescaleImage(width(),height()); |
258 | resizeContents(_image_data.width(),_image_data.height()); | 258 | resizeContents(_image_data.width(),_image_data.height()); |
259 | } else if (!first_resize_done||r!=last_rot||_image_data.width()==0) { | 259 | } else if (!first_resize_done||r!=last_rot||_image_data.width()==0) { |
260 | if (r==Rotate0) { | 260 | if (r==Rotate0) { |
261 | _image_data = _original_data; | 261 | _image_data = _original_data; |
262 | } else { | 262 | } else { |
263 | rotate_into_data(r); | 263 | rotate_into_data(r); |
264 | } | 264 | } |
265 | last_rot = r; | 265 | last_rot = r; |
266 | resizeContents(_image_data.width(),_image_data.height()); | 266 | resizeContents(_image_data.width(),_image_data.height()); |
267 | } | 267 | } |
268 | _pdata.convertFromImage(_image_data); | 268 | _pdata.convertFromImage(_image_data); |
269 | |||
269 | 270 | ||
270 | /* | 271 | /* |
271 | * update the zoomer | 272 | * update the zoomer |
272 | */ | 273 | */ |
274 | check_zoomer(); | ||
273 | emit imageSizeChanged( _image_data.size() ); | 275 | emit imageSizeChanged( _image_data.size() ); |
274 | rescaleImage( 128, 128 ); | 276 | rescaleImage( 128, 128 ); |
277 | /* | ||
278 | * move scrollbar | ||
279 | */ | ||
280 | _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2, | ||
281 | _image_data.width()/2, _image_data.height()/2 ); | ||
282 | |||
275 | _zoomer->setImage( _image_data ); | 283 | _zoomer->setImage( _image_data ); |
276 | |||
277 | /* | 284 | /* |
278 | * invalidate | 285 | * invalidate |
279 | */ | 286 | */ |
280 | _image_data=QImage(); | 287 | _image_data=QImage(); |
281 | } | 288 | } |
282 | 289 | ||
283 | void ImageScrollView::resizeEvent(QResizeEvent * e) | 290 | void ImageScrollView::resizeEvent(QResizeEvent * e) |
284 | { | 291 | { |
285 | odebug << "ImageScrollView resizeEvent" << oendl; | 292 | odebug << "ImageScrollView resizeEvent" << oendl; |
286 | QScrollView::resizeEvent(e); | 293 | QScrollView::resizeEvent(e); |
287 | generateImage(); | 294 | generateImage(); |
288 | first_resize_done = true; | 295 | first_resize_done = true; |
289 | emit viewportSizeChanged( viewport()->size() ); | 296 | emit viewportSizeChanged( viewport()->size() ); |
290 | 297 | ||
291 | /* | ||
292 | * move scrollbar | ||
293 | */ | ||
294 | _zoomer->setGeometry( viewport()->width()-100, viewport()->height()-50, 100, 50 ); | ||
295 | } | 298 | } |
296 | 299 | ||
297 | void ImageScrollView::keyPressEvent(QKeyEvent * e) | 300 | void ImageScrollView::keyPressEvent(QKeyEvent * e) |
298 | { | 301 | { |
299 | if (!e) return; | 302 | if (!e) return; |
300 | int dx = horizontalScrollBar()->lineStep(); | 303 | int dx = horizontalScrollBar()->lineStep(); |
301 | int dy = verticalScrollBar()->lineStep(); | 304 | int dy = verticalScrollBar()->lineStep(); |
302 | if (e->key()==Qt::Key_Right) { | 305 | if (e->key()==Qt::Key_Right) { |
303 | scrollBy(dx,0); | 306 | scrollBy(dx,0); |
304 | e->accept(); | 307 | e->accept(); |
305 | } else if (e->key()==Qt::Key_Left) { | 308 | } else if (e->key()==Qt::Key_Left) { |
306 | scrollBy(0-dx,0); | 309 | scrollBy(0-dx,0); |
307 | e->accept(); | 310 | e->accept(); |
308 | } else if (e->key()==Qt::Key_Up) { | 311 | } else if (e->key()==Qt::Key_Up) { |
309 | scrollBy(0,0-dy); | 312 | scrollBy(0,0-dy); |
310 | e->accept(); | 313 | e->accept(); |
311 | } else if (e->key()==Qt::Key_Down) { | 314 | } else if (e->key()==Qt::Key_Down) { |
312 | scrollBy(0,dy); | 315 | scrollBy(0,dy); |
313 | e->accept(); | 316 | e->accept(); |
314 | } else { | 317 | } else { |
315 | e->ignore(); | 318 | e->ignore(); |
316 | } | 319 | } |
317 | QScrollView::keyPressEvent(e); | 320 | QScrollView::keyPressEvent(e); |
318 | } | 321 | } |
319 | 322 | ||
320 | void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) | 323 | void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) |
321 | { | 324 | { |
322 | int w = clipw; | 325 | int w = clipw; |
323 | int h = cliph; | 326 | int h = cliph; |
324 | int x = clipx; | 327 | int x = clipx; |
325 | int y = clipy; | 328 | int y = clipy; |
326 | bool erase = false; | 329 | bool erase = false; |
327 | 330 | ||
328 | if (!_pdata.size().isValid()) { | 331 | if (!_pdata.size().isValid()) { |
329 | p->fillRect(clipx,clipy,clipw,cliph,white); | 332 | p->fillRect(clipx,clipy,clipw,cliph,white); |
330 | return; | 333 | return; |
331 | } | 334 | } |
332 | if (w>_pdata.width()) { | 335 | if (w>_pdata.width()) { |
333 | w=_pdata.width(); | 336 | w=_pdata.width(); |
334 | x = 0; | 337 | x = 0; |
335 | erase = true; | 338 | erase = true; |
336 | } else if (x+w>_pdata.width()){ | 339 | } else if (x+w>_pdata.width()){ |
337 | x = _pdata.width()-w; | 340 | x = _pdata.width()-w; |
338 | } | 341 | } |
339 | if (h>_pdata.height()) { | 342 | if (h>_pdata.height()) { |
340 | h=_pdata.height(); | 343 | h=_pdata.height(); |
341 | y = 0; | 344 | y = 0; |
342 | erase = true; | 345 | erase = true; |
343 | } else if (y+h>_pdata.height()){ | 346 | } else if (y+h>_pdata.height()){ |
344 | y = _pdata.height()-h; | 347 | y = _pdata.height()-h; |
345 | } | 348 | } |
346 | if (erase||_original_data.hasAlphaBuffer()) { | 349 | if (erase||_original_data.hasAlphaBuffer()) { |
347 | p->fillRect(clipx,clipy,clipw,cliph,white); | 350 | p->fillRect(clipx,clipy,clipw,cliph,white); |
348 | } | 351 | } |
349 | p->drawPixmap(clipx,clipy,_pdata,x,y,w,h); | 352 | p->drawPixmap(clipx,clipy,_pdata,x,y,w,h); |
350 | } | 353 | } |
351 | 354 | ||
352 | /* using the real geometry points and not the translated points is wanted! */ | 355 | /* using the real geometry points and not the translated points is wanted! */ |
353 | void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) | 356 | void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) |
354 | { | 357 | { |
355 | odebug << "Move X and Y " << e->x() << " " << e->y() << oendl; | 358 | odebug << "Move X and Y " << e->x() << " " << e->y() << oendl; |
356 | int mx, my; | 359 | int mx, my; |
357 | mx = e->x(); | 360 | mx = e->x(); |
358 | my = e->y(); | 361 | my = e->y(); |
359 | if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) { | 362 | if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) { |
360 | int diffx = _mouseStartPosX-mx; | 363 | int diffx = _mouseStartPosX-mx; |
361 | int diffy = _mouseStartPosY-my; | 364 | int diffy = _mouseStartPosY-my; |
362 | #if 0 | 365 | #if 0 |
363 | QScrollBar*xbar = horizontalScrollBar(); | 366 | QScrollBar*xbar = horizontalScrollBar(); |
364 | QScrollBar*ybar = verticalScrollBar(); | 367 | QScrollBar*ybar = verticalScrollBar(); |
365 | if (xbar->value()+diffx>xbar->maxValue()) { | 368 | if (xbar->value()+diffx>xbar->maxValue()) { |
366 | diffx = xbar->maxValue()-xbar->value(); | 369 | diffx = xbar->maxValue()-xbar->value(); |
367 | } else if (xbar->value()+diffx<0) { | 370 | } else if (xbar->value()+diffx<0) { |
368 | diffx=0-xbar->value(); | 371 | diffx=0-xbar->value(); |
369 | } | 372 | } |
370 | if (ybar->value()+diffy>ybar->maxValue()) { | 373 | if (ybar->value()+diffy>ybar->maxValue()) { |
371 | diffy = ybar->maxValue()-ybar->value(); | 374 | diffy = ybar->maxValue()-ybar->value(); |
372 | } else if (ybar->value()+diffy<0) { | 375 | } else if (ybar->value()+diffy<0) { |
373 | diffy=0-ybar->value(); | 376 | diffy=0-ybar->value(); |
374 | } | 377 | } |
375 | #endif | 378 | #endif |
376 | scrollBy(diffx,diffy); | 379 | scrollBy(diffx,diffy); |
377 | } | 380 | } |
378 | _mouseStartPosX=mx; | 381 | _mouseStartPosX=mx; |
379 | _mouseStartPosY=my; | 382 | _mouseStartPosY=my; |
380 | } | 383 | } |
381 | 384 | ||
382 | void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e) | 385 | void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e) |
383 | { | 386 | { |
384 | odebug << " X and Y " << e->x() << " " << e->y() << oendl; | 387 | odebug << " X and Y " << e->x() << " " << e->y() << oendl; |
385 | /* this marks the beginning of a possible mouse move. Due internal reasons of QT | 388 | /* this marks the beginning of a possible mouse move. Due internal reasons of QT |
386 | the geometry values here may real differ from that set in MoveEvent (I don't know | 389 | the geometry values here may real differ from that set in MoveEvent (I don't know |
387 | why). For getting them in real context, we use the first move-event to set the start | 390 | why). For getting them in real context, we use the first move-event to set the start |
388 | position ;) | 391 | position ;) |
389 | */ | 392 | */ |
390 | _mouseStartPosX = -1; | 393 | _mouseStartPosX = -1; |
391 | _mouseStartPosY = -1; | 394 | _mouseStartPosY = -1; |
392 | } | 395 | } |
393 | 396 | ||
394 | void ImageScrollView::setDestructiveClose() { | 397 | void ImageScrollView::setDestructiveClose() { |
395 | WFlags fl = getWFlags(); | 398 | WFlags fl = getWFlags(); |
396 | /* clear it just in case */ | 399 | /* clear it just in case */ |
397 | fl &= ~WDestructiveClose; | 400 | fl &= ~WDestructiveClose; |
398 | fl |= WDestructiveClose; | 401 | fl |= WDestructiveClose; |
399 | setWFlags( fl ); | 402 | setWFlags( fl ); |
400 | } | 403 | } |
404 | |||
405 | bool ImageScrollView::image_fit_into(const QSize&s ) | ||
406 | { | ||
407 | if (s.width()>width()||s.height()>height()) { | ||
408 | return false; | ||
409 | } | ||
410 | return true; | ||
411 | } | ||
412 | |||
413 | void ImageScrollView::setShowZoomer(bool how) | ||
414 | { | ||
415 | show_zoomer = how; | ||
416 | check_zoomer(); | ||
417 | } | ||
418 | |||
419 | void ImageScrollView::check_zoomer() | ||
420 | { | ||
421 | if ( (!show_zoomer||image_fit_into(_pdata.size()) ) && _zoomer->isVisible()) { | ||
422 | _zoomer->hide(); | ||
423 | } else if ( show_zoomer && !image_fit_into(_pdata.size()) && _zoomer->isHidden()){ | ||
424 | _zoomer->show(); | ||
425 | } | ||
426 | } | ||
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h index 1b25103..e209dfb 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.h +++ b/noncore/graphics/opie-eye/gui/imagescrollview.h | |||
@@ -1,71 +1,75 @@ | |||
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> | 4 | #include <lib/oimagezoomer.h> |
5 | 5 | ||
6 | #include <qscrollview.h> | 6 | #include <qscrollview.h> |
7 | #include <qimage.h> | 7 | #include <qimage.h> |
8 | #include <qpixmap.h> | 8 | #include <qpixmap.h> |
9 | #include <qstring.h> | 9 | #include <qstring.h> |
10 | #include <qdialog.h> | 10 | #include <qdialog.h> |
11 | 11 | ||
12 | 12 | ||
13 | 13 | ||
14 | class QPainter; | 14 | class QPainter; |
15 | 15 | ||
16 | class ImageScrollView:public QScrollView | 16 | class ImageScrollView:public QScrollView |
17 | { | 17 | { |
18 | Q_OBJECT | 18 | Q_OBJECT |
19 | public: | 19 | public: |
20 | ImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 ); | 20 | ImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 ); |
21 | ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); | 21 | ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); |
22 | ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); | 22 | ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); |
23 | virtual ~ImageScrollView(); | 23 | virtual ~ImageScrollView(); |
24 | 24 | ||
25 | virtual void setImage(const QImage&); | 25 | virtual void setImage(const QImage&); |
26 | virtual void setImage( const QString& path ); | 26 | virtual void setImage( const QString& path ); |
27 | virtual void setDestructiveClose(); | 27 | virtual void setDestructiveClose(); |
28 | 28 | ||
29 | virtual void setAutoRotate(bool); | 29 | virtual void setAutoRotate(bool); |
30 | virtual void setAutoScale(bool); | 30 | virtual void setAutoScale(bool); |
31 | virtual void setShowZoomer(bool); | ||
31 | 32 | ||
32 | enum Rotation { | 33 | enum Rotation { |
33 | Rotate0, | 34 | Rotate0, |
34 | Rotate90, | 35 | Rotate90, |
35 | Rotate180, | 36 | Rotate180, |
36 | Rotate270 | 37 | Rotate270 |
37 | }; | 38 | }; |
38 | 39 | ||
39 | signals: | 40 | signals: |
40 | void sig_return(); | 41 | void sig_return(); |
41 | void imageSizeChanged( const QSize& ); | 42 | void imageSizeChanged( const QSize& ); |
42 | void viewportSizeChanged( const QSize& ); | 43 | void viewportSizeChanged( const QSize& ); |
43 | 44 | ||
44 | protected: | 45 | protected: |
45 | virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); | 46 | virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); |
46 | void init(); | 47 | void init(); |
47 | 48 | ||
48 | Opie::MM::OImageZoomer *_zoomer; | 49 | Opie::MM::OImageZoomer *_zoomer; |
49 | QImage _image_data; | 50 | QImage _image_data; |
50 | QImage _original_data; | 51 | QImage _original_data; |
51 | QPixmap _pdata; | 52 | QPixmap _pdata; |
52 | 53 | ||
53 | int _mouseStartPosX,_mouseStartPosY; | 54 | int _mouseStartPosX,_mouseStartPosY; |
54 | 55 | ||
55 | bool scale_to_fit; | 56 | bool scale_to_fit; |
56 | bool rotate_to_fit; | 57 | bool rotate_to_fit; |
58 | bool show_zoomer; | ||
57 | bool first_resize_done; | 59 | bool first_resize_done; |
58 | Rotation last_rot; | 60 | Rotation last_rot; |
59 | QString m_lastName; | 61 | QString m_lastName; |
60 | virtual void rescaleImage(int w, int h); | 62 | virtual void rescaleImage(int w, int h); |
61 | 63 | ||
62 | virtual void rotate_into_data(Rotation r); | 64 | virtual void rotate_into_data(Rotation r); |
63 | virtual void generateImage(); | 65 | virtual void generateImage(); |
66 | bool image_fit_into(const QSize&s); | ||
67 | void check_zoomer(); | ||
64 | 68 | ||
65 | protected slots: | 69 | protected slots: |
66 | virtual void viewportMouseMoveEvent(QMouseEvent* e); | 70 | virtual void viewportMouseMoveEvent(QMouseEvent* e); |
67 | virtual void contentsMousePressEvent ( QMouseEvent * e); | 71 | virtual void contentsMousePressEvent ( QMouseEvent * e); |
68 | virtual void resizeEvent(QResizeEvent * e); | 72 | virtual void resizeEvent(QResizeEvent * e); |
69 | virtual void keyPressEvent(QKeyEvent * e); | 73 | virtual void keyPressEvent(QKeyEvent * e); |
70 | }; | 74 | }; |
71 | #endif | 75 | #endif |
diff --git a/noncore/graphics/opie-eye/gui/mainwindow.cpp b/noncore/graphics/opie-eye/gui/mainwindow.cpp index 3650493..ef23f79 100644 --- a/noncore/graphics/opie-eye/gui/mainwindow.cpp +++ b/noncore/graphics/opie-eye/gui/mainwindow.cpp | |||
@@ -1,293 +1,308 @@ | |||
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 | 6 | ||
7 | #include "iconview.h" | 7 | #include "iconview.h" |
8 | #include "filesystem.h" | 8 | #include "filesystem.h" |
9 | #include "imageinfoui.h" | 9 | #include "imageinfoui.h" |
10 | #include "imageview.h" | 10 | #include "imageview.h" |
11 | 11 | ||
12 | #include <iface/ifaceinfo.h> | 12 | #include <iface/ifaceinfo.h> |
13 | #include <iface/dirview.h> | 13 | #include <iface/dirview.h> |
14 | 14 | ||
15 | #include <opie2/odebug.h> | 15 | #include <opie2/odebug.h> |
16 | #include <opie2/owidgetstack.h> | 16 | #include <opie2/owidgetstack.h> |
17 | #include <opie2/oapplicationfactory.h> | 17 | #include <opie2/oapplicationfactory.h> |
18 | #include <opie2/otabwidget.h> | 18 | #include <opie2/otabwidget.h> |
19 | #include <opie2/okeyconfigwidget.h> | 19 | #include <opie2/okeyconfigwidget.h> |
20 | 20 | ||
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | #include <qpe/ir.h> | 23 | #include <qpe/ir.h> |
24 | #include <qpe/applnk.h> | 24 | #include <qpe/applnk.h> |
25 | 25 | ||
26 | #include <qtoolbar.h> | 26 | #include <qtoolbar.h> |
27 | #include <qtoolbutton.h> | 27 | #include <qtoolbutton.h> |
28 | #include <qlayout.h> | 28 | #include <qlayout.h> |
29 | #include <qdialog.h> | 29 | #include <qdialog.h> |
30 | #include <qmap.h> | 30 | #include <qmap.h> |
31 | #include <qtimer.h> | 31 | #include <qtimer.h> |
32 | 32 | ||
33 | 33 | ||
34 | 34 | ||
35 | 35 | ||
36 | OPIE_EXPORT_APP_V2( Opie::Core::OApplicationFactory<PMainWindow>,"Opie Eye" ) | 36 | OPIE_EXPORT_APP_V2( Opie::Core::OApplicationFactory<PMainWindow>,"Opie Eye" ) |
37 | 37 | ||
38 | PMainWindow::PMainWindow(QWidget* wid, const char* name, WFlags style) | 38 | PMainWindow::PMainWindow(QWidget* wid, const char* name, WFlags style) |
39 | : QMainWindow( wid, name, style ), m_info( 0 ), m_disp( 0 ) | 39 | : QMainWindow( wid, name, style ), m_info( 0 ), m_disp( 0 ) |
40 | { | 40 | { |
41 | setCaption( QObject::tr("Opie Eye Caramba" ) ); | 41 | setCaption( QObject::tr("Opie Eye Caramba" ) ); |
42 | m_cfg = new Opie::Core::OConfig("phunkview"); | 42 | m_cfg = new Opie::Core::OConfig("phunkview"); |
43 | m_cfg->setGroup("Zecke_view" ); | 43 | m_cfg->setGroup("Zecke_view" ); |
44 | // qDebug( "Process-wide OApplication object @ %0x", oApp ); | 44 | // qDebug( "Process-wide OApplication object @ %0x", oApp ); |
45 | /* | 45 | /* |
46 | * Initialize ToolBar and IconView | 46 | * Initialize ToolBar and IconView |
47 | * And Connect Them | 47 | * And Connect Them |
48 | */ | 48 | */ |
49 | QToolBar *bar = new QToolBar( this ); | 49 | QToolBar *bar = new QToolBar( this ); |
50 | bar->setHorizontalStretchable( true ); | 50 | bar->setHorizontalStretchable( true ); |
51 | setToolBarsMovable( false ); | 51 | setToolBarsMovable( false ); |
52 | 52 | ||
53 | m_stack = new Opie::Ui::OWidgetStack( this ); | 53 | m_stack = new Opie::Ui::OWidgetStack( this ); |
54 | setCentralWidget( m_stack ); | 54 | setCentralWidget( m_stack ); |
55 | 55 | ||
56 | m_view = new PIconView( m_stack, m_cfg ); | 56 | m_view = new PIconView( m_stack, m_cfg ); |
57 | m_stack->addWidget( m_view, IconView ); | 57 | m_stack->addWidget( m_view, IconView ); |
58 | m_stack->raiseWidget( IconView ); | 58 | m_stack->raiseWidget( IconView ); |
59 | connect(m_view, SIGNAL(sig_display(const QString&)), | 59 | connect(m_view, SIGNAL(sig_display(const QString&)), |
60 | this, SLOT(slotDisplay(const QString&))); | 60 | this, SLOT(slotDisplay(const QString&))); |
61 | connect(m_view, SIGNAL(sig_showInfo(const QString&)), | 61 | connect(m_view, SIGNAL(sig_showInfo(const QString&)), |
62 | this, SLOT(slotShowInfo(const QString&)) ); | 62 | this, SLOT(slotShowInfo(const QString&)) ); |
63 | 63 | ||
64 | QToolButton *btn = new QToolButton( bar ); | 64 | QToolButton *btn = new QToolButton( bar ); |
65 | btn->setIconSet( Resource::loadIconSet( "up" ) ); | 65 | btn->setIconSet( Resource::loadIconSet( "up" ) ); |
66 | connect( btn, SIGNAL(clicked()), | 66 | connect( btn, SIGNAL(clicked()), |
67 | m_view, SLOT(slotDirUp()) ); | 67 | m_view, SLOT(slotDirUp()) ); |
68 | 68 | ||
69 | btn = new PFileSystem( bar ); | 69 | btn = new PFileSystem( bar ); |
70 | connect( btn, SIGNAL( changeDir( const QString& ) ), | 70 | connect( btn, SIGNAL( changeDir( const QString& ) ), |
71 | m_view, SLOT(slotChangeDir( const QString& ) ) ); | 71 | m_view, SLOT(slotChangeDir( const QString& ) ) ); |
72 | 72 | ||
73 | btn = new QToolButton( bar ); | 73 | btn = new QToolButton( bar ); |
74 | btn->setIconSet( Resource::loadIconSet( "edit" ) ); | 74 | btn->setIconSet( Resource::loadIconSet( "edit" ) ); |
75 | connect( btn, SIGNAL(clicked()), | 75 | connect( btn, SIGNAL(clicked()), |
76 | m_view, SLOT(slotRename()) ); | 76 | m_view, SLOT(slotRename()) ); |
77 | 77 | ||
78 | if ( Ir::supported() ) { | 78 | if ( Ir::supported() ) { |
79 | btn = new QToolButton( bar ); | 79 | btn = new QToolButton( bar ); |
80 | btn->setIconSet( Resource::loadIconSet( "beam" ) ); | 80 | btn->setIconSet( Resource::loadIconSet( "beam" ) ); |
81 | connect( btn, SIGNAL(clicked()), | 81 | connect( btn, SIGNAL(clicked()), |
82 | m_view, SLOT(slotBeam()) ); | 82 | m_view, SLOT(slotBeam()) ); |
83 | } | 83 | } |
84 | 84 | ||
85 | btn = new QToolButton( bar ); | 85 | btn = new QToolButton( bar ); |
86 | btn->setIconSet( Resource::loadIconSet( "trash" ) ); | 86 | btn->setIconSet( Resource::loadIconSet( "trash" ) ); |
87 | connect( btn, SIGNAL(clicked() ), | 87 | connect( btn, SIGNAL(clicked() ), |
88 | m_view, SLOT(slotTrash() ) ); | 88 | m_view, SLOT(slotTrash() ) ); |
89 | 89 | ||
90 | btn = new QToolButton( bar ); | 90 | btn = new QToolButton( bar ); |
91 | btn->setIconSet( Resource::loadIconSet( "SettingsIcon" ) ); | 91 | btn->setIconSet( Resource::loadIconSet( "SettingsIcon" ) ); |
92 | connect( btn, SIGNAL(clicked() ), | 92 | connect( btn, SIGNAL(clicked() ), |
93 | this, SLOT(slotConfig() ) ); | 93 | this, SLOT(slotConfig() ) ); |
94 | 94 | ||
95 | rotateButton = new QToolButton(bar); | 95 | rotateButton = new QToolButton(bar); |
96 | rotateButton->setIconSet( Resource::loadIconSet( "rotate" ) ); | 96 | rotateButton->setIconSet( Resource::loadIconSet( "rotate" ) ); |
97 | rotateButton->setToggleButton(true); | 97 | rotateButton->setToggleButton(true); |
98 | rotateButton->setOn(true); | 98 | rotateButton->setOn(true); |
99 | connect(rotateButton,SIGNAL(toggled(bool)),this,SLOT(slotRotateToggled(bool))); | 99 | connect(rotateButton,SIGNAL(toggled(bool)),this,SLOT(slotRotateToggled(bool))); |
100 | autoRotate = true; | 100 | autoRotate = true; |
101 | 101 | ||
102 | btn = new QToolButton(bar); | 102 | btn = new QToolButton(bar); |
103 | btn->setIconSet( Resource::loadIconSet( "1to1" ) ); | 103 | btn->setIconSet( Resource::loadIconSet( "1to1" ) ); |
104 | btn->setToggleButton(true); | 104 | btn->setToggleButton(true); |
105 | btn->setOn(false); | 105 | btn->setOn(false); |
106 | connect(btn,SIGNAL(toggled(bool)),this,SLOT(slotScaleToggled(bool))); | 106 | connect(btn,SIGNAL(toggled(bool)),this,SLOT(slotScaleToggled(bool))); |
107 | autoScale = true; | 107 | autoScale = true; |
108 | 108 | ||
109 | btn = new QToolButton(bar); | ||
110 | btn->setIconSet( Resource::loadIconSet( "mag" ) ); | ||
111 | btn->setToggleButton(true); | ||
112 | btn->setOn(true); | ||
113 | connect(btn,SIGNAL(toggled(bool)),this,SLOT(slotZoomerToggled(bool))); | ||
114 | zoomerOn = true; | ||
109 | } | 115 | } |
110 | 116 | ||
111 | PMainWindow::~PMainWindow() { | 117 | PMainWindow::~PMainWindow() { |
112 | odebug << "Shutting down" << oendl; | 118 | odebug << "Shutting down" << oendl; |
113 | } | 119 | } |
114 | 120 | ||
121 | void PMainWindow::slotZoomerToggled(bool how) | ||
122 | { | ||
123 | zoomerOn = how; | ||
124 | if (m_disp) { | ||
125 | m_disp->setShowZoomer(zoomerOn); | ||
126 | } | ||
127 | } | ||
128 | |||
115 | void PMainWindow::slotRotateToggled(bool how) | 129 | void PMainWindow::slotRotateToggled(bool how) |
116 | { | 130 | { |
117 | autoRotate = how; | 131 | autoRotate = how; |
118 | if (m_disp) { | 132 | if (m_disp) { |
119 | m_disp->setAutoRotate(how); | 133 | m_disp->setAutoRotate(how); |
120 | } | 134 | } |
121 | } | 135 | } |
122 | 136 | ||
123 | void PMainWindow::slotScaleToggled(bool how) | 137 | void PMainWindow::slotScaleToggled(bool how) |
124 | { | 138 | { |
125 | autoScale = !how; | 139 | autoScale = !how; |
126 | if (m_disp) { | 140 | if (m_disp) { |
127 | m_disp->setAutoScale(autoScale); | 141 | m_disp->setAutoScale(autoScale); |
128 | } | 142 | } |
129 | if (!autoScale && autoRotate) { | 143 | if (!autoScale && autoRotate) { |
130 | rotateButton->setOn(false); | 144 | rotateButton->setOn(false); |
131 | } | 145 | } |
132 | rotateButton->setEnabled(!how); | 146 | rotateButton->setEnabled(!how); |
133 | } | 147 | } |
134 | 148 | ||
135 | void PMainWindow::slotConfig() { | 149 | void PMainWindow::slotConfig() { |
136 | /* | 150 | /* |
137 | * have a tab with the possible views | 151 | * have a tab with the possible views |
138 | * a tab for globals image cache size.. scaled loading | 152 | * a tab for globals image cache size.. scaled loading |
139 | * and one tab for the KeyConfigs | 153 | * and one tab for the KeyConfigs |
140 | */ | 154 | */ |
141 | QDialog dlg(this, 0, true); | 155 | QDialog dlg(this, 0, true); |
142 | dlg.setCaption( tr("Phunk View - Config" ) ); | 156 | dlg.setCaption( tr("Phunk View - Config" ) ); |
143 | 157 | ||
144 | QHBoxLayout *lay = new QHBoxLayout(&dlg); | 158 | QHBoxLayout *lay = new QHBoxLayout(&dlg); |
145 | Opie::Ui::OTabWidget *wid = new Opie::Ui::OTabWidget(&dlg ); | 159 | Opie::Ui::OTabWidget *wid = new Opie::Ui::OTabWidget(&dlg ); |
146 | lay->addWidget( wid ); | 160 | lay->addWidget( wid ); |
147 | ViewMap *vM = viewMap(); | 161 | ViewMap *vM = viewMap(); |
148 | ViewMap::Iterator _it = vM->begin(); | 162 | ViewMap::Iterator _it = vM->begin(); |
149 | QMap<PDirView*, QWidget*> lst; | 163 | QMap<PDirView*, QWidget*> lst; |
150 | 164 | ||
151 | for( ; _it != vM->end(); ++_it ) { | 165 | for( ; _it != vM->end(); ++_it ) { |
152 | PDirView *view = (_it.data())(*m_cfg); | 166 | PDirView *view = (_it.data())(*m_cfg); |
153 | PInterfaceInfo *inf = view->interfaceInfo(); | 167 | PInterfaceInfo *inf = view->interfaceInfo(); |
154 | QWidget *_wid = inf->configWidget( *m_cfg ); | 168 | QWidget *_wid = inf->configWidget( *m_cfg ); |
155 | _wid->reparent(wid, QPoint() ); | 169 | _wid->reparent(wid, QPoint() ); |
156 | lst.insert( view, _wid ); | 170 | lst.insert( view, _wid ); |
157 | wid->addTab( _wid, "fileopen", inf->name() ); | 171 | wid->addTab( _wid, "fileopen", inf->name() ); |
158 | } | 172 | } |
159 | 173 | ||
160 | /* | 174 | /* |
161 | * Add the KeyConfigWidget | 175 | * Add the KeyConfigWidget |
162 | */ | 176 | */ |
163 | Opie::Ui::OKeyConfigWidget* keyWid = new Opie::Ui::OKeyConfigWidget( wid, "key config" ); | 177 | Opie::Ui::OKeyConfigWidget* keyWid = new Opie::Ui::OKeyConfigWidget( wid, "key config" ); |
164 | keyWid->setChangeMode( Opie::Ui::OKeyConfigWidget::Queue ); | 178 | keyWid->setChangeMode( Opie::Ui::OKeyConfigWidget::Queue ); |
165 | keyWid->insert( tr("Browser Keyboard Actions"), m_view->manager() ); | 179 | keyWid->insert( tr("Browser Keyboard Actions"), m_view->manager() ); |
166 | 180 | ||
167 | if ( !m_info ) { | 181 | if ( !m_info ) { |
168 | initInfo(); | 182 | initInfo(); |
169 | } | 183 | } |
170 | keyWid->insert( tr("Imageinfo Keyboard Actions"), m_info->manager() ); | 184 | keyWid->insert( tr("Imageinfo Keyboard Actions"), m_info->manager() ); |
171 | 185 | ||
172 | if ( !m_disp ) { | 186 | if ( !m_disp ) { |
173 | initDisp(); | 187 | initDisp(); |
174 | } | 188 | } |
175 | keyWid->insert( tr("Imageview Keyboard Actions"), m_disp->manager() ); | 189 | keyWid->insert( tr("Imageview Keyboard Actions"), m_disp->manager() ); |
176 | 190 | ||
177 | keyWid->load(); | 191 | keyWid->load(); |
178 | wid->addTab( keyWid, QString::fromLatin1("AppsIcon" ), tr("Keyboard Configuration") ); | 192 | wid->addTab( keyWid, QString::fromLatin1("AppsIcon" ), tr("Keyboard Configuration") ); |
179 | 193 | ||
180 | 194 | ||
181 | bool act = ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ); | 195 | bool act = ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ); |
182 | 196 | ||
183 | /* | 197 | /* |
184 | * clean up | 198 | * clean up |
185 | *apply changes | 199 | *apply changes |
186 | */ | 200 | */ |
187 | 201 | ||
188 | QMap<PDirView*, QWidget*>::Iterator it; | 202 | QMap<PDirView*, QWidget*>::Iterator it; |
189 | for ( it = lst.begin(); it != lst.end(); ++it ) { | 203 | for ( it = lst.begin(); it != lst.end(); ++it ) { |
190 | if ( act ) | 204 | if ( act ) |
191 | it.key()->interfaceInfo()->writeConfig(it.data(), *m_cfg); | 205 | it.key()->interfaceInfo()->writeConfig(it.data(), *m_cfg); |
192 | delete it.key(); | 206 | delete it.key(); |
193 | } | 207 | } |
194 | 208 | ||
195 | 209 | ||
196 | if ( act ) { | 210 | if ( act ) { |
197 | m_view->resetView(); | 211 | m_view->resetView(); |
198 | keyWid->save(); | 212 | keyWid->save(); |
199 | m_disp->manager()->save(); | 213 | m_disp->manager()->save(); |
200 | m_info->manager()->save(); | 214 | m_info->manager()->save(); |
201 | m_view->manager()->save(); | 215 | m_view->manager()->save(); |
202 | } | 216 | } |
203 | delete keyWid; | 217 | delete keyWid; |
204 | } | 218 | } |
205 | 219 | ||
206 | /* | 220 | /* |
207 | * create a new image info component | 221 | * create a new image info component |
208 | * and detach the current one | 222 | * and detach the current one |
209 | * we will make the other delete on exit | 223 | * we will make the other delete on exit |
210 | */ | 224 | */ |
211 | template<class T> | 225 | template<class T> |
212 | void PMainWindow::initT( const char* name, T** ptr, int id) { | 226 | void PMainWindow::initT( const char* name, T** ptr, int id) { |
213 | if ( *ptr ) { | 227 | if ( *ptr ) { |
214 | (*ptr)->disconnect(this, SLOT(slotReturn())); | 228 | (*ptr)->disconnect(this, SLOT(slotReturn())); |
215 | (*ptr)->setDestructiveClose(); | 229 | (*ptr)->setDestructiveClose(); |
216 | m_stack->removeWidget( *ptr ); | 230 | m_stack->removeWidget( *ptr ); |
217 | } | 231 | } |
218 | *ptr = new T(m_cfg, m_stack, name ); | 232 | *ptr = new T(m_cfg, m_stack, name ); |
219 | m_stack->addWidget( *ptr, id ); | 233 | m_stack->addWidget( *ptr, id ); |
220 | 234 | ||
221 | connect(*ptr, SIGNAL(sig_return()), | 235 | connect(*ptr, SIGNAL(sig_return()), |
222 | this,SLOT(slotReturn())); | 236 | this,SLOT(slotReturn())); |
223 | 237 | ||
224 | } | 238 | } |
225 | void PMainWindow::initInfo() { | 239 | void PMainWindow::initInfo() { |
226 | initT<imageinfo>( "Image Info", &m_info, ImageInfo ); | 240 | initT<imageinfo>( "Image Info", &m_info, ImageInfo ); |
227 | connect(m_info,SIGNAL(dispImage(const QString&)),this,SLOT(slotDisplay(const QString&))); | 241 | connect(m_info,SIGNAL(dispImage(const QString&)),this,SLOT(slotDisplay(const QString&))); |
228 | } | 242 | } |
229 | void PMainWindow::initDisp() { | 243 | void PMainWindow::initDisp() { |
230 | initT<ImageView>( "Image ScrollView", &m_disp, ImageDisplay ); | 244 | initT<ImageView>( "Image ScrollView", &m_disp, ImageDisplay ); |
231 | if (m_disp) { | 245 | if (m_disp) { |
232 | m_disp->setAutoScale(autoScale); | 246 | m_disp->setAutoScale(autoScale); |
233 | m_disp->setAutoRotate(autoRotate); | 247 | m_disp->setAutoRotate(autoRotate); |
248 | m_disp->setShowZoomer(zoomerOn); | ||
234 | connect(m_disp,SIGNAL(dispImageInfo(const QString&)),this,SLOT(slotShowInfo(const QString&))); | 249 | connect(m_disp,SIGNAL(dispImageInfo(const QString&)),this,SLOT(slotShowInfo(const QString&))); |
235 | } | 250 | } |
236 | } | 251 | } |
237 | 252 | ||
238 | /** | 253 | /** |
239 | * With big Screen the plan could be to 'detach' the image | 254 | * With big Screen the plan could be to 'detach' the image |
240 | * window if visible and to create a ne wone | 255 | * window if visible and to create a ne wone |
241 | * init* already supports it but I make no use of it for | 256 | * init* already supports it but I make no use of it for |
242 | * now. We set filename and raise | 257 | * now. We set filename and raise |
243 | * | 258 | * |
244 | * ### FIXME and talk to alwin | 259 | * ### FIXME and talk to alwin |
245 | */ | 260 | */ |
246 | void PMainWindow::slotShowInfo( const QString& inf ) { | 261 | void PMainWindow::slotShowInfo( const QString& inf ) { |
247 | if ( !m_info ) { | 262 | if ( !m_info ) { |
248 | initInfo(); | 263 | initInfo(); |
249 | } | 264 | } |
250 | m_info->setPath( inf ); | 265 | m_info->setPath( inf ); |
251 | m_stack->raiseWidget( ImageInfo ); | 266 | m_stack->raiseWidget( ImageInfo ); |
252 | } | 267 | } |
253 | 268 | ||
254 | void PMainWindow::slotDisplay( const QString& inf ) { | 269 | void PMainWindow::slotDisplay( const QString& inf ) { |
255 | if ( !m_disp ) { | 270 | if ( !m_disp ) { |
256 | initDisp(); | 271 | initDisp(); |
257 | } | 272 | } |
258 | m_disp->setImage( inf ); | 273 | m_disp->setImage( inf ); |
259 | m_stack->raiseWidget( ImageDisplay ); | 274 | m_stack->raiseWidget( ImageDisplay ); |
260 | } | 275 | } |
261 | 276 | ||
262 | void PMainWindow::slotReturn() { | 277 | void PMainWindow::slotReturn() { |
263 | raiseIconView(); | 278 | raiseIconView(); |
264 | } | 279 | } |
265 | 280 | ||
266 | 281 | ||
267 | void PMainWindow::closeEvent( QCloseEvent* ev ) { | 282 | void PMainWindow::closeEvent( QCloseEvent* ev ) { |
268 | /* | 283 | /* |
269 | * return from view | 284 | * return from view |
270 | * or properly quit | 285 | * or properly quit |
271 | */ | 286 | */ |
272 | if ( m_stack->visibleWidget() == m_info || | 287 | if ( m_stack->visibleWidget() == m_info || |
273 | m_stack->visibleWidget() == m_disp ) { | 288 | m_stack->visibleWidget() == m_disp ) { |
274 | raiseIconView(); | 289 | raiseIconView(); |
275 | ev->ignore(); | 290 | ev->ignore(); |
276 | return; | 291 | return; |
277 | } | 292 | } |
278 | ev->accept(); | 293 | ev->accept(); |
279 | QTimer::singleShot(0, qApp, SLOT(closeAllWindows())); | 294 | QTimer::singleShot(0, qApp, SLOT(closeAllWindows())); |
280 | } | 295 | } |
281 | 296 | ||
282 | void PMainWindow::raiseIconView() { | 297 | void PMainWindow::raiseIconView() { |
283 | m_stack->raiseWidget( IconView ); | 298 | m_stack->raiseWidget( IconView ); |
284 | } | 299 | } |
285 | 300 | ||
286 | void PMainWindow::setDocument( const QString& showImg ) { | 301 | void PMainWindow::setDocument( const QString& showImg ) { |
287 | QString file = showImg; | 302 | QString file = showImg; |
288 | DocLnk lnk(showImg); | 303 | DocLnk lnk(showImg); |
289 | if (lnk.isValid() ) | 304 | if (lnk.isValid() ) |
290 | file = lnk.file(); | 305 | file = lnk.file(); |
291 | 306 | ||
292 | slotDisplay( file ); | 307 | slotDisplay( file ); |
293 | } | 308 | } |
diff --git a/noncore/graphics/opie-eye/gui/mainwindow.h b/noncore/graphics/opie-eye/gui/mainwindow.h index 59dba30..e9b16d0 100644 --- a/noncore/graphics/opie-eye/gui/mainwindow.h +++ b/noncore/graphics/opie-eye/gui/mainwindow.h | |||
@@ -1,70 +1,72 @@ | |||
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 PIconView; | 24 | class PIconView; |
25 | class imageinfo; | 25 | class imageinfo; |
26 | class ImageView; | 26 | class ImageView; |
27 | class PMainWindow : public QMainWindow { | 27 | class PMainWindow : public QMainWindow { |
28 | Q_OBJECT | 28 | Q_OBJECT |
29 | enum Views { IconView, ImageInfo, ImageDisplay }; | 29 | enum Views { IconView, ImageInfo, ImageDisplay }; |
30 | public: | 30 | public: |
31 | static QString appName() { return QString::fromLatin1("opie-eye" ); } | 31 | static QString appName() { return QString::fromLatin1("opie-eye" ); } |
32 | PMainWindow(QWidget*, const char*, WFlags ); | 32 | PMainWindow(QWidget*, const char*, WFlags ); |
33 | ~PMainWindow(); | 33 | ~PMainWindow(); |
34 | 34 | ||
35 | signals: | 35 | signals: |
36 | void configChanged(); | 36 | void configChanged(); |
37 | 37 | ||
38 | public slots: | 38 | public slots: |
39 | void slotShowInfo( const QString& inf ); | 39 | void slotShowInfo( const QString& inf ); |
40 | void slotDisplay( const QString& inf ); | 40 | void slotDisplay( const QString& inf ); |
41 | void slotReturn(); | 41 | void slotReturn(); |
42 | void slotRotateToggled(bool); | 42 | void slotRotateToggled(bool); |
43 | void slotScaleToggled(bool); | 43 | void slotScaleToggled(bool); |
44 | void slotZoomerToggled(bool); | ||
44 | void setDocument( const QString& ); | 45 | void setDocument( const QString& ); |
45 | 46 | ||
46 | protected: | 47 | protected: |
47 | void raiseIconView(); | 48 | void raiseIconView(); |
48 | void closeEvent( QCloseEvent* ); | 49 | void closeEvent( QCloseEvent* ); |
49 | 50 | ||
50 | private: | 51 | private: |
51 | template<class T> void initT( const char* name, T**, int ); | 52 | template<class T> void initT( const char* name, T**, int ); |
52 | void initInfo(); | 53 | void initInfo(); |
53 | void initDisp(); | 54 | void initDisp(); |
54 | 55 | ||
55 | private: | 56 | private: |
56 | Opie::Core::OConfig *m_cfg; | 57 | Opie::Core::OConfig *m_cfg; |
57 | Opie::Ui::OWidgetStack *m_stack; | 58 | Opie::Ui::OWidgetStack *m_stack; |
58 | PIconView* m_view; | 59 | PIconView* m_view; |
59 | imageinfo *m_info; | 60 | imageinfo *m_info; |
60 | ImageView *m_disp; | 61 | ImageView *m_disp; |
61 | bool autoRotate; | 62 | bool autoRotate; |
62 | bool autoScale; | 63 | bool autoScale; |
64 | bool zoomerOn; | ||
63 | QToolButton*rotateButton; | 65 | QToolButton*rotateButton; |
64 | 66 | ||
65 | 67 | ||
66 | private slots: | 68 | private slots: |
67 | void slotConfig(); | 69 | void slotConfig(); |
68 | }; | 70 | }; |
69 | 71 | ||
70 | #endif | 72 | #endif |