summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-11-03 18:14:36 (UTC)
committer llornkcor <llornkcor>2002-11-03 18:14:36 (UTC)
commit7d282e8e721d4c7c71a6d308d082da7138139484 (patch) (side-by-side diff)
treecd37bc23214230258054562657a1d5eff49232b7
parent8b3893f3b11731151c19274d2c9ed22d7a00a2b3 (diff)
downloadopie-7d282e8e721d4c7c71a6d308d082da7138139484.zip
opie-7d282e8e721d4c7c71a6d308d082da7138139484.tar.gz
opie-7d282e8e721d4c7c71a6d308d082da7138139484.tar.bz2
fix ofileselector open
Diffstat (more/less context) (show 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
@@ -154,769 +154,769 @@ void InfoDialog::displayInfo(const QString &caption, const QStringList text, QWi
dlg->exec();
delete dlg;
}
//===========================================================================
ImagePane::ImagePane( QWidget *parent ) : QWidget( parent )
{
vb = new QVBoxLayout( this );
image = new QScrollView(this,0,WResizeNoErase|WNorthWestGravity);
pic=new ImageWidget(image);
image->addChild(pic);
connect(pic, SIGNAL( clicked() ), this, SLOT( imageClicked() ));
vb->addWidget( image );
}
void ImagePane::setPixmap( const QPixmap &pm )
{
pic->setPixmap( pm );
pic->resize(pm.width(),pm.height());
image->updateScrollBars ();
pic->repaint(false);
}
void ImagePane::imageClicked()
{
emit clicked();
}
//===========================================================================
/*
Draws the portion of the scaled pixmap that needs to be updated
*/
void ImageWidget::paintEvent( QPaintEvent *e )
{
QPainter painter(this);
painter.setClipRect(e->rect());
painter.fillRect(0,0,width(),height(),QColor(0,0,0));
if ( pixmap.size() != QSize( 0, 0 ) )
{ // is an image loaded?
painter.drawPixmap((width() - pixmap.width()) / 2, (height() - pixmap.height()) / 2, pixmap);
}
}
void ImageWidget::mouseReleaseEvent(QMouseEvent *)
{
emit clicked();
}
//===========================================================================
ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
: QMainWindow( parent, name, wFlags ), filename( 0 ), bFromDocView( FALSE )
{
setCaption( tr("Image Viewer") );
setIcon( Resource::loadPixmap( "ImageViewer" ) );
Config cfg("Image Viewer");
cfg.setGroup("Image Viewer");
showThumbView=cfg.readBoolEntry("ShowThumbnails",false);
isSized=cfg.readBoolEntry("SizeToScreen",true);
isFullScreen = FALSE;
setToolBarsMovable( FALSE );
toolBar = new QPEToolBar( this );
toolBar->setHorizontalStretchable( TRUE );
menuBar = new QPEMenuBar( toolBar );
current=menuBar;
fileMenuFile = new QPopupMenu(this);
//menuBarmenubarFile->insertItem( tr("File"), fileMenu );
fileMenuFile->insertItem(tr("Open"),
this, SLOT(openFile()), 0);
viewMenuFile = new QPopupMenu( this );
//menubarFile->insertItem( tr("View"), viewMenu );
viewMenuFile->insertItem( tr("Thumbnail View"),
this, SLOT(switchThumbView()), 0, SHOW_THUMBNAILS );
viewMenuFile->setItemChecked ( SHOW_THUMBNAILS, showThumbView );
optionsMenuFile = new QPopupMenu( this);
//menubarFile->insertItem( tr("Options"),optionsMenu );
slideAction = new QAction( tr( "Slide show" ), Resource::loadIconSet( "slideshow" ),
QString::null, 0, this, 0 );
slideAction->setToggleAction( TRUE );
connect( slideAction, SIGNAL( toggled(bool) ), this, SLOT( slideShow(bool) ) );
slideAction->addTo( optionsMenuFile);
// slideAction->addTo( toolBar );
// optionsMenuFile->insertItem( tr("Slideshow") );
optionsMenuFile->insertSeparator();
optionsMenuFile->insertItem( tr("Preferences.."), this, SLOT(settings()), 0);
// optionsMenuFile->insertItem( tr("Help"), this, SLOT(help()), 0);
QStrList fmt = QImage::outputFormats();
fileMenuView = new QPopupMenu( this );
//menubarView->insertItem( tr("File"),fileMenu );
fileMenuView->insertItem( tr("Image Info ..."),this, SLOT(displayInfoDialog()),0 );
fileMenuView->insertSeparator();
viewMenuView = new QPopupMenu(this );
viewMenuView->setCheckable ( true );
//menubarView->insertItem( tr("View"),viewMenu );
viewMenuView->insertItem(tr("Horizontal flip"), this, SLOT(hFlip()), 0);
viewMenuView->insertItem(tr("Vertical flip"), this, SLOT(vFlip()), 0);
stack = new QWidgetStack( this );
stack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
setCentralWidget( stack );
imagePanel = new ImagePane( stack );
connect(imagePanel, SIGNAL(clicked()), this, SLOT(normalView()));
ImageFileSelector::CURRENT_VIEW cv;
if(showThumbView)
cv=ImageFileSelector::THUMBNAIL;
else
cv=ImageFileSelector::DETAILED;
qDebug("cv = %d",cv);
fileSelector = new ImageFileSelector( cv,stack, "fs");
//switchThumbView();
//fileSelector = new ImageFileSelector("image/*", stack, "fs");
//fileSelector->setNewVisible(FALSE);
//fileSelector->setCloseVisible(FALSE);
connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( closeFileSelector() ) );
connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ),
this, SLOT( openFile( const DocLnk & ) ) );
imageList = fileSelector->fileList();
slideAction->setEnabled( imageList.count() != 0);
iconToolBar = new QPEToolBar(this);
QAction *a;
a = new QAction( tr( "Open ..." ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( open() ) );
a->addTo( fileMenuView);
a->addTo( iconToolBar );
a = new QAction( tr( "Rotate 90"), Resource::loadPixmap( "rotate90" ), QString::null, 0, this, 0);
connect( a, SIGNAL( activated() ), this, SLOT( rot90() ) );
a->addTo( iconToolBar );
a->addTo( viewMenuView );
a = new QAction( tr( "Rotate 180" ), Resource::loadPixmap( "repeat" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( rot180() ) );
a->addTo( iconToolBar );
a->addTo( viewMenuView );
a = new QAction( tr( "Rotate 270"), Resource::loadPixmap( "rotate270" ), QString::null, 0, this, 0);
connect( a, SIGNAL( activated() ), this, SLOT( rot270() ) );
//a->addTo( iconToolBar );
a->addTo( viewMenuView );
viewMenuView->insertSeparator();
viewMenuView->insertItem(tr("Brightness ..."), this, SLOT(displayControlsDialog()), 0);
viewMenuView->insertItem(tr("Black And White"), this, SLOT(blackAndWhite()), 0,BLACKANDWHITE);
viewMenuView->insertSeparator();
sss = new QAction( tr( "Scale to Screen"), Resource::loadPixmap( "scale" ), QString::null, 0, this, 0,true);
connect( sss, SIGNAL( activated() ), this, SLOT( switchSizeToScreen() ) );
sss->addTo( iconToolBar );
sss->addTo( viewMenuView );
sss->setOn(isSized);
viewMenuView->insertSeparator();
a = new QAction( tr( "Fullscreen" ), Resource::loadPixmap( "fullscreen" ),
QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( fullScreen() ) );
a->addTo( iconToolBar );
a->addTo( viewMenuView);
a = new QAction( tr( "Stop Slideshow" ), Resource::loadPixmap( "quit_icon" ),
QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( stopSlideShow() ) );
a->addTo( iconToolBar );
a->addTo( viewMenuView);
Config config( "ImageViewer" );
config.setGroup( "SlideShow" );
slideDelay = config.readNumEntry( "Delay", 2);
slideRepeat = config.readBoolEntry( "Repeat", FALSE );
slideReverse = config.readBoolEntry("Reverse", FALSE);
config.setGroup("Default");
rotateOnLoad = config.readBoolEntry("Rotate", FALSE);
fastLoad = config.readBoolEntry("FastLoad", TRUE);
slideTimer = new QTimer( this );
connect( slideTimer, SIGNAL(timeout()), this, SLOT(slideUpdate()) );
switchToFileSelector();
setMouseTracking( TRUE );
}
ImageViewer::~ImageViewer()
{
Config cfg("Image Viewer");
cfg.setGroup("Image Viewer");
cfg.writeEntry("ShowThumbnails",(int)showThumbView);
cfg.writeEntry("SizeToScreen",(int)isSized);
cfg.setGroup( "SlideShow" );
cfg.writeEntry( "Delay", slideDelay);
cfg.writeEntry( "Repeat", slideRepeat );
cfg.writeEntry("Reverse", slideReverse);
cfg.setGroup("Default");
cfg.writeEntry("Rotate", rotateOnLoad);
cfg.writeEntry("FastLoad", fastLoad);
delete imagePanel; // in case it is fullscreen
}
void ImageViewer::help() {
}
void ImageViewer::settings()
{
SettingsDialog dlg( this, 0, TRUE );
dlg.setDelay( slideDelay );
dlg.setRepeat( slideRepeat );
dlg.setReverse( slideReverse );
dlg.setRotate(rotateOnLoad);
dlg.setFastLoad(fastLoad);
if ( QPEApplication::execDialog(&dlg) == QDialog::Accepted ) {
qDebug("<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>");
slideDelay = dlg.delay();
slideRepeat = dlg.repeat();
slideReverse = dlg.reverse();
rotateOnLoad = dlg.rotate();
fastLoad = dlg.fastLoad();
Config config( "ImageViewer" );
config.setGroup( "SlideShow" );
config.writeEntry( "Delay", slideDelay );
config.writeEntry( "Repeat", slideRepeat );
config.writeEntry("Reverse", slideReverse);
config.setGroup("Default");
config.writeEntry("Rotate", rotateOnLoad);
config.writeEntry("FastLoad", fastLoad);
}
}
void ImageViewer::switchSizeToScreen()
{
isSized=!isSized;
sss->setOn(isSized);
updateImage();
}
void ImageViewer::updateImage()
{
if ( isSized ) {
imagePanel->setPixmap(pmScaled);
} else {
imagePanel->setPixmap(pm);
}
}
void ImageViewer::switchThumbView()
{
showThumbView=!showThumbView;
viewMenuFile->setItemChecked ( SHOW_THUMBNAILS, showThumbView );
fileSelector->switchView();
}
void ImageViewer::switchToFileSelector()
{
stack->raiseWidget(fileSelector);
menuBar->clear();
menuBar->insertItem( tr("File"), fileMenuFile );
menuBar->insertItem( tr("View"), viewMenuFile );
menuBar->insertItem( tr("Options"), optionsMenuFile );
iconToolBar->hide();
imagePanel->disable();
slideShow(false);
}
void ImageViewer::switchToImageView()
{
stack->raiseWidget(imagePanel);
menuBar->clear();
menuBar->insertItem( tr("File"), fileMenuView );
menuBar->insertItem( tr("View"), viewMenuView );
viewMenuView->setItemEnabled(BLACKANDWHITE,true);
iconToolBar->show();
imagePanel->setPosition(0,0);
}
void ImageViewer::setDocument(const QString& fileref)
{
delayLoad = fileref;
switchToImageView();
QTimer::singleShot( 0, this, SLOT(doDelayedLoad()) );
}
void ImageViewer::doDelayedLoad()
{
show(delayLoad);
}
void ImageViewer::show()
{
normalView();
QMainWindow::show();
}
void ImageViewer::show(const QString& fileref)
{
// qDebug("Show "+fileref);
bFromDocView = TRUE;
closeFileSelector();
DocLnk link(fileref);
if ( link.isValid() ) {
openFile(link);
} else {
filename = fileref;
updateCaption( fileref );
loadImage( fileref );
}
}
void ImageViewer::openFile() {
MimeTypes types;
QStringList image;
image << "image/*";
types.insert("Images", image);
QString str = OFileDialog::getOpenFileName( 1,QPEApplication::documentDir(),"", types, 0 );
DocLnk link(str);
- if ( link.isValid() )
+// if ( link.isValid() )
openFile(link);
}
void ImageViewer::openFile( const DocLnk &link )
{
closeFileSelector();
// DocLnk link(file);
qDebug("open "+link.name());
updateCaption( link.name() );
loadImage( link.file() );
if (slideTimer->isActive()) {
slideTimer->start(slideDelay * 1000, FALSE);
}
}
void ImageViewer::open()
{
switchToFileSelector();
}
void ImageViewer::closeFileSelector()
{
switchToImageView();
}
void ImageViewer::updateCaption( QString name )
{
int sep = name.findRev( '/' );
if ( sep >= 0 )
name = name.mid( sep+1 );
setCaption( name + tr(" - Image Viewer") );
}
/*
This function loads an image from a file.
*/
void ImageViewer::loadImage( const char *fileName )
{
filename = fileName;
if ( filename ) {
QApplication::setOverrideCursor( waitCursor ); // this might take time
//imagePanel->statusLabel()->setText( tr("Loading image...") );
qApp->processEvents();
bool ok = image.load(filename, 0);
if ( ok ) {
ok = reconvertImage();
updateImageInfo(filename);
}
if ( !ok ) {
pm.resize(0,0); // couldn't load image
update();
}
QApplication::restoreOverrideCursor(); // restore original cursor
}
// fastLoad ? ", Fast" : "",
// fastLoad ? QMAX(imagewidth/maxsize, imageheight/maxsize) : 1);
// matrix.reset();
rotated90 = FALSE;
if (rotateOnLoad) {
rotated90 = TRUE;
rot90();
// matrix.rotate( -90.0 );
}
switchToImageView();
updateImage();
}
bool ImageViewer::loadSelected()
{
bool ok = false;
if ( stack->visibleWidget() == fileSelector )
{
const DocLnk *link = fileSelector->selected();
if ( link )
{
if ( link->file() != filename )
{
updateCaption( link->name() );
filename = link->file();
qApp->processEvents();
ok = image.load(filename, 0);
if ( ok )
{
updateImageInfo(filename);
ok = reconvertImage();
}
if ( !ok )
pm.resize(0,0);
}
}
}
if ( !image.isNull() )
{
ok = true;
closeFileSelector();
}
return ok;
}
bool ImageViewer::reconvertImage()
{
bool success = FALSE;
if ( image.isNull() ) return FALSE;
QApplication::setOverrideCursor( waitCursor ); // this might take time
if ( pm.convertFromImage(image /*, conversion_flags */ ) )
{
pmScaled = QPixmap();
scale();
success = TRUE; // load successful
}
else
{
pm.resize(0,0); // couldn't load image
}
QApplication::restoreOverrideCursor(); // restore original cursor
return success; // TRUE if loaded OK
}
int ImageViewer::calcHeight()
{
if ( !isFullScreen )
return imagePanel->paneHeight();
else
return qApp->desktop()->height();
}
/*
This functions scales the pixmap in the member variable "pm" to fit the
widget size and puts the resulting pixmap in the member variable "pmScaled".
*/
void ImageViewer::scale()
{
int h = calcHeight();
if ( image.isNull() ) return;
QApplication::setOverrideCursor( waitCursor ); // this might take time
if ( imagePanel->paneWidth() == pm.width() && h == pm.height() )
{ // no need to scale if widget
pmScaled = pm; // size equals pixmap size
}
else
{
double hs = (double)h / (double)image.height();
double ws = (double)imagePanel->paneWidth() / (double)image.width();
double scaleFactor = (hs > ws) ? ws : hs;
int smoothW = (int)(scaleFactor * image.width());
int smoothH = (int)(scaleFactor * image.height());
pmScaled.convertFromImage( image.smoothScale( smoothW, smoothH ) /*, conversion_flags */ );
}
QApplication::restoreOverrideCursor(); // restore original cursor
}
/*
The resize event handler, if a valid pixmap was loaded it will call
scale() to fit the pixmap to the new widget size.
*/
void ImageViewer::resizeEvent( QResizeEvent * )
{
if ( pm.size() == QSize( 0, 0 ) ) // we couldn't load the image
return;
int h = calcHeight();
if ( imagePanel->paneWidth() != pmScaled.width() || h != pmScaled.height() )
{ // if new size,
scale(); // scale pmScaled to window
}
if ( image.hasAlphaBuffer() )
erase();
}
void ImageViewer::hFlip()
{
// matrix.scale( -1.0, 1.0 );
setImage(image.mirror(TRUE,FALSE));
}
void ImageViewer::vFlip()
{
// matrix.scale( 1.0, -1.0 );
setImage(image.mirror(FALSE,TRUE));
}
void ImageViewer::rot180()
{
// matrix.rotate( 180.0 );
setImage(image.mirror(TRUE,TRUE));
}
void ImageViewer::rot90()
{
QImage oldimage;
oldimage = image.convertDepth(32);
// matrix.rotate( -90.0 );
setImage(rotate(oldimage,Rotate90));
}
void ImageViewer::rot270()
{
QImage oldimage;
oldimage = image.convertDepth(32);
// matrix.rotate(90.0);
setImage(rotate(oldimage,Rotate270));
}
void ImageViewer::blackAndWhite()
{
viewMenuView->setItemEnabled(BLACKANDWHITE,false);
setImage(toGray(image,false));
}
void ImageViewer::displayControlsDialog()
{
int w=80;
int h=w;
QImage small;
if ( image.width()<w ||image.height()<h )
small=image.smoothScale(w,h);
else
small=image.copy(0,0,w,h);
int newB=0;
ControlsDialog *dlg=new ControlsDialog("Image Viewer",small,&newB,this);
dlg->exec();
if ( newB ) {
intensity(image,(float)newB/100);
setImage(image);
}
}
void ImageViewer::displayInfoDialog()
{
QStringList ls;
for ( int i=0;i<LAST;i++ )
ls.append(imageInfo[i]);
InfoDialog::displayInfo("Image Viewer",ls,this);
}
void ImageViewer::normalView()
{
if ( !imagePanel->parentWidget() )
{
isFullScreen = FALSE;
stack->addWidget( imagePanel, 1 );
switchToImageView();
if ( isSized )
scale();
updateImage();
}
}
void ImageViewer::stopSlideShow() {
if (slideTimer->isActive())
slideTimer->stop();
}
void ImageViewer::fullScreen()
{
// Full-screen option
// contributed by Robert Wittams <robert@wittams.com>
if ( imagePanel->parentWidget() && loadSelected() )
{
isFullScreen = TRUE;
imagePanel->reparent(0,QPoint(0,0));
imagePanel->resize(qApp->desktop()->width(), qApp->desktop()->height());
if ( isSized )
scale();
updateImage();
imagePanel->showFullScreen();
}
}
void ImageViewer::setImage(const QImage& newimage)
{
image = newimage;
reconvertImage();
updateImage();
}
void ImageViewer::updateImageInfo(QString &filePath)
{
for ( int i=0;i<LAST;i++ )
{
imageInfo[i]="";
}
imageInfo[FORMAT]=QImage::imageFormat (filePath );
QFileInfo fi(filePath);
imageInfo[PATH]=fi.fileName();
imageInfo[FILE_SIZE]=QString::number(fi.size())+" (bytes)";
QString message("%1x%2");
imageInfo[SIZE]=QString("%1x%2");
imageInfo[SIZE]=imageInfo[SIZE].arg(image.width()).arg(image.height());
if ( image.numColors() > 0 )
{
imageInfo[COLORS]=tr("%1 colors").arg(image.numColors());
}
else if ( image.depth() >= 16 )
{
imageInfo[COLORS]=tr(" True color");
}
if ( image.hasAlphaBuffer() )
{
if ( image.depth() == 8 )
{
int i;
bool alpha[256];
int nalpha=0;
for ( i=0; i<256; i++ )
alpha[i] = FALSE;
for ( i=0; i<image.numColors(); i++ )
{
int alevel = image.color(i) >> 24;
if ( !alpha[alevel] )
{
alpha[alevel] = TRUE;
nalpha++;
}
}
imageInfo[ALPHA]=tr("%1 alpha levels").arg(nalpha);
}
else
{
imageInfo[ALPHA]=tr("8-bit alpha channel");
}
}
}
void ImageViewer::closeEvent( QCloseEvent *e )
{
if ( stack->visibleWidget() == imagePanel && !bFromDocView )
{
e->ignore();
open();
}
else
{
bFromDocView = FALSE;
e->accept();
}
}
// Intensity,toGray and rotate code courtesy of KDE project.
QImage& ImageViewer::intensity(QImage &image, float percent)
{
int segColors = image.depth() > 8 ? 256 : image.numColors();
unsigned char *segTbl = new unsigned char[segColors];