summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/showimg/showimg.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/multimedia/showimg/showimg.cpp b/noncore/multimedia/showimg/showimg.cpp
index 7c43e11..24218e6 100644
--- a/noncore/multimedia/showimg/showimg.cpp
+++ b/noncore/multimedia/showimg/showimg.cpp
@@ -1,329 +1,329 @@
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 26
27#include <qpe/resource.h> 27#include <qpe/resource.h>
28#include <qpe/fileselector.h> 28#include <qpe/fileselector.h>
29#include <qpe/applnk.h> 29#include <qpe/applnk.h>
30 30
31#include <qpe/qpemenubar.h> 31#include <qpe/qpemenubar.h>
32#include <qwidgetstack.h> 32#include <qwidgetstack.h>
33#include <qpe/qpetoolbar.h> 33#include <qpe/qpetoolbar.h>
34#include <qaction.h> 34#include <qaction.h>
35#include <qfiledialog.h> 35#include <qfiledialog.h>
36#include <qmessagebox.h> 36#include <qmessagebox.h>
37#include <qpopupmenu.h> 37#include <qpopupmenu.h>
38#include <qlabel.h> 38#include <qlabel.h>
39#include <qpainter.h> 39#include <qpainter.h>
40#include <qkeycode.h> 40#include <qkeycode.h>
41#include <qapplication.h> 41#include <qapplication.h>
42#include <qclipboard.h> 42#include <qclipboard.h>
43#include <qtimer.h> 43#include <qtimer.h>
44 44
45 45
46ImagePane::ImagePane( QWidget *parent ) : QWidget( parent ) 46ImagePane::ImagePane( QWidget *parent ) : QWidget( parent )
47{ 47{
48 vb = new QVBoxLayout( this ); 48 vb = new QVBoxLayout( this );
49 49
50 image = new ImageWidget( this ); 50 image = new ImageWidget( this );
51 connect(image, SIGNAL( clicked() ), this, SLOT( imageClicked() )); 51 connect(image, SIGNAL( clicked() ), this, SLOT( imageClicked() ));
52 52
53 vb->addWidget( image ); 53 vb->addWidget( image );
54 54
55 status = new QLabel( this ); 55 status = new QLabel( this );
56 status->setFixedHeight( fontMetrics().height() + 4 ); 56 status->setFixedHeight( fontMetrics().height() + 4 );
57 vb->addWidget( status ); 57 vb->addWidget( status );
58} 58}
59 59
60void ImagePane::setPixmap( const QPixmap &pm ) 60void ImagePane::setPixmap( const QPixmap &pm )
61{ 61{
62 image->setPixmap( pm ); 62 image->setPixmap( pm );
63 image->repaint( false ); 63 image->repaint( false );
64} 64}
65 65
66void ImagePane::imageClicked() 66void ImagePane::imageClicked()
67{ 67{
68 emit clicked(); 68 emit clicked();
69} 69}
70 70
71void ImagePane::showStatus() 71void ImagePane::showStatus()
72{ 72{
73 delete vb; 73 delete vb;
74 vb = new QVBoxLayout( this ); 74 vb = new QVBoxLayout( this );
75 vb->addWidget( image ); 75 vb->addWidget( image );
76 status->show(); 76 status->show();
77 vb->addWidget( status ); 77 vb->addWidget( status );
78} 78}
79 79
80 80
81void ImagePane::hideStatus() 81void ImagePane::hideStatus()
82{ 82{
83 delete vb; 83 delete vb;
84 vb = new QVBoxLayout( this ); 84 vb = new QVBoxLayout( this );
85 vb->addWidget( image ); 85 vb->addWidget( image );
86 status->hide(); 86 status->hide();
87} 87}
88 88
89//=========================================================================== 89//===========================================================================
90/* 90/*
91 Draws the portion of the scaled pixmap that needs to be updated 91 Draws the portion of the scaled pixmap that needs to be updated
92*/ 92*/
93 93
94void ImageWidget::paintEvent( QPaintEvent *e ) 94void ImageWidget::paintEvent( QPaintEvent *e )
95{ 95{
96 QPainter painter(this); 96 QPainter painter(this);
97 97
98 painter.setClipRect(e->rect()); 98 painter.setClipRect(e->rect());
99 painter.setBrush( black ); 99 painter.setBrush( black );
100 painter.drawRect( 0, 0, width(), height() ); 100 painter.drawRect( 0, 0, width(), height() );
101 101
102 if ( pixmap.size() != QSize( 0, 0 ) ) { // is an image loaded? 102 if ( pixmap.size() != QSize( 0, 0 ) ) { // is an image loaded?
103 painter.drawPixmap((width() - pixmap.width()) / 2, (height() - pixmap.height()) / 2, pixmap); 103 painter.drawPixmap((width() - pixmap.width()) / 2, (height() - pixmap.height()) / 2, pixmap);
104 } 104 }
105} 105}
106 106
107void ImageWidget::mouseReleaseEvent(QMouseEvent *) 107void ImageWidget::mouseReleaseEvent(QMouseEvent *)
108{ 108{
109 emit clicked(); 109 emit clicked();
110} 110}
111 111
112 112
113//=========================================================================== 113//===========================================================================
114 114
115ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags ) 115ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
116 : QMainWindow( parent, name, wFlags ), filename( 0 ), 116 : QMainWindow( parent, name, wFlags ), filename( 0 ),
117 pickx( -1 ), picky( -1 ), clickx( -1 ), clicky( -1 ), bFromDocView( FALSE ) 117 pickx( -1 ), picky( -1 ), clickx( -1 ), clicky( -1 ), bFromDocView( FALSE )
118{ 118{
119 setCaption( tr("Image Viewer") ); 119 setCaption( tr("Image Viewer") );
120 setIcon( Resource::loadPixmap( "ImageViewer" ) ); 120 setIcon( Resource::loadPixmap( "ImageViewer" ) );
121 121
122 isFullScreen = FALSE; 122 isFullScreen = FALSE;
123 123
124 setToolBarsMovable( FALSE ); 124 setToolBarsMovable( FALSE );
125 125
126 toolBar = new QPEToolBar( this ); 126 toolBar = new QPEToolBar( this );
127 toolBar->setHorizontalStretchable( TRUE ); 127 toolBar->setHorizontalStretchable( TRUE );
128 128
129 menubar = new QPEMenuBar( toolBar ); 129 menubar = new QPEMenuBar( toolBar );
130 130
131 QStrList fmt = QImage::outputFormats(); 131 QStrList fmt = QImage::outputFormats();
132 132
133 QPopupMenu *edit = new QPopupMenu( menubar ); 133 QPopupMenu *edit = new QPopupMenu( menubar );
134 QPopupMenu *view = new QPopupMenu( menubar ); 134 QPopupMenu *view = new QPopupMenu( menubar );
135 135
136 menubar->insertItem( "Edit", edit ); 136 menubar->insertItem(tr("Edit"), edit );
137 menubar->insertItem( "View", view ); 137 menubar->insertItem(tr("View"), view );
138 138
139 edit->insertItem(tr("Horizontal flip"), this, SLOT(hFlip()), 0); 139 edit->insertItem(tr("Horizontal flip"), this, SLOT(hFlip()), 0);
140 edit->insertItem(tr("Vertical flip"), this, SLOT(vFlip()), 0); 140 edit->insertItem(tr("Vertical flip"), this, SLOT(vFlip()), 0);
141 141
142 stack = new QWidgetStack( this ); 142 stack = new QWidgetStack( this );
143 stack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); 143 stack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
144 setCentralWidget( stack ); 144 setCentralWidget( stack );
145 145
146 imagePanel = new ImagePane( stack ); 146 imagePanel = new ImagePane( stack );
147 connect(imagePanel, SIGNAL(clicked()), this, SLOT(normalView())); 147 connect(imagePanel, SIGNAL(clicked()), this, SLOT(normalView()));
148 148
149 fileSelector = new FileSelector("image/*", stack, "fs"); 149 fileSelector = new FileSelector("image/*", stack, "fs");
150 fileSelector->setNewVisible(FALSE); 150 fileSelector->setNewVisible(FALSE);
151 fileSelector->setCloseVisible(FALSE); 151 fileSelector->setCloseVisible(FALSE);
152 connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( closeFileSelector() ) ); 152 connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( closeFileSelector() ) );
153 connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); 153 connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) );
154 154
155 toolBar = new QPEToolBar( this ); 155 toolBar = new QPEToolBar( this );
156 156
157 QAction *a; 157 QAction *a;
158 158
159 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); 159 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
160 connect( a, SIGNAL( activated() ), this, SLOT( open() ) ); 160 connect( a, SIGNAL( activated() ), this, SLOT( open() ) );
161 a->addTo( toolBar ); 161 a->addTo( toolBar );
162 162
163 a = new QAction( tr( "Rotate 180" ), Resource::loadPixmap( "repeat" ), QString::null, 0, this, 0 ); 163 a = new QAction( tr( "Rotate 180" ), Resource::loadPixmap( "repeat" ), QString::null, 0, this, 0 );
164 connect( a, SIGNAL( activated() ), this, SLOT( rot180() ) ); 164 connect( a, SIGNAL( activated() ), this, SLOT( rot180() ) );
165 a->addTo( toolBar ); 165 a->addTo( toolBar );
166 a->addTo( edit ); 166 a->addTo( edit );
167 167
168 a = new QAction( tr( "Rotate 90"), Resource::loadPixmap( "rotate90" ), QString::null, 0, this, 0); 168 a = new QAction( tr( "Rotate 90"), Resource::loadPixmap( "rotate90" ), QString::null, 0, this, 0);
169 connect( a, SIGNAL( activated() ), this, SLOT( rot90() ) ); 169 connect( a, SIGNAL( activated() ), this, SLOT( rot90() ) );
170 a->addTo( toolBar ); 170 a->addTo( toolBar );
171 a->addTo( edit ); 171 a->addTo( edit );
172 172
173 a = new QAction( tr( "Fullscreen" ), Resource::loadPixmap( "fullscreen" ), QString::null, 0, this, 0 ); 173 a = new QAction( tr( "Fullscreen" ), Resource::loadPixmap( "fullscreen" ), QString::null, 0, this, 0 );
174 connect( a, SIGNAL( activated() ), this, SLOT( fullScreen() ) ); 174 connect( a, SIGNAL( activated() ), this, SLOT( fullScreen() ) );
175 a->addTo( toolBar ); 175 a->addTo( toolBar );
176 a->addTo( view); 176 a->addTo( view);
177 177
178 stack->raiseWidget( fileSelector ); 178 stack->raiseWidget( fileSelector );
179 179
180 setMouseTracking( TRUE ); 180 setMouseTracking( TRUE );
181} 181}
182 182
183ImageViewer::~ImageViewer() 183ImageViewer::~ImageViewer()
184{ 184{
185 delete imagePanel; // in case it is fullscreen 185 delete imagePanel; // in case it is fullscreen
186} 186}
187 187
188void ImageViewer::setDocument(const QString& fileref) 188void ImageViewer::setDocument(const QString& fileref)
189{ 189{
190 delayLoad = fileref; 190 delayLoad = fileref;
191 stack->raiseWidget(imagePanel); 191 stack->raiseWidget(imagePanel);
192 QTimer::singleShot( 0, this, SLOT(doDelayedLoad()) ); 192 QTimer::singleShot( 0, this, SLOT(doDelayedLoad()) );
193} 193}
194 194
195void ImageViewer::doDelayedLoad() 195void ImageViewer::doDelayedLoad()
196{ 196{
197 show(delayLoad); 197 show(delayLoad);
198} 198}
199 199
200void ImageViewer::show() 200void ImageViewer::show()
201{ 201{
202 normalView(); 202 normalView();
203 QMainWindow::show(); 203 QMainWindow::show();
204} 204}
205 205
206void ImageViewer::show(const QString& fileref) 206void ImageViewer::show(const QString& fileref)
207{ 207{
208 bFromDocView = TRUE; 208 bFromDocView = TRUE;
209 closeFileSelector(); 209 closeFileSelector();
210 DocLnk link(fileref); 210 DocLnk link(fileref);
211 if ( link.isValid() ) { 211 if ( link.isValid() ) {
212 openFile(link); 212 openFile(link);
213 } else { 213 } else {
214 filename = fileref; 214 filename = fileref;
215 updateCaption( fileref ); 215 updateCaption( fileref );
216 loadImage( fileref ); 216 loadImage( fileref );
217 } 217 }
218} 218}
219 219
220void ImageViewer::openFile( const DocLnk &file ) 220void ImageViewer::openFile( const DocLnk &file )
221{ 221{
222 closeFileSelector(); 222 closeFileSelector();
223 DocLnk link(file); 223 DocLnk link(file);
224 updateCaption( link.name() ); 224 updateCaption( link.name() );
225 loadImage( link.file() ); 225 loadImage( link.file() );
226} 226}
227 227
228void ImageViewer::open() 228void ImageViewer::open()
229{ 229{
230 stack->raiseWidget(fileSelector); 230 stack->raiseWidget(fileSelector);
231} 231}
232 232
233void ImageViewer::closeFileSelector() 233void ImageViewer::closeFileSelector()
234{ 234{
235 stack->raiseWidget(imagePanel); 235 stack->raiseWidget(imagePanel);
236} 236}
237 237
238void ImageViewer::updateCaption( QString name ) 238void ImageViewer::updateCaption( QString name )
239{ 239{
240 int sep = name.findRev( '/' ); 240 int sep = name.findRev( '/' );
241 if ( sep >= 0 ) 241 if ( sep >= 0 )
242 name = name.mid( sep+1 ); 242 name = name.mid( sep+1 );
243 setCaption( name + tr(" - Image Viewer") ); 243 setCaption( name + tr(" - Image Viewer") );
244} 244}
245 245
246/* 246/*
247 This function loads an image from a file. 247 This function loads an image from a file.
248*/ 248*/
249 249
250void ImageViewer::loadImage( const char *fileName ) 250void ImageViewer::loadImage( const char *fileName )
251{ 251{
252 filename = fileName; 252 filename = fileName;
253 if ( filename ) { 253 if ( filename ) {
254 QApplication::setOverrideCursor( waitCursor ); // this might take time 254 QApplication::setOverrideCursor( waitCursor ); // this might take time
255 imagePanel->statusLabel()->setText( tr("Loading image...") ); 255 imagePanel->statusLabel()->setText( tr("Loading image...") );
256 qApp->processEvents(); 256 qApp->processEvents();
257 bool ok = image.load(filename, 0); 257 bool ok = image.load(filename, 0);
258 pickx = -1; 258 pickx = -1;
259 clickx = -1; 259 clickx = -1;
260 if ( ok ) 260 if ( ok )
261 ok = reconvertImage(); 261 ok = reconvertImage();
262 if ( !ok ) { 262 if ( !ok ) {
263 pm.resize(0,0); // couldn't load image 263 pm.resize(0,0); // couldn't load image
264 update(); 264 update();
265 } 265 }
266 QApplication::restoreOverrideCursor();// restore original cursor 266 QApplication::restoreOverrideCursor();// restore original cursor
267 } 267 }
268 updateStatus(); 268 updateStatus();
269 imagePanel->setPixmap( pmScaled ); 269 imagePanel->setPixmap( pmScaled );
270 stack->raiseWidget(imagePanel); 270 stack->raiseWidget(imagePanel);
271} 271}
272 272
273bool ImageViewer::loadSelected() 273bool ImageViewer::loadSelected()
274{ 274{
275 bool ok = false; 275 bool ok = false;
276 if ( stack->visibleWidget() == fileSelector ) { 276 if ( stack->visibleWidget() == fileSelector ) {
277 const DocLnk *link = fileSelector->selected(); 277 const DocLnk *link = fileSelector->selected();
278 if ( link ) { 278 if ( link ) {
279 if ( link->file() != filename ) { 279 if ( link->file() != filename ) {
280 updateCaption( link->name() ); 280 updateCaption( link->name() );
281 filename = link->file(); 281 filename = link->file();
282 imagePanel->statusLabel()->setText( tr("Loading image...") ); 282 imagePanel->statusLabel()->setText( tr("Loading image...") );
283 qApp->processEvents(); 283 qApp->processEvents();
284 ok = image.load(filename, 0); 284 ok = image.load(filename, 0);
285 if ( ok ) 285 if ( ok )
286 ok = reconvertImage(); 286 ok = reconvertImage();
287 if ( !ok ) 287 if ( !ok )
288 pm.resize(0,0); 288 pm.resize(0,0);
289 } 289 }
290 } 290 }
291 } 291 }
292 if ( !image.isNull() ) { 292 if ( !image.isNull() ) {
293 ok = true; 293 ok = true;
294 closeFileSelector(); 294 closeFileSelector();
295 } 295 }
296 296
297 return ok; 297 return ok;
298} 298}
299 299
300bool ImageViewer::reconvertImage() 300bool ImageViewer::reconvertImage()
301{ 301{
302 bool success = FALSE; 302 bool success = FALSE;
303 303
304 if ( image.isNull() ) return FALSE; 304 if ( image.isNull() ) return FALSE;
305 305
306 QApplication::setOverrideCursor( waitCursor ); // this might take time 306 QApplication::setOverrideCursor( waitCursor ); // this might take time
307 if ( pm.convertFromImage(image /*, conversion_flags */ ) ) 307 if ( pm.convertFromImage(image /*, conversion_flags */ ) )
308 { 308 {
309 pmScaled = QPixmap(); 309 pmScaled = QPixmap();
310 scale(); 310 scale();
311 success = TRUE; // load successful 311 success = TRUE; // load successful
312 } else { 312 } else {
313 pm.resize(0,0); // couldn't load image 313 pm.resize(0,0); // couldn't load image
314 } 314 }
315 QApplication::restoreOverrideCursor();// restore original cursor 315 QApplication::restoreOverrideCursor();// restore original cursor
316 316
317 return success; // TRUE if loaded OK 317 return success; // TRUE if loaded OK
318} 318}
319 319
320 320
321int ImageViewer::calcHeight() 321int ImageViewer::calcHeight()
322{ 322{
323 if ( !isFullScreen) 323 if ( !isFullScreen)
324 return height() - menubar->heightForWidth( width() ) 324 return height() - menubar->heightForWidth( width() )
325 - imagePanel->statusLabel()->height(); 325 - imagePanel->statusLabel()->height();
326 else 326 else
327 return qApp->desktop()->height(); 327 return qApp->desktop()->height();
328} 328}
329/* 329/*