summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/multimedia/showimg/showimg.cpp845
1 files changed, 666 insertions, 179 deletions
diff --git a/noncore/multimedia/showimg/showimg.cpp b/noncore/multimedia/showimg/showimg.cpp
index 24218e6..d7d53ec 100644
--- a/noncore/multimedia/showimg/showimg.cpp
+++ b/noncore/multimedia/showimg/showimg.cpp
@@ -25,3 +25,5 @@
#include "showimg.h"
+#include "ImageFileSelector.h"
+#include <qpe/config.h>
#include <qpe/resource.h>
@@ -29,3 +31,4 @@
#include <qpe/applnk.h>
-
+#include <qfileinfo.h>
+#include <math.h>
#include <qpe/qpemenubar.h>
@@ -37,2 +40,3 @@
#include <qpopupmenu.h>
+#include <qscrollview.h>
#include <qlabel.h>
@@ -43,47 +47,133 @@
#include <qtimer.h>
+#include <qspinbox.h>
-ImagePane::ImagePane( QWidget *parent ) : QWidget( parent )
+
+ControlsDialog::ControlsDialog(const QString &caption,QImage image,int *brightness,QWidget *parent):QDialog(parent,0,true)
{
- vb = new QVBoxLayout( this );
+ setCaption(caption);
+
+ if ( parent )
+ {
+ setPalette(parent->palette());
+ }
- image = new ImageWidget( this );
- connect(image, SIGNAL( clicked() ), this, SLOT( imageClicked() ));
+ b=brightness;
+ img=image;
- vb->addWidget( image );
+ setMinimumSize(140,80);
+
+ QGridLayout *gl= new QGridLayout(this,2,2,4,4);
+
+ pixmap =new ImageWidget(this);;
+ QPixmap pm;
+ pm.convertFromImage(img);
+ pixmap->setPixmap(pm);
+ pixmap->setMinimumSize(pm.width(),pm.height());
+ gl->addMultiCellWidget(pixmap,0,0,0,2,AlignCenter);
+ QLabel *l=new QLabel(tr("Brightness")+":",this);
+ gl->addWidget(l,1,0,AlignLeft);
+ spb=new QSpinBox(-100,100,2,this);
+ gl->addWidget(spb,1,1,AlignRight);
+
+ spb->setValue(0);
+
+ connect(spb,SIGNAL(valueChanged(int)),this, SLOT(bValueChanged(int)));
- status = new QLabel( this );
- status->setFixedHeight( fontMetrics().height() + 4 );
- vb->addWidget( status );
}
-void ImagePane::setPixmap( const QPixmap &pm )
+void ControlsDialog::bValueChanged(int value)
{
- image->setPixmap( pm );
- image->repaint( false );
+ QImage nImage=img;
+ nImage.detach();
+ ImageViewer::intensity(nImage, (float)value/100);
+ QPixmap pm;
+ pm.convertFromImage(nImage);
+ pixmap->setPixmap(pm);
+ pixmap->repaint(false);
+
+
}
-void ImagePane::imageClicked()
+void ControlsDialog::accept()
{
- emit clicked();
+ *b=spb->value();
+ done(1);
}
-void ImagePane::showStatus()
+
+
+InfoDialog::InfoDialog(const QString &caption, const QStringList text,QWidget *parent):QDialog(parent,0,true)
{
- delete vb;
- vb = new QVBoxLayout( this );
- vb->addWidget( image );
- status->show();
- vb->addWidget( status );
+ setCaption(caption);
+
+ if ( parent )
+ {
+ setPalette(parent->palette());
}
+ const char *labels[]={"File Name","Format","File Size","Size","Colors","Alpha"};
+
+ setMinimumSize(180,80);
+ int num=ImageViewer::LAST+1;
+ if ( text[ImageViewer::ALPHA].isEmpty() )
+ num--;
+ QGridLayout *gl= new QGridLayout(this,num,2,4,2);
+ QLabel *l;
+ int count=0;
+ for ( int i=0;i<num;i++ )
+ {
+ if ( i==1 )
+ {
+ QFrame *frm=new QFrame(this);
+ frm->setFrameStyle(QFrame::HLine|QFrame::Sunken);
+ gl->addMultiCellWidget(frm,i,i,0,1);
+ }
+ else
+ {
+ l=new QLabel(tr(labels[count])+":",this);
+ gl->addWidget(l,i,0,AlignLeft);
+ l=new QLabel(text[count],this);
+ gl->addWidget(l,i,1,AlignRight);
+ count++;
+ }
-void ImagePane::hideStatus()
+ }
+
+}
+
+void InfoDialog::displayInfo(const QString &caption, const QStringList text, QWidget *parent)
+{
+ InfoDialog *dlg=new InfoDialog(caption,text,parent);
+ dlg->exec();
+ delete dlg;
+}
+
+
+ImagePane::ImagePane( QWidget *parent ) : QWidget( parent )
{
- delete vb;
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 );
- status->hide();
+
+}
+
+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();
+}
//===========================================================================
@@ -98,6 +188,6 @@ void ImageWidget::paintEvent( QPaintEvent *e )
painter.setClipRect(e->rect());
- painter.setBrush( black );
- painter.drawRect( 0, 0, width(), height() );
+ painter.fillRect(0,0,width(),height(),QColor(0,0,0));
- if ( pixmap.size() != QSize( 0, 0 ) ) { // is an image loaded?
+ if ( pixmap.size() != QSize( 0, 0 ) )
+ { // is an image loaded?
painter.drawPixmap((width() - pixmap.width()) / 2, (height() - pixmap.height()) / 2, pixmap);
@@ -111,3 +201,2 @@ void ImageWidget::mouseReleaseEvent(QMouseEvent *)
-
//===========================================================================
@@ -115,4 +204,3 @@ void ImageWidget::mouseReleaseEvent(QMouseEvent *)
ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
- : QMainWindow( parent, name, wFlags ), filename( 0 ),
- pickx( -1 ), picky( -1 ), clickx( -1 ), clicky( -1 ), bFromDocView( FALSE )
+: QMainWindow( parent, name, wFlags ), filename( 0 ), bFromDocView( FALSE )
{
@@ -121,2 +209,9 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
+
+ Config cfg("Image Viewer");
+ cfg.setGroup("Image Viewer");
+
+ showThumbView=cfg.readBoolEntry("ShowThumbnails",false);
+ isSized=cfg.readBoolEntry("SizeToScreen",true);
+
isFullScreen = FALSE;
@@ -128,3 +223,30 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
- menubar = new QPEMenuBar( toolBar );
+ 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 );
+ optionsMenuFile->insertItem( tr("Slideshow") );
+ optionsMenuFile->insertSeparator();
+ optionsMenuFile->insertItem( tr("Preferences.."));
+ optionsMenuFile->insertItem( tr("Help"));
+
+
+
@@ -132,10 +254,14 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
- QPopupMenu *edit = new QPopupMenu( menubar );
- QPopupMenu *view = new QPopupMenu( menubar );
- menubar->insertItem(tr("Edit"), edit );
- menubar->insertItem(tr("View"), view );
+ 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 );
- edit->insertItem(tr("Horizontal flip"), this, SLOT(hFlip()), 0);
- edit->insertItem(tr("Vertical flip"), this, SLOT(vFlip()), 0);
+ //menubarView->insertItem( tr("View"),viewMenu );
+ viewMenuView->insertItem(tr("Horizontal flip"), this, SLOT(hFlip()), 0);
+ viewMenuView->insertItem(tr("Vertical flip"), this, SLOT(vFlip()), 0);
@@ -145,2 +271,3 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
+
imagePanel = new ImagePane( stack );
@@ -148,5 +275,19 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
- fileSelector = new FileSelector("image/*", stack, "fs");
- fileSelector->setNewVisible(FALSE);
- fileSelector->setCloseVisible(FALSE);
+
+ 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() ) );
@@ -154,3 +295,3 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
- toolBar = new QPEToolBar( this );
+ iconToolBar = new QPEToolBar(this);
@@ -158,10 +299,7 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
- a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
+ a = new QAction( tr( "Open ..." ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( open() ) );
- a->addTo( toolBar );
+ a->addTo( fileMenuView);
+ a->addTo( iconToolBar );
- a = new QAction( tr( "Rotate 180" ), Resource::loadPixmap( "repeat" ), QString::null, 0, this, 0 );
- connect( a, SIGNAL( activated() ), this, SLOT( rot180() ) );
- a->addTo( toolBar );
- a->addTo( edit );
@@ -169,4 +307,32 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
connect( a, SIGNAL( activated() ), this, SLOT( rot90() ) );
- a->addTo( toolBar );
- a->addTo( edit );
+ 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();
+
@@ -174,8 +340,10 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
connect( a, SIGNAL( activated() ), this, SLOT( fullScreen() ) );
- a->addTo( toolBar );
- a->addTo( view);
+ a->addTo( iconToolBar );
+ a->addTo( viewMenuView);
- stack->raiseWidget( fileSelector );
+ switchToFileSelector();
setMouseTracking( TRUE );
+
+
}
@@ -184,2 +352,8 @@ ImageViewer::~ImageViewer()
{
+ Config cfg("Image Viewer");
+ cfg.setGroup("Image Viewer");
+
+ cfg.writeEntry("ShowThumbnails",(int)showThumbView);
+ cfg.writeEntry("SizeToScreen",(int)isSized);
+
delete imagePanel; // in case it is fullscreen
@@ -187,2 +361,57 @@ ImageViewer::~ImageViewer()
+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();
+
+}
+
+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)
@@ -190,3 +419,3 @@ void ImageViewer::setDocument(const QString& fileref)
delayLoad = fileref;
- stack->raiseWidget(imagePanel);
+ switchToImageView();
QTimer::singleShot( 0, this, SLOT(doDelayedLoad()) );
@@ -210,5 +439,8 @@ void ImageViewer::show(const QString& fileref)
DocLnk link(fileref);
- if ( link.isValid() ) {
+ if ( link.isValid() )
+ {
openFile(link);
- } else {
+ }
+ else
+ {
filename = fileref;
@@ -229,3 +461,3 @@ void ImageViewer::open()
{
- stack->raiseWidget(fileSelector);
+ switchToFileSelector();
}
@@ -234,3 +466,3 @@ void ImageViewer::closeFileSelector()
{
- stack->raiseWidget(imagePanel);
+ switchToImageView();
}
@@ -252,12 +484,15 @@ void ImageViewer::loadImage( const char *fileName )
filename = fileName;
- if ( filename ) {
+ if ( filename )
+ {
QApplication::setOverrideCursor( waitCursor ); // this might take time
- imagePanel->statusLabel()->setText( tr("Loading image...") );
+ //imagePanel->statusLabel()->setText( tr("Loading image...") );
qApp->processEvents();
bool ok = image.load(filename, 0);
- pickx = -1;
- clickx = -1;
if ( ok )
+ {
ok = reconvertImage();
- if ( !ok ) {
+ updateImageInfo(filename);
+ }
+ if ( !ok )
+ {
pm.resize(0,0); // couldn't load image
@@ -267,5 +502,5 @@ void ImageViewer::loadImage( const char *fileName )
}
- updateStatus();
- imagePanel->setPixmap( pmScaled );
- stack->raiseWidget(imagePanel);
+ switchToImageView();
+ updateImage();
+
}
@@ -275,9 +510,11 @@ bool ImageViewer::loadSelected()
bool ok = false;
- if ( stack->visibleWidget() == fileSelector ) {
+ if ( stack->visibleWidget() == fileSelector )
+ {
const DocLnk *link = fileSelector->selected();
- if ( link ) {
- if ( link->file() != filename ) {
+ if ( link )
+ {
+ if ( link->file() != filename )
+ {
updateCaption( link->name() );
filename = link->file();
- imagePanel->statusLabel()->setText( tr("Loading image...") );
qApp->processEvents();
@@ -285,3 +522,6 @@ bool ImageViewer::loadSelected()
if ( ok )
+ {
+ updateImageInfo(filename);
ok = reconvertImage();
+ }
if ( !ok )
@@ -291,3 +531,4 @@ bool ImageViewer::loadSelected()
}
- if ( !image.isNull() ) {
+ if ( !image.isNull() )
+ {
ok = true;
@@ -311,3 +552,5 @@ bool ImageViewer::reconvertImage()
success = TRUE; // load successful
- } else {
+ }
+ else
+ {
pm.resize(0,0); // couldn't load image
@@ -323,4 +566,3 @@ int ImageViewer::calcHeight()
if ( !isFullScreen)
- return height() - menubar->heightForWidth( width() )
- - imagePanel->statusLabel()->height();
+ return imagePanel->paneHeight();
else
@@ -332,3 +574,2 @@ int ImageViewer::calcHeight()
*/
-
void ImageViewer::scale()
@@ -339,7 +580,10 @@ void ImageViewer::scale()
QApplication::setOverrideCursor( waitCursor ); // this might take time
- if ( width() == pm.width() && h == pm.height() ) { // no need to scale if widget
+ if ( imagePanel->paneWidth() == pm.width() && h == pm.height() )
+ { // no need to scale if widget
pmScaled = pm; // size equals pixmap size
- } else {
+ }
+ else
+ {
double hs = (double)h / (double)image.height();
- double ws = (double)width() / (double)image.width();
+ double ws = (double)imagePanel->paneWidth() / (double)image.width();
double scaleFactor = (hs > ws) ? ws : hs;
@@ -360,4 +604,2 @@ void ImageViewer::resizeEvent( QResizeEvent * )
{
- imagePanel->statusLabel()->setGeometry(0, height() - imagePanel->statusLabel()->height(),
- width(), imagePanel->statusLabel()->height());
@@ -368,6 +610,5 @@ void ImageViewer::resizeEvent( QResizeEvent * )
- if ( width() != pmScaled.width() || h != pmScaled.height())
+ if ( imagePanel->paneWidth() != pmScaled.width() || h != pmScaled.height() )
{ // if new size,
scale(); // scale pmScaled to window
- updateStatus();
}
@@ -377,25 +618,2 @@ void ImageViewer::resizeEvent( QResizeEvent * )
-void ImageViewer::convertEvent( QMouseEvent* e, int& x, int& y)
-{
- if ( pm.size() != QSize( 0, 0 ) ) {
- int h = height() - menubar->heightForWidth( width() ) - imagePanel->statusLabel()->height();
- int nx = e->x() * image.width() / width();
- int ny = (e->y()-menubar->heightForWidth( width() )) * image.height() / h;
- if (nx != x || ny != y ) {
- x = nx;
- y = ny;
- updateStatus();
- }
- }
-}
-
-void ImageViewer::mousePressEvent( QMouseEvent *e )
-{
- convertEvent(e, clickx, clicky);
-}
-
-void ImageViewer::mouseMoveEvent( QMouseEvent *e )
-{
- convertEvent( e, pickx, picky );
-}
@@ -403,3 +621,2 @@ void ImageViewer::hFlip()
{
- if ( loadSelected() )
setImage(image.mirror(TRUE,FALSE));
@@ -409,3 +626,2 @@ void ImageViewer::vFlip()
{
- if ( loadSelected() )
setImage(image.mirror(FALSE,TRUE));
@@ -415,3 +631,3 @@ void ImageViewer::rot180()
{
- if ( loadSelected() )
+
setImage(image.mirror(TRUE,TRUE));
@@ -421,40 +637,71 @@ void ImageViewer::rot90()
{
- if ( loadSelected() ) {
- QImage oldimage, newimage;
- uchar *oldbits, *newbits;
- int i, j, p;
- int w, h;
+ QImage oldimage;
+ oldimage = image.convertDepth(32);
+ setImage(rotate(oldimage,Rotate90));
+
+}
+void ImageViewer::rot270()
+{
+ QImage oldimage;
oldimage = image.convertDepth(32);
- w = oldimage.height();
- h = oldimage.width();
- newimage = QImage( w, h, 32);
+ setImage(rotate(oldimage,Rotate270));
- oldbits = oldimage.bits();
- newbits = newimage.bits();
+}
+
+void ImageViewer::blackAndWhite()
+{
+
+ viewMenuView->setItemEnabled(BLACKANDWHITE,false);
+ setImage(toGray(image,false));
- for (i=0; i < w ; i++)
- for (j=0; j < h; j++)
- for (p = 0 ; p < 4 ; p++)
- newbits[(j * w + i) * 4 + p] = oldbits[ ((i + 1) * h - j ) * 4 + p];
- setImage(newimage);
}
+
+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() ) {
+ if ( !imagePanel->parentWidget() )
+ {
+
isFullScreen = FALSE;
stack->addWidget( imagePanel, 1 );
-// imagePanel->reparent(stack,0,QPoint(0,0),FALSE);
-// imagePanel->resize(width(), calcHeight());
+ switchToImageView();
+ if ( isSized )
scale();
- updateStatus();
- imagePanel->setPixmap( pmScaled );
- imagePanel->showStatus();
- // imagePanel->show();
- stack->raiseWidget( imagePanel );
+
+ updateImage();
+
}
@@ -464,6 +711,6 @@ void ImageViewer::fullScreen()
{
- // Full-screen and rotation options
+ // Full-screen option
// contributed by Robert Wittams <robert@wittams.com>
-
- if ( imagePanel->parentWidget() && loadSelected() ) {
+ if ( imagePanel->parentWidget() && loadSelected() )
+ {
isFullScreen = TRUE;
@@ -472,6 +719,5 @@ void ImageViewer::fullScreen()
+ if ( isSized )
scale();
- updateStatus();
- imagePanel->hideStatus();
- imagePanel->setPixmap( pmScaled );
+ updateImage();
imagePanel->showFullScreen();
@@ -483,42 +729,33 @@ void ImageViewer::setImage(const QImage& newimage)
image = newimage;
- pickx = -1;
- clickx = -1;
reconvertImage();
- imagePanel->setPixmap( pmScaled );
- updateStatus();
+ updateImage();
}
-void ImageViewer::updateStatus()
+void ImageViewer::updateImageInfo(QString &filePath)
{
- if ( pm.size() == QSize( 0, 0 ) ) {
- if ( filename )
- imagePanel->statusLabel()->setText( tr("Could not load image") );
- else
- imagePanel->statusLabel()->setText( tr("No image - select Open from File menu.") );
- } else {
+
+ 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");
- message = message.arg(image.width()).arg(image.height());
- if ( pm.size() != pmScaled.size() )
- message += QString(" [%1x%2]").arg(pmScaled.width()).arg(pmScaled.height());
- if (image.valid(pickx,picky)) {
- QString moremsg;
- moremsg.sprintf("(%d,%d)=#%0*x ",
- pickx, picky,
- image.hasAlphaBuffer() ? 8 : 6,
- image.pixel(pickx,picky));
- message += moremsg;
- }
- if ( image.numColors() > 0 ) {
- if (image.valid(pickx,picky)) {
- message += tr(", %1/%2 colors")
- .arg(image.pixelIndex(pickx,picky))
- .arg(image.numColors());
- } else {
- message += tr(", %1 colors").arg(image.numColors());
- }
- } else if ( image.depth() >= 16 ) {
- message += tr(" True color");
- }
- if ( image.hasAlphaBuffer() ) {
- if ( image.depth() == 8 ) {
+ 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;
@@ -530,5 +767,7 @@ void ImageViewer::updateStatus()
- for (i=0; i<image.numColors(); i++) {
+ for ( i=0; i<image.numColors(); i++ )
+ {
int alevel = image.color(i) >> 24;
- if (!alpha[alevel]) {
+ if ( !alpha[alevel] )
+ {
alpha[alevel] = TRUE;
@@ -537,10 +776,10 @@ void ImageViewer::updateStatus()
}
- message += tr(", %1 alpha levels").arg(nalpha);
- } else {
- // Too many pixels to bother counting.
- message += tr(", 8-bit alpha channel");
+ imageInfo[ALPHA]=tr("%1 alpha levels").arg(nalpha);
}
+ else
+ {
+ imageInfo[ALPHA]=tr("8-bit alpha channel");
}
- imagePanel->statusLabel()->setText(message);
}
+
}
@@ -549,6 +788,9 @@ void ImageViewer::closeEvent( QCloseEvent *e )
{
- if ( stack->visibleWidget() == imagePanel && !bFromDocView ) {
+ if ( stack->visibleWidget() == imagePanel && !bFromDocView )
+ {
e->ignore();
open();
- } else {
+ }
+ else
+ {
bFromDocView = FALSE;
@@ -557 +799,246 @@ void ImageViewer::closeEvent( QCloseEvent *e )
}
+
+// 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];
+ int pixels = image.depth() > 8 ? image.width()*image.height() :
+ image.numColors();
+ unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() :
+ (unsigned int *)image.colorTable();
+
+ bool brighten = (percent >= 0);
+ if ( percent < 0 )
+ percent = -percent;
+
+ if ( brighten )
+ { // keep overflow check out of loops
+ for ( int i=0; i < segColors; ++i )
+ {
+ int tmp = (int)(i*percent);
+ if ( tmp > 255 )
+ tmp = 255;
+ segTbl[i] = tmp;
+ }
+ }
+ else
+ {
+ for ( int i=0; i < segColors; ++i )
+ {
+ int tmp = (int)(i*percent);
+ if ( tmp < 0 )
+ tmp = 0;
+ segTbl[i] = tmp;
+ }
+ }
+
+ if ( brighten )
+ { // same here
+ for ( int i=0; i < pixels; ++i )
+ {
+ int r = qRed(data[i]);
+ int g = qGreen(data[i]);
+ int b = qBlue(data[i]);
+ int a = qAlpha(data[i]);
+ r = r + segTbl[r] > 255 ? 255 : r + segTbl[r];
+ g = g + segTbl[g] > 255 ? 255 : g + segTbl[g];
+ b = b + segTbl[b] > 255 ? 255 : b + segTbl[b];
+ data[i] = qRgba(r, g, b,a);
+ }
+ }
+ else
+ {
+ for ( int i=0; i < pixels; ++i )
+ {
+ int r = qRed(data[i]);
+ int g = qGreen(data[i]);
+ int b = qBlue(data[i]);
+ int a = qAlpha(data[i]);
+ r = r - segTbl[r] < 0 ? 0 : r - segTbl[r];
+ g = g - segTbl[g] < 0 ? 0 : g - segTbl[g];
+ b = b - segTbl[b] < 0 ? 0 : b - segTbl[b];
+ data[i] = qRgba(r, g, b, a);
+ }
+ }
+ delete [] segTbl;
+
+ return image;
+}
+
+QImage& ImageViewer::toGray(QImage &img, bool fast)
+{
+ if ( img.width() == 0 || img.height() == 0 )
+ return img;
+
+ if ( fast )
+ {
+ if ( img.depth() == 32 )
+ {
+ register uchar * r(img.bits());
+ register uchar * g(img.bits() + 1);
+ register uchar * b(img.bits() + 2);
+
+ uchar * end(img.bits() + img.numBytes());
+
+ while ( r != end )
+ {
+
+ *r = *g = *b = (((*r + *g) >> 1) + *b) >> 1; // (r + b + g) / 3
+
+ r += 4;
+ g += 4;
+ b += 4;
+ }
+ }
+ else
+ {
+ for ( int i = 0; i < img.numColors(); i++ )
+ {
+ register uint r = qRed(img.color(i));
+ register uint g = qGreen(img.color(i));
+ register uint b = qBlue(img.color(i));
+
+ register uint gray = (((r + g) >> 1) + b) >> 1;
+ img.setColor(i, qRgba(gray, gray, gray, qAlpha(img.color(i))));
+ }
+ }
+ }
+ else
+ {
+ int pixels = img.depth() > 8 ? img.width()*img.height() :
+ img.numColors();
+ unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() :
+ (unsigned int *)img.colorTable();
+ int val, i;
+ for ( i=0; i < pixels; ++i )
+ {
+ val = qGray(data[i]);
+ data[i] = qRgba(val, val, val, qAlpha(data[i]));
+ }
+ }
+ return img;
+}
+
+
+QImage ImageViewer::rotate(QImage &img, RotateDirection r)
+{
+ QImage dest;
+ int x, y;
+ if ( img.depth() > 8 )
+ {
+ unsigned int *srcData, *destData;
+ switch ( r )
+ {
+ case Rotate90:
+ dest.create(img.height(), img.width(), img.depth());
+ for ( y=0; y < img.height(); ++y )
+ {
+ srcData = (unsigned int *)img.scanLine(y);
+ for ( x=0; x < img.width(); ++x )
+ {
+ destData = (unsigned int *)dest.scanLine(x);
+ destData[img.height()-y-1] = srcData[x];
+ }
+ }
+ break;
+ case Rotate180:
+ dest.create(img.width(), img.height(), img.depth());
+ for ( y=0; y < img.height(); ++y )
+ {
+ srcData = (unsigned int *)img.scanLine(y);
+ destData = (unsigned int *)dest.scanLine(img.height()-y-1);
+ for ( x=0; x < img.width(); ++x )
+ destData[img.width()-x-1] = srcData[x];
+ }
+ break;
+ case Rotate270:
+ dest.create(img.height(), img.width(), img.depth());
+ for ( y=0; y < img.height(); ++y )
+ {
+ srcData = (unsigned int *)img.scanLine(y);
+ for ( x=0; x < img.width(); ++x )
+ {
+ destData = (unsigned int *)dest.scanLine(img.width()-x-1);
+ destData[y] = srcData[x];
+ }
+ }
+ break;
+ default:
+ dest = img;
+ break;
+ }
+ }
+ else
+ {
+ unsigned char *srcData, *destData;
+ unsigned int *srcTable, *destTable;
+ switch ( r )
+ {
+ case Rotate90:
+ dest.create(img.height(), img.width(), img.depth());
+ dest.setNumColors(img.numColors());
+ srcTable = (unsigned int *)img.colorTable();
+ destTable = (unsigned int *)dest.colorTable();
+ for ( x=0; x < img.numColors(); ++x )
+ destTable[x] = srcTable[x];
+ for ( y=0; y < img.height(); ++y )
+ {
+ srcData = (unsigned char *)img.scanLine(y);
+ for ( x=0; x < img.width(); ++x )
+ {
+ destData = (unsigned char *)dest.scanLine(x);
+ destData[img.height()-y-1] = srcData[x];
+ }
+ }
+ break;
+ case Rotate180:
+ dest.create(img.width(), img.height(), img.depth());
+ dest.setNumColors(img.numColors());
+ srcTable = (unsigned int *)img.colorTable();
+ destTable = (unsigned int *)dest.colorTable();
+ for ( x=0; x < img.numColors(); ++x )
+ destTable[x] = srcTable[x];
+ for ( y=0; y < img.height(); ++y )
+ {
+ srcData = (unsigned char *)img.scanLine(y);
+ destData = (unsigned char *)dest.scanLine(img.height()-y-1);
+ for ( x=0; x < img.width(); ++x )
+ destData[img.width()-x-1] = srcData[x];
+ }
+ break;
+ case Rotate270:
+ dest.create(img.height(), img.width(), img.depth());
+ dest.setNumColors(img.numColors());
+ srcTable = (unsigned int *)img.colorTable();
+ destTable = (unsigned int *)dest.colorTable();
+ for ( x=0; x < img.numColors(); ++x )
+ destTable[x] = srcTable[x];
+ for ( y=0; y < img.height(); ++y )
+ {
+ srcData = (unsigned char *)img.scanLine(y);
+ for ( x=0; x < img.width(); ++x )
+ {
+ destData = (unsigned char *)dest.scanLine(img.width()-x-1);
+ destData[y] = srcData[x];
+ }
+ }
+ break;
+ default:
+ dest = img;
+ break;
+ }
+
+ }
+ return (dest);
+
+
+}
+
+
+
+
+