summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-11-03 18:14:36 (UTC)
committer llornkcor <llornkcor>2002-11-03 18:14:36 (UTC)
commit7d282e8e721d4c7c71a6d308d082da7138139484 (patch) (unidiff)
treecd37bc23214230258054562657a1d5eff49232b7
parent8b3893f3b11731151c19274d2c9ed22d7a00a2b3 (diff)
downloadopie-7d282e8e721d4c7c71a6d308d082da7138139484.zip
opie-7d282e8e721d4c7c71a6d308d082da7138139484.tar.gz
opie-7d282e8e721d4c7c71a6d308d082da7138139484.tar.bz2
fix ofileselector open
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/showimg/showimg.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/multimedia/showimg/showimg.cpp b/noncore/multimedia/showimg/showimg.cpp
index 0fbffe7..d6f0733 100644
--- a/noncore/multimedia/showimg/showimg.cpp
+++ b/noncore/multimedia/showimg/showimg.cpp
@@ -1,1249 +1,1249 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21// 21//
22// Full-screen and rotation options contributed by Robert Wittams <robert@wittams.com> 22// Full-screen and rotation options contributed by Robert Wittams <robert@wittams.com>
23// 23//
24 24
25#include "showimg.h" 25#include "showimg.h"
26#include "ImageFileSelector.h" 26#include "ImageFileSelector.h"
27#include "settingsdialog.h" 27#include "settingsdialog.h"
28 28
29 29
30#include <opie/ofiledialog.h> 30#include <opie/ofiledialog.h>
31 31
32#include <qpe/qpeapplication.h> 32#include <qpe/qpeapplication.h>
33#include <qpe/config.h> 33#include <qpe/config.h>
34#include <qpe/resource.h> 34#include <qpe/resource.h>
35#include <qpe/fileselector.h> 35#include <qpe/fileselector.h>
36#include <qpe/applnk.h> 36#include <qpe/applnk.h>
37#include <qfileinfo.h> 37#include <qfileinfo.h>
38#include <math.h> 38#include <math.h>
39#include <qpe/qpemenubar.h> 39#include <qpe/qpemenubar.h>
40#include <qwidgetstack.h> 40#include <qwidgetstack.h>
41#include <qpe/qpetoolbar.h> 41#include <qpe/qpetoolbar.h>
42#include <qaction.h> 42#include <qaction.h>
43#include <qfiledialog.h> 43#include <qfiledialog.h>
44#include <qmessagebox.h> 44#include <qmessagebox.h>
45#include <qpopupmenu.h> 45#include <qpopupmenu.h>
46#include <qscrollview.h> 46#include <qscrollview.h>
47#include <qlabel.h> 47#include <qlabel.h>
48#include <qpainter.h> 48#include <qpainter.h>
49#include <qkeycode.h> 49#include <qkeycode.h>
50#include <qapplication.h> 50#include <qapplication.h>
51#include <qclipboard.h> 51#include <qclipboard.h>
52#include <qtimer.h> 52#include <qtimer.h>
53#include <qspinbox.h> 53#include <qspinbox.h>
54 54
55 55
56 56
57ControlsDialog::ControlsDialog(const QString &caption,QImage image,int *brightness,QWidget *parent) 57ControlsDialog::ControlsDialog(const QString &caption,QImage image,int *brightness,QWidget *parent)
58 : QDialog(parent,0,true) 58 : QDialog(parent,0,true)
59{ 59{
60 setCaption(caption); 60 setCaption(caption);
61 61
62 if ( parent ) { 62 if ( parent ) {
63 setPalette(parent->palette()); 63 setPalette(parent->palette());
64 } 64 }
65 65
66 b=brightness; 66 b=brightness;
67 img=image; 67 img=image;
68 68
69 setMinimumSize(140,80); 69 setMinimumSize(140,80);
70 70
71 QGridLayout *gl= new QGridLayout(this,2,2,4,4); 71 QGridLayout *gl= new QGridLayout(this,2,2,4,4);
72 72
73 pixmap =new ImageWidget(this);; 73 pixmap =new ImageWidget(this);;
74 QPixmap pm; 74 QPixmap pm;
75 pm.convertFromImage(img); 75 pm.convertFromImage(img);
76 pixmap->setPixmap(pm); 76 pixmap->setPixmap(pm);
77 pixmap->setMinimumSize(pm.width(),pm.height()); 77 pixmap->setMinimumSize(pm.width(),pm.height());
78 gl->addMultiCellWidget(pixmap,0,0,0,2,AlignCenter); 78 gl->addMultiCellWidget(pixmap,0,0,0,2,AlignCenter);
79 QLabel *l=new QLabel(tr("Brightness")+":",this); 79 QLabel *l=new QLabel(tr("Brightness")+":",this);
80 gl->addWidget(l,1,0,AlignLeft); 80 gl->addWidget(l,1,0,AlignLeft);
81 spb=new QSpinBox(-100,100,2,this); 81 spb=new QSpinBox(-100,100,2,this);
82 gl->addWidget(spb,1,1,AlignRight); 82 gl->addWidget(spb,1,1,AlignRight);
83 83
84 spb->setValue(0); 84 spb->setValue(0);
85 85
86 connect(spb,SIGNAL(valueChanged(int)),this, SLOT(bValueChanged(int))); 86 connect(spb,SIGNAL(valueChanged(int)),this, SLOT(bValueChanged(int)));
87 87
88} 88}
89 89
90void ControlsDialog::bValueChanged(int value) 90void ControlsDialog::bValueChanged(int value)
91{ 91{
92 QImage nImage=img; 92 QImage nImage=img;
93 nImage.detach(); 93 nImage.detach();
94 ImageViewer::intensity(nImage, (float)value/100); 94 ImageViewer::intensity(nImage, (float)value/100);
95 QPixmap pm; 95 QPixmap pm;
96 pm.convertFromImage(nImage); 96 pm.convertFromImage(nImage);
97 pixmap->setPixmap(pm); 97 pixmap->setPixmap(pm);
98 pixmap->repaint(false); 98 pixmap->repaint(false);
99 99
100 100
101} 101}
102 102
103void ControlsDialog::accept() 103void ControlsDialog::accept()
104{ 104{
105 *b=spb->value(); 105 *b=spb->value();
106 done(1); 106 done(1);
107} 107}
108 108
109//=========================================================================== 109//===========================================================================
110 110
111InfoDialog::InfoDialog(const QString &caption, const QStringList text,QWidget *parent) 111InfoDialog::InfoDialog(const QString &caption, const QStringList text,QWidget *parent)
112 : QDialog(parent,0,true) 112 : QDialog(parent,0,true)
113{ 113{
114 setCaption(caption); 114 setCaption(caption);
115 115
116 if ( parent ) 116 if ( parent )
117 { 117 {
118 setPalette(parent->palette()); 118 setPalette(parent->palette());
119 } 119 }
120 120
121 const char *labels[]={"File Name","Format","File Size","Size","Colors","Alpha"}; 121 const char *labels[]={"File Name","Format","File Size","Size","Colors","Alpha"};
122 122
123 setMinimumSize(180,80); 123 setMinimumSize(180,80);
124 int num=ImageViewer::LAST+1; 124 int num=ImageViewer::LAST+1;
125 if ( text[ImageViewer::ALPHA].isEmpty() ) 125 if ( text[ImageViewer::ALPHA].isEmpty() )
126 num--; 126 num--;
127 QGridLayout *gl= new QGridLayout(this,num,2,4,2); 127 QGridLayout *gl= new QGridLayout(this,num,2,4,2);
128 QLabel *l; 128 QLabel *l;
129 int count=0; 129 int count=0;
130 for ( int i=0;i<num;i++ ) 130 for ( int i=0;i<num;i++ )
131 { 131 {
132 if ( i==1 ) 132 if ( i==1 )
133 { 133 {
134 QFrame *frm=new QFrame(this); 134 QFrame *frm=new QFrame(this);
135 frm->setFrameStyle(QFrame::HLine|QFrame::Sunken); 135 frm->setFrameStyle(QFrame::HLine|QFrame::Sunken);
136 gl->addMultiCellWidget(frm,i,i,0,1); 136 gl->addMultiCellWidget(frm,i,i,0,1);
137 } 137 }
138 else 138 else
139 { 139 {
140 l=new QLabel(tr(labels[count])+":",this); 140 l=new QLabel(tr(labels[count])+":",this);
141 gl->addWidget(l,i,0,AlignLeft); 141 gl->addWidget(l,i,0,AlignLeft);
142 l=new QLabel(text[count],this); 142 l=new QLabel(text[count],this);
143 gl->addWidget(l,i,1,AlignRight); 143 gl->addWidget(l,i,1,AlignRight);
144 count++; 144 count++;
145 } 145 }
146 146
147 } 147 }
148 148
149} 149}
150 150
151void InfoDialog::displayInfo(const QString &caption, const QStringList text, QWidget *parent) 151void InfoDialog::displayInfo(const QString &caption, const QStringList text, QWidget *parent)
152{ 152{
153 InfoDialog *dlg=new InfoDialog(caption,text,parent); 153 InfoDialog *dlg=new InfoDialog(caption,text,parent);
154 dlg->exec(); 154 dlg->exec();
155 delete dlg; 155 delete dlg;
156} 156}
157 157
158//=========================================================================== 158//===========================================================================
159 159
160 160
161ImagePane::ImagePane( QWidget *parent ) : QWidget( parent ) 161ImagePane::ImagePane( QWidget *parent ) : QWidget( parent )
162{ 162{
163 vb = new QVBoxLayout( this ); 163 vb = new QVBoxLayout( this );
164 164
165 image = new QScrollView(this,0,WResizeNoErase|WNorthWestGravity); 165 image = new QScrollView(this,0,WResizeNoErase|WNorthWestGravity);
166 pic=new ImageWidget(image); 166 pic=new ImageWidget(image);
167 image->addChild(pic); 167 image->addChild(pic);
168 168
169 connect(pic, SIGNAL( clicked() ), this, SLOT( imageClicked() )); 169 connect(pic, SIGNAL( clicked() ), this, SLOT( imageClicked() ));
170 170
171 vb->addWidget( image ); 171 vb->addWidget( image );
172 172
173} 173}
174 174
175void ImagePane::setPixmap( const QPixmap &pm ) 175void ImagePane::setPixmap( const QPixmap &pm )
176{ 176{
177 pic->setPixmap( pm ); 177 pic->setPixmap( pm );
178 pic->resize(pm.width(),pm.height()); 178 pic->resize(pm.width(),pm.height());
179 image->updateScrollBars (); 179 image->updateScrollBars ();
180 pic->repaint(false); 180 pic->repaint(false);
181} 181}
182 182
183void ImagePane::imageClicked() 183void ImagePane::imageClicked()
184{ 184{
185 emit clicked(); 185 emit clicked();
186} 186}
187//=========================================================================== 187//===========================================================================
188/* 188/*
189 Draws the portion of the scaled pixmap that needs to be updated 189 Draws the portion of the scaled pixmap that needs to be updated
190*/ 190*/
191 191
192void ImageWidget::paintEvent( QPaintEvent *e ) 192void ImageWidget::paintEvent( QPaintEvent *e )
193{ 193{
194 QPainter painter(this); 194 QPainter painter(this);
195 195
196 painter.setClipRect(e->rect()); 196 painter.setClipRect(e->rect());
197 painter.fillRect(0,0,width(),height(),QColor(0,0,0)); 197 painter.fillRect(0,0,width(),height(),QColor(0,0,0));
198 198
199 if ( pixmap.size() != QSize( 0, 0 ) ) 199 if ( pixmap.size() != QSize( 0, 0 ) )
200 { // is an image loaded? 200 { // is an image loaded?
201 painter.drawPixmap((width() - pixmap.width()) / 2, (height() - pixmap.height()) / 2, pixmap); 201 painter.drawPixmap((width() - pixmap.width()) / 2, (height() - pixmap.height()) / 2, pixmap);
202 } 202 }
203} 203}
204 204
205void ImageWidget::mouseReleaseEvent(QMouseEvent *) 205void ImageWidget::mouseReleaseEvent(QMouseEvent *)
206{ 206{
207 emit clicked(); 207 emit clicked();
208} 208}
209 209
210//=========================================================================== 210//===========================================================================
211 211
212ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags ) 212ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
213: QMainWindow( parent, name, wFlags ), filename( 0 ), bFromDocView( FALSE ) 213: QMainWindow( parent, name, wFlags ), filename( 0 ), bFromDocView( FALSE )
214{ 214{
215 setCaption( tr("Image Viewer") ); 215 setCaption( tr("Image Viewer") );
216 setIcon( Resource::loadPixmap( "ImageViewer" ) ); 216 setIcon( Resource::loadPixmap( "ImageViewer" ) );
217 217
218 218
219 Config cfg("Image Viewer"); 219 Config cfg("Image Viewer");
220 cfg.setGroup("Image Viewer"); 220 cfg.setGroup("Image Viewer");
221 221
222 showThumbView=cfg.readBoolEntry("ShowThumbnails",false); 222 showThumbView=cfg.readBoolEntry("ShowThumbnails",false);
223 isSized=cfg.readBoolEntry("SizeToScreen",true); 223 isSized=cfg.readBoolEntry("SizeToScreen",true);
224 224
225 isFullScreen = FALSE; 225 isFullScreen = FALSE;
226 226
227 setToolBarsMovable( FALSE ); 227 setToolBarsMovable( FALSE );
228 228
229 toolBar = new QPEToolBar( this ); 229 toolBar = new QPEToolBar( this );
230 toolBar->setHorizontalStretchable( TRUE ); 230 toolBar->setHorizontalStretchable( TRUE );
231 231
232 menuBar = new QPEMenuBar( toolBar ); 232 menuBar = new QPEMenuBar( toolBar );
233 233
234 current=menuBar; 234 current=menuBar;
235 235
236 236
237 237
238 fileMenuFile = new QPopupMenu(this); 238 fileMenuFile = new QPopupMenu(this);
239 //menuBarmenubarFile->insertItem( tr("File"), fileMenu ); 239 //menuBarmenubarFile->insertItem( tr("File"), fileMenu );
240 fileMenuFile->insertItem(tr("Open"), 240 fileMenuFile->insertItem(tr("Open"),
241 this, SLOT(openFile()), 0); 241 this, SLOT(openFile()), 0);
242 242
243 viewMenuFile = new QPopupMenu( this ); 243 viewMenuFile = new QPopupMenu( this );
244 //menubarFile->insertItem( tr("View"), viewMenu ); 244 //menubarFile->insertItem( tr("View"), viewMenu );
245 viewMenuFile->insertItem( tr("Thumbnail View"), 245 viewMenuFile->insertItem( tr("Thumbnail View"),
246 this, SLOT(switchThumbView()), 0, SHOW_THUMBNAILS ); 246 this, SLOT(switchThumbView()), 0, SHOW_THUMBNAILS );
247 247
248 viewMenuFile->setItemChecked ( SHOW_THUMBNAILS, showThumbView ); 248 viewMenuFile->setItemChecked ( SHOW_THUMBNAILS, showThumbView );
249 249
250 250
251 251
252 252
253 optionsMenuFile = new QPopupMenu( this); 253 optionsMenuFile = new QPopupMenu( this);
254 //menubarFile->insertItem( tr("Options"),optionsMenu ); 254 //menubarFile->insertItem( tr("Options"),optionsMenu );
255 slideAction = new QAction( tr( "Slide show" ), Resource::loadIconSet( "slideshow" ), 255 slideAction = new QAction( tr( "Slide show" ), Resource::loadIconSet( "slideshow" ),
256 QString::null, 0, this, 0 ); 256 QString::null, 0, this, 0 );
257 slideAction->setToggleAction( TRUE ); 257 slideAction->setToggleAction( TRUE );
258 connect( slideAction, SIGNAL( toggled(bool) ), this, SLOT( slideShow(bool) ) ); 258 connect( slideAction, SIGNAL( toggled(bool) ), this, SLOT( slideShow(bool) ) );
259 slideAction->addTo( optionsMenuFile); 259 slideAction->addTo( optionsMenuFile);
260// slideAction->addTo( toolBar ); 260// slideAction->addTo( toolBar );
261 261
262 262
263// optionsMenuFile->insertItem( tr("Slideshow") ); 263// optionsMenuFile->insertItem( tr("Slideshow") );
264 optionsMenuFile->insertSeparator(); 264 optionsMenuFile->insertSeparator();
265 optionsMenuFile->insertItem( tr("Preferences.."), this, SLOT(settings()), 0); 265 optionsMenuFile->insertItem( tr("Preferences.."), this, SLOT(settings()), 0);
266// optionsMenuFile->insertItem( tr("Help"), this, SLOT(help()), 0); 266// optionsMenuFile->insertItem( tr("Help"), this, SLOT(help()), 0);
267 267
268 QStrList fmt = QImage::outputFormats(); 268 QStrList fmt = QImage::outputFormats();
269 269
270 270
271 fileMenuView = new QPopupMenu( this ); 271 fileMenuView = new QPopupMenu( this );
272 //menubarView->insertItem( tr("File"),fileMenu ); 272 //menubarView->insertItem( tr("File"),fileMenu );
273 fileMenuView->insertItem( tr("Image Info ..."),this, SLOT(displayInfoDialog()),0 ); 273 fileMenuView->insertItem( tr("Image Info ..."),this, SLOT(displayInfoDialog()),0 );
274 fileMenuView->insertSeparator(); 274 fileMenuView->insertSeparator();
275 275
276 viewMenuView = new QPopupMenu(this ); 276 viewMenuView = new QPopupMenu(this );
277 viewMenuView->setCheckable ( true ); 277 viewMenuView->setCheckable ( true );
278 278
279 //menubarView->insertItem( tr("View"),viewMenu ); 279 //menubarView->insertItem( tr("View"),viewMenu );
280 viewMenuView->insertItem(tr("Horizontal flip"), this, SLOT(hFlip()), 0); 280 viewMenuView->insertItem(tr("Horizontal flip"), this, SLOT(hFlip()), 0);
281 viewMenuView->insertItem(tr("Vertical flip"), this, SLOT(vFlip()), 0); 281 viewMenuView->insertItem(tr("Vertical flip"), this, SLOT(vFlip()), 0);
282 282
283 stack = new QWidgetStack( this ); 283 stack = new QWidgetStack( this );
284 stack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); 284 stack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
285 setCentralWidget( stack ); 285 setCentralWidget( stack );
286 286
287 287
288 imagePanel = new ImagePane( stack ); 288 imagePanel = new ImagePane( stack );
289 connect(imagePanel, SIGNAL(clicked()), this, SLOT(normalView())); 289 connect(imagePanel, SIGNAL(clicked()), this, SLOT(normalView()));
290 290
291 291
292 ImageFileSelector::CURRENT_VIEW cv; 292 ImageFileSelector::CURRENT_VIEW cv;
293 if(showThumbView) 293 if(showThumbView)
294 cv=ImageFileSelector::THUMBNAIL; 294 cv=ImageFileSelector::THUMBNAIL;
295 else 295 else
296 cv=ImageFileSelector::DETAILED; 296 cv=ImageFileSelector::DETAILED;
297 297
298 qDebug("cv = %d",cv); 298 qDebug("cv = %d",cv);
299 299
300 fileSelector = new ImageFileSelector( cv,stack, "fs"); 300 fileSelector = new ImageFileSelector( cv,stack, "fs");
301 301
302 //switchThumbView(); 302 //switchThumbView();
303 303
304 304
305 //fileSelector = new ImageFileSelector("image/*", stack, "fs"); 305 //fileSelector = new ImageFileSelector("image/*", stack, "fs");
306 //fileSelector->setNewVisible(FALSE); 306 //fileSelector->setNewVisible(FALSE);
307 //fileSelector->setCloseVisible(FALSE); 307 //fileSelector->setCloseVisible(FALSE);
308 connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( closeFileSelector() ) ); 308 connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( closeFileSelector() ) );
309 connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), 309 connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ),
310 this, SLOT( openFile( const DocLnk & ) ) ); 310 this, SLOT( openFile( const DocLnk & ) ) );
311 311
312 imageList = fileSelector->fileList(); 312 imageList = fileSelector->fileList();
313 slideAction->setEnabled( imageList.count() != 0); 313 slideAction->setEnabled( imageList.count() != 0);
314 314
315 iconToolBar = new QPEToolBar(this); 315 iconToolBar = new QPEToolBar(this);
316 316
317 QAction *a; 317 QAction *a;
318 318
319 a = new QAction( tr( "Open ..." ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); 319 a = new QAction( tr( "Open ..." ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
320 connect( a, SIGNAL( activated() ), this, SLOT( open() ) ); 320 connect( a, SIGNAL( activated() ), this, SLOT( open() ) );
321 a->addTo( fileMenuView); 321 a->addTo( fileMenuView);
322 a->addTo( iconToolBar ); 322 a->addTo( iconToolBar );
323 323
324 324
325 a = new QAction( tr( "Rotate 90"), Resource::loadPixmap( "rotate90" ), QString::null, 0, this, 0); 325 a = new QAction( tr( "Rotate 90"), Resource::loadPixmap( "rotate90" ), QString::null, 0, this, 0);
326 connect( a, SIGNAL( activated() ), this, SLOT( rot90() ) ); 326 connect( a, SIGNAL( activated() ), this, SLOT( rot90() ) );
327 a->addTo( iconToolBar ); 327 a->addTo( iconToolBar );
328 a->addTo( viewMenuView ); 328 a->addTo( viewMenuView );
329 329
330 a = new QAction( tr( "Rotate 180" ), Resource::loadPixmap( "repeat" ), QString::null, 0, this, 0 ); 330 a = new QAction( tr( "Rotate 180" ), Resource::loadPixmap( "repeat" ), QString::null, 0, this, 0 );
331 connect( a, SIGNAL( activated() ), this, SLOT( rot180() ) ); 331 connect( a, SIGNAL( activated() ), this, SLOT( rot180() ) );
332 a->addTo( iconToolBar ); 332 a->addTo( iconToolBar );
333 a->addTo( viewMenuView ); 333 a->addTo( viewMenuView );
334 334
335 335
336 a = new QAction( tr( "Rotate 270"), Resource::loadPixmap( "rotate270" ), QString::null, 0, this, 0); 336 a = new QAction( tr( "Rotate 270"), Resource::loadPixmap( "rotate270" ), QString::null, 0, this, 0);
337 connect( a, SIGNAL( activated() ), this, SLOT( rot270() ) ); 337 connect( a, SIGNAL( activated() ), this, SLOT( rot270() ) );
338 //a->addTo( iconToolBar ); 338 //a->addTo( iconToolBar );
339 a->addTo( viewMenuView ); 339 a->addTo( viewMenuView );
340 340
341 341
342 342
343 viewMenuView->insertSeparator(); 343 viewMenuView->insertSeparator();
344 viewMenuView->insertItem(tr("Brightness ..."), this, SLOT(displayControlsDialog()), 0); 344 viewMenuView->insertItem(tr("Brightness ..."), this, SLOT(displayControlsDialog()), 0);
345 viewMenuView->insertItem(tr("Black And White"), this, SLOT(blackAndWhite()), 0,BLACKANDWHITE); 345 viewMenuView->insertItem(tr("Black And White"), this, SLOT(blackAndWhite()), 0,BLACKANDWHITE);
346 viewMenuView->insertSeparator(); 346 viewMenuView->insertSeparator();
347 347
348 348
349 sss = new QAction( tr( "Scale to Screen"), Resource::loadPixmap( "scale" ), QString::null, 0, this, 0,true); 349 sss = new QAction( tr( "Scale to Screen"), Resource::loadPixmap( "scale" ), QString::null, 0, this, 0,true);
350 connect( sss, SIGNAL( activated() ), this, SLOT( switchSizeToScreen() ) ); 350 connect( sss, SIGNAL( activated() ), this, SLOT( switchSizeToScreen() ) );
351 sss->addTo( iconToolBar ); 351 sss->addTo( iconToolBar );
352 sss->addTo( viewMenuView ); 352 sss->addTo( viewMenuView );
353 353
354 sss->setOn(isSized); 354 sss->setOn(isSized);
355 viewMenuView->insertSeparator(); 355 viewMenuView->insertSeparator();
356 356
357 357
358 a = new QAction( tr( "Fullscreen" ), Resource::loadPixmap( "fullscreen" ), 358 a = new QAction( tr( "Fullscreen" ), Resource::loadPixmap( "fullscreen" ),
359 QString::null, 0, this, 0 ); 359 QString::null, 0, this, 0 );
360 connect( a, SIGNAL( activated() ), this, SLOT( fullScreen() ) ); 360 connect( a, SIGNAL( activated() ), this, SLOT( fullScreen() ) );
361 a->addTo( iconToolBar ); 361 a->addTo( iconToolBar );
362 a->addTo( viewMenuView); 362 a->addTo( viewMenuView);
363 363
364 a = new QAction( tr( "Stop Slideshow" ), Resource::loadPixmap( "quit_icon" ), 364 a = new QAction( tr( "Stop Slideshow" ), Resource::loadPixmap( "quit_icon" ),
365 QString::null, 0, this, 0 ); 365 QString::null, 0, this, 0 );
366 connect( a, SIGNAL( activated() ), this, SLOT( stopSlideShow() ) ); 366 connect( a, SIGNAL( activated() ), this, SLOT( stopSlideShow() ) );
367 a->addTo( iconToolBar ); 367 a->addTo( iconToolBar );
368 a->addTo( viewMenuView); 368 a->addTo( viewMenuView);
369 369
370 370
371 Config config( "ImageViewer" ); 371 Config config( "ImageViewer" );
372 config.setGroup( "SlideShow" ); 372 config.setGroup( "SlideShow" );
373 slideDelay = config.readNumEntry( "Delay", 2); 373 slideDelay = config.readNumEntry( "Delay", 2);
374 slideRepeat = config.readBoolEntry( "Repeat", FALSE ); 374 slideRepeat = config.readBoolEntry( "Repeat", FALSE );
375 slideReverse = config.readBoolEntry("Reverse", FALSE); 375 slideReverse = config.readBoolEntry("Reverse", FALSE);
376 376
377 config.setGroup("Default"); 377 config.setGroup("Default");
378 rotateOnLoad = config.readBoolEntry("Rotate", FALSE); 378 rotateOnLoad = config.readBoolEntry("Rotate", FALSE);
379 fastLoad = config.readBoolEntry("FastLoad", TRUE); 379 fastLoad = config.readBoolEntry("FastLoad", TRUE);
380 slideTimer = new QTimer( this ); 380 slideTimer = new QTimer( this );
381 connect( slideTimer, SIGNAL(timeout()), this, SLOT(slideUpdate()) ); 381 connect( slideTimer, SIGNAL(timeout()), this, SLOT(slideUpdate()) );
382 382
383 switchToFileSelector(); 383 switchToFileSelector();
384 384
385 setMouseTracking( TRUE ); 385 setMouseTracking( TRUE );
386 386
387 387
388} 388}
389 389
390ImageViewer::~ImageViewer() 390ImageViewer::~ImageViewer()
391{ 391{
392 Config cfg("Image Viewer"); 392 Config cfg("Image Viewer");
393 cfg.setGroup("Image Viewer"); 393 cfg.setGroup("Image Viewer");
394 394
395 cfg.writeEntry("ShowThumbnails",(int)showThumbView); 395 cfg.writeEntry("ShowThumbnails",(int)showThumbView);
396 cfg.writeEntry("SizeToScreen",(int)isSized); 396 cfg.writeEntry("SizeToScreen",(int)isSized);
397 397
398 cfg.setGroup( "SlideShow" ); 398 cfg.setGroup( "SlideShow" );
399 cfg.writeEntry( "Delay", slideDelay); 399 cfg.writeEntry( "Delay", slideDelay);
400 cfg.writeEntry( "Repeat", slideRepeat ); 400 cfg.writeEntry( "Repeat", slideRepeat );
401 cfg.writeEntry("Reverse", slideReverse); 401 cfg.writeEntry("Reverse", slideReverse);
402 402
403 cfg.setGroup("Default"); 403 cfg.setGroup("Default");
404 cfg.writeEntry("Rotate", rotateOnLoad); 404 cfg.writeEntry("Rotate", rotateOnLoad);
405 cfg.writeEntry("FastLoad", fastLoad); 405 cfg.writeEntry("FastLoad", fastLoad);
406 406
407 delete imagePanel; // in case it is fullscreen 407 delete imagePanel; // in case it is fullscreen
408} 408}
409 409
410void ImageViewer::help() { 410void ImageViewer::help() {
411 411
412} 412}
413 413
414 414
415void ImageViewer::settings() 415void ImageViewer::settings()
416{ 416{
417 SettingsDialog dlg( this, 0, TRUE ); 417 SettingsDialog dlg( this, 0, TRUE );
418 dlg.setDelay( slideDelay ); 418 dlg.setDelay( slideDelay );
419 dlg.setRepeat( slideRepeat ); 419 dlg.setRepeat( slideRepeat );
420 dlg.setReverse( slideReverse ); 420 dlg.setReverse( slideReverse );
421 dlg.setRotate(rotateOnLoad); 421 dlg.setRotate(rotateOnLoad);
422 dlg.setFastLoad(fastLoad); 422 dlg.setFastLoad(fastLoad);
423 423
424 if ( QPEApplication::execDialog(&dlg) == QDialog::Accepted ) { 424 if ( QPEApplication::execDialog(&dlg) == QDialog::Accepted ) {
425 qDebug("<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>"); 425 qDebug("<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>");
426 slideDelay = dlg.delay(); 426 slideDelay = dlg.delay();
427 slideRepeat = dlg.repeat(); 427 slideRepeat = dlg.repeat();
428 slideReverse = dlg.reverse(); 428 slideReverse = dlg.reverse();
429 rotateOnLoad = dlg.rotate(); 429 rotateOnLoad = dlg.rotate();
430 fastLoad = dlg.fastLoad(); 430 fastLoad = dlg.fastLoad();
431 431
432 Config config( "ImageViewer" ); 432 Config config( "ImageViewer" );
433 config.setGroup( "SlideShow" ); 433 config.setGroup( "SlideShow" );
434 config.writeEntry( "Delay", slideDelay ); 434 config.writeEntry( "Delay", slideDelay );
435 config.writeEntry( "Repeat", slideRepeat ); 435 config.writeEntry( "Repeat", slideRepeat );
436 config.writeEntry("Reverse", slideReverse); 436 config.writeEntry("Reverse", slideReverse);
437 437
438 config.setGroup("Default"); 438 config.setGroup("Default");
439 config.writeEntry("Rotate", rotateOnLoad); 439 config.writeEntry("Rotate", rotateOnLoad);
440 config.writeEntry("FastLoad", fastLoad); 440 config.writeEntry("FastLoad", fastLoad);
441 } 441 }
442} 442}
443 443
444void ImageViewer::switchSizeToScreen() 444void ImageViewer::switchSizeToScreen()
445{ 445{
446 isSized=!isSized; 446 isSized=!isSized;
447 sss->setOn(isSized); 447 sss->setOn(isSized);
448 updateImage(); 448 updateImage();
449} 449}
450 450
451void ImageViewer::updateImage() 451void ImageViewer::updateImage()
452{ 452{
453 if ( isSized ) { 453 if ( isSized ) {
454 imagePanel->setPixmap(pmScaled); 454 imagePanel->setPixmap(pmScaled);
455 } else { 455 } else {
456 imagePanel->setPixmap(pm); 456 imagePanel->setPixmap(pm);
457 } 457 }
458} 458}
459 459
460void ImageViewer::switchThumbView() 460void ImageViewer::switchThumbView()
461{ 461{
462 462
463 showThumbView=!showThumbView; 463 showThumbView=!showThumbView;
464 viewMenuFile->setItemChecked ( SHOW_THUMBNAILS, showThumbView ); 464 viewMenuFile->setItemChecked ( SHOW_THUMBNAILS, showThumbView );
465 fileSelector->switchView(); 465 fileSelector->switchView();
466 466
467} 467}
468 468
469void ImageViewer::switchToFileSelector() 469void ImageViewer::switchToFileSelector()
470{ 470{
471 stack->raiseWidget(fileSelector); 471 stack->raiseWidget(fileSelector);
472 menuBar->clear(); 472 menuBar->clear();
473 menuBar->insertItem( tr("File"), fileMenuFile ); 473 menuBar->insertItem( tr("File"), fileMenuFile );
474 menuBar->insertItem( tr("View"), viewMenuFile ); 474 menuBar->insertItem( tr("View"), viewMenuFile );
475 menuBar->insertItem( tr("Options"), optionsMenuFile ); 475 menuBar->insertItem( tr("Options"), optionsMenuFile );
476 iconToolBar->hide(); 476 iconToolBar->hide();
477 imagePanel->disable(); 477 imagePanel->disable();
478 slideShow(false); 478 slideShow(false);
479 479
480} 480}
481 481
482void ImageViewer::switchToImageView() 482void ImageViewer::switchToImageView()
483{ 483{
484 stack->raiseWidget(imagePanel); 484 stack->raiseWidget(imagePanel);
485 485
486 menuBar->clear(); 486 menuBar->clear();
487 menuBar->insertItem( tr("File"), fileMenuView ); 487 menuBar->insertItem( tr("File"), fileMenuView );
488 menuBar->insertItem( tr("View"), viewMenuView ); 488 menuBar->insertItem( tr("View"), viewMenuView );
489 viewMenuView->setItemEnabled(BLACKANDWHITE,true); 489 viewMenuView->setItemEnabled(BLACKANDWHITE,true);
490 iconToolBar->show(); 490 iconToolBar->show();
491 491
492 imagePanel->setPosition(0,0); 492 imagePanel->setPosition(0,0);
493 493
494} 494}
495 495
496 496
497void ImageViewer::setDocument(const QString& fileref) 497void ImageViewer::setDocument(const QString& fileref)
498{ 498{
499 delayLoad = fileref; 499 delayLoad = fileref;
500 switchToImageView(); 500 switchToImageView();
501 QTimer::singleShot( 0, this, SLOT(doDelayedLoad()) ); 501 QTimer::singleShot( 0, this, SLOT(doDelayedLoad()) );
502} 502}
503 503
504void ImageViewer::doDelayedLoad() 504void ImageViewer::doDelayedLoad()
505{ 505{
506 show(delayLoad); 506 show(delayLoad);
507} 507}
508 508
509void ImageViewer::show() 509void ImageViewer::show()
510{ 510{
511 normalView(); 511 normalView();
512 QMainWindow::show(); 512 QMainWindow::show();
513} 513}
514 514
515void ImageViewer::show(const QString& fileref) 515void ImageViewer::show(const QString& fileref)
516{ 516{
517// qDebug("Show "+fileref); 517// qDebug("Show "+fileref);
518 bFromDocView = TRUE; 518 bFromDocView = TRUE;
519 closeFileSelector(); 519 closeFileSelector();
520 DocLnk link(fileref); 520 DocLnk link(fileref);
521 if ( link.isValid() ) { 521 if ( link.isValid() ) {
522 openFile(link); 522 openFile(link);
523 } else { 523 } else {
524 filename = fileref; 524 filename = fileref;
525 updateCaption( fileref ); 525 updateCaption( fileref );
526 loadImage( fileref ); 526 loadImage( fileref );
527 } 527 }
528} 528}
529 529
530void ImageViewer::openFile() { 530void ImageViewer::openFile() {
531 MimeTypes types; 531 MimeTypes types;
532 QStringList image; 532 QStringList image;
533 image << "image/*"; 533 image << "image/*";
534 types.insert("Images", image); 534 types.insert("Images", image);
535 535
536 QString str = OFileDialog::getOpenFileName( 1,QPEApplication::documentDir(),"", types, 0 ); 536 QString str = OFileDialog::getOpenFileName( 1,QPEApplication::documentDir(),"", types, 0 );
537 DocLnk link(str); 537 DocLnk link(str);
538 if ( link.isValid() ) 538// if ( link.isValid() )
539 openFile(link); 539 openFile(link);
540 540
541} 541}
542 542
543void ImageViewer::openFile( const DocLnk &link ) 543void ImageViewer::openFile( const DocLnk &link )
544{ 544{
545 closeFileSelector(); 545 closeFileSelector();
546// DocLnk link(file); 546// DocLnk link(file);
547 qDebug("open "+link.name()); 547 qDebug("open "+link.name());
548 updateCaption( link.name() ); 548 updateCaption( link.name() );
549 loadImage( link.file() ); 549 loadImage( link.file() );
550 if (slideTimer->isActive()) { 550 if (slideTimer->isActive()) {
551 slideTimer->start(slideDelay * 1000, FALSE); 551 slideTimer->start(slideDelay * 1000, FALSE);
552 } 552 }
553 553
554} 554}
555 555
556void ImageViewer::open() 556void ImageViewer::open()
557{ 557{
558 switchToFileSelector(); 558 switchToFileSelector();
559} 559}
560 560
561void ImageViewer::closeFileSelector() 561void ImageViewer::closeFileSelector()
562{ 562{
563 switchToImageView(); 563 switchToImageView();
564} 564}
565 565
566void ImageViewer::updateCaption( QString name ) 566void ImageViewer::updateCaption( QString name )
567{ 567{
568 int sep = name.findRev( '/' ); 568 int sep = name.findRev( '/' );
569 if ( sep >= 0 ) 569 if ( sep >= 0 )
570 name = name.mid( sep+1 ); 570 name = name.mid( sep+1 );
571 setCaption( name + tr(" - Image Viewer") ); 571 setCaption( name + tr(" - Image Viewer") );
572} 572}
573 573
574/* 574/*
575 This function loads an image from a file. 575 This function loads an image from a file.
576*/ 576*/
577 577
578void ImageViewer::loadImage( const char *fileName ) 578void ImageViewer::loadImage( const char *fileName )
579{ 579{
580 filename = fileName; 580 filename = fileName;
581 if ( filename ) { 581 if ( filename ) {
582 QApplication::setOverrideCursor( waitCursor ); // this might take time 582 QApplication::setOverrideCursor( waitCursor ); // this might take time
583 //imagePanel->statusLabel()->setText( tr("Loading image...") ); 583 //imagePanel->statusLabel()->setText( tr("Loading image...") );
584 qApp->processEvents(); 584 qApp->processEvents();
585 bool ok = image.load(filename, 0); 585 bool ok = image.load(filename, 0);
586 if ( ok ) { 586 if ( ok ) {
587 ok = reconvertImage(); 587 ok = reconvertImage();
588 updateImageInfo(filename); 588 updateImageInfo(filename);
589 } 589 }
590 if ( !ok ) { 590 if ( !ok ) {
591 pm.resize(0,0); // couldn't load image 591 pm.resize(0,0); // couldn't load image
592 update(); 592 update();
593 } 593 }
594 QApplication::restoreOverrideCursor(); // restore original cursor 594 QApplication::restoreOverrideCursor(); // restore original cursor
595 } 595 }
596 596
597// fastLoad ? ", Fast" : "", 597// fastLoad ? ", Fast" : "",
598// fastLoad ? QMAX(imagewidth/maxsize, imageheight/maxsize) : 1); 598// fastLoad ? QMAX(imagewidth/maxsize, imageheight/maxsize) : 1);
599 599
600 600
601// matrix.reset(); 601// matrix.reset();
602 rotated90 = FALSE; 602 rotated90 = FALSE;
603 603
604 if (rotateOnLoad) { 604 if (rotateOnLoad) {
605 rotated90 = TRUE; 605 rotated90 = TRUE;
606 rot90(); 606 rot90();
607// matrix.rotate( -90.0 ); 607// matrix.rotate( -90.0 );
608 } 608 }
609 609
610 switchToImageView(); 610 switchToImageView();
611 updateImage(); 611 updateImage();
612 612
613} 613}
614 614
615bool ImageViewer::loadSelected() 615bool ImageViewer::loadSelected()
616{ 616{
617 bool ok = false; 617 bool ok = false;
618 if ( stack->visibleWidget() == fileSelector ) 618 if ( stack->visibleWidget() == fileSelector )
619 { 619 {
620 const DocLnk *link = fileSelector->selected(); 620 const DocLnk *link = fileSelector->selected();
621 if ( link ) 621 if ( link )
622 { 622 {
623 if ( link->file() != filename ) 623 if ( link->file() != filename )
624 { 624 {
625 updateCaption( link->name() ); 625 updateCaption( link->name() );
626 filename = link->file(); 626 filename = link->file();
627 qApp->processEvents(); 627 qApp->processEvents();
628 ok = image.load(filename, 0); 628 ok = image.load(filename, 0);
629 if ( ok ) 629 if ( ok )
630 { 630 {
631 updateImageInfo(filename); 631 updateImageInfo(filename);
632 ok = reconvertImage(); 632 ok = reconvertImage();
633 } 633 }
634 if ( !ok ) 634 if ( !ok )
635 pm.resize(0,0); 635 pm.resize(0,0);
636 } 636 }
637 } 637 }
638 } 638 }
639 if ( !image.isNull() ) 639 if ( !image.isNull() )
640 { 640 {
641 ok = true; 641 ok = true;
642 closeFileSelector(); 642 closeFileSelector();
643 } 643 }
644 644
645 return ok; 645 return ok;
646} 646}
647 647
648bool ImageViewer::reconvertImage() 648bool ImageViewer::reconvertImage()
649{ 649{
650 bool success = FALSE; 650 bool success = FALSE;
651 651
652 if ( image.isNull() ) return FALSE; 652 if ( image.isNull() ) return FALSE;
653 653
654 QApplication::setOverrideCursor( waitCursor ); // this might take time 654 QApplication::setOverrideCursor( waitCursor ); // this might take time
655 if ( pm.convertFromImage(image /*, conversion_flags */ ) ) 655 if ( pm.convertFromImage(image /*, conversion_flags */ ) )
656 { 656 {
657 pmScaled = QPixmap(); 657 pmScaled = QPixmap();
658 scale(); 658 scale();
659 success = TRUE; // load successful 659 success = TRUE; // load successful
660 } 660 }
661 else 661 else
662 { 662 {
663 pm.resize(0,0); // couldn't load image 663 pm.resize(0,0); // couldn't load image
664 } 664 }
665 QApplication::restoreOverrideCursor(); // restore original cursor 665 QApplication::restoreOverrideCursor(); // restore original cursor
666 666
667 return success; // TRUE if loaded OK 667 return success; // TRUE if loaded OK
668} 668}
669 669
670 670
671int ImageViewer::calcHeight() 671int ImageViewer::calcHeight()
672{ 672{
673 if ( !isFullScreen ) 673 if ( !isFullScreen )
674 return imagePanel->paneHeight(); 674 return imagePanel->paneHeight();
675 else 675 else
676 return qApp->desktop()->height(); 676 return qApp->desktop()->height();
677} 677}
678/* 678/*
679 This functions scales the pixmap in the member variable "pm" to fit the 679 This functions scales the pixmap in the member variable "pm" to fit the
680 widget size and puts the resulting pixmap in the member variable "pmScaled". 680 widget size and puts the resulting pixmap in the member variable "pmScaled".
681*/ 681*/
682void ImageViewer::scale() 682void ImageViewer::scale()
683{ 683{
684 int h = calcHeight(); 684 int h = calcHeight();
685 if ( image.isNull() ) return; 685 if ( image.isNull() ) return;
686 686
687 QApplication::setOverrideCursor( waitCursor ); // this might take time 687 QApplication::setOverrideCursor( waitCursor ); // this might take time
688 if ( imagePanel->paneWidth() == pm.width() && h == pm.height() ) 688 if ( imagePanel->paneWidth() == pm.width() && h == pm.height() )
689 { // no need to scale if widget 689 { // no need to scale if widget
690 pmScaled = pm; // size equals pixmap size 690 pmScaled = pm; // size equals pixmap size
691 } 691 }
692 else 692 else
693 { 693 {
694 double hs = (double)h / (double)image.height(); 694 double hs = (double)h / (double)image.height();
695 double ws = (double)imagePanel->paneWidth() / (double)image.width(); 695 double ws = (double)imagePanel->paneWidth() / (double)image.width();
696 double scaleFactor = (hs > ws) ? ws : hs; 696 double scaleFactor = (hs > ws) ? ws : hs;
697 int smoothW = (int)(scaleFactor * image.width()); 697 int smoothW = (int)(scaleFactor * image.width());
698 int smoothH = (int)(scaleFactor * image.height()); 698 int smoothH = (int)(scaleFactor * image.height());
699 699
700 pmScaled.convertFromImage( image.smoothScale( smoothW, smoothH ) /*, conversion_flags */ ); 700 pmScaled.convertFromImage( image.smoothScale( smoothW, smoothH ) /*, conversion_flags */ );
701 } 701 }
702 QApplication::restoreOverrideCursor(); // restore original cursor 702 QApplication::restoreOverrideCursor(); // restore original cursor
703} 703}
704 704
705/* 705/*
706 The resize event handler, if a valid pixmap was loaded it will call 706 The resize event handler, if a valid pixmap was loaded it will call
707 scale() to fit the pixmap to the new widget size. 707 scale() to fit the pixmap to the new widget size.
708*/ 708*/
709 709
710void ImageViewer::resizeEvent( QResizeEvent * ) 710void ImageViewer::resizeEvent( QResizeEvent * )
711{ 711{
712 712
713 if ( pm.size() == QSize( 0, 0 ) ) // we couldn't load the image 713 if ( pm.size() == QSize( 0, 0 ) ) // we couldn't load the image
714 return; 714 return;
715 715
716 int h = calcHeight(); 716 int h = calcHeight();
717 717
718 if ( imagePanel->paneWidth() != pmScaled.width() || h != pmScaled.height() ) 718 if ( imagePanel->paneWidth() != pmScaled.width() || h != pmScaled.height() )
719 { // if new size, 719 { // if new size,
720 scale(); // scale pmScaled to window 720 scale(); // scale pmScaled to window
721 } 721 }
722 if ( image.hasAlphaBuffer() ) 722 if ( image.hasAlphaBuffer() )
723 erase(); 723 erase();
724} 724}
725 725
726 726
727void ImageViewer::hFlip() 727void ImageViewer::hFlip()
728{ 728{
729// matrix.scale( -1.0, 1.0 ); 729// matrix.scale( -1.0, 1.0 );
730 730
731 setImage(image.mirror(TRUE,FALSE)); 731 setImage(image.mirror(TRUE,FALSE));
732} 732}
733 733
734void ImageViewer::vFlip() 734void ImageViewer::vFlip()
735{ 735{
736// matrix.scale( 1.0, -1.0 ); 736// matrix.scale( 1.0, -1.0 );
737 setImage(image.mirror(FALSE,TRUE)); 737 setImage(image.mirror(FALSE,TRUE));
738} 738}
739 739
740void ImageViewer::rot180() 740void ImageViewer::rot180()
741{ 741{
742// matrix.rotate( 180.0 ); 742// matrix.rotate( 180.0 );
743 setImage(image.mirror(TRUE,TRUE)); 743 setImage(image.mirror(TRUE,TRUE));
744} 744}
745 745
746void ImageViewer::rot90() 746void ImageViewer::rot90()
747{ 747{
748 QImage oldimage; 748 QImage oldimage;
749 oldimage = image.convertDepth(32); 749 oldimage = image.convertDepth(32);
750// matrix.rotate( -90.0 ); 750// matrix.rotate( -90.0 );
751 setImage(rotate(oldimage,Rotate90)); 751 setImage(rotate(oldimage,Rotate90));
752 752
753} 753}
754void ImageViewer::rot270() 754void ImageViewer::rot270()
755{ 755{
756 756
757 QImage oldimage; 757 QImage oldimage;
758 oldimage = image.convertDepth(32); 758 oldimage = image.convertDepth(32);
759// matrix.rotate(90.0); 759// matrix.rotate(90.0);
760 setImage(rotate(oldimage,Rotate270)); 760 setImage(rotate(oldimage,Rotate270));
761 761
762} 762}
763 763
764void ImageViewer::blackAndWhite() 764void ImageViewer::blackAndWhite()
765{ 765{
766 766
767 viewMenuView->setItemEnabled(BLACKANDWHITE,false); 767 viewMenuView->setItemEnabled(BLACKANDWHITE,false);
768 setImage(toGray(image,false)); 768 setImage(toGray(image,false));
769} 769}
770 770
771void ImageViewer::displayControlsDialog() 771void ImageViewer::displayControlsDialog()
772{ 772{
773 int w=80; 773 int w=80;
774 int h=w; 774 int h=w;
775 QImage small; 775 QImage small;
776 776
777 if ( image.width()<w ||image.height()<h ) 777 if ( image.width()<w ||image.height()<h )
778 small=image.smoothScale(w,h); 778 small=image.smoothScale(w,h);
779 else 779 else
780 small=image.copy(0,0,w,h); 780 small=image.copy(0,0,w,h);
781 781
782 int newB=0; 782 int newB=0;
783 ControlsDialog *dlg=new ControlsDialog("Image Viewer",small,&newB,this); 783 ControlsDialog *dlg=new ControlsDialog("Image Viewer",small,&newB,this);
784 dlg->exec(); 784 dlg->exec();
785 if ( newB ) { 785 if ( newB ) {
786 intensity(image,(float)newB/100); 786 intensity(image,(float)newB/100);
787 setImage(image); 787 setImage(image);
788 } 788 }
789 789
790} 790}
791 791
792 792
793void ImageViewer::displayInfoDialog() 793void ImageViewer::displayInfoDialog()
794{ 794{
795 795
796 QStringList ls; 796 QStringList ls;
797 797
798 for ( int i=0;i<LAST;i++ ) 798 for ( int i=0;i<LAST;i++ )
799 ls.append(imageInfo[i]); 799 ls.append(imageInfo[i]);
800 800
801 InfoDialog::displayInfo("Image Viewer",ls,this); 801 InfoDialog::displayInfo("Image Viewer",ls,this);
802} 802}
803void ImageViewer::normalView() 803void ImageViewer::normalView()
804{ 804{
805 if ( !imagePanel->parentWidget() ) 805 if ( !imagePanel->parentWidget() )
806 { 806 {
807 807
808 isFullScreen = FALSE; 808 isFullScreen = FALSE;
809 stack->addWidget( imagePanel, 1 ); 809 stack->addWidget( imagePanel, 1 );
810 switchToImageView(); 810 switchToImageView();
811 if ( isSized ) 811 if ( isSized )
812 scale(); 812 scale();
813 813
814 updateImage(); 814 updateImage();
815 815
816 } 816 }
817} 817}
818 818
819void ImageViewer::stopSlideShow() { 819void ImageViewer::stopSlideShow() {
820 if (slideTimer->isActive()) 820 if (slideTimer->isActive())
821 slideTimer->stop(); 821 slideTimer->stop();
822} 822}
823 823
824void ImageViewer::fullScreen() 824void ImageViewer::fullScreen()
825{ 825{
826 // Full-screen option 826 // Full-screen option
827 // contributed by Robert Wittams <robert@wittams.com> 827 // contributed by Robert Wittams <robert@wittams.com>
828 if ( imagePanel->parentWidget() && loadSelected() ) 828 if ( imagePanel->parentWidget() && loadSelected() )
829 { 829 {
830 isFullScreen = TRUE; 830 isFullScreen = TRUE;
831 imagePanel->reparent(0,QPoint(0,0)); 831 imagePanel->reparent(0,QPoint(0,0));
832 imagePanel->resize(qApp->desktop()->width(), qApp->desktop()->height()); 832 imagePanel->resize(qApp->desktop()->width(), qApp->desktop()->height());
833 833
834 if ( isSized ) 834 if ( isSized )
835 scale(); 835 scale();
836 updateImage(); 836 updateImage();
837 imagePanel->showFullScreen(); 837 imagePanel->showFullScreen();
838 } 838 }
839} 839}
840 840
841void ImageViewer::setImage(const QImage& newimage) 841void ImageViewer::setImage(const QImage& newimage)
842{ 842{
843 image = newimage; 843 image = newimage;
844 reconvertImage(); 844 reconvertImage();
845 updateImage(); 845 updateImage();
846} 846}
847 847
848void ImageViewer::updateImageInfo(QString &filePath) 848void ImageViewer::updateImageInfo(QString &filePath)
849{ 849{
850 850
851 for ( int i=0;i<LAST;i++ ) 851 for ( int i=0;i<LAST;i++ )
852 { 852 {
853 imageInfo[i]=""; 853 imageInfo[i]="";
854 } 854 }
855 855
856 imageInfo[FORMAT]=QImage::imageFormat (filePath ); 856 imageInfo[FORMAT]=QImage::imageFormat (filePath );
857 QFileInfo fi(filePath); 857 QFileInfo fi(filePath);
858 imageInfo[PATH]=fi.fileName(); 858 imageInfo[PATH]=fi.fileName();
859 imageInfo[FILE_SIZE]=QString::number(fi.size())+" (bytes)"; 859 imageInfo[FILE_SIZE]=QString::number(fi.size())+" (bytes)";
860 QString message("%1x%2"); 860 QString message("%1x%2");
861 imageInfo[SIZE]=QString("%1x%2"); 861 imageInfo[SIZE]=QString("%1x%2");
862 imageInfo[SIZE]=imageInfo[SIZE].arg(image.width()).arg(image.height()); 862 imageInfo[SIZE]=imageInfo[SIZE].arg(image.width()).arg(image.height());
863 if ( image.numColors() > 0 ) 863 if ( image.numColors() > 0 )
864 { 864 {
865 imageInfo[COLORS]=tr("%1 colors").arg(image.numColors()); 865 imageInfo[COLORS]=tr("%1 colors").arg(image.numColors());
866 } 866 }
867 else if ( image.depth() >= 16 ) 867 else if ( image.depth() >= 16 )
868 { 868 {
869 imageInfo[COLORS]=tr(" True color"); 869 imageInfo[COLORS]=tr(" True color");
870 } 870 }
871 if ( image.hasAlphaBuffer() ) 871 if ( image.hasAlphaBuffer() )
872 { 872 {
873 if ( image.depth() == 8 ) 873 if ( image.depth() == 8 )
874 { 874 {
875 int i; 875 int i;
876 bool alpha[256]; 876 bool alpha[256];
877 int nalpha=0; 877 int nalpha=0;
878 878
879 for ( i=0; i<256; i++ ) 879 for ( i=0; i<256; i++ )
880 alpha[i] = FALSE; 880 alpha[i] = FALSE;
881 881
882 for ( i=0; i<image.numColors(); i++ ) 882 for ( i=0; i<image.numColors(); i++ )
883 { 883 {
884 int alevel = image.color(i) >> 24; 884 int alevel = image.color(i) >> 24;
885 if ( !alpha[alevel] ) 885 if ( !alpha[alevel] )
886 { 886 {
887 alpha[alevel] = TRUE; 887 alpha[alevel] = TRUE;
888 nalpha++; 888 nalpha++;
889 } 889 }
890 } 890 }
891 imageInfo[ALPHA]=tr("%1 alpha levels").arg(nalpha); 891 imageInfo[ALPHA]=tr("%1 alpha levels").arg(nalpha);
892 } 892 }
893 else 893 else
894 { 894 {
895 imageInfo[ALPHA]=tr("8-bit alpha channel"); 895 imageInfo[ALPHA]=tr("8-bit alpha channel");
896 } 896 }
897 } 897 }
898 898
899} 899}
900 900
901void ImageViewer::closeEvent( QCloseEvent *e ) 901void ImageViewer::closeEvent( QCloseEvent *e )
902{ 902{
903 if ( stack->visibleWidget() == imagePanel && !bFromDocView ) 903 if ( stack->visibleWidget() == imagePanel && !bFromDocView )
904 { 904 {
905 e->ignore(); 905 e->ignore();
906 open(); 906 open();
907 } 907 }
908 else 908 else
909 { 909 {
910 bFromDocView = FALSE; 910 bFromDocView = FALSE;
911 e->accept(); 911 e->accept();
912 } 912 }
913} 913}
914 914
915// Intensity,toGray and rotate code courtesy of KDE project. 915// Intensity,toGray and rotate code courtesy of KDE project.
916 916
917 917
918QImage& ImageViewer::intensity(QImage &image, float percent) 918QImage& ImageViewer::intensity(QImage &image, float percent)
919{ 919{
920 920
921 int segColors = image.depth() > 8 ? 256 : image.numColors(); 921 int segColors = image.depth() > 8 ? 256 : image.numColors();
922 unsigned char *segTbl = new unsigned char[segColors]; 922 unsigned char *segTbl = new unsigned char[segColors];
923 int pixels = image.depth() > 8 ? image.width()*image.height() : 923 int pixels = image.depth() > 8 ? image.width()*image.height() :
924 image.numColors(); 924 image.numColors();
925 unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() : 925 unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() :
926 (unsigned int *)image.colorTable(); 926 (unsigned int *)image.colorTable();
927 927
928 bool brighten = (percent >= 0); 928 bool brighten = (percent >= 0);
929 if ( percent < 0 ) 929 if ( percent < 0 )
930 percent = -percent; 930 percent = -percent;
931 931
932 if ( brighten ) 932 if ( brighten )
933 { // keep overflow check out of loops 933 { // keep overflow check out of loops
934 for ( int i=0; i < segColors; ++i ) 934 for ( int i=0; i < segColors; ++i )
935 { 935 {
936 int tmp = (int)(i*percent); 936 int tmp = (int)(i*percent);
937 if ( tmp > 255 ) 937 if ( tmp > 255 )
938 tmp = 255; 938 tmp = 255;
939 segTbl[i] = tmp; 939 segTbl[i] = tmp;
940 } 940 }
941 } 941 }
942 else 942 else
943 { 943 {
944 for ( int i=0; i < segColors; ++i ) 944 for ( int i=0; i < segColors; ++i )
945 { 945 {
946 int tmp = (int)(i*percent); 946 int tmp = (int)(i*percent);
947 if ( tmp < 0 ) 947 if ( tmp < 0 )
948 tmp = 0; 948 tmp = 0;
949 segTbl[i] = tmp; 949 segTbl[i] = tmp;
950 } 950 }
951 } 951 }
952 952
953 if ( brighten ) 953 if ( brighten )
954 { // same here 954 { // same here
955 for ( int i=0; i < pixels; ++i ) 955 for ( int i=0; i < pixels; ++i )
956 { 956 {
957 int r = qRed(data[i]); 957 int r = qRed(data[i]);
958 int g = qGreen(data[i]); 958 int g = qGreen(data[i]);
959 int b = qBlue(data[i]); 959 int b = qBlue(data[i]);
960 int a = qAlpha(data[i]); 960 int a = qAlpha(data[i]);
961 r = r + segTbl[r] > 255 ? 255 : r + segTbl[r]; 961 r = r + segTbl[r] > 255 ? 255 : r + segTbl[r];
962 g = g + segTbl[g] > 255 ? 255 : g + segTbl[g]; 962 g = g + segTbl[g] > 255 ? 255 : g + segTbl[g];
963 b = b + segTbl[b] > 255 ? 255 : b + segTbl[b]; 963 b = b + segTbl[b] > 255 ? 255 : b + segTbl[b];
964 data[i] = qRgba(r, g, b,a); 964 data[i] = qRgba(r, g, b,a);
965 } 965 }
966 } 966 }
967 else 967 else
968 { 968 {
969 for ( int i=0; i < pixels; ++i ) 969 for ( int i=0; i < pixels; ++i )
970 { 970 {
971 int r = qRed(data[i]); 971 int r = qRed(data[i]);
972 int g = qGreen(data[i]); 972 int g = qGreen(data[i]);
973 int b = qBlue(data[i]); 973 int b = qBlue(data[i]);
974 int a = qAlpha(data[i]); 974 int a = qAlpha(data[i]);
975 r = r - segTbl[r] < 0 ? 0 : r - segTbl[r]; 975 r = r - segTbl[r] < 0 ? 0 : r - segTbl[r];
976 g = g - segTbl[g] < 0 ? 0 : g - segTbl[g]; 976 g = g - segTbl[g] < 0 ? 0 : g - segTbl[g];
977 b = b - segTbl[b] < 0 ? 0 : b - segTbl[b]; 977 b = b - segTbl[b] < 0 ? 0 : b - segTbl[b];
978 data[i] = qRgba(r, g, b, a); 978 data[i] = qRgba(r, g, b, a);
979 } 979 }
980 } 980 }
981 delete [] segTbl; 981 delete [] segTbl;
982 982
983 return image; 983 return image;
984} 984}
985 985
986QImage& ImageViewer::toGray(QImage &img, bool fast) 986QImage& ImageViewer::toGray(QImage &img, bool fast)
987{ 987{
988 if ( img.width() == 0 || img.height() == 0 ) 988 if ( img.width() == 0 || img.height() == 0 )
989 return img; 989 return img;
990 990
991 if ( fast ) 991 if ( fast )
992 { 992 {
993 if ( img.depth() == 32 ) 993 if ( img.depth() == 32 )
994 { 994 {
995 register uchar * r(img.bits()); 995 register uchar * r(img.bits());
996 register uchar * g(img.bits() + 1); 996 register uchar * g(img.bits() + 1);
997 register uchar * b(img.bits() + 2); 997 register uchar * b(img.bits() + 2);
998 998
999 uchar * end(img.bits() + img.numBytes()); 999 uchar * end(img.bits() + img.numBytes());
1000 1000
1001 while ( r != end ) 1001 while ( r != end )
1002 { 1002 {
1003 1003
1004 *r = *g = *b = (((*r + *g) >> 1) + *b) >> 1; // (r + b + g) / 3 1004 *r = *g = *b = (((*r + *g) >> 1) + *b) >> 1; // (r + b + g) / 3
1005 1005
1006 r += 4; 1006 r += 4;
1007 g += 4; 1007 g += 4;
1008 b += 4; 1008 b += 4;
1009 } 1009 }
1010 } 1010 }
1011 else 1011 else
1012 { 1012 {
1013 for ( int i = 0; i < img.numColors(); i++ ) 1013 for ( int i = 0; i < img.numColors(); i++ )
1014 { 1014 {
1015 register uint r = qRed(img.color(i)); 1015 register uint r = qRed(img.color(i));
1016 register uint g = qGreen(img.color(i)); 1016 register uint g = qGreen(img.color(i));
1017 register uint b = qBlue(img.color(i)); 1017 register uint b = qBlue(img.color(i));
1018 1018
1019 register uint gray = (((r + g) >> 1) + b) >> 1; 1019 register uint gray = (((r + g) >> 1) + b) >> 1;
1020 img.setColor(i, qRgba(gray, gray, gray, qAlpha(img.color(i)))); 1020 img.setColor(i, qRgba(gray, gray, gray, qAlpha(img.color(i))));
1021 } 1021 }
1022 } 1022 }
1023 } 1023 }
1024 else 1024 else
1025 { 1025 {
1026 int pixels = img.depth() > 8 ? img.width()*img.height() : 1026 int pixels = img.depth() > 8 ? img.width()*img.height() :
1027 img.numColors(); 1027 img.numColors();
1028 unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() : 1028 unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() :
1029 (unsigned int *)img.colorTable(); 1029 (unsigned int *)img.colorTable();
1030 int val, i; 1030 int val, i;
1031 for ( i=0; i < pixels; ++i ) 1031 for ( i=0; i < pixels; ++i )
1032 { 1032 {
1033 val = qGray(data[i]); 1033 val = qGray(data[i]);
1034 data[i] = qRgba(val, val, val, qAlpha(data[i])); 1034 data[i] = qRgba(val, val, val, qAlpha(data[i]));
1035 } 1035 }
1036 } 1036 }
1037 return img; 1037 return img;
1038} 1038}
1039 1039
1040 1040
1041QImage ImageViewer::rotate(QImage &img, RotateDirection r) 1041QImage ImageViewer::rotate(QImage &img, RotateDirection r)
1042{ 1042{
1043 QImage dest; 1043 QImage dest;
1044 int x, y; 1044 int x, y;
1045 if ( img.depth() > 8 ) 1045 if ( img.depth() > 8 )
1046 { 1046 {
1047 unsigned int *srcData, *destData; 1047 unsigned int *srcData, *destData;
1048 switch ( r ) 1048 switch ( r )
1049 { 1049 {
1050 case Rotate90: 1050 case Rotate90:
1051 dest.create(img.height(), img.width(), img.depth()); 1051 dest.create(img.height(), img.width(), img.depth());
1052 for ( y=0; y < img.height(); ++y ) 1052 for ( y=0; y < img.height(); ++y )
1053 { 1053 {
1054 srcData = (unsigned int *)img.scanLine(y); 1054 srcData = (unsigned int *)img.scanLine(y);
1055 for ( x=0; x < img.width(); ++x ) 1055 for ( x=0; x < img.width(); ++x )
1056 { 1056 {
1057 destData = (unsigned int *)dest.scanLine(x); 1057 destData = (unsigned int *)dest.scanLine(x);
1058 destData[img.height()-y-1] = srcData[x]; 1058 destData[img.height()-y-1] = srcData[x];
1059 } 1059 }
1060 } 1060 }
1061 break; 1061 break;
1062 case Rotate180: 1062 case Rotate180:
1063 dest.create(img.width(), img.height(), img.depth()); 1063 dest.create(img.width(), img.height(), img.depth());
1064 for ( y=0; y < img.height(); ++y ) 1064 for ( y=0; y < img.height(); ++y )
1065 { 1065 {
1066 srcData = (unsigned int *)img.scanLine(y); 1066 srcData = (unsigned int *)img.scanLine(y);
1067 destData = (unsigned int *)dest.scanLine(img.height()-y-1); 1067 destData = (unsigned int *)dest.scanLine(img.height()-y-1);
1068 for ( x=0; x < img.width(); ++x ) 1068 for ( x=0; x < img.width(); ++x )
1069 destData[img.width()-x-1] = srcData[x]; 1069 destData[img.width()-x-1] = srcData[x];
1070 } 1070 }
1071 break; 1071 break;
1072 case Rotate270: 1072 case Rotate270:
1073 dest.create(img.height(), img.width(), img.depth()); 1073 dest.create(img.height(), img.width(), img.depth());
1074 for ( y=0; y < img.height(); ++y ) 1074 for ( y=0; y < img.height(); ++y )
1075 { 1075 {
1076 srcData = (unsigned int *)img.scanLine(y); 1076 srcData = (unsigned int *)img.scanLine(y);
1077 for ( x=0; x < img.width(); ++x ) 1077 for ( x=0; x < img.width(); ++x )
1078 { 1078 {
1079 destData = (unsigned int *)dest.scanLine(img.width()-x-1); 1079 destData = (unsigned int *)dest.scanLine(img.width()-x-1);
1080 destData[y] = srcData[x]; 1080 destData[y] = srcData[x];
1081 } 1081 }
1082 } 1082 }
1083 break; 1083 break;
1084 default: 1084 default:
1085 dest = img; 1085 dest = img;
1086 break; 1086 break;
1087 } 1087 }
1088 } 1088 }
1089 else 1089 else
1090 { 1090 {
1091 unsigned char *srcData, *destData; 1091 unsigned char *srcData, *destData;
1092 unsigned int *srcTable, *destTable; 1092 unsigned int *srcTable, *destTable;
1093 switch ( r ) 1093 switch ( r )
1094 { 1094 {
1095 case Rotate90: 1095 case Rotate90:
1096 dest.create(img.height(), img.width(), img.depth()); 1096 dest.create(img.height(), img.width(), img.depth());
1097 dest.setNumColors(img.numColors()); 1097 dest.setNumColors(img.numColors());
1098 srcTable = (unsigned int *)img.colorTable(); 1098 srcTable = (unsigned int *)img.colorTable();
1099 destTable = (unsigned int *)dest.colorTable(); 1099 destTable = (unsigned int *)dest.colorTable();
1100 for ( x=0; x < img.numColors(); ++x ) 1100 for ( x=0; x < img.numColors(); ++x )
1101 destTable[x] = srcTable[x]; 1101 destTable[x] = srcTable[x];
1102 for ( y=0; y < img.height(); ++y ) 1102 for ( y=0; y < img.height(); ++y )
1103 { 1103 {
1104 srcData = (unsigned char *)img.scanLine(y); 1104 srcData = (unsigned char *)img.scanLine(y);
1105 for ( x=0; x < img.width(); ++x ) 1105 for ( x=0; x < img.width(); ++x )
1106 { 1106 {
1107 destData = (unsigned char *)dest.scanLine(x); 1107 destData = (unsigned char *)dest.scanLine(x);
1108 destData[img.height()-y-1] = srcData[x]; 1108 destData[img.height()-y-1] = srcData[x];
1109 } 1109 }
1110 } 1110 }
1111 break; 1111 break;
1112 case Rotate180: 1112 case Rotate180:
1113 dest.create(img.width(), img.height(), img.depth()); 1113 dest.create(img.width(), img.height(), img.depth());
1114 dest.setNumColors(img.numColors()); 1114 dest.setNumColors(img.numColors());
1115 srcTable = (unsigned int *)img.colorTable(); 1115 srcTable = (unsigned int *)img.colorTable();
1116 destTable = (unsigned int *)dest.colorTable(); 1116 destTable = (unsigned int *)dest.colorTable();
1117 for ( x=0; x < img.numColors(); ++x ) 1117 for ( x=0; x < img.numColors(); ++x )
1118 destTable[x] = srcTable[x]; 1118 destTable[x] = srcTable[x];
1119 for ( y=0; y < img.height(); ++y ) 1119 for ( y=0; y < img.height(); ++y )
1120 { 1120 {
1121 srcData = (unsigned char *)img.scanLine(y); 1121 srcData = (unsigned char *)img.scanLine(y);
1122 destData = (unsigned char *)dest.scanLine(img.height()-y-1); 1122 destData = (unsigned char *)dest.scanLine(img.height()-y-1);
1123 for ( x=0; x < img.width(); ++x ) 1123 for ( x=0; x < img.width(); ++x )
1124 destData[img.width()-x-1] = srcData[x]; 1124 destData[img.width()-x-1] = srcData[x];
1125 } 1125 }
1126 break; 1126 break;
1127 case Rotate270: 1127 case Rotate270:
1128 dest.create(img.height(), img.width(), img.depth()); 1128 dest.create(img.height(), img.width(), img.depth());
1129 dest.setNumColors(img.numColors()); 1129 dest.setNumColors(img.numColors());
1130 srcTable = (unsigned int *)img.colorTable(); 1130 srcTable = (unsigned int *)img.colorTable();
1131 destTable = (unsigned int *)dest.colorTable(); 1131 destTable = (unsigned int *)dest.colorTable();
1132 for ( x=0; x < img.numColors(); ++x ) 1132 for ( x=0; x < img.numColors(); ++x )
1133 destTable[x] = srcTable[x]; 1133 destTable[x] = srcTable[x];
1134 for ( y=0; y < img.height(); ++y ) 1134 for ( y=0; y < img.height(); ++y )
1135 { 1135 {
1136 srcData = (unsigned char *)img.scanLine(y); 1136 srcData = (unsigned char *)img.scanLine(y);
1137 for ( x=0; x < img.width(); ++x ) 1137 for ( x=0; x < img.width(); ++x )
1138 { 1138 {
1139 destData = (unsigned char *)dest.scanLine(img.width()-x-1); 1139 destData = (unsigned char *)dest.scanLine(img.width()-x-1);
1140 destData[y] = srcData[x]; 1140 destData[y] = srcData[x];
1141 } 1141 }
1142 } 1142 }
1143 break; 1143 break;
1144 default: 1144 default:
1145 dest = img; 1145 dest = img;
1146 break; 1146 break;
1147 } 1147 }
1148 1148
1149 } 1149 }
1150 return (dest); 1150 return (dest);
1151} 1151}
1152 1152
1153void ImageViewer::slideShow( bool on ) 1153void ImageViewer::slideShow( bool on )
1154{ 1154{
1155 if (on) { 1155 if (on) {
1156 if (!imageList.isEmpty()) { 1156 if (!imageList.isEmpty()) {
1157 slideTimer->start(slideDelay * 1000, FALSE); 1157 slideTimer->start(slideDelay * 1000, FALSE);
1158 filename = ""; // force restart 1158 filename = ""; // force restart
1159 slideReverse ? prevImage() : nextImage(); 1159 slideReverse ? prevImage() : nextImage();
1160 } 1160 }
1161 } else { 1161 } else {
1162 slideTimer->stop(); 1162 slideTimer->stop();
1163 slideAction->setOn( false); 1163 slideAction->setOn( false);
1164 } 1164 }
1165} 1165}
1166 1166
1167void ImageViewer::slideUpdate() 1167void ImageViewer::slideUpdate()
1168{ 1168{
1169 bool final_image = slideReverse ? prevImage() : nextImage(); 1169 bool final_image = slideReverse ? prevImage() : nextImage();
1170 1170
1171 if (final_image && !slideRepeat) { 1171 if (final_image && !slideRepeat) {
1172 slideTimer->stop(); 1172 slideTimer->stop();
1173 slideAction->setOn(FALSE); 1173 slideAction->setOn(FALSE);
1174 } 1174 }
1175} 1175}
1176 1176
1177// 1177//
1178// Display the image after the current one in the image list. 1178// Display the image after the current one in the image list.
1179// Return TRUE if the next call to nextImage() will wrap around to the 1179// Return TRUE if the next call to nextImage() will wrap around to the
1180// first image in the list (ie. we're now viewing the last image in the list). 1180// first image in the list (ie. we're now viewing the last image in the list).
1181// 1181//
1182bool ImageViewer::nextImage(void) 1182bool ImageViewer::nextImage(void)
1183{ 1183{
1184 int idx = 0; 1184 int idx = 0;
1185 1185
1186 if (imageList.count() > 0) { 1186 if (imageList.count() > 0) {
1187 idx = imageIndex(); 1187 idx = imageIndex();
1188 if (idx != -1) { 1188 if (idx != -1) {
1189 if (idx == int(imageList.count() - 1)) { 1189 if (idx == int(imageList.count() - 1)) {
1190 idx = 0; 1190 idx = 0;
1191 } else { 1191 } else {
1192 idx++; 1192 idx++;
1193 } 1193 }
1194 } else { 1194 } else {
1195 idx = 0; 1195 idx = 0;
1196 } 1196 }
1197 openFile(imageList[idx]); 1197 openFile(imageList[idx]);
1198 } 1198 }
1199 1199
1200 return idx == int(imageList.count() - 1) ? TRUE : FALSE; 1200 return idx == int(imageList.count() - 1) ? TRUE : FALSE;
1201} 1201}
1202 1202
1203// 1203//
1204// Display the image preceeding the current one in the image list. 1204// Display the image preceeding the current one in the image list.
1205// Return TRUE if the next call to prevImage() will wrap around to the last 1205// Return TRUE if the next call to prevImage() will wrap around to the last
1206// image in the list (ie. we're now viewing the first image in the list). 1206// image in the list (ie. we're now viewing the first image in the list).
1207// 1207//
1208bool ImageViewer::prevImage(void) 1208bool ImageViewer::prevImage(void)
1209{ 1209{
1210 int idx = -1; 1210 int idx = -1;
1211 1211
1212 if (imageList.count() > 0) { 1212 if (imageList.count() > 0) {
1213 idx = imageIndex(); 1213 idx = imageIndex();
1214 if (idx != -1) { 1214 if (idx != -1) {
1215 if (idx == 0) { 1215 if (idx == 0) {
1216 idx = imageList.count() - 1; 1216 idx = imageList.count() - 1;
1217 } else { 1217 } else {
1218 idx--; 1218 idx--;
1219 } 1219 }
1220 } else { 1220 } else {
1221 idx = imageList.count() - 1; 1221 idx = imageList.count() - 1;
1222 } 1222 }
1223 openFile(imageList[idx]); 1223 openFile(imageList[idx]);
1224 } 1224 }
1225 1225
1226 return idx == 0 ? TRUE : FALSE; 1226 return idx == 0 ? TRUE : FALSE;
1227} 1227}
1228 1228
1229// 1229//
1230// Return the index into the imageList of the currently viewed 1230// Return the index into the imageList of the currently viewed
1231// image (ie. ImageViewer::filename in ImageViewer::imageList). 1231// image (ie. ImageViewer::filename in ImageViewer::imageList).
1232// 1232//
1233int ImageViewer::imageIndex(void) 1233int ImageViewer::imageIndex(void)
1234{ 1234{
1235 QValueListConstIterator<DocLnk> i; 1235 QValueListConstIterator<DocLnk> i;
1236 int index; 1236 int index;
1237 1237
1238 if (imageList.count() == 0) { 1238 if (imageList.count() == 0) {
1239 return -1; 1239 return -1;
1240 } 1240 }
1241 1241
1242 for (index = 0, i = imageList.begin(); i != imageList.end(); ++i, index++) { 1242 for (index = 0, i = imageList.begin(); i != imageList.end(); ++i, index++) {
1243 if ((*i).file() == filename) { 1243 if ((*i).file() == filename) {
1244 return index; 1244 return index;
1245 } 1245 }
1246 } 1246 }
1247 1247
1248 return -1; 1248 return -1;
1249} 1249}